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
WeaveConcat.c
Go to the documentation of this file.
1//
2// Copyright (C) 2020 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 = "concatenate result files produced by lalpulsar_Weave";
37
38 ////////// Parse user input //////////
39
40 // Initialise user input variables
41 struct uvar_type {
42 CHAR *output_result_file;
43 LALStringVector *input_result_files;
44 UINT4 toplist_limit;
45 } uvar_struct = {
46 .toplist_limit = 0,
47 };
48 struct uvar_type *const uvar = &uvar_struct;
49
50 // Register user input variables:
51 //
52 // - General
53 //
55 input_result_files, STRINGVector, 'i', REQUIRED,
56 "Input result files produced by lalpulsar_Weave for concatenation. "
57 );
59 output_result_file, STRING, 'o', REQUIRED,
60 "Output concatenated result file. "
61 );
63 toplist_limit, UINT4, 'n', OPTIONAL,
64 "Maximum number of candidates to return in an output toplist; if 0, all candidates are returned. "
65 );
66
67 // Parse user input
68 XLAL_CHECK_MAIN( xlalErrno == 0, XLAL_EFUNC, "A call to XLALRegisterUvarMember() failed" );
69 BOOLEAN should_exit = 0;
71
72 // Check user input:
73 //
74 // - General
75 //
76
77 // Exit if required
78 if ( should_exit ) {
79 return EXIT_FAILURE;
80 }
81 LogPrintf( LOG_NORMAL, "Parsed user input successfully\n" );
82
83 ////////// Concatenate output results //////////
84
85 // Number of computed coherent results, and number of coherent and semicoherent templates
86 UINT8 coh_nres = 0;
87 UINT8 coh_ntmpl = 0;
88 UINT8 semi_ntmpl = 0;
89
90 // Total wall and CPU time
91 REAL8 wall_total = 0;
92 REAL8 cpu_total = 0;
93
94 // Output results
95 WeaveOutputResults *out = NULL;
96
97 // Concatenate input result files
98 for ( size_t i = 0; i < uvar->input_result_files->length; ++i ) {
99 LogPrintf( LOG_NORMAL, "Opening input result file '%s' for reading ...\n", uvar->input_result_files->data[i] );
100 FITSFile *file = XLALFITSFileOpenRead( uvar->input_result_files->data[i] );
101 XLAL_CHECK_MAIN( file != NULL, XLAL_EFUNC, "Could not open input result file '%s'", uvar->input_result_files->data[i] );
102 {
103 UINT8 coh_nres_i = 0;
104 XLAL_CHECK_MAIN( XLALFITSHeaderReadUINT8( file, "ncohres", &coh_nres_i ) == XLAL_SUCCESS, XLAL_EFUNC );
105 coh_nres += coh_nres_i;
106 }
107 {
108 UINT8 coh_ntmpl_i = 0;
109 XLAL_CHECK_MAIN( XLALFITSHeaderReadUINT8( file, "ncohtpl", &coh_ntmpl_i ) == XLAL_SUCCESS, XLAL_EFUNC );
110 coh_ntmpl += coh_ntmpl_i;
111 }
112 {
113 UINT8 semi_ntmpl_i = 0;
114 XLAL_CHECK_MAIN( XLALFITSHeaderReadUINT8( file, "nsemitpl", &semi_ntmpl_i ) == XLAL_SUCCESS, XLAL_EFUNC );
115 semi_ntmpl += semi_ntmpl_i;
116 }
117 {
118 REAL8 wall_total_i = 0;
119 XLAL_CHECK( XLALFITSHeaderReadREAL8( file, "wall total", &wall_total_i ) == XLAL_SUCCESS, XLAL_EFUNC );
120 wall_total += wall_total_i;
121 }
122 {
123 REAL8 cpu_total_i = 0;
124 XLAL_CHECK( XLALFITSHeaderReadREAL8( file, "cpu total", &cpu_total_i ) == XLAL_SUCCESS, XLAL_EFUNC );
125 cpu_total += cpu_total_i;
126 }
129 LogPrintf( LOG_NORMAL, "Closed input result file '%s'\n", uvar->input_result_files->data[i] );
130 }
131
132 // Write output concatenated result file
133 {
134 LogPrintf( LOG_NORMAL, "Opening output result file '%s' for writing ...\n", uvar->output_result_file );
135 FITSFile *file = XLALFITSFileOpenWrite( uvar->output_result_file );
136 XLAL_CHECK_MAIN( file != NULL, XLAL_EFUNC, "Could not open output result file '%s'", uvar->output_result_file );
137 XLAL_CHECK_MAIN( XLALFITSHeaderWriteUINT8( file, "ncohres", coh_nres, "number of computed coherent results" ) == XLAL_SUCCESS, XLAL_EFUNC );
138 XLAL_CHECK_MAIN( XLALFITSHeaderWriteUINT8( file, "ncohtpl", coh_ntmpl, "number of coherent templates" ) == XLAL_SUCCESS, XLAL_EFUNC );
139 XLAL_CHECK_MAIN( XLALFITSHeaderWriteUINT8( file, "nsemitpl", semi_ntmpl, "number of semicoherent templates" ) == XLAL_SUCCESS, XLAL_EFUNC );
140 XLAL_CHECK( XLALFITSHeaderWriteREAL8( file, "wall total", wall_total, "total wall time" ) == XLAL_SUCCESS, XLAL_EFUNC );
141 XLAL_CHECK( XLALFITSHeaderWriteREAL8( file, "cpu total", cpu_total, "total CPU time" ) == XLAL_SUCCESS, XLAL_EFUNC );
144 LogPrintf( LOG_NORMAL, "Closed output result file '%s'\n", uvar->output_result_file );
145 }
146
147 ////////// Cleanup memory and exit //////////
148
149 // Cleanup memory from output results
151
152 // Cleanup memory from user input
154
155 // Check for memory leaks
157
158 return EXIT_SUCCESS;
159
160}
161
162// Local Variables:
163// c-file-style: "linux"
164// c-basic-offset: 2
165// End:
int XLALFITSHeaderReadREAL8(FITSFile UNUSED *file, const CHAR UNUSED *key, REAL8 UNUSED *value)
Definition: FITSFileIO.c:1184
FITSFile * XLALFITSFileOpenWrite(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:263
FITSFile * XLALFITSFileOpenRead(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:320
int XLALFITSHeaderWriteUINT8(FITSFile UNUSED *file, const CHAR UNUSED *key, const UINT8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:827
void XLALFITSFileClose(FITSFile UNUSED *file)
Definition: FITSFileIO.c:245
int XLALFITSHeaderWriteREAL8(FITSFile UNUSED *file, const CHAR UNUSED *key, const REAL8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1150
int XLALFITSHeaderReadUINT8(FITSFile UNUSED *file, const CHAR UNUSED *key, UINT8 UNUSED *value)
Definition: FITSFileIO.c:863
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
int XLALWeaveOutputResultsWrite(FITSFile *file, const WeaveOutputResults *out)
Write output results to a FITS file.
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)
Module which handles the setup data.
int main(int argc, char *argv[])
Definition: WeaveConcat.c:32
struct tagFITSFile FITSFile
Representation of a FITS file.
Definition: FITSFileIO.h:54
unsigned char BOOLEAN
uint64_t UINT8
double REAL8
char CHAR
uint32_t UINT4
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
LOG_NORMAL
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 xlalErrno
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
out
UserInput_t uvar_struct
Definition: sw_inj_frames.c:93