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
WeaveCompare.c
Go to the documentation of this file.
1//
2// Copyright (C) 2016, 2017 Karl Wette
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/// \file
22/// \ingroup lalpulsar_bin_Weave
23///
24
25#include "Weave.h"
26#include "SetupData.h"
27#include "OutputResults.h"
28
29#include <lal/LogPrintf.h>
30#include <lal/UserInput.h>
31
32int main( int argc, char *argv[] )
33{
34
35 // Set help information
36 lalUserVarHelpBrief = "compare result files produced by lalpulsar_Weave";
37
38 ////////// Parse user input //////////
39
40 // Initialise user input variables
41 struct uvar_type {
42 BOOLEAN sort_by_semi_phys;
43 CHAR *setup_file, *result_file_1, *result_file_2;
44 REAL8 unmatched_item_tol, param_tol_mism, result_tol_L1, result_tol_L2, result_tol_angle, result_tol_at_max;
45 UINT4 round_param_to_dp, round_param_to_sf, toplist_limit;
46 } uvar_struct = {
47 .unmatched_item_tol = 0,
48 .param_tol_mism = 1e-3,
49 .result_tol_L1 = 5.5e-2,
50 .result_tol_L2 = 4.5e-2,
51 .result_tol_angle = 0.04,
52 .result_tol_at_max = 5e-2,
53 };
54 struct uvar_type *const uvar = &uvar_struct;
55
56 // Register user input variables:
57 //
58 // - General
59 //
61 setup_file, STRING, 'S', REQUIRED,
62 "Setup file generated by lalpulsar_WeaveSetup; the segment list, parameter-space metrics, and other required data. "
63 );
65 result_file_1, STRING, '1', REQUIRED,
66 "First result file produced by lalpulsar_Weave for comparison. "
67 );
69 result_file_2, STRING, '2', REQUIRED,
70 "Second result file produced by lalpulsar_Weave for comparison. "
71 );
72 //
73 // - Comparison options
74 //
75 lalUserVarHelpOptionSubsection = "Comparison options";
77 sort_by_semi_phys, BOOLEAN, 'p', OPTIONAL,
78 "Sort toplist items by semicoherent physical coordinates, instead of serial number. "
79 );
81 round_param_to_dp, UINT4, 'f', OPTIONAL,
82 "Round parameter-space points to the given number of decimal places (must be >0, or zero to disable). "
83 );
85 round_param_to_sf, UINT4, 'e', OPTIONAL,
86 "Round parameter-space points to the given number of significant figures (must be >0, or zero to disable). "
87 );
88 //
89 // - Tolerances
90 //
91 lalUserVarHelpOptionSubsection = "Tolerances";
93 unmatched_item_tol, REAL8, 'u', OPTIONAL,
94 "When comparing toplists, allow this fraction of items to be umatched to an item in the other toplist (must in in range [0, 1]). "
95 );
97 param_tol_mism, REAL8, 'm', OPTIONAL,
98 "Allowed tolerance on mismatch between parameter-space points (must be >0, or zero to disable comparison). "
99 );
101 result_tol_L1, REAL8, 'r', OPTIONAL,
102 "Allowed tolerance on relative error between mismatch between result vectors using L1 (sum of absolutes) norm. "
103 "Must be within range [0,2]. "
104 );
106 result_tol_L2, REAL8, 's', OPTIONAL,
107 "Allowed tolerance on relative error between mismatch between result vectors using L2 (root of sum of squares) norm. "
108 "Must be within range [0,2]. "
109 );
111 result_tol_angle, REAL8, 'a', OPTIONAL,
112 "Allowed tolerance on angle between result vectors, in radians. "
113 "Must be within range [0,PI]. "
114 );
116 result_tol_at_max, REAL8, 'x', OPTIONAL,
117 "Allowed tolerance on relative errors at maximum component of each result vector. "
118 "Must be within range [0,2]. "
119 );
121 toplist_limit, UINT4, 'n', OPTIONAL,
122 "Maximum number of candidates to compare in an output toplist; if 0, all candidates are compared. "
123 );
124
125 // Parse user input
126 XLAL_CHECK_FAIL( xlalErrno == 0, XLAL_EFUNC, "A call to XLALRegisterUvarMember() failed" );
127 BOOLEAN should_exit = 0;
129
130 // Check user input:
131 //
132 // - General
133 //
134
135 //
136 // - Comparison options
137 //
138
139 //
140 // - Tolerances
141 //
142 XLALUserVarCheck( &should_exit,
143 0 <= uvar->unmatched_item_tol && uvar->unmatched_item_tol <= 1,
144 UVAR_STR( unmatched_item_tol ) " must be within range [0,1]" );
145 XLALUserVarCheck( &should_exit,
146 0 <= uvar->param_tol_mism,
147 UVAR_STR( param_tol_mism ) " must be >=0" );
148 XLALUserVarCheck( &should_exit,
149 0 <= uvar->result_tol_L1 && uvar->result_tol_L1 <= 2,
150 UVAR_STR( result_tol_L1 ) " must be within range [0,2]" );
151 XLALUserVarCheck( &should_exit,
152 0 <= uvar->result_tol_L2 && uvar->result_tol_L2 <= 2,
153 UVAR_STR( result_tol_L2 ) " must be within range [0,2]" );
154 XLALUserVarCheck( &should_exit,
155 0 <= uvar->result_tol_angle && uvar->result_tol_angle <= LAL_PI,
156 UVAR_STR( result_tol_angle ) " must be within range [0,PI]" );
157 XLALUserVarCheck( &should_exit,
158 0 <= uvar->result_tol_at_max && uvar->result_tol_at_max <= 2,
159 UVAR_STR( result_tol_at_max ) " must be within range [0,2]" );
160
161 // Exit if required
162 if ( should_exit ) {
163 return EXIT_FAILURE;
164 }
165 LogPrintf( LOG_NORMAL, "Parsed user input successfully\n" );
166
167 ////////// Load setup data //////////
168
169 // Initialise setup data
170 WeaveSetupData XLAL_INIT_DECL( setup );
171
172 {
173 // Open setup file
174 LogPrintf( LOG_NORMAL, "Opening setup file '%s' for reading ...\n", uvar->setup_file );
175 FITSFile *file = XLALFITSFileOpenRead( uvar->setup_file );
176 XLAL_CHECK_FAIL( file != NULL, XLAL_EFUNC );
177
178 // Read setup data
180
181 // Close result file
183 LogPrintf( LOG_NORMAL, "Closed setup file '%s'\n", uvar->setup_file );
184 }
185
186 ////////// Load output results //////////
187
188 // Initialise output results
189 WeaveOutputResults *out_1 = NULL, *out_2 = NULL;
190
191 {
192 // Open result file #1
193 LogPrintf( LOG_NORMAL, "Opening result file '%s' for reading ...\n", uvar->result_file_1 );
194 FITSFile *file = XLALFITSFileOpenRead( uvar->result_file_1 );
195 XLAL_CHECK_FAIL( file != NULL, XLAL_EFUNC );
196
197 // Read output results
199
200 // Close result file
202 LogPrintf( LOG_NORMAL, "Closed result file '%s'\n", uvar->result_file_1 );
203 }
204
205 {
206 // Open result file #2
207 LogPrintf( LOG_NORMAL, "Opening result file '%s' for reading ...\n", uvar->result_file_2 );
208 FITSFile *file = XLALFITSFileOpenRead( uvar->result_file_2 );
209 XLAL_CHECK_FAIL( file != NULL, XLAL_EFUNC );
210
211 // Read output results
213
214 // Close result file
216 LogPrintf( LOG_NORMAL, "Closed result file '%s'\n", uvar->result_file_2 );
217 }
218
219 ////////// Compare output results //////////
220
221 // Initalise struct with comparison tolerances
222 const VectorComparison result_tol = {
223 .relErr_L1 = uvar->result_tol_L1,
224 .relErr_L2 = uvar->result_tol_L2,
225 .angleV = uvar->result_tol_angle,
226 .relErr_atMaxAbsx = uvar->result_tol_at_max,
227 .relErr_atMaxAbsy = uvar->result_tol_at_max,
228 };
229
230 // Compare output results
231 BOOLEAN equal = 0;
232 LogPrintf( LOG_NORMAL, "Comparing result files '%s' and '%s ...\n", uvar->result_file_1, uvar->result_file_2 );
234 &setup, uvar->sort_by_semi_phys,
235 uvar->round_param_to_dp, uvar->round_param_to_sf, uvar->unmatched_item_tol, uvar->param_tol_mism, &result_tol, uvar->toplist_limit,
236 out_1, out_2
237 ) == XLAL_SUCCESS, XLAL_EFUNC );
238 LogPrintf( LOG_NORMAL, "Result files compare %s\n", equal ? "EQUAL" : "NOT EQUAL" );
239
240 ////////// Cleanup memory and exit //////////
241
242 // Cleanup memory from output results
245
246 // Cleanup memory from setup data
247 XLALWeaveSetupDataClear( &setup );
248
249 // Cleanup memory from user input
251
252 // Check for memory leaks
254
255 LogPrintf( LOG_NORMAL, "Finished successfully!\n" );
256
257 // Indicate whether result files compared equal
258 return equal ? 0 : 1;
259
260XLAL_FAIL:
261
262 // Indicate an error preventing result files from being compared
263 return 2;
264
265}
266
267// Local Variables:
268// c-file-style: "linux"
269// c-basic-offset: 2
270// End:
FITSFile * XLALFITSFileOpenRead(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:320
void XLALFITSFileClose(FITSFile UNUSED *file)
Definition: FITSFileIO.c:245
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
int XLALWeaveOutputResultsCompare(BOOLEAN *equal, const WeaveSetupData *setup, const BOOLEAN sort_by_semi_phys, const UINT4 round_param_to_dp, const UINT4 round_param_to_sf, const REAL8 unmatched_item_tol, const REAL8 param_tol_mism, const VectorComparison *result_tol, const UINT4 toplist_compare_limit, const WeaveOutputResults *out_1, const WeaveOutputResults *out_2)
Compare two output results and return whether they are equal.
int XLALWeaveOutputResultsReadAppend(FITSFile *file, WeaveOutputResults **out, UINT4 toplist_limit)
Read results from a FITS file and append to new/existing output results.
void XLALWeaveOutputResultsDestroy(WeaveOutputResults *out)
Free output results.
Module which handles the output results.
#define STRING(a)
void XLALWeaveSetupDataClear(WeaveSetupData *setup)
Free contents of setup data.
Definition: SetupData.c:40
int XLALWeaveSetupDataRead(FITSFile *file, WeaveSetupData *setup)
Read setup data from a FITS file.
Definition: SetupData.c:91
Module which handles the setup data.
int main(int argc, char *argv[])
Definition: WeaveCompare.c:32
double e
struct tagFITSFile FITSFile
Representation of a FITS file.
Definition: FITSFileIO.h:54
#define LAL_PI
unsigned char BOOLEAN
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
LOG_NORMAL
const char * lalUserVarHelpOptionSubsection
const char * lalUserVarHelpBrief
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterUvarMember(name, type, option, category,...)
#define UVAR_STR(n)
void XLALUserVarCheck(BOOLEAN *should_exit, const int assertion, const CHAR *fmt,...) _LAL_GCC_PRINTF_FORMAT_(3
#define xlalErrno
#define XLAL_CHECK_FAIL(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
Struct holding the results of comparing two floating-point vectors (real-valued or complex),...
Definition: LFTandTSutils.h:64
REAL4 relErr_L1
relative error between vectors using L1 norm
Definition: LFTandTSutils.h:65
UserInput_t uvar_struct
Definition: sw_inj_frames.c:93