Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-ea7c608
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
WriteSFTsfromSFDBs.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2020 Pep Covas, David Keitel, Rodrigo Tenorio
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_WriteSFTsfromSFDBs
23* \author Pep Covas, David Keitel
24* \brief Read data in the form of Virgo Collaboration's SFDBs, convert to SFTs in the usual LALSuite format, and write those to disk.
25*/
26
27#include <sys/stat.h>
28#include <sys/types.h>
29#include <lal/LALPulsarVCSInfo.h>
30#include <lal/UserInput.h>
31#include <lal/PulsarDataTypes.h>
32#include <lal/SFTfileIO.h>
33#include <lal/LogPrintf.h>
34
35typedef struct {
36 REAL8 fmin;
37 REAL8 fmax;
38 CHAR *file_pattern;
39 CHAR *timeStampsStarting;
40 CHAR *timeStampsFinishing;
41 CHAR *outSFTnames;
42 CHAR *outSFTdir;
43 BOOLEAN outSingleSFT;
45
46int initUserVars( UserInput_t *uvar );
47
48BOOLEAN is_directory( const CHAR *fname ); // Function taken from makefakedata_v5
49
50int main( int argc, char *argv[] )
51{
52
54
55 /* register all user-variables */
57
58 /* read cmdline & cfgfile */
59 BOOLEAN should_exit = 0;
61 if ( should_exit ) {
62 exit( 1 );
63 }
64
65 XLAL_CHECK_MAIN( ( ( XLALUserVarWasSet( &uvar.outSFTnames ) == 1 && XLALUserVarWasSet( &uvar.outSFTdir ) == 0 ) || ( XLALUserVarWasSet( &uvar.outSFTnames ) == 0 && XLALUserVarWasSet( &uvar.outSFTdir ) == 1 ) ), XLAL_EINVAL, "Only one of the two inputs (outSFTnames or outSFTdir) has to be used\n" );
66
67 MultiSFTVector *inputSFTs = NULL;
68 XLAL_CHECK_MAIN( ( inputSFTs = XLALReadSFDB( uvar.fmin, uvar.fmax, uvar.file_pattern, uvar.timeStampsStarting, uvar.timeStampsFinishing ) ) != NULL, XLAL_EFUNC );
69
70 LALStringVector *fnames = NULL;
71 if ( uvar.outSFTnames ) { // Parsing the input filenames into a string vector
72 XLAL_CHECK_MAIN( ( fnames = XLALFindFiles( uvar.outSFTnames ) ) != NULL, XLAL_EFUNC, "Failed to parse file(s) with pattern '%s'.\n\n", uvar.outSFTnames );
73 } else {
74 XLAL_CHECK_MAIN( is_directory( uvar.outSFTdir ), XLAL_EFUNC, "Directory '%s' is not valid\n", uvar.outSFTdir );
75 }
76
77 /* generate comment string */
78 size_t len;
79 char *VCSInfoString = XLALVCSInfoString( lalPulsarVCSInfoList, 0, "%% " );
80 XLAL_CHECK( VCSInfoString != NULL, XLAL_EFUNC, "XLALVCSInfoString failed.\n" );
81 char *logstr;
83 char *comment = XLALCalloc( 1, len = strlen( logstr ) + strlen( VCSInfoString ) + 512 );
84 XLAL_CHECK( comment != NULL, XLAL_ENOMEM, "XLALCalloc(1,%zu) failed.\n", len );
85 sprintf( comment, "Generated by:\n%s\n%s\n", logstr, VCSInfoString );
86
88 XLAL_CHECK_MAIN( XLALFillSFTFilenameSpecStrings( &spec, uvar.outSFTdir, NULL, NULL, "unknown", "fromSFDBs", NULL, NULL ) == XLAL_SUCCESS, XLAL_EFUNC );
89
90 for ( UINT4 X = 0; X < inputSFTs->length; X++ ) {
91
92 SFTVector *sfts = inputSFTs->data[X];
93
94 /* either write whole SFT-vector to single concatenated file or as individual SFT-files */
95 if ( uvar.outSFTnames ) {
96 XLAL_CHECK_MAIN( XLALWriteSFTVector2NamedFile( sfts, fnames->data[X], spec.window_type, spec.window_param, comment ) == XLAL_SUCCESS, XLAL_EFUNC );
97 } else {
98 XLAL_CHECK_MAIN( XLALWriteSFTVector2StandardFile( sfts, &spec, comment, uvar.outSingleSFT ) == XLAL_SUCCESS, XLAL_EFUNC );
99 }
100
101 }
102
103 XLALDestroyMultiSFTVector( inputSFTs );
104 if ( uvar.outSFTnames ) {
106 }
107 XLALFree( logstr );
108 XLALFree( comment );
109 XLALFree( VCSInfoString );
110
111 return 0;
112
113}
114
115
117{
118
119 XLAL_CHECK( uvar != NULL, XLAL_EINVAL );
120
121 uvar->fmin = 0;
122 uvar->fmax = 0;
123 uvar->file_pattern = NULL;
124 uvar->timeStampsStarting = NULL;
125 uvar->timeStampsFinishing = NULL;
126 uvar->outSFTnames = NULL;
127 uvar->outSFTdir = NULL;
128 uvar->outSingleSFT = 1;
129
130 /* now register all our user-variable */
131 XLALRegisterUvarMember( file_pattern, STRING, 'i', REQUIRED, "String of SFDB files (possibly from more than one detector, separated by a ;)" );
132 XLALRegisterUvarMember( timeStampsStarting, STRING, 's', OPTIONAL, "File(s) containing the starting timestamps of science segments (possibly from more than one detector, separated by a ;)" );
133 XLALRegisterUvarMember( timeStampsFinishing, STRING, 'f', OPTIONAL, "File(s) containing the starting timestamps of science segments (possibly from more than one detector, separated by a ;)" );
134 XLALRegisterUvarMember( fmin, REAL8, 0, REQUIRED, "Lowest frequency to extract from SFTs" );
135 XLALRegisterUvarMember( fmax, REAL8, 0, REQUIRED, "Highest frequency to extract from SFTs" );
136 XLALRegisterUvarMember( outSFTnames, STRING, 'd', OPTIONAL, "Single SFT output custom path(s) (possibly from more than one detector, separated by a ;). Ignored if outSingleSFT is FALSE. Only use either outSFTnames or outSFTdir" );
137 XLALRegisterUvarMember( outSFTdir, STRING, 'n', OPTIONAL, "Directory for officially-named output SFTs. Only use either outSFTnames or outSFTdir." );
138 XLALRegisterUvarMember( outSingleSFT, BOOLEAN, 0, OPTIONAL, "Write a single concatenated SFT file instead of individual files (default: TRUE)" );
139
140
141 return XLAL_SUCCESS;
142
143} /* initUserVars() */
144
145/* determine if the given filepath is an existing directory or not */
147is_directory( const CHAR *fname )
148{
149 struct stat stat_buf;
150
151 if ( stat( fname, &stat_buf ) ) {
152 return 0;
153 }
154
155 if ( ! S_ISDIR( stat_buf.st_mode ) ) {
156 return 0;
157 } else {
158 return 1;
159 }
160
161} /* is_directory() */
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define STRING(a)
const char * comment
Definition: SearchTiming.c:94
int main(int argc, char *argv[])
int initUserVars(UserInput_t *uvar)
BOOLEAN is_directory(const CHAR *fname)
unsigned char BOOLEAN
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
void * XLALCalloc(size_t m, size_t n)
void XLALFree(void *p)
char * XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
void XLALDestroyMultiSFTVector(MultiSFTVector *multvect)
Destroy a multi SFT-vector.
Definition: SFTtypes.c:424
MultiSFTVector * XLALReadSFDB(REAL8 f_min, REAL8 f_max, const CHAR *file_pattern, const CHAR *timeStampsStarting, const CHAR *timeStampsFinishing)
Return a MultiSFTVector struct from an input set of SFDBs, possibly from more than one detector.
Definition: SFDBfileIO.c:100
LALStringVector * XLALFindFiles(const CHAR *globstring)
Returns a list of filenames matching the input argument, which may be one of the following:
Definition: FindFiles.c:61
int XLALWriteSFTVector2NamedFile(const SFTVector *sftVect, const CHAR *SFTfilename, const CHAR *SFTwindowtype, const REAL8 SFTwindowparam, const CHAR *SFTcomment)
Write the given SFTVector to a single merged SFT file with the supplied filename.
Definition: SFTfileIO.c:712
int XLALWriteSFTVector2StandardFile(const SFTVector *sftVect, SFTFilenameSpec *SFTfnspec, const CHAR *SFTcomment, const BOOLEAN merged)
Write the given SFTVector to SFT file(s) with a standard () filename(s).
Definition: SFTfileIO.c:755
int XLALFillSFTFilenameSpecStrings(SFTFilenameSpec *spec, const CHAR *path, const CHAR *extn, const CHAR *detector, const CHAR *window_type, const CHAR *privMisc, const CHAR *pubObsKind, const CHAR *pubChannel)
Convenience function for filling out the string fields in a SFTFilenameSpec.
Definition: SFTnaming.c:257
void XLALDestroyStringVector(LALStringVector *vect)
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
#define XLALRegisterUvarMember(name, type, option, category,...)
void CHAR * XLALUserVarGetLog(UserVarLogFormat format)
int XLALUserVarWasSet(const void *cvar)
UVAR_LOGFMT_CMDLINE
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EINVAL
fnames
A vector of COMPLEX8FrequencySeries.
A collection of SFT vectors – one for each IFO in a multi-IFO search.
Definition: SFTfileIO.h:179
UINT4 length
number of ifos
Definition: SFTfileIO.h:183
SFTVector ** data
sftvector for each ifo
Definition: SFTfileIO.h:184
Structure specifying an SFT file name, following the convention in .
Definition: SFTfileIO.h:266