10#include <lal/LALStdlib.h>
11#include <lal/LALConstants.h>
12#include <lal/ReadPulsarParFile.h>
13#include <lal/LALString.h>
15#define PARFILE "test.par"
17typedef struct tagParamData {
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,
" " },
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,
" " },
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",
" " },
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",
" " },
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",
" " },
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",
" " },
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",
" " },
98 {
"H0",
"1.23000e-22",
"1.23000e-22",
"1.23000E-23",
"1.23000e-23",
" " },
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",
" " },
103 {
"ACROSS",
"1.23000e-22",
"1.23000e-22",
"1.23000D-23",
"1.23000e-23",
" " },
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",
" " },
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",
" " },
135 {
"TRANSIENTWINDOWTYPE",
"RECT",
"RECT", NULL, NULL,
" " },
136 {
"TRANSIENTSTARTTIME",
"54321.0",
"870652748.81600", NULL, NULL,
" " },
137 {
"TRANSIENTTAU",
"1.23",
"106272.00000", NULL, NULL,
" " },
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,
" " },
154 if ( (
fp = fopen(
PARFILE,
"w" ) ) == NULL ) {
159 if (
p[
i].sigma != NULL ) {
175 CHAR outfitflag[256];
179 CHAR *namecopy = NULL, *token = NULL;
182 if ( strchr(
p[
i].
name,
'_' ) && strncmp(
p[
i].
name,
"WAVE", 4 ) ) {
183 token = strtok( namecopy,
"_" );
185 token = strtok( namecopy,
"0123456789" );
192 CHAR sinname[256], cosname[256];
194 if ( sscanf(
p[
i].
name + strlen(
"WAVE" ),
"%d", &num ) != 1 ) {
198 sprintf( sinname,
"WAVESIN%d", (
INT4 )num );
199 sprintf( cosname,
"WAVECOS%d", (
INT4 )num );
202 if ( !strchr(
p[
i].valcheck,
'e' ) ) {
209 if ( !strchr(
p[
i].valcheck,
'e' ) ) {
215 sprintf( outfitflag,
" " );
220 if ( !strchr(
p[
i].valcheck,
'e' ) ) {
226 if (
p[
i].sigmacheck != NULL ) {
228 if ( !strchr(
p[
i].sigmacheck,
'e' ) ) {
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,
" " );
248 if ( !strchr(
p[
i].valcheck,
'e' ) ) {
254 if (
p[
i].sigmacheck != NULL ) {
256 if ( !strchr(
p[
i].sigmacheck,
'e' ) ) {
264 if ( fitFlag[0] == 1 ) {
265 sprintf( outfitflag,
"1" );
266 }
else if ( fitFlag[0] == 0 ) {
267 sprintf( outfitflag,
" " );
276 sprintf( outval,
"%s",
out );
280 if ( strcmp( outval,
p[
i].valcheck ) != 0 ) {
285 if (
p[
i].sigma != NULL ) {
287 if ( strcmp( outsigma,
p[
i].sigmacheck ) != 0 ) {
289 outsigma,
p[
i].sigmacheck );
292 if ( strcmp( outfitflag,
p[
i].fitFlag ) != 0 ) {
301 if ( remove(
PARFILE ) != 0 ) {
305 fprintf( stderr,
"Successfully read in .par file values!\n" );
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
char char * XLALStringDuplicate(const char *s)
The PulsarParameters structure to contain a set of pulsar parameters.