/** * Load all SFTs according to user-input, returns multi-SFT vector. * \return cfg: * Returns 'effective' range of SFT-bins [firstBin, lastBin], which which the PSD will be estimated: * - if the user input {fStart, fBand} then these are loaded from SFTs and directly translated into bins * - if user input {Freq, FreqBand}, we load a wider frequency-band ADDING running-median/2 on either side * from the SFTs, and firstBind, lastBin correspond to {Freq,FreqBand} (rounded to closest bins) * Also returns the 'data-segment' for which SFTs were loaded * */ MultiSFTVector * XLALReadSFTs ( ConfigVariables_t *cfg, /**< [out] return derived configuration info (firstBin, lastBin, segment) */ const UserVariables_t *uvar /**< [in] complete user-input */ ) { SFTCatalog *catalog = NULL; SFTConstraints XLAL_INIT_DECL(constraints); LIGOTimeGPS startTimeGPS = {0,0}, endTimeGPS = {0,0}; LIGOTimeGPSVector *inputTimeStampsVector = NULL; /* check input */ if ( !uvar || !uvar->inputData ) { XLALPrintError ("%s: invalid NULL input 'uvar' or 'uvar->inputData'\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } if ( !cfg ) { XLALPrintError ("%s: invalid NULL input 'cfg'", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } /* set detector constraint */ if ( XLALUserVarWasSet ( &uvar->IFO ) ) constraints.detector = uvar->IFO; else constraints.detector = NULL; if ( XLALUserVarWasSet( &uvar->startTime ) ) { XLALGPSSetREAL8 ( &startTimeGPS, uvar->startTime); constraints.minStartTime = &startTimeGPS; } if ( XLALUserVarWasSet( &uvar->endTime ) ) { XLALGPSSetREAL8 ( &endTimeGPS, uvar->endTime); constraints.maxStartTime = &endTimeGPS; } if ( XLALUserVarWasSet( &uvar->timeStampsFile ) ) { if ( (inputTimeStampsVector = XLALReadTimestampsFile ( uvar->timeStampsFile )) == NULL ) XLAL_ERROR_NULL ( XLAL_EFUNC ); constraints.timestamps = inputTimeStampsVector; } /* get sft catalog */ LogPrintf ( LOG_DEBUG, "Finding all SFTs to load ... "); if ( ( catalog = XLALSFTdataFind ( uvar->inputData, &constraints) ) == NULL ) { XLALPrintError ("%s: XLALSFTdataFind() failed with xlalErrno = %d\n", __func__, xlalErrno ); XLAL_ERROR_NULL ( XLAL_EFAILED ); } if ( (catalog == NULL) || (catalog->length == 0) ) { XLALPrintError ("%s: Unable to match any SFTs with pattern '%s'\n", __func__, uvar->inputData ); XLAL_ERROR_NULL ( XLAL_EFAILED ); } LogPrintfVerbatim ( LOG_DEBUG, "done (found %i SFTs).\n", catalog->length); /* now we can free the inputTimeStampsVector */ if ( inputTimeStampsVector ) XLALDestroyTimestampVector ( inputTimeStampsVector ); /* ----- some user-input consistency checks */ BOOLEAN have_fStart = XLALUserVarWasSet ( &uvar->fStart ); BOOLEAN have_Freq = XLALUserVarWasSet ( &uvar->Freq ); BOOLEAN have_fBand = XLALUserVarWasSet ( &uvar->fBand ); BOOLEAN have_FreqBand = XLALUserVarWasSet ( &uvar->FreqBand ); if ( have_fStart && have_Freq ) { XLALPrintError ("%s: use only one of --fStart OR --Freq (see --help)\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } if ( have_fBand && have_FreqBand ) { XLALPrintError ("%s: use only one of --fBand OR --FreqBand (see --help)\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } if ( ( have_fStart && have_FreqBand ) || ( have_Freq && have_fBand ) ) { XLALPrintError ("%s: don't mix {--fStart,--fBand} with {--Freq,--FreqBand} inputs (see --help)\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } /* ---------- figure out the right frequency-band to read from the SFTs, depending on user-input ----- */ REAL8 fMin, fMax; UINT4 binsOffset; /* rngmed bin offset from start and end */ UINT4 binsBand=0; /* width of physical FreqBand in bins */ if ( have_Freq ) { REAL8 dFreq = catalog->data[0].header.deltaF; binsOffset = uvar->blocksRngMed / 2 + 1; /* truncates down plus add one bin extra safety! */ binsBand = ceil ( (uvar->FreqBand - 1e-9) / dFreq ) + 1; /* round up ! */ REAL8 rngmedSideBand = binsOffset * dFreq; fMin = uvar->Freq - rngmedSideBand; fMax = uvar->Freq + uvar->FreqBand + rngmedSideBand; } else /* NOTE: if no user-input on freq-band, we fall back to defaults on {fStart, fBand} */ { fMin = uvar->fStart; fMax = uvar->fStart + uvar->fBand; binsOffset = 0; /* no truncation of rngmed sidebands */ } /* ----- figure out the data-segment span from the user-input and SFT-catalog ----- */ /* if used passed these, then 'startTimeGPS' and 'endTimeGPS' are already set */ if ( startTimeGPS.gpsSeconds == 0 ) startTimeGPS = catalog->data[0].header.epoch; if ( endTimeGPS.gpsSeconds == 0 ) endTimeGPS = catalog->data[catalog->length-1].header.epoch; /* SFT 'constraints' only refer to SFT *start-times*, for segment we need the end-time */ REAL8 Tsft = 1.0 / catalog->data[0].header.deltaF; XLALGPSAdd ( &endTimeGPS, Tsft ); /* ---------- read the sfts ---------- */ LogPrintf (LOG_DEBUG, "Loading all SFTs ... "); MultiSFTVector *multi_sfts; if ( ( multi_sfts = XLALLoadMultiSFTs ( catalog, fMin, fMax ) ) == NULL ) { XLALPrintError ("%s: XLALLoadMultiSFTs( %f, %f ) failed with xlalErrno = %d\n", __func__, fMin, fMax, xlalErrno ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } XLALDestroySFTCatalog ( catalog ); LogPrintfVerbatim ( LOG_DEBUG, "done.\n"); /* ---------- end loading SFTs ---------- */ /* figure out effective PSD bin-boundaries for user */ UINT4 numBins = multi_sfts->data[0]->data[0].data->length; INT4 bin0, bin1; if ( have_Freq ) { bin0 = 0 + binsOffset; bin1 = bin0 + binsBand - 1; } else /* output all bins loaded from SFTs (includes rngmed-sidebands) */ { bin0 = 0; bin1 = numBins - 1; } /* return results */ cfg->firstBin = (UINT4) bin0; cfg->lastBin = (UINT4) bin1; cfg->dataSegment.start = startTimeGPS; cfg->dataSegment.end = endTimeGPS; XLALPrintInfo ("%s: loaded SFTs have %d bins, effective PSD output band is [%d, %d]\n", __func__, numBins, bin0, bin1 ); return multi_sfts; } /* XLALReadSFTs() */
/*---------------------------------------------------------------------- * main function *----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { SFTConstraints XLAL_INIT_DECL(constraints); LIGOTimeGPS XLAL_INIT_DECL(minStartTimeGPS); LIGOTimeGPS XLAL_INIT_DECL(maxStartTimeGPS); SFTCatalog *FullCatalog = NULL; CHAR *add_comment = NULL; UINT4 i; REAL8 fMin, fMax; UserInput_t XLAL_INIT_DECL(uvar); /* register all user-variables */ XLAL_CHECK_MAIN ( initUserVars ( &uvar ) == XLAL_SUCCESS, XLAL_EFUNC ); /* read cmdline & cfgfile */ XLAL_CHECK_MAIN ( XLALUserVarReadAllInput (argc, argv) == XLAL_SUCCESS, XLAL_EFUNC ); if (uvar.help) { /* help requested: we're done */ exit (0); } /* ----- make sure output directory exists ---------- */ if ( uvar.outputDir ) { int ret; ret = mkdir ( uvar.outputDir, 0777); if ( (ret == -1) && ( errno != EEXIST ) ) { int errsv = errno; LogPrintf (LOG_CRITICAL, "Failed to create directory '%s': %s\n", uvar.outputDir, strerror(errsv) ); return -1; } } LIGOTimeGPSVector *timestamps = NULL; if ( uvar.timestampsFile ) { if ( (timestamps = XLALReadTimestampsFile ( uvar.timestampsFile )) == NULL ) { XLALPrintError ("XLALReadTimestampsFile() failed to load timestamps from file '%s'\n", uvar.timestampsFile ); return -1; } } /* use IFO-contraint if one given by the user */ if ( LALUserVarWasSet ( &uvar.IFO ) ) { XLAL_CHECK_MAIN ( (constraints.detector = XLALGetChannelPrefix ( uvar.IFO )) != NULL, XLAL_EINVAL ); } minStartTimeGPS.gpsSeconds = uvar.minStartTime; maxStartTimeGPS.gpsSeconds = uvar.maxStartTime; constraints.minStartTime = &minStartTimeGPS; constraints.maxStartTime = &maxStartTimeGPS; constraints.timestamps = timestamps; /* get full SFT-catalog of all matching (multi-IFO) SFTs */ XLAL_CHECK_MAIN ( (FullCatalog = XLALSFTdataFind ( uvar.inputSFTs, &constraints )) != NULL, XLAL_EFUNC ); if ( constraints.detector ) { XLALFree ( constraints.detector ); } XLAL_CHECK_MAIN ( (FullCatalog != NULL) && (FullCatalog->length > 0), XLAL_EINVAL, "\nSorry, didn't find any matching SFTs with pattern '%s'!\n\n", uvar.inputSFTs ); /* build up full comment-string to be added to SFTs: 1) converted by ConvertToSFTv2, VCS ID 2) user extraComment */ { UINT4 len = 128; len += strlen ( uvar.inputSFTs ); if ( uvar.extraComment ) len += strlen ( uvar.extraComment ); XLAL_CHECK_MAIN ( ( add_comment = LALCalloc ( 1, len )) != NULL, XLAL_ENOMEM ); /** \deprecated FIXME: the following code uses obsolete CVS ID tags. * It should be modified to use git version information. */ sprintf ( add_comment, "Converted by $Id$, inputSFTs = '%s';", uvar.inputSFTs ); if ( uvar.extraComment ) { strcat ( add_comment, "\n"); strcat ( add_comment, uvar.extraComment ); } } /* construct comment-string */ /* which frequency-band to extract? */ fMin = -1; /* default: all */ fMax = -1; if ( LALUserVarWasSet ( &uvar.fmin ) ) fMin = uvar.fmin; if ( LALUserVarWasSet ( &uvar.fmax ) ) fMax = uvar.fmax; FILE *fpSingleSFT = NULL; if ( uvar.outputSingleSFT ) XLAL_CHECK ( ( fpSingleSFT = fopen ( uvar.outputSingleSFT, "wb" )) != NULL, XLAL_EIO, "Failed to open singleSFT file '%s' for writing\n", uvar.outputSingleSFT ); /* loop over all SFTs in SFTCatalog */ for ( i=0; i < FullCatalog->length; i ++ ) { SFTCatalog oneSFTCatalog; SFTVector *thisSFT = NULL; const CHAR *sft_comment; CHAR *new_comment; UINT4 comment_len = 0; /* set catalog containing only one SFT */ oneSFTCatalog.length = 1; oneSFTCatalog.data = &(FullCatalog->data[i]); comment_len = strlen ( add_comment ) + 10; sft_comment = oneSFTCatalog.data->comment; if ( sft_comment ) comment_len += strlen ( sft_comment ); XLAL_CHECK_MAIN ( ( new_comment = LALCalloc (1, comment_len )) != NULL, XLAL_ENOMEM ); if ( sft_comment ) { strcpy ( new_comment, sft_comment ); strcat ( new_comment, ";\n"); } strcat ( new_comment, add_comment ); XLAL_CHECK_MAIN ( (thisSFT = XLALLoadSFTs ( &oneSFTCatalog, fMin, fMax )) != NULL, XLAL_EFUNC ); if ( uvar.mysteryFactor != 1.0 ) { XLAL_CHECK_MAIN ( applyFactor2SFTs ( thisSFT, uvar.mysteryFactor ) == XLAL_SUCCESS, XLAL_EFUNC ); } // if user asked for single-SFT output, add this SFT to the open file if ( uvar.outputSingleSFT ) XLAL_CHECK ( XLAL_SUCCESS == XLALWriteSFT2fp( &(thisSFT->data[0]), fpSingleSFT, new_comment ), XLAL_EFUNC, "XLALWriteSFT2fp() failed to write SFT to '%s'!\n", uvar.outputSingleSFT ); // if user asked for directory output, write this SFT into that directory if ( uvar.outputDir ) { XLAL_CHECK_MAIN ( XLALWriteSFTVector2Dir ( thisSFT, uvar.outputDir, new_comment, uvar.descriptionMisc ) == XLAL_SUCCESS, XLAL_EFUNC ); } XLALDestroySFTVector ( thisSFT ); XLALFree ( new_comment ); } /* for i < numSFTs */ if ( fpSingleSFT ) { fclose ( fpSingleSFT ); } /* free memory */ XLALFree ( add_comment ); XLALDestroySFTCatalog ( FullCatalog ); XLALDestroyUserVars(); XLALDestroyTimestampVector ( timestamps ); LALCheckMemoryLeaks(); return 0; } /* main */
/** * Handle user-input and check its validity. * Load ephemeris and calculate AM-coefficients (stored globally) */ void Initialize (LALStatus *status, struct CommandLineArgsTag *CLA) { EphemerisData *edat=NULL; /* Stores earth/sun ephemeris data for barycentering */ BarycenterInput baryinput; /* Stores detector location and other barycentering data */ EarthState earth; AMCoeffsParams *amParams; LIGOTimeGPS *midTS=NULL; /* Time stamps for amplitude modulation coefficients */ LALDetector *Detector; /* Our detector*/ INT4 k; INITSTATUS(status); ATTATCHSTATUSPTR (status); if ( XLALUserVarWasSet ( &(CLA->nTsft) ) ) CLA->duration = 1.0 * CLA->nTsft * CLA->Tsft; /* read or generate SFT timestamps */ if ( XLALUserVarWasSet(&(CLA->timestamps)) ) { XLAL_CHECK_LAL ( status, ( timestamps = XLALReadTimestampsFile ( CLA->timestamps ) ) != NULL, XLAL_EFUNC ); if ( (CLA->nTsft > 0) && ( (UINT4)CLA->nTsft < timestamps->length ) ) /* truncate if required */ timestamps->length = CLA->nTsft; CLA->nTsft = timestamps->length; } /* if have_timestamps */ else { LIGOTimeGPS tStart; tStart.gpsSeconds = CLA->gpsStart; tStart.gpsNanoSeconds = 0; XLAL_CHECK_LAL ( status, ( timestamps = XLALMakeTimestamps( tStart, CLA->duration, CLA->Tsft, 0 ) ) != NULL, XLAL_EFUNC ); CLA->nTsft = timestamps->length; } /* no timestamps */ /*---------- initialize detector ---------- */ { BOOLEAN have_IFO = XLALUserVarWasSet ( &CLA->IFO ); BOOLEAN have_detector = XLALUserVarWasSet ( &CLA->detector ); CHAR *IFO; if ( !have_IFO && !have_detector ) { fprintf (stderr, "\nNeed to specify the detector (--IFO) !\n\n"); ABORT (status, SEMIANALYTIC_EINPUT, SEMIANALYTIC_MSGEINPUT); } if ( have_IFO ) IFO = CLA->IFO; else IFO = CLA->detector; if ( ( Detector = XLALGetSiteInfo ( IFO ) ) == NULL ) { ABORT (status, SEMIANALYTIC_EINPUT, SEMIANALYTIC_MSGEINPUT); } } /* ---------- load ephemeris-files ---------- */ { edat = XLALInitBarycenter( CLA->ephemEarth, CLA->ephemSun ); if ( !edat ) { XLALPrintError("XLALInitBarycenter failed: could not load Earth ephemeris '%s' and Sun ephemeris '%s'\n", CLA->ephemEarth, CLA->ephemSun); ABORT (status, SEMIANALYTIC_EINPUT, SEMIANALYTIC_MSGEINPUT); } } /* ephemeris-reading */ /* ---------- calculate AM-coefficients ---------- */ /* prepare call to barycentering routing */ baryinput.site.location[0] = Detector->location[0]/LAL_C_SI; baryinput.site.location[1] = Detector->location[1]/LAL_C_SI; baryinput.site.location[2] = Detector->location[2]/LAL_C_SI; baryinput.alpha = CLA->Alpha; baryinput.delta = CLA->Delta; baryinput.dInv = 0.e0; /* amParams structure to compute a(t) and b(t) */ /* Allocate space for amParams stucture */ /* Here, amParams->das is the Detector and Source info */ amParams = (AMCoeffsParams *)LALMalloc(sizeof(AMCoeffsParams)); amParams->das = (LALDetAndSource *)LALMalloc(sizeof(LALDetAndSource)); amParams->das->pSource = (LALSource *)LALMalloc(sizeof(LALSource)); /* Fill up AMCoeffsParams structure */ amParams->baryinput = &baryinput; amParams->earth = &earth; amParams->edat = edat; amParams->das->pDetector = Detector; amParams->das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams->das->pSource->equatorialCoords.longitude = CLA->Alpha; amParams->das->pSource->equatorialCoords.latitude = CLA->Delta; amParams->das->pSource->orientation = 0.0; amParams->polAngle = amParams->das->pSource->orientation ; /* These two have to be the same!!!!!!!!!*/ /* Allocate space for AMCoeffs */ XLAL_INIT_MEM(amc); TRY ( LALSCreateVector(status->statusPtr, &(amc.a), (UINT4) CLA->nTsft), status); TRY ( LALSCreateVector(status->statusPtr, &(amc.b), (UINT4) CLA->nTsft), status); /* Mid point of each SFT */ midTS = (LIGOTimeGPS *)LALCalloc(CLA->nTsft,sizeof(LIGOTimeGPS)); for(k=0; k < CLA->nTsft; k++) { /* FIXME: loss of precision; consider midTS[k] = timestamps->data[k]; XLALGPSAdd(&midTS[k], 0.5*CLA->Tsft); */ REAL8 teemp=0.0; teemp = XLALGPSGetREAL8(&(timestamps->data[k])); teemp += 0.5*CLA->Tsft; XLALGPSSetREAL8(&(midTS[k]), teemp); } TRY ( LALComputeAM(status->statusPtr, &amc, midTS, amParams), status); /* Free memory */ XLALDestroyTimestampVector ( timestamps); LALFree(midTS); LALFree(Detector); XLALDestroyEphemerisData(edat); LALFree(amParams->das->pSource); LALFree(amParams->das); LALFree(amParams); DETATCHSTATUSPTR (status); RETURN(status); } /* ParseUserInput() */
/** * basic initializations: deal with user input and return standardized 'ConfigVariables' */ int XLALInitCode ( ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name) { XLAL_CHECK ( cfg && uvar && app_name, XLAL_EINVAL, "Illegal NULL pointer input." ); /* init ephemeris data */ XLAL_CHECK ( ( cfg->edat = XLALInitBarycenter( uvar->ephemEarth, uvar->ephemSun ) ) != NULL, XLAL_EFUNC, "XLALInitBarycenter failed: could not load Earth ephemeris '%s' and Sun ephemeris '%s.", uvar->ephemEarth, uvar->ephemSun); cfg->numDetectors = uvar->IFOs->length; cfg->numTimeStamps = 0; XLAL_CHECK ( (cfg->numTimeStampsX = XLALCreateUINT4Vector ( cfg->numDetectors )) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector(%d) failed.", cfg->numDetectors ); BOOLEAN haveTimeGPS = XLALUserVarWasSet( &uvar->timeGPS ); BOOLEAN haveTimeStampsFile = XLALUserVarWasSet( &uvar->timeStampsFile ); BOOLEAN haveTimeStampsFiles = XLALUserVarWasSet( &uvar->timeStampsFiles ); XLAL_CHECK ( !(haveTimeStampsFiles && haveTimeStampsFile), XLAL_EINVAL, "Can't handle both timeStampsFiles and (deprecated) haveTimeStampsFiles input options." ); XLAL_CHECK ( !(haveTimeGPS && haveTimeStampsFile), XLAL_EINVAL, "Can't handle both (deprecated) timeStampsFile and timeGPS input options." ); XLAL_CHECK ( !(haveTimeGPS && haveTimeStampsFiles), XLAL_EINVAL, "Can't handle both timeStampsFiles and timeGPS input options." ); XLAL_CHECK ( haveTimeGPS || haveTimeStampsFiles || haveTimeStampsFile, XLAL_EINVAL, "Need either timeStampsFiles or timeGPS input option." ); if ( haveTimeStampsFiles ) { XLAL_CHECK ( (uvar->timeStampsFiles->length == 1 ) || ( uvar->timeStampsFiles->length == cfg->numDetectors ), XLAL_EINVAL, "Length of timeStampsFiles list is neither 1 (one file for all detectors) nor does it match the number of detectors. (%d != %d)", uvar->timeStampsFiles->length, cfg->numDetectors ); XLAL_CHECK ( (uvar->timeStampsFiles->length == 1 ) || !uvar->outab, XLAL_EINVAL, "At the moment, can't produce a(t), b(t) output (--outab) when given per-IFO --timeStampsFiles."); } if ( haveTimeStampsFiles && ( uvar->timeStampsFiles->length == cfg->numDetectors ) ) { XLAL_CHECK ( ( cfg->multiTimestamps = XLALReadMultiTimestampsFiles ( uvar->timeStampsFiles ) ) != NULL, XLAL_EFUNC ); XLAL_CHECK ( (cfg->multiTimestamps->length > 0) && (cfg->multiTimestamps->data != NULL), XLAL_EINVAL, "Got empty timestamps-list from '%s'.", uvar->timeStampsFiles ); } else { /* prepare multiTimestamps structure */ UINT4 nTS = 0; XLAL_CHECK ( ( cfg->multiTimestamps = XLALCalloc ( 1, sizeof(*cfg->multiTimestamps))) != NULL, XLAL_ENOMEM, "Allocating multiTimestamps failed." ); XLAL_CHECK ( ( cfg->multiTimestamps->data = XLALCalloc ( cfg->numDetectors, sizeof(cfg->multiTimestamps->data) )) != NULL, XLAL_ENOMEM, "Allocating multiTimestamps->data failed." ); cfg->multiTimestamps->length = cfg->numDetectors; if ( haveTimeGPS ) { /* set up timestamps vector from timeGPS, use same for all IFOs */ nTS = uvar->timeGPS->length; XLAL_CHECK ( (cfg->multiTimestamps->data[0] = XLALCreateTimestampVector ( nTS ) ) != NULL, XLAL_EFUNC, "XLALCreateTimestampVector( %d ) failed.", nTS ); /* convert input REAL8 times into LIGOTimeGPS for first detector */ for (UINT4 t = 0; t < nTS; t++) { REAL8 temp_real8_timestamp = 0; XLAL_CHECK ( 1 == sscanf ( uvar->timeGPS->data[t], "%" LAL_REAL8_FORMAT, &temp_real8_timestamp ), XLAL_EINVAL, "Illegal REAL8 commandline argument to --timeGPS[%d]: '%s'", t, uvar->timeGPS->data[t] ); XLAL_CHECK ( XLALGPSSetREAL8( &cfg->multiTimestamps->data[0]->data[t], temp_real8_timestamp ) != NULL, XLAL_EFUNC, "Failed to convert input GPS %g into LIGOTimeGPS", temp_real8_timestamp ); } // for (UINT4 t = 0; t < nTS; t++) } // if ( haveTimeGPS ) else { // haveTimeStampsFiles || haveTimeStampsFile CHAR *singleTimeStampsFile = NULL; if ( haveTimeStampsFiles ) { singleTimeStampsFile = uvar->timeStampsFiles->data[0]; } else if ( haveTimeStampsFile ) { singleTimeStampsFile = uvar->timeStampsFile; } XLAL_CHECK ( ( cfg->multiTimestamps->data[0] = XLALReadTimestampsFile ( singleTimeStampsFile ) ) != NULL, XLAL_EFUNC ); nTS = cfg->multiTimestamps->data[0]->length; } // else: haveTimeStampsFiles || haveTimeStampsFile /* copy timestamps from first detector to all others */ if ( cfg->numDetectors > 1 ) { for ( UINT4 X=1; X < cfg->numDetectors; X++ ) { XLAL_CHECK ( (cfg->multiTimestamps->data[X] = XLALCreateTimestampVector ( nTS ) ) != NULL, XLAL_EFUNC, "XLALCreateTimestampVector( %d ) failed.", nTS ); for (UINT4 t = 0; t < nTS; t++) { cfg->multiTimestamps->data[X]->data[t].gpsSeconds = cfg->multiTimestamps->data[0]->data[t].gpsSeconds; cfg->multiTimestamps->data[X]->data[t].gpsNanoSeconds = cfg->multiTimestamps->data[0]->data[t].gpsNanoSeconds; } // for (UINT4 t = 0; t < nTS; t++) } // for ( UINT4 X=1; X < cfg->numDetectors X++ ) } // if ( cfg->numDetectors > 1 ) } // if !( haveTimeStampsFiles && ( uvar->timeStampsFiles->length == cfg->numDetectors ) ) for ( UINT4 X=0; X < cfg->numDetectors; X++ ) { cfg->numTimeStampsX->data[X] = cfg->multiTimestamps->data[X]->length; cfg->numTimeStamps += cfg->numTimeStampsX->data[X]; } /* convert detector names into site-info */ MultiLALDetector multiDet; XLAL_CHECK ( XLALParseMultiLALDetector ( &multiDet, uvar->IFOs ) == XLAL_SUCCESS, XLAL_EFUNC ); /* get detector states */ XLAL_CHECK ( (cfg->multiDetStates = XLALGetMultiDetectorStates ( cfg->multiTimestamps, &multiDet, cfg->edat, 0.5 * uvar->Tsft )) != NULL, XLAL_EFUNC, "XLALGetDetectorStates() failed." ); BOOLEAN haveAlphaDelta = ( XLALUserVarWasSet(&uvar->Alpha) && XLALUserVarWasSet(&uvar->Delta) ); BOOLEAN haveSkyGrid = XLALUserVarWasSet( &uvar->skyGridFile ); XLAL_CHECK ( !(haveAlphaDelta && haveSkyGrid), XLAL_EINVAL, "Can't handle both Alpha/Delta and skyGridFile input options." ); XLAL_CHECK ( haveAlphaDelta || haveSkyGrid, XLAL_EINVAL, "Need either Alpha/Delta or skyGridFile input option." ); if (haveAlphaDelta) { /* parse this into one-element Alpha, Delta vectors */ XLAL_CHECK ( (cfg->Alpha = XLALCreateREAL8Vector ( 1 )) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector(1) failed." ); cfg->Alpha->data[0] = uvar->Alpha; XLAL_CHECK ( (cfg->Delta = XLALCreateREAL8Vector ( 1 )) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector(1) failed." ); cfg->Delta->data[0] = uvar->Delta; cfg->numSkyPoints = 1; } // if (haveAlphaDelta) else if ( haveSkyGrid ) { LALParsedDataFile *data = NULL; XLAL_CHECK ( XLALParseDataFile (&data, uvar->skyGridFile) == XLAL_SUCCESS, XLAL_EFUNC, "Failed to parse data file '%s'.", uvar->skyGridFile ); cfg->numSkyPoints = data->lines->nTokens; XLAL_CHECK ( (cfg->Alpha = XLALCreateREAL8Vector ( cfg->numSkyPoints )) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector( %d ) failed.", cfg->numSkyPoints ); XLAL_CHECK ( (cfg->Delta = XLALCreateREAL8Vector ( cfg->numSkyPoints )) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector( %d ) failed.", cfg->numSkyPoints ); for (UINT4 n=0; n < cfg->numSkyPoints; n++) { XLAL_CHECK ( 2 == sscanf( data->lines->tokens[n], "%" LAL_REAL8_FORMAT "%" LAL_REAL8_FORMAT, &cfg->Alpha->data[n], &cfg->Delta->data[n] ), XLAL_EDATA, "Could not parse 2 numbers from line %d in candidate-file '%s':\n'%s'", n, uvar->skyGridFile, data->lines->tokens[n] ); } // for (UINT4 n=0; n < cfg->numSkyPoints; n++) XLALDestroyParsedDataFile ( data ); } // else if ( haveSkyGrid ) if ( uvar->noiseSqrtShX ) { /* translate user-input PSD sqrt(SX) to noise-weights (this actually does not care whether they were normalized or not) */ if ( uvar->noiseSqrtShX->length != cfg->numDetectors ) { fprintf(stderr, "Length of noiseSqrtShX vector does not match number of detectors! (%d != %d)\n", uvar->noiseSqrtShX->length, cfg->numDetectors); XLAL_ERROR ( XLAL_EINVAL ); } REAL8Vector *noiseSqrtShX = NULL; if ( (noiseSqrtShX = XLALCreateREAL8Vector ( cfg->numDetectors )) == NULL ) { fprintf(stderr, "Failed call to XLALCreateREAL8Vector( %d )\n", cfg->numDetectors ); XLAL_ERROR ( XLAL_EFUNC ); } REAL8 psd_normalization = 0; for (UINT4 X = 0; X < cfg->numDetectors; X++) { if ( 1 != sscanf ( uvar->noiseSqrtShX->data[X], "%" LAL_REAL8_FORMAT, &noiseSqrtShX->data[X] ) ) { fprintf(stderr, "Illegal REAL8 commandline argument to --noiseSqrtShX[%d]: '%s'\n", X, uvar->noiseSqrtShX->data[X]); XLAL_ERROR ( XLAL_EINVAL ); } if ( noiseSqrtShX->data[X] <= 0.0 ) { fprintf(stderr, "Non-positive input PSD ratio for detector X=%d: noiseSqrtShX[X]=%f\n", X, noiseSqrtShX->data[X] ); XLAL_ERROR ( XLAL_EINVAL ); } psd_normalization += 1.0/SQ(noiseSqrtShX->data[X]); } /* for X < cfg->numDetectors */ psd_normalization = (REAL8)cfg->numDetectors/psd_normalization; /* S = NSFT / sum S_Xalpha^-1, no per-SFT variation here -> S = Ndet / sum S_X^-1 */ /* create multi noise weights */ if ( (cfg->multiNoiseWeights = XLALCalloc(1, sizeof(*cfg->multiNoiseWeights))) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, sizeof(*cfg->multiNoiseWeights) ); XLAL_ERROR ( XLAL_ENOMEM ); } if ( (cfg->multiNoiseWeights->data = XLALCalloc(cfg->numDetectors, sizeof(*cfg->multiNoiseWeights->data))) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( %d, %d )\n", __func__, cfg->numDetectors, sizeof(*cfg->multiNoiseWeights->data) ); XLAL_ERROR ( XLAL_ENOMEM ); } cfg->multiNoiseWeights->length = cfg->numDetectors; for (UINT4 X = 0; X < cfg->numDetectors; X++) { REAL8 noise_weight_X = psd_normalization/SQ(noiseSqrtShX->data[X]); /* w_Xalpha = S_Xalpha^-1/S^-1 = S / S_Xalpha */ /* create k^th weights vector */ if( ( cfg->multiNoiseWeights->data[X] = XLALCreateREAL8Vector ( cfg->numTimeStampsX->data[X] ) ) == NULL ) { /* free weights vectors created previously in loop */ XLALDestroyMultiNoiseWeights ( cfg->multiNoiseWeights ); XLAL_ERROR ( XLAL_EFUNC, "Failed to allocate noiseweights for IFO X = %d\n", X ); } /* if XLALCreateREAL8Vector() failed */ /* loop over rngmeds and calculate weights -- one for each sft */ for ( UINT4 alpha = 0; alpha < cfg->numTimeStampsX->data[X]; alpha++) { cfg->multiNoiseWeights->data[X]->data[alpha] = noise_weight_X; } } /* for X < cfg->numDetectors */ XLALDestroyREAL8Vector ( noiseSqrtShX ); } /* if ( uvar->noiseSqrtShX ) */ else { cfg->multiNoiseWeights = NULL; } return XLAL_SUCCESS; } /* XLALInitCode() */
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; }