/*============================================================ * FUNCTION definitions *============================================================*/ int main(int argc, char *argv[]) { static LALStatus status; /* LALStatus pointer */ UserVariables_t XLAL_INIT_DECL(uvar); ConfigVariables_t XLAL_INIT_DECL(cfg); UINT4 k, numBins, numIFOs, maxNumSFTs, X, alpha; REAL8 Freq0, dFreq, normPSD; UINT4 finalBinSize, finalBinStep, finalNumBins; REAL8Vector *overSFTs = NULL; /* one frequency bin over SFTs */ REAL8Vector *overIFOs = NULL; /* one frequency bin over IFOs */ REAL8Vector *finalPSD = NULL; /* math. operation PSD over SFTs and IFOs */ REAL8Vector *finalNormSFT = NULL; /* normalised SFT power */ vrbflg = 1; /* verbose error-messages */ /* set LAL error-handler */ lal_errhandler = LAL_ERR_EXIT; /* register and read user variables */ if (initUserVars(argc, argv, &uvar) != XLAL_SUCCESS) return EXIT_FAILURE; MultiSFTVector *inputSFTs = NULL; if ( ( inputSFTs = XLALReadSFTs ( &cfg, &uvar ) ) == NULL ) { XLALPrintError ("Call to XLALReadSFTs() failed with xlalErrno = %d\n", xlalErrno ); return EXIT_FAILURE; } /* clean sfts if required */ if ( XLALUserVarWasSet( &uvar.linefiles ) ) { RandomParams *randPar=NULL; FILE *fpRand=NULL; INT4 seed, ranCount; if ( (fpRand = fopen("/dev/urandom", "r")) == NULL ) { fprintf(stderr,"Error in opening /dev/urandom" ); return EXIT_FAILURE; } if ( (ranCount = fread(&seed, sizeof(seed), 1, fpRand)) != 1 ) { fprintf(stderr,"Error in getting random seed" ); return EXIT_FAILURE; } LAL_CALL ( LALCreateRandomParams (&status, &randPar, seed), &status ); LAL_CALL( LALRemoveKnownLinesInMultiSFTVector ( &status, inputSFTs, uvar.maxBinsClean, uvar.blocksRngMed, uvar.linefiles, randPar), &status); LAL_CALL ( LALDestroyRandomParams (&status, &randPar), &status); fclose(fpRand); } /* end cleaning */ LogPrintf (LOG_DEBUG, "Computing spectrogram and PSD ... "); /* get power running-median rngmed[ |data|^2 ] from SFTs */ MultiPSDVector *multiPSD = NULL; XLAL_CHECK_MAIN( ( multiPSD = XLALNormalizeMultiSFTVect ( inputSFTs, uvar.blocksRngMed, NULL ) ) != NULL, XLAL_EFUNC); /* restrict this PSD to just the "physical" band if requested using {--Freq, --FreqBand} */ if ( ( XLALCropMultiPSDandSFTVectors ( multiPSD, inputSFTs, cfg.firstBin, cfg.lastBin )) != XLAL_SUCCESS ) { XLALPrintError ("%s: XLALCropMultiPSDandSFTVectors (inputPSD, inputSFTs, %d, %d) failed with xlalErrno = %d\n", __func__, cfg.firstBin, cfg.lastBin, xlalErrno ); return EXIT_FAILURE; } /* start frequency and frequency spacing */ Freq0 = multiPSD->data[0]->data[0].f0; dFreq = multiPSD->data[0]->data[0].deltaF; /* number of raw bins in final PSD */ numBins = multiPSD->data[0]->data[0].data->length; if ( (finalPSD = XLALCreateREAL8Vector ( numBins )) == NULL ) { LogPrintf (LOG_CRITICAL, "Out of memory!\n"); return EXIT_FAILURE; } /* number of IFOs */ numIFOs = multiPSD->length; if ( (overIFOs = XLALCreateREAL8Vector ( numIFOs )) == NULL ) { LogPrintf (LOG_CRITICAL, "Out of memory!\n"); return EXIT_FAILURE; } /* maximum number of SFTs */ maxNumSFTs = 0; for (X = 0; X < numIFOs; ++X) { maxNumSFTs = GSL_MAX(maxNumSFTs, multiPSD->data[X]->length); } if ( (overSFTs = XLALCreateREAL8Vector ( maxNumSFTs )) == NULL ) { LogPrintf (LOG_CRITICAL, "Out of memory!\n"); return EXIT_FAILURE; } /* normalize rngmd(power) to get proper *single-sided* PSD: Sn = (2/Tsft) rngmed[|data|^2]] */ normPSD = 2.0 * dFreq; /* loop over frequency bins in final PSD */ for (k = 0; k < numBins; ++k) { /* loop over IFOs */ for (X = 0; X < numIFOs; ++X) { /* number of SFTs for this IFO */ UINT4 numSFTs = multiPSD->data[X]->length; /* copy PSD frequency bins and normalise multiPSD for later use */ for (alpha = 0; alpha < numSFTs; ++alpha) { multiPSD->data[X]->data[alpha].data->data[k] *= normPSD; overSFTs->data[alpha] = multiPSD->data[X]->data[alpha].data->data[k]; } /* compute math. operation over SFTs for this IFO */ overIFOs->data[X] = math_op(overSFTs->data, numSFTs, uvar.PSDmthopSFTs); if ( isnan( overIFOs->data[X] ) ) XLAL_ERROR ( EXIT_FAILURE, "Found Not-A-Number in overIFOs->data[X=%d] = NAN ... exiting\n", X ); } /* for IFOs X */ /* compute math. operation over IFOs for this frequency */ finalPSD->data[k] = math_op(overIFOs->data, numIFOs, uvar.PSDmthopIFOs); if ( isnan ( finalPSD->data[k] ) ) XLAL_ERROR ( EXIT_FAILURE, "Found Not-A-Number in finalPSD->data[k=%d] = NAN ... exiting\n", k ); } /* for freq bins k */ LogPrintfVerbatim ( LOG_DEBUG, "done.\n"); /* compute normalised SFT power */ if (uvar.outputNormSFT) { LogPrintf (LOG_DEBUG, "Computing normalised SFT power ... "); if ( (finalNormSFT = XLALCreateREAL8Vector ( numBins )) == NULL ) { LogPrintf (LOG_CRITICAL, "Out of memory!\n"); return EXIT_FAILURE; } /* loop over frequency bins in SFTs */ for (k = 0; k < numBins; ++k) { /* loop over IFOs */ for (X = 0; X < numIFOs; ++X) { /* number of SFTs for this IFO */ UINT4 numSFTs = inputSFTs->data[X]->length; /* compute SFT power */ for (alpha = 0; alpha < numSFTs; ++alpha) { COMPLEX8 bin = inputSFTs->data[X]->data[alpha].data->data[k]; overSFTs->data[alpha] = crealf(bin)*crealf(bin) + cimagf(bin)*cimagf(bin); } /* compute math. operation over SFTs for this IFO */ overIFOs->data[X] = math_op(overSFTs->data, numSFTs, uvar.nSFTmthopSFTs); if ( isnan ( overIFOs->data[X] )) XLAL_ERROR ( EXIT_FAILURE, "Found Not-A-Number in overIFOs->data[X=%d] = NAN ... exiting\n", X ); } /* over IFOs */ /* compute math. operation over IFOs for this frequency */ finalNormSFT->data[k] = math_op(overIFOs->data, numIFOs, uvar.nSFTmthopIFOs); if ( isnan( finalNormSFT->data[k] ) ) XLAL_ERROR ( EXIT_FAILURE, "Found Not-A-Number in bin finalNormSFT->data[k=%d] = NAN ... exiting\n", k ); } /* over freq bins */ LogPrintfVerbatim ( LOG_DEBUG, "done.\n"); } /* output spectrograms */ if ( uvar.outputSpectBname ) { LAL_CALL ( LALfwriteSpectrograms ( &status, uvar.outputSpectBname, multiPSD ), &status ); } /* ---------- if user requested it, output complete MultiPSDVector over IFOs X, timestamps and freq-bins into ASCI file(s) */ if ( uvar.dumpMultiPSDVector ) { if ( XLALDumpMultiPSDVector ( uvar.outputPSD, multiPSD ) != XLAL_SUCCESS ) { XLALPrintError ("%s: XLALDumpMultiPSDVector() failed, xlalErrnor = %d\n", __func__, xlalErrno ); return EXIT_FAILURE; } } /* if uvar.dumpMultiPSDVector */ /* ----- if requested, compute data-quality factor 'Q' -------------------- */ if ( uvar.outputQ ) { REAL8FrequencySeries *Q; if ( (Q = XLALComputeSegmentDataQ ( multiPSD, cfg.dataSegment )) == NULL ) { XLALPrintError ("%s: XLALComputeSegmentDataQ() failed with xlalErrno = %d\n", __func__, xlalErrno ); return EXIT_FAILURE; } if ( XLAL_SUCCESS != XLALWriteREAL8FrequencySeries_to_file ( Q, uvar.outputQ ) ) { return EXIT_FAILURE; } XLALDestroyREAL8FrequencySeries ( Q ); } /* if outputQ */ /* ---------- BINNING if requested ---------- */ /* work out bin size */ if (XLALUserVarWasSet(&uvar.binSize)) { finalBinSize = uvar.binSize; } else if (XLALUserVarWasSet(&uvar.binSizeHz)) { finalBinSize = (UINT4)floor(uvar.binSizeHz / dFreq + 0.5); /* round to nearest bin */ } else { finalBinSize = 1; } /* work out bin step */ if (XLALUserVarWasSet(&uvar.binStep)) { finalBinStep = uvar.binStep; } else if (XLALUserVarWasSet(&uvar.binStepHz)) { finalBinStep = (UINT4)floor(uvar.binStepHz / dFreq + 0.5); /* round to nearest bin */ } else { finalBinStep = finalBinSize; } /* work out total number of bins */ finalNumBins = (UINT4)floor((numBins - finalBinSize) / finalBinStep) + 1; /* write final PSD to file */ if (XLALUserVarWasSet(&uvar.outputPSD)) { FILE *fpOut = NULL; if ((fpOut = fopen(uvar.outputPSD, "wb")) == NULL) { LogPrintf ( LOG_CRITICAL, "Unable to open output file %s for writing...exiting \n", uvar.outputPSD ); return EXIT_FAILURE; } /* write header info in comments */ if ( XLAL_SUCCESS != XLALOutputVersionString ( fpOut, 0 ) ) XLAL_ERROR ( XLAL_EFUNC ); /* write the command-line */ for (int a = 0; a < argc; a++) fprintf(fpOut,"%%%% argv[%d]: '%s'\n", a, argv[a]); /* write column headings */ fprintf(fpOut,"%%%% columns:\n%%%% FreqBinStart"); if (uvar.outFreqBinEnd) fprintf(fpOut," FreqBinEnd"); fprintf(fpOut," PSD"); if (uvar.outputNormSFT) fprintf(fpOut," normSFTpower"); fprintf(fpOut,"\n"); LogPrintf(LOG_DEBUG, "Printing PSD to file ... "); for (k = 0; k < finalNumBins; ++k) { UINT4 b = k * finalBinStep; REAL8 f0 = Freq0 + b * dFreq; REAL8 f1 = f0 + finalBinStep * dFreq; fprintf(fpOut, "%f", f0); if (uvar.outFreqBinEnd) fprintf(fpOut, " %f", f1); REAL8 psd = math_op(&(finalPSD->data[b]), finalBinSize, uvar.PSDmthopBins); if ( isnan ( psd )) XLAL_ERROR ( EXIT_FAILURE, "Found Not-A-Number in psd[k=%d] = NAN ... exiting\n", k ); fprintf(fpOut, " %e", psd); if (uvar.outputNormSFT) { REAL8 nsft = math_op(&(finalNormSFT->data[b]), finalBinSize, uvar.nSFTmthopBins); if ( isnan ( nsft )) XLAL_ERROR ( EXIT_FAILURE, "Found Not-A-Number in nsft[k=%d] = NAN ... exiting\n", k ); fprintf(fpOut, " %f", nsft); } fprintf(fpOut, "\n"); } // k < finalNumBins LogPrintfVerbatim ( LOG_DEBUG, "done.\n"); fclose(fpOut); } /* we are now done with the psd */ XLALDestroyMultiPSDVector ( multiPSD); XLALDestroyMultiSFTVector ( inputSFTs); XLALDestroyUserVars(); XLALDestroyREAL8Vector ( overSFTs ); XLALDestroyREAL8Vector ( overIFOs ); XLALDestroyREAL8Vector ( finalPSD ); XLALDestroyREAL8Vector ( finalNormSFT ); LALCheckMemoryLeaks(); return EXIT_SUCCESS; } /* main() */
int main(int argc, char *argv[]) { ConfigVariables XLAL_INIT_DECL(config); UserVariables_t XLAL_INIT_DECL(uvar); DopplerMetricParams XLAL_INIT_DECL(metricParams); vrbflg = 1; /* verbose error-messages */ /* set LAL error-handler */ lal_errhandler = LAL_ERR_EXIT; /* register user-variables */ if ( initUserVars(&uvar) != XLAL_SUCCESS ) { XLALPrintError( "%s(): initUserVars() failed\n", __func__ ); return EXIT_FAILURE; } /* read cmdline & cfgfile */ if ( XLALUserVarReadAllInput(argc,argv) != XLAL_SUCCESS ) { XLALPrintError( "%s(): XLALUserVarReadAllInput() failed\n", __func__ ); return EXIT_FAILURE; } if (uvar.help) /* help requested: we're done */ return 0; CHAR *VCSInfoString; if ( (VCSInfoString = XLALGetVersionString(0)) == NULL ) { XLALPrintError("XLALGetVersionString(0) failed.\n"); exit(1); } if ( uvar.version ) { printf ( "%s\n", VCSInfoString ); return 0; } if ( uvar.coordsHelp ) { CHAR *helpstr; if ( (helpstr = XLALDopplerCoordinateHelpAll()) == NULL ) { LogPrintf ( LOG_CRITICAL, "XLALDopplerCoordinateHelpAll() failed!\n\n"); return -1; } printf ( "\n%s\n", helpstr ); XLALFree ( helpstr ); return 0; } /* if coordsHelp */ /* basic setup and initializations */ XLAL_CHECK ( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC, "XLALInitCode() failed with xlalErrno = %d\n\n", xlalErrno ); config.history->VCSInfoString = VCSInfoString; /* parse detector motion string */ int detMotionType = XLALParseDetectorMotionString( uvar.detMotionStr ); XLAL_CHECK ( detMotionType != XLAL_FAILURE, XLAL_EFUNC, "Failed to pass detector motion string '%s'", uvar.detMotionStr ); metricParams.detMotionType = detMotionType; metricParams.segmentList = config.segmentList; metricParams.coordSys = config.coordSys; metricParams.multiIFO = config.multiIFO; metricParams.multiNoiseFloor = config.multiNoiseFloor; metricParams.signalParams = config.signalParams; metricParams.projectCoord = uvar.projection - 1; /* user-input counts from 1, but interally we count 0=1st coord. (-1==no projection) */ metricParams.approxPhase = uvar.approxPhase; /* ----- compute metric full metric + Fisher matrix ---------- */ DopplerPhaseMetric *Pmetric = NULL; if ( uvar.metricType == 0 || uvar.metricType == 2 ) { if ( (Pmetric = XLALComputeDopplerPhaseMetric ( &metricParams, config.edat )) == NULL ) { LogPrintf (LOG_CRITICAL, "Something failed in XLALComputeDopplerPhaseMetric(). xlalErrno = %d\n\n", xlalErrno); return -1; } } DopplerFstatMetric *Fmetric = NULL; if ( uvar.metricType == 1 || uvar.metricType == 2 ) { if ( (Fmetric = XLALComputeDopplerFstatMetric ( &metricParams, config.edat )) == NULL ) { LogPrintf (LOG_CRITICAL, "Something failed in XLALComputeDopplerFstatMetric(). xlalErrno = %d\n\n", xlalErrno); return -1; } } /* ---------- output results ---------- */ if ( uvar.outputMetric ) { FILE *fpMetric; if ( (fpMetric = fopen ( uvar.outputMetric, "wb" )) == NULL ) { LogPrintf (LOG_CRITICAL, "%s: failed to open '%s' for writing. error = '%s'\n", __func__, uvar.outputMetric, strerror(errno)); return FSTATMETRIC_EFILE; } if ( XLALOutputDopplerMetric ( fpMetric, Pmetric, Fmetric, config.history ) != XLAL_SUCCESS ) { LogPrintf (LOG_CRITICAL, "%s: failed to write Doppler metric into output-file '%s'. xlalErrno = %d\n\n", __func__, uvar.outputMetric, xlalErrno ); return FSTATMETRIC_EFILE; } fclose ( fpMetric ); } /* if outputMetric */ /* ----- done: free all memory */ XLALDestroyDopplerPhaseMetric ( Pmetric ); XLALDestroyDopplerFstatMetric ( Fmetric ); if ( XLALDestroyConfig( &config ) != XLAL_SUCCESS ) { LogPrintf (LOG_CRITICAL, "%s: XLADestroyConfig() failed, xlalErrno = %d.\n\n", __func__, xlalErrno ); return FSTATMETRIC_EXLAL; } LALCheckMemoryLeaks(); return 0; } /* main */
/*---------------------------------------------------------------------- * 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 */
int main(int argc, char *argv[]) { FILE *fp = NULL; BarycenterInput XLAL_INIT_DECL(baryinput); INT4 leap0,leap; LIGOTimeGPS epoch; LIGOTimeGPS TstartSSB, TendSSB, TendGPS; INT4 n; LIGOTimeGPS *TSSB = NULL; MJDTime TstartUTCMJD; LIGOTimeGPS TDET; REAL8 temp; INT4 i; MJDTime tempTOA; REAL8 dt; LIGOTimeGPS TstartGPS; MJDTime *TOA = NULL; CHAR tempstr[18]; CHAR *tempstr2; CHAR TstartMJDstr[20],TfinishMJDstr[20],TOAstr[22]; PulsarSignalParams pulsarparams; CHAR parfile[256]; CHAR timfile[256]; CHAR detcode[16]; REAL8 TstartUTCMJDtest; REAL8 diff; MJDTime MJDdiff, MJDtest; MJDTime TrefTDBMJD; LIGOTimeGPS TrefSSB_TDB_GPS; // ---------------------------------------------------------------------- UserVariables_t XLAL_INIT_DECL(uvar); XLAL_CHECK ( initUserVars (argc, argv, &uvar) == XLAL_SUCCESS, XLAL_EFUNC ); unsigned int seed = uvar.randSeed; if ( uvar.randSeed == 0 ) { seed = clock(); } srand ( seed ); // ----- sky position: random or user-specified ---------- REAL8 alpha, delta; CHAR *RAJ = NULL, *DECJ = NULL; BOOLEAN have_RAJ = XLALUserVarWasSet ( &uvar.RAJ ); BOOLEAN have_DECJ = XLALUserVarWasSet ( &uvar.DECJ ); if ( have_RAJ ) { XLAL_CHECK ( XLALTranslateHMStoRAD ( &alpha, uvar.RAJ ) == XLAL_SUCCESS, XLAL_EFUNC ); RAJ = XLALStringDuplicate ( uvar.RAJ ); } else { // pick randomly alpha = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); // alpha uniform in [0, 2pi) XLAL_CHECK ( (RAJ = XLALTranslateRADtoHMS ( alpha )) != NULL, XLAL_EFUNC ); } if ( have_DECJ ) { XLAL_CHECK ( XLALTranslateDMStoRAD ( &delta, uvar.DECJ ) == XLAL_SUCCESS, XLAL_EFUNC ); DECJ = XLALStringDuplicate ( uvar.DECJ ); } else { // pick randomly delta = LAL_PI_2 - acos ( 1 - 2.0 * rand()/RAND_MAX ); // sin(delta) uniform in [-1,1] XLAL_CHECK ( (DECJ = XLALTranslateRADtoDMS ( delta )) != NULL, XLAL_EFUNC ); } /* define start time in an MJD structure */ REAL8toMJD ( &TstartUTCMJD, uvar.TstartUTCMJD ); XLALPrintInfo ( "TstartUTCMJD=%f converted to MJD days = %d fracdays = %6.12f\n", uvar.TstartUTCMJD, TstartUTCMJD.days, TstartUTCMJD.fracdays ); /* convert back to test conversions */ TstartUTCMJDtest = MJDtoREAL8 (TstartUTCMJD); diff = uvar.TstartUTCMJD - TstartUTCMJDtest; if ( fabs(diff) > 1e-9) { fprintf(stderr,"ERROR : Time conversion gives discrepancy of %e sec. Exiting.\n",diff); return(-1); } XLALPrintInfo ( "MJD conversion gives discrepancies of %e sec\n", diff); /* use start time to define an epoch for the leap seconds */ /* Note that epochs are defined in TDB !!! but here we only need to be rough to get a leap second value */ TDBMJDtoGPS(&epoch,TstartUTCMJD); XLALPrintInfo ( "leap second epoch = %d %d\n",epoch.gpsSeconds,epoch.gpsNanoSeconds); /* deal with ephemeris files and compute leap seconds */ EphemerisData *edat; XLAL_CHECK ( (edat = XLALInitBarycenter( uvar.ephemEarth, uvar.ephemSun )) != NULL, XLAL_EFUNC ); leap0 = XLALGPSLeapSeconds (epoch.gpsSeconds); XLALPrintInfo ( "leap seconds = %d\n",leap0); /* select detector location */ if (strcmp(uvar.Observatory,"GBT")==0) { baryinput.site.location[0] = GBT_LOCATION_X; baryinput.site.location[1] = GBT_LOCATION_Y; baryinput.site.location[2] = GBT_LOCATION_Z; sprintf(detcode,"gbt"); } else if (strcmp(uvar.Observatory,"NARRABRI")==0) { baryinput.site.location[0] = NARRABRI_LOCATION_X; baryinput.site.location[1] = NARRABRI_LOCATION_Y; baryinput.site.location[2] = NARRABRI_LOCATION_Z; sprintf(detcode,"atca"); } else if (strcmp(uvar.Observatory,"ARECIBO")==0) { baryinput.site.location[0] = ARECIBO_LOCATION_X; baryinput.site.location[1] = ARECIBO_LOCATION_Y; baryinput.site.location[2] = ARECIBO_LOCATION_Z; sprintf(detcode,"ao"); } else if (strcmp(uvar.Observatory,"NANSHAN")==0) { baryinput.site.location[0] = NANSHAN_LOCATION_X; baryinput.site.location[1] = NANSHAN_LOCATION_Y; baryinput.site.location[2] = NANSHAN_LOCATION_Z; sprintf(detcode,"nanshan"); } else if (strcmp(uvar.Observatory,"DSS_43")==0) { baryinput.site.location[0] = DSS_43_LOCATION_X; baryinput.site.location[1] = DSS_43_LOCATION_Y; baryinput.site.location[2] = DSS_43_LOCATION_Z; sprintf(detcode,"tid43"); } else if (strcmp(uvar.Observatory,"PARKES")==0) { baryinput.site.location[0] = PARKES_LOCATION_X; baryinput.site.location[1] = PARKES_LOCATION_Y; baryinput.site.location[2] = PARKES_LOCATION_Z; sprintf(detcode,"pks"); } else if (strcmp(uvar.Observatory,"JODRELL")==0) { baryinput.site.location[0] = JODRELL_LOCATION_X; baryinput.site.location[1] = JODRELL_LOCATION_Y; baryinput.site.location[2] = JODRELL_LOCATION_Z; sprintf(detcode,"jb"); } else if (strcmp(uvar.Observatory,"VLA")==0) { baryinput.site.location[0] = VLA_LOCATION_X; baryinput.site.location[1] = VLA_LOCATION_Y; baryinput.site.location[2] = VLA_LOCATION_Z; sprintf(detcode,"vla"); } else if (strcmp(uvar.Observatory,"NANCAY")==0) { baryinput.site.location[0] = NANCAY_LOCATION_X; baryinput.site.location[1] = NANCAY_LOCATION_Y; baryinput.site.location[2] = NANCAY_LOCATION_Z; sprintf(detcode,"ncy"); } else if (strcmp(uvar.Observatory,"EFFELSBERG")==0) { baryinput.site.location[0] = EFFELSBERG_LOCATION_X; baryinput.site.location[1] = EFFELSBERG_LOCATION_Y; baryinput.site.location[2] = EFFELSBERG_LOCATION_Z; sprintf(detcode,"eff"); } else if (strcmp(uvar.Observatory,"JODRELLM4")==0) { baryinput.site.location[0] = JODRELLM4_LOCATION_X; baryinput.site.location[1] = JODRELLM4_LOCATION_Y; baryinput.site.location[2] = JODRELLM4_LOCATION_Z; sprintf(detcode,"jbm4"); } else if (strcmp(uvar.Observatory,"GB300")==0) { baryinput.site.location[0] = GB300_LOCATION_X; baryinput.site.location[1] = GB300_LOCATION_Y; baryinput.site.location[2] = GB300_LOCATION_Z; sprintf(detcode,"gb300"); } else if (strcmp(uvar.Observatory,"GB140")==0) { baryinput.site.location[0] = GB140_LOCATION_X; baryinput.site.location[1] = GB140_LOCATION_Y; baryinput.site.location[2] = GB140_LOCATION_Z; sprintf(detcode,"gb140"); } else if (strcmp(uvar.Observatory,"GB853")==0) { baryinput.site.location[0] = GB853_LOCATION_X; baryinput.site.location[1] = GB853_LOCATION_Y; baryinput.site.location[2] = GB853_LOCATION_Z; sprintf(detcode,"gb853"); } else if (strcmp(uvar.Observatory,"LA_PALMA")==0) { baryinput.site.location[0] = LA_PALMA_LOCATION_X; baryinput.site.location[1] = LA_PALMA_LOCATION_Y; baryinput.site.location[2] = LA_PALMA_LOCATION_Z; sprintf(detcode,"lap"); } else if (strcmp(uvar.Observatory,"Hobart")==0) { baryinput.site.location[0] = Hobart_LOCATION_X; baryinput.site.location[1] = Hobart_LOCATION_Y; baryinput.site.location[2] = Hobart_LOCATION_Z; sprintf(detcode,"hob"); } else if (strcmp(uvar.Observatory,"Hartebeesthoek")==0) { baryinput.site.location[0] = Hartebeesthoek_LOCATION_X; baryinput.site.location[1] = Hartebeesthoek_LOCATION_Y; baryinput.site.location[2] = Hartebeesthoek_LOCATION_Z; sprintf(detcode,"hart"); } else if (strcmp(uvar.Observatory,"WSRT")==0) { baryinput.site.location[0] = WSRT_LOCATION_X; baryinput.site.location[1] = WSRT_LOCATION_Y; baryinput.site.location[2] = WSRT_LOCATION_Z; sprintf(detcode,"wsrt"); } else if (strcmp(uvar.Observatory,"COE")==0) { baryinput.site.location[0] = COE_LOCATION_X; baryinput.site.location[1] = COE_LOCATION_Y; baryinput.site.location[2] = COE_LOCATION_Z; sprintf(detcode,"coe"); } else if (strcmp(uvar.Observatory,"SSB")!=0) { fprintf(stderr,"ERROR. Unknown Observatory %s. Exiting.\n",uvar.Observatory); return(-1); } XLALPrintInfo ( "selected observatory %s - observatoryt code = %s\n",uvar.Observatory,detcode); XLALPrintInfo ( "baryinput location = %6.12f %6.12f %6.12f\n",baryinput.site.location[0],baryinput.site.location[1],baryinput.site.location[2]); /* convert start time to UTC GPS */ UTCMJDtoGPS(&TstartGPS, TstartUTCMJD, leap0); XLALPrintInfo ( "TstartGPS = %d %d\n",TstartGPS.gpsSeconds,TstartGPS.gpsNanoSeconds); /* convert back to test conversion */ UTCGPStoMJD(&MJDtest,&TstartGPS,leap0); deltaMJD ( &MJDdiff, &MJDtest, &TstartUTCMJD ); diff = (MJDdiff.days+MJDdiff.fracdays)*86400; if ( fabs(diff) > 1e-9) { fprintf(stderr,"ERROR : Time conversion gives discrepancy of %e sec. Exiting.\n",diff); return(-1); } XLALPrintInfo ( "MJD conversion gives discrepancies of %e sec\n",diff); /* define reference time in an MJD structure */ REAL8toMJD ( &TrefTDBMJD, uvar.TrefTDBMJD ); XLALPrintInfo ( "TrefTDBMJD converted to MJD days = %d fracdays = %6.12f\n",TrefTDBMJD.days,TrefTDBMJD.fracdays); /* convert reference time to TDB GPS */ TDBMJDtoGPS(&TrefSSB_TDB_GPS,TrefTDBMJD); XLALPrintInfo ( "TrefSSB_TDB_GPS = %d %d\n",TrefSSB_TDB_GPS.gpsSeconds,TrefSSB_TDB_GPS.gpsNanoSeconds); /* convert back to test conversion */ TDBGPStoMJD ( &MJDtest, TrefSSB_TDB_GPS, leap0 ); deltaMJD ( &MJDdiff, &MJDtest, &TrefTDBMJD ); diff = (MJDdiff.days+MJDdiff.fracdays)*86400; if ( fabs(diff) > 1e-9) { fprintf(stderr,"ERROR : Time conversion gives discrepancy of %e sec. Exiting.\n",diff); return(-1); } XLALPrintInfo ( "MJD conversion gives discrepancies of %e sec\n",diff); /* fill in required pulsar params structure for Barycentering */ LALDetector *site = NULL; site = (LALDetector *)LALMalloc(sizeof(LALDetector)); site->location[0] = baryinput.site.location[0]; site->location[1] = baryinput.site.location[1]; site->location[2] = baryinput.site.location[2]; pulsarparams.site = site; pulsarparams.pulsar.position.longitude = alpha; pulsarparams.pulsar.position.latitude = delta; pulsarparams.pulsar.position.system = COORDINATESYSTEM_EQUATORIAL; pulsarparams.ephemerides = edat; /* generate SSB initial TOA in GPS */ XLALConvertGPS2SSB ( &TstartSSB, TstartGPS, &pulsarparams); XLALPrintInfo ( "TstartSSB = %d %d\n",TstartSSB.gpsSeconds,TstartSSB.gpsNanoSeconds); /* define TOA end time in GPS */ temp = uvar.DurationMJD*86400.0; TendGPS = TstartGPS; XLALGPSAdd(&TendGPS, temp); XLALPrintInfo ( "GPS end time of TOAs = %d %d\n",TendGPS.gpsSeconds,TendGPS.gpsNanoSeconds); /* generate SSB end time in GPS (force integer seconds) */ XLALConvertGPS2SSB (&TendSSB,TendGPS,&pulsarparams); XLALPrintInfo ( "TendSSB = %d %d\n",TendSSB.gpsSeconds,TendSSB.gpsNanoSeconds); /* define TOA seperation in the SSB */ dt = uvar.DeltaTMJD*86400.0; n = (INT4)ceil(uvar.DurationMJD/uvar.DeltaTMJD); XLALPrintInfo ( "TOA seperation at SSB = %g sec\n",dt); XLALPrintInfo ( "number of TOAs to generate = %d\n",n); /* allocate memory for artificial SSB TOAs */ TSSB = (LIGOTimeGPS *)LALMalloc(n*sizeof(LIGOTimeGPS)); TOA = (MJDTime *)LALMalloc(n*sizeof(MJDTime)); /* generate artificial SSB TOAs given the phase model phi = 2*pi*(f0*(t-tref) + 0.5*fdot*(t-tref)^2) */ for (i=0;i<n;i++) { REAL8 dtref,fnow,cyclefrac,dtcor; LIGOTimeGPS tnow; /* define current interval */ XLALPrintInfo ( "current (t-tstart) = %g sec\n", i * dt); /* define current t */ tnow = TstartSSB; XLALGPSAdd(&tnow, i * dt); XLALPrintInfo ( "current t = %d %d\n",tnow.gpsSeconds,tnow.gpsNanoSeconds); /* define current t-tref */ dtref = XLALGPSDiff(&tnow,&TrefSSB_TDB_GPS); XLALPrintInfo ( "current (t - tref) = %9.12f\n",dtref); dtcor = 1; while (dtcor>1e-9) { /* define actual cycle fraction at requested time */ cyclefrac = fmod(uvar.f0*dtref + 0.5*uvar.fdot*dtref*dtref,1.0); XLALPrintInfo ( "cyclefrac = %9.12f\n",cyclefrac); /* define instantaneous frequency */ fnow = uvar.f0 + uvar.fdot*dtref; XLALPrintInfo ( "instananeous frequency = %9.12f\n",fnow); /* add correction to time */ dtcor = cyclefrac/fnow; dtref -= dtcor; XLALPrintInfo ( "timing correction = %9.12f\n",dtcor); XLALPrintInfo ( "corrected dtref to = %9.12f\n",dtref); } // while dtcor>1e-9 /* define time of zero phase */ TSSB[i] = TrefSSB_TDB_GPS; XLALGPSAdd(&TSSB[i], dtref); XLALPrintInfo ( "TSSB[%d] = %d %d\n",i,TSSB[i].gpsSeconds,TSSB[i].gpsNanoSeconds); } // for i < n /* loop over SSB time of arrivals and compute detector time of arrivals */ for (i=0;i<n;i++) { LIGOTimeGPS TSSBtest; LIGOTimeGPS GPStest; /* convert SSB to Detector time */ int ret = XLALConvertSSB2GPS ( &TDET, TSSB[i], &pulsarparams); if ( ret != XLAL_SUCCESS ) { XLALPrintError ("XLALConvertSSB2GPS() failed with xlalErrno = %d\n", xlalErrno ); return(-1); } XLALPrintInfo ( "converted SSB TOA %d %d -> Detector TOA %d %d\n",TSSB[i].gpsSeconds,TSSB[i].gpsNanoSeconds,TDET.gpsSeconds,TDET.gpsNanoSeconds); /* convert back for testing conversion */ XLALConvertGPS2SSB (&TSSBtest,TDET,&pulsarparams); diff = XLALGPSDiff(&TSSBtest,&TSSB[i]); if ( fabs(diff) > 1e-9) { fprintf(stderr,"ERROR : Time conversion gives discrepancy of %e sec. Exiting.\n",diff); return(-1); } XLALPrintInfo ( "SSB -> detector conversion gives discrepancies of %e sec\n",diff); /* recompute leap seconds incase they've changed */ leap = XLALGPSLeapSeconds (TDET.gpsSeconds); /* must now convert to an MJD time for TEMPO */ /* Using UTC conversion as used by Matt in his successful comparison */ UTCGPStoMJD (&tempTOA,&TDET,leap); XLALPrintInfo ( "output MJD time = %d %6.12f\n",tempTOA.days,tempTOA.fracdays); /* convert back to test conversion */ UTCMJDtoGPS ( &GPStest, tempTOA, leap ); diff = XLALGPSDiff(&TDET,&GPStest); if ( fabs(diff) > 1e-9) { fprintf(stderr,"ERROR. Time conversion gives discrepancy of %e sec. Exiting.\n",diff); return(-1); } XLALPrintInfo ( "MJD time conversion gives discrepancies of %e sec\n",diff); /* fill in results */ TOA[i].days = tempTOA.days; TOA[i].fracdays = tempTOA.fracdays; } // for i < n snprintf(tempstr,15,"%1.13f",TOA[0].fracdays); tempstr2 = tempstr+2; snprintf(TstartMJDstr,19,"%d.%s",TOA[0].days,tempstr2); XLALPrintInfo ( "Converted initial TOA MJD %d %6.12f to the string %s\n",TOA[0].days,TOA[0].fracdays,TstartMJDstr); snprintf(tempstr,15,"%1.13f",TOA[n-1].fracdays); tempstr2 = tempstr+2; snprintf(TfinishMJDstr,19,"%d.%s",TOA[n-1].days,tempstr2); XLALPrintInfo ( "*** Converted MJD to a string %s\n",TfinishMJDstr); XLALPrintInfo ( "Converted final TOA MJD %d %6.12f to the string %s\n",TOA[n-1].days,TOA[n-1].fracdays,TfinishMJDstr); /* define output file names */ sprintf(parfile,"%s.par",uvar.PSRJ); sprintf(timfile,"%s.tim",uvar.PSRJ); /* output to par file in format required by TEMPO 2 */ if ((fp = fopen(parfile,"w")) == NULL) { fprintf(stderr,"ERROR. Could not open file %s. Exiting.\n",parfile); return(-1); } fprintf(fp,"PSRJ\t%s\n",uvar.PSRJ); fprintf(fp,"RAJ\t%s\t1\n",RAJ); fprintf(fp,"DECJ\t%s\t1\n",DECJ); fprintf(fp,"PEPOCH\t%6.12f\n",uvar.TrefTDBMJD); fprintf(fp,"POSEPOCH\t%6.12f\n",uvar.TrefTDBMJD); fprintf(fp,"DMEPOCH\t%6.12f\n",uvar.TrefTDBMJD); fprintf(fp,"DM\t0.0\n"); fprintf(fp,"F0\t%6.16f\t1\n",uvar.f0); fprintf(fp,"F1\t%6.16f\t0\n",uvar.fdot); fprintf(fp,"START\t%s\n",TstartMJDstr); fprintf(fp,"FINISH\t%s\n",TfinishMJDstr); fprintf(fp,"TZRSITE\t%s\n",detcode); fprintf(fp,"CLK\tUTC(NIST)\n"); fprintf(fp,"EPHEM\tDE405\n"); fprintf(fp,"UNITS\tTDB\n"); fprintf(fp,"MODE\t0\n"); /* close par file */ fclose(fp); /* output to tim file in format required by TEMPO 2 */ if ((fp = fopen(timfile,"w")) == NULL) { fprintf(stderr,"ERROR. Could not open file %s. Exiting.\n",timfile); return(-1); } fprintf(fp,"FORMAT 1\n"); for (i=0;i<n;i++) { /* convert each TOA to a string for output */ snprintf(tempstr,18,"%1.16f",TOA[i].fracdays); tempstr2 = tempstr+2; snprintf(TOAstr,22,"%d.%s",TOA[i].days,tempstr2); fprintf(fp,"blank.dat\t1000.0\t%s\t1.0\t%s\n",TOAstr,detcode); XLALPrintInfo ( "Converting MJD time %d %6.16f to string %s\n",TOA[i].days,TOA[i].fracdays,TOAstr); } // for i < n /* close tim file */ fclose(fp); /* free memory */ XLALFree ( TSSB ); XLALFree ( TOA ); XLALFree ( site ); XLALDestroyEphemerisData ( edat ); XLALDestroyUserVars (); LALCheckMemoryLeaks(); return XLAL_SUCCESS; } /* 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 */
/** * MAIN function of PredictFStat code. * Calculates the F-statistic for a given position in the sky and detector * semi-analytically and outputs the final 2F value. */ int main(int argc,char *argv[]) { LALStatus status = blank_status; /* initialize status */ REAL8 rho2; /* SNR^2 */ UserInput_t uvar = empty_UserInput; CHAR *VCSInfoString; /**< LAL + LALapps Git version string */ vrbflg = 1; /* verbose error-messages */ /* set LAL error-handler */ lal_errhandler = LAL_ERR_EXIT; /* register all user-variable */ LAL_CALL (initUserVars(&status, &uvar), &status); /* do ALL cmdline and cfgfile handling */ LAL_CALL (LALUserVarReadAllInput(&status, argc, argv), &status); if (uvar.help) /* if help was requested, we're done here */ exit (0); if ( (VCSInfoString = XLALGetVersionString(0)) == NULL ) { XLALPrintError("XLALGetVersionString(0) failed.\n"); exit(1); } if ( uvar.version ) { printf ("%s\n", VCSInfoString ); exit(0); } /* Initialize code-setup */ LAL_CALL ( InitPFS(&status, &GV, &uvar ), &status); { /* Calculating the F-Statistic */ REAL8 al1, al2, al3; REAL8 Ap2 = SQ(GV.aPlus); REAL8 Ac2 = SQ(GV.aCross); REAL8 cos2psi2 = SQ( cos(2*uvar.psi) ); REAL8 sin2psi2 = SQ( sin(2*uvar.psi) ); al1 = Ap2 * cos2psi2 + Ac2 * sin2psi2; /* A1^2 + A3^2 */ al2 = Ap2 * sin2psi2 + Ac2 * cos2psi2; /* A2^2 + A4^2 */ al3 = ( Ap2 - Ac2 ) * sin(2.0*uvar.psi) * cos(2.0*uvar.psi); /* A1 A2 + A3 A4 */ /* SNR^2 */ rho2 = GV.Mmunu.Sinv_Tsft * (GV.Mmunu.Ad * al1 + GV.Mmunu.Bd * al2 + 2.0 * GV.Mmunu.Cd * al3 ); } if (uvar.printFstat) fprintf(stdout, "\n%.1f\n", 4.0 + rho2); /* output predicted Fstat-value into file, if requested */ if (uvar.outputFstat) { FILE *fpFstat = NULL; CHAR *logstr = NULL; if ( (fpFstat = fopen (uvar.outputFstat, "wb")) == NULL) { XLALPrintError ("\nError opening file '%s' for writing..\n\n", uvar.outputFstat); return (PREDICTFSTAT_ESYS); } /* log search-footprint at head of output-file */ LAL_CALL( LALUserVarGetLog (&status, &logstr, UVAR_LOGFMT_CMDLINE ), &status ); fprintf(fpFstat, "%%%% cmdline: %s\n", logstr ); LALFree ( logstr ); fprintf ( fpFstat, "%s\n", VCSInfoString ); /* append 'dataSummary' */ fprintf (fpFstat, "%s", GV.dataSummary ); /* output E[2F] and std[2F] */ fprintf (fpFstat, "twoF_expected = %g;\n", 4.0 + rho2); fprintf (fpFstat, "twoF_sigma = %g;\n", sqrt( 4.0 * ( 2.0 + rho2 ) ) ); /* output antenna-pattern matrix MNat_mu_nu = matrix(A, B, C) */ { /* compute A = <a^2>, B=<b^2>, C=<ab> from the 'discretized versions Ad, Bc, Cd */ REAL8 A = GV.Mmunu.Ad / GV.numSFTs; REAL8 B = GV.Mmunu.Bd / GV.numSFTs; REAL8 C = GV.Mmunu.Cd / GV.numSFTs; REAL8 D = A * B - C * C; fprintf (fpFstat, "A = %f;\n", A ); fprintf (fpFstat, "B = %f;\n", B ); fprintf (fpFstat, "C = %f;\n", C ); fprintf (fpFstat, "D = %f;\n", D ); } fclose (fpFstat); } /* if outputFstat */ /* Free config-Variables and userInput stuff */ LAL_CALL (LALDestroyUserVars (&status), &status); LALFree ( GV.dataSummary ); XLALFree ( VCSInfoString ); /* did we forget anything ? */ LALCheckMemoryLeaks(); return 0; } /* main() */