LALPulsar  6.1.0.1-89842e6
FITSPulsarIO.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 #include <lal/FITSPulsarIO.h>
21 
22 ///
23 /// Initialise a FITS table for writing/reading a table of LALSeg entries
24 ///
26  FITSFile *file
27 )
28 {
29  XLAL_CHECK( file != NULL, XLAL_EFAULT );
34  return XLAL_SUCCESS;
35 }
36 
38  FITSFile *file,
39  const CHAR *name,
40  const LALSegList *segments,
41  const CHAR *comment
42 )
43 {
44 
45  // Check input
46  XLAL_CHECK( file != NULL, XLAL_EFAULT );
47  XLAL_CHECK( name != NULL, XLAL_EFAULT );
48  XLAL_CHECK( segments != NULL, XLAL_EFAULT );
49  XLAL_CHECK( comment != NULL, XLAL_EFAULT );
50 
51  // Write segment list to a FITS table
54  for ( size_t i = 0; i < segments->length; ++i ) {
56  }
57 
58  return XLAL_SUCCESS;
59 
60 }
61 
63  FITSFile *file,
64  const CHAR *name,
65  LALSegList **segments
66 )
67 {
68 
69  // Check input
70  XLAL_CHECK( file != NULL, XLAL_EFAULT );
71  XLAL_CHECK( name != NULL, XLAL_EFAULT );
72  XLAL_CHECK( segments != NULL && *segments == NULL, XLAL_EFAULT );
73 
74  // Read segment list from a FITS table
75  UINT8 nrows = 0;
78  *segments = XLALSegListCreate();
79  XLAL_CHECK( *segments != NULL, XLAL_EFUNC );
80  while ( nrows > 0 ) {
81  LALSeg XLAL_INIT_DECL( seg );
83  XLAL_CHECK( XLALSegListAppend( *segments, &seg ) == XLAL_SUCCESS, XLAL_EFUNC );
84  }
85 
86  return XLAL_SUCCESS;
87 
88 }
89 
90 ///
91 /// Initialise a FITS table for writing/reading a table of PosVelAcc entries
92 ///
94  FITSFile *file
95 )
96 {
97  XLAL_CHECK( file != NULL, XLAL_EFAULT );
103  return XLAL_SUCCESS;
104 }
105 
107  FITSFile *file,
109 )
110 {
111 
112  // Check input
113  XLAL_CHECK( file != NULL, XLAL_EFAULT );
114  XLAL_CHECK( ephemerides != NULL, XLAL_EFAULT );
115 
116  // Write Earth ephemerides to a FITS table
117  {
118  XLAL_CHECK( XLALFITSTableOpenWrite( file, "earth_ephem", "Earth ephemeris" ) == XLAL_SUCCESS, XLAL_EFUNC );
120  for ( INT4 i = 0; i < ephemerides->nentriesE; ++i ) {
122  }
123  XLAL_CHECK( XLALFITSHeaderWriteString( file, "filename", ephemerides->filenameE, "ephemeris filename" ) == XLAL_SUCCESS, XLAL_EFUNC );
124  XLAL_CHECK( XLALFITSHeaderWriteUINT4( file, "etype", ephemerides->etype, "ephemeris type" ) == XLAL_SUCCESS, XLAL_EFUNC );
125  XLAL_CHECK( XLALFITSHeaderWriteREAL8( file, "dttable", ephemerides->dtEtable, "spacing in seconds" ) == XLAL_SUCCESS, XLAL_EFUNC );
126  }
127 
128  // Write Sun ephemerides to a FITS table
129  {
130  XLAL_CHECK( XLALFITSTableOpenWrite( file, "sun_ephem", "Sun ephemeris" ) == XLAL_SUCCESS, XLAL_EFUNC );
132  for ( INT4 i = 0; i < ephemerides->nentriesS; ++i ) {
134  }
135  XLAL_CHECK( XLALFITSHeaderWriteString( file, "filename", ephemerides->filenameS, "ephemeris filename" ) == XLAL_SUCCESS, XLAL_EFUNC );
136  XLAL_CHECK( XLALFITSHeaderWriteUINT4( file, "etype", ephemerides->etype, "ephemeris type" ) == XLAL_SUCCESS, XLAL_EFUNC );
137  XLAL_CHECK( XLALFITSHeaderWriteREAL8( file, "dttable", ephemerides->dtStable, "spacing in seconds" ) == XLAL_SUCCESS, XLAL_EFUNC );
138  }
139 
140  return XLAL_SUCCESS;
141 
142 }
143 
145  FITSFile *file,
147 )
148 {
149 
150  // Check input
151  XLAL_CHECK( file != NULL, XLAL_EFAULT );
152  XLAL_CHECK( ephemerides != NULL && *ephemerides == NULL, XLAL_EFAULT );
153 
154  // Allocate memory
155  *ephemerides = XLALCalloc( 1, sizeof( **ephemerides ) );
156  XLAL_CHECK( *ephemerides != NULL, XLAL_ENOMEM );
157 
158  // Read Earth ephemerides from a FITS table
159  {
160  UINT8 nrows = 0;
161  XLAL_CHECK( XLALFITSTableOpenRead( file, "earth_ephem", &nrows ) == XLAL_SUCCESS, XLAL_EFUNC );
163  ( *ephemerides )->nentriesE = nrows;
164  ( *ephemerides )->ephemE = XLALCalloc( ( *ephemerides )->nentriesE, sizeof( ( *ephemerides )->ephemE[0] ) );
165  XLAL_CHECK( ( *ephemerides )->ephemE != NULL, XLAL_ENOMEM );
166  for ( INT4 i = 0; i < ( *ephemerides )->nentriesE; ++i ) {
167  XLAL_CHECK( XLALFITSTableReadRow( file, &( *ephemerides )->ephemE[i], NULL ) == XLAL_SUCCESS, XLAL_EFUNC );
168  }
169  XLAL_CHECK( XLALFITSHeaderReadString( file, "filename", &( *ephemerides )->filenameE ) == XLAL_SUCCESS, XLAL_EFUNC );
170  UINT4 etype = 0;
172  ( *ephemerides )->etype = etype;
173  XLAL_CHECK( XLALFITSHeaderReadREAL8( file, "dttable", &( *ephemerides )->dtEtable ) == XLAL_SUCCESS, XLAL_EFUNC );
174  }
175 
176  // Read Sun ephemerides from a FITS table
177  {
178  UINT8 nrows = 0;
179  XLAL_CHECK( XLALFITSTableOpenRead( file, "sun_ephem", &nrows ) == XLAL_SUCCESS, XLAL_EFUNC );
181  ( *ephemerides )->nentriesS = nrows;
182  ( *ephemerides )->ephemS = XLALCalloc( ( *ephemerides )->nentriesS, sizeof( ( *ephemerides )->ephemS[0] ) );
183  XLAL_CHECK( ( *ephemerides )->ephemS != NULL, XLAL_ENOMEM );
184  for ( INT4 i = 0; i < ( *ephemerides )->nentriesS; ++i ) {
185  XLAL_CHECK( XLALFITSTableReadRow( file, &( *ephemerides )->ephemS[i], NULL ) == XLAL_SUCCESS, XLAL_EFUNC );
186  }
187  XLAL_CHECK( XLALFITSHeaderReadString( file, "filename", &( *ephemerides )->filenameS ) == XLAL_SUCCESS, XLAL_EFUNC );
188  UINT4 etype = 0;
190  XLAL_CHECK( ( *ephemerides )->etype == ( EphemerisType ) etype, XLAL_EIO );
191  XLAL_CHECK( XLALFITSHeaderReadREAL8( file, "dttable", &( *ephemerides )->dtStable ) == XLAL_SUCCESS, XLAL_EFUNC );
192  }
193 
194  return XLAL_SUCCESS;
195 
196 }
197 
198 // Local Variables:
199 // c-file-style: "linux"
200 // c-basic-offset: 2
201 // End:
int XLALFITSHeaderReadREAL8(FITSFile UNUSED *file, const CHAR UNUSED *key, REAL8 UNUSED *value)
Definition: FITSFileIO.c:1184
int XLALFITSHeaderWriteUINT4(FITSFile UNUSED *file, const CHAR UNUSED *key, const UINT4 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:762
int XLALFITSTableWriteRow(FITSFile UNUSED *file, const void UNUSED *record)
Definition: FITSFileIO.c:2550
int XLALFITSTableReadRow(FITSFile UNUSED *file, void UNUSED *record, UINT8 UNUSED *rem_nrows)
Definition: FITSFileIO.c:2621
int XLALFITSTableOpenWrite(FITSFile UNUSED *file, const CHAR UNUSED *name, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:2162
int XLALFITSHeaderWriteREAL8(FITSFile UNUSED *file, const CHAR UNUSED *key, const REAL8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1150
int XLALFITSHeaderReadUINT4(FITSFile UNUSED *file, const CHAR UNUSED *key, UINT4 UNUSED *value)
Definition: FITSFileIO.c:797
int XLALFITSTableOpenRead(FITSFile UNUSED *file, const CHAR UNUSED *name, UINT8 UNUSED *nrows)
Definition: FITSFileIO.c:2198
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
static int fits_table_init_LALSeg(FITSFile *file)
Initialise a FITS table for writing/reading a table of LALSeg entries.
Definition: FITSPulsarIO.c:25
static int fits_table_init_PosVelAcc(FITSFile *file)
Initialise a FITS table for writing/reading a table of PosVelAcc entries.
Definition: FITSPulsarIO.c:93
const char * name
Definition: SearchTiming.c:93
const char * comment
Definition: SearchTiming.c:94
#define XLAL_FITS_TABLE_COLUMN_BEGIN(record_type)
Definition: FITSFileIO.h:239
#define XLAL_FITS_TABLE_COLUMN_ADD_NAMED(file, type, field, col_name)
Definition: FITSFileIO.h:246
#define XLAL_FITS_TABLE_COLUMN_ADD_ARRAY(file, type, field)
Definition: FITSFileIO.h:249
#define XLAL_FITS_TABLE_COLUMN_ADD(file, type, field)
Definition: FITSFileIO.h:243
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
EphemerisType
Enumerated type denoting the JPL solar system ephemeris to be used in calculating barycentre time cor...
Definition: LALBarycenter.h:86
uint64_t UINT8
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
int32_t INT4
void * XLALCalloc(size_t m, size_t n)
int XLALSegListAppend(LALSegList *seglist, const LALSeg *seg)
LALSegList * XLALSegListCreate(void)
#define XLAL_CHECK(assertion,...)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFAULT
XLAL_EFUNC
XLAL_EIO
pos
end
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
UINT4 length
LALSeg * segs
Structure holding a REAL8 time, and a position, velocity and acceleration vector.