Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-3a66518
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
compareFstats.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Bernd Machenschalk, Reinhard Prix
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/**
21 * \author R. Prix
22 */
23
24/* ---------- includes ---------- */
25#include "config.h"
26
27#include <math.h>
28
29#include <lal/UserInput.h>
30#include <lal/LALConstants.h>
31#include <lal/PulsarDataTypes.h>
32#include <lal/LFTandTSutils.h>
33#include <lal/LALPulsarVCSInfo.h>
34
35// ----- defines & macros ----------
36#define TRUE (1==1)
37#define FALSE (1==0)
38
39/* (possible) fields of the output Fstat-file */
40typedef struct {
49
50/* User variables */
51typedef struct {
54
55 REAL8 tol_param; // tolerance on relative error between parameter values
56 REAL8 tol_L1; // tolerance on relative error between vectors using L1 norm
57 REAL8 tol_L2; // tolerance on relative error between vectors using L2 norm
58 REAL8 tol_angle; // tolerance on angle between the two vectors, in radians
59 REAL8 tol_atMax; // tolerance on single-sample relative error *at* respective maximum
60
62
63/* ---------- local prototypes ---------- */
66int XLALParseFstatLine( FstatLine_t *FstatLine, const CHAR *line );
68
69/*----------------------------------------------------------------------
70 * main function
71 *----------------------------------------------------------------------*/
72int
73main( int argc, char *argv[] )
74{
75 /* register all user-variables */
78
79 /* read cmdline & cfgfile */
80 BOOLEAN should_exit = 0;
82 if ( should_exit ) {
83 exit( 1 );
84 }
85
86 /* read in the two Fstats-files (we use XLALParseDataFile() for that purpose) */
87 LALParsedDataFile *Fstats1 = NULL, *Fstats2 = NULL;
88 XLAL_CHECK( XLALParseDataFile( &Fstats1, uvar.Fname1 ) == XLAL_SUCCESS, XLAL_EFUNC );
89 XLAL_CHECK( XLALParseDataFile( &Fstats2, uvar.Fname2 ) == XLAL_SUCCESS, XLAL_EFUNC );
90
92 tol.relErr_L1 = uvar.tol_L1;
93 tol.relErr_L2 = uvar.tol_L2;
94 tol.angleV = uvar.tol_angle;
95 tol.relErr_atMaxAbsx = uvar.tol_atMax;
96 tol.relErr_atMaxAbsy = uvar.tol_atMax;
97
98 XLAL_CHECK( XLALcompareFstatFiles( Fstats1, Fstats2, uvar.tol_param, tol ) == XLAL_SUCCESS, XLAL_EFUNC );
99
100 XLALDestroyParsedDataFile( Fstats1 );
101 XLALDestroyParsedDataFile( Fstats2 );
103
105
106 return XLAL_SUCCESS;
107
108} /* main */
109
110
111/* register all our "user-variables" */
112int
114{
115 XLAL_CHECK( uvar != NULL, XLAL_EINVAL );
116
117 uvar->tol_param = 100.0 * LAL_REAL4_EPS;
118 uvar->tol_L1 = 5.5e-2;
119 uvar->tol_L2 = 4.5e-2;
120 uvar->tol_angle = 0.04; // rad
121 uvar->tol_atMax = 5e-2;
122
123 /* now register all user-variables */
124 XLALRegisterUvarMember( Fname1, STRING, '1', REQUIRED, "Path and basefilename for first Fstats file" );
125 XLALRegisterUvarMember( Fname2, STRING, '2', REQUIRED, "Path and basefilename for second Fstats file" );
126 XLALRegisterUvarMember( tol_param, REAL8, 0, OPTIONAL, "tolerance on relative error between parameter values" );
127 XLALRegisterUvarMember( tol_L1, REAL8, 0, OPTIONAL, "tolerance on relative error between vectors using L1 norm, between [0,2]" );
128 XLALRegisterUvarMember( tol_L2, REAL8, 0, OPTIONAL, "tolerance on relative error between vectors using L2 norm, between [0,2]" );
129 XLALRegisterUvarMember( tol_angle, REAL8, 0, OPTIONAL, "tolerance on angle between the two vectors in radians, between [0,pi]" );
130 XLALRegisterUvarMember( tol_atMax, REAL8, 0, OPTIONAL, "tolerance on single-sample relative error *at* respective maximum, between [0,2]" );
131
132 return XLAL_SUCCESS;
133
134} /* XLALinitUserVars() */
135
136/**
137 * comparison specific to pure Fstat-output files (5 entries )
138 */
139int
141{
142 XLAL_CHECK( ( f1 != NULL ) && ( f2 != NULL ), XLAL_EINVAL );
143
144 FstatLine_t XLAL_INIT_DECL( parsed1 );
145 FstatLine_t XLAL_INIT_DECL( parsed2 );
146
147 XLAL_CHECK( f1->lines->nTokens == f2->lines->nTokens, XLAL_ETOL, "Different number of lines: %d != %d\n", f1->lines->nTokens, f2->lines->nTokens );
148 UINT4 nlines = f1->lines->nTokens;
149
150 REAL4Vector *twoF1, *twoF2;
151 XLAL_CHECK( ( twoF1 = XLALCreateREAL4Vector( nlines ) ) != NULL, XLAL_EFUNC );
152 XLAL_CHECK( ( twoF2 = XLALCreateREAL4Vector( nlines ) ) != NULL, XLAL_EFUNC );
153
154 for ( UINT4 i = 0; i < nlines ; i++ ) {
155 const char *line1 = f1->lines->tokens[i];
156 const char *line2 = f2->lines->tokens[i];
157
158 /* read pure Fstats files */
159 XLAL_CHECK( XLALParseFstatLine( &parsed1, line1 ) == XLAL_SUCCESS, XLAL_EFUNC );
160 XLAL_CHECK( XLALParseFstatLine( &parsed2, line2 ) == XLAL_SUCCESS, XLAL_EFUNC );
161
162 /* compare all template parameters */
163 REAL8 relErr;
164 if ( ( relErr = relError( parsed1.Freq, parsed2.Freq ) ) > tol_param ) {
165 XLAL_ERROR( XLAL_ETOL, "Relative frequency-error %g exceeds %g in line %d\n", relErr, tol_param, i + 1 );
166 }
167 if ( ( relErr = relError( parsed1.Alpha, parsed2.Alpha ) ) > tol_param ) {
168 XLAL_ERROR( XLAL_ETOL, "Relative error %g in alpha exceeds %g in line %d\n", relErr, tol_param, i + 1 );
169 }
170 if ( ( relErr = relError( parsed1.Delta, parsed2.Delta ) ) > tol_param ) {
171 XLAL_ERROR( XLAL_ETOL, "Relative error %g in delta exceeds %g in line %d\n", relErr, tol_param, i + 1 );
172 }
173 if ( ( relErr = relError( parsed1.f1dot, parsed2.f1dot ) ) > tol_param ) {
174 XLAL_ERROR( XLAL_ETOL, "Relative error %g in f1dot exceeds %g in line %d\n", relErr, tol_param, i + 1 );
175 }
176 if ( ( relErr = relError( parsed1.f2dot, parsed2.f2dot ) ) > tol_param ) {
177 XLAL_ERROR( XLAL_ETOL, "Relative error %g in f2dot exceeds %g in line %d\n", relErr, tol_param, i + 1 );
178 }
179 if ( ( relErr = relError( parsed1.f3dot, parsed2.f3dot ) ) > tol_param ) {
180 XLAL_ERROR( XLAL_ETOL, "Relative error %g in f3dot exceeds %g in line %d\n", relErr, tol_param, i + 1 );
181 }
182
183 // and store respective 2F values in vectors for comparison
184 twoF1->data[i] = ( REAL4 )parsed1.TwoF;
185 twoF2->data[i] = ( REAL4 )parsed2.TwoF;
186
187 } /* for i < nlines */
188
189 // ----- finally vector-compare 2F values against given tolerances ----------
191 XLAL_CHECK( XLALCompareREAL4Vectors( &cmp, twoF1, twoF2, &tol ) == XLAL_SUCCESS, XLAL_EFUNC );
192
193 XLALDestroyREAL4Vector( twoF1 );
194 XLALDestroyREAL4Vector( twoF2 );
195
196 return XLAL_SUCCESS;
197
198} /* XLALcompareFstatFiles() */
199
200
201/* parse one Fstat-line into the FstatLine_t struct
202 * This function is flexible concerning the number of spindown-entries found
203 * as CFS_v2 now returns second and third spindown also, while CFS_v1 only
204 * has one spindown.
205 *
206 */
207int
209{
210 XLAL_CHECK( ( line != NULL ) && ( FstatLine != NULL ), XLAL_EINVAL );
211
212
213 REAL8 e[7];
214 int ret = sscanf( line, "%lf %lf %lf %lf %lf %lf %lf",
215 &e[0], &e[1], &e[2], &e[3], &e[4], &e[5], &e[6] );
216
217 XLAL_CHECK( ret >= 5, XLAL_EDATA, "Failed to parse Fstat-line (less than 5 entries):\n'%s'\n", line );
218
219 FstatLine->Freq = e[0];
220 FstatLine->Alpha = e[1];
221 FstatLine->Delta = e[2];
222 FstatLine->f1dot = e[3];
223
224
225 switch ( ret ) {
226 case 5:
227 FstatLine->TwoF = e[4];
228 FstatLine->f2dot = 0;
229 FstatLine->f3dot = 0;
230 break;
231 case 6:
232 FstatLine->f2dot = e[4];
233 FstatLine->TwoF = e[5];
234 FstatLine->f3dot = 0;
235 break;
236 case 7:
237 FstatLine->f2dot = e[4];
238 FstatLine->f3dot = e[5];
239 FstatLine->TwoF = e[6];
240 break;
241
242 } /* switch(ret) */
243
244 return XLAL_SUCCESS;
245
246} /* XLALParseFstatLine() */
247
248REAL8
250{
251 if ( x == y ) {
252 return 0;
253 }
254
255 REAL8 denom = fmax( 4, 0.5 * ( x + y ) );
256 return fabs( ( x - y ) / denom );
257
258} /* relError() */
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
REAL8 tol
#define STRING(a)
const WeaveSearchTimingDenominator denom
Definition: SearchTiming.c:95
double e
int main(int argc, char *argv[])
Definition: compareFstats.c:73
int XLALinitUserVars(UserVariables_t *uvar)
int XLALParseFstatLine(FstatLine_t *FstatLine, const CHAR *line)
int XLALcompareFstatFiles(const LALParsedDataFile *f1, const LALParsedDataFile *f2, REAL8 tol_param, VectorComparison tol)
comparison specific to pure Fstat-output files (5 entries )
REAL8 relError(REAL8 x, REAL8 y)
int XLALParseDataFile(LALParsedDataFile **cfgdata, const CHAR *fname)
void XLALDestroyParsedDataFile(LALParsedDataFile *cfgdata)
#define LAL_REAL4_EPS
unsigned char BOOLEAN
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
float REAL4
int XLALCompareREAL4Vectors(VectorComparison *result, const REAL4Vector *x, const REAL4Vector *y, const VectorComparison *tol)
Compare two REAL4 vectors using various different comparison metrics.
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterUvarMember(name, type, option, category,...)
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
#define XLAL_ERROR(...)
#define XLAL_CHECK(assertion,...)
XLAL_EDATA
XLAL_SUCCESS
XLAL_EFUNC
XLAL_ETOL
XLAL_EINVAL
list y
REAL4 * data
user input variables
Definition: compareFstats.c:51
Struct holding the results of comparing two floating-point vectors (real-valued or complex),...
Definition: LFTandTSutils.h:64