/** * Handle user-input and set up shop accordingly, and do all * consistency-checks on user-input. */ int XLALInitMakefakedata ( ConfigVars_t *cfg, UserVariables_t *uvar ) { XLAL_CHECK ( cfg != NULL, XLAL_EINVAL, "Invalid NULL input 'cfg'\n" ); XLAL_CHECK ( uvar != NULL, XLAL_EINVAL, "Invalid NULL input 'uvar'\n"); cfg->VCSInfoString = XLALGetVersionString(0); XLAL_CHECK ( cfg->VCSInfoString != NULL, XLAL_EFUNC, "XLALGetVersionString(0) failed.\n" ); // version info was requested: output then exit if ( uvar->version ) { printf ("%s\n", cfg->VCSInfoString ); exit (0); } /* if requested, log all user-input and code-versions */ if ( uvar->logfile ) { XLAL_CHECK ( XLALWriteMFDlog ( uvar->logfile, cfg ) == XLAL_SUCCESS, XLAL_EFUNC, "XLALWriteMFDlog() failed with xlalErrno = %d\n", xlalErrno ); } /* Init ephemerides */ XLAL_CHECK ( (cfg->edat = XLALInitBarycenter ( uvar->ephemEarth, uvar->ephemSun )) != NULL, XLAL_EFUNC ); /* check for negative fMin and Band, which would break the fMin_eff, fBand_eff calculation below */ XLAL_CHECK ( uvar->fmin >= 0, XLAL_EDOM, "Invalid negative frequency fMin=%f!\n\n", uvar->fmin ); XLAL_CHECK ( uvar->Band > 0, XLAL_EDOM, "Invalid non-positive frequency band Band=%f!\n\n", uvar->Band ); // ---------- check user-input consistency ---------- // ----- check if frames + frame channels given BOOLEAN have_frames = (uvar->inFrames != NULL); BOOLEAN have_channels= (uvar->inFrChannels != NULL); XLAL_CHECK ( !(have_frames || have_channels) || (have_frames && have_channels), XLAL_EINVAL, "Need both --inFrames and --inFrChannels, or NONE\n"); // ----- IFOs : only from one of {--IFOs, --noiseSFTs, --inFrChannels}: mutually exclusive BOOLEAN have_IFOs = (uvar->IFOs != NULL); BOOLEAN have_noiseSFTs = (uvar->noiseSFTs != NULL); XLAL_CHECK ( have_frames || have_IFOs || have_noiseSFTs, XLAL_EINVAL, "Need one of --IFOs, --noiseSFTs or --inFrChannels to determine detectors\n"); if ( have_frames ) { XLAL_CHECK ( !have_IFOs && !have_noiseSFTs, XLAL_EINVAL, "If --inFrames given, cannot handle --IFOs or --noiseSFTs input\n"); XLAL_CHECK ( XLALParseMultiLALDetector ( &(cfg->multiIFO), uvar->inFrChannels ) == XLAL_SUCCESS, XLAL_EFUNC ); } else { // !have_frames XLAL_CHECK ( !(have_IFOs && have_noiseSFTs), XLAL_EINVAL, "Cannot handle both --IFOs and --noiseSFTs input\n"); } if ( have_IFOs ) { XLAL_CHECK ( XLALParseMultiLALDetector ( &(cfg->multiIFO), uvar->IFOs ) == XLAL_SUCCESS, XLAL_EFUNC ); } // ----- TIMESTAMPS: either from --timestampsFiles, --startTime+duration, or --noiseSFTs BOOLEAN have_startTime = XLALUserVarWasSet ( &uvar->startTime ); BOOLEAN have_duration = XLALUserVarWasSet ( &uvar->duration ); BOOLEAN have_timestampsFiles = ( uvar->timestampsFiles != NULL ); // need BOTH startTime+duration or none XLAL_CHECK ( ( have_duration && have_startTime) || !( have_duration || have_startTime ), XLAL_EINVAL, "Need BOTH {--startTime,--duration} or NONE\n"); // at least one of {startTime,timestamps,noiseSFTs,inFrames} required XLAL_CHECK ( have_timestampsFiles || have_startTime || have_noiseSFTs || have_frames, XLAL_EINVAL, "Need at least one of {--timestampsFiles, --startTime+duration, --noiseSFTs, --inFrames}\n" ); // don't allow timestamps + {startTime+duration OR noiseSFTs} XLAL_CHECK ( !have_timestampsFiles || !(have_startTime||have_noiseSFTs), XLAL_EINVAL, "--timestampsFiles incompatible with {--noiseSFTs or --startTime+duration}\n"); // note, however, that we DO allow --noiseSFTs and --startTime+duration, which will act as a constraint // on the noise-SFTs to load in // don't allow --SFToverlap with either --noiseSFTs OR --timestampsFiles XLAL_CHECK ( uvar->SFToverlap >= 0, XLAL_EDOM ); BOOLEAN haveOverlap = ( uvar->SFToverlap > 0 ); XLAL_CHECK ( !haveOverlap || !( have_noiseSFTs || have_timestampsFiles ), XLAL_EINVAL, "--SFToverlap incompatible with {--noiseSFTs or --timestampsFiles}\n" ); // now handle the 3 mutually-exclusive cases: have_noiseSFTs || have_timestampsFiles || have_startTime (only) if ( have_noiseSFTs ) { SFTConstraints XLAL_INIT_DECL(constraints); if ( have_startTime && have_duration ) // use optional (startTime+duration) as constraints, { LIGOTimeGPS minStartTime, maxStartTime; minStartTime = uvar->startTime; maxStartTime = uvar->startTime; XLALGPSAdd ( &maxStartTime, uvar->duration ); constraints.minStartTime = &minStartTime; constraints.maxStartTime = &maxStartTime; char bufGPS1[32], bufGPS2[32]; XLALPrintWarning ( "Only noise-SFTs between GPS [%s, %s] will be used!\n", XLALGPSToStr(bufGPS1, &minStartTime), XLALGPSToStr(bufGPS2, &maxStartTime) ); } /* if start+duration given */ XLAL_CHECK ( (cfg->noiseCatalog = XLALSFTdataFind ( uvar->noiseSFTs, &constraints )) != NULL, XLAL_EFUNC ); XLAL_CHECK ( cfg->noiseCatalog->length > 0, XLAL_EINVAL, "No noise-SFTs matching (start+duration, timestamps) were found!\n" ); XLAL_CHECK ( (cfg->multiNoiseCatalogView = XLALGetMultiSFTCatalogView ( cfg->noiseCatalog )) != NULL, XLAL_EFUNC ); // extract multi-timestamps from the multi-SFT-catalog view XLAL_CHECK ( (cfg->multiTimestamps = XLALTimestampsFromMultiSFTCatalogView ( cfg->multiNoiseCatalogView )) != NULL, XLAL_EFUNC ); // extract IFOs from multi-SFT catalog XLAL_CHECK ( XLALMultiLALDetectorFromMultiSFTCatalogView ( &(cfg->multiIFO), cfg->multiNoiseCatalogView ) == XLAL_SUCCESS, XLAL_EFUNC ); } // endif have_noiseSFTs else if ( have_timestampsFiles ) { 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 XLALReadMultiTimestampsFiles()\n" ); for ( UINT4 X=0; X < cfg->multiTimestamps->length; X ++ ) { cfg->multiTimestamps->data[X]->deltaT = uvar->Tsft; // Tsft information not given by timestamps-file } } // endif have_timestampsFiles else if ( have_startTime && have_duration ) { XLAL_CHECK ( ( cfg->multiTimestamps = XLALMakeMultiTimestamps ( uvar->startTime, uvar->duration, uvar->Tsft, uvar->SFToverlap, cfg->multiIFO.length )) != NULL, XLAL_EFUNC ); } // endif have_startTime // check if the user asked for Gaussian white noise to be produced (sqrtSn[X]!=0), otherwise leave noise-floors at 0 if ( uvar->sqrtSX != NULL ) { XLAL_CHECK ( XLALParseMultiNoiseFloor ( &(cfg->multiNoiseFloor), uvar->sqrtSX, cfg->multiIFO.length ) == XLAL_SUCCESS, XLAL_EFUNC ); } else { cfg->multiNoiseFloor.length = cfg->multiIFO.length; // values remain at their default sqrtSn[X] = 0; } #ifdef HAVE_LIBLALFRAME // if user requested time-series data from frames to be added: try to read the frames now if ( have_frames ) { UINT4 numDetectors = uvar->inFrChannels->length; XLAL_CHECK ( uvar->inFrames->length == numDetectors, XLAL_EINVAL, "Need equal number of channel names (%d) as frame specifications (%d)\n", uvar->inFrChannels->length, numDetectors ); XLAL_CHECK ( (cfg->inputMultiTS = XLALCalloc ( 1, sizeof(*cfg->inputMultiTS))) != NULL, XLAL_ENOMEM ); cfg->inputMultiTS->length = numDetectors; XLAL_CHECK ( (cfg->inputMultiTS->data = XLALCalloc ( numDetectors, sizeof(cfg->inputMultiTS->data[0]) )) != NULL, XLAL_ENOMEM ); if ( cfg->multiTimestamps == NULL ) { XLAL_CHECK ( (cfg->multiTimestamps = XLALCalloc ( 1, sizeof(*cfg->multiTimestamps) )) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( (cfg->multiTimestamps->data = XLALCalloc ( numDetectors, sizeof(cfg->multiTimestamps->data[0]))) != NULL, XLAL_ENOMEM ); cfg->multiTimestamps->length = numDetectors; } for ( UINT4 X = 0; X < numDetectors; X ++ ) { LALCache *cache; XLAL_CHECK ( (cache = XLALCacheImport ( uvar->inFrames->data[X] )) != NULL, XLAL_EFUNC, "Failed to import cache file '%s'\n", uvar->inFrames->data[X] ); // this is a sorted cache, so extract its time-range: REAL8 cache_tStart = cache->list[0].t0; REAL8 cache_tEnd = cache->list[cache->length-1].t0 + cache->list[cache->length-1].dt; REAL8 cache_duration = (cache_tEnd - cache_tStart); LIGOTimeGPS ts_start; REAL8 ts_duration; // check that it's consistent with timestamps, if given, otherwise create timestamps from this if ( cfg->multiTimestamps->data[X] != NULL ) // FIXME: implicitly assumes timestamps are sorted, which is not guaranteed by timestamps-reading from file { const LIGOTimeGPSVector *timestampsX = cfg->multiTimestamps->data[X]; REAL8 tStart = XLALGPSGetREAL8( ×tampsX->data[0] ); REAL8 tEnd = XLALGPSGetREAL8( ×tampsX->data[timestampsX->length-1]) + timestampsX->deltaT; XLAL_CHECK ( tStart >= cache_tStart && tEnd <= cache_tEnd, XLAL_EINVAL, "Detector X=%d: Requested timestamps-range [%.0f, %.0f]s outside of cache range [%.0f,%.0f]s\n", X, tStart, tEnd, cache_tStart, cache_tEnd ); XLALGPSSetREAL8 ( &ts_start, tStart ); ts_duration = (tEnd - tStart); } else { XLALGPSSetREAL8 ( &ts_start, (REAL8)cache_tStart + 1); // cache times can apparently be by rounded up or down by 1s, so shift by 1s to be safe ts_duration = cache_duration - 1; XLAL_CHECK ( (cfg->multiTimestamps->data[X] = XLALMakeTimestamps ( ts_start, ts_duration, uvar->Tsft, uvar->SFToverlap ) ) != NULL, XLAL_EFUNC ); } // ----- now open frame stream and read *all* the data within this time-range [FIXME] ---------- LALFrStream *stream; XLAL_CHECK ( (stream = XLALFrStreamCacheOpen ( cache )) != NULL, XLAL_EFUNC, "Failed to open stream from cache file '%s'\n", uvar->inFrames->data[X] ); XLALDestroyCache ( cache ); const char *channel = uvar->inFrChannels->data[X]; size_t limit = 0; // unlimited read REAL8TimeSeries *ts; XLAL_CHECK ( (ts = XLALFrStreamInputREAL8TimeSeries ( stream, channel, &ts_start, ts_duration, limit )) != NULL, XLAL_EFUNC, "Frame reading failed for stream created for '%s': ts_start = {%d,%d}, duration=%.0f\n", uvar->inFrames->data[X], ts_start.gpsSeconds, ts_start.gpsNanoSeconds, ts_duration ); cfg->inputMultiTS->data[X] = ts; XLAL_CHECK ( XLALFrStreamClose ( stream ) == XLAL_SUCCESS, XLAL_EFUNC, "Stream closing failed for cache file '%s'\n", uvar->inFrames->data[X] ); } // for X < numDetectors } // if inFrames // if user requested timeseries *output* to frame files, handle deprecated options XLAL_CHECK ( !(uvar->TDDframedir && uvar->outFrameDir), XLAL_EINVAL, "Specify only ONE of {--TDDframedir or --outFrameDir} or NONE\n"); if ( uvar->TDDframedir ) { cfg->outFrameDir = uvar->TDDframedir; } else if ( uvar->outFrameDir ) { cfg->outFrameDir = uvar->outFrameDir; } #endif return XLAL_SUCCESS; } /* XLALInitMakefakedata() */
/** * 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() */