Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ReadTEMPOFileTest.c
Go to the documentation of this file.
1/* Code to check that the function to read TEMPO-style par files return the expected values
2 *
3 * Matthew Pitkin 21/01/2014
4*/
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <math.h>
9
10#include <lal/LALStdlib.h>
11#include <lal/LALConstants.h>
12#include <lal/ReadPulsarParFile.h>
13#include <lal/LALString.h>
14
15#define PARFILE "test.par" /* define par file name */
16
17typedef struct tagParamData {
18 const CHAR *name; /* parameter name as given by the conventions (see param variable in TEMPOs mxprt.f file */
19 const CHAR *val; /* parameter value for output to par file */
20 const CHAR *valcheck; /* if parameter will be converted to SI units, this is the conversion (other wise
21 * set to the same value as val) given to 5 d.p. */
22 const CHAR *sigma; /* standard deviation on the parameter as read from the .par file */
23 const CHAR *sigmacheck; /* check of read in sigma converted to SI units */
24 const CHAR *fitFlag; /* add a TEMPO-style fitting flag to some parameters */
25} ParamData;
26
27#define NUMPARS 102
28
29/* setup a collection of allowed .par file parameters */
31 /* frequency parameters */
32 { "F0", "123.00000", "123.00000", "1.00000e-08", "1.00000e-08", "1" },
33 { "F1", "-1.23000e-10", "-1.23000e-10", "1.00000e-12", "1.00000e-12", "1" },
34 { "F2", "1.23000e-15", "1.23000e-15", "1.00000e-17", "1.00000e-17", "1" },
35 { "F3", "-1.23000e-20", "-1.23000e-20", "1.00000e-22", "1.00000e-22", "1" },
36 { "F4", "1.23000e-25", "1.23000e-25", "1.00000e-27", "1.00000e-27", "1" },
37 { "F5", "-1.23000e-30", "-1.23000e-30", "1.00000e-32", "1.00000e-32", " " },
38 { "F6", "1.23000e-35", "1.23000e-35", "1.00000e-37", "1.00000e-37", "1" },
39 { "F7", "-1.23000e-40", "-1.23000e-40", "1.00000e-42", "1.00000e-42", "1" },
40 { "F8", "1.23000e-45", "1.23000e-45", "1.00000e-47", "1.00000e-47", "1" },
41 { "F9", "-1.23000e-50", "-1.23000e-50", "1.00000e-52", "1.00000e-52", " " },
42 { "F10", "1.23000e-67", "1.23000e-67", "1.00000e-68", "1.00000e-68", " " },
43 { "PEPOCH", "54321.0", "870652748.81600", NULL, NULL, " " },
44 /* name parameters */
45 { "PSRJ", "J0000+0000", "J0000+0000", NULL, NULL, " " },
46 { "PSRB", "B0000+0000", "B0000+0000", NULL, NULL, " " },
47 { "PSR", "0000+0000", "0000+0000", NULL, NULL, " " },
48 { "NAME", "J0000+0000", "J0000+0000", NULL, NULL, " " },
49 /* position parameters */
50 { "RAJ", "12:34:56.7", "3.29407", "1.23", "8.94481e-05", "1" },
51 { "ra", "12:34:56.7", "3.29407", "1.23", "8.94481e-05", " " }, /* use lower case input name*/
52 { "ELONG", "188.73630842", "3.29407", "1.0", "0.01745", " " },
53 { "LAMBDA", "188.73630842", "3.29407", "1.0", "0.01745", " " },
54 { "DECJ", "-12:34:56.7", "-0.21960", "1.23", "5.96321e-06", " " },
55 { "DEC", "-12:34:56.7", "-0.21960", "1.23", "5.96321e-06", " " },
56 { "ELAT", "-12.58215318", "-0.21960", "1.0", "0.01745", " " },
57 { "BETA", "-12.58215318", "-0.21960", "1.0", "0.01745", " " },
58 { "POSEPOCH", "54321.0", "870652748.81600", NULL, NULL, " " },
59 { "PMRA", "12.345", "1.89654e-15", "1.23", "1.88963e-16", " " },
60 { "PMELONG", "12.345", "1.89654e-15", "1.23", "1.88963e-16", " " },
61 { "PMLAMBDA", "12.345", "1.89654e-15", "1.23", "1.88963e-16", " " },
62 { "EPHEM", "DE405", "DE405", NULL, NULL, " " },
63 { "PMDEC", "-12.345", "-1.89654e-15", "1.23", "1.88963e-16", "1" },
64 { "PMELAT", "-12.345", "-1.89654e-15", "1.23", "1.88963e-16", "1" },
65 { "PMBETA", "-12.345", "-1.89654e-15", "1.23", "1.88963e-16", "1" },
66 { "DIST", "123.00000", "3.79538e+21", "12.30000", "3.79538e+20", " " },
67 /* glitch parameters */
68 { "GLEP_1", "54321.0", "870652748.81600", "0.00123", "106.27200", " " },
69 { "GLEP_2", "54322.0", "870739148.81600", "0.00123", "106.27200", " " },
70 { "GLPH_1", "0.43453", "0.43453", "0.00453", "0.00453", "1" },
71 { "GLPH_2", "0.93453", "0.93453", "0.01453", "0.01453", "1" },
72 { "GLF0_1", "2.50000e-8", "2.50000e-08", "4.50000e-09", "4.50000e-09", " " },
73 { "GLF0_2", "3.50000e-8", "3.50000e-08", "2.50000e-09", "2.50000e-09", " " },
74 { "GLF0D_1", "5.50000e-6", "5.50000e-06", "7.50000e-09", "7.50000e-09", " " },
75 { "GLF0D_2", "6.50000e-6", "6.50000e-06", "9.50000e-09", "9.50000e-09", " " },
76 { "GLTD_1", "234.500000", "20260800.00000", "2.00000", "172800.00000", " " },
77 { "GLTD_2", "23.450000", "2026080.00000", "1.00000", "86400.00000", " " },
78 /* binary parameters */
79 { "BINARY", "BT", "BT", NULL, NULL, " " },
80 { "OM", "123.45", "2.15461", "1.23", "0.02147", " " },
81 { "A1", "12.34500", "12.34500", "1.23000e-04", "1.23000e-04", "1" },
82 { "ECC", "1.23400e-05", "1.23400e-05", "1.23400e-08", "1.23400e-08", " " },
83 { "PB", "1.23", "106272.00000", "0.00123", "106.27200", " " },
84 { "T0", "54321.0", "870652748.81600", "0.00123", "106.27200", " " },
85 { "TASC", "54321.0", "870652748.81600", "0.00123", "106.27200", " " },
86 { "EPS1", "1.23400e-05", "1.23400e-05", "1.23400e-08", "1.23400e-08", "1" },
87 { "EPS2", "1.23400e-05", "1.23400e-05", "1.23400e-08", "1.23400e-08", "1" },
88 { "FB0", "1.23400e-05", "1.23400e-05", "1.23400e-14", "1.23400e-14", "1" },
89 { "FB2", "1.23400e-09", "1.23400e-09", "1.23400e-18", "1.23400e-18", " " },
90 { "FB1", "1.23400e-09", "1.23400e-09", "1.23400e-18", "1.23400e-18", "1" },
91 { "EDOT", "1.23400e-05", "1.23400e-17", "1.23400e-18", "1.23400e-18", " " },
92 /* FITWAVES parameters */
93 { "WAVE_OM", "0.30000", "0.30000", NULL, NULL, " " },
94 { "WAVEEPOCH", "54321.0", "870652748.81600", NULL, NULL, " " },
95 { "WAVE1", "0.21000", "0.21000", "0.56000", "0.56000", " " },
96 { "WAVE2", "0.01000", "0.01000", "-0.02000", "-0.02000", " " },
97 /* GW parameters */
98 { "H0", "1.23000e-22", "1.23000e-22", "1.23000E-23", "1.23000e-23", " " }, /* input exponent as E */
99 { "COSIOTA", "-0.12300", "-0.12300", "0.00123", "0.00123", " " },
100 { "PHI0", "1.23000", "1.23000", "0.12300", "0.12300", " " },
101 { "PSI", "-0.12300", "-0.12300", "0.01230", "0.01230", " " },
102 { "APLUS", "1.23000e-22", "1.23000e-22", "1.23000D-23", "1.23000e-23", " " }, /* input exponent as D */
103 { "ACROSS", "1.23000e-22", "1.23000e-22", "1.23000D-23", "1.23000e-23", " " }, /* input exponent as D */
104 /* waveform parameters */
105 { "C21", "7.83000e-22", "7.83000e-22", "4.65000E-23", "4.65000e-23", " " },
106 { "C22", "3.65000E-23", "3.65000e-23", "6.54000e-25", "6.54000e-25", " " },
107 { "PHI21", "0.3", "0.30000", "0.12", "0.12000", " " },
108 { "PHI22", "2.37281", "2.37281", "0.0011", "0.00110", " " },
109 /* non-GR parameters */
110 { "HPLUS", "5.40000e-24", "5.40000e-24", "1.26000e-26", "1.26000e-26", " " },
111 { "HPLUS_F", "6.20000e-24", "6.20000e-24", "5.28000e-26", "5.28000e-26", " " },
112 { "HCROSS", "7.40000e-24", "7.40000e-24", "1.26000e-26", "1.26000e-26", " " },
113 { "HCROSS_F", "8.20000e-24", "8.20000e-24", "5.28000e-26", "5.28000e-26", " " },
114 { "HVECTORX", "9.40000e-24", "9.40000e-24", "1.26000e-26", "1.26000e-26", " " },
115 { "HVECTORX_F", "1.20000e-24", "1.20000e-24", "5.28000e-26", "5.28000e-26", " " },
116 { "HVECTORY", "2.40000e-24", "2.40000e-24", "1.26000e-26", "1.26000e-26", " " },
117 { "HVECTORY_F", "3.20000E-24", "3.20000e-24", "5.28000e-26", "5.28000e-26", " " },
118 { "HSCALARL", "4.40000D-24", "4.40000e-24", "1.26000e-26", "1.26000e-26", " " },
119 { "HSCALARL_F", "5.20000e-24", "5.20000e-24", "5.28000e-26", "5.28000e-26", " " },
120 { "HSCALARB", "6.40000E-24", "6.40000e-24", "1.26000e-26", "1.26000e-26", " " },
121 { "HSCALARB_F", "7.20000E-24", "7.20000e-24", "5.28000e-26", "5.28000e-26", " " },
122 { "PSITENSOR", "1.46252", "1.46252", "0.91", "0.91000", " " },
123 { "PSITENSOR_F", "0.3", "0.30000", "0.02", "0.02000", " " },
124 { "PHI0TENSOR", "2.65", "2.65000", "0.03", "0.03000", " " },
125 { "PHI0TENSOR_F", "2.1201", "2.12010", "0.04", "0.04000", " " },
126 { "PSIVECTOR", "0.00230", "0.00230", "0.05", "0.05000", " " },
127 { "PSIVECTOR_F", "0.786", "0.78600", "0.06", "0.06000", " " },
128 { "PHI0VECTOR", "0.10230", "0.10230", "0.07", "0.07000", " " },
129 { "PHI0VECTOR_F", "0.116", "0.11600", "0.08", "0.08000", " " },
130 { "PSISCALAR", "1.00430", "1.00430", "0.09", "0.09000", " " },
131 { "PSISCALAR_F", "0.286", "0.28600", "0.10", "0.10000", " " },
132 { "PHI0SCALAR", "2.10230", "2.10230", "0.11", "0.11000", " " },
133 { "PHI0SCALAR_F", "0.476", "0.47600", "0.12", "0.12000", " " },
134 /* transient signal parameters */
135 { "TRANSIENTWINDOWTYPE", "RECT", "RECT", NULL, NULL, " " },
136 { "TRANSIENTSTARTTIME", "54321.0", "870652748.81600", NULL, NULL, " " },
137 { "TRANSIENTTAU", "1.23", "106272.00000", NULL, NULL, " " },
138 /* TEMPO parameters */
139 { "UNITS", "TDB", "TDB", NULL, NULL, " " },
140 { "T2CMETHOD", "TEMPO", "TEMPO", NULL, NULL, " " },
141 { "TIMEEPH", "FB90", "FB90", NULL, NULL, " " },
142 { "CLK", "TT(TAI)", "TT(TAI)", NULL, NULL, " " },
143 { "TRES", "532.1", "0.00053", NULL, NULL, " " },
144};
145
146
147int main( void )
148{
149 INT4 i = 0;
150 PulsarParameters *pars = NULL;
151
152 /* output par file */
153 FILE *fp = NULL;
154 if ( ( fp = fopen( PARFILE, "w" ) ) == NULL ) {
155 XLAL_ERROR( XLAL_EIO, "Error... problem writing parfile!\n" );
156 }
157
158 for ( i = 0; i < NUMPARS; i++ ) {
159 if ( p[i].sigma != NULL ) { /* write out value and error */
160 fprintf( fp, "%s\t%s\t%s\t%s\n", p[i].name, p[i].val, p[i].fitFlag, p[i].sigma );
161 } else { /* just write out value */
162 fprintf( fp, "%s\t%s\n", p[i].name, p[i].val );
163 }
164 }
165
166 fclose( fp );
167
168 /* read in par file */
170
171 /* check read-in parameters against originals */
172 for ( i = 0; i < NUMPARS; i++ ) {
173 CHAR outval[256];
174 CHAR outsigma[256];
175 CHAR outfitflag[256];
176
177 /* see if the parameter can be split into an alphabet and numerical value (as is the case
178 * for e.g. FB, which is held as a vector */
179 CHAR *namecopy = NULL, *token = NULL;
180 namecopy = XLALStringDuplicate( p[i].name );
181 /* get part of the name before the numerical/underscore delimiter */
182 if ( strchr( p[i].name, '_' ) && strncmp( p[i].name, "WAVE", 4 ) ) { /* delimiter by underscores and not a FITWAVES parameter */
183 token = strtok( namecopy, "_" );
184 } else {
185 token = strtok( namecopy, "0123456789" );
186 }
187
188 /* value is a FITWAVES vector */
189 if ( !strncmp( p[i].name, "WAVE", 4 ) && strlen( p[i].name ) < 7 && PulsarCheckParam( pars, "WAVESIN" ) && PulsarCheckParam( pars, "WAVECOS" ) ) {
190 /* in the ParamDict array the "val" item contains WAVESIN and the "sigma" entry contains "WAVECOS" */
191 UINT4 num = 0;
192 CHAR sinname[256], cosname[256];
193
194 if ( sscanf( p[i].name + strlen( "WAVE" ), "%d", &num ) != 1 ) {
195 XLAL_ERROR( XLAL_EINVAL, "Error...problem reading %s number from par file.\n", p[i].name );
196 }
197
198 sprintf( sinname, "WAVESIN%d", ( INT4 )num );
199 sprintf( cosname, "WAVECOS%d", ( INT4 )num );
200
201 /* get WAVESIN value and convert to string */
202 if ( !strchr( p[i].valcheck, 'e' ) ) { /* number doesn't contain an exponent */
203 sprintf( outval, "%.5lf", PulsarGetREAL8VectorParamIndividual( pars, sinname ) );
204 } else { /* number does contain an exponent */
205 sprintf( outval, "%.5le", PulsarGetREAL8VectorParamIndividual( pars, sinname ) );
206 }
207
208 /* get WAVECOS value and convert to string */
209 if ( !strchr( p[i].valcheck, 'e' ) ) { /* number doesn't contain an exponent */
210 sprintf( outsigma, "%.5lf", PulsarGetREAL8VectorParamIndividual( pars, cosname ) );
211 } else { /* number does contain an exponent */
212 sprintf( outsigma, "%.5le", PulsarGetREAL8VectorParamIndividual( pars, cosname ) );
213 }
214
215 sprintf( outfitflag, " " );
216 }
217 /* value is a vector */
218 else if ( PulsarCheckParam( pars, token ) && PulsarGetParamType( pars, token ) == PULSARTYPE_REAL8Vector_t ) {
219 /* get value and convert to string */
220 if ( !strchr( p[i].valcheck, 'e' ) ) { /* number doesn't contain an exponent */
221 sprintf( outval, "%.5lf", PulsarGetREAL8VectorParamIndividual( pars, p[i].name ) );
222 } else { /* number does contain an exponent */
223 sprintf( outval, "%.5le", PulsarGetREAL8VectorParamIndividual( pars, p[i].name ) );
224 }
225
226 if ( p[i].sigmacheck != NULL ) {
227 /* get error and convert to string */
228 if ( !strchr( p[i].sigmacheck, 'e' ) ) { /* number doesn't contain an exponent */
229 sprintf( outsigma, "%.5lf", PulsarGetREAL8VectorParamErrIndividual( pars, p[i].name ) );
230 } else {
231 sprintf( outsigma, "%.5le", PulsarGetREAL8VectorParamErrIndividual( pars, p[i].name ) );
232 }
233
234 const UINT4 *fitFlag = PulsarGetParamFitFlag( pars, token );
235
236 if ( fitFlag[atoi( p[i].name + strlen( token ) )] == 1 ) {
237 sprintf( outfitflag, "1" );
238 } else if ( fitFlag[atoi( p[i].name + strlen( token ) )] == 0 ) {
239 sprintf( outfitflag, " " );
240 } else {
241 XLAL_ERROR( XLAL_EFAILED, "Error... fit flag incorrect for %s.\n", p[i].name );
242 }
243 }
244 }
245 /* value is a double */
246 else if ( PulsarGetParamType( pars, p[i].name ) == PULSARTYPE_REAL8_t ) {
247 /* get value and convert to string */
248 if ( !strchr( p[i].valcheck, 'e' ) ) { /* number doesn't contain an exponent */
249 sprintf( outval, "%.5lf", PulsarGetREAL8Param( pars, p[i].name ) );
250 } else { /* number does contain an exponent */
251 sprintf( outval, "%.5le", PulsarGetREAL8Param( pars, p[i].name ) );
252 }
253
254 if ( p[i].sigmacheck != NULL ) {
255 /* get error and convert to string */
256 if ( !strchr( p[i].sigmacheck, 'e' ) ) { /* number doesn't contain an exponent */
257 sprintf( outsigma, "%.5lf", PulsarGetREAL8ParamErr( pars, p[i].name ) );
258 } else {
259 sprintf( outsigma, "%.5le", PulsarGetREAL8ParamErr( pars, p[i].name ) );
260 }
261
262 const UINT4 *fitFlag = PulsarGetParamFitFlag( pars, p[i].name );
263
264 if ( fitFlag[0] == 1 ) {
265 sprintf( outfitflag, "1" );
266 } else if ( fitFlag[0] == 0 ) {
267 sprintf( outfitflag, " " );
268 } else {
269 XLAL_ERROR( XLAL_EFAILED, "Error... fit flag incorrect for %s.\n", p[i].name );
270 }
271 }
272 }
273 /* value is a string */
274 else if ( PulsarGetParamType( pars, p[i].name ) == PULSARTYPE_string_t ) {
275 const CHAR *out = PulsarGetStringParam( pars, p[i].name );
276 sprintf( outval, "%s", out );
277 }
278
279 /* compare returned value with input value */
280 if ( strcmp( outval, p[i].valcheck ) != 0 ) {
281 XLAL_ERROR( XLAL_EFAILED, "Error... parameter %s does not match input (%s cf. %s)!\n", p[i].name, outval,
282 p[i].valcheck );
283 }
284
285 if ( p[i].sigma != NULL ) {
286 /* compare returned value with input value */
287 if ( strcmp( outsigma, p[i].sigmacheck ) != 0 ) {
288 XLAL_ERROR( XLAL_EFAILED, "Error... parameter sigma %s does not match input (%s cf. %s)!\n", p[i].name,
289 outsigma, p[i].sigmacheck );
290 }
291
292 if ( strcmp( outfitflag, p[i].fitFlag ) != 0 ) {
293 XLAL_ERROR( XLAL_EFAILED, "Error... parameter %s fit flag does not match input!\n", p[i].name );
294 }
295 }
296
297 XLALFree( namecopy );
298 }
299
300 /* remove par file */
301 if ( remove( PARFILE ) != 0 ) {
302 XLAL_ERROR( XLAL_EIO, "Error... problem removing parfile!\n" );
303 }
304
305 fprintf( stderr, "Successfully read in .par file values!\n" );
306
307 PulsarFreeParams( pars );
308
310
311 return XLAL_SUCCESS;
312}
void LALCheckMemoryLeaks(void)
REAL8 PulsarGetREAL8VectorParamErrIndividual(const PulsarParameters *pars, const CHAR *name)
Return an individual REAL8 value from a REAL8Vector parameter.
REAL8 PulsarGetREAL8ParamErr(const PulsarParameters *pars, const CHAR *name)
Return a REAL8 parameter error value.
int PulsarCheckParam(const PulsarParameters *pars, const CHAR *name)
Check for the existence of the parameter name in the PulsarParameters structure.
PulsarParameters * XLALReadTEMPOParFile(const CHAR *pulsarAndPath)
Read in the parameters from a TEMPO(2) parameter file into a PulsarParameters structure.
REAL8 PulsarGetREAL8Param(const PulsarParameters *pars, const CHAR *name)
Return a REAL8 parameter.
const CHAR * PulsarGetStringParam(const PulsarParameters *pars, const CHAR *name)
Return a string parameter.
void PulsarFreeParams(PulsarParameters *pars)
Function to free memory from pulsar parameters.
REAL8 PulsarGetREAL8VectorParamIndividual(const PulsarParameters *pars, const CHAR *name)
Return an individual REAL8 value from a REAL8Vector parameter.
const UINT4 * PulsarGetParamFitFlag(const PulsarParameters *pars, const CHAR *name)
Get the fit flag array for a given parameter from the PulsarParameters structure.
PulsarParamType PulsarGetParamType(const PulsarParameters *pars, const char *name)
Get the required parameter's type.
@ PULSARTYPE_REAL8Vector_t
@ PULSARTYPE_string_t
@ PULSARTYPE_REAL8_t
int main(void)
#define NUMPARS
#define PARFILE
ParamData p[NUMPARS]
const char * name
Definition: SearchTiming.c:93
#define fprintf
char CHAR
uint32_t UINT4
int32_t INT4
void XLALFree(void *p)
char char * XLALStringDuplicate(const char *s)
#define XLAL_ERROR(...)
XLAL_SUCCESS
XLAL_EIO
XLAL_EINVAL
XLAL_EFAILED
out
const CHAR * sigmacheck
const CHAR * sigma
const CHAR * val
const CHAR * name
const CHAR * fitFlag
const CHAR * valcheck
The PulsarParameters structure to contain a set of pulsar parameters.