23 #include <lal/AVFactories.h>
24 #include <lal/ConfigFile.h>
25 #include <lal/StringVector.h>
30 int main (
int argc,
char *argv[])
46 const char *cfgname = TEST_DATA_DIR
"ConfigFileSample.cfg";
54 XLAL_CHECK ( strcmp ( sections->
data[0],
"default" ) == 0,
XLAL_EFAILED,
"%s: found section '%s' instead of 'default'\n", cfgname, sections->
data[0] );
72 REAL8 longHMS, longRad;
85 XLAL_CHECK ( unread == NULL,
XLAL_EFAILED,
"Some entries in config-file '%s' have not been parsed!\n", cfgname );
97 const char *string1_ref =
"some text. You can also use line-continuation";
98 XLAL_CHECK ( strcmp(string1, string1_ref) == 0,
XLAL_EFAILED,
"%s: got string1 = '%s', expected '%s'\n", cfgname, string1, string1_ref );
100 const char *string2_ref =
"this is also possible, and # here does nothing; and neither does semi-colon ";
101 XLAL_CHECK ( strcmp ( string2, string2_ref ) == 0,
XLAL_EFAILED,
"%s: got string2 = '%s', expected '%s'\n", cfgname, string2, string2_ref );
103 const char *string3_ref =
"how about #quotes AND line-continuation?";
104 XLAL_CHECK ( strcmp ( string3, string3_ref ) == 0,
XLAL_EFAILED,
"%s: got string3 = '%s', expected '%s'\n", cfgname, string3, string3_ref );
111 REAL8 diff, tol = 3e-15;
112 XLAL_CHECK ( (diff = fabs(longHMS - longRad)) < tol,
XLAL_EFAILED,
"longitude(HMS) = %.16g differs from longitude(rad) = %.16g by %g > %g\n", longHMS, longRad, diff, tol );
113 XLAL_CHECK ( (diff = fabs(latDMS - latRad)) < tol,
XLAL_EFAILED,
"latitude(HMS) = %.16g differs from latitude(rad) = %.16g by %g > %g\n", latDMS, latRad, diff, tol );
120 string1 = string2 = string3 = NULL;
124 cfgname = TEST_DATA_DIR
"ConfigFileSample2.cfg";
130 XLAL_CHECK ( strcmp ( sections->
data[0],
"section1" ) == 0,
XLAL_EFAILED,
"%s: 1st section found is '%s' instead of 'section1'\n", cfgname, sections->
data[0] );
131 XLAL_CHECK ( strcmp ( sections->
data[1],
"section2" ) == 0,
XLAL_EFAILED,
"%s: 2nd section found is '%s' instead of 'section2'\n", cfgname, sections->
data[1] );
132 XLAL_CHECK ( strcmp ( sections->
data[2],
"section3" ) == 0,
XLAL_EFAILED,
"%s: 3rd section found is '%s' instead of 'section3'\n", cfgname, sections->
data[2] );
156 XLAL_CHECK ( unread == NULL,
XLAL_EFAILED,
"Some entries in config-file '%s' have not been parsed!\n", cfgname );
168 XLAL_CHECK ( strcmp(string1, string1_ref) == 0,
XLAL_EFAILED,
"%s: got string1 = '%s', expected '%s'\n", cfgname, string1, string1_ref );
170 XLAL_CHECK ( strcmp ( string2, string2_ref ) == 0,
XLAL_EFAILED,
"%s: got string2 = '%s', expected '%s'\n", cfgname, string2, string2_ref );
172 XLAL_CHECK ( strcmp ( string3, string3_ref ) == 0,
XLAL_EFAILED,
"%s: got string3 = '%s', expected '%s'\n", cfgname, string3, string3_ref );
180 cfgname = TEST_DATA_DIR
"ConfigFileSample3.cfg.gz";
int XLALReadConfigSTRINGVariable(CHAR **varp, LALParsedDataFile *cfgdata, const CHAR *secName, const CHAR *varName, BOOLEAN *wasRead)
String parser for config-file: can read config-variables of the form VARIABLE [=:] VALUE.
int main(int argc, char *argv[])
void LALCheckMemoryLeaks(void)
UINT4Vector * XLALConfigFileGetUnreadEntries(const LALParsedDataFile *cfgdata)
Return a list of unread config-file entries, NULL if none found (without error).
int XLALParseDataFile(LALParsedDataFile **cfgdata, const CHAR *path)
Parse an ASCII data-file into a pre-cleaned array of lines.
int XLALConfigSectionExists(const LALParsedDataFile *cfgdata, const CHAR *secName)
Function to determine whether a given section secName exists in the parsed config-file contents cfgda...
LALStringVector * XLALListConfigFileSections(const LALParsedDataFile *cfgdata)
Function to find all sections in given config-file contents cfgdata.
void XLALDestroyParsedDataFile(LALParsedDataFile *cfgdata)
Free memory associated with a LALParsedDataFile structure.
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
double REAL8
Double precision real floating-point number (8 bytes).
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
int32_t INT4
Four-byte signed integer.
void XLALDestroyStringVector(LALStringVector *vect)
XLAL-interface: Free a string-vector ;)
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFAILED
Generic failure.
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
Compares two GPS times.
This structure is returned by XLALParseDataFile() and holds the contents of an ASCII data-file in a p...
TokenList * lines
list of pre-parsed data-file lines
Vector of type CHAR*, ie 'strings', see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
CHAR ** data
Pointer to the data array.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
INT4 gpsNanoSeconds
Residual nanoseconds.
CHAR ** tokens
A list of pointers to the individual tokens; the elements tokens[0..nTokens-1] point to tokens,...
UINT4 nTokens
The number of tokens in the list.
Vector of type UINT4, see DATATYPE-Vector types for more details.