Commit 15ce0d14 authored by Jolien Creighton's avatar Jolien Creighton Committed by Adam Mercer

modify lalDebugLevel using an environment variable only

Original: 2c9ae10a3480942dd6428938e5c6754b790d56cf
parent 889bffdc
......@@ -17,5 +17,15 @@
* MA 02111-1307 USA
*/
/* an empty file to give automake something to find */
int lalDebugLevel = 0; /* resolve this final symbol */
/* An almost-empty file to give automake something to find */
/*
* This needs to be in some source code somewhere,
* so may as well put it here.
*/
#include <config.h>
#if defined(NDEBUG) || defined(LAL_NDEBUG)
const int lalNoDebug = 1;
#else
const int lalNoDebug = 0;
#endif
......@@ -49,16 +49,12 @@ to.
#include <lal/LALStdlib.h>
#include <lal/LALVersion.h>
extern int lalDebugLevel;
int main( void )
{
static LALStatus status;
char msg[16384];
int verbose = 1;
lalDebugLevel = 0;
if ( strcmp( LAL_VERSION, lalVersion ) ||
strcmp( LAL_CONFIGURE_ARGS, lalConfigureArgs ) ||
strcmp( LAL_CONFIGURE_DATE, lalConfigureDate ) )
......
......@@ -46,7 +46,6 @@ extern "C" {
The general approach consists of these steps
<ol>
<li> read log-level from user-input using XLALGetDebugLevel() [<b>Note:</b> this must happend before and (X)LAL memory allocation!!]</li>
<li> set default-value for optional user-variables</li>
<li> \c register all user-variables using calls to \c XLALRegister<TYPE>UserVar(), or more conveniently, using the shortcut-macros
XLALreg<TYPE>UserStruct() that assume a struct-pointer named 'uvar' containing all user-variables as 'uvar->UserVariable'.</li>
......@@ -79,15 +78,11 @@ int main(int argc,char *argv[])
UserInput_t UserVariables = empty_UserInput; // initializes this struct to {0}
UserInput_t *uvar = &UserVariables; // struct-pointer allows us to use the XLALreg<TYPE>UserStruct() macros...
// 1. step: read lal-debug level, using short-option '-v'
if ( XLALGetDebugLevel ( argc, argv, 'v') != XLAL_SUCCESS )
XLAL_ERROR ( XLAL_EFUNC );
// 2. step: set default-values for optional user-input variables
// 1. step: set default-values for optional user-input variables
uvar->anInteger = 0;
uvar->andAString = NULL; // Note: need to assign allocated strings here as default!!
// 3. step: Register all user-variables using the shortcut macros:
// 2. step: Register all user-variables using the shortcut macros:
XLALregBOOLUserStruct ( help, 'h', UVAR_HELP, "Output this help-message");
XLALregINTUserStruct ( anInteger, 'i', UVAR_OPTIONAL, "An example user-variable of an optional integer");
XLALregREALUserStruct ( aDoubleVar, 'r', UVAR_REQUIRED, "This REAL8 user-variable is required");
......@@ -95,7 +90,7 @@ int main(int argc,char *argv[])
XLALregREALUserStruct ( specialGeekSwitch, 'g', UVAR_DEVELOPER, "This REAL8 user-variable is required");
// 4. step: parse all user-input, from either config-file if given, or commandline (overloads config-file values)
// 3. step: parse all user-input, from either config-file if given, or commandline (overloads config-file values)
if ( XLALUserVarReadAllInput ( argc, argv ) != XLAL_SUCCESS )
XLAL_ERROR ( XLAL_EFUNC );
......@@ -104,7 +99,7 @@ int main(int argc,char *argv[])
printf ("User-input was: anInteger = %d, aDoubleVar = %f, andAString = %s\n", uvar->anInteger, uvar->aDoubleVar, uvar->andAString );
// 5. step: free user-input module memory
// 4. step: free user-input module memory
XLALDestroyUserVars();
LALCheckMemoryLeaks();
......@@ -190,7 +185,6 @@ CHAR *XLALUserVarHelpString ( const CHAR *progname );
int XLALUserVarReadAllInput ( int argc, char *argv[] );
int XLALUserVarCheckRequired( void );
int XLALUserVarWasSet (const void *cvar);
int XLALGetDebugLevel (int argc, char *argv[], CHAR optchar);
CHAR * XLALUserVarGetLog ( UserVarLogFormat format );
/* type-specific wrappers to XLALRegisterUserVar() to allow type-checking! */
......@@ -287,7 +281,6 @@ void LALUserVarReadCfgfile (LALStatus *, const CHAR *cfgfile);
void LALUserVarHelpString (LALStatus *, CHAR **helpstring, const CHAR *progname);
void LALUserVarCheckRequired (LALStatus *);
INT4 LALUserVarWasSet (const void *cvar);
void LALGetDebugLevel (LALStatus *, int argc, char *argv[], CHAR optchar);
void LALUserVarGetLog (LALStatus *, CHAR **logstr, UserVarLogFormat format);
#if 0
void LALUserVarGetProcParamsTable (LALStatus *status, ProcessParamsTable **out, CHAR *progname);
......
......@@ -46,8 +46,6 @@
#include <lal/ConfigFile.h>
extern INT4 lalDebugLevel;
#define FMT_STRING "string" /* reading in quoted strings needs some special treatment */
#define WHITESPACE " \t"
......
......@@ -26,8 +26,6 @@
#include <lal/LALString.h>
#include <lal/StringVector.h>
extern INT4 lalDebugLevel;
#define TRUE (1==1)
#define FALSE (1==0)
......@@ -937,69 +935,6 @@ XLALUserVarCheckRequired (void)
} /* XLALUserVarCheckRequired() */
/** Handle the delicate setting of lalDebuglevel.
*
* \note *NEVER* call this function after any LALMalloc/LALCalloc/LALRealloc
* have been used. A change of lalDebugLevel can then lead to inconsistencies
* in the LAL memory-checker.
* You should therefore call this function very early on in main(), before any
* LALMallocs ...
*/
int
XLALGetDebugLevel (int argc, char *argv[], CHAR optchar)
{
static const char *help = "set lalDebugLevel";
static INT4 defaultDebugLevel;
INT4 i;
CHAR *ptr;
if ( !argv ) {
XLALPrintError ("%s: NULL argv[] passed as input.\n", __func__ );
XLAL_ERROR ( XLAL_EINVAL );
}
if ( UVAR_vars.next != NULL || UVAR_vars.varp ) {
XLALPrintError ("%s: lalDebugLevel can only be read before ANY mallocs(), even hidden..\n", __func__ );
XLAL_ERROR ( XLAL_EFAULT );
}
/* "register" the debug-level variable in the head of the UVAR-list,
* to avoid any mallocs. We need this to show up in the help-string */
UVAR_vars.name = NULL;
UVAR_vars.type = UVAR_INT4;
UVAR_vars.optchar = optchar;
UVAR_vars.help = help;
defaultDebugLevel = lalDebugLevel;
UVAR_vars.varp = &defaultDebugLevel; /* trick: use to store default-value (for help-string) */
UVAR_vars.state = UVAR_OPTIONAL;
UVAR_vars.next = NULL;
/* the command-line has to be processed by hand for this... ! */
for (i=1; i < argc; i++)
{
if ( (argv[i][0] == '-') && (argv[i][1] == optchar) )
{
if (argv[i][2] != '\0')
ptr = argv[i]+2;
else
ptr = argv[i+1];
if ( (ptr == NULL) || (sscanf ( ptr, "%d", &lalDebugLevel) != 1) ) {
XLALPrintError ("%s: Setting debug-level `-%c` requires an argument\n", __func__, optchar);
XLAL_ERROR ( XLAL_EDOM );
}
break;
} /* if debug-switch found */
} /* for i < argc */
return XLAL_SUCCESS;
} /* XLALGetDebugLevel() */
/** Return a log-string representing the <em>complete</em> user-input.
* <em>NOTE:</em> we only record user-variables that have been set
* by the user.
......@@ -1399,28 +1334,6 @@ LALUserVarWasSet (const void *cvar)
return (XLALUserVarWasSet(cvar));
}
/** \deprecated use XLALGetDebugLevel() instead */
void
LALGetDebugLevel (LALStatus *status, int argc, char *argv[], CHAR optchar)
{
const char *fn = __func__;
INITSTATUS(status);
ASSERT (argv, status, USERINPUTH_ENULL, USERINPUTH_MSGENULL);
ASSERT (UVAR_vars.next == NULL, status, USERINPUTH_EDEBUG, USERINPUTH_MSGEDEBUG);
ASSERT (UVAR_vars.varp == NULL, status, USERINPUTH_EDEBUG, USERINPUTH_MSGEDEBUG);
if ( XLALGetDebugLevel (argc, argv, optchar) != XLAL_SUCCESS ) {
XLALPrintError ("%s: call to XLALGetDebugLevel() failed with code %d\n", fn, xlalErrno );
ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL );
}
RETURN (status);
} /* LALGetDebugLevel() */
/** \deprecated use XLALUserVarGetLog() instead */
void
LALUserVarGetLog (LALStatus *status, CHAR **logstr, UserVarLogFormat format)
......
......@@ -22,7 +22,6 @@
#include <lal/ConfigFile.h>
/* Default parameters. */
INT4 lalDebugLevel=3;
int main ( int argc, char *argv[])
{
......
......@@ -63,7 +63,6 @@ for integers are not tested.
#include <lal/LALStdlib.h>
#include <lal/AVFactories.h>
INT4 lalDebugLevel = LALMSGLVL3;
int main( void )
{
......
......@@ -74,7 +74,6 @@ examinaton of the output files.
#endif
#endif
INT4 lalDebugLevel = 3;
int main( void )
{
......
......@@ -66,7 +66,6 @@ routines and checks to make sure the resulting series agree, printing the result
#define READFTSERIESTEST_TOL 1e6
#define READFTSERIESTEST_LEN 20
extern int lalDebugLevel;
int main( void )
......@@ -130,7 +129,6 @@ int main( void )
/* Data Test Variable */
UINT4 j;
lalDebugLevel = LALMSGLVL3;
fprintf(stderr,"Testing value of LALUnitTextSize ... ");
if ( (int)LALSupportUnitTextSize != (int)LALUnitTextSize )
......
......@@ -81,13 +81,12 @@ and inspecting the output.
/*-- Default debug level includes info messages (4), but not
memory checking (16), error messages (1), or warning messages (2) --*/
extern int lalDebugLevel;
/*===========================================================================*/
/*===========================================================================*/
int main( int argc, char *argv[] )
int main(void)
{
INT4 nfailures = 0;
static LALStatus status;
......@@ -99,16 +98,6 @@ int main( int argc, char *argv[] )
/*-- Default debug level includes info messages (4), but not
memory checking (16), error messages (1), or warning messages (2) --*/
lalDebugLevel = 4;
/*------ Parse input line. ------*/
if ( argc == 2 )
lalDebugLevel = atoi( argv[1] );
else if ( argc != 1 )
{
fprintf( stderr, "Usage: %s [ lalDebugLevel ]\n", argv[0] );
return 0; /* so that test script won't fail */
}
/*-------------------------------------------------------------------------*/
XLALPrintInfo("\n========== Initial setup \n");
......
......@@ -98,7 +98,6 @@ type-dependent format.
#include <lal/StreamInput.h>
/* Default parameter settings. */
extern int lalDebugLevel;
#define INFILE TEST_DATA_DIR "StreamInput.data"
/* Usage format string. */
......@@ -316,7 +315,6 @@ main(int argc, char **argv)
FILE *fpOut = NULL; /* output file pointer */
clock_t start = 0, stop = 0; /* data input timestamps */
lalDebugLevel = 0;
/* Parse argument list. arg stores the current position. */
arg = 1;
......@@ -336,7 +334,6 @@ main(int argc, char **argv)
else if ( !strcmp( argv[arg], "-d" ) ) {
if ( argc > arg + 1 ) {
arg++;
lalDebugLevel = atoi( argv[arg++] );
} else {
ERROR( STREAMINPUTTESTC_EARG, STREAMINPUTTESTC_MSGEARG, 0 );
LALPrintError( USAGE, *argv );
......
......@@ -87,7 +87,6 @@ data file formats.
#include <lal/StreamOutput.h>
/* Default parameter settings. */
extern int lalDebugLevel;
#define INFILE TEST_DATA_DIR "StreamSeriesInput.data"
/* Usage format string. */
......@@ -140,7 +139,6 @@ main(int argc, char **argv)
FILE *fpIn = NULL; /* input file pointer */
FILE *fpOut = NULL; /* output file pointer */
lalDebugLevel = 0;
/* Parse argument list. arg stores the current position. */
arg = 1;
......@@ -175,7 +173,6 @@ main(int argc, char **argv)
else if ( !strcmp( argv[arg], "-d" ) ) {
if ( argc > arg + 1 ) {
arg++;
lalDebugLevel = atoi( argv[arg++] );
} else {
ERROR( STREAMSERIESINPUTTESTC_EARG,
STREAMSERIESINPUTTESTC_MSGEARG, 0 );
......
......@@ -27,7 +27,6 @@
/* Default parameters. */
INT4 lalDebugLevel=3;
typedef struct
{
......@@ -90,12 +89,6 @@ main(int argc, char *argv[])
strcpy ( my_argv[i], argv_in[i] );
}
/* laldebug level always needs to be read first (before any lal-mallocs!) */
if ( XLALGetDebugLevel (my_argc, my_argv, 'v') != XLAL_SUCCESS ) {
XLALPrintError ("%s: XLALGetDebugLevel() failed with code %d\n", __func__, xlalErrno );
XLAL_ERROR ( XLAL_EFUNC );
}
/* ----- dump config-file content into config-file ----- */
FILE *fid;
if ( (fid = fopen ( CFG_FNAME, "wb" )) == NULL ) {
......
......@@ -53,9 +53,8 @@ This program does zero-th order tests for XLALTimeDelayFromEarthCenter().
#define DOUBLE_EPSILON 1.0536712127723507013e-08
extern int lalDebugLevel;
int main(int argc, char **argv)
int main(void)
{
LALFrDetector frdet1; /* Framelib detector info */
LALFrDetector frdet2;
......@@ -66,10 +65,6 @@ int main(int argc, char **argv)
REAL8 delay;
REAL8 difference;
lalDebugLevel = 0;
if (argc > 1)
lalDebugLevel = atoi(argv[1]);
/*
* Set up a source that will be used in both LALTimeDelay() and
......
......@@ -25,7 +25,6 @@
#include <lal/LALStdlib.h>
#include <lal/Date.h>
INT4 lalDebugLevel = 0;
static int test_random_doubles(unsigned int seed)
{
......@@ -55,10 +54,8 @@ static int test_random_doubles(unsigned int seed)
int main(int argc, char *argv[])
int main(void)
{
if (argc > 1)
lalDebugLevel = atoi(argv[1]);
/* 5 */
if(test_random_doubles(time(NULL)))
......
......@@ -26,7 +26,6 @@
#include <lal/Date.h>
#include <lal/AVFactories.h>
INT4 lalDebugLevel = 0;
int main(void)
{
......
......@@ -26,9 +26,8 @@
#include <lal/Date.h>
#include <lal/AVFactories.h>
INT4 lalDebugLevel = 0;
int main(int argc, char *argv[])
int main(void)
{
LIGOTimeGPS gpsTime = {0, 0};
LIGOTimeGPS tmpGps = {0, 0};
......@@ -37,9 +36,6 @@ int main(int argc, char *argv[])
char refstamp[128];
/* char infostr[256]; */