LALREAL8SequenceInterp *XLALREAL8SequenceInterpCreate(const REAL8Sequence *s, int kernel_length) { LALREAL8SequenceInterp *interp; double *cached_kernel; if(kernel_length < 3) XLAL_ERROR_NULL(XLAL_EDOM); /* interpolator induces phase shifts unless this is odd */ kernel_length -= (~kernel_length) & 1; interp = XLALMalloc(sizeof(*interp)); cached_kernel = XLALMalloc(kernel_length * sizeof(*cached_kernel)); if(!interp || !cached_kernel) { XLALFree(interp); XLALFree(cached_kernel); XLAL_ERROR_NULL(XLAL_EFUNC); } interp->s = s; interp->kernel_length = kernel_length; interp->welch_factor = 1.0 / ((kernel_length - 1.) / 2. + 1.); interp->cached_kernel = cached_kernel; /* >= 1 --> impossible. forces kernel init on first eval */ interp->residual = 2.; /* set no-op threshold. the kernel is recomputed when the residual * changes by this much */ interp->noop_threshold = 1. / (4 * interp->kernel_length); return interp; }
/** * Destroy the a full DopplerFullScanState structure */ void XLALDestroyDopplerFullScan ( DopplerFullScanState *scan ) { if ( scan == NULL ) { return; } if ( scan->factoredScan ) { XLALDestroyDopplerSkyScan ( &(scan->factoredScan->skyScan) ); XLALFree ( scan->factoredScan ); } if ( scan->covering ) { XLALREAL8VectorListDestroy ( scan->covering ); } if (scan->spindownTiling) { XLALDestroyLatticeTiling(scan->spindownTiling); } if (scan->spindownTilingItr) { XLALDestroyLatticeTilingIterator(scan->spindownTilingItr); } if (scan->spindownTilingPoint) { gsl_vector_free(scan->spindownTilingPoint); } if ( scan->skyRegion.vertices) { XLALFree ( scan->skyRegion.vertices); } XLALFree ( scan ); return; } // XLALDestroyDopplerFullScan()
/** * Simply outputs version information to fp. * * Returns != XLAL_SUCCESS on error (version-mismatch or writing to fp) */ int XLALOutputVersionString ( FILE *fp, int level ) { char *VCSInfoString; if (!fp ) { XLALPrintError ("%s: invalid NULL input 'fp'\n", __func__ ); XLAL_ERROR ( XLAL_EINVAL ); } if ( (VCSInfoString = XLALGetVersionString(level)) == NULL ) { XLALPrintError("%s: XLALGetVersionString() failed.\n", __func__); XLAL_ERROR ( XLAL_EFUNC ); } if ( fprintf (fp, "%s", VCSInfoString ) < 0 ) { XLALPrintError("%s: fprintf failed for given file-pointer 'fp'\n", __func__); XLALFree ( VCSInfoString); XLAL_ERROR ( XLAL_EIO ); } XLALFree ( VCSInfoString); return XLAL_SUCCESS; } /* XLALOutputVersionString() */
void XLALSQTPNDestroyCoherentGW(CoherentGW *wave) { //static const char *func = "LALSQTPNDestroyCoherentGW"; if (wave->a) { if (wave->a->data) { XLALDestroyREAL4VectorSequence(wave->a->data); } XLALFree(wave->a); } if (wave->f) { if (wave->f->data) { XLALDestroyREAL4Vector(wave->f->data); } XLALFree(wave->f); } if (wave->phi) { if (wave->phi->data) { XLALDestroyREAL8Vector(wave->phi->data); } XLALFree(wave->phi); } if (wave->shift) { if (wave->shift->data) { XLALDestroyREAL4Vector(wave->shift->data); } XLALFree(wave->shift); } }
/** * @brief Read a two-column data file. * @details Read a data file containing two whitespace separated columns * of data and create two arrays containing the data in each column. * If any line begins with the character '#' then it is ignored. * @param[out] xdat The x-data stored in the first column. * @param[out] ydat The y-data stored in the second column. * @param fp Pointer to a LALFILE structure opened for input. * @return The number of data points read or <0 if an error occurs. */ size_t XLALSimReadDataFile2Col(double **xdat, double **ydat, LALFILE * fp) { char line[LINE_MAX]; size_t size = PAGESIZE; size_t lnum = 0; size_t npts; *xdat = XLALMalloc(size * sizeof(**xdat)); *ydat = XLALMalloc(size * sizeof(**ydat)); npts = 0; while (XLALFileGets(line, sizeof(line), fp)) { ++lnum; if (strchr(line, '\n') == NULL) { /* line too long */ XLALFree(*xdat); XLALFree(*ydat); XLAL_ERROR(XLAL_EIO, "Line %zd too long\n", lnum); } if (*line == '#') /* ignore lines beginning with a '#' */ continue; if (sscanf(line, "%lf %lf", *xdat + npts, *ydat + npts) != 2) { XLALFree(*xdat); XLALFree(*ydat); XLAL_ERROR(XLAL_EIO, "Line %zd malformed\n", lnum); } if (++npts == size) { size += PAGESIZE; *xdat = XLALRealloc(*xdat, size * sizeof(**xdat)); *ydat = XLALRealloc(*ydat, size * sizeof(**ydat)); } } *xdat = XLALRealloc(*xdat, npts * sizeof(**xdat)); *ydat = XLALRealloc(*ydat, npts * sizeof(**ydat)); return npts; }
/// Parse a string into a BOOLEAN /// Allowed string-values are (case-insensitive): /// {"yes", "true", "1"} --> TRUE /// {"no", "false", "0"} --> FALSE /// /// NOTE: This throws an error on _any_ extraneous leading or trailing characters or whitespace int XLALParseStringValueAsBOOLEAN ( BOOLEAN *valBOOLEAN, ///< [out] return BOOLEAN value const char *valString ///< [in] input string value ) { XLAL_CHECK ( (valBOOLEAN != NULL) && (valString != NULL ), XLAL_EINVAL ); /* get rid of case ambiguities */ char *valStringLower; XLAL_CHECK ( (valStringLower = XLALMalloc ( strlen(valString) + 1 )) != NULL, XLAL_ENOMEM ); strcpy ( valStringLower, valString ); XLALStringToLowerCase ( valStringLower ); /* parse it as a bool */ if ( !strcmp(valStringLower, "yes") || !strcmp(valStringLower, "true") || !strcmp(valStringLower, "1") ) { (*valBOOLEAN) = 1; } else if ( !strcmp(valStringLower, "no") || !strcmp(valStringLower, "false") || !strcmp(valStringLower, "0") ) { (*valBOOLEAN) = 0; } else { XLALFree ( valStringLower ); XLAL_ERROR ( XLAL_EINVAL, "Illegal bool-string '%s', needs to be one of {'yes', 'true', '1'} or {'no', 'false', '0'} (case-insensitive)\n", valString ); } XLALFree ( valStringLower ); return XLAL_SUCCESS; } // XLALParseStringValueAsBOOLEAN()
// test string-vector parsing function XLALParseStringValueAsStringVector() int test_ParseStringVector(void) { #define STR1 "Hello, world!" #define STR2 "xyda 3!#4134" #define STR3 "&\\//.. :: some junk" #define STR4 "H1" #define STR5 "H2" #define STR6 "L1" LALStringVector *strVect1; XLAL_CHECK ( (strVect1 = XLALCreateStringVector ( STR1, STR2, STR3, STR4, STR5, NULL )) != NULL, XLAL_EFUNC ); XLAL_CHECK ( (strVect1 = XLALAppendString2Vector ( strVect1, STR6 )) != NULL, XLAL_EFUNC ); // now 'print' this string-vector as a 'string-value', then re-parse back into a vector: CHAR *strValue1 = NULL; LALStringVector *strVect2 = NULL; XLAL_CHECK ( (strValue1 = XLALPrintStringValueOfSTRINGVector ( &strVect1 )) != NULL, XLAL_EFUNC ); XLALPrintInfo ("String value of initial string-vector: %s\n", strValue1 ); XLAL_CHECK ( XLALParseStringValueAsSTRINGVector ( &strVect2, strValue1 ) == XLAL_SUCCESS, XLAL_EFUNC ); CHAR *strValue2 = NULL; XLAL_CHECK ( (strValue2 = XLALPrintStringValueOfSTRINGVector ( &strVect2 )) != NULL, XLAL_EFUNC ); XLALPrintInfo ("String value of re-parsed string-vector: %s\n", strValue2 ); // ----- compare results // 1) compare string values XLAL_CHECK ( strcmp ( strValue1, strValue2 ) == 0, XLAL_EFAILED, "String values differ:\nstrValue1 = %s\nstrValue2 = %s\n", strValue1, strValue2 ); // 2) compare string vectors UINT4 len1 = strVect1->length; UINT4 len2 = strVect2->length; XLAL_CHECK ( len1 == len2, XLAL_EFAILED, "String vectors vect1 and vect2 have different lengths (%d != %d )\n", len1, len2 ); for ( UINT4 i = 0; i < len1; i++ ) { if ( strcmp ( strVect1->data[i], strVect2->data[i] ) != 0 ) { for ( UINT4 j=0; j < len1; j ++ ) { XLALPrintError ("j = %d: s1[j] = %6s, s2[j] = %6s\n", j, strVect1->data[j], strVect2->data[j] ); } XLAL_ERROR ( XLAL_EFAILED, "Printed and re-parsed string-vector differ!\n" ); } // if s1[i] != s2[i] } // for i < len // clean up memory XLALFree ( strValue1 ); XLALFree ( strValue2 ); XLALDestroyStringVector ( strVect1 ); XLALDestroyStringVector ( strVect2 ); return XLAL_SUCCESS; } // test_ParseStringVector()
void free_inputParams(inputParamsStruct *input) { XLALFree((CHAR*)input->sftType); XLALFree((LALDetector*)input->det); gsl_rng_free(input->rng); XLALFree((inputParamsStruct*)input); } /* free_inputParams() */
/** * Free a candidateVector * \param [in] vector Pointer of candidateVector to be freed */ void free_candidateVector(candidateVector *vector) { if (vector==NULL) return; if ((!vector->length || !vector->data) && (vector->length || vector->data)) XLAL_ERROR_VOID(XLAL_EINVAL); if (vector->data) XLALFree((candidate*)vector->data); vector->data = NULL; XLALFree((candidateVector*)vector); return; } /* free_candidateVector() */
/** * Restrict the EphemerisData 'edat' to the smallest number of entries * required to cover the GPS time range ['startGPS', 'endGPS'] * * \ingroup LALBarycenter_h */ int XLALRestrictEphemerisData ( EphemerisData *edat, const LIGOTimeGPS *startGPS, const LIGOTimeGPS *endGPS ) { // Check input XLAL_CHECK(edat != NULL, XLAL_EFAULT); XLAL_CHECK(startGPS != NULL, XLAL_EFAULT); XLAL_CHECK(endGPS != NULL, XLAL_EFAULT); XLAL_CHECK(XLALGPSCmp(startGPS, endGPS) < 0, XLAL_EINVAL); // Convert 'startGPS' and 'endGPS' to REAL8s const REAL8 start = XLALGPSGetREAL8(startGPS), end = XLALGPSGetREAL8(endGPS); // Increase 'ephemE' and decrease 'nentriesE' to fit the range ['start', 'end'] PosVelAcc *const old_ephemE = edat->ephemE; do { if (edat->nentriesE > 1 && edat->ephemE[0].gps < start && edat->ephemE[1].gps <= start) { ++edat->ephemE; --edat->nentriesE; } else if (edat->nentriesE > 1 && edat->ephemE[edat->nentriesE-1].gps > end && edat->ephemE[edat->nentriesE-2].gps >= end) { --edat->nentriesE; } else { break; } } while(1); // Reallocate 'ephemE' to new table size, and free old table PosVelAcc *const new_ephemE = XLALMalloc(edat->nentriesE * sizeof(*new_ephemE)); XLAL_CHECK(new_ephemE != NULL, XLAL_ENOMEM); memcpy(new_ephemE, edat->ephemE, edat->nentriesE * sizeof(*new_ephemE)); edat->ephemE = new_ephemE; XLALFree(old_ephemE); // Increase 'ephemS' and decrease 'nentriesS' to fit the range ['start', 'end'] PosVelAcc *const old_ephemS = edat->ephemS; do { if (edat->nentriesS > 1 && edat->ephemS[0].gps < start && edat->ephemS[1].gps <= start) { ++edat->ephemS; --edat->nentriesS; } else if (edat->nentriesS > 1 && edat->ephemS[edat->nentriesS-1].gps > end && edat->ephemS[edat->nentriesS-2].gps >= end) { --edat->nentriesS; } else { break; } } while(1); // Reallocate 'ephemS' to new table size, and free old table PosVelAcc *const new_ephemS = XLALMalloc(edat->nentriesS * sizeof(*new_ephemS)); XLAL_CHECK(new_ephemS != NULL, XLAL_ENOMEM); memcpy(new_ephemS, edat->ephemS, edat->nentriesS * sizeof(*new_ephemS)); edat->ephemS = new_ephemS; XLALFree(old_ephemS); return XLAL_SUCCESS; } /* XLALRestrictEphemerisData() */
/** Function that destroys the whole test GR params linked list */ void XLALSimInspiralDestroyTestGRParam( LALSimInspiralTestGRParam *parameter /**< Linked list to destroy */ ) { LALSimInspiralTestGRParam *tmp; while(parameter){ tmp=parameter->next; XLALFree(parameter->data); XLALFree(parameter); parameter=tmp; } }
/** * Destructor for PulsarParams types */ void XLALDestroyPulsarParams ( PulsarParams *params ) { if ( params == NULL ) { return; } XLALFree ( params->name ); XLALFree ( params ); return; } // XLALDestroyPulsarParams()
/** * \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; }
/** * Destructor for EphemerisVector, NULL robust. */ void XLALDestroyEphemerisVector ( EphemerisVector *ephemV ) { if ( !ephemV ) return; if ( ephemV->data ) XLALFree ( ephemV->data ); XLALFree ( ephemV ); return; } /* XLALDestroyEphemerisVector() */
/** * Free an UpperLimitVector * \param [in] vector Pointer to an UpperLimitVector */ void free_UpperLimitVector(UpperLimitVector *vector) { if (vector==NULL) return; if ((!vector->length || !vector->data) && (vector->length || vector->data)) XLAL_ERROR_VOID(XLAL_EINVAL); if (vector->data) { for (UINT4 ii=0; ii<vector->length; ii++) free_UpperLimitStruct(&(vector->data[ii])); XLALFree((UpperLimit*)vector->data); } vector->data = NULL; XLALFree((UpperLimitVector*)vector); return; } /* free_UpperLimitVector() */
/** * Destructor for TimeCorrectionData struct, NULL robust. * \ingroup LALBarycenter_h */ void XLALDestroyTimeCorrectionData ( TimeCorrectionData *tcd ) { if ( !tcd ) return; if ( tcd->timeCorrs ) XLALFree ( tcd->timeCorrs ); XLALFree ( tcd ); return; } /* XLALDestroyTimeCorrectionData() */
/** * @brief Opens a specified data file, searching default path if necessary. * @details Opens a data file for input with a specified path name. * If the path name is an absolute path then this specific file is opened; * otherwise, search for the file in paths given in the environment variable * LALSIM_DATA_PATH, and finally search in the installed PKG_DATA_DIR path. * @param[in] fname The path of the file to open. * @return A pointer to a LALFILE structure or NULL on failure. */ LALFILE *XLALSimReadDataFileOpen(const char *fname) { const char *pkgdatadir = PKG_DATA_DIR; char path[PATH_MAX] = ""; LALFILE *fp; if (strchr(fname, '/')) { /* a specific path is given */ if (realpath(fname, path) == NULL) XLAL_ERROR_NULL(XLAL_EIO, "Unresolvable path %s\n", path); } else { /* unspecific path given: use LALSIM_DATA_PATH environment */ char *env = getenv("LALSIM_DATA_PATH"); char *str; char *dir; env = str = XLALStringDuplicate(env ? env : ":"); while ((dir = strsep(&str, ":"))) { if (strlen(dir)) snprintf(path, sizeof(path), "%s/%s", dir, fname); else /* use default path */ snprintf(path, sizeof(path), "%s/%s", pkgdatadir, fname); if (access(path, R_OK) == 0) /* found it! */ break; *path = 0; } XLALFree(env); } if (!*path) /* could not find file */ XLAL_ERROR_NULL(XLAL_EIO, "Could not find data file %s\n", fname); fp = XLALFileOpenRead(path); if (!fp) /* open failure */ XLAL_ERROR_NULL(XLAL_EIO, "Could not open data file %s\n", path); return fp; }
/** * Change frequency-bin order from 'SFT' to fftw-convention * ie. from f[-(N-1)/2], ... f[-1], f[0], f[1], .... f[N/2] * to FFTW: f[0], f[1],...f[N/2], f[-(N-1)/2], ... f[-2], f[-1] */ int XLALReorderSFTtoFFTW (COMPLEX8Vector *X) { XLAL_CHECK ( (X != NULL) && (X->length > 0), XLAL_EINVAL ); UINT4 N = X->length; UINT4 Npos_and_DC = NhalfPosDC ( N ); UINT4 Nneg = NhalfNeg ( N ); /* allocate temporary storage for swap */ COMPLEX8 *tmp; XLAL_CHECK ( (tmp = XLALMalloc ( N * sizeof(*tmp) )) != NULL, XLAL_ENOMEM ); memcpy ( tmp, X->data, N * sizeof(*tmp) ); /* Copy second half of FFTW: 'negative' frequencies */ memcpy ( X->data + Npos_and_DC, tmp, Nneg * sizeof(*tmp) ); /* Copy first half of FFTW: 'DC + positive' frequencies */ memcpy ( X->data, tmp + Nneg, Npos_and_DC * sizeof(*tmp) ); XLALFree(tmp); return XLAL_SUCCESS; } // XLALReorderSFTtoFFTW()
/** * Function to determine the PulsarParamsVector input from a user-input defining CW sources. * * This option supports a dual-type feature: if any string in the list is of the form '{...}', then * it determines the *contents* of a config-file, otherwise the name-pattern of config-files to be parsed by XLALFindFiles(), * NOTE: when specifying file-contents, options can be separated by ';' and/or newlines) */ PulsarParamsVector * XLALPulsarParamsFromUserInput ( const LALStringVector *UserInput ///< [in] user-input CSV list defining 'CW sources' ) { XLAL_CHECK_NULL ( UserInput, XLAL_EINVAL ); XLAL_CHECK_NULL ( UserInput->length > 0, XLAL_EINVAL ); PulsarParamsVector *allSources = NULL; for ( UINT4 l = 0; l < UserInput->length; l ++ ) { const char *thisInput = UserInput->data[l]; if ( thisInput[0] != '{' ) // if it's an actual file-specification { LALStringVector *file_list; XLAL_CHECK_NULL ( ( file_list = XLALFindFiles ( &thisInput[0] )) != NULL, XLAL_EFUNC ); UINT4 numFiles = file_list->length; for ( UINT4 i = 0; i < numFiles; i ++ ) { PulsarParamsVector *sources_i; XLAL_CHECK_NULL ( (sources_i = XLALPulsarParamsFromFile ( file_list->data[i] )) != NULL, XLAL_EFUNC ); XLAL_CHECK_NULL ( (allSources = XLALPulsarParamsVectorAppend ( allSources, sources_i )) != NULL, XLAL_EFUNC ); XLALDestroyPulsarParamsVector ( sources_i ); } // for i < numFiles XLALDestroyStringVector ( file_list ); } // if file-pattern given else { UINT4 len = strlen(thisInput); XLAL_CHECK_NULL ( (thisInput[0] == '{') && (thisInput[len-1] == '}'), XLAL_EINVAL, "Invalid file-content input:\n%s\n", thisInput ); char *buf; XLAL_CHECK_NULL ( (buf = XLALStringDuplicate ( &thisInput[1] )) != NULL, XLAL_EFUNC ); len = strlen(buf); buf[len-1] = 0; // remove trailing '}' LALParsedDataFile *cfgdata = NULL; XLAL_CHECK_NULL ( XLALParseDataFileContent ( &cfgdata, buf ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALFree ( buf ); PulsarParamsVector *addSource; XLAL_CHECK_NULL ( (addSource = XLALCreatePulsarParamsVector ( 1 )) != NULL, XLAL_EFUNC ); XLAL_CHECK_NULL ( XLALReadPulsarParams ( &addSource->data[0], cfgdata, NULL ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK_NULL ( (addSource->data[0].name = XLALStringDuplicate ( "direct-string-input" )) != NULL, XLAL_EFUNC ); XLALDestroyParsedDataFile ( cfgdata ); XLAL_CHECK_NULL ( (allSources = XLALPulsarParamsVectorAppend ( allSources, addSource )) != NULL, XLAL_EFUNC ); XLALDestroyPulsarParamsVector ( addSource ); } // if direct config-string given } // for l < len(UserInput) return allSources; } // XLALPulsarParamsFromUserInput()
static void SplineData_Destroy(SplineData *splinedata) { if(!splinedata) return; if(splinedata->bwx) gsl_bspline_free(splinedata->bwx); if(splinedata->bwy) gsl_bspline_free(splinedata->bwy); XLALFree(splinedata); }
/** * This routine frees up all the memory. */ int XLALFreeMem ( ConfigVars_t *cfg ) { XLAL_CHECK ( cfg != NULL, XLAL_EINVAL ); /* Free config-Variables and userInput stuff */ XLALDestroyUserVars(); /* free timestamps if any */ XLALDestroyMultiTimestamps ( cfg->multiTimestamps ); XLALFree ( cfg->VCSInfoString ); // free noise-SFT catalog XLALDestroySFTCatalog ( cfg->noiseCatalog ); XLALDestroyMultiSFTCatalogView ( cfg->multiNoiseCatalogView ); // free noise time-series data XLALDestroyMultiREAL8TimeSeries ( cfg->inputMultiTS ); /* Clean up earth/sun Ephemeris tables */ XLALDestroyEphemerisData ( cfg->edat ); return XLAL_SUCCESS; } /* XLALFreeMem() */
/** * Extract multi detector-info from a given multi SFTCatalog view */ int XLALMultiLALDetectorFromMultiSFTCatalogView ( MultiLALDetector *multiIFO, //!< [out] list of detectors found in catalog const MultiSFTCatalogView *multiView //!< [in] multi-IFO view of SFT catalog ) { // check input consistency XLAL_CHECK ( multiIFO != NULL, XLAL_EINVAL ); XLAL_CHECK ( multiView != NULL, XLAL_EINVAL ); UINT4 numIFOs = multiView->length; XLAL_CHECK ( (numIFOs > 0) && (numIFOs <= PULSAR_MAX_DETECTORS), XLAL_EINVAL ); multiIFO->length = numIFOs; for ( UINT4 X=0; X < numIFOs; X ++ ) { LALDetector *site; XLAL_CHECK ( (site = XLALGetSiteInfo ( multiView->data[X].data->header.name )) != NULL, XLAL_EFUNC ); multiIFO->sites[X] = (*site); // struct-copy XLALFree ( site ); } /* for X < numIFOs */ return XLAL_SUCCESS; } /* XLALMultiLALDetectorFromMultiSFTCatalogView() */
/** * Parse string-vectors (typically input by user) of N detector-names * for detectors \f$X=1\ldots N\f$, returns a MultiLALDetector struct * */ int XLALParseMultiLALDetector ( MultiLALDetector *detInfo, /**< [out] parsed detector-info struct */ const LALStringVector *detNames /**< [in] list of detector names */ ) { XLAL_CHECK ( detInfo != NULL, XLAL_EINVAL ); XLAL_CHECK ( detNames != NULL, XLAL_EINVAL ); UINT4 numDet = detNames->length; XLAL_CHECK ( (numDet > 0) && (numDet <= PULSAR_MAX_DETECTORS), XLAL_EINVAL ); detInfo->length = numDet; /* parse input strings and fill detInfo */ for ( UINT4 X = 0; X < numDet; X ++ ) { LALDetector *ifo; /* first parse detector name */ XLAL_CHECK ( (ifo = XLALGetSiteInfo ( detNames->data[X] ) ) != NULL, XLAL_EINVAL, "Failed to parse detector-name '%s'\n", detNames->data[X] ); detInfo->sites[X] = (*ifo); // struct copy XLALFree ( ifo ); } /* for X < numDet */ return XLAL_SUCCESS; } /* XLALParseMultiLALDetector() */
// test string-vector parsing function XLALParseStringValueAsStringVector() int test_ParseREAL8Vector(void) { const char *csvIn = "0.1,5,-5.1e+99,1.23456789e-99,inf,nan"; REAL8 vals[] = {0.1, 5, -5.1e+99, 1.23456789e-99 }; // only finite values for comparison // parse csv string as REAL8Vector: REAL8Vector *vect1 = NULL; XLAL_CHECK ( XLALParseStringValueAsREAL8Vector ( &vect1, csvIn ) == XLAL_SUCCESS, XLAL_EFUNC ); // test1: re-print as string, compare strings char *csvOut; XLAL_CHECK ( (csvOut = XLALPrintStringValueOfREAL8Vector ( &vect1 )) != NULL, XLAL_EFUNC ); XLAL_CHECK ( strcmp ( csvIn, csvOut ) == 0, XLAL_EFAILED, "csvIn != csvOut:\ncsvIn = %s\ncsvOut = %s\n", csvIn, csvOut ); // test2: compare finite parsed values: for ( UINT4 i = 0; i < 4; i ++ ) { XLAL_CHECK ( vect1->data[i] == vals[i], XLAL_EFAILED, "Parsed %d-th value differs from input: %.16g != %.16g\n", i, vect1->data[i], vals[i] ); } // check non-finite values XLAL_CHECK ( fpclassify ( vect1->data[4] ) == FP_INFINITE, XLAL_EFAILED, "Failed to parse 'inf'\n"); XLAL_CHECK ( fpclassify ( vect1->data[5] ) == FP_NAN, XLAL_EFAILED, "Failed to parse 'nan'\n"); // clean up memory XLALFree ( csvOut ); XLALDestroyREAL8Vector ( vect1 ); return XLAL_SUCCESS; } // test_ParseREAL8Vector()
void DSERIES ( SERIESTYPE *series ) { if(series) DSEQUENCE (series->data); XLALFree(series); }
/** * Destroy a LALSimInspiralWaveformFlags struct. */ void XLALSimInspiralDestroyWaveformFlags( LALSimInspiralWaveformFlags *waveFlags ) { if( waveFlags ) XLALFree(waveFlags); return; }
/** * \brief Deserializes a \c LIGOTimeGPS structure from a VOTable XML document * * This function takes a VOTable XML document and deserializes (extracts) * the \c LIGOTimeGPS structure identified by the given name. * * \param xmlDocument [in] Pointer to the VOTable XML document containing the structure * \param name [in] Unique identifier of the particular \c LIGOTimeGPS structure to be deserialized * \param ltg [out] Pointer to an empty \c LIGOTimeGPS structure to store the deserialized instance * * \return \c XLAL_SUCCESS if the specified \c LIGOTimeGPS structure could be found and * deserialized successfully. * * \sa XLALVOTXML2LIGOTimeGPSByName * \sa XLALGetSingleNodeContentByXPath * * \author Oliver Bock\n * Albert-Einstein-Institute Hannover, Germany */ INT4 XLALVOTDoc2LIGOTimeGPSByName ( const xmlDocPtr xmlDocument, const CHAR *name, LIGOTimeGPS *ltg ) { /* set up local variables */ CHAR *nodeContent = NULL; /* sanity checks */ if(!xmlDocument) { XLALPrintError("Invalid input parameter: xmlDocument\n"); XLAL_ERROR(XLAL_EINVAL); } if(!name || strlen(name) <= 0) { XLALPrintError("Invalid input parameter: name\n"); XLAL_ERROR(XLAL_EINVAL); } if(!ltg) { XLALPrintError("Invalid input parameter: ltg\n"); XLAL_ERROR(XLAL_EINVAL); } /* retrieve LIGOTimeGPS.gpsSeconds content */ if ( (nodeContent = XLALReadVOTAttributeFromNamedElement ( xmlDocument, name, "gpsSeconds", VOT_PARAM, VOT_VALUE )) == NULL ) { XLAL_ERROR ( XLAL_EFUNC ); } /* parse content */ if( sscanf ( nodeContent, "%i", <g->gpsSeconds) == EOF ) { XLALFree(nodeContent); XLALPrintError("Invalid node content encountered: %s.gpsSeconds\n", name); XLAL_ERROR ( XLAL_EDATA ); } XLALFree(nodeContent); /* retrieve LIGOTimeGPS.gpsNanoSeconds content */ nodeContent = XLALReadVOTAttributeFromNamedElement ( xmlDocument, name, "gpsNanoSeconds", VOT_PARAM, VOT_VALUE ); if( !nodeContent || sscanf( nodeContent, "%i", <g->gpsNanoSeconds) == EOF) { if ( nodeContent ) XLALFree (nodeContent); XLALPrintError("Invalid node content encountered: %s.gpsNanoSeconds\n", name); XLAL_ERROR(XLAL_EDATA); } /* clean up*/ XLALFree ( nodeContent ); return XLAL_SUCCESS; } /* XLALVOTDoc2LIGOTimeGPSByName() */
/** * Free an allocated KDE structure. * * Frees all memory allocated for a given KDE structure. * @param[in] kde The KDE structure to be freed. * \sa LALInferenceKDE, LALInferenceInitKDE */ void LALInferenceDestroyKDE(LALInferenceKDE *kde) { if (kde) { gsl_vector_free(kde->mean); gsl_matrix_free(kde->cholesky_decomp_cov); gsl_matrix_free(kde->cholesky_decomp_cov_lower); gsl_matrix_free(kde->cov); if (kde->npts > 0) gsl_matrix_free(kde->data); XLALFree(kde->lower_bound_types); XLALFree(kde->upper_bound_types); XLALFree(kde->lower_bounds); XLALFree(kde->upper_bounds); XLALFree(kde); } }
void XLALHashTblDestroy( LALHashTbl *ht ) { if ( ht != NULL ) { if ( ht->data != NULL ) { if ( ht->dtor != NULL ) { for ( int i = 0; i < ht->data_len; ++i ) { if ( ht->data[i] != NULL && ht->data[i] != DEL ) { ht->dtor( ht->data[i] ); } } } XLALFree( ht->data ); } XLALFree( ht ); } }
/// /// Destroy coherent input data /// void XLALWeaveCohInputDestroy( WeaveCohInput *coh_input ) { if ( coh_input != NULL ) { XLALDestroyFstatInput( coh_input->Fstat_input ); XLALFree( coh_input ); } }