Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-3a66518
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
dumpSFT.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004, 2005, 2013 Reinhard Prix
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/**
22 * \author Reinhard Prix
23 * \date 2005, 2013
24 * \file
25 * \ingroup lalpulsar_bin_SFTTools
26 * \brief Code to dump various SFT-info in human-readable form to stdout.
27 */
28
29/* ---------- includes ---------- */
30#include "config.h"
31
32#include <lal/UserInput.h>
33#include <lal/SFTfileIO.h>
34#include <lal/PulsarDataTypes.h>
35#include <lal/LALString.h>
36#include <lal/LALPulsarVCSInfo.h>
37
38/*---------- DEFINES ----------*/
39#define MIN(x,y) ((x) < (y) ? (x) : (y))
40
41/*----- Macros ----- */
42
43/*---------- internal types ----------*/
44/*---------- empty initializers ---------- */
45/*---------- Global variables ----------*/
46
47/* User variables */
48typedef struct {
55
56/*---------- internal prototypes ----------*/
57int XLALprintDescriptor( const SFTDescriptor *ptr );
58int XLALprintHeader( const SFTtype *header );
59int XLALprintData( const SFTtype *sft );
60int XLALprintTimestamps( const SFTCatalog *catalog, const UINT4 Nmax );
61
62int XLALReadUserInput( int argc, char *argv[], UserVariables_t *uvar );
63
64/*==================== FUNCTION DEFINITIONS ====================*/
65
66/*----------------------------------------------------------------------
67 * main function
68 *----------------------------------------------------------------------*/
69int
70main( int argc, char *argv[] )
71{
72 /* register all our user-variable */
74 XLAL_CHECK( XLALReadUserInput( argc, argv, &uvar ) == XLAL_SUCCESS, XLAL_EFUNC );
75
76 SFTCatalog *catalog;
77 XLAL_CHECK( ( catalog = XLALSFTdataFind( uvar.SFTfiles, NULL ) ) != NULL, XLAL_EFUNC, "No SFTs matched your --SFTfiles query\n" );
78 if ( XLALUserVarWasSet( &uvar.Nmax ) && ( uvar.Nmax > catalog->length ) ) {
79 XLALPrintWarning( "Nmax=%u requested but SFT catalog has only %u entries. Returning them all.", uvar.Nmax, catalog->length );
80 }
81
82 if ( uvar.headerOnly ) {
83 for ( UINT4 i = 0; i < MIN( uvar.Nmax, catalog->length ); i ++ ) {
84 SFTDescriptor *ptr = &( catalog->data[i] );
85
86 XLALprintHeader( &( ptr->header ) );
88
89 } // for i < catalog->length
90 } // if --headerOnly
91 else if ( uvar.timestampsOnly ) {
92 XLAL_CHECK( XLALprintTimestamps( catalog, uvar.Nmax ) == XLAL_SUCCESS, XLAL_EFUNC );
93 } // if --timestampsOnly
94 else { // if --dataOnly or data+headers [default]
95 SFTVector *sfts;
96 XLAL_CHECK( ( sfts = XLALLoadSFTs( catalog, -1, -1 ) ) != NULL, XLAL_EFUNC );
97
98 BOOLEAN segmentedSFTs = 0;
99 if ( sfts->length < catalog->length ) {
100 segmentedSFTs = 1;
101 printf( "\n" );
102 printf( "%%%% Frequency-segmented SFTs: len(catalog) = %d, len(sft-vector) = %d\n", catalog->length, sfts->length );
103 if ( !uvar.dataOnly ) {
104 printf( "%%%% For segmented SFTS we can't output SFT 'descriptors' + data. Use --headerOnly if you need the descriptor fields\n\n" );
105 }
106 } // if we're dealing with 'segmented SFTs': currently can't map them to catalog-descriptors
107
108 for ( UINT4 i = 0; i < MIN( uvar.Nmax, sfts->length ); i ++ ) {
109 SFTtype *sft_i = &( sfts->data[i] );;
110
111 if ( !uvar.dataOnly ) {
112 XLALprintHeader( sft_i );
113 if ( !segmentedSFTs ) { // skip descriptor fields for segmented SFTs (as we can't map them to SFTs)
114 XLALprintDescriptor( &( catalog->data[i] ) );
115 }
116 } // output header info
117
118 XLALprintData( sft_i );
119
120 } // for i < num_sfts
121
122 XLALDestroySFTVector( sfts );
123 } /* if !headerOnly */
124
125 /* free memory */
126 XLALDestroySFTCatalog( catalog );
128
130
131 return 0;
132} /* main */
133
134int
136{
137 XLAL_CHECK( desc != NULL, XLAL_EINVAL );
138
139 printf( "%%%% ----- Descriptor:\n" );
140 printf( "Locator: '%s'\n", XLALshowSFTLocator( desc->locator ) );
141 printf( "SFT version: %d\n", desc->version );
142 printf( "numBins: %d\n", desc->numBins );
143 printf( "crc64: %" LAL_UINT8_FORMAT "\n", desc->crc64 );
144 printf( "window: %s(%0.10g)\n", desc->window_type, desc->window_param );
145 if ( desc->comment ) {
146 if ( strchr( desc->comment, '\n' ) ) {
147 printf( "comment: ==========\n%s\nend comment: ------\n", desc->comment );
148 } else {
149 printf( "comment: %s\n", desc->comment );
150 }
151 } else {
152 printf( "comment: <none>\n" );
153 }
154
155 return XLAL_SUCCESS;
156
157} // XLALprintDescriptor()
158
159
160int
162{
163 XLAL_CHECK( header != NULL, XLAL_EINVAL );
164
165 printf( "%%%% ----- Header:\n" );
166 printf( "Name: '%s'\n", header->name );
167 printf( "epoch: [%d, %d]\n", header->epoch.gpsSeconds, header->epoch.gpsNanoSeconds );
168 printf( "f0: %.9f\n", header->f0 );
169 printf( "deltaF: %.9g\n", header->deltaF );
170 if ( header->data ) {
171 printf( "numBins: %d\n", header->data->length );
172 }
173
174 return XLAL_SUCCESS;
175} // XLALprintHeader()
176
177int
179{
180 XLAL_CHECK( ( sft != NULL ) && ( sft->data != NULL ), XLAL_EINVAL );
181
182 printf( "%%%% ----- Data x(f):\n" );
183 printf( "%%%% Frequency f[Hz] Real(x) Imag(x) \n" );
184 for ( UINT4 k = 0; k < sft->data->length; k ++ ) {
185 printf( "%.9f % 6e % 6e \n", sft->f0 + k * sft->deltaF, crealf( sft->data->data[k] ), cimagf( sft->data->data[k] ) );
186 }
187
188 return XLAL_SUCCESS;
189
190} // XLALprintData()
191
192// output timestamps in a format parseable by XLALReadTimestampsFile(), ie.
193// "The timestamps file is of the format: <repeated lines of the form "seconds nano-seconds">
194// allowing for '%#' as comments, which are ignored."
195int
196XLALprintTimestamps( const SFTCatalog *catalog, const UINT4 Nmax )
197{
198 XLAL_CHECK( ( catalog != NULL ) && ( catalog->data != NULL ), XLAL_EINVAL );
199
200 // print fully descriptive commented header-log for reproducibility:
201 char *version;
203 char *cmdline;
204 XLAL_CHECK( ( cmdline = XLALUserVarGetLog( UVAR_LOGFMT_CMDLINE ) ) != NULL, XLAL_EFUNC );
205
206 char *logstr = NULL;
207 XLAL_CHECK( ( logstr = XLALStringAppend( logstr, version ) ) != NULL, XLAL_EFUNC );
208 XLALFree( version );
209 XLAL_CHECK( ( logstr = XLALStringAppend( logstr, "%% cmdline: " ) ) != NULL, XLAL_EFUNC );
210 XLAL_CHECK( ( logstr = XLALStringAppend( logstr, cmdline ) ) != NULL, XLAL_EFUNC );
211 XLALFree( cmdline );
212 XLAL_CHECK( ( logstr = XLALStringAppend( logstr, "\n" ) ) != NULL, XLAL_EFUNC );
213 printf( "%s", logstr );
214 XLALFree( logstr );
215
216 // print timestamps
217 printf( "%%%% Timestamps: seconds nano-seconds\n" );
218 for ( UINT4 i = 0; i < MIN( Nmax, catalog->length ); i ++ ) {
219 const SFTtype *header = &( catalog->data[i].header );
220 printf( "%10d %09d\n", header->epoch.gpsSeconds, header->epoch.gpsNanoSeconds );
221 }
222
223 return XLAL_SUCCESS;
224
225} // XLALprintTimestamps()
226
227int
228XLALReadUserInput( int argc, char *argv[], UserVariables_t *uvar )
229{
230 /* set a few defaults */
231 uvar->Nmax = LAL_UINT4_MAX;
232
233 XLALRegisterUvarMember( SFTfiles, STRING, 'i', REQUIRED, "File-pattern for input SFTs. Possibilities are:\n"
234 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'" );
235 XLALRegisterUvarMember( headerOnly, BOOLEAN, 'H', OPTIONAL, "Output only SFT headers" );
236 XLALRegisterUvarMember( dataOnly, BOOLEAN, 'd', OPTIONAL, "Output only SFT data, no header info" );
237 XLALRegisterUvarMember( timestampsOnly, BOOLEAN, 't', OPTIONAL, "Output only timestamps, in timestamps-file format" );
238 XLALRegisterUvarMember( Nmax, UINT4, 'N', OPTIONAL, "When run on multiple SFTs, exit after this many" );
239
240 /* read cmdline & cfgfile */
241 BOOLEAN should_exit = 0;
243 if ( should_exit ) {
244 exit( 1 );
245 }
246
247 // ---------- sanity input checks ----------
248 XLAL_CHECK( UVAR_SET3( headerOnly, dataOnly, timestampsOnly ) <= 1, XLAL_EINVAL, "Contradictory input: at most *one* of --headerOnly, --dataOnly or --timestampsOnly allowed\n" );
249 XLAL_CHECK( uvar->Nmax > 0, XLAL_EINVAL );
250
251 return XLAL_SUCCESS;
252
253} // XLALReadUserInput()
ProcessParamsTable * ptr
int k
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define STRING(a)
int main(int argc, char *argv[])
Definition: dumpSFT.c:70
int XLALprintData(const SFTtype *sft)
Definition: dumpSFT.c:178
#define MIN(x, y)
Definition: dumpSFT.c:39
int XLALReadUserInput(int argc, char *argv[], UserVariables_t *uvar)
Definition: dumpSFT.c:228
int XLALprintDescriptor(const SFTDescriptor *ptr)
Definition: dumpSFT.c:135
int XLALprintTimestamps(const SFTCatalog *catalog, const UINT4 Nmax)
Definition: dumpSFT.c:196
int XLALprintHeader(const SFTtype *header)
Definition: dumpSFT.c:161
#define LAL_UINT4_MAX
unsigned char BOOLEAN
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
void XLALFree(void *p)
#define LAL_UINT8_FORMAT
int char * XLALStringAppend(char *s, const char *append)
char * XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
void XLALDestroySFTVector(SFTVector *vect)
XLAL interface to destroy an SFTVector.
Definition: SFTtypes.c:300
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
Definition: SFTcatalog.c:329
SFTVector * XLALLoadSFTs(const SFTCatalog *catalog, REAL8 fMin, REAL8 fMax)
Load the given frequency-band [fMin, fMax) (half-open) from the SFT-files listed in the SFT-'catalogu...
Definition: SFTfileIO.c:87
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
Definition: SFTcatalog.c:71
const CHAR * XLALshowSFTLocator(const struct tagSFTLocator *locator)
Mostly for debugging purposes: provide a user-API to allow inspecting the SFT-locator [which is an OP...
Definition: SFTcatalog.c:602
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterUvarMember(name, type, option, category,...)
void CHAR * XLALUserVarGetLog(UserVarLogFormat format)
int XLALUserVarWasSet(const void *cvar)
#define UVAR_SET3(n1, n2, n3)
UVAR_LOGFMT_CMDLINE
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
int int XLALPrintWarning(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EINVAL
desc
COMPLEX8Sequence * data
A vector of COMPLEX8FrequencySeries.
COMPLEX8FrequencySeries * data
Pointer to the data array.
UINT4 length
Number of elements in array.
COMPLEX8 * data
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
Definition: SFTfileIO.h:238
SFTDescriptor * data
array of data-entries describing matched SFTs
Definition: SFTfileIO.h:243
UINT4 length
number of SFTs in catalog
Definition: SFTfileIO.h:242
A 'descriptor' of an SFT: basically containing the header-info plus an opaque description of where ex...
Definition: SFTfileIO.h:226
SFTtype header
SFT-header info.
Definition: SFTfileIO.h:228
user input variables
Definition: compareFstats.c:51
BOOLEAN dataOnly
Definition: dumpSFT.c:51
BOOLEAN headerOnly
Definition: dumpSFT.c:50
BOOLEAN timestampsOnly
Definition: dumpSFT.c:52
UINT4 Nmax
Definition: dumpSFT.c:53
CHAR * SFTfiles
Definition: dumpSFT.c:49