LAL  7.5.0.1-b72065a
UserInputParse.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2016 Karl Wette
3 // Copyright (C) 2004, 2015 Reinhard Prix
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with with program; see the file COPYING. If not, write to the
17 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301 USA
19 //
20 
21 #ifndef _USERINPUTPARSE_H /* Double-include protection. */
22 #define _USERINPUTPARSE_H
23 
24 #include <lal/LALDatatypes.h>
25 
26 /* C++ protection. */
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /**
32  * \defgroup UserInputParse_h Header UserInputParse.h
33  * \ingroup UserInput_h
34  * \author Reinhard Prix
35  * \brief Sub-module for parsing of input 'string values' as various 'types' (as defined in \ref UserInput_h).
36  *
37  */
38 
39 /** @{ */
40 
41 ///
42 /// Convert an unsigned long index \c i into a bit, i.e. \f$b = 2^i\f$
43 ///
44 #define XLAL_IDX2BIT(i) (1UL << ((unsigned long)(i)))
45 
46 ///
47 /// Convert an unsigned long \e single bit \c b into an index, i.e. \f$i = \log_2 b \f$
48 ///
49 #define XLAL_BIT2IDX(b) ( \
50  (((((unsigned long)(b)) & 0xAAAAAAAAAAAAAAAAUL) != 0)) | \
51  (((((unsigned long)(b)) & 0xCCCCCCCCCCCCCCCCUL) != 0) << 1UL) | \
52  (((((unsigned long)(b)) & 0xF0F0F0F0F0F0F0F0UL) != 0) << 2UL) | \
53  (((((unsigned long)(b)) & 0xFF00FF00FF00FF00UL) != 0) << 3UL) | \
54  (((((unsigned long)(b)) & 0xFFFF0000FFFF0000UL) != 0) << 4UL) | \
55  (((((unsigned long)(b)) & 0xFFFFFFFF00000000UL) != 0) << 5UL) \
56  )
57 
58 ///
59 /// A range of REAL8 values; first element is minimum, second element is maximum of range
60 ///
61 typedef REAL8 REAL8Range[2];
62 
63 ///
64 /// A range of INT4 values; first element is minimum, second element is maximum of range
65 ///
66 typedef INT4 INT4Range[2];
67 
68 ///
69 /// A range of GPS times; first element is minimum, second element is maximum of range
70 ///
72 
73 ///
74 /// Possible choices the user may select for an enumeration or bitflag
75 ///
76 #ifdef SWIG /* SWIG interface directives */
77 SWIGLAL(IMMUTABLE_MEMBERS(tagUserChoice, name));
78 #endif /* SWIG */
79 typedef struct tagUserChoice { int val; const char *name; } UserChoices[32];
80 
81 // ---------- Function prototypes ----------
82 int XLALParseStringValueAsINT4PlusFrac ( INT4 *valINT4, REAL8 *valFrac, const char *valString );
83 
84 // --------------- parsers for various USER_TYPE_<UTYPE>s ----------
85 int XLALParseStringValueAsINT8 ( INT8 *valINT8, const char *valString );
86 int XLALParseStringValueAsINT4 ( INT4 *valINT4, const char *valString );
87 int XLALParseStringValueAsUINT8 ( UINT8 *valUINT8, const char *valString );
88 int XLALParseStringValueAsUINT4 ( UINT4 *valUINT4, const char *valString );
89 int XLALParseStringValueAsREAL8 ( REAL8 *valREAL8, const char *valString );
90 int XLALParseStringValueAsREAL4 ( REAL4 *valREAL4, const char *valString );
91 int XLALParseStringValueAsBOOLEAN ( BOOLEAN *valBOOLEAN, const char *valString );
92 int XLALParseStringValueAsGPS ( LIGOTimeGPS *gps, const char *valString );
93 int XLALParseStringValueAsEPOCH ( LIGOTimeGPS *gps, const char *valString );
94 int XLALParseStringValueAsRAJ ( REAL8 *valRAJ, const char *valString );
95 int XLALParseStringValueAsDECJ ( REAL8 *valDECJ, const char *valString );
96 
97 #ifdef SWIG /* SWIG interface directives */
98 SWIGLAL(OUTPUT_ARRAY_1D(INT4, int4Range[2]));
99 SWIGLAL(OUTPUT_ARRAY_1D(REAL8, real8Range[2]));
100 SWIGLAL(OUTPUT_ARRAY_1D(LIGOTimeGPS, gpsRange[2]));
101 SWIGLAL(OUTPUT_ARRAY_1D(REAL8, rajRange[2]));
102 SWIGLAL(OUTPUT_ARRAY_1D(REAL8, decjRange[2]));
103 #endif /* SWIG */
104 
105 int XLALParseStringValueAsINT4Range ( INT4Range int4Range, const char *valString );
106 int XLALParseStringValueAsREAL8Range ( REAL8Range real8Range, const char *valString );
107 int XLALParseStringValueAsEPOCHRange ( LIGOTimeGPSRange gpsRange, const char *valString );
108 int XLALParseStringValueAsRAJRange ( REAL8Range rajRange, const char *valString );
109 int XLALParseStringValueAsDECJRange ( REAL8Range decjRange, const char *valString );
110 
111 int XLALParseStringValueAsUserEnum ( int *valEnum, const UserChoices *enumData, const char *valString );
112 int XLALParseStringValueAsUserFlag ( int *valFlag, const UserChoices *flagData, const char *valString );
113 
114 int XLALParseStringValueAsSTRING ( CHAR **valOut, const char *valString );
115 int XLALParseStringValueAsSTRINGVector ( LALStringVector **valSTRINGVector, const CHAR *valString );
116 
117 // use macro templating to define parsers for numerical <CTYPE>vectors
118 #define DECL_XLALParseStringValueAsVector(CTYPE) \
119  int XLALParseStringValueAs ##CTYPE## Vector ( CTYPE ## Vector **vect, const CHAR *valString )
120 
124 
125 /** @} */
126 
127 /* C++ protection. */
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* Double-include protection. */
const char *const name
type name
Definition: UserInput.c:193
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
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.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
LIGOTimeGPS LIGOTimeGPSRange[2]
A range of GPS times; first element is minimum, second element is maximum of range.
int XLALParseStringValueAsGPS(LIGOTimeGPS *gps, const char *valString)
Parse a string representing a GPS time into LIGOTimeGPS, without loss of (ns) accuracy.
int XLALParseStringValueAsRAJRange(REAL8Range rajRange, const char *valString)
Parse a string representing a range of RAJ values into a REAL8Range.
int XLALParseStringValueAsUINT8(UINT8 *valUINT8, const char *valString)
Parse a string into an UINT8 This ignores initial whitespace, but throws an error on any non-converte...
int XLALParseStringValueAsUINT4(UINT4 *valUINT4, const char *valString)
Parse a string into an UINT4 This ignores initial whitespace, but throws an error on any non-converte...
int XLALParseStringValueAsEPOCHRange(LIGOTimeGPSRange gpsRange, const char *valString)
Parse a string representing a range of LIGOTimeGPS values into a LIGOTimeGPSRange.
int XLALParseStringValueAsINT4PlusFrac(INT4 *valINT4, REAL8 *valFrac, const char *valString)
Parse a string containing a floating-point number into integer and fractional part,...
REAL8 REAL8Range[2]
A range of REAL8 values; first element is minimum, second element is maximum of range.
int XLALParseStringValueAsEPOCH(LIGOTimeGPS *gps, const char *valString)
Parse a string representing an 'epoch' into an LIGOTimeGPS, allowing both GPS and MJD(TT) inputs,...
int XLALParseStringValueAsINT4(INT4 *valINT4, const char *valString)
Parse a string into an INT4 This ignores initial whitespace, but throws an error on any non-converted...
#define DECL_XLALParseStringValueAsVector(CTYPE)
int XLALParseStringValueAsREAL4(REAL4 *valREAL4, const char *valString)
Parse a string into a REAL4.
int XLALParseStringValueAsREAL8Range(REAL8Range real8Range, const char *valString)
Parse a string representing a range of REAL8 values into a REAL8Range.
int XLALParseStringValueAsINT8(INT8 *valINT8, const char *valString)
Parse a string into an INT8 This ignores initial whitespace, but throws an error on any non-converted...
int XLALParseStringValueAsDECJ(REAL8 *valDECJ, const char *valString)
Parse a string representing an 'equatorial latitude' (aka declination or DEC) into REAL8 radians,...
INT4 INT4Range[2]
A range of INT4 values; first element is minimum, second element is maximum of range.
int XLALParseStringValueAsBOOLEAN(BOOLEAN *valBOOLEAN, const char *valString)
Parse a string into a BOOLEAN Allowed string-values are (case-insensitive): {"yes",...
int XLALParseStringValueAsSTRINGVector(LALStringVector **valSTRINGVector, const CHAR *valString)
Parse a string containing a list of comma-separated values (CSV) into a StringVector.
int XLALParseStringValueAsDECJRange(REAL8Range decjRange, const char *valString)
Parse a string representing a range of DECJ values into a REAL8Range.
int XLALParseStringValueAsINT4Range(INT4Range int4Range, const char *valString)
Parse a string representing a range of INT4 values into a INT4Range.
int XLALParseStringValueAsRAJ(REAL8 *valRAJ, const char *valString)
Parse a string representing an 'equatorial longitude' (aka right ascension or RA) into REAL8 radians,...
int XLALParseStringValueAsSTRING(CHAR **valOut, const char *valString)
Duplicate string 'in', removing surrounding quotes " or \' if present.
int XLALParseStringValueAsREAL8(REAL8 *valREAL8, const char *valString)
Parse a string into a REAL8 This ignores initial whitespace, but throws an error on any non-converted...
int XLALParseStringValueAsUserEnum(int *valEnum, const UserChoices *enumData, const char *valString)
Parse a string representing a user selection of an enumeration value.
int XLALParseStringValueAsUserFlag(int *valFlag, const UserChoices *flagData, const char *valString)
Parse a string representing a user selection of a set of bitflags.
Vector of type CHAR*, ie 'strings', see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:82
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
Possible choices the user may select for an enumeration or bitflag.
const char * name