int XLALPsdFromFile(REAL8FrequencySeries **psd, /**< [out] The PSD */ const CHAR *filename) /**< [in] name of the file to be read */ { REAL8FrequencySeries *ret; LALParsedDataFile *cfgdata=NULL; LIGOTimeGPS stubEpoch; UINT4 length, k, r; REAL8 freq, value; REAL8 step1=0, deltaF=0; int retval; /* XLALParseDataFile checks that filename is not null for us */ retval = XLALParseDataFile(&cfgdata, filename); if ( retval != XLAL_SUCCESS ) { XLAL_ERROR ( retval ); } /*number of data points */ length = cfgdata->lines->nTokens; /* allocate memory */ ret = XLALCreateREAL8FrequencySeries("PSD", &stubEpoch, 0, 0, &lalHertzUnit, length); if (ret == NULL) { XLALDestroyParsedDataFile( cfgdata ); XLALPrintError ("%s: XLALPsdFromFile() failed.\n", __func__ ); XLAL_ERROR ( XLAL_ENOMEM ); } /* now get the data */ for (k = 0; k < length; k++) { r = sscanf(cfgdata->lines->tokens[k], "%lf%lf", &freq, &value); /* Check the data file format */ if ( r != 2 ) { XLALDestroyParsedDataFile( cfgdata ); XLALPrintError ("%s: XLALPsdFromFile() failed on bad line in psd file.\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } if (deltaF == 0) { if (step1 == 0) { step1 = freq; } else { deltaF = (freq - step1); ret->deltaF = deltaF; } } ret->data->data[k] = value; } (*psd) = ret; XLALDestroyParsedDataFile( cfgdata ); return XLAL_SUCCESS; }
/** * Read config-variables from cfgfile and parse into input-structure. * An error is reported if the config-file reading fails, but the * individual variable-reads are treated as optional */ int XLALUserVarReadCfgfile ( const CHAR *cfgfile ) /**< [in] name of config-file */ { XLAL_CHECK ( cfgfile != NULL, XLAL_EINVAL ); XLAL_CHECK ( UVAR_vars.next != NULL, XLAL_EINVAL, "No memory allocated in UVAR_vars.next, did you register any user-variables?\n" ); LALParsedDataFile *cfg = NULL; XLAL_CHECK ( XLALParseDataFile ( &cfg, cfgfile ) == XLAL_SUCCESS, XLAL_EFUNC ); // step through all user-variable: read those with names from config-file LALUserVariable *ptr = &UVAR_vars; while ( (ptr=ptr->next) != NULL) { if (ptr->name == NULL) { // ignore name-less user-variable continue; } XLAL_CHECK ( (ptr->type > UVAR_TYPE_START) && (ptr->type < UVAR_TYPE_END), XLAL_EFAILED, "Invalid UVAR_TYPE '%d' outside of [%d,%d]\n", ptr->type, UVAR_TYPE_START+1, UVAR_TYPE_END-1 ); BOOLEAN wasRead; CHAR *valString = NULL; // first read the value as a string XLAL_CHECK ( XLALReadConfigSTRINGVariable ( &valString, cfg, NULL, ptr->name, &wasRead ) == XLAL_SUCCESS, XLAL_EFUNC ); if ( wasRead ) // if successful, parse this as the desired type { // destroy previous value, is applicable, then parse new one if ( UserVarTypeMap [ ptr->type ].destructor != NULL ) { UserVarTypeMap [ ptr->type ].destructor( *(char**)ptr->varp ); *(char**)ptr->varp = NULL; } // if a destructor was registered XLAL_CHECK ( UserVarTypeMap [ ptr->type ].parser( ptr->varp, valString ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALFree (valString); check_and_mark_as_set ( ptr ); } // if wasRead } // while ptr->next // ok, that should be it: check if there were more definitions we did not read UINT4Vector *unread = XLALConfigFileGetUnreadEntries ( cfg ); XLAL_CHECK ( xlalErrno == 0, XLAL_EFUNC, "XLALConfigFileGetUnreadEntries() failed\n"); if ( unread != NULL ) { XLALPrintWarning ("The following entries in config-file '%s' have not been parsed:\n", cfgfile ); for ( UINT4 i = 0; i < unread->length; i ++ ) { XLALPrintWarning ("%s\n", cfg->lines->tokens[ unread->data[i] ] ); } XLALDestroyUINT4Vector ( unread ); } XLALDestroyParsedDataFile ( cfg ); return XLAL_SUCCESS; } // XLALUserVarReadCfgfile()
/** * Parse a given 'CWsources' config file for PulsarParams, return vector * of all pulsar definitions found [using sections] */ PulsarParamsVector * XLALPulsarParamsFromFile ( const char *fname ///< [in] 'CWsources' config file name ) { XLAL_CHECK_NULL ( fname != NULL, XLAL_EINVAL ); LALParsedDataFile *cfgdata = NULL; XLAL_CHECK_NULL ( XLALParseDataFile ( &cfgdata, fname ) == XLAL_SUCCESS, XLAL_EFUNC ); LALStringVector *sections; XLAL_CHECK_NULL ( (sections = XLALListConfigFileSections ( cfgdata )) != NULL, XLAL_EFUNC ); UINT4 numPulsars = sections->length; // currently only single-section defs supported! FIXME PulsarParamsVector *sources; XLAL_CHECK_NULL ( (sources = XLALCreatePulsarParamsVector ( numPulsars )) != NULL, XLAL_EFUNC ); for ( UINT4 i = 0; i < numPulsars; i ++ ) { const char *sec_i = sections->data[i]; if ( strcmp ( sec_i, "default" ) == 0 ) { // special handling of 'default' section sec_i = NULL; } XLAL_CHECK_NULL ( XLALReadPulsarParams ( &sources->data[i], cfgdata, sec_i ) == XLAL_SUCCESS, XLAL_EFUNC ); // ----- source naming convention: 'filename:section' char *name; size_t len = strlen(fname) + strlen(sections->data[i]) + 2; XLAL_CHECK_NULL ( (name = XLALCalloc(1, len)) != NULL, XLAL_ENOMEM ); sprintf ( name, "%s:%s", fname, sections->data[i] ); sources->data[i].name = name; } // for i < numPulsars XLALDestroyStringVector ( sections ); XLALDestroyParsedDataFile ( cfgdata ); return sources; } // XLALPulsarParamsFromFile()
/** * Function for reading a numerical relativity metadata file. * It returns a list of numrel wave parameters. It uses * XLALParseDataFile() for reading the data file. This automatically * takes care of removing comment lines starting with # and other details. */ void LALNRDataFind( LALStatus *status, /**< pointer to LALStatus structure */ NRWaveCatalog *out, /**< [out] list of numrel metadata */ const CHAR *dir, /**< [in] directory with data files */ const CHAR *filename /**< [in] File with metadata information */) { LALParsedDataFile *cfgdata=NULL; UINT4 k, numWaves; INITSTATUS(status); ATTATCHSTATUSPTR (status); ASSERT (filename != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); ASSERT ( out != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); ASSERT ( dir != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); if ( XLALParseDataFile ( &cfgdata, filename ) != XLAL_SUCCESS ) { ABORT( status, NRWAVEIO_EFILE, NRWAVEIO_MSGEFILE ); } numWaves = cfgdata->lines->nTokens; /*number of waves */ /* allocate memory for output catalog */ out->length = numWaves; out->data = LALCalloc(1, out->length * sizeof(NRWaveMetaData)); if ( out->data == NULL) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } /* now get wave parameters from each line of data */ for (k = 0; k < numWaves; k++) { TRY(LALGetSingleNRMetaData( status->statusPtr, out->data + k, dir, cfgdata->lines->tokens[k]), status); } XLALDestroyParsedDataFile (cfgdata); DETATCHSTATUSPTR(status); RETURN(status); }
/** The main function of binary2sft.c * */ int main( int argc, char *argv[] ) { UserInput_t uvar = empty_UserInput; /* user input variables */ INT4 i,j; /* counter */ SFTVector *SFTvect = NULL; char *noisestr = XLALCalloc(1,sizeof(char)); /**********************************************************************************/ /* register and read all user-variables */ if (XLALReadUserVars(argc,argv,&uvar)) { LogPrintf(LOG_CRITICAL,"%s : XLALReadUserVars() failed with error = %d\n",__func__,xlalErrno); return 1; } LogPrintf(LOG_DEBUG,"%s : read in uservars\n",__func__); /**********************************************************************************/ /* read in the cache file */ LALParsedDataFile *cache = NULL; if ( XLALParseDataFile( &cache, uvar.cachefile ) != XLAL_SUCCESS ) { LogPrintf(LOG_CRITICAL,"%s : failed to parse cache file %s\n",__func__,uvar.cachefile); return 1; } INT4 Nfiles = cache->lines->nTokens; LogPrintf(LOG_DEBUG,"%s : counted %d files listed in the cache file.\n",__func__,Nfiles); /* allocate memory */ char **filenames = LALCalloc(Nfiles,sizeof(char*)); LIGOTimeGPSVector fileStart; fileStart.data = LALCalloc(Nfiles,sizeof(LIGOTimeGPS)); for (i=0;i<Nfiles;i++) filenames[i] = LALCalloc(512,sizeof(char)); for (i=0;i<Nfiles;i++) { sscanf(cache->lines->tokens[i],"%s %d %d",filenames[i],&(fileStart.data[i].gpsSeconds),&(fileStart.data[i].gpsNanoSeconds)); } XLALDestroyParsedDataFile( cache ); /* initialise the random number generator */ gsl_rng * r; if (XLALInitgslrand(&r,uvar.seed)) { LogPrintf(LOG_CRITICAL,"%s: XLALinitgslrand() failed with error = %d\n",__func__,xlalErrno); XLAL_ERROR(XLAL_EFAULT); } /* setup the binaryToSFT parameters */ BinaryToSFTparams par; par.tsft = uvar.tsft; par.freq = uvar.freq; par.freqband = uvar.freqband; par.tsamp = uvar.tsamp; par.highpassf = uvar.highpassf; par.amp_inj = uvar.amp_inj; par.f_inj = uvar.f_inj; par.asini_inj = uvar.asini_inj; XLALGPSSetREAL8(&(par.tasc_inj),uvar.tasc_inj); par.tref = fileStart.data[0]; par.P_inj = uvar.P_inj; par.phi_inj = uvar.phi_inj; par.r = r; /**********************************************************************************/ /* loop over the input files */ long int ntot = 0; for (j=0;j<Nfiles;j++) { UINT4 k = 0; INT8Vector *np = NULL; REAL8Vector *R = NULL; par.tstart = fileStart.data[j]; REAL8 norm1 = par.tsamp/par.tsft; REAL8 norm2 = 1.0/(par.tsamp*par.tsft); UINT4 oldlen; if (SFTvect==NULL) oldlen = 0; else oldlen = SFTvect->length; LogPrintf(LOG_DEBUG,"%s : working on file %s\n",__func__,filenames[j]); if (XLALBinaryToSFTVector(&SFTvect,filenames[j],&(fileStart.data[j]),&par,&np,&R)) { LogPrintf(LOG_CRITICAL,"%s : failed to convert binary input file %s to sfts\n",__func__,filenames[j]); return 1; } if ((np!=NULL) && (R!=NULL)) { for (k=0;k<np->length;k++) { ntot += np->data[k]; char temp[64]; sprintf(temp,"%d %e %e\n",SFTvect->data[oldlen+k].epoch.gpsSeconds,(REAL8)np->data[k]*norm1,R->data[k]*norm2); noisestr = (char *)XLALRealloc(noisestr,sizeof(char)*(1+strlen(noisestr)+strlen(temp))); strcat(noisestr,temp); } XLALDestroyINT8Vector(np); XLALDestroyREAL8Vector(R); } } /* end loop over input files */ /**********************************************************************************/ /* create a noise string */ /**********************************************************************************/ /* generate comment string */ char *VCSInfoString = XLALGetVersionString(0); XLAL_CHECK ( VCSInfoString != NULL, XLAL_EFUNC, "XLALGetVersionString(0) failed.\n" ); CHAR *logstr; size_t len; XLAL_CHECK ( (logstr = XLALUserVarGetLog ( UVAR_LOGFMT_CMDLINE )) != NULL, XLAL_EFUNC ); char *comment = XLALCalloc ( 1, len = strlen ( logstr ) + strlen(VCSInfoString) + strlen(noisestr) + 512 ); XLAL_CHECK ( comment != NULL, XLAL_ENOMEM, "XLALCalloc(1,%zd) failed.\n", len ); sprintf ( comment, "Generated by:\n%s\n%s\nTotal number of photons = %ld\n%s\n", logstr, VCSInfoString, ntot, noisestr ); /**********************************************************************************/ /* either write whole SFT-vector to single concatenated file */ if ( uvar.outSingleSFT ) { XLAL_CHECK ( XLALWriteSFTVector2File( SFTvect, uvar.outputdir, comment, uvar.outLabel ) == XLAL_SUCCESS, XLAL_EFUNC ); } else { /* or as individual SFT-files */ XLAL_CHECK ( XLALWriteSFTVector2Dir( SFTvect, uvar.outputdir, comment, uvar.outLabel ) == XLAL_SUCCESS, XLAL_EFUNC ); } /**********************************************************************************/ /* free memory */ XLALDestroySFTVector(SFTvect); XLALFree(logstr); XLALFree(comment); XLALFree(noisestr); LALCheckMemoryLeaks(); return 0; }
/** * 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() */
/* * main program entry point */ INT4 main(INT4 argc, CHAR **argv) { /* status */ LALStatus status = blank_status; /* counters */ int c; UINT4 i; /* mode counters */ UINT4 l, m; /* metadata file/directory */ CHAR *nrMetaFile = NULL; CHAR *nrDataDir = NULL; CHAR file_path[FILENAME_MAX]; /* metadata format */ CHAR *metadata_format = NULL; /* metadata parsing variables */ LALParsedDataFile *meta_file = NULL; BOOLEAN wasRead = 0; CHAR field[HISTORY_COMMENT]; CHAR *wf_name[MAX_L+1][(2*MAX_L) + 1]; /* common metadata */ CHAR *md_mass_ratio = NULL; CHAR *md_spin1x = NULL; CHAR *md_spin1y = NULL; CHAR *md_spin1z = NULL; CHAR *md_spin2x = NULL; CHAR *md_spin2y = NULL; CHAR *md_spin2z = NULL; CHAR *md_freq_start_22 = NULL; /* NINJA1 metadata */ CHAR *md_simulation_details = NULL; CHAR *md_nr_group = NULL; CHAR *md_email = NULL; /* NINJA2 metadata */ CHAR *md_waveform_name = NULL; CHAR *md_initial_separation = NULL; CHAR *md_eccentricity = NULL; CHAR *md_number_of_cycles_22 = NULL; CHAR *md_code = NULL; CHAR *md_submitter_email = NULL; CHAR *md_authors_emails = NULL; /* common metadata strings */ CHAR str_mass_ratio[HISTORY_COMMENT]; CHAR str_spin1x[HISTORY_COMMENT]; CHAR str_spin1y[HISTORY_COMMENT]; CHAR str_spin1z[HISTORY_COMMENT]; CHAR str_spin2x[HISTORY_COMMENT]; CHAR str_spin2y[HISTORY_COMMENT]; CHAR str_spin2z[HISTORY_COMMENT]; CHAR str_freq_start_22[HISTORY_COMMENT]; CHAR str_creator[HISTORY_COMMENT]; /* NINJA1 metadata strings */ CHAR str_simulation_details[HISTORY_COMMENT]; CHAR str_nr_group[HISTORY_COMMENT]; CHAR str_email[HISTORY_COMMENT]; /* NINJA2 metadata strings */ CHAR str_waveform_name[HISTORY_COMMENT]; CHAR str_initial_separation[HISTORY_COMMENT]; CHAR str_eccentricity[HISTORY_COMMENT]; CHAR str_number_of_cycles_22[HISTORY_COMMENT]; CHAR str_code[HISTORY_COMMENT]; CHAR str_submitter_email[HISTORY_COMMENT]; CHAR str_authors_emails[HISTORY_COMMENT]; /* channel names */ CHAR *plus_channel[MAX_L+1][(2*MAX_L) + 1]; CHAR *cross_channel[MAX_L+1][(2*MAX_L) + 1]; /* waveforms */ UINT4 wf_length; REAL4TimeVectorSeries *waveforms[MAX_L][(2*MAX_L) + 1]; REAL4TimeSeries *hplus[MAX_L+1][(2*MAX_L) + 1]; REAL4TimeSeries *hcross[MAX_L+1][(2*MAX_L) + 1]; REAL8TimeVectorSeries *waveformsREAL8[MAX_L][(2*MAX_L) + 1]; REAL8TimeSeries *hplusREAL8[MAX_L+1][(2*MAX_L) + 1]; REAL8TimeSeries *hcrossREAL8[MAX_L+1][(2*MAX_L) + 1]; /* frame variables */ LALFrameH *frame; CHAR *frame_name = NULL; LIGOTimeGPS epoch; INT4 duration; INT4 detector_flags; INT4 generatingREAL8 = 0; /* LALgetopt arguments */ struct LALoption long_options[] = { /* options that set a flag */ {"verbose", no_argument, &vrbflg, 1}, /* options that don't set a flag */ {"format", required_argument, 0, 'f'}, {"nr-meta-file", required_argument, 0, 'm'}, {"nr-data-dir", required_argument, 0, 'd'}, {"output", required_argument, 0, 'o'}, {"double-precision", no_argument, 0, 'p'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} }; /* default debug level */ lal_errhandler = LAL_ERR_EXIT; /* parse the arguments */ while(1) { /* LALgetopt_long stores long option here */ int option_index = 0; size_t LALoptarg_len; c = LALgetopt_long_only(argc, argv, "f:m:d:o:phV", long_options, &option_index); /* detect the end of the options */ if (c == -1) break; switch(c) { case 0: /* if this option sets a flag, do nothing else for now */ if (long_options[option_index].flag != 0) break; else { fprintf(stderr, "Error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg); exit(1); } break; case 'h': /* help message */ print_usage(stdout, argv[0]); exit(0); break; case 'V': /* print version information and exit */ fprintf(stdout, "Numerical Relativity Frame Generation\n"); XLALOutputVersionString(stderr, 0); exit(0); break; case 'f': /* create storage for the metadata format */ LALoptarg_len = strlen(LALoptarg) + 1; metadata_format = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR)); memcpy(metadata_format, LALoptarg, LALoptarg_len); break; case 'm': /* create storage for the meta file name */ LALoptarg_len = strlen(LALoptarg) + 1; nrMetaFile = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR)); memcpy(nrMetaFile, LALoptarg, LALoptarg_len); break; case 'd': /* create storage for the meta data directory name */ LALoptarg_len = strlen(LALoptarg) + 1; nrDataDir = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR)); memcpy(nrDataDir, LALoptarg, LALoptarg_len); break; case 'o': /* create storage for the output frame file name */ LALoptarg_len = strlen(LALoptarg) + 1; frame_name = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR)); memcpy(frame_name, LALoptarg, LALoptarg_len); break; case 'p': /* We're generating a double-precision frame */ generatingREAL8 = 1; break; case '?': print_usage(stderr, argv[0]); exit(1); break; default: fprintf(stderr, "Unknown error while parsing arguments\n"); print_usage(stderr, argv[0]); exit(1); break; } } /* check for extraneous command line arguments */ if (LALoptind < argc) { fprintf(stderr, "Extraneous command line arguments:\n"); while(LALoptind < argc) fprintf(stderr, "%s\n", argv[LALoptind++]); exit(1); } /* * check validity of arguments */ /* metadata format specified */ if (metadata_format == NULL) { fprintf(stderr, "warning: --format not specified, assuming NINJA1\n"); metadata_format = (CHAR *)calloc(7, sizeof(CHAR)); memcpy(metadata_format, "NINJA1", 7); } /* check for supported metadata format */ if (strcmp(metadata_format, "NINJA1") == 0); else if (strcmp(metadata_format, "NINJA2") == 0); else { fprintf(stderr, "Supported metadata formats are NINJA1 and NINJA2 (%s specified)\n", metadata_format); exit(1); } /* meta file specified */ if (nrMetaFile == NULL) { fprintf(stderr, "--nr-meta-file must be specified\n"); exit(1); } /* data directory specified */ if (nrDataDir == NULL) { fprintf(stderr, "--nr-data-dir must be specified\n"); exit(1); } /* output frame filename specified */ if (frame_name == NULL) { fprintf(stderr, "--output must be specified\n"); exit(1); } /* * main code */ /* frame metadata */ /* TODO: set these to something sensible */ duration = 0; epoch.gpsSeconds = 0; epoch.gpsNanoSeconds = 0; detector_flags = 0; if (vrbflg) fprintf(stdout, "reading metadata: %s\n", nrMetaFile); /* open metadata file */ XLAL_CHECK ( XLALParseDataFile(&meta_file, nrMetaFile) == XLAL_SUCCESS, XLAL_EFUNC ); /* * get metadata */ /* common metadata */ XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_mass_ratio, meta_file, NULL, "mass-ratio", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin1x, meta_file, NULL, "spin1x", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin1y, meta_file, NULL, "spin1y", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin1z, meta_file, NULL, "spin1z", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin2x, meta_file, NULL, "spin2x", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin2y, meta_file, NULL, "spin2y", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin2z, meta_file, NULL, "spin2z", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); /* format specific metadata */ if (strcmp(metadata_format, "NINJA1") == 0) { /* NINJA1 */ XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_simulation_details, meta_file, NULL, "simulation-details", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_nr_group, meta_file, NULL, "nr-group", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_email, meta_file, NULL, "email", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_freq_start_22, meta_file, NULL, "freqStart22", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); } else if (strcmp(metadata_format, "NINJA2") == 0) { /* NINJA2 */ XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_waveform_name, meta_file, NULL, "waveform-name", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_initial_separation, meta_file, NULL, "initial-separation", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_eccentricity, meta_file, NULL, "eccentricity", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_number_of_cycles_22, meta_file, NULL, "number-of-cycles-22", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_code, meta_file, NULL, "code", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_submitter_email, meta_file, NULL, "submitter-email", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_authors_emails, meta_file, NULL, "authors-emails", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_freq_start_22, meta_file, NULL, "freq-start-22", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); } else { /* unknown metadata format - should not be executed */ fprintf(stderr, "error: unsupported metadata format: %s\n", metadata_format); exit(1); } /* * set metadata strings */ /* common waveform */ snprintf(str_mass_ratio, HISTORY_COMMENT, "mass-ratio:%s", md_mass_ratio); snprintf(str_spin1x, HISTORY_COMMENT, "spin1x:%s", md_spin1x); snprintf(str_spin1y, HISTORY_COMMENT, "spin1y:%s", md_spin1y); snprintf(str_spin1z, HISTORY_COMMENT, "spin1z:%s", md_spin1z); snprintf(str_spin2x, HISTORY_COMMENT, "spin2x:%s", md_spin2x); snprintf(str_spin2y, HISTORY_COMMENT, "spin2y:%s", md_spin2y); snprintf(str_spin2z, HISTORY_COMMENT, "spin2z:%s", md_spin2z); snprintf(str_creator, HISTORY_COMMENT, "creator:%s(git:%s)", PROGRAM_NAME, lalAppsVCSId); /* format specific metadata */ if (strcmp(metadata_format, "NINJA1") == 0) { /* NINJA1 */ snprintf(str_freq_start_22, HISTORY_COMMENT, "freqStart22:%s", md_freq_start_22); snprintf(str_simulation_details, HISTORY_COMMENT, "simulation-details:%s", md_simulation_details); snprintf(str_nr_group, HISTORY_COMMENT, "nr-group:%s", md_nr_group); snprintf(str_email, HISTORY_COMMENT, "email:%s", md_email); } else if (strcmp(metadata_format, "NINJA2") == 0) { /* NINJA2 */ snprintf(str_waveform_name, HISTORY_COMMENT, "waveform-name:%s", md_waveform_name); snprintf(str_initial_separation, HISTORY_COMMENT, "inital-separation:%s", md_initial_separation); snprintf(str_eccentricity, HISTORY_COMMENT, "eccentricity:%s", md_eccentricity); snprintf(str_freq_start_22, HISTORY_COMMENT, "freq_start_22:%s", md_freq_start_22); snprintf(str_number_of_cycles_22, HISTORY_COMMENT, "number-of-cycles-22:%s", md_number_of_cycles_22); snprintf(str_code, HISTORY_COMMENT, "code:%s", md_code); snprintf(str_submitter_email, HISTORY_COMMENT, "submitter-email:%s", md_submitter_email); snprintf(str_authors_emails, HISTORY_COMMENT, "authors-emails:%s", md_authors_emails); } else { /* unknown metadata format - should not be executed */ fprintf(stderr, "error: unsupported metadata format: %s\n", metadata_format); exit(1); } /* define frame */ frame = XLALFrameNew(&epoch, duration, "NR", 0, 1, detector_flags); /* * add metadata as FrHistory structures */ /* common metadata */ XLALFrameAddFrHistory(frame, "creator", str_creator); XLALFrameAddFrHistory(frame, "mass-ratio", str_mass_ratio); XLALFrameAddFrHistory(frame, "spin1x", str_spin1x); XLALFrameAddFrHistory(frame, "spin1y", str_spin1y); XLALFrameAddFrHistory(frame, "spin1z", str_spin1z); XLALFrameAddFrHistory(frame, "spin2x", str_spin2x); XLALFrameAddFrHistory(frame, "spin2y", str_spin2y); XLALFrameAddFrHistory(frame, "spin2z", str_spin2z); /* format specific metadata */ if (strcmp(metadata_format, "NINJA1") == 0) { /* NINJA1 */ XLALFrameAddFrHistory(frame, "simulation-details", str_simulation_details); XLALFrameAddFrHistory(frame, "nr-group", str_nr_group); XLALFrameAddFrHistory(frame, "email", str_email); XLALFrameAddFrHistory(frame, "freqStart22", str_freq_start_22); } else if (strcmp(metadata_format, "NINJA2") == 0) { /* NINJA2 */ XLALFrameAddFrHistory(frame, "waveform-name", str_waveform_name); XLALFrameAddFrHistory(frame, "initial-separation", str_initial_separation); XLALFrameAddFrHistory(frame, "eccentricity", str_eccentricity); XLALFrameAddFrHistory(frame, "freq_start_22", str_freq_start_22); XLALFrameAddFrHistory(frame, "number-of-cycles-22", str_number_of_cycles_22); XLALFrameAddFrHistory(frame, "code", str_code); XLALFrameAddFrHistory(frame, "submitter-email", str_code); XLALFrameAddFrHistory(frame, "authors-emails", str_authors_emails); } else { /* unknown metadata format - should not be executed */ fprintf(stderr, "error: unsupported metadata format: %s\n", metadata_format); exit(1); } /* loop over l & m values */ for (l = MIN_L; l <= MAX_L; l++) { for (m = (MAX_L - l); m <= MAX_L + l; m++) { /* ensure pointers are NULL */ wf_name[l][m] = NULL; plus_channel[l][m] = NULL; cross_channel[l][m] = NULL; /* generate channel names */ plus_channel[l][m] = XLALGetNinjaChannelName("plus", l, m - MAX_L); cross_channel[l][m] = XLALGetNinjaChannelName("cross", l, m - MAX_L); if (generatingREAL8) { hplusREAL8[l][m] = NULL; hcrossREAL8[l][m] = NULL; waveformsREAL8[l][m] = NULL; /* initilise waveform time series */ hplusREAL8[l][m] = XLALCreateREAL8TimeSeries(plus_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0); hcrossREAL8[l][m] = XLALCreateREAL8TimeSeries(cross_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0); } else { hplus[l][m] = NULL; hcross[l][m] = NULL; waveforms[l][m] = NULL; /* initilise waveform time series */ hplus[l][m] = XLALCreateREAL4TimeSeries(plus_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0); hcross[l][m] = XLALCreateREAL4TimeSeries(cross_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0); } /* read ht-data section of metadata file */ snprintf(field, HISTORY_COMMENT, "%d,%d", l, m - MAX_L); XLAL_CHECK ( XLALReadConfigSTRINGVariable( &wf_name[l][m], meta_file, NULL, field, &wasRead) == XLAL_SUCCESS, XLAL_EFUNC ); /* read waveform */ if (wf_name[l][m] != NULL) { /* get full path to waveform data file */ snprintf(file_path, FILENAME_MAX, "%s/%s", nrDataDir, wf_name[l][m]); if (vrbflg) fprintf(stdout, "reading waveform: %s\n", file_path); /* read waveforms */ if (generatingREAL8) { LAL_CALL(LALReadNRWave_raw_real8(&status, &waveformsREAL8[l][m], file_path), &status); } else { LAL_CALL(LALReadNRWave_raw(&status, &waveforms[l][m], file_path), &status); } } /* generate waveform time series from vector series */ /* TODO: should use pointer arithmetic here and update the data * pointer in the REAL4TimeSeries to point to the appropriate * location within the REAL4TimeVector Series */ if (generatingREAL8) { if (waveformsREAL8[l][m]) { /* get length of waveform */ wf_length = waveformsREAL8[l][m]->data->vectorLength; /* allocate memory for waveform */ XLALResizeREAL8TimeSeries(hplusREAL8[l][m], 0, wf_length); XLALResizeREAL8TimeSeries(hcrossREAL8[l][m], 0, wf_length); /* set time spacing */ hplusREAL8[l][m]->deltaT = waveformsREAL8[l][m]->deltaT; hcrossREAL8[l][m]->deltaT = waveformsREAL8[l][m]->deltaT; /* copy waveforms into appropriate series */ for (i = 0; i < wf_length; i ++) { hplusREAL8[l][m]->data->data[i] = waveformsREAL8[l][m]->data->data[i]; hcrossREAL8[l][m]->data->data[i] = waveformsREAL8[l][m]->data->data[wf_length + i]; } /* Done with waveformsREAL8, clean up here to limit memory usage */ LALFree(waveformsREAL8[l][m]->data->data); LALFree(waveformsREAL8[l][m]->data); LALFree(waveformsREAL8[l][m]); } } else /* REAL4 */ { if (waveforms[l][m]) { /* get length of waveform */ wf_length = waveforms[l][m]->data->vectorLength; /* allocate memory for waveform */ XLALResizeREAL4TimeSeries(hplus[l][m], 0, wf_length); XLALResizeREAL4TimeSeries(hcross[l][m], 0, wf_length); /* set time spacing */ hplus[l][m]->deltaT = waveforms[l][m]->deltaT; hcross[l][m]->deltaT = waveforms[l][m]->deltaT; /* copy waveforms into appropriate series */ for (i = 0; i < wf_length; i ++) { hplus[l][m]->data->data[i] = waveforms[l][m]->data->data[i]; hcross[l][m]->data->data[i] = waveforms[l][m]->data->data[wf_length + i]; } } } /* add channels to frame */ if (generatingREAL8) { if ((hplusREAL8[l][m]->data->length) && (hcrossREAL8[l][m]->data->length)) { XLALFrameAddREAL8TimeSeriesSimData(frame, hplusREAL8[l][m]); XLALFrameAddREAL8TimeSeriesSimData(frame, hcrossREAL8[l][m]); } } else { if ((hplus[l][m]->data->length) && (hcross[l][m]->data->length)) { XLALFrameAddREAL4TimeSeriesSimData(frame, hplus[l][m]); XLALFrameAddREAL4TimeSeriesSimData(frame, hcross[l][m]); } } } } if (vrbflg) fprintf(stdout, "writing frame: %s\n", frame_name); /* write frame */ if (XLALFrameWrite(frame, frame_name) != 0 ) { fprintf(stderr, "Error: Cannot save frame file '%s'\n", frame_name); exit(1); } /* * clear memory */ /* strings */ if(nrMetaFile) free(nrMetaFile); if(nrDataDir) free(nrDataDir); if(frame_name) free(frame_name); if(metadata_format) free(metadata_format); /* common metadata */ if(md_mass_ratio) LALFree(md_mass_ratio); if(md_spin1x) LALFree(md_spin1x); if(md_spin1y) LALFree(md_spin1y); if(md_spin1z) LALFree(md_spin1z); if(md_spin2x) LALFree(md_spin2x); if(md_spin2y) LALFree(md_spin2y); if(md_spin2z) LALFree(md_spin2z); if(md_freq_start_22) LALFree(md_freq_start_22); /* NINJA1 metadata */ if(md_simulation_details) LALFree(md_simulation_details); if(md_nr_group) LALFree(md_nr_group); if(md_email) LALFree(md_email); /* NINJA2 metadata */ if(md_waveform_name) LALFree(md_waveform_name); if(md_initial_separation) LALFree(md_initial_separation); if(md_eccentricity) LALFree(md_eccentricity); if(md_number_of_cycles_22) LALFree(md_number_of_cycles_22); if(md_code) LALFree(md_code); if(md_submitter_email) LALFree(md_submitter_email); if(md_authors_emails) LALFree(md_authors_emails); /* config file */ if(meta_file->lines->list->data) LALFree(meta_file->lines->list->data); if(meta_file->lines->list) LALFree(meta_file->lines->list); if(meta_file->lines->tokens) LALFree(meta_file->lines->tokens); if(meta_file->lines) LALFree(meta_file->lines); if(meta_file->wasRead) LALFree(meta_file->wasRead); if(meta_file) LALFree(meta_file); /* waveforms */ if (generatingREAL8) { for (l = MIN_L; l <= MAX_L; l++) { for (m = (MAX_L - l); m <= MAX_L + l; m++) { /* channel names */ if (plus_channel[l][m]) LALFree(plus_channel[l][m]); if (cross_channel[l][m]) LALFree(cross_channel[l][m]); if (wf_name[l][m]) LALFree(wf_name[l][m]); /* hplus */ if (hplusREAL8[l][m]) XLALDestroyREAL8TimeSeries(hplusREAL8[l][m]); /* hcross */ if (hcrossREAL8[l][m]) XLALDestroyREAL8TimeSeries(hcrossREAL8[l][m]); } } } else { for (l = MIN_L; l <= MAX_L; l++) { for (m = (MAX_L - l); m <= MAX_L + l; m++) { /* channel names */ if (plus_channel[l][m]) LALFree(plus_channel[l][m]); if (cross_channel[l][m]) LALFree(cross_channel[l][m]); if (wf_name[l][m]) LALFree(wf_name[l][m]); /* raw waveforms */ if (waveforms[l][m]) { LALFree(waveforms[l][m]->data->data); LALFree(waveforms[l][m]->data); LALFree(waveforms[l][m]); } /* hplus */ if (hplus[l][m]) XLALDestroyREAL4TimeSeries(hplus[l][m]); /* hcross */ if (hcross[l][m]) XLALDestroyREAL4TimeSeries(hcross[l][m]); } } } /* clear frame */ XLALFrameFree(frame); /* check for memory leaks */ LALCheckMemoryLeaks(); exit(0); }
/** * An XLAL interface for reading a time correction file containing a table * of values for converting between Terrestrial Time TT (or TDT) to either * TDB (i.e. the file contains time corrections related to the Einstein delay) * or Teph (a time system from Irwin and Fukushima, 1999, closely related to * Coordinate Barycentric Time, TCB) depending on the file. * * The file contains a header with the GPS start time, GPS end time, time * interval between subsequent entries (seconds), and the number of entries. * * The rest of the file contains a list of the time delays (in seconds). * * The tables for the conversion to TDB and Teph are derived from the ephemeris * file TDB.1950.2050 and TIMEEPH_short.te405 within TEMPO2 * http://www.atnf.csiro.au/research/pulsar/tempo2/. They are created from the * Chebychev polynomials in these files using the conversion in the lalapps code * lalapps_create_time_correction_ephemeris * * \ingroup LALBarycenter_h */ TimeCorrectionData * XLALInitTimeCorrections ( const CHAR *timeCorrectionFile /**< File containing Earth's position. */ ) { REAL8 *tvec = NULL; /* create time vector */ LALParsedDataFile *flines = NULL; UINT4 numLines = 0, j = 0; REAL8 endtime = 0.; /* check user input consistency */ if ( !timeCorrectionFile ) XLAL_ERROR_NULL( XLAL_EINVAL, "Invalid NULL input for 'timeCorrectionFile'\n" ); char *fname_path; XLAL_CHECK_NULL ( (fname_path = XLALPulsarFileResolvePath ( timeCorrectionFile )) != NULL, XLAL_EINVAL ); /* read in file with XLALParseDataFile to ignore comment header lines */ if ( XLALParseDataFile ( &flines, fname_path ) != XLAL_SUCCESS ) { XLALFree ( fname_path ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } XLALFree ( fname_path ); /* prepare output ephemeris struct for returning */ TimeCorrectionData *tdat; if ( ( tdat = XLALCalloc ( 1, sizeof(*tdat) ) ) == NULL ) XLAL_ERROR_NULL ( XLAL_ENOMEM, "XLALCalloc ( 1, %zu ) failed.\n", sizeof(*tdat) ); numLines = flines->lines->nTokens; /* read in info from first line (an uncommented header) */ if ( 4 != sscanf(flines->lines->tokens[0], "%lf %lf %lf %u", &tdat->timeCorrStart, &endtime, &tdat->dtTtable, &tdat->nentriesT) ) { XLALDestroyParsedDataFile ( flines ); XLALDestroyTimeCorrectionData( tdat ); XLAL_ERROR_NULL ( XLAL_EDOM, "Couldn't parse first line of %s\n", timeCorrectionFile ); } if( numLines - 1 != tdat->nentriesT ) { XLALDestroyParsedDataFile ( flines ); XLALDestroyTimeCorrectionData( tdat ); XLAL_ERROR_NULL ( XLAL_EDOM, "Header says file has '%d' data-lines, but found '%d'.\n", tdat->nentriesT, numLines -1 ); } /* allocate memory for table entries */ if ( (tvec = XLALCalloc( tdat->nentriesT, sizeof(REAL8) )) == NULL ) { XLALDestroyParsedDataFile ( flines ); XLALDestroyTimeCorrectionData( tdat ); XLAL_ERROR_NULL ( XLAL_ENOMEM, " XLALCalloc(%u, sizeof(REAL8))\n", tdat->nentriesT ); } /* read in table data */ int ret; for (j=1; j < numLines; j++) { if ( (ret = sscanf( flines->lines->tokens[j], "%lf", &tvec[j-1] )) != 1 ) { XLALFree( tvec ); XLALDestroyParsedDataFile ( flines ); XLALDestroyTimeCorrectionData( tdat ); XLAL_ERROR_NULL ( XLAL_EDOM, "Couldn't parse line %d of %s: read %d instead of 1\n", j+2, timeCorrectionFile, ret); } } // for j < numLines XLALDestroyParsedDataFile ( flines ); /* set output time delay vector */ tdat->timeCorrs = tvec; return tdat; } /* XLALInitTimeCorrections() */
/** * XLAL function to read ephemeris-data from one file, returning a EphemerisVector. * This is a helper-function to XLALInitBarycenter(). * * NOTE: This function tries to read ephemeris from "<fname>" first, if that fails it also tries * to read "<fname>.gz" instead. This allows us to handle gzip-compressed ephemeris-files without having * to worry about the detailed filename extension used in the case of compression. * * NOTE2: files are searches first locally, then in LAL_DATA_PATH, and finally in PKG_DATA_DIR * using XLALPulsarFileResolvePath() */ EphemerisVector * XLALReadEphemerisFile ( const CHAR *fname ) { /* check input consistency */ XLAL_CHECK_NULL ( fname != NULL, XLAL_EINVAL ); char *fname_path = NULL; // first check if "<fname>" can be resolved ... if ( (fname_path = XLALPulsarFileResolvePath ( fname )) == NULL ) { // if not, check if we can find "<fname>.gz" instead ... char *fname_gz; XLAL_CHECK_NULL ( (fname_gz = XLALMalloc ( strlen(fname) + strlen(".gz") + 1 )) != NULL, XLAL_ENOMEM ); sprintf ( fname_gz, "%s.gz", fname ); if ( (fname_path = XLALPulsarFileResolvePath ( fname_gz )) == NULL ) { XLALFree ( fname_gz ); XLAL_ERROR_NULL ( XLAL_EINVAL, "Failed to find ephemeris-file '%s[.gz]'\n", fname ); } // if 'fname_gz' could not be resolved XLALFree ( fname_gz ); } // if 'fname' couldn't be resolved // if we're here, it means we found it // read in whole file (compressed or not) with XLALParseDataFile(), which ignores comment header lines LALParsedDataFile *flines = NULL; XLAL_CHECK_NULL ( XLALParseDataFile ( &flines, fname_path ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALFree ( fname_path ); UINT4 numLines = flines->lines->nTokens; INT4 gpsYr; /* gpsYr + leap is the time on the GPS clock * at first instant of new year, UTC; equivalently * leap is # of leap secs added between Jan.6, 1980 and * Jan. 2 of given year */ REAL8 dt; /* ephemeris-file time-step in seconds */ UINT4 nEntries; /* number of ephemeris-file entries */ /* read first line */ if ( 3 != sscanf(flines->lines->tokens[0],"%d %le %u\n", &gpsYr, &dt, &nEntries)) { XLALDestroyParsedDataFile( flines ); XLAL_ERROR_NULL ( XLAL_EDOM, "Couldn't parse first line of %s\n", fname ); } /* check that number of lines is correct */ if( nEntries != (numLines - 1)/4 ) { XLALDestroyParsedDataFile( flines ); XLAL_ERROR_NULL ( XLAL_EDOM, "Inconsistent number of data-lines (%d) in file '%s' compared to header information (%d)\n", (numLines - 1)/4, fname, nEntries); } /* prepare output ephemeris vector */ EphemerisVector *ephemV; if ( (ephemV = XLALCreateEphemerisVector ( nEntries )) == NULL ) XLAL_ERROR_NULL ( XLAL_EFUNC, "Failed to XLALCreateEphemerisVector(%d)\n", nEntries ); ephemV->dt = dt; /* first column in ephemeris-file is gps time--one long integer * giving the number of secs that have ticked since start of GPS epoch * + on 1980 Jan. 6 00:00:00 UTC */ /* the ephemeris files are created with each entry spanning 4 lines with the * format: * gps\tposX\tposY\n * posZ\tvelX\tvelY\n * velZ\taccX\taccY\n * accZ\n ***************************************************************************/ /* read the remaining lines */ for ( UINT4 j = 0; j < nEntries; j++ ) { UINT4 i_line; int ret; i_line = 1 + 4*j; ret = sscanf( flines->lines->tokens[ i_line ], "%le %le %le\n", &ephemV->data[j].gps, &ephemV->data[j].pos[0], &ephemV->data[j].pos[1] ); XLAL_CHECK_NULL ( ret == 3, XLAL_EDOM, "Couldn't parse line %d of %s: read %d items instead of 3\n", i_line, fname, ret ); i_line ++; ret = sscanf( flines->lines->tokens[ i_line ], "%le %le %le\n", &ephemV->data[j].pos[2], &ephemV->data[j].vel[0], &ephemV->data[j].vel[1] ); XLAL_CHECK_NULL ( ret == 3, XLAL_EDOM, "Couldn't parse line %d of %s: read %d items instead of 3\n", i_line, fname, ret ); i_line ++; ret = sscanf( flines->lines->tokens[ i_line ], "%le %le %le\n", &ephemV->data[j].vel[2], &ephemV->data[j].acc[0], &ephemV->data[j].acc[1] ); XLAL_CHECK_NULL ( ret == 3, XLAL_EDOM, "Couldn't parse line %d of %s: read %d items instead of 3\n", i_line, fname, ret ); i_line ++; ret = sscanf( flines->lines->tokens[ i_line ], "%le\n", &ephemV->data[j].acc[2] ); XLAL_CHECK_NULL ( ret == 1, XLAL_EDOM, "Couldn't parse line %d of %s: read %d items instead of 1\n", i_line, fname, ret ); /* check timestamps */ if(j == 0) { if (gpsYr - ephemV->data[j].gps > 3600 * 24 * 365 ) { XLALDestroyEphemerisVector ( ephemV ); XLALDestroyParsedDataFile( flines ); XLAL_ERROR_NULL ( XLAL_EDOM, "Wrong timestamp in line %d of %s: %d/%le\n", j+2, fname, gpsYr, ephemV->data[j].gps ); } } else { if (ephemV->data[j].gps != ephemV->data[j-1].gps + ephemV->dt ) { XLALDestroyEphemerisVector ( ephemV ); XLALDestroyParsedDataFile( flines ); XLAL_ERROR_NULL ( XLAL_EDOM, "Wrong timestamp in line %d of %s: %le/%le\n", j+2, fname, ephemV->data[j].gps, ephemV->data[j-1].gps + ephemV->dt ); } } } /* for j < nEntries */ XLALDestroyParsedDataFile( flines ); /* return result */ return ephemV; } /* XLALReadEphemerisFile() */
void LALReadNRWave_raw(LALStatus *status, /**< pointer to LALStatus structure */ REAL4TimeVectorSeries **out, /**< [out] output time series for h+ and hx */ const CHAR *filename /**< [in] File containing numrel waveform */) { UINT4 length, k, r; REAL4TimeVectorSeries *ret=NULL; REAL4VectorSequence *data=NULL; REAL4Vector *timeVec=NULL; LALParsedDataFile *cfgdata=NULL; REAL4 tmp1, tmp2, tmp3; INITSTATUS(status); ATTATCHSTATUSPTR (status); /* some consistency checks */ ASSERT (filename != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); ASSERT ( out != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); ASSERT ( *out == NULL, status, NRWAVEIO_ENONULL, NRWAVEIO_MSGENONULL ); if ( XLALParseDataFile ( &cfgdata, filename) != XLAL_SUCCESS ) { ABORT( status, NRWAVEIO_EFILE, NRWAVEIO_MSGEFILE ); } length = cfgdata->lines->nTokens; /*number of data points */ /* allocate memory */ ret = LALCalloc(1, sizeof(*ret)); if (!ret) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } strcpy(ret->name,filename); ret->f0 = 0; data = XLALCreateREAL4VectorSequence (2, length); if (!data) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } timeVec = XLALCreateREAL4Vector (length); if (!timeVec) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } /* now get the data */ for (k = 0; k < length; k++) { r = sscanf(cfgdata->lines->tokens[k], "%f%f%f", &tmp1, &tmp2, &tmp3); /* Check the data file format */ if ( r != 3) { /* there must be exactly 3 data entries -- time, h+, hx */ ABORT( status, NRWAVEIO_EFORMAT, NRWAVEIO_MSGEFORMAT ); } timeVec->data[k] = tmp1; data->data[k] = tmp2; data->data[data->vectorLength + k] = tmp3; } /* scale time */ ret->deltaT = timeVec->data[1] - timeVec->data[0]; /* might also want to go through timeVec to make sure it is evenly spaced */ ret->data = data; (*out) = ret; XLALDestroyREAL4Vector (timeVec); XLALDestroyParsedDataFile ( cfgdata); DETATCHSTATUSPTR(status); RETURN(status); } /* LALReadNRWave() */
/** * Read config-variables from cfgfile and parse into input-structure. * An error is reported if the config-file reading fails, but the * individual variable-reads are treated as optional * * If \p *should_exit is TRUE when this function returns, the * caller should exit immediately. */ int XLALUserVarReadCfgfile ( BOOLEAN *should_exit, const CHAR *cfgfile ) { XLAL_CHECK ( should_exit != NULL, XLAL_EFAULT ); XLAL_CHECK ( cfgfile != NULL, XLAL_EINVAL ); XLAL_CHECK ( UVAR_vars.next != NULL, XLAL_EINVAL, "No memory allocated in UVAR_vars.next, did you register any user-variables?\n" ); *should_exit = 0; LALParsedDataFile *cfg = NULL; XLAL_CHECK ( XLALParseDataFile ( &cfg, cfgfile ) == XLAL_SUCCESS, XLAL_EFUNC ); // step through all user-variable: read those with names from config-file LALUserVariable *ptr = &UVAR_vars; while ( (ptr=ptr->next) != NULL) { XLAL_CHECK ( (ptr->type > UVAR_TYPE_START) && (ptr->type < UVAR_TYPE_END), XLAL_EFAILED, "Invalid UVAR_TYPE '%d' outside of [%d,%d]\n", ptr->type, UVAR_TYPE_START+1, UVAR_TYPE_END-1 ); BOOLEAN wasRead; CHAR *valString = NULL; // first read the value as a string XLAL_CHECK ( XLALReadConfigSTRINGVariable ( &valString, cfg, NULL, ptr->name, &wasRead ) == XLAL_SUCCESS, XLAL_EFUNC ); if ( wasRead ) // if successful, parse this as the desired type { // destroy previous value, is applicable, then parse new one if ( UserVarTypeMap [ ptr->type ].destructor != NULL ) { UserVarTypeMap [ ptr->type ].destructor( *(char**)ptr->varp ); *(char**)ptr->varp = NULL; } // if a destructor was registered if ( UserVarTypeMap [ ptr->type ].parser( ptr->varp, valString ) != XLAL_SUCCESS ) { XLALPrintError( "\n%s: could not parse value given to option " UVAR_FMT "\n\n", program_name, ptr->name ); *should_exit = 1; return XLAL_SUCCESS; } XLALFree (valString); switch ( ptr->was_set ) { case 0: // this variable has not been set; mark as set in configuration file ptr->was_set = 1; break; default: // this variable has been set before; error XLALUserVarCheck( should_exit, 0, "configuration option `%s' was set more than once!", ptr->name ); return XLAL_SUCCESS; } } // if wasRead } // while ptr->next // ok, that should be it: check if there were more definitions we did not read UINT4Vector *unread = XLALConfigFileGetUnreadEntries ( cfg ); XLAL_CHECK ( xlalErrno == 0, XLAL_EFUNC, "XLALConfigFileGetUnreadEntries() failed\n"); if ( unread != NULL ) { XLALPrintWarning ("The following entries in config-file '%s' have not been parsed:\n", cfgfile ); for ( UINT4 i = 0; i < unread->length; i ++ ) { XLALPrintWarning ("%s\n", cfg->lines->tokens[ unread->data[i] ] ); } XLALDestroyUINT4Vector ( unread ); } XLALDestroyParsedDataFile ( cfg ); return XLAL_SUCCESS; } // XLALUserVarReadCfgfile()