LALPulsar 7.1.1.1-eeff03c
SetupData.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 "SetupData.h"
26
27#include <lal/LALInitBarycenter.h>
28#include <lal/FITSPulsarIO.h>
29#include <lal/LogPrintf.h>
30
31///
32/// \name Internal functions
33///
34/// @{
35
36/// @}
37
38///
39/// Free contents of setup data
40///
42 WeaveSetupData *setup
43)
44{
45 if ( setup != NULL ) {
46 XLALFree( setup->metric_type );
47 XLALDestroyStringVector( setup->detectors );
48 XLALSegListFree( setup->segments );
49 XLALDestroySuperskyMetrics( setup->metrics );
50 XLALDestroyEphemerisData( setup->ephemerides );
51 }
52}
53
54///
55/// Write setup data to a FITS file
56///
59 const WeaveSetupData *setup
60)
61{
62
63 // Check input
64 XLAL_CHECK( file != NULL, XLAL_EFAULT );
65 XLAL_CHECK( setup != NULL, XLAL_EFAULT );
66 XLAL_CHECK( setup->detectors != NULL, XLAL_EFAULT );
67 XLAL_CHECK( setup->segments != NULL, XLAL_EFAULT );
68 XLAL_CHECK( setup->metrics != NULL, XLAL_EFAULT );
69 XLAL_CHECK( setup->ephemerides != NULL, XLAL_EFAULT );
70
71 // Write metric type
72 XLAL_CHECK( XLALFITSHeaderWriteString( file, "metric-type", setup->metric_type, "metric type (for all-sky/directed searches)" ) == XLAL_SUCCESS, XLAL_EFUNC );
73
74 // Write reference time
75 XLAL_CHECK( XLALFITSHeaderWriteGPSTime( file, "date-obs", &setup->ref_time, "reference time" ) == XLAL_SUCCESS, XLAL_EFUNC );
76
77 // Write list of detector names
78 XLAL_CHECK( XLALFITSHeaderWriteStringVector( file, "detect", setup->detectors, "setup detectors" ) == XLAL_SUCCESS, XLAL_EFUNC );
79
80 // Write ephemerides
82
83 // Write segment list
84 XLAL_CHECK( XLALFITSWriteSegmentList( file, "segments", setup->segments, "segment list" ) == XLAL_SUCCESS, XLAL_EFUNC );
85
86 // Write supersky metrics
88
89 return XLAL_SUCCESS;
90
91}
92
93///
94/// Read setup data from a FITS file
95///
98 WeaveSetupData *setup
99)
100{
101
102 // Check input
103 XLAL_CHECK( file != NULL, XLAL_EFAULT );
104 XLAL_CHECK( setup != NULL, XLAL_EFAULT );
105
106 // Erase memory
107 XLAL_INIT_MEM( *setup );
108
109 // Read metric type
110 int read_status;
111 read_status = XLALFITSHeaderReadString( file, "metric-type", &setup->metric_type );
112 if ( read_status != XLAL_SUCCESS ) {
113 // If not found, set it to 'all-sky'
115 LogPrintf( LOG_NORMAL, "Setup file does not contain 'metric-type'. Defaulting to 'all-sky'\n" );
116 setup->metric_type = XLALStringDuplicate( "all-sky" );
117 // Check that the string duplication was successful
118 XLAL_CHECK( setup->metric_type != NULL, XLAL_ENOMEM );
119 }
120
121 // Read reference time
122 XLAL_CHECK( XLALFITSHeaderReadGPSTime( file, "date-obs", &setup->ref_time ) == XLAL_SUCCESS, XLAL_EFUNC );
123
124 // Read list of detector names
125 XLAL_CHECK( XLALFITSHeaderReadStringVector( file, "detect", &setup->detectors ) == XLAL_SUCCESS, XLAL_EFUNC );
126 XLAL_CHECK( setup->detectors != NULL, XLAL_EFAULT );
127
128 // Read ephemerides
129 XLAL_CHECK( XLALFITSReadEphemerisData( file, &setup->ephemerides ) == XLAL_SUCCESS, XLAL_EFUNC );
130 XLAL_CHECK( setup->ephemerides != NULL, XLAL_EFAULT );
131
132 // Read segment list
133 XLAL_CHECK( XLALFITSReadSegmentList( file, "segments", &setup->segments ) == XLAL_SUCCESS, XLAL_EFUNC );
134 XLAL_CHECK( setup->ephemerides != NULL, XLAL_EFAULT );
135
136 // Read supersky metrics
138 XLAL_CHECK( setup->metrics != NULL, XLAL_EFAULT );
139
140 return XLAL_SUCCESS;
141
142}
143
144// Local Variables:
145// c-file-style: "linux"
146// c-basic-offset: 2
147// End:
int XLALFITSHeaderWriteStringVector(FITSFile UNUSED *file, const CHAR UNUSED *key, const LALStringVector UNUSED *values, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1412
int XLALFITSHeaderWriteGPSTime(FITSFile UNUSED *file, const CHAR UNUSED *key, const LIGOTimeGPS UNUSED *value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1494
int XLALFITSHeaderReadGPSTime(FITSFile UNUSED *file, const CHAR UNUSED *key, LIGOTimeGPS UNUSED *value)
Definition: FITSFileIO.c:1547
int XLALFITSHeaderReadStringVector(FITSFile UNUSED *file, const CHAR UNUSED *key, LALStringVector UNUSED **values)
Definition: FITSFileIO.c:1456
int XLALFITSHeaderReadString(FITSFile UNUSED *file, const CHAR UNUSED *key, CHAR UNUSED **value)
Definition: FITSFileIO.c:1377
int XLALFITSHeaderWriteString(FITSFile UNUSED *file, const CHAR UNUSED *key, const CHAR UNUSED *value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1339
void XLALWeaveSetupDataClear(WeaveSetupData *setup)
Free contents of setup data.
Definition: SetupData.c:41
int XLALWeaveSetupDataWrite(FITSFile *file, const WeaveSetupData *setup)
Write setup data to a FITS file.
Definition: SetupData.c:57
int XLALWeaveSetupDataRead(FITSFile *file, WeaveSetupData *setup)
Read setup data from a FITS file.
Definition: SetupData.c:96
Module which handles the setup data.
struct tagFITSFile FITSFile
Representation of a FITS file.
Definition: FITSFileIO.h:54
int XLALFITSReadEphemerisData(FITSFile *file, EphemerisData **ephemerides)
Read ephemeris data from a FITS file.
Definition: FITSPulsarIO.c:144
int XLALFITSWriteEphemerisData(FITSFile *file, const EphemerisData *ephemerides)
Write ephemeris data to a FITS file.
Definition: FITSPulsarIO.c:106
int XLALFITSWriteSegmentList(FITSFile *file, const CHAR *name, const LALSegList *segments, const CHAR *comment)
Write a segment list to a FITS file.
Definition: FITSPulsarIO.c:37
int XLALFITSReadSegmentList(FITSFile *file, const CHAR *name, LALSegList **segments)
Read a segment list from a FITS file.
Definition: FITSPulsarIO.c:62
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
#define XLAL_INIT_MEM(x)
void XLALFree(void *p)
char char * XLALStringDuplicate(const char *s)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
LOG_NORMAL
int XLALSegListFree(LALSegList *seglist)
void XLALDestroyStringVector(LALStringVector *vect)
void XLALDestroySuperskyMetrics(SuperskyMetrics *metrics)
Destroy a SuperskyMetrics struct.
int XLALFITSWriteSuperskyMetrics(FITSFile *file, const SuperskyMetrics *metrics)
Write a SuperskyMetrics struct to a FITS file.
int XLALFITSReadSuperskyMetrics(FITSFile *file, SuperskyMetrics **metrics)
Read a SuperskyMetrics struct from a FITS file.
#define XLAL_CHECK(assertion,...)
int XLALClearErrno(void)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFAULT
XLAL_EFUNC