LALPulsar 7.1.2.1-bf6a62b
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/// Definitions of search type choices
40///
42 { SUPERSKY_METRIC_TYPE, "all-sky" },
43 { SUPERSKY_DIRECTED_METRIC_TYPE, "directed" },
44 { 0, NULL }
45};
46
47///
48/// Free contents of setup data
49///
51 WeaveSetupData *setup
52)
53{
54 if ( setup != NULL ) {
55 XLALFree( setup->metric_type );
56 XLALDestroyStringVector( setup->detectors );
57 XLALSegListFree( setup->segments );
58 XLALDestroySuperskyMetrics( setup->metrics );
59 XLALDestroyEphemerisData( setup->ephemerides );
60 }
61}
62
63///
64/// Write setup data to a FITS file
65///
68 const WeaveSetupData *setup
69)
70{
71
72 // Check input
73 XLAL_CHECK( file != NULL, XLAL_EFAULT );
74 XLAL_CHECK( setup != NULL, XLAL_EFAULT );
75 XLAL_CHECK( setup->detectors != NULL, XLAL_EFAULT );
76 XLAL_CHECK( setup->segments != NULL, XLAL_EFAULT );
77 XLAL_CHECK( setup->metrics != NULL, XLAL_EFAULT );
78 XLAL_CHECK( setup->ephemerides != NULL, XLAL_EFAULT );
79
80 // Write metric type
81 XLAL_CHECK( XLALFITSHeaderWriteString( file, "metric-type", setup->metric_type, "metric type (for all-sky/directed searches)" ) == XLAL_SUCCESS, XLAL_EFUNC );
82
83 // Write reference time
84 XLAL_CHECK( XLALFITSHeaderWriteGPSTime( file, "date-obs", &setup->ref_time, "reference time" ) == XLAL_SUCCESS, XLAL_EFUNC );
85
86 // Write list of detector names
87 XLAL_CHECK( XLALFITSHeaderWriteStringVector( file, "detect", setup->detectors, "setup detectors" ) == XLAL_SUCCESS, XLAL_EFUNC );
88
89 // Write ephemerides
91
92 // Write segment list
93 XLAL_CHECK( XLALFITSWriteSegmentList( file, "segments", setup->segments, "segment list" ) == XLAL_SUCCESS, XLAL_EFUNC );
94
95 // Write supersky metrics
97
98 return XLAL_SUCCESS;
99
100}
101
102///
103/// Read setup data from a FITS file
104///
106 FITSFile *file,
107 WeaveSetupData *setup
108)
109{
110
111 // Check input
112 XLAL_CHECK( file != NULL, XLAL_EFAULT );
113 XLAL_CHECK( setup != NULL, XLAL_EFAULT );
114
115 // Erase memory
116 XLAL_INIT_MEM( *setup );
117
118 // Read metric type
119 int read_status;
120 read_status = XLALFITSHeaderReadString( file, "metric-type", &setup->metric_type );
121 if ( read_status != XLAL_SUCCESS ) {
122 // If not found, set it to 'all-sky'
123 const char *default_type = WeaveMetricTypeChoices[0].name; // "all-sky"
125 LogPrintf( LOG_NORMAL, "Setup file does not contain 'metric-type'. Defaulting to '%s'\n", default_type );
126 setup->metric_type = XLALStringDuplicate( default_type );
127
128 // Check that the string duplication was successful
129 XLAL_CHECK( setup->metric_type != NULL, XLAL_ENOMEM );
130 }
131
132 // Read reference time
133 XLAL_CHECK( XLALFITSHeaderReadGPSTime( file, "date-obs", &setup->ref_time ) == XLAL_SUCCESS, XLAL_EFUNC );
134
135 // Read list of detector names
136 XLAL_CHECK( XLALFITSHeaderReadStringVector( file, "detect", &setup->detectors ) == XLAL_SUCCESS, XLAL_EFUNC );
137 XLAL_CHECK( setup->detectors != NULL, XLAL_EFAULT );
138
139 // Read ephemerides
140 XLAL_CHECK( XLALFITSReadEphemerisData( file, &setup->ephemerides ) == XLAL_SUCCESS, XLAL_EFUNC );
141 XLAL_CHECK( setup->ephemerides != NULL, XLAL_EFAULT );
142
143 // Read segment list
144 XLAL_CHECK( XLALFITSReadSegmentList( file, "segments", &setup->segments ) == XLAL_SUCCESS, XLAL_EFUNC );
145 XLAL_CHECK( setup->ephemerides != NULL, XLAL_EFAULT );
146
147 // Read supersky metrics
149 XLAL_CHECK( setup->metrics != NULL, XLAL_EFAULT );
150
151 return XLAL_SUCCESS;
152
153}
154
155// Local Variables:
156// c-file-style: "linux"
157// c-basic-offset: 2
158// 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
const UserChoices WeaveMetricTypeChoices
Definitions of search type choices.
Definition: SetupData.c:41
void XLALWeaveSetupDataClear(WeaveSetupData *setup)
Free contents of setup data.
Definition: SetupData.c:50
int XLALWeaveSetupDataWrite(FITSFile *file, const WeaveSetupData *setup)
Write setup data to a FITS file.
Definition: SetupData.c:66
int XLALWeaveSetupDataRead(FITSFile *file, WeaveSetupData *setup)
Read setup data from a FITS file.
Definition: SetupData.c:105
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.
@ SUPERSKY_METRIC_TYPE
Metric for all-sky searches.
@ SUPERSKY_DIRECTED_METRIC_TYPE
Metric for directed searches.
#define XLAL_CHECK(assertion,...)
int XLALClearErrno(void)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFAULT
XLAL_EFUNC
const char * name