int main(int argc, char *argv[]){ static LALStatus status; static LALDetector *detector; static LIGOTimeGPSVector timeV; static REAL8Cart3CoorVector velV; static REAL8Vector timeDiffV; static REAL8 foft; static HoughPulsarTemplate pulsarTemplate; EphemerisData *edat = NULL; CHAR *uvar_earthEphemeris = NULL; CHAR *uvar_sunEphemeris = NULL; SFTVector *inputSFTs = NULL; REAL8 *alphaVec=NULL; REAL8 *deltaVec=NULL; REAL8 *freqVec=NULL; REAL8 *spndnVec=NULL; /* pgV is vector of peakgrams and pg1 is onepeakgram */ static UCHARPeakGram *pg1, **pgV; UINT4 msp; /*number of spin-down parameters */ CHAR *uvar_ifo = NULL; CHAR *uvar_sftDir = NULL; /* the directory where the SFT could be */ CHAR *uvar_fnameOut = NULL; /* The output prefix filename */ CHAR *uvar_fnameIn = NULL; INT4 numberCount, ind; UINT8 nTemplates; UINT4 mObsCoh; REAL8 uvar_peakThreshold; REAL8 f_min, f_max, fWings, timeBase; INT4 uvar_blocksRngMed; UINT4 sftlength; INT4 sftFminBin; UINT4 loopId, tempLoopId; FILE *fpOut = NULL; CHAR *fnameLog=NULL; FILE *fpLog = NULL; CHAR *logstr=NULL; /*REAL8 asq, bsq;*/ /* square of amplitude modulation functions a and b */ /******************************************************************/ /* Set up the default parameters. */ /* ****************************************************************/ /* LAL error-handler */ lal_errhandler = LAL_ERR_EXIT; msp = 1; /*only one spin-down */ /* memory allocation for spindown */ pulsarTemplate.spindown.length = msp; pulsarTemplate.spindown.data = NULL; pulsarTemplate.spindown.data = (REAL8 *)LALMalloc(msp*sizeof(REAL8)); uvar_peakThreshold = THRESHOLD; uvar_earthEphemeris = (CHAR *)LALMalloc(1024*sizeof(CHAR)); strcpy(uvar_earthEphemeris,EARTHEPHEMERIS); uvar_sunEphemeris = (CHAR *)LALMalloc(1024*sizeof(CHAR)); strcpy(uvar_sunEphemeris,SUNEPHEMERIS); uvar_sftDir = (CHAR *)LALMalloc(1024*sizeof(CHAR)); strcpy(uvar_sftDir,SFTDIRECTORY); uvar_fnameOut = (CHAR *)LALMalloc(1024*sizeof(CHAR)); strcpy(uvar_fnameOut,VALIDATEOUT); uvar_fnameIn = (CHAR *)LALMalloc(1024*sizeof(CHAR)); strcpy(uvar_fnameIn,VALIDATEIN); uvar_blocksRngMed = BLOCKSRNGMED; /* register user input variables */ XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_ifo, "ifo", STRING, 'i', OPTIONAL, "Detector GEO(1) LLO(2) LHO(3)" ) == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_earthEphemeris, "earthEphemeris", STRING, 'E', OPTIONAL, "Earth Ephemeris file") == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_sunEphemeris, "sunEphemeris", STRING, 'S', OPTIONAL, "Sun Ephemeris file") == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_sftDir, "sftDir", STRING, 'D', OPTIONAL, "SFT Directory") == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fnameIn, "fnameIn", STRING, 'T', OPTIONAL, "Input template file") == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fnameOut, "fnameOut", STRING, 'o', OPTIONAL, "Output filename") == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_blocksRngMed, "blocksRngMed", INT4, 'w', OPTIONAL, "RngMed block size") == XLAL_SUCCESS, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_peakThreshold, "peakThreshold", REAL8, 't', OPTIONAL, "Peak selection threshold") == XLAL_SUCCESS, XLAL_EFUNC); /* read all command line variables */ BOOLEAN should_exit = 0; XLAL_CHECK_MAIN( XLALUserVarReadAllInput(&should_exit, argc, argv, lalAppsVCSInfoList) == XLAL_SUCCESS, XLAL_EFUNC); if (should_exit) exit(1); /* open log file for writing */ fnameLog = LALCalloc( (strlen(uvar_fnameOut) + strlen(".log") + 10),1); strcpy(fnameLog,uvar_fnameOut); strcat(fnameLog,".log"); if ((fpLog = fopen(fnameLog, "w")) == NULL) { fprintf(stderr, "Unable to open file %s for writing\n", fnameLog); LALFree(fnameLog); exit(1); } /* get the log string */ XLAL_CHECK_MAIN( ( logstr = XLALUserVarGetLog(UVAR_LOGFMT_CFGFILE) ) != NULL, XLAL_EFUNC); fprintf( fpLog, "## Log file for HoughValidate\n\n"); fprintf( fpLog, "# User Input:\n"); fprintf( fpLog, "#-------------------------------------------\n"); fprintf( fpLog, "%s", logstr); LALFree(logstr); /* append an ident-string defining the exact CVS-version of the code used */ { CHAR command[1024] = ""; fprintf (fpLog, "\n\n# CVS-versions of executable:\n"); fprintf (fpLog, "# -----------------------------------------\n"); fclose (fpLog); sprintf (command, "ident %s | sort -u >> %s", argv[0], fnameLog); /* we don't check this. If it fails, we assume that */ /* one of the system-commands was not available, and */ /* therefore the CVS-versions will not be logged */ if ( system(command) ) fprintf (stderr, "\nsystem('%s') returned non-zero status!\n\n", command ); LALFree(fnameLog); } /* open output file for writing */ fpOut= fopen(uvar_fnameOut, "w"); /*setlinebuf(fpOut);*/ /* line buffered on */ setvbuf(fpOut, (char *)NULL, _IOLBF, 0); /*****************************************************************/ /* read template file */ /*****************************************************************/ { FILE *fpIn = NULL; INT4 r; REAL8 temp1, temp2, temp3, temp4, temp5; UINT8 templateCounter; fpIn = fopen(uvar_fnameIn, "r"); if ( !fpIn ) { fprintf(stderr, "Unable to fine file %s\n", uvar_fnameIn); return DRIVEHOUGHCOLOR_EFILE; } nTemplates = 0; do { r=fscanf(fpIn,"%lf%lf%lf%lf%lf\n", &temp1, &temp2, &temp3, &temp4, &temp5); /* make sure the line has the right number of entries or is EOF */ if (r==5) nTemplates++; } while ( r != EOF); rewind(fpIn); alphaVec = (REAL8 *)LALMalloc(nTemplates*sizeof(REAL8)); deltaVec = (REAL8 *)LALMalloc(nTemplates*sizeof(REAL8)); freqVec = (REAL8 *)LALMalloc(nTemplates*sizeof(REAL8)); spndnVec = (REAL8 *)LALMalloc(nTemplates*sizeof(REAL8)); for (templateCounter = 0; templateCounter < nTemplates; templateCounter++) { r=fscanf(fpIn,"%lf%lf%lf%lf%lf\n", &temp1, alphaVec + templateCounter, deltaVec + templateCounter, freqVec + templateCounter, spndnVec + templateCounter); } fclose(fpIn); } /**************************************************/ /* read sfts */ /*************************************************/ f_min = freqVec[0]; /* initial frequency to be analyzed */ /* assume that the last frequency in the templates file is also the highest frequency */ f_max = freqVec[nTemplates-1] ; /* we need to add wings to fmin and fmax to account for the Doppler shift, the size of the rngmed block size and also nfsizecylinder. The block size and nfsizecylinder are specified in terms of frequency bins...this goes as one of the arguments of LALReadSFTfiles */ /* first correct for Doppler shift */ fWings = f_max * VTOT; f_min -= fWings; f_max += fWings; /* create pattern to look for in SFT directory */ { CHAR *tempDir = NULL; SFTCatalog *catalog = NULL; static SFTConstraints constraints; /* set detector constraint */ constraints.detector = NULL; if ( XLALUserVarWasSet( &uvar_ifo ) ) constraints.detector = XLALGetChannelPrefix ( uvar_ifo ); /* get sft catalog */ tempDir = (CHAR *)LALCalloc(512, sizeof(CHAR)); strcpy(tempDir, uvar_sftDir); strcat(tempDir, "/*SFT*.*"); XLAL_CHECK_MAIN( ( catalog = XLALSFTdataFind( tempDir, &constraints) ) != NULL, XLAL_EFUNC); detector = XLALGetSiteInfo( catalog->data[0].header.name); mObsCoh = catalog->length; timeBase = 1.0 / catalog->data->header.deltaF; XLAL_CHECK_MAIN( ( inputSFTs = XLALLoadSFTs ( catalog, f_min, f_max) ) != NULL, XLAL_EFUNC); XLAL_CHECK_MAIN( XLALNormalizeSFTVect( inputSFTs, uvar_blocksRngMed, 0.0 ) == XLAL_SUCCESS, XLAL_EFUNC); if ( XLALUserVarWasSet( &uvar_ifo ) ) LALFree( constraints.detector ); LALFree( tempDir); XLALDestroySFTCatalog(catalog ); } sftlength = inputSFTs->data->data->length; { INT4 tempFbin; sftFminBin = floor( (REAL4)(timeBase * inputSFTs->data->f0) + (REAL4)(0.5)); tempFbin = floor( timeBase * inputSFTs->data->f0 + 0.5); if (tempFbin - sftFminBin) { fprintf(stderr, "Rounding error in calculating fminbin....be careful! \n"); } } /* loop over sfts and select peaks */ /* first the memory allocation for the peakgramvector */ pgV = NULL; pgV = (UCHARPeakGram **)LALMalloc(mObsCoh*sizeof(UCHARPeakGram *)); /* memory for peakgrams */ for (tempLoopId=0; tempLoopId < mObsCoh; tempLoopId++) { pgV[tempLoopId] = (UCHARPeakGram *)LALMalloc(sizeof(UCHARPeakGram)); pgV[tempLoopId]->length = sftlength; pgV[tempLoopId]->data = NULL; pgV[tempLoopId]->data = (UCHAR *)LALMalloc(sftlength* sizeof(UCHAR)); LAL_CALL (SFTtoUCHARPeakGram( &status, pgV[tempLoopId], inputSFTs->data + tempLoopId, uvar_peakThreshold), &status); } /* having calculated the peakgrams we don't need the sfts anymore */ XLALDestroySFTVector( inputSFTs); /* ****************************************************************/ /* setting timestamps vector */ /* ****************************************************************/ timeV.length = mObsCoh; timeV.data = NULL; timeV.data = (LIGOTimeGPS *)LALMalloc(mObsCoh*sizeof(LIGOTimeGPS)); { UINT4 j; for (j=0; j < mObsCoh; j++){ timeV.data[j].gpsSeconds = pgV[j]->epoch.gpsSeconds; timeV.data[j].gpsNanoSeconds = pgV[j]->epoch.gpsNanoSeconds; } } /******************************************************************/ /* compute the time difference relative to startTime for all SFTs */ /******************************************************************/ timeDiffV.length = mObsCoh; timeDiffV.data = NULL; timeDiffV.data = (REAL8 *)LALMalloc(mObsCoh*sizeof(REAL8)); { REAL8 t0, ts, tn, midTimeBase; UINT4 j; midTimeBase=0.5*timeBase; ts = timeV.data[0].gpsSeconds; tn = timeV.data[0].gpsNanoSeconds * 1.00E-9; t0=ts+tn; timeDiffV.data[0] = midTimeBase; for (j=1; j< mObsCoh; ++j){ ts = timeV.data[j].gpsSeconds; tn = timeV.data[j].gpsNanoSeconds * 1.00E-9; timeDiffV.data[j] = ts + tn -t0 + midTimeBase; } } /******************************************************************/ /* compute detector velocity for those time stamps */ /******************************************************************/ velV.length = mObsCoh; velV.data = NULL; velV.data = (REAL8Cart3Coor *)LALMalloc(mObsCoh*sizeof(REAL8Cart3Coor)); { VelocityPar velPar; REAL8 vel[3]; UINT4 j; velPar.detector = *detector; velPar.tBase = timeBase; velPar.vTol = ACCURACY; velPar.edat = NULL; /* read in ephemeris data */ XLAL_CHECK_MAIN( ( edat = XLALInitBarycenter( uvar_earthEphemeris, uvar_sunEphemeris ) ) != NULL, XLAL_EFUNC); velPar.edat = edat; /* now calculate average velocity */ for(j=0; j< velV.length; ++j){ velPar.startTime.gpsSeconds = timeV.data[j].gpsSeconds; velPar.startTime.gpsNanoSeconds = timeV.data[j].gpsNanoSeconds; LAL_CALL( LALAvgDetectorVel ( &status, vel, &velPar), &status ); velV.data[j].x= vel[0]; velV.data[j].y= vel[1]; velV.data[j].z= vel[2]; } } /* amplitude modulation stuff */ { AMCoeffs XLAL_INIT_DECL(amc); AMCoeffsParams *amParams; EarthState earth; BarycenterInput baryinput; /* Stores detector location and other barycentering data */ /* detector location */ 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.dInv = 0.e0; /* alpha and delta must come from the skypatch */ /* for now set it to something arbitrary */ baryinput.alpha = 0.0; baryinput.delta = 0.0; /* 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; /* make sure alpha and delta are correct */ amParams->das->pSource->equatorialCoords.latitude = baryinput.delta; amParams->das->pSource->equatorialCoords.longitude = baryinput.alpha; amParams->das->pSource->orientation = 0.0; amParams->das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams->polAngle = amParams->das->pSource->orientation ; /* These two have to be the same!!*/ /* timeV is start time ---> change to mid time */ LAL_CALL (LALComputeAM(&status, &amc, timeV.data, amParams), &status); /* calculate a^2 and b^2 */ /* for (ii=0, asq=0.0, bsq=0.0; ii<mObsCoh; ii++) */ /* { */ /* REAL8 *a, *b; */ /* a = amc.a + ii; */ /* b = amc.b + ii; */ /* asq += (*a) * (*a); */ /* bsq += (*b) * (*b); */ /* } */ /* free amParams */ LALFree(amParams->das->pSource); LALFree(amParams->das); LALFree(amParams); } /* loop over templates */ for(loopId=0; loopId < nTemplates; ++loopId){ /* set template parameters */ pulsarTemplate.f0 = freqVec[loopId]; pulsarTemplate.longitude = alphaVec[loopId]; pulsarTemplate.latitude = deltaVec[loopId]; pulsarTemplate.spindown.data[0] = spndnVec[loopId]; { REAL8 f0new, vcProdn, timeDiffN; REAL8 sourceDelta, sourceAlpha, cosDelta, factorialN; UINT4 j, i, f0newBin; REAL8Cart3Coor sourceLocation; sourceDelta = pulsarTemplate.latitude; sourceAlpha = pulsarTemplate.longitude; cosDelta = cos(sourceDelta); sourceLocation.x = cosDelta* cos(sourceAlpha); sourceLocation.y = cosDelta* sin(sourceAlpha); sourceLocation.z = sin(sourceDelta); /* loop for all different time stamps,calculate frequency and produce number count*/ /* first initialize number count */ numberCount=0; for (j=0; j<mObsCoh; ++j) { /* calculate v/c.n */ vcProdn = velV.data[j].x * sourceLocation.x + velV.data[j].y * sourceLocation.y + velV.data[j].z * sourceLocation.z; /* loop over spindown values to find f_0 */ f0new = pulsarTemplate.f0; factorialN = 1.0; timeDiffN = timeDiffV.data[j]; for (i=0; i<msp;++i) { factorialN *=(i+1.0); f0new += pulsarTemplate.spindown.data[i]*timeDiffN / factorialN; timeDiffN *= timeDiffN; } f0newBin = floor(f0new*timeBase + 0.5); foft = f0newBin * (1.0 +vcProdn) / timeBase; /* get the right peakgram */ pg1 = pgV[j]; /* calculate frequency bin for template */ ind = floor( foft * timeBase + 0.5 ) - sftFminBin; /* update the number count */ numberCount+=pg1->data[ind]; } } /* end of block calculating frequency path and number count */ /******************************************************************/ /* printing result in the output file */ /******************************************************************/ fprintf(fpOut,"%d %f %f %f %g \n", numberCount, pulsarTemplate.longitude, pulsarTemplate.latitude, pulsarTemplate.f0, pulsarTemplate.spindown.data[0] ); } /* end of loop over templates */ /******************************************************************/ /* Closing files */ /******************************************************************/ fclose(fpOut); /******************************************************************/ /* Free memory and exit */ /******************************************************************/ LALFree(alphaVec); LALFree(deltaVec); LALFree(freqVec); LALFree(spndnVec); for (tempLoopId = 0; tempLoopId < mObsCoh; tempLoopId++){ pg1 = pgV[tempLoopId]; LALFree(pg1->data); LALFree(pg1); } LALFree(pgV); LALFree(timeV.data); LALFree(timeDiffV.data); LALFree(velV.data); LALFree(pulsarTemplate.spindown.data); XLALDestroyEphemerisData(edat); XLALDestroyUserVars(); LALCheckMemoryLeaks(); return DRIVEHOUGHCOLOR_ENORM; }
REAL4Vector * readInSFTs(inputParamsStruct *input, REAL8 *normalization) { INT4 ii, jj; SFTCatalog *catalog = NULL; //Set the start and end times in the LIGO GPS format LIGOTimeGPS start = LIGOTIMEGPSZERO, end = LIGOTIMEGPSZERO; XLALGPSSetREAL8(&start, input->searchstarttime); if (xlalErrno != 0) { fprintf(stderr, "%s: XLALGPSSetREAL8() failed on start time = %.9f.\n", __func__, input->searchstarttime); XLAL_ERROR_NULL(XLAL_EFUNC); } XLALGPSSetREAL8(&end, input->searchstarttime+input->Tobs); if (xlalErrno != 0) { fprintf(stderr, "%s: XLALGPSSetREAL8() failed on end time = %.9f.\n", __func__, input->searchstarttime+input->Tobs); XLAL_ERROR_NULL(XLAL_EFUNC); } //Setup the constraints SFTConstraints constraints; constraints.detector = NULL; constraints.minStartTime = constraints.maxStartTime = NULL; constraints.timestamps = NULL; constraints.detector = input->det[0].frDetector.prefix; constraints.minStartTime = &start; constraints.maxStartTime = &end; //Find SFT files catalog = XLALSFTdataFind(sft_dir_file, &constraints); if (catalog==NULL) { fprintf(stderr,"%s: XLALSFTdataFind() failed.\n", __func__); XLAL_ERROR_NULL(XLAL_EFUNC); } //Determine band size (remember to get extra bins because of the running median and the bin shifts due to detector velocity) REAL8 minfbin = round(input->fmin*input->Tcoh - input->dfmax*input->Tcoh - 0.5*(input->blksize-1) - (REAL8)(input->maxbinshift) - 6.0)/input->Tcoh; REAL8 maxfbin = round((input->fmin + input->fspan)*input->Tcoh + input->dfmax*input->Tcoh + 0.5*(input->blksize-1) + (REAL8)(input->maxbinshift) + 6.0)/input->Tcoh; //Now extract the data SFTVector *sfts = XLALLoadSFTs(catalog, minfbin+0.1/input->Tcoh, maxfbin-0.1/input->Tcoh); if (sfts == NULL) { fprintf(stderr,"%s: XLALLoadSFTs() failed to load SFTs with given input parameters.\n", __func__); XLAL_ERROR_NULL(XLAL_EFUNC); } //Now put the power data into the TF plane, looping through each SFT //If an SFT doesn't exit, fill the TF pixels of the SFT with zeros INT4 numffts = (INT4)floor(input->Tobs/(input->Tcoh-input->SFToverlap)-1); INT4 sftlength; if (sfts->length == 0) sftlength = (INT4)round(maxfbin*input->Tcoh - minfbin*input->Tcoh + 1); else { sftlength = sfts->data->data->length; //Check the length is what we expect if (sftlength!=(INT4)round(maxfbin*input->Tcoh - minfbin*input->Tcoh + 1)) { fprintf(stderr, "%s: sftlength (%d) is not matching expected length (%d).\n", __func__, sftlength, (INT4)round(maxfbin*input->Tcoh - minfbin*input->Tcoh + 1)); XLAL_ERROR_NULL(XLAL_EFPINEXCT); } } INT4 nonexistantsft = 0; REAL4Vector *tfdata = XLALCreateREAL4Vector(numffts*sftlength); if (tfdata==NULL) { fprintf(stderr,"%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numffts*sftlength); XLAL_ERROR_NULL(XLAL_EFUNC); } //Load the data into the output vector, roughly normalizing as we go along from the input value REAL8 sqrtnorm = sqrt(*(normalization)); for (ii=0; ii<numffts; ii++) { SFTDescriptor *sftdescription = &(catalog->data[ii - nonexistantsft]); if (sftdescription->header.epoch.gpsSeconds == (INT4)round(ii*(input->Tcoh-input->SFToverlap)+input->searchstarttime)) { SFTtype *sft = &(sfts->data[ii - nonexistantsft]); for (jj=0; jj<sftlength; jj++) { COMPLEX8 sftcoeff = sft->data->data[jj]; tfdata->data[ii*sftlength + jj] = (REAL4)((sqrtnorm*crealf(sftcoeff))*(sqrtnorm*crealf(sftcoeff)) + (sqrtnorm*cimagf(sftcoeff))*(sqrtnorm*cimagf(sftcoeff))); //power, normalized } } else { for (jj=0; jj<sftlength; jj++) tfdata->data[ii*sftlength + jj] = 0.0; //Set values to be zero nonexistantsft++; //increment the nonexistantsft counter } } /* for ii < numffts */ //Vladimir's code uses a different SFT normalization factor than MFD if (strcmp(input->sftType, "vladimir") == 0) { REAL4 vladimirfactor = (REAL4)(0.25*(8.0/3.0)); for (ii=0; ii<(INT4)tfdata->length; ii++) tfdata->data[ii] *= vladimirfactor; } //Destroy stuff XLALDestroySFTCatalog(catalog); XLALDestroySFTVector(sfts); fprintf(stderr, "Duty factor = %f\n", 1.0-(REAL4)nonexistantsft/(REAL4)numffts); return tfdata; } /* readInSFTs() */
/*---------------------------------------------------------------------- * 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 */
/*---------------------------------------------------------------------- * main function *----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { /* register all our user-variable */ UserVariables_t XLAL_INIT_DECL(uvar); XLAL_CHECK ( XLALReadUserInput ( argc, argv, &uvar ) == XLAL_SUCCESS, XLAL_EFUNC ); SFTConstraints XLAL_INIT_DECL(constraints); CHAR detector[2] = "??"; /* allow reading v1-SFTs without detector-info */ constraints.detector = detector; SFTCatalog *catalog; XLAL_CHECK ( (catalog = XLALSFTdataFind ( uvar.SFTfiles, &constraints )) != NULL, XLAL_EFUNC, "No SFTs matched your --SFTfiles query\n" ); if ( uvar.headerOnly ) { for ( UINT4 i=0; i < catalog->length; i ++ ) { SFTDescriptor *ptr = &(catalog->data[i]); XLALprintHeader ( &(ptr->header) ); XLALprintDescriptor ( ptr ); } // for i < catalog->length } // if header else { SFTVector *sfts; XLAL_CHECK ( (sfts = XLALLoadSFTs ( catalog, -1, -1 )) != NULL, XLAL_EFUNC ); BOOLEAN segmentedSFTs = 0; if ( sfts->length < catalog->length ) { segmentedSFTs = 1; printf ("\n"); printf ("%%%% Frequency-segmented SFTs: len(catalog) = %d, len(sft-vector) = %d\n", catalog->length, sfts->length ); if ( !uvar.noHeader ) { printf ("%%%% For segmented SFTS we can't output SFT 'descriptors' + data. Use --headerOnly if you need the descriptor fields\n\n"); } } // if we're dealing with 'segmented SFTs': currently can't map them to catalog-descriptors for ( UINT4 i=0; i < sfts->length; i ++ ) { SFTtype *sft_i = &(sfts->data[i]);; if ( !uvar.noHeader ) { XLALprintHeader ( sft_i ); if ( !segmentedSFTs ) { // skip descriptor fields for segmented SFTs (as we can't map them to SFTs) XLALprintDescriptor ( &(catalog->data[i]) ); } } // output header info XLALprintData ( sft_i ); } // for i < num_sfts XLALDestroySFTVector ( sfts ); } /* if !headerOnly */ /* free memory */ XLALDestroySFTCatalog (catalog); XLALDestroyUserVars(); LALCheckMemoryLeaks(); return 0; } /* main */
/*---------------------------------------------------------------------- * main function *----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { SFTConstraints XLAL_INIT_DECL(constraints); CHAR detector[2] = "??"; /* allow reading v1-SFTs without detector-info */ SFTVector *diffs = NULL; REAL8 maxd = 0; /* register all user-variables */ UserInput_t XLAL_INIT_DECL(uvar); 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); } /* now read in the two complete sft-vectors */ constraints.detector = detector; SFTCatalog *catalog; XLAL_CHECK_MAIN ( (catalog = XLALSFTdataFind ( uvar.sftBname1, &constraints )) != NULL, XLAL_EFUNC ); SFTVector *SFTs1; XLAL_CHECK_MAIN ( (SFTs1 = XLALLoadSFTs( catalog, -1, -1 )) != NULL, XLAL_EFUNC ); XLALDestroySFTCatalog ( catalog ); XLAL_CHECK_MAIN ( (catalog = XLALSFTdataFind ( uvar.sftBname2, &constraints )) != NULL, XLAL_EFUNC ); SFTVector *SFTs2; XLAL_CHECK_MAIN ( (SFTs2 = XLALLoadSFTs( catalog, -1, -1 )) != NULL, XLAL_EFUNC ); XLALDestroySFTCatalog ( catalog ); /* ---------- do some sanity checks of consistency of SFTs ----------*/ XLAL_CHECK_MAIN ( SFTs1->length == SFTs2->length, XLAL_EINVAL, "Number of SFTs differ for SFTbname1 and SFTbname2!\n"); for ( UINT4 i=0; i < SFTs1->length; i++ ) { SFTtype *sft1 = &(SFTs1->data[i]); SFTtype *sft2 = &(SFTs2->data[i]); if( strcmp( sft1->name, sft2->name ) ) { if ( lalDebugLevel ) { XLALPrintError("WARNING SFT %d: detector-prefix differ! '%s' != '%s'\n", i, sft1->name, sft2->name ); } /* exit (1); */ /* can't be too strict here, as we also allow v1-SFTs, which don't have detector-name */ } XLAL_CHECK_MAIN ( sft1->data->length == sft2->data->length, XLAL_EINVAL, "\nERROR SFT %d: lengths differ! %d != %d\n", i, sft1->data->length, sft2->data->length ); REAL8 Tdiff = XLALGPSDiff(&(sft1->epoch), &(sft2->epoch)); CHAR buf1[32], buf2[32];; XLAL_CHECK_MAIN ( Tdiff == 0.0, XLAL_EINVAL, "SFT %d: epochs differ: %s vs %s\n", i, XLALGPSToStr(buf1,&sft1->epoch), XLALGPSToStr(buf2,&sft2->epoch) ); XLAL_CHECK_MAIN ( sft1->f0 == sft2->f0, XLAL_EINVAL, "ERROR SFT %d: fmin differ: %fHz vs %fHz\n", i, sft1->f0, sft2->f0 ); XLAL_CHECK_MAIN ( sft1->deltaF == sft2->deltaF, XLAL_EINVAL, "ERROR SFT %d: deltaF differs: %fHz vs %fHz\n", i, sft1->deltaF, sft2->deltaF ); } /* for i < numSFTs */ /*---------- now do some actual comparisons ----------*/ XLAL_CHECK_MAIN ( (diffs = subtractSFTVectors ( SFTs1, SFTs2)) != NULL, XLAL_EFUNC ); if ( uvar.verbose) { for ( UINT4 i=0; i < SFTs1->length; i++) { SFTtype *sft1 = &(SFTs1->data[i]); SFTtype *sft2 = &(SFTs2->data[i]); XLALPrintInfo ("i=%02d: ", i); REAL4 norm1 = scalarProductSFT ( sft1, sft1 ); norm1 = sqrt(norm1); REAL4 norm2 = scalarProductSFT ( sft2, sft2 ); norm2 = sqrt(norm2); REAL4 scalar = scalarProductSFT ( sft1, sft2 ); REAL4 normdiff = scalarProductSFT ( &(diffs->data[i]), &(diffs->data[i]) ); REAL4 d1 = (norm1 - norm2)/norm1; REAL4 d2 = 1.0 - scalar / (norm1*norm2); REAL4 d3 = normdiff / (norm1*norm1 + norm2*norm2 ); REAL4 d4 = getMaxErrSFT (sft1, sft2); XLALPrintInfo ("(|x|-|y|)/|x|=%10.3e, 1-x.y/(|x||y|)=%10.3e, |x-y|^2/(|x|^2+|y|^2))=%10.3e, maxErr=%10.3e\n", d1, d2, d3, d4); } /* for i < SFTs->length */ } /* if verbose */ /* ---------- COMBINED measures ---------- */ { REAL4 ret; ret = scalarProductSFTVector ( SFTs1, SFTs1 ); REAL8 norm1 = sqrt( (REAL8)ret ); ret = scalarProductSFTVector ( SFTs2, SFTs2 ); REAL8 norm2 = sqrt( (REAL8)ret ); ret = scalarProductSFTVector ( SFTs1, SFTs2 ); REAL8 scalar = (REAL8) ret; ret = scalarProductSFTVector ( diffs, diffs ); REAL8 normdiff = (REAL8) ret; REAL8 d1 = (norm1 - norm2)/norm1; maxd = fmax ( maxd, d1 ); REAL8 d2 = 1.0 - scalar / (norm1*norm2); maxd = fmax ( maxd, d2 ); REAL8 d3 = normdiff / ( norm1*norm1 + norm2*norm2); maxd = fmax ( maxd, d3 ); REAL8 d4 = getMaxErrSFTVector (SFTs1, SFTs2); maxd = fmax ( maxd, d4 ); if ( uvar.verbose ) { printf ("\nTOTAL:(|x|-|y|)/|x|=%10.3e, 1-x.y/(|x||y|)=%10.3e, |x-y|^2/(|x|^2+|y|^2)=%10.3e, maxErr=%10.3e\n", d1, d2, d3, d4); } else { printf ("%10.3e %10.3e\n", d3, d4); } } /* combined total measures */ /* free memory */ XLALDestroySFTVector ( SFTs1 ); XLALDestroySFTVector ( SFTs2 ); XLALDestroySFTVector ( diffs ); XLALDestroyUserVars(); LALCheckMemoryLeaks(); if ( maxd <= uvar.relErrorMax ) { return 0; } else { return 1; } } /* main */
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; }