LALPulsar  6.1.0.1-89842e6
SFTReferenceLibrary.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Karl Wette
3  * Copyright (C) 2004, 2005 Bruce Allen, Reinhard Prix
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with with program; see the file COPYING. If not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301 USA
19  */
20 
21 #ifndef _SFTREFERENCELIBRARY_H /* Double-include protection. */
22 #define _SFTREFERENCELIBRARY_H
23 
24 #ifdef __cplusplus /* C++ protection. */
25 extern "C" {
26 #endif
27 
28 /**
29  * \defgroup SFTReferenceLibrary_h Header SFTReferenceLibrary.h
30  * \ingroup lalpulsar_sft
31  * \author Bruce Allen, Reinhard Prix
32  * \brief This is a reference library for the SFT data format \cite SFT-spec
33  */
34 
35 /** @{ */
36 
37 /* SFT header */
38 struct headertag2 {
39  double version;
40  int gps_sec;
41  int gps_nsec;
42  double tbase;
44  int nsamples;
45  unsigned long long crc64;
46  char detector[2];
47  unsigned short windowspec;
49 };
50 
51 int WriteSFT( FILE *fp, /* stream to write to. On return, is at the end of SFT */
52  int gps_sec, /* GPS sec of first sample */
53  int gps_nsec, /* GPS nsec of first sample */
54  double tbase, /* time baseline of SFTs */
55  int firstfreqindex, /* index of first frequency bin included in data (0=DC)*/
56  int nsamples, /* number of frequency bins to include in SFT */
57  const char *detector, /* channel-prefix defining detector */
58  unsigned short windowspec, /* SFT windowspec */
59  const char *comment, /* null-terminated comment string to include in SFT */
60  float *data /* points to nsamples x 2 x floats (Real/Imag) */
61  );
62 
63 int ReadSFTHeader( FILE *fp, /* stream to read. Position unchanged on return */
64  struct headertag2 *info, /* address to return header */
65  char **comment, /* if non-NULL, put pointer to comment */
66  int *swapendian, /* set nonzero if data in reverse endian order */
67  int validate ); /* validate checksum of the file */
68 
69 int ReadSFTData( FILE *fp, /* data file. Position unchanged on return */
70  float *data, /* location where data should be written */
71  int firstbin, /* first frequency bin to read from data set */
72  int nsamples, /* number of frequency bin samples to retrieve */
73  char **comment, /* if non-NULL, will contain pointer to comment string */
74  struct headertag2 *info /* if non-NULL, will contain header information */
75  );
76 
77 /* This routine returns zero if the two headers contain consistent
78  information, else an error code if they are not consistent */
79 int CheckSFTHeaderConsistency( struct headertag2 *headerone, /* pointer to earlier header */
80  struct headertag2 *headertwo /* pointer to later header */
81  );
82 
83 int ValidateSFTFile( const char *fname );
84 
85 /* various possible error codes. See SFTErrorMessage() for decodings */
86 #define SFTNOERROR 0 /* MUST BE ZERO, MEANS NO ERROR */
87 #define SFTENULLFP 1
88 #define SFTESEEK 2
89 #define SFTEGETSTREAMPOS 3
90 #define SFTERESTORESTREAMPOS 4
91 #define SFTEREAD 5
92 #define SFTEUNKNOWN 6
93 #define SFTEGPSNSEC 7
94 #define SFTEBADCOMMENT 8
95 #define SFTEBADCRC64 9
96 #define SFTENOMEM 10
97 #define SFTESIZEWRONG 11
98 #define SFTEWRITE 12
99 #define SFTENULLPOINTER 13
100 #define SFTENONE 14
101 #define SFTEHIDDENCOMMENT 15
102 #define SFTENONULLINCOMMENT 16
103 #define SFTEGPSNOTINCREASING 17
104 #define SFTETBASECHANGES 18
105 #define SFTEFIRSTINDEXCHANGES 19
106 #define SFTENSAMPLESCHANGES 20
107 #define SFTEINSTRUMENTCHANGES 21
108 #define SFTEVERSIONCHANGES 22
109 #define SFTETBASENOTPOS 23
110 #define SFTEFIRSTINDEXNEG 24
111 #define SFTENSAMPLESNOTPOS 25
112 #define SFTEINSTRUMENTUNKNOWN 26
113 #define SFTEBEFOREDATA 27
114 #define SFTEAFTERDATA 28
115 #define SFTNOTFINITE 29
116 #define SFTEWINDOWSPECCHANGES 300
117 
118 /* takes error code from above list and returns static human-readable
119  description as null-terminated string */
120 const char *SFTErrorMessage( int errorcode );
121 
122 /* internal functions for checking validity of detector-entry */
123 int unknownDetector( const char *detector ); /* returns zero if detector is known */
124 
125 /** @} */
126 
127 #ifdef __cplusplus
128 } /* Close C++ protection */
129 #endif
130 
131 #endif /* Close double-include protection _SFTREFERENCELIBRARY_H */
const char * comment
Definition: SearchTiming.c:94
const char * SFTErrorMessage(int errorcode)
int CheckSFTHeaderConsistency(struct headertag2 *headerone, struct headertag2 *headertwo)
int unknownDetector(const char *detector)
int ReadSFTHeader(FILE *fp, struct headertag2 *info, char **comment, int *swapendian, int validate)
int ValidateSFTFile(const char *fname)
Verify that the contents of a SFT file are valid.
int WriteSFT(FILE *fp, int gps_sec, int gps_nsec, double tbase, int firstfreqindex, int nsamples, const char *detector, unsigned short windowspec, const char *comment, float *data)
int ReadSFTData(FILE *fp, float *data, int firstbin, int nsamples, char **comment, struct headertag2 *info)
unsigned long long crc64
unsigned short windowspec