28#include <lal/LogPrintf.h>
29#include <lal/UserInput.h>
30#include <lal/FrequencySeries.h>
31#include <lal/SFTfileIO.h>
32#include <lal/NormalizeSFTRngMed.h>
33#include <lal/LALPulsarVCSInfo.h>
37int main(
int argc,
char **argv )
39 lalUserVarHelpBrief =
"Normalize and average SFTs and compute spectrogram from SFTs for Fscan";
40 lalUserVarHelpDescription =
"Provide SFTs to this program for computing normalized and averaged spectra and spectrogram saved as ASCII data files for use by Fscan";
42 FILE *
fp = NULL, *fp2 = NULL, *fp3 = NULL, *fp4 = NULL;
52 CHAR outbase[256],
outfile[512], outfile2[512], outfile3[512], outfile4[512];
54 CHAR *SFTpatt = NULL, *
IFO = NULL, *outputDir = NULL, *outputBname = NULL, *
header = NULL;
55 INT4 startGPS = 0, endGPS = 0;
56 REAL8 f_min = 0.0,
f_max = 0.0, freqres = 0.1, subband = 100.0, timebaseline = 0;
57 INT4 blocksRngMed = 101, cur_epoch = 0;
71 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'" ) ==
XLAL_SUCCESS,
XLAL_EFUNC );
94 endTime.gpsSeconds = endGPS;
95 startTime.gpsNanoSeconds = endTime.gpsNanoSeconds = 0;
99 constraints.maxStartTime = &endTime;
100 constraints.detector =
IFO;
109 if ( allow_skipping ) {
125 snprintf( outbase,
sizeof( outbase ),
"%s/%s", outputDir, outputBname );
127 snprintf( outbase,
sizeof( outbase ),
"%s/spec_%.2f_%.2f_%s_%d_%d", outputDir,
f_min,
f_max, constraints.detector,
startTime.gpsSeconds, endTime.gpsSeconds );
131 snprintf(
outfile,
sizeof(
outfile ),
"%s_spectrogram.txt", outbase );
132 snprintf( outfile2,
sizeof( outfile2 ),
"%s_timestamps.txt", outbase );
133 snprintf( outfile4,
sizeof( outfile4 ),
"%s_date.txt", outbase );
139 fp2 = fopen( outfile2,
"w" );
141 XLAL_CHECK_MAIN( fp2 != NULL,
XLAL_EIO,
"Failed to open '%s' for writing: %s", outfile2, strerror( fopenerr ) );
142 fp4 = fopen( outfile4,
"w" );
144 XLAL_CHECK_MAIN( fp4 != NULL,
XLAL_EIO,
"Failed to open '%s' for writing: %s", outfile4, strerror( fopenerr ) );
163 printf(
"Looping over SFTs to compute average spectra and spectrograms\n" );
165 fprintf( stderr,
"Extracting SFT %d...\n",
j );
186 if ( spectrogram_blocksize < 1.0 ) {
189 NumBinsAvg = (
UINT4 )spectrogram_blocksize;
233 if (
i == NumBinsAvg - 1 ) {
237 for (
UINT4 k = 0;
k < NumBinsAvg;
k++ ) {
240 avg += 2.0 * ( re * re + im * im ) / (
REAL8 )timebaseline;
247 if (
j < ( catalog->
length - 1 ) ) {
249 while ( cur_epoch + timebaseline < catalog->
data[
j + 1].
header.epoch.gpsSeconds ) {
250 cur_epoch += timebaseline;
260 if (
i == NumBinsAvg - 1 ) {
279 timeavg->
data[
i] += re * re + im * im;
294 if ( f_max_subband >
f_max ) {
295 f_max_subband =
f_max;
300 snprintf( outbase,
sizeof( outbase ),
"%s/%s_%.2f_%.2f", outputDir, outputBname, f_min_subband, f_max_subband );
302 snprintf( outbase,
sizeof( outbase ),
"%s/spec_%.2f_%.2f_%s_%d_%d", outputDir, f_min_subband, f_max_subband, constraints.detector,
startTime.gpsSeconds, endTime.gpsSeconds );
304 snprintf( outfile3,
sizeof( outfile3 ),
"%s_timeaverage.txt", outbase );
305 fp3 = fopen( outfile3,
"w" );
307 XLAL_CHECK_MAIN( fp3 != NULL,
XLAL_EIO,
"Failed to open '%s' for writing: %s", outfile3, strerror( fopenerr ) );
312 fprintf( fp3,
"%16.6f %16.3f \n",
f, PWR );
314 if (
f +
deltaF >= f_max_subband ) {
335 fprintf( stderr,
"end of spec_avg\n" );
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
LIGOTimeGPSVector * timestamps
SFTVector * extract_one_sft(const SFTCatalog *full_catalog, const LIGOTimeGPS starttime, const REAL8 f_min, const REAL8 f_max)
REAL8FrequencySeries * XLALCreateREAL8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL8FrequencySeries(REAL8FrequencySeries *series)
#define XLAL_INIT_DECL(var,...)
char char * XLALStringDuplicate(const char *s)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
int XLALNormalizeSFT(REAL8FrequencySeries *rngmed, SFTtype *sft, UINT4 blockSize, const REAL8 assumeSqrtS)
Normalize an sft based on RngMed estimated PSD, and returns running-median.
void XLALDestroySFTVector(SFTVector *vect)
XLAL interface to destroy an SFTVector.
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
INT4Vector * XLALResizeINT4Vector(INT4Vector *vector, UINT4 length)
INT4Vector * XLALCreateINT4Vector(UINT4 length)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
void XLALDestroyINT4Vector(INT4Vector *vector)
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
#define XLAL_CHECK_MAIN(assertion,...)
#define XLAL_ERROR_MAIN(...)
#define XLAL_TRY(statement, errnum)
int main(int argc, char **argv)
A vector of COMPLEX8FrequencySeries.
COMPLEX8FrequencySeries * data
Pointer to the data array.
UINT4 length
Number of elements in array.
LIGOTimeGPS * data
array of timestamps
UINT4 length
number of timestamps
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
SFTDescriptor * data
array of data-entries describing matched SFTs
UINT4 length
number of SFTs in catalog
'Constraints' for SFT-matching: which detector, within which time-stretch and which timestamps exactl...
SFTtype header
SFT-header info.