LALPulsar  6.1.0.1-fe68b98
SFTinternal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010, 2014, 2016, 2020, 2022 Karl Wette
3  * Copyright (C) 2010 Chris Messenger
4  * Copyright (C) 2004--2006, 2010 Reinhard Prix
5  * Copyright (C) 2004, 2005 Bernd Machenschalk
6  * Copyright (C) 2004, 2005 Alicia Sintes
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with with program; see the file COPYING. If not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23 
24 /**
25  * \file
26  * \ingroup SFTfileIO_h
27  * \brief Internal SFT types and functions
28  */
29 
30 /*---------- includes ----------*/
31 
32 #include <lal/SFTfileIO.h>
33 
34 /*---------- SFT versions ----------*/
35 
36 /**
37  * \name SFT versions
38  *
39  * - Version 1 (--2004):
40  * - No formal specification.
41  * - No longer supported.
42  * - Version 2 (2004--2022):
43  * - Specified in https://dcc.ligo.org/LIGO-T040164-v1/public.
44  * - Added header fields for detector name, checksum, comment string.
45  * - Incompatible with version 1.
46  * - Version 3 (2022--):
47  * - Specified in https://dcc.ligo.org/LIGO-T040164-v2/public.
48  * - Modified header to record window type and parameter.
49  * - Compatible with version 2.
50  */
51 /** @{ */
52 
53 #define MIN_SFT_VERSION 2
54 #define MAX_SFT_VERSION 3
55 
56 /** @} */
57 
58 /*---------- constants ----------*/
59 
60 #define TRUE 1
61 #define FALSE 0
62 
63 static const REAL8 fudge_up = 1 + 10 * LAL_REAL8_EPS; // about ~1 + 2e-15
64 static const REAL8 fudge_down = 1 - 10 * LAL_REAL8_EPS; // about ~1 - 2e-15
65 
66 /** size of blocks allocated for SFT data. For Einstein\@home SFTs this should be set to 8000 (externally) */
67 #ifndef SFTFILEIO_REALLOC_BLOCKSIZE
68 #define SFTFILEIO_REALLOC_BLOCKSIZE 100
69 #endif
70 
71 /*---------- macros ----------*/
72 
73 #if defined(__GNUC__)
74 #define UNUSED __attribute__ ((unused))
75 #else
76 #define UNUSED
77 #endif
78 
79 #define GPS2REAL8(gps) (1.0 * (gps).gpsSeconds + 1.e-9 * (gps).gpsNanoSeconds )
80 #define GPSEQUAL(gps1,gps2) (((gps1).gpsSeconds == (gps2).gpsSeconds) && ((gps1).gpsNanoSeconds == (gps2).gpsNanoSeconds))
81 #define GPSZERO(gps) (((gps).gpsSeconds == 0) && ((gps).gpsNanoSeconds == 0))
82 
83 /*---------- internal types ----------*/
84 
85 /* NOTE: the locator is implemented as an OPAQUE type in order to enforce encapsulation
86  * of the actual physical storage of SFTs and to ease future extensions of the interface.
87  * DO NOT TRY TO USE THIS TYPE OUTSIDE OF THIS MODULE!!
88  */
89 struct tagSFTLocator {
90  CHAR *fname; /* name of file containing this SFT */
91  long offset; /* SFT-offset with respect to a merged-SFT */
92  UINT4 isft; /* index of SFT this locator belongs to, used only in XLALLoadSFTs() */
93 };
94 
95 /*---------- internal prototypes ----------*/
96 
97 // These functions are defined in SFTtypes.c
98 
99 REAL8 TSFTfromDFreq( REAL8 dFreq );
100 
101 int compareSFTdesc( const void *ptr1, const void *ptr2 );
102 int compareSFTloc( const void *ptr1, const void *ptr2 );
103 int compareDetNameCatalogs( const void *ptr1, const void *ptr2 );
104 int compareSFTepoch( const void *ptr1, const void *ptr2 );
105 
106 // These functions are defined in SFTnaming.c
107 
108 int build_sft_windowspec( UINT2 *windowspec, CHAR( *windowspec_str )[9], const char *window_type, REAL8 window_param );
109 int parse_sft_windowspec( const UINT2 windowspec, const char **window_type, REAL8 *window_param );
110 int parse_sft_windowspec_str( const CHAR *windowspec_str, CHAR( *window_type )[32], REAL8 *window_param );
111 
112 // These functions are defined in SFTfileIO.c
113 
114 void endian_swap( CHAR *pdata, size_t dsize, size_t nelements );
115 
116 FILE *fopen_SFTLocator( const struct tagSFTLocator *locator );
117 
118 int read_SFTversion_from_fp( UINT4 *version, BOOLEAN *need_swap, FILE *fp );
119 int read_sft_header_from_fp( FILE *fp, SFTtype *header, UINT4 *version, UINT8 *crc64, UINT2 *SFTwindowspec, BOOLEAN *swapEndian, CHAR **SFTcomment, UINT4 *numBins );
120 UINT4 read_sft_bins_from_fp( SFTtype *ret, UINT4 *firstBinRead, UINT4 firstBin2read, UINT4 lastBin2read, FILE *fp );
121 
122 BOOLEAN has_valid_crc64( FILE *fp );
123 
124 // These functions are defined in SFTReferenceLibrary.c
125 
126 unsigned long long crc64( const unsigned char *data, unsigned int length, unsigned long long crc );
static const REAL8 fudge_up
Definition: SFTinternal.h:63
unsigned long long crc64(const unsigned char *data, unsigned int length, unsigned long long crc)
static const REAL8 fudge_down
Definition: SFTinternal.h:64
const char * window_type
Definition: SFTnaming.c:44
#define LAL_REAL8_EPS
unsigned char BOOLEAN
uint64_t UINT8
double REAL8
uint16_t UINT2
char CHAR
uint32_t UINT4
int parse_sft_windowspec(const UINT2 windowspec, const char **window_type, REAL8 *window_param)
Parse an SFT 2-byte 'windowspec' into a window name 'window_type' and possible parameter 'window_para...
Definition: SFTnaming.c:752
UINT4 read_sft_bins_from_fp(SFTtype *ret, UINT4 *firstBinRead, UINT4 firstBin2read, UINT4 lastBin2read, FILE *fp)
Definition: SFTfileIO.c:1282
REAL8 TSFTfromDFreq(REAL8 dFreq)
Definition: SFTtypes.c:1144
void endian_swap(CHAR *pdata, size_t dsize, size_t nelements)
Definition: SFTfileIO.c:844
int build_sft_windowspec(UINT2 *windowspec, CHAR(*windowspec_str)[9], const char *window_type, REAL8 window_param)
Build an SFT 2-byte 'windowspec' or filename field 'windowspec_str' for the window given by 'window_t...
Definition: SFTnaming.c:691
int read_sft_header_from_fp(FILE *fp, SFTtype *header, UINT4 *version, UINT8 *crc64, UINT2 *SFTwindowspec, BOOLEAN *swapEndian, CHAR **SFTcomment, UINT4 *numBins)
Definition: SFTfileIO.c:992
FILE * fopen_SFTLocator(const struct tagSFTLocator *locator)
Open an "SFT" defined by the SFT-locator, return a FILE-pointer to the beginning of this SFT.
Definition: SFTfileIO.c:882
int compareSFTloc(const void *ptr1, const void *ptr2)
Definition: SFTtypes.c:1182
int compareDetNameCatalogs(const void *ptr1, const void *ptr2)
Definition: SFTtypes.c:1208
int parse_sft_windowspec_str(const CHAR *windowspec_str, CHAR(*window_type)[32], REAL8 *window_param)
Parse an SFT filename field 'windowspec_str' into a window name 'window_type' and possible parameter ...
Definition: SFTnaming.c:802
BOOLEAN has_valid_crc64(FILE *fp)
Check the SFT-block starting at fp for valid crc64 checksum.
Definition: SFTfileIO.c:1409
int compareSFTdesc(const void *ptr1, const void *ptr2)
Definition: SFTtypes.c:1161
int compareSFTepoch(const void *ptr1, const void *ptr2)
Definition: SFTtypes.c:1231
int read_SFTversion_from_fp(UINT4 *version, BOOLEAN *need_swap, FILE *fp)
Read valid SFT version-number at position fp, and determine if we need to endian-swap the data.
Definition: SFTfileIO.c:916
CHAR * fname
Definition: SFTinternal.h:90