/** * Construct an empty KDE structure. * * Create an empty LALInferenceKDE structure, allocated to handle the given size * and dimension. * @param[in] npts Number of samples that will be used to estimate * the distribution. * @param[in] dim Number of dimensions that the probability density function * will be estimated in. * @return An allocated, empty LALInferenceKDE structure. * \sa LALInferenceKDE, LALInferenceSetKDEBandwidth() */ LALInferenceKDE *LALInferenceInitKDE(INT4 npts, INT4 dim) { INT4 p; LALInferenceKDE *kde = XLALCalloc(1, sizeof(LALInferenceKDE)); kde->dim = dim; kde->npts = npts; kde->mean = gsl_vector_calloc(dim); kde->cholesky_decomp_cov = gsl_matrix_calloc(dim, dim); kde->cholesky_decomp_cov_lower = gsl_matrix_calloc(dim, dim); kde->cov = gsl_matrix_calloc(dim, dim); kde->lower_bound_types = XLALCalloc(dim, sizeof(LALInferenceParamVaryType)); kde->upper_bound_types = XLALCalloc(dim, sizeof(LALInferenceParamVaryType)); kde->lower_bounds = XLALCalloc(dim, sizeof(REAL8)); kde->upper_bounds = XLALCalloc(dim, sizeof(REAL8)); for (p = 0; p < dim; p++) { kde->lower_bound_types[p] = LALINFERENCE_PARAM_OUTPUT; kde->upper_bound_types[p] = LALINFERENCE_PARAM_OUTPUT; } if (npts > 0) kde->data = gsl_matrix_alloc(npts, dim); return kde; }
/* ----- function definitions ---------- */ int main ( void ) { LALStatus XLAL_INIT_DECL(status); SFTCatalog *catalog = NULL; SFTConstraints XLAL_INIT_DECL(constraints); MultiSFTVector *multiSFTs = NULL; MultiPSDVector *multiPSDs = NULL; MultiNoiseWeights *multiWeightsXLAL = NULL; MultiNoiseWeights *multiWeightsCorrect = NULL; UINT4 rngmedBins = 11; REAL8 tolerance = 2e-6; /* same algorithm, should be basically identical results */ /* Construct the "correct" weights, calculated using the old LAL routines */ UINT4 numIFOsCorrect = 2; XLAL_CHECK ( ( multiWeightsCorrect = XLALCalloc ( 1, sizeof(*multiWeightsCorrect ) ) ) != NULL, XLAL_ENOMEM ); multiWeightsCorrect->length = numIFOsCorrect; multiWeightsCorrect->Sinv_Tsft = 1.980867126449e+52; XLAL_CHECK ( ( multiWeightsCorrect->data = XLALCalloc ( numIFOsCorrect, sizeof(*multiWeightsCorrect->data ) ) ) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( ( multiWeightsCorrect->data[0] = XLALCreateREAL8Vector(4) ) != NULL, XLAL_ENOMEM ); multiWeightsCorrect->data[0]->data[0] = 6.425160659487e-05; multiWeightsCorrect->data[0]->data[1] = 7.259453662367e-06; multiWeightsCorrect->data[0]->data[2] = 9.838893684664e-04; multiWeightsCorrect->data[0]->data[3] = 5.043766789923e-05; XLAL_CHECK ( ( multiWeightsCorrect->data[1] = XLALCreateREAL8Vector(3) ) != NULL, XLAL_ENOMEM ); multiWeightsCorrect->data[1]->data[0] = 1.582309910283e-04; multiWeightsCorrect->data[1]->data[1] = 5.345673753744e-04; multiWeightsCorrect->data[1]->data[2] = 6.998201363537e+00; /* Construct the catalog */ XLAL_CHECK ( ( catalog = XLALSFTdataFind ( TEST_DATA_DIR "MultiNoiseWeightsTest*.sft", &constraints ) ) != NULL, XLAL_EFUNC, " XLALSFTdataFind failed\n" ); /* Load the SFTs */ XLAL_CHECK ( ( multiSFTs = XLALLoadMultiSFTs ( catalog, -1, -1 ) ) != NULL, XLAL_EFUNC, " XLALLoadMultiSFTs failed\n" ); /* calculate the psd and normalize the SFTs */ XLAL_CHECK ( ( multiPSDs = XLALNormalizeMultiSFTVect ( multiSFTs, rngmedBins, NULL ) ) != NULL, XLAL_EFUNC, " XLALNormalizeMultiSFTVect failed\n" ); /* Get weights using XLAL function */ XLAL_CHECK ( ( multiWeightsXLAL = XLALComputeMultiNoiseWeights ( multiPSDs, rngmedBins, 0 ) ) != NULL, XLAL_EFUNC, " XLALComputeMultiNoiseWeights failed\n" ); /* Compare XLAL weights to reference */ XLAL_CHECK ( XLALCompareMultiNoiseWeights ( multiWeightsXLAL, multiWeightsCorrect, tolerance ) == XLAL_SUCCESS, XLAL_EFAILED, "Comparison between XLAL and reference MultiNoiseWeights failed\n" ); /* Clean up memory */ XLALDestroyMultiNoiseWeights ( multiWeightsCorrect ); XLALDestroyMultiNoiseWeights ( multiWeightsXLAL ); XLALDestroyMultiPSDVector ( multiPSDs ); XLALDestroyMultiSFTVector ( multiSFTs ); XLALDestroySFTCatalog ( catalog ); /* check for memory-leaks */ LALCheckMemoryLeaks(); return XLAL_SUCCESS; } /* main() */
MultiNoiseWeights * XLALComputeConstantMultiNoiseWeightsFromNoiseFloor ( const MultiNoiseFloor *multiNoiseFloor, /**< [in] noise floor values sqrt(S) for all detectors */ const MultiLIGOTimeGPSVector *multiTS, /**< [in] timestamps vectors for all detectors, only needed for their lengths */ const UINT4 Tsft /**< [in] length of SFTs in secons, needed for normalization factor Sinv_Tsft */ ) { /* check input parameters */ XLAL_CHECK_NULL ( multiNoiseFloor != NULL, XLAL_EINVAL ); XLAL_CHECK_NULL ( multiTS != NULL, XLAL_EINVAL ); UINT4 numDet = multiNoiseFloor->length; XLAL_CHECK_NULL ( numDet == multiTS->length, XLAL_EINVAL, "Inconsistent length between multiNoiseFloor (%d) and multiTimeStamps (%d) structs.\n", numDet, multiTS->length ); /* create multi noise weights for output */ MultiNoiseWeights *multiWeights = NULL; XLAL_CHECK_NULL ( (multiWeights = XLALCalloc(1, sizeof(*multiWeights))) != NULL, XLAL_ENOMEM, "Failed call to XLALCalloc ( 1, %zu )\n", sizeof(*multiWeights) ); XLAL_CHECK_NULL ( (multiWeights->data = XLALCalloc(numDet, sizeof(*multiWeights->data))) != NULL, XLAL_ENOMEM, "Failed call to XLALCalloc ( %d, %zu )\n", numDet, sizeof(*multiWeights->data) ); multiWeights->length = numDet; REAL8 sqrtSnTotal = 0; UINT4 numSFTsTotal = 0; for (UINT4 X = 0; X < numDet; X++) { /* first loop over detectors: compute total noise floor normalization */ sqrtSnTotal += multiTS->data[X]->length / SQ ( multiNoiseFloor->sqrtSn[X] ); /* actually summing up 1/Sn, not sqrtSn yet */ numSFTsTotal += multiTS->data[X]->length; } sqrtSnTotal = sqrt ( numSFTsTotal / sqrtSnTotal ); /* SnTotal = harmonicMean{S_X} assuming per-detector stationarity */ for (UINT4 X = 0; X < numDet; X++) { /* second loop over detectors: compute the weights */ /* compute per-IFO weights */ REAL8 noise_weight_X = SQ(sqrtSnTotal/multiNoiseFloor->sqrtSn[X]); /* w_Xalpha = S_Xalpha^-1/S^-1 = S / S_Xalpha */ /* create k^th weights vector */ if( ( multiWeights->data[X] = XLALCreateREAL8Vector ( multiTS->data[X]->length ) ) == NULL ) { /* free weights vectors created previously in loop */ XLALDestroyMultiNoiseWeights ( multiWeights ); XLAL_ERROR_NULL ( XLAL_EFUNC, "Failed to allocate noiseweights for IFO X = %d\n", X ); } /* if XLALCreateREAL8Vector() failed */ /* loop over SFT timestamps and use same weights for all */ for ( UINT4 alpha = 0; alpha < multiTS->data[X]->length; alpha++) { multiWeights->data[X]->data[alpha] = noise_weight_X; } } /* for X < numDet */ multiWeights->Sinv_Tsft = Tsft / SQ ( sqrtSnTotal ); return multiWeights; } /* XLALComputeConstantMultiNoiseWeightsFromNoiseFloor() */
/** * Multi-IFO version of XLALComputeAMCoeffs(). * Computes noise-weighted combined multi-IFO antenna pattern functions. * * \note *) contrary to LALGetMultiAMCoeffs(), and XLALComputeAMCoeffs(), this function applies * the noise-weights and computes the multi-IFO antenna-pattern matrix components * {A, B, C}, and single-IFO matrix components {A_X,B_X,C_X} for detector X. * * Therefore: DONT use XLALWeightMultiAMCoeffs() on the result! * * \note *) an input of multiWeights = NULL corresponds to unit-weights */ MultiAMCoeffs * XLALComputeMultiAMCoeffs ( const MultiDetectorStateSeries *multiDetStates, /**< [in] detector-states at timestamps t_i */ const MultiNoiseWeights *multiWeights, /**< [in] noise-weigths at timestamps t_i (can be NULL) */ SkyPosition skypos /**< source sky-position [in equatorial coords!] */ ) { /* check input consistency */ if ( !multiDetStates ) { XLALPrintError ("%s: invalid NULL input argument 'multiDetStates'\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } UINT4 numDetectors = multiDetStates->length; /* prepare output vector */ MultiAMCoeffs *ret; if ( ( ret = XLALCalloc( 1, sizeof( *ret ) )) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc( 1, %d)\n", __func__, sizeof( *ret ) ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } ret->length = numDetectors; if ( ( ret->data = XLALCalloc ( numDetectors, sizeof ( *ret->data ) )) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc(%d, %d)\n", __func__, numDetectors, sizeof ( *ret->data ) ); XLALFree ( ret ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } /* loop over detectors and generate AMCoeffs for each one */ UINT4 X; for ( X=0; X < numDetectors; X ++ ) { if ( (ret->data[X] = XLALComputeAMCoeffs ( multiDetStates->data[X], skypos )) == NULL ) { XLALPrintError ("%s: call to XLALComputeAMCoeffs() failed with xlalErrno = %d\n", __func__, xlalErrno ); XLALDestroyMultiAMCoeffs ( ret ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } } /* for X < numDetectors */ /* apply noise-weights and compute antenna-pattern matrix {A,B,C} */ if ( XLALWeightMultiAMCoeffs ( ret, multiWeights ) != XLAL_SUCCESS ) { XLALPrintError ("%s: call to XLALWeightMultiAMCoeffs() failed with xlalErrno = %d\n", __func__, xlalErrno ); XLALDestroyMultiAMCoeffs ( ret ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } /* return result */ return ret; } /* XLALComputeMultiAMCoeffs() */
/** * \brief Subtract the running median from complex data * * This function uses \c gsl_stats_median_from_sorted_data to subtract a running median, calculated from the 30 * consecutive point around a set point, from the data. At the start of the data running median is calculated from * 30-15+(i-1) points, and at the end it is calculated from 15+(N-i) points, where i is the point index and N is the * total number of data points. * * \param data [in] A complex data vector * * \return A complex vector containing data with the running median removed */ COMPLEX16Vector *subtract_running_median( COMPLEX16Vector *data ){ COMPLEX16Vector *submed = NULL; UINT4 length = data->length, i = 0, j = 0, n = 0; UINT4 mrange = 0; UINT4 N = 0; INT4 sidx = 0; if ( length > 30 ){ mrange = 30; } /* perform running median with 30 data points */ else { mrange = 2*floor((length-1)/2); } /* an even number less than length */ N = (UINT4)floor(mrange/2); submed = XLALCreateCOMPLEX16Vector( length ); for ( i = 1; i < length+1; i++ ){ REAL8 *dre = NULL; REAL8 *dim = NULL; /* get median of data within RANGE */ if ( i < N ){ n = N+i; sidx = 0; } else{ if ( i > length - N ){ n = length - i + N; } else{ n = mrange; } sidx = i-N; } dre = XLALCalloc( n, sizeof(REAL8) ); dim = XLALCalloc( n, sizeof(REAL8) ); for ( j = 0; j < n; j++ ){ dre[j] = creal(data->data[j+sidx]); dim[j] = cimag(data->data[j+sidx]); } /* sort data */ gsl_sort( dre, 1, n ); gsl_sort( dim, 1, n ); /* get median and subtract from data*/ submed->data[i-1] = ( creal(data->data[i-1]) - gsl_stats_median_from_sorted_data( dre, 1, n ) ) + I * ( cimag(data->data[i-1]) - gsl_stats_median_from_sorted_data( dim, 1, n ) ); XLALFree( dre ); XLALFree( dim ); } return submed; }
/** * Generate a multi-FstatAtomVector for given antenna-pattern functions. * Simply creates MultiFstatAtomVector and initializes with antenna-pattern function. */ MultiFstatAtomVector* XLALGenerateMultiFstatAtomVector ( const MultiDetectorStateSeries *multiDetStates, /**< [in] multi-detector state series, only used for timestamps */ const MultiAMCoeffs *multiAM /**< input antenna-pattern functions {a_i, b_i} */ ) { /* check input consistency */ if ( !multiDetStates || !multiDetStates->data ) { XLALPrintError ("%s: invalid NULL input in 'multiDetStates'\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } if ( !multiAM || !multiAM->data || !multiAM->data[0] ) { XLALPrintError ("%s: invalid NULL input in 'mutiAM'\n", __func__ ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } UINT4 numDet = multiDetStates->length; if ( numDet != multiAM->length ) { XLALPrintError ("%s: inconsistent number of detectors in multiDetStates (%d) and multiAM (%d)\n", __func__, multiDetStates->length, multiAM->length ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } /* create multi-atoms vector */ MultiFstatAtomVector *multiAtoms; if ( ( multiAtoms = XLALCalloc ( 1, sizeof(*multiAtoms) )) == NULL ) { XLALPrintError ("%s: XLALCalloc ( 1, %zu) failed.\n", __func__, sizeof(*multiAtoms) ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } multiAtoms->length = numDet; if ( ( multiAtoms->data = XLALCalloc ( numDet, sizeof(*multiAtoms->data) ) ) == NULL ) { XLALPrintError ("%s: XLALCalloc ( %d, %zu) failed.\n", __func__, numDet, sizeof(*multiAtoms->data) ); XLALFree ( multiAtoms ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } /* loop over detectors and generate each atoms-vector individually */ UINT4 X; for ( X=0; X < numDet; X ++ ) { if ( ( multiAtoms->data[X] = XLALGenerateFstatAtomVector ( multiDetStates->data[X], multiAM->data[X] )) == NULL ) { XLALPrintError ("%s: XLALGenerateFstatAtomVector() failed.\n", __func__ ); XLALDestroyMultiFstatAtomVector ( multiAtoms ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } } /* for X < numDet */ /* return result */ return multiAtoms; } /* XLALGenerateMultiFstatAtomVector() */
/** * Create *zero-initialized* PulsarParamsVector for numPulsars */ PulsarParamsVector * XLALCreatePulsarParamsVector ( UINT4 numPulsars ) { PulsarParamsVector *ret; XLAL_CHECK_NULL ( ( ret = XLALCalloc ( 1, sizeof(*ret))) != NULL, XLAL_ENOMEM ); ret->length = numPulsars; if ( numPulsars > 0 ) { XLAL_CHECK_NULL ( (ret->data = XLALCalloc ( numPulsars, sizeof(ret->data[0]))) != NULL, XLAL_ENOMEM ); } return ret; } // XLALCreatePulsarParamsVector()
/** * Construct and initialize a waveform cache. Caches are used to * avoid re-computation of waveforms that differ only by simple * scaling relations in extrinsic parameters. */ LALSimInspiralWaveformCache *XLALCreateSimInspiralWaveformCache() { LALSimInspiralWaveformCache *cache = XLALCalloc(1, sizeof(LALSimInspiralWaveformCache)); return cache; }
/** (Complex)Sinc-interpolate an input SFT to an output SFT. * This is a simple convenience wrapper to XLALSincInterpolateCOMPLEX8FrequencySeries() * for the special case of interpolating onto new SFT frequency bins */ SFTtype * XLALSincInterpolateSFT ( const SFTtype *sft_in, ///< [in] input SFT REAL8 f0Out, ///< [in] new start frequency REAL8 dfOut, ///< [in] new frequency step-size UINT4 numBinsOut, ///< [in] new number of bins UINT4 Dterms ///< [in] truncate interpolation kernel sum to +-Dterms around max ) { XLAL_CHECK_NULL ( sft_in != NULL, XLAL_EINVAL ); XLAL_CHECK_NULL ( dfOut > 0, XLAL_EINVAL ); XLAL_CHECK_NULL ( numBinsOut > 0, XLAL_EINVAL ); // setup frequency vector REAL8Vector *f_out; XLAL_CHECK_NULL ( (f_out = XLALCreateREAL8Vector ( numBinsOut )) != NULL, XLAL_EFUNC ); for ( UINT4 k = 0; k < numBinsOut; k ++ ) { f_out->data[k] = f0Out + k * dfOut; } // for k < numBinsOut SFTtype *out; XLAL_CHECK_NULL ( (out = XLALCalloc ( 1, sizeof(*out))) != NULL, XLAL_EFUNC ); (*out) = (*sft_in); // copy header out->f0 = f0Out; out->deltaF = dfOut; XLAL_CHECK_NULL ( (out->data = XLALCreateCOMPLEX8Vector ( numBinsOut )) != NULL, XLAL_EFUNC ); XLAL_CHECK_NULL ( XLALSincInterpolateCOMPLEX8FrequencySeries ( out->data, f_out, sft_in, Dterms ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyREAL8Vector ( f_out ); return out; } // XLALSincInterpolateSFT()
/** * Append the given PulsarParamsVector 'add' to the vector 'list' ( which can be NULL), return resulting list * with new elements 'add' appended at the end of 'list'. */ PulsarParamsVector * XLALPulsarParamsVectorAppend ( PulsarParamsVector *list, const PulsarParamsVector *add ) { XLAL_CHECK_NULL ( add != NULL, XLAL_EINVAL ); PulsarParamsVector *ret; if ( list == NULL ) { XLAL_CHECK_NULL ( (ret = XLALCalloc ( 1, sizeof(*ret))) != NULL, XLAL_ENOMEM ); } else { ret = list; } UINT4 oldlen = ret->length; UINT4 addlen = add->length; UINT4 newlen = oldlen + addlen; ret->length = newlen; XLAL_CHECK_NULL ( (ret->data = XLALRealloc ( ret->data, newlen * sizeof(ret->data[0]) )) != NULL, XLAL_ENOMEM ); memcpy ( ret->data + oldlen, add->data, addlen * sizeof(ret->data[0]) ); // we have to properly copy the 'name' string fields for ( UINT4 i = 0; i < addlen; i ++ ) { XLAL_CHECK_NULL ( (ret->data[oldlen + i].name = XLALStringDuplicate ( add->data[i].name )) != NULL, XLAL_EFUNC ); } return ret; } // XLALPulsarParamsVectorAppend()
/** * Create an AMCeoffs vector for given number of timesteps */ AMCoeffs * XLALCreateAMCoeffs ( UINT4 numSteps ) { AMCoeffs *ret; if ( ( ret = XLALCalloc ( 1, sizeof (*ret) ) ) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, sizeof (*ret) ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } if ( ( ret->a = XLALCreateREAL4Vector ( numSteps )) == NULL ) { XLALPrintError ("%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numSteps ); XLALDestroyAMCoeffs ( ret ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } if ( ( ret->b = XLALCreateREAL4Vector ( numSteps )) == NULL ) { XLALPrintError ("%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numSteps ); XLALDestroyAMCoeffs ( ret ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } return ret; } /* XLALCreateAMCoeffs() */
LALHashTbl *XLALHashTblCreate2( LALHashTblDtorFcn dtor, LALHashTblHashParamFcn hash, void *hash_param, LALHashTblCmpParamFcn cmp, void *cmp_param ) { /* Check input */ XLAL_CHECK_NULL( hash != NULL, XLAL_EFAULT ); XLAL_CHECK_NULL( cmp != NULL, XLAL_EFAULT ); /* Allocate memory for hash table struct */ LALHashTbl *ht = XLALCalloc( 1, sizeof( *ht ) ); XLAL_CHECK_NULL( ht != NULL, XLAL_ENOMEM ); /* Set hash table struct parameters */ ht->dtor = dtor; ht->hash = hash; ht->hash_param = hash_param; ht->cmp = cmp; ht->cmp_param = cmp_param; return ht; }
int XLALSetupFstatDemod ( void **method_data, FstatCommon *common, FstatMethodFuncs* funcs, MultiSFTVector *multiSFTs, const FstatOptionalArgs *optArgs ) { // Check input XLAL_CHECK ( method_data != NULL, XLAL_EFAULT ); XLAL_CHECK ( common != NULL, XLAL_EFAULT ); XLAL_CHECK ( funcs != NULL, XLAL_EFAULT ); XLAL_CHECK ( multiSFTs != NULL, XLAL_EFAULT ); XLAL_CHECK ( optArgs != NULL, XLAL_EFAULT ); // Allocate method data DemodMethodData *demod = *method_data = XLALCalloc( 1, sizeof(*demod) ); XLAL_CHECK( demod != NULL, XLAL_ENOMEM ); // Set method function pointers funcs->compute_func = XLALComputeFstatDemod; funcs->method_data_destroy_func = XLALDestroyDemodMethodData; funcs->workspace_destroy_func = NULL; // Save pointer to SFTs demod->multiSFTs = multiSFTs; // Save Dterms demod->Dterms = optArgs->Dterms; // Save flag about collecting timing data demod->timingInfo.collectTiming = optArgs->collectTiming; // Select XLALComputeFaFb_...() function for the user-requested hotloop variant switch ( optArgs->FstatMethod ) { case FMETHOD_DEMOD_GENERIC: demod->computefafb_func = XLALComputeFaFb_Generic; break; case FMETHOD_DEMOD_OPTC: demod->computefafb_func = XLALComputeFaFb_OptC; break; #ifdef HAVE_ALTIVEC case FMETHOD_DEMOD_ALTIVEC: demod->computefafb_func = XLALComputeFaFb_Altivec; break; #endif #ifdef HAVE_SSE_COMPILER case FMETHOD_DEMOD_SSE: demod->computefafb_func = XLALComputeFaFb_SSE; break; #endif default: XLAL_ERROR ( XLAL_EINVAL, "Invalid Demod hotloop optArgs->FstatMethod='%d'", optArgs->FstatMethod ); break; } return XLAL_SUCCESS; } // XLALSetupFstatDemod()
/** simple creator function for EphemerisVector type */ EphemerisVector * XLALCreateEphemerisVector ( UINT4 length ) { EphemerisVector * ret; if ( ( ret = XLALCalloc ( 1, sizeof (*ret) )) == NULL ) XLAL_ERROR_NULL ( XLAL_ENOMEM, "Failed to XLALCalloc(1, %zu)\n", sizeof (*ret) ); if ( ( ret->data = XLALCalloc ( length, sizeof(*ret->data) ) ) == NULL ) { XLALFree ( ret ); XLAL_ERROR_NULL ( XLAL_ENOMEM, "Failed to XLALCalloc (%d, %zu)\n", length, sizeof(*ret->data) ); } ret->length = length; return ret; } /* XLALCreateEphemerisVector() */
static void SplineData_Init( SplineData **splinedata ) { if(!splinedata) exit(1); if(*splinedata) SplineData_Destroy(*splinedata); (*splinedata)=XLALCalloc(1,sizeof(SplineData)); const int ncx = 159; // points in q const int ncy = 49; // points in chi (*splinedata)->ncx = ncx; (*splinedata)->ncy = ncy; // Set up B-spline basis for desired knots double qvec[] = {1., 1.125, 1.25, 1.375, 1.5, 1.75, 2., 2.25, 2.5, 2.75, 3., 3.25, \ 3.5, 3.75, 4., 4.25, 4.5, 4.75, 5., 5.5, 6., 6.5, 7., 7.5, 8., 8.5, \ 9., 9.5, 10., 10.5, 11., 11.5, 12., 12.5, 13., 13.5, 14., 14.5, 15., \ 15.5, 16., 16.5, 17., 17.5, 18., 18.5, 19., 19.5, 20., 20.5, 21., \ 21.5, 22., 22.5, 23., 23.5, 24., 24.5, 25., 25.5, 26., 26.5, 27., \ 27.5, 28., 28.5, 29., 29.5, 30., 30.5, 31., 31.5, 32., 32.5, 33., \ 33.5, 34., 34.5, 35., 35.5, 36., 36.5, 37., 37.5, 38., 38.5, 39., \ 39.5, 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., \ 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., \ 66., 67., 68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., \ 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., \ 94., 95., 95.5, 96., 96.5, 97., 97.5, 98., 98.5, 98.75, 99., 99.25, \ 99.5, 99.75, 100.}; double chivec[] = {-1., -0.975, -0.95, -0.925, -0.9, -0.875, -0.85, -0.825, -0.8, \ -0.775, -0.75, -0.725, -0.7, -0.675, -0.65, -0.625, -0.6, -0.55, \ -0.5, -0.45, -0.4, -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0., \ 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.325, 0.35, 0.375, 0.4, 0.425, \ 0.45, 0.475, 0.5, 0.525, 0.55, 0.575, 0.6}; const size_t nbreak_x = ncx-2; // must have nbreak = n -2 for cubic splines const size_t nbreak_y = ncy-2; // must have nbreak = n -2 for cubic splines // allocate a cubic bspline workspace (k = 4) gsl_bspline_workspace *bwx = gsl_bspline_alloc(4, nbreak_x); gsl_bspline_workspace *bwy = gsl_bspline_alloc(4, nbreak_y); // set breakpoints (and thus knots by hand) gsl_vector *breakpts_x = gsl_vector_alloc(nbreak_x); gsl_vector *breakpts_y = gsl_vector_alloc(nbreak_y); for (UINT4 i=0; i<nbreak_x; i++) gsl_vector_set(breakpts_x, i, qvec[i]); for (UINT4 j=0; j<nbreak_y; j++) gsl_vector_set(breakpts_y, j, chivec[j]); gsl_bspline_knots(breakpts_x, bwx); gsl_bspline_knots(breakpts_y, bwy); gsl_vector_free(breakpts_x); gsl_vector_free(breakpts_y); (*splinedata)->bwx=bwx; (*splinedata)->bwy=bwy; }
/** * \ingroup UserInput_h * Internal function: Register a user-variable with the module. * Effectively put an appropriate entry into UVAR_vars * * Checks that long- and short-options are unique, an error is returned * if a previous option name collides. * * \note don't use this function directly, as it is not type-safe!! * ==> use the type-safe macro XLALRegisterUvarMember(name,type,option,category,help) instead! */ int XLALRegisterUserVar ( void *cvar, /**< pointer to the actual C-variabe to link to this user-variable */ const CHAR *name, /**< name of user-variable to register */ UserVarType type, /**< variable type (int,bool,string,real) */ CHAR optchar, /**< optional short-option character */ UserVarCategory category, /**< sets category to this */ const CHAR *help /**< help-string explaining this input-variable */ ) { XLAL_CHECK ( cvar != NULL, XLAL_EINVAL ); XLAL_CHECK ( name != NULL, XLAL_EINVAL ); XLAL_CHECK ( strlen(name) < sizeof(UVAR_vars.name), XLAL_EINVAL, "User-variable name '%s' is too long", name ); XLAL_CHECK ( (category > UVAR_CATEGORY_START) && (category < UVAR_CATEGORY_END), XLAL_EINVAL ); XLAL_CHECK ( help != NULL, XLAL_EINVAL ); XLAL_CHECK ( strlen(help) < sizeof(UVAR_vars.help), XLAL_EINVAL, "User-variable help '%s' is too long", help ); // check that neither short- nor long-option are used by help XLAL_CHECK ( strcmp ( name, "help" ) != 0, XLAL_EINVAL, "Long-option name '--%s' is reserved for help!\n", name ); XLAL_CHECK ( optchar != 'h', XLAL_EINVAL, "Short-option '-%c' is reserved for help!\n", optchar ); // find end of uvar-list && check that neither short- nor long-option are taken already LALUserVariable *ptr = &UVAR_vars; while ( ptr->next != NULL ) { ptr = ptr->next; // long-option name taken already? XLAL_CHECK ( strcmp ( name, ptr->name ) != 0, XLAL_EINVAL, "Long-option name '--%s' already taken!\n", name ); // short-option character taken already? XLAL_CHECK ( (optchar == 0) || (ptr->optchar == 0) || (optchar != ptr->optchar), XLAL_EINVAL, "Short-option '-%c' already taken (by '--%s')!\n", optchar, ptr->name ); } // while ptr->next // append new entry at the end XLAL_CHECK ( (ptr->next = XLALCalloc (1, sizeof(LALUserVariable))) != NULL, XLAL_ENOMEM ); // set pointer to newly created entry ptr = ptr->next; // copy entry name, replacing '_' with '-' so that // e.g. uvar->a_long_option maps to --a-long-option XLALStringReplaceChar( strncpy( ptr->name, name, sizeof(ptr->name) - 1 ), '_', '-' ); // copy entry help string strncpy( ptr->help, help, sizeof(ptr->help) - 1 ); format_user_var_names( ptr->help ); // fill in entry values ptr->type = type; ptr->optchar = optchar; ptr->varp = cvar; ptr->category = category; return XLAL_SUCCESS; } // XLALRegisterUserVar()
static void SplineData_Init( SplineData **splinedata ) { if(!splinedata) exit(1); if(*splinedata) SplineData_Destroy(*splinedata); (*splinedata)=XLALCalloc(1,sizeof(SplineData)); int ncx = 41+2; // points in q int ncy = 21+2; // points in chi1 int ncz = 21+2; // points in chi2 (*splinedata)->ncx = ncx; (*splinedata)->ncy = ncy; (*splinedata)->ncz = ncz; // Set up B-spline basis for desired knots double qvec[] = {1., 1.125, 1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 2., 2.25, 2.5, \ 2.75, 3., 3.25, 3.5, 3.75, 4., 4.25, 4.5, 4.75, 5., 5.25, 5.5, 5.75, \ 6., 6.25, 6.5, 6.75, 7., 7.25, 7.5, 7.75, 8., 8.25, 8.5, 8.75, 9., \ 9.25, 9.5, 9.75, 10.}; double chi1vec[] = {-1., -0.95, -0.9, -0.85, -0.8, -0.75, -0.7, -0.6, -0.5, -0.4, -0.3, \ -0.2, -0.1, 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.55, 0.6}; double chi2vec[] = {-1., -0.95, -0.9, -0.85, -0.8, -0.75, -0.7, -0.6, -0.5, -0.4, -0.3, \ -0.2, -0.1, 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.55, 0.6}; const size_t nbreak_x = ncx-2; // must have nbreak = n-2 for cubic splines const size_t nbreak_y = ncy-2; // must have nbreak = n-2 for cubic splines const size_t nbreak_z = ncz-2; // must have nbreak = n-2 for cubic splines // allocate a cubic bspline workspace (k = 4) gsl_bspline_workspace *bwx = gsl_bspline_alloc(4, nbreak_x); gsl_bspline_workspace *bwy = gsl_bspline_alloc(4, nbreak_y); gsl_bspline_workspace *bwz = gsl_bspline_alloc(4, nbreak_z); // set breakpoints (and thus knots by hand) gsl_vector *breakpts_x = gsl_vector_alloc(nbreak_x); gsl_vector *breakpts_y = gsl_vector_alloc(nbreak_y); gsl_vector *breakpts_z = gsl_vector_alloc(nbreak_z); for (UINT4 i=0; i<nbreak_x; i++) gsl_vector_set(breakpts_x, i, qvec[i]); for (UINT4 j=0; j<nbreak_y; j++) gsl_vector_set(breakpts_y, j, chi1vec[j]); for (UINT4 k=0; k<nbreak_z; k++) gsl_vector_set(breakpts_z, k, chi2vec[k]); gsl_bspline_knots(breakpts_x, bwx); gsl_bspline_knots(breakpts_y, bwy); gsl_bspline_knots(breakpts_z, bwz); gsl_vector_free(breakpts_x); gsl_vector_free(breakpts_y); gsl_vector_free(breakpts_z); (*splinedata)->bwx=bwx; (*splinedata)->bwy=bwy; (*splinedata)->bwz=bwz; }
/* Structure for internal use */ static void SEOBNRROMdata_coeff_Init(SEOBNRROMdata_coeff **romdatacoeff) { if(!romdatacoeff) exit(1); /* Create storage for structures */ if(!*romdatacoeff) *romdatacoeff=XLALCalloc(1,sizeof(SEOBNRROMdata_coeff)); else SEOBNRROMdata_coeff_Cleanup(*romdatacoeff); (*romdatacoeff)->c_amp = gsl_vector_alloc(nk_amp); (*romdatacoeff)->c_phi = gsl_vector_alloc(nk_phi); }
xmlNodePtr LALInferenceVariableItem2VOTParamNode(LALInferenceVariableItem *const varitem) { VOTABLE_DATATYPE vo_type; CHAR *unitName={0}; UINT4 bufsize=1024; UINT4 required_size=0; CHAR *valString=XLALCalloc(bufsize,sizeof(CHAR)); CHAR arraysize[32]=""; switch(varitem->type) { /* Special case for matrix */ case LALINFERENCE_gslMatrix_t: return(XLALgsl_matrix2VOTNode(*(gsl_matrix **)varitem->value, varitem->name, unitName)); break; /* Special case for string */ case LALINFERENCE_string_t: return(XLALCreateVOTParamNode(varitem->name,unitName,VOT_CHAR,"*",*(char **)varitem->value)); break; case LALINFERENCE_REAL8Vector_t: { REAL8Vector *vec=*(REAL8Vector **)varitem->value; snprintf(arraysize,32,"%i",vec->length); vo_type=VOT_REAL8; break; } case LALINFERENCE_INT4Vector_t: { INT4Vector *vec=*(INT4Vector **)varitem->value; snprintf(arraysize,32,"%i",vec->length); vo_type=VOT_INT4; break; } default: /* Check the type of the item */ vo_type=LALInferenceVariableType2VOT(varitem->type); } if(vo_type>=VOT_DATATYPE_LAST){ XLALPrintError("%s: Unsupported LALInferenceVariableType %i\n",__func__,(int)varitem->type); return NULL; } required_size=LALInferencePrintNVariableItem(valString, bufsize, varitem); if(required_size>bufsize){ bufsize=required_size; valString=XLALRealloc(valString,bufsize*sizeof(CHAR)); required_size=LALInferencePrintNVariableItem(valString, bufsize, varitem); } xmlNodePtr node = XLALCreateVOTParamNode(varitem->name,unitName,vo_type,arraysize,valString); XLALFree(valString); return(node); }
/** * Takes in the h_lm spherical harmonic decomposed modes and rotates the modes * by Euler angles alpha, beta, and gamma using the Wigner D matrices. * * e.g. * * \f$\tilde{h}_{l,m}(t) = D^l_{m',m} h_{l,m'}(t)\f$ */ int XLALSimInspiralPrecessionRotateModes( SphHarmTimeSeries* h_lm, /**< spherical harmonic decomposed modes, modified in place */ REAL8TimeSeries* alpha, /**< alpha Euler angle time series */ REAL8TimeSeries* beta, /**< beta Euler angle time series */ REAL8TimeSeries* gam /**< gamma Euler angle time series */ ){ unsigned int i; int l, lmax, m, mp; lmax = XLALSphHarmTimeSeriesGetMaxL( h_lm ); // Temporary holding variables complex double *x_lm = XLALCalloc( 2*lmax+1, sizeof(complex double) ); COMPLEX16TimeSeries **h_xx = XLALCalloc( 2*lmax+1, sizeof(COMPLEX16TimeSeries) ); for(i=0; i<alpha->data->length; i++){ for(l=2; l<=lmax; l++){ for(m=0; m<2*l+1; m++){ h_xx[m] = XLALSphHarmTimeSeriesGetMode(h_lm, l, m-l); if( !h_xx[m] ){ x_lm[m] = 0; } else { x_lm[m] = h_xx[m]->data->data[i]; h_xx[m]->data->data[i] = 0; } } for(m=0; m<2*l+1; m++){ for(mp=0; mp<2*l+1; mp++){ if( !h_xx[m] ) continue; h_xx[m]->data->data[i] += x_lm[mp] * XLALWignerDMatrix( l, mp-l, m-l, alpha->data->data[i], beta->data->data[i], gam->data->data[i] ); } } } } XLALFree( x_lm ); XLALFree( h_xx ); return XLAL_SUCCESS; }
/** * Duplicates a MultiCOMPLEX8TimeSeries structure. * Allocates memory and copies contents. */ MultiCOMPLEX8TimeSeries * XLALDuplicateMultiCOMPLEX8TimeSeries ( MultiCOMPLEX8TimeSeries *multiTimes ) { XLAL_CHECK_NULL ( multiTimes != NULL, XLAL_EINVAL ); XLAL_CHECK_NULL ( multiTimes->length > 0, XLAL_EINVAL ); UINT4 numDetectors = multiTimes->length; // ----- prepare memory for multicomplex8timeseries container MultiCOMPLEX8TimeSeries *out; XLAL_CHECK_NULL ( (out = XLALCalloc ( 1, sizeof(*out) )) != NULL, XLAL_ENOMEM ); out->length = numDetectors; XLAL_CHECK_NULL ( (out->data = XLALCalloc ( numDetectors, sizeof(*out->data) )) != NULL, XLAL_ENOMEM ); // ----- copy each of the numDet complex8timeseries contents for ( UINT4 X = 0; X < numDetectors; X ++ ) { XLAL_CHECK_NULL ( (out->data[X] = XLALDuplicateCOMPLEX8TimeSeries ( multiTimes->data[X] )) != NULL, XLAL_EFUNC ); } return out; } // XLALDuplicateMultiCOMPLEX8TimeSeries()
FstatInputData* XLALSetupFstat_Demod( MultiSFTVector **multiSFTs, MultiNoiseWeights **multiWeights, const EphemerisData *edat, const SSBprecision SSBprec, const UINT4 Dterms, const DemodHLType demodHL ) { // Check non-common input XLAL_CHECK_NULL(Dterms > 0, XLAL_EINVAL); // Check common input and allocate input data struct FstatInputData* input = SetupFstat_Common(multiSFTs, multiWeights, edat, SSBprec); XLAL_CHECK_NULL(input != NULL, XLAL_EFUNC); // Allocate demodulation input data struct FstatInputData_Demod *demod = XLALCalloc(1, sizeof(FstatInputData_Demod)); XLAL_CHECK_NULL(demod != NULL, XLAL_ENOMEM); // Save pointer to input SFTs, set supplied pointer to NULL demod->multiSFTs = *multiSFTs; *multiSFTs = NULL; // Calculate the detector states from the SFTs { LALStatus status = empty_status; LALGetMultiDetectorStates(&status, &demod->multiDetStates, demod->multiSFTs, edat); if (status.statusCode) { XLAL_ERROR_NULL(XLAL_EFAILED, "LALGetMultiDetectorStates() failed: %s (statusCode=%i)", status.statusDescription, status.statusCode); } } // Set parameters to pass to ComputeFStat() demod->params.Dterms = Dterms; demod->params.SSBprec = SSBprec; demod->params.buffer = NULL; demod->params.edat = edat; demod->params.demodHL = demodHL; // Save pointer to demodulation input data input->demod = demod; return input; } // XLALSetupFstat_Demod()
/** * \ingroup UserInput_h * Internal function: Register a user-variable with the module. * Effectively put an appropriate entry into UVAR_vars * * Checks that long- and short-options are unique, an error is returned * if a previous option name collides. * * \note don't use this function directly, as it is not type-safe!! * ==> use the type-safe macro XLALRegisterUvarMember(name,type,option,category,help) instead! */ int XLALRegisterUserVar ( const CHAR *name, /**< name of user-variable to register */ UserVarType type, /**< variable type (int,bool,string,real) */ CHAR optchar, /**< optional short-option character */ UserVarCategory category, /**< sets category to this */ const CHAR *helpstr, /**< help-string explaining this input-variable */ void *cvar /**< pointer to the actual C-variabe to link to this user-variable */ ) { XLAL_CHECK ( name != NULL, XLAL_EINVAL ); XLAL_CHECK ( (category > UVAR_CATEGORY_START) && (category < UVAR_CATEGORY_END), XLAL_EINVAL ); XLAL_CHECK ( cvar != NULL, XLAL_EINVAL ); // find end of uvar-list && check that neither short- nor long-option are taken already LALUserVariable *ptr = &UVAR_vars; while ( ptr->next != NULL ) { ptr = ptr->next; // long-option name taken already? XLAL_CHECK ( (name == NULL) || (ptr->name == NULL) || (strcmp ( name, ptr->name ) != 0), XLAL_EINVAL, "Long-option name '--%s' already taken!\n", name ); // short-option character taken already? XLAL_CHECK ( (optchar == 0) || (ptr->optchar == 0) || (optchar != ptr->optchar), XLAL_EINVAL, "Short-option '-%c' already taken (by '--%s')!\n", ptr->optchar, ptr->name ); } // while ptr->next // append new entry at the end XLAL_CHECK ( (ptr->next = XLALCalloc (1, sizeof(LALUserVariable))) != NULL, XLAL_ENOMEM ); // set pointer to newly created entry and fill in values ptr = ptr->next; ptr->name = name; ptr->type = type; ptr->optchar = optchar; ptr->help = helpstr; ptr->varp = cvar; ptr->category = category; return XLAL_SUCCESS; } // XLALRegisterUserVar()
/** * Simple creator function for MultiLIGOTimeGPSVector with numDetectors entries */ MultiLIGOTimeGPSVector * XLALCreateMultiLIGOTimeGPSVector ( UINT4 numDetectors ) { MultiLIGOTimeGPSVector *ret; if ( (ret = XLALMalloc ( sizeof(*ret) )) == NULL ) { XLALPrintError ("%s: XLALMalloc(%zu) failed.\n", __func__, sizeof(*ret) ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } ret->length = numDetectors; if ( (ret->data = XLALCalloc ( numDetectors, sizeof(*ret->data) )) == NULL ) { XLALPrintError ("%s: XLALCalloc(%d, %zu) failed.\n", __func__, numDetectors, sizeof(*ret->data) ); XLALFree ( ret ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } return ret; } /* XLALCreateMultiLIGOTimeGPSVector() */
/** * 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()
/** * Duplicates a COMPLEX8TimeSeries structure. * Allocates memory and copies contents. */ COMPLEX8TimeSeries * XLALDuplicateCOMPLEX8TimeSeries ( COMPLEX8TimeSeries *times ) { XLAL_CHECK_NULL ( times != NULL, XLAL_EINVAL ); XLAL_CHECK_NULL ( (times->data != NULL) && (times->data->length > 0) && ( times->data->data != NULL ), XLAL_EINVAL ); COMPLEX8TimeSeries *out; XLAL_CHECK_NULL ( (out = XLALCalloc ( 1, sizeof(*out) )) != NULL, XLAL_ENOMEM ); // copy header info [including data-pointer, will be reset] memcpy ( out, times, sizeof(*times) ); UINT4 numBins = times->data->length; XLAL_CHECK_NULL ( (out->data = XLALCreateCOMPLEX8Vector ( numBins )) != NULL, XLAL_EFUNC ); // copy contents of COMPLEX8 vector memcpy ( out->data->data, times->data->data, numBins * sizeof(times->data->data[0]) ); return out; } // XLALDuplicateCOMPLEX8TimeSeries()
/// /// Duplicate string 'in', removing surrounding quotes \" or \' if present. /// /// \note Quotes at the beginning of the string must be matched at the end, /// otherwise we return an error. /// /// \note The output string (*out) must be NULL /// int XLALParseStringValueAsSTRING ( CHAR **out, ///< [out] return allocated string const CHAR *valStr ///< [in] input string value ) { XLAL_CHECK ( valStr != NULL, XLAL_EINVAL ); XLAL_CHECK ( (out != NULL) && (*out == NULL), XLAL_EINVAL ); CHAR opening_quote = 0; CHAR closing_quote = 0; UINT4 inlen = strlen ( valStr ); if ( (valStr[0] == '\'') || (valStr[0] == '\"') ) { opening_quote = valStr[0]; } if ( (inlen >= 2) && ( (valStr[inlen-1] == '\'') || (valStr[inlen-1] == '\"') ) ) { closing_quote = valStr[inlen-1]; } // check matching quotes XLAL_CHECK ( opening_quote == closing_quote, XLAL_EINVAL, "Unmatched quotes in string [%s]\n", valStr ); const CHAR *start = valStr; UINT4 outlen = inlen; if ( opening_quote ) { start = valStr + 1; outlen = inlen - 2; } CHAR *ret; XLAL_CHECK ( (ret = XLALCalloc (1, outlen + 1)) != NULL, XLAL_ENOMEM ); strncpy ( ret, start, outlen ); ret[outlen] = 0; (*out) = ret; return XLAL_SUCCESS; } // XLALParseStringValueAsSTRING()
/* Resize and rebuild the hash table */ static int hashtbl_resize( LALHashTbl *ht ) { void **old_data = ht->data; int old_data_len = ht->data_len; ht->data_len = 2; while ( ht->data_len < 3*ht->n ) { ht->data_len *= 2; } ht->data = XLALCalloc( ht->data_len, sizeof( ht->data[0] ) ); XLAL_CHECK( ht->data != NULL, XLAL_ENOMEM ); ht->q = ht->n; for ( int k = 0; k < old_data_len; ++k ) { if ( old_data[k] != NULL && old_data[k] != DEL ) { int i = HASHIDX( ht, old_data[k] ); while ( ht->data[i] != NULL ) { INCRIDX( ht, i ); } ht->data[i] = old_data[k]; } } XLALFree( old_data ); return XLAL_SUCCESS; }
/** * function to generate random time-series with gaps, and corresponding SFTs */ int XLALgenerateRandomData ( REAL4TimeSeries **ts, SFTVector **sfts ) { /* input sanity checks */ XLAL_CHECK ( (ts != NULL) && ( (*ts) == NULL ), XLAL_EINVAL ); XLAL_CHECK ( (sfts != NULL) && ( (*sfts) == NULL ), XLAL_EINVAL ); // test parameters LIGOTimeGPS epoch0 = { 714180733, 0 }; UINT4 numSFTs = 20; REAL8 Tsft = 1000.0; // noise sigma REAL8 sigmaN = 0.1; /* prepare sampling constants */ REAL8 numR4SamplesPerSFT = 2 * 5000; REAL8 dtR4 = (Tsft / numR4SamplesPerSFT); UINT4 numR4SamplesTS = numSFTs * numR4SamplesPerSFT; /* ----- allocate timeseries ----- */ REAL4TimeSeries *outTS; // input timeseries XLAL_CHECK ( (outTS = XLALCreateREAL4TimeSeries ("H1:test timeseries", &epoch0, 0, dtR4, &emptyLALUnit, numR4SamplesTS )) != NULL, XLAL_EFUNC ); REAL4 *TSdata = outTS->data->data; /* initialize timeseries to zero (to allow for gaps) */ memset ( TSdata, 0, outTS->data->length * sizeof (*TSdata) ); /* also set up corresponding SFT timestamps vector */ LIGOTimeGPSVector *timestampsSFT; XLAL_CHECK ( (timestampsSFT = XLALCalloc (1, sizeof(*timestampsSFT)) ) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( (timestampsSFT->data = XLALCalloc (numSFTs, sizeof (*timestampsSFT->data) )) != NULL, XLAL_ENOMEM ); timestampsSFT->length = numSFTs; /* ----- set up random-noise timeseries with gaps ---------- */ for ( UINT4 alpha=0; alpha < numSFTs; alpha ++ ) { /* record this SFT's timestamp */ timestampsSFT->data[alpha] = epoch0; timestampsSFT->data[alpha].gpsSeconds += lround( alpha * Tsft ); /* generate all data-points of this SFT */ for ( UINT4 j=0; j < numR4SamplesPerSFT; j++ ) { UINT4 alpha_j = alpha * numR4SamplesPerSFT + j; REAL8 ti = alpha * Tsft + j * dtR4; /* unit-variance Gaussian noise + sinusoid */ TSdata[alpha_j] = crealf ( testSignal ( ti, sigmaN ) ); } // for js < numR4SamplesPerSFT } /* for alpha < numSFTs */ /* ----- generate SFTs from this timeseries ---------- */ SFTParams XLAL_INIT_DECL(sftParams); sftParams.Tsft = Tsft; sftParams.timestamps = timestampsSFT; sftParams.noiseSFTs = NULL; sftParams.window = NULL; SFTVector *outSFTs; XLAL_CHECK ( (outSFTs = XLALSignalToSFTs ( outTS, &sftParams )) != NULL, XLAL_EFUNC ); /* free memory */ XLALFree ( timestampsSFT->data ); XLALFree ( timestampsSFT ); /* return timeseries and SFTvector */ (*ts) = outTS; (*sfts) = outSFTs; return XLAL_SUCCESS; } // XLALgenerateRandomData()
/* ----- function definitions ---------- */ int main ( int argc, char *argv[] ) { LALStatus status; UserInput_t uvar_s; UserInput_t *uvar = &uvar_s; INIT_MEM ( status ); INIT_MEM ( uvar_s ); struct tms buf; uvar->randSeed = times(&buf); // ---------- register all our user-variable ---------- XLALregBOOLUserStruct ( help, 'h', UVAR_HELP , "Print this help/usage message"); XLALregINTUserStruct ( randSeed, 's', UVAR_OPTIONAL, "Specify random-number seed for reproducible noise."); /* read cmdline & cfgfile */ XLAL_CHECK ( XLALUserVarReadAllInput ( argc, argv ) == XLAL_SUCCESS, XLAL_EFUNC ); if ( uvar->help ) { /* if help was requested, we're done */ exit (0); } srand ( uvar->randSeed ); REAL8 startTimeREAL8 = 714180733; REAL8 duration = 180000; /* 50 hours */ REAL8 Tsft = 1800; /* assume 30min SFTs */ char earthEphem[] = TEST_DATA_DIR "earth00-19-DE200.dat.gz"; char sunEphem[] = TEST_DATA_DIR "sun00-19-DE200.dat.gz"; //REAL8 tolerance = 2e-10; /* same algorithm, should be basically identical results */ LIGOTimeGPS startTime, refTime; XLALGPSSetREAL8 ( &startTime, startTimeREAL8 ); refTime = startTime; // pick skyposition at random ----- */ SkyPosition skypos; skypos.longitude = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); // alpha uniform in [0, 2pi) skypos.latitude = LAL_PI_2 - acos ( 1 - 2.0 * rand()/RAND_MAX ); // sin(delta) uniform in [-1,1] skypos.system = COORDINATESYSTEM_EQUATORIAL; // pick binary orbital parameters: // somewhat inspired by Sco-X1 parameters from S2-paper (PRD76, 082001 (2007), gr-qc/0605028) // but with a more extreme eccentricity, and random argp REAL8 argp = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); // uniform in [0, 2pi) BinaryOrbitParams orbit; XLALGPSSetREAL8 ( &orbit.tp, 731163327 ); // time of observed periapsis passage (in SSB) orbit.argp = argp; // argument of periapsis (radians) orbit.asini = 1.44; // projected, normalized orbital semi-major axis (s) */ orbit.ecc = 1e-2; // relatively large value, for better testing orbit.period = 68023; // period (s) : about ~18.9h // ----- step 0: prepare test-case input for calling the BinarySSB-functions // setup detectors const char *sites[3] = { "H1", "L1", "V1" }; UINT4 numDetectors = sizeof( sites ) / sizeof ( sites[0] ); MultiLALDetector multiIFO; multiIFO.length = numDetectors; for ( UINT4 X = 0; X < numDetectors; X ++ ) { LALDetector *det = XLALGetSiteInfo ( sites[X] ); XLAL_CHECK ( det != NULL, XLAL_EFUNC, "XLALGetSiteInfo ('%s') failed for detector X=%d\n", sites[X], X ); multiIFO.sites[X] = (*det); // struct copy XLALFree ( det ); } // load ephemeris EphemerisData *edat = XLALInitBarycenter ( earthEphem, sunEphem ); XLAL_CHECK ( edat != NULL, XLAL_EFUNC, "XLALInitBarycenter('%s','%s') failed\n", earthEphem, sunEphem ); // setup multi-timeseries MultiLIGOTimeGPSVector *multiTS; XLAL_CHECK ( (multiTS = XLALCalloc ( 1, sizeof(*multiTS))) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( (multiTS->data = XLALCalloc (numDetectors, sizeof(*multiTS->data))) != NULL, XLAL_ENOMEM ); multiTS->length = numDetectors; for ( UINT4 X = 0; X < numDetectors; X ++ ) { multiTS->data[X] = XLALMakeTimestamps ( startTime, duration, Tsft, 0 ); XLAL_CHECK ( multiTS->data[X] != NULL, XLAL_EFUNC, "XLALMakeTimestamps() failed.\n"); } /* for X < numIFOs */ // generate detector-states MultiDetectorStateSeries *multiDetStates = XLALGetMultiDetectorStates ( multiTS, &multiIFO, edat, 0 ); XLAL_CHECK ( multiDetStates != NULL, XLAL_EFUNC, "XLALGetMultiDetectorStates() failed.\n"); // generate isolated-NS SSB times MultiSSBtimes *multiSSBIn = XLALGetMultiSSBtimes ( multiDetStates, skypos, refTime, SSBPREC_RELATIVISTICOPT ); XLAL_CHECK ( multiSSBIn != NULL, XLAL_EFUNC, "XLALGetMultiSSBtimes() failed.\n"); // ----- step 1: compute reference-result using old LALGetMultiBinarytimes() MultiSSBtimes *multiBinary_ref = NULL; LALGetMultiBinarytimes (&status, &(multiBinary_ref), multiSSBIn, multiDetStates, &orbit, refTime ); XLAL_CHECK ( status.statusCode == 0, XLAL_EFAILED, "LALGetMultiBinarytimes() failed with status = %d : '%s'\n", status.statusCode, status.statusDescription ); // ----- step 2: compute test-result using new XLALAddMultiBinaryTimes() MultiSSBtimes *multiBinary_test = NULL; PulsarDopplerParams doppler; memset(&doppler, 0, sizeof(doppler)); doppler.tp = orbit.tp; doppler.argp = orbit.argp; doppler.asini = orbit.asini; doppler.ecc = orbit.ecc; doppler.period = orbit.period; XLAL_CHECK ( XLALAddMultiBinaryTimes ( &multiBinary_test, multiSSBIn, &doppler ) == XLAL_SUCCESS, XLAL_EFUNC ); // ----- step 3: compare results REAL8 err_DeltaT, err_Tdot; REAL8 tolerance = 1e-10; int ret = XLALCompareMultiSSBtimes ( &err_DeltaT, &err_Tdot, multiBinary_ref, multiBinary_test ); XLAL_CHECK ( ret == XLAL_SUCCESS, XLAL_EFUNC, "XLALCompareMultiSSBtimes() failed.\n"); XLALPrintWarning ( "INFO: err(DeltaT) = %g, err(Tdot) = %g\n", err_DeltaT, err_Tdot ); XLAL_CHECK ( err_DeltaT < tolerance, XLAL_ETOL, "error(DeltaT) = %g exceeds tolerance of %g\n", err_DeltaT, tolerance ); XLAL_CHECK ( err_Tdot < tolerance, XLAL_ETOL, "error(Tdot) = %g exceeds tolerance of %g\n", err_Tdot, tolerance ); // ---- step 4: clean-up memory XLALDestroyUserVars(); XLALDestroyEphemerisData ( edat ); XLALDestroyMultiSSBtimes ( multiBinary_test ); XLALDestroyMultiSSBtimes ( multiBinary_ref ); XLALDestroyMultiSSBtimes ( multiSSBIn ); XLALDestroyMultiTimestamps ( multiTS ); XLALDestroyMultiDetectorStateSeries ( multiDetStates ); // check for memory-leaks LALCheckMemoryLeaks(); return XLAL_SUCCESS; } // main()