int main(int argc, char *argv[]){ static LALStatus status; /* LALStatus pointer */ static MultiSFTVector *inputSFTs = NULL; static SFTCatalog *catalog = NULL; static SFTCatalog thisCatalog; static SFTConstraints constraints; /* 09/09/05 gam; randPar now a parameter for LALCleanCOMPLEX8SFT */ FILE *fp=NULL; INT4 seed, ranCount; RandomParams *randPar=NULL; UINT4 k, j; /* user input variables */ BOOLEAN uvar_help; LALStringVector *uvar_linefiles=NULL; /* files with harmonics info */ CHAR *uvar_sftDir; /* directory for unclean sfts */ CHAR *uvar_outDir; /* directory for cleaned sfts */ REAL8 uvar_fMin, uvar_fMax; INT4 uvar_window, uvar_maxBins; /* set defaults */ uvar_help = FALSE; uvar_sftDir = (CHAR *)LALMalloc(256 * sizeof(CHAR)); strcpy(uvar_sftDir, INPUTSFTDIR); uvar_outDir = (CHAR *)LALMalloc(256 * sizeof(CHAR)); strcpy(uvar_outDir, OUTPUTSFTDIR); uvar_fMin = STARTFREQ; uvar_fMax = ENDFREQ; uvar_window = WINDOWSIZE; uvar_maxBins = MAXBINS; /* register user input variables */ LAL_CALL( LALRegisterBOOLUserVar( &status, "help", 'h',UVAR_HELP, "Print this message", &uvar_help), &status); LAL_CALL( LALRegisterSTRINGUserVar( &status, "sftDir", 'i',UVAR_OPTIONAL, "Input SFT file pattern", &uvar_sftDir), &status); LAL_CALL( LALRegisterSTRINGUserVar( &status, "outDir", 'o',UVAR_OPTIONAL, "Output SFT Directory", &uvar_outDir), &status); LAL_CALL( LALRegisterREALUserVar( &status, "fMin", 0, UVAR_OPTIONAL, "start Frequency", &uvar_fMin), &status); LAL_CALL( LALRegisterREALUserVar( &status, "fMax", 0, UVAR_OPTIONAL, "Max Frequency Band", &uvar_fMax), &status); LAL_CALL( LALRegisterINTUserVar( &status, "window", 'w',UVAR_OPTIONAL, "Window size", &uvar_window), &status); LAL_CALL( LALRegisterINTUserVar( &status, "maxBins", 'm',UVAR_OPTIONAL, "Max. bins to clean", &uvar_maxBins),&status); LAL_CALL( LALRegisterLISTUserVar( &status, "linefiles", 0, UVAR_OPTIONAL, "List of linefiles (filenames must contain IFO name)", &uvar_linefiles), &status); /* read all command line variables */ LAL_CALL( LALUserVarReadAllInput(&status, argc, argv), &status); /* exit if help was required */ if (uvar_help) exit(0); /* set detector constraint */ constraints.detector = NULL; /* get sft catalog */ LAL_CALL( LALSFTdataFind( &status, &catalog, uvar_sftDir, &constraints), &status); if ( (catalog == NULL) || (catalog->length == 0) ) { fprintf (stderr,"Unable to match any SFTs with pattern '%s'\n", uvar_sftDir ); exit(1); } thisCatalog.length = 1; fprintf(stdout, "%d\n",catalog->length); /* get a new seed value, and use it to create a new random parameter structure */ fp=fopen("/dev/urandom", "r"); if (!fp) { fprintf(stderr,"Error in opening /dev/urandom \n"); exit(1); } ranCount = fread(&seed, sizeof(seed), 1, fp); fclose(fp); if (!(ranCount==1)) { fprintf(stderr,"Error in reading random seed \n"); exit(1); } LAL_CALL ( LALCreateRandomParams (&status, &randPar, seed), &status ); /* loop over sfts and clean them -- load one sft at a time */ for (j=0; j<catalog->length; j++) { thisCatalog.data = catalog->data + j; /* read the sfts */ LAL_CALL( LALLoadMultiSFTs ( &status, &inputSFTs, &thisCatalog, uvar_fMin, uvar_fMax), &status); /* clean lines */ if ( LALUserVarWasSet( &uvar_linefiles ) ) { LAL_CALL( LALRemoveKnownLinesInMultiSFTVector ( &status, inputSFTs, uvar_maxBins, uvar_window, uvar_linefiles, randPar), &status); } /* write output */ for (k = 0; k < inputSFTs->length; k++) { LAL_CALL( LALWriteSFTVector2Dir ( &status, inputSFTs->data[k], uvar_outDir, "cleaned", "cleaned"), &status); } LAL_CALL( LALDestroyMultiSFTVector(&status, &inputSFTs), &status ); } /* end loop over sfts */ /* Free memory */ LAL_CALL( LALDestroySFTCatalog( &status, &catalog ), &status); LAL_CALL( LALDestroyUserVars(&status), &status); LAL_CALL( LALDestroyRandomParams (&status, &randPar), &status); LALCheckMemoryLeaks(); return 0; }
int main(int argc, char *argv[]) { const char *fn = __func__; LALStatus status = empty_status; SFTCatalog *catalog = NULL; SFTConstraints constraints = empty_constraints; SFTVector *sft_vect = NULL; SFTVector *sft_vect2 = NULL; MultiSFTVector *multsft_vect = NULL; MultiSFTVector *multsft_vect2 = NULL; CHAR detector[2] = "H1"; INT4 crc_check; /* band to read from infile.* SFTs */ REAL8 fMin = 1008.5; REAL8 fMax = 1009.1; if ( argc == 1) /* avoid warning */ argc = 1; /* check that mal-formated SFTs are properly detected */ SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad1", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad2", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad3", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad4", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad5", NULL ), &status); /* the following (SFT-bad6) has a wrong CRC64 checksum. However, this is * not checked in LALSFTdataFind, so it should succeed! */ SHOULD_WORK( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad6", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad7", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad8", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad9", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad10", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad11", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad12", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad13", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad14", NULL ), &status ); /* now check some crc-checksums */ SHOULD_WORK( LALCheckSFTs ( &status, &crc_check, TEST_DATA_DIR "SFT-test1", NULL ), &status ); if ( crc_check != 0 ) { XLALPrintError ("\nLALCheckSFTs(): SFT-test1 has correct checksum but LALCheckSFTs claimed it hasn't.\n\n"); return crc_check; } SHOULD_WORK( LALCheckSFTs ( &status, &crc_check, TEST_DATA_DIR "SFT-bad6", NULL ), &status ); if ( crc_check != SFTFILEIO_ECRC64 ) { XLALPrintError ( "\nLALCheckSFTs() failed to catch invalid CRC checksum in SFT-bad6 \n\n"); return SFTFILEIOTESTC_ESUB; } /* check that proper v2-SFTs are read-in properly */ SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test1", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test2", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test3", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test4", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test5", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test6", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test7", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* now completely read-in a v2 merged-SFT */ SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test*", NULL ), &status ); /* skip sft nr 4 with has Tsft=50 instead of Tsft=60 */ SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test[123567]*", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* try the same with a ";" separated list of files and of patterns */ SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test1;" TEST_DATA_DIR "SFT-test2;" TEST_DATA_DIR "SFT-test3;" TEST_DATA_DIR "SFT-test5;" TEST_DATA_DIR "SFT-test6;" TEST_DATA_DIR "SFT-test7", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test[123]*;" TEST_DATA_DIR "SFT-test[5]*", NULL ), &status ); /* load once as a single SFT-vector (mix of detectors) */ SHOULD_WORK ( LALLoadSFTs ( &status, &sft_vect, catalog, -1, -1 ), &status ); /* load once as a multi-SFT vector */ SHOULD_WORK ( LALLoadMultiSFTs ( &status, &multsft_vect, catalog, -1, -1 ), &status ); /* load again, using XLAL API */ if ( ( multsft_vect2 = XLALLoadMultiSFTs ( catalog, -1, -1 )) == NULL ) { XLALPrintError ("%s: XLALLoadMultiSFTs (cat, -1, -1) failed with xlalErrno = %d\n", fn, xlalErrno ); return SFTFILEIOTESTC_ESUB; } SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* 6 SFTs from 2 IFOs should have been read */ if ( (sft_vect->length != 4) /* either as a single SFTVector */ || (multsft_vect->length != 2) /* or separated by detector */ || (multsft_vect->data[0]->length != 3) || ( multsft_vect->data[1]->length != 1 ) ) { XLALPrintError ( "\nFailed to read in multi-SFT from 2 IFOs 'SFT-test*'!\n\n"); return SFTFILEIOTESTC_ESUB; } /* compare results from LALLoadMultiSFTs() and XLALLoadMultiSFTs() */ { UINT4 numIFOs = multsft_vect->length; UINT4 X; for ( X=0; X < numIFOs; X ++ ) { if( CompareSFTVectors ( multsft_vect->data[X], multsft_vect2->data[X] ) ) { XLALPrintError ("%s: comparing (X)LALLoadMultiSFTs(): sft-vectors differ for X=%d\n", fn, X ); return SFTFILEIOTESTC_ESUB; } } /* for X < numIFOs */ } /* ------ */ /* ----- v2 SFT writing ----- */ /* write v2-SFT to disk */ SHOULD_WORK ( LALWriteSFT2file( &status, &(multsft_vect->data[0]->data[0]), "outputsftv2_v2.sft", "A v2-SFT file for testing!"), &status ); SHOULD_WORK ( LALWriteSFTVector2Dir( &status, multsft_vect->data[0], ".", "A v2-SFT file for testing!", "test"), &status); /* write v2-SFT to single file */ { const CHAR *currSingleSFT = NULL; UINT4 i = 0; FILE *fpConcat = NULL, *fpSingle = NULL; int concat = 0, single = 0; xlalErrno = 0; if (XLAL_SUCCESS != XLALWriteSFTVector2File ( multsft_vect->data[0], ".", "A v2-SFT file for testing!", "test_concat" )) { LALPrintError ( "\n XLALWriteSFTVector2File failed to write multi-SFT vector to file!\n\n"); return SFTFILEIOTESTC_ESUB; } /* check that the single file SFT is the same as the single SFTs */ const UINT4 numSingleSFTs = 3; const CHAR *singleSFTs[] = { "H-1_H1_60SFT_test-000012345-61.sft", "H-1_H1_60SFT_test-000012465-61.sft", "H-1_H1_60SFT_test-000012585-61.sft" }; printf("*** Comparing single and concatenated SFTs ***\n"); /* try to open concatenated SFT */ const CHAR *concatSFT = "H-3_H1_60SFT_test_concat-000012345-302.sft"; if ( ( fpConcat = fopen(concatSFT, "rb" ) ) == NULL ) { LALPrintError ( "\n Cound not open SFT '%s'!\n\n", concatSFT); return SFTFILEIOTESTC_ESUB; } /* do loop while concat. SFT has data */ while (!feof(fpConcat)) { /* get character from concat. SFT */ concat = fgetc(fpConcat); if ( ferror(fpConcat) ) { LALPrintError ( "\n IO error reading '%s'!\n\n", concatSFT); return SFTFILEIOTESTC_ESUB; } /* get character from single SFT */ while (1) { /* need to open next single SFT file */ if (fpSingle == NULL) { /* break if we've run out of single SFTs */ if (i == numSingleSFTs) break; /* try to open single SFT */ if ( ( fpSingle = fopen(singleSFTs[i], "rb" ) ) == NULL ) { LALPrintError ( "\n Cound not open SFT '%s'!\n\n", singleSFTs[i]); return SFTFILEIOTESTC_ESUB; } currSingleSFT = singleSFTs[i]; } /* get character from single SFT */ single = fgetc(fpSingle); if ( ferror(fpSingle) ) { LALPrintError ( "\n IO error reading '%s'!\n\n", singleSFTs[i]); return SFTFILEIOTESTC_ESUB; } /* if single SFT is out of data, close it (open next one at beginning of loop) */ if (feof(fpSingle)) { fclose(fpSingle); fpSingle = NULL; ++i; } /* otherwise we have a valid character */ else break; } /* do character-by-character comparison */ if ( concat != single ) { LALPrintError ( "\n Comparison failed between '%s'(last char = %i) and '%s'(last char = %i)!!\n\n", concatSFT, concat, currSingleSFT, single ); return SFTFILEIOTESTC_ESFTDIFF; } } fclose(fpConcat); printf( "*** Comparing was successful!!! ***\n"); } /* write v2-SFt as a v1-SFT to disk (correct normalization) */ multsft_vect->data[0]->data[0].epoch.gpsSeconds += 60; /* shift start-time so they don't look like segmented SFTs! */ SHOULD_WORK ( LALWrite_v2SFT_to_v1file( &status, &(multsft_vect->data[0]->data[0]), "outputsftv2_v1.sft"), &status ); SUB ( LALDestroySFTVector ( &status, &sft_vect ), &status ); SUB ( LALDestroyMultiSFTVector (&status, &multsft_vect ), &status ); SUB ( LALDestroyMultiSFTVector (&status, &multsft_vect2 ), &status ); /* ----- read the previous two SFTs back */ SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, "outputsftv2_*.sft", NULL ), &status ); /* need to set proper detector! */ constraints.detector = detector; SUB ( LALSFTdataFind ( &status, &catalog, "outputsftv2_*.sft", &constraints ), &status); SUB ( LALLoadSFTs ( &status, &sft_vect, catalog, -1, -1 ), &status ); if ( sft_vect->length != 2 ) { if ( lalDebugLevel ) XLALPrintError ("\nFailed to read back in 'outputsftv2_*.sft'\n\n"); return SFTFILEIOTESTC_ESUB; } sft_vect2 = XLALLoadSFTs ( catalog, -1, -1 ); if (!sft_vect2) { XLALPrintError ( "\nXLALLoadSFTs() call failed (where it should have succeeded)!\n\n"); return SFTFILEIOTESTC_ESUB; } /* compare the SFT vectors just read */ if(CompareSFTVectors(sft_vect, sft_vect2)) return SFTFILEIOTESTC_ESUB; /* the data of 'outputsftv2_v2.sft' and 'outputsftv2_v1.sft' should agree, as the normalization * should be corrected again when reading-in */ { UINT4 i; UINT4 numBins = sft_vect->data[0].data->length; for ( i=0; i < numBins; i++) { COMPLEX8 *data1 = &(sft_vect->data[0].data->data[i]); COMPLEX8 *data2 = &(sft_vect->data[1].data->data[i]); if ( (crealf(*data1) != crealf(*data2)) || (cimagf(*data1) != cimagf(*data2)) ) { XLALPrintError ("\nv1- and v2- SFT differ after writing/reading\n\n"); return SFTFILEIOTESTC_ESFTDIFF; } } /* for i < numBins */ } SUB ( LALDestroySFTVector (&status, &sft_vect2 ), &status ); SUB ( LALDestroySFTVector (&status, &sft_vect ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* `----- v1 SFT writing */ /* read v1-SFTs: 'inputsft.0' and 'inputsft.1' (one is big-endian, the other little-endian!) */ SUB ( LALSFTdataFind (&status, &catalog, TEST_DATA_DIR "inputsft.?", &constraints ), &status ); SUB ( LALLoadSFTs ( &status, &sft_vect, catalog, fMin, fMax ), &status ); if ( sft_vect->length != 2 ) { if ( lalDebugLevel ) XLALPrintError ("\nFailed to read in v1-SFTs 'inputsft.0' and 'inputsft.1'\n\n"); return SFTFILEIOTESTC_ESUB; } /* read with XLALLoadSFTs() */ sft_vect2 = XLALLoadSFTs ( catalog, fMin, fMax ); if (!sft_vect2) { XLALPrintError ( "\nXLALLoadSFTs() call failed (where it should have succeeded)!\n\n"); return SFTFILEIOTESTC_ESUB; } /* compare the SFT vectors just read */ if(CompareSFTVectors(sft_vect, sft_vect2)) return SFTFILEIOTESTC_ESUB; /* write v1-SFT to disk */ SUB ( LALWriteSFTfile (&status, &(sft_vect->data[0]), "outputsft_v1.sft"), &status); /* try to write this v1-SFTs as v2: should fail without detector-info ! */ strncpy( sft_vect->data[0].name, "??", 2 ); SHOULD_FAIL (LALWriteSFT2file( &status, &(sft_vect->data[0]), "outputsft_v2.sft", "Another v2-SFT file for testing!"), &status ); /* put detector there */ strcpy ( sft_vect->data[0].name, "H1" ); SHOULD_WORK (LALWriteSFT2file( &status, &(sft_vect->data[0]), "outputsft_v2.sft", "Another v2-SFT file for testing!"), &status ); SUB ( LALDestroySFTVector (&status, &sft_vect2 ), &status ); SUB ( LALDestroySFTVector (&status, &sft_vect ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* ---------- test timestamps-reading functions by comparing LAL- and XLAL-versions against each other ---------- */ { #define TS_FNAME "testTimestamps.dat" LIGOTimeGPSVector *ts1 = NULL, *ts2 = NULL; /* ----- load timestamps with deprecated LAL function */ SUB ( LALReadTimestampsFile ( &status, &ts1, TEST_DATA_DIR TS_FNAME ), &status ); /* ----- load timestamps w new XLAL function */ if ( (ts2 = XLALReadTimestampsFile ( TEST_DATA_DIR TS_FNAME )) == NULL ) { XLALPrintError ("XLALReadTimestampsFile() failed to read timestamps from file '%s'. xlalErrno = %d\n", TS_FNAME ); return SFTFILEIOTESTC_ESUB; } /* ----- compare the two */ if ( ts1->length != ts2->length ) { XLALPrintError ("Read timestamps-lists differ in length %d != %d\n", ts1->length, ts2->length ); return 1; } if ( ts1->deltaT != ts2->deltaT ) { XLALPrintError ("Read timestamps-lists differ in deltaT %g != %g\n", ts1->deltaT, ts2->deltaT ); return 1; } UINT4 i, numTS = ts1->length; for ( i = 0; i < numTS; i ++ ) { if ( XLALGPSDiff( &ts1->data[i], &ts2->data[i]) != 0 ) { XLALPrintError ("Read timestamps-lists differ in entry %d: { %d, %d } != { %d, %d }\n", i + 1, ts1->data[i].gpsSeconds, ts1->data[i].gpsNanoSeconds, ts2->data[i].gpsSeconds, ts2->data[i].gpsNanoSeconds ); return 1; } } /* for i < numTS */ /* free mem */ XLALDestroyTimestampVector ( ts1 ); XLALDestroyTimestampVector ( ts2 ); } /* ------------------------------ */ LALCheckMemoryLeaks(); XLALPrintError ("\n\n--------------------------------------------------------------------------------\n"); XLALPrintError ("\n OK. All tests passed correctly ! (error-messages above are OK!)\n"); XLALPrintError ("\n--------------------------------------------------------------------------------\n"); INFO( SFTFILEIOTESTC_MSGENORM ); return SFTFILEIOTESTC_ENORM; }