/** * @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; }
STYPE * XFUNC ( UINT4 length, UINT4 veclen ) { STYPE *seq; if ( ! length || ! veclen ) XLAL_ERROR_NULL( XLAL_EBADLEN ); seq = LALMalloc( sizeof( *seq ) ); if ( ! seq ) XLAL_ERROR_NULL( XLAL_ENOMEM ); seq->length = length; seq->vectorLength = veclen; if ( ! length || ! veclen ) seq->data = NULL; else { seq->data = LALMalloc( length * veclen * sizeof( *seq->data ) ); if ( ! seq ) { LALFree( seq ); XLAL_ERROR_NULL( XLAL_ENOMEM ); } } return seq; }
LALFrameUFrDetector *XLALFrameUFrDetectorAlloc_FrameL_(const char *name, const char *prefix, double latitude, double longitude, double elevation, double azimuthX, double azimuthY, double altitudeX, double altitudeY, double midpointX, double midpointY, int localTime) { LALFrameUFrDetector *detector; detector = LALCalloc(1, sizeof(*detector)); if (!detector) XLAL_ERROR_NULL(XLAL_ENOMEM); detector->handle = calloc(1, sizeof(*detector->handle)); if (!detector->handle) XLAL_ERROR_NULL(XLAL_ENOMEM); detector->handle->classe = FrDetectorDef(); detector->handle->name = strdup(name); if (!detector->handle->name) { XLALFrameUFrDetectorFree(detector); XLAL_ERROR_NULL(XLAL_ENOMEM); } if (prefix) { memcpy(detector->prefix, prefix, 2); memcpy(detector->handle->prefix, prefix, 2); } detector->handle->longitude = longitude; /* longitude (east of greenwich) in radians */ detector->handle->latitude = latitude; /* latitude (north of equator) in radians */ detector->handle->elevation = elevation; /* detector altitude (meter) */ detector->handle->armXazimuth = azimuthX; /* orientation of X arm in radians CW from North */ detector->handle->armYazimuth = azimuthY; /* orientation of Y arm in radians CW from North */ /* Azimuth values should be in the range 0 to 2pi */ detector->handle->armXaltitude = altitudeX; /* altitude (pitch) of the X arm */ detector->handle->armYaltitude = altitudeY; /* altitude (pitch) of the Y arm */ detector->handle->armXmidpoint = midpointX; /* vertex to middle of the X arm distance */ detector->handle->armYmidpoint = midpointY; /* vertex to middle of the Y arm distance */ detector->handle->localTime = localTime; /* local time - UTC time (second) */ return detector; }
STYPE *STREAMREADSERIES(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit) { STYPE *series; size_t length; /* create and initialize a zero-length time series vector */ series = CREATESERIES(chname, start, 0.0, 0.0, &lalADCCountUnit, 0); if (!series) XLAL_ERROR_NULL(XLAL_EFUNC); /* get the time series meta-data */ if (STREAMGETSERIES(series, stream)) { DESTROYSERIES(series); XLAL_ERROR_NULL(XLAL_EFUNC); } /* resize the time series to the correct number of samples */ length = duration / series->deltaT; if (lengthlimit && (lengthlimit < length)) length = lengthlimit; if (!RESIZESERIES(series, 0, length)) { DESTROYSERIES(series); XLAL_ERROR_NULL(XLAL_EFUNC); } /* read the data */ if (XLALFrStreamSeek(stream, start) || STREAMGETSERIES(series, stream)) { DESTROYSERIES(series); XLAL_ERROR_NULL(XLAL_EFUNC); } return series; }
REAL8FrequencySeries *XLALFrStreamInputREAL8FrequencySeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch) { REAL8FrequencySeries *series; LALTYPECODE typecode; if (XLALFrStreamSeek(stream, epoch)) XLAL_ERROR_NULL(XLAL_EFUNC); typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos); switch (typecode) { case LAL_S_TYPE_CODE: INPUTFS(series, REAL8, REAL4, S2S, stream, chname, epoch); break; case LAL_D_TYPE_CODE: series = XLALFrStreamReadREAL8FrequencySeries(stream, chname, epoch); if (!series) XLAL_ERROR_NULL(XLAL_EFUNC); break; case LAL_C_TYPE_CODE: case LAL_Z_TYPE_CODE: XLAL_PRINT_ERROR("Cannot convert complex type to float type"); default: XLAL_ERROR_NULL(XLAL_ETYPE); } return series; }
static FrHistory *XLALFrHistoryCopy(const FrHistory * original) { FrHistory *copy; copy = calloc(1, sizeof(*copy)); if (!copy) XLAL_ERROR_NULL(XLAL_ENOMEM); memcpy(copy, original, sizeof(*copy)); /* in case of failure, set to zero/null the things we need * to allocate separately */ copy->name = NULL; copy->comment = NULL; copy->next = NULL; if (original->name) { copy->name = strdup(original->name); if (!copy->name) goto failure; } if (original->comment) { copy->comment = strdup(original->comment); if (!copy->comment) goto failure; } if (original->next) { copy->next = XLALFrHistoryCopy(original->next); if (!copy->next) goto failure; } /* successful return */ return copy; failure: /* unsuccessful return */ FrHistoryFree(copy); XLAL_ERROR_NULL(XLAL_ENOMEM); }
/* stripped-down copy of FrAdcDataNewF */ static FrAdcData *XLALFrameUFrAdcDataNew(const char *name, int type) { FrAdcData *adcData; adcData = calloc(1, sizeof(*adcData)); if (!adcData) XLAL_ERROR_NULL(XLAL_ENOMEM); adcData->classe = FrAdcDataDef(); adcData->name = strdup(name); if (!adcData->name) { FrAdcDataFree(adcData); XLAL_ERROR_NULL(XLAL_ENOMEM); } switch (type) { case FR_VECT_4S: adcData->nBits = 32; break; case FR_VECT_2S: adcData->nBits = 16; break; case FR_VECT_C: adcData->nBits = 8; break; case FR_VECT_4R: adcData->nBits = 32; break; case FR_VECT_8R: adcData->nBits = 64; break; default: /* invalid type */ FrAdcDataFree(adcData); XLAL_ERROR_NULL(XLAL_ETYPE); } return adcData; }
COMPLEX16FrequencySeries *XLALFrStreamInputCOMPLEX16FrequencySeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch) { COMPLEX16FrequencySeries *series; LALTYPECODE typecode; if (XLALFrStreamSeek(stream, epoch)) XLAL_ERROR_NULL(XLAL_EFUNC); typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos); switch (typecode) { case LAL_S_TYPE_CODE: INPUTFS(series, COMPLEX16, REAL4, S2S, stream, chname, epoch); break; case LAL_D_TYPE_CODE: INPUTFS(series, COMPLEX16, REAL8, S2S, stream, chname, epoch); break; case LAL_C_TYPE_CODE: INPUTFS(series, COMPLEX16, COMPLEX8, S2S, stream, chname, epoch); case LAL_Z_TYPE_CODE: series = XLALFrStreamReadCOMPLEX16FrequencySeries(stream, chname, epoch); if (!series) XLAL_ERROR_NULL(XLAL_EFUNC); default: XLAL_ERROR_NULL(XLAL_ETYPE); } return series; }
/** * 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() */
/** * @brief Creates an equation of state structure from tabulated equation * of state data of a known name. * @details A known, installed, named tabulated equation of state data file is * read and the used to create the equation of state structure. Presently * the known equations of state are: * - AP4 * - FPS * - SLY4 * @param[in] name The name of the equation of state. * @return A pointer to neutron star equation of state structure. */ LALSimNeutronStarEOS *XLALSimNeutronStarEOSByName(const char *name) { static const char fname_base[] = "LALSimNeutronStarEOS_"; static const char fname_extn[] = ".dat"; static const char *eos_names[] = { "FPS", "SLY4", "AP4" }; size_t n = XLAL_NUM_ELEM(eos_names); size_t i; char fname[FILENAME_MAX]; for (i = 0; i < n; ++i) if (mystrcasecmp(name, eos_names[i]) == 0) { LALSimNeutronStarEOS *eos; snprintf(fname, sizeof(fname), "%s%s%s", fname_base, eos_names[i], fname_extn); eos = XLALSimNeutronStarEOSFromFile(fname); if (!eos) XLAL_ERROR_NULL(XLAL_EFUNC); snprintf(eos->name, sizeof(eos->name), "%s", eos_names[i]); return eos; } XLAL_PRINT_ERROR("Unrecognized EOS name %s...", name); XLALPrintError("\tKnown EOS names are: %s", eos_names[0]); for (i = 1; i < n; ++i) XLALPrintError(", %s", eos_names[i]); XLALPrintError("\n"); XLAL_ERROR_NULL(XLAL_ENAME); }
LALFrameUFrameH *XLALFrameUFrameHRead_FrameL_(LALFrameUFrFile * stream, int pos) { LALFrameUFrameH *frame; LALFrameUFrameH *copy; /* make sure the TOC is read */ if (stream->handle->toc == NULL) if (FrTOCReadFull(stream->handle) == NULL || stream->handle->error != FR_OK) XLAL_ERROR_NULL(XLAL_EIO, "FrTOCReadFull failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error)); /* go to the right position */ if (FrFileIOSet(stream->handle, stream->handle->toc->positionH[pos]) == -1) XLAL_ERROR_NULL(XLAL_EIO, "FrFileIOSet failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error)); /* get the frame */ frame = FrameRead(stream->handle); if (!frame || stream->handle->error != FR_OK) XLAL_ERROR_NULL(XLAL_EIO, "FrameRead failed with error code %s.", XLALFrameLErrorMessage(stream->handle->error)); copy = FrameHCopy(frame); FrSetIni(stream->handle); stream->handle->curFrame = NULL; FrameFree(frame); return copy; }
/** * Divide a GPS time by a number. Computes gps / x and places the result * in gps. Returns gps on success, NULL on failure. */ LIGOTimeGPS *XLALGPSDivide( LIGOTimeGPS *gps, REAL8 x ) { LIGOTimeGPS quotient; double residual; if(isnan(x)) { XLALPrintError("%s(): NaN", __func__); XLAL_ERROR_NULL(XLAL_EFPINVAL); } if(x == 0) { XLALPrintError("%s(): divide by zero", __func__); XLAL_ERROR_NULL(XLAL_EFPDIV0); } /* initial guess */ if(!XLALGPSSetREAL8("ient, XLALGPSGetREAL8(gps) / x)) XLAL_ERROR_NULL(XLAL_EFUNC); /* use Newton's method to iteratively solve for quotient. strictly * speaking we're using Newton's method to solve for the inverse of * XLALGPSMultiply(), which we assume implements multiplication. */ do { LIGOTimeGPS workspace = quotient; if(!XLALGPSMultiply(&workspace, x)) XLAL_ERROR_NULL(XLAL_EFUNC); residual = XLALGPSDiff(gps, &workspace) / x; if(!XLALGPSAdd("ient, residual)) XLAL_ERROR_NULL(XLAL_EFUNC); } while(fabs(residual) > 0.5e-9); *gps = quotient; return gps; }
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; }
EphemerisData *InitEphemeris (const CHAR *ephemType, const CHAR *ephemDir){ const CHAR *fn = __func__; #define FNAME_LENGTH 1024 CHAR EphemEarth[FNAME_LENGTH]; /* filename of earth-ephemeris data */ CHAR EphemSun[FNAME_LENGTH]; /* filename of sun-ephemeris data */ /* check input consistency */ if ( !ephemType ) { XLALPrintError ("%s: invalid NULL input for 'ephemType'\n", fn ); XLAL_ERROR_NULL ( XLAL_EINVAL ); } snprintf(EphemEarth, FNAME_LENGTH, "%s/earth00-19-%s.dat.gz", ephemDir, ephemType); snprintf(EphemSun, FNAME_LENGTH, "%s/sun00-19-%s.dat.gz", ephemDir, ephemType); EphemEarth[FNAME_LENGTH-1]=0; EphemSun[FNAME_LENGTH-1]=0; EphemerisData *edat; if ( (edat = XLALInitBarycenter ( EphemEarth, EphemSun)) == NULL ) { XLALPrintError ("%s: XLALInitBarycenter() failed.\n", fn ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } /* return ephemeris */ return edat; } /* InitEphemeris() */
/** * Function for interpolating PSD to a given sample rate */ REAL8FrequencySeries * XLALInterpolatePSD( REAL8FrequencySeries *in, /**< input strain time series */ REAL8 deltaFout /**< sample rate of time series */) { REAL8FrequencySeries *ret=NULL; REAL8 deltaFin, r, y_1, y_2; UINT4 k, lo, numPoints; deltaFin = in->deltaF; /* length of output vector */ numPoints = (UINT4) (in->data->length * deltaFin / deltaFout); /* allocate memory */ ret = LALCalloc(1, sizeof(*ret)); if (!ret) { XLAL_ERROR_NULL( XLAL_ENOMEM ); } ret->data = XLALCreateREAL8Vector( numPoints ); if (! ret->data) { XLAL_ERROR_NULL( XLAL_ENOMEM ); } ret->deltaF = deltaFout; /* copy values from in which should be the same */ ret->epoch = in->epoch; ret->f0 = in->f0; ret->sampleUnits = in->sampleUnits; strcpy(ret->name, in->name); /* go over points of output vector and interpolate linearly using closest points of input */ for (k = 0; k < numPoints; k++) { lo = (UINT4)( k*deltaFout / deltaFin); /* y_1 and y_2 are the input values at x1 and x2 */ /* here we need to make sure that we don't exceed bounds of input vector */ if ( lo < in->data->length - 1) { y_1 = in->data->data[lo]; y_2 = in->data->data[lo+1]; /* we want to calculate y_2*r + y_1*(1-r) where r = (x-x1)/(x2-x1) */ r = k*deltaFout / deltaFin - lo; ret->data->data[k] = y_2 * r + y_1 * (1 - r); } else { ret->data->data[k] = 0.0; } } return ret; }
COMPLEX16TimeSeries *XLALFrStreamInputCOMPLEX16TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit) { COMPLEX16TimeSeries *series; LALTYPECODE typecode; if (XLALFrStreamSeek(stream, start)) XLAL_ERROR_NULL(XLAL_EFUNC); typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos); switch (typecode) { case LAL_I2_TYPE_CODE: INPUTTS(series, COMPLEX16, INT2, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_I4_TYPE_CODE: INPUTTS(series, COMPLEX16, INT4, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_I8_TYPE_CODE: INPUTTS(series, COMPLEX16, INT8, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_U2_TYPE_CODE: INPUTTS(series, COMPLEX16, UINT2, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_U4_TYPE_CODE: INPUTTS(series, COMPLEX16, UINT4, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_U8_TYPE_CODE: INPUTTS(series, COMPLEX16, UINT8, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_S_TYPE_CODE: INPUTTS(series, COMPLEX16, REAL4, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_D_TYPE_CODE: INPUTTS(series, COMPLEX16, REAL8, S2S, stream, chname, start, duration, lengthlimit); break; case LAL_C_TYPE_CODE: INPUTTS(series, COMPLEX16, COMPLEX8, S2S, stream, chname, start, duration, lengthlimit); case LAL_Z_TYPE_CODE: series = XLALFrStreamReadCOMPLEX16TimeSeries(stream, chname, start, duration, lengthlimit); if (!series) XLAL_ERROR_NULL(XLAL_EFUNC); default: XLAL_ERROR_NULL(XLAL_ETYPE); } return series; }
/** * Turn pulsar doppler-params into a single string that can be used for filenames * The format is * tRefNNNNNN_RAXXXXX_DECXXXXXX_FreqXXXXX[_f1dotXXXXX][_f2dotXXXXx][_f3dotXXXXX] */ CHAR* XLALPulsarDopplerParams2String ( const PulsarDopplerParams *par ) { #define MAXLEN 1024 CHAR buf[MAXLEN]; CHAR *ret = NULL; int len; UINT4 i; if ( !par ) { LogPrintf(LOG_CRITICAL, "%s: NULL params input.\n", __func__ ); XLAL_ERROR_NULL( XLAL_EDOM); } len = snprintf ( buf, MAXLEN, "tRef%09d_RA%.9g_DEC%.9g_Freq%.15g", par->refTime.gpsSeconds, par->Alpha, par->Delta, par->fkdot[0] ); if ( len >= MAXLEN ) { LogPrintf(LOG_CRITICAL, "%s: filename-size (%d) exceeded maximal length (%d): '%s'!\n", __func__, len, MAXLEN, buf ); XLAL_ERROR_NULL( XLAL_EDOM); } for ( i = 1; i < PULSAR_MAX_SPINS; i++) { if ( par->fkdot[i] ) { CHAR buf1[MAXLEN]; len = snprintf ( buf1, MAXLEN, "%s_f%ddot%.7g", buf, i, par->fkdot[i] ); if ( len >= MAXLEN ) { LogPrintf(LOG_CRITICAL, "%s: filename-size (%d) exceeded maximal length (%d): '%s'!\n", __func__, len, MAXLEN, buf1 ); XLAL_ERROR_NULL( XLAL_EDOM); } strcpy ( buf, buf1 ); } } if ( par->asini > 0 ) { LogPrintf(LOG_NORMAL, "%s: orbital params not supported in Doppler-filenames yet\n", __func__ ); } len = strlen(buf) + 1; if ( (ret = LALMalloc ( len )) == NULL ) { LogPrintf(LOG_CRITICAL, "%s: failed to LALMalloc(%d)!\n", __func__, len ); XLAL_ERROR_NULL( XLAL_ENOMEM); } strcpy ( ret, buf ); return ret; } /* PulsarDopplerParams2String() */
/** * Multiply a GPS time by a number. Computes gps * x and places the result * in gps. Returns gps on success, NULL on failure. */ LIGOTimeGPS *XLALGPSMultiply( LIGOTimeGPS *gps, REAL8 x ) { LIGOTimeGPS workspace = *gps; double slo, shi; double xlo, xhi; double addendlo[4], addendhi[4]; if(isnan(x) || isinf(x)) { XLALPrintError("%s(): invalid multiplicand %g", __func__, x); XLAL_ERROR_NULL(XLAL_EFPINVAL); } /* ensure the seconds and nanoseconds components have the same sign so * that the addend fragments we compute below all have the same sign */ if(workspace.gpsSeconds < 0 && workspace.gpsNanoSeconds > 0) { workspace.gpsSeconds += 1; workspace.gpsNanoSeconds -= 1000000000; } else if(workspace.gpsSeconds > 0 && workspace.gpsNanoSeconds < 0) { workspace.gpsSeconds -= 1; workspace.gpsNanoSeconds += 1000000000; } /* split seconds and multiplicand x into leading-order and low-order * components */ slo = workspace.gpsSeconds % (1<<16); shi = workspace.gpsSeconds - slo; split_double(x, &xhi, &xlo); /* the count of seconds and the multiplicand x have each been split into * two parts, a high part and a low part. from these, there are 4 terms * in their product, and each term has sufficiently low dynamic range * that it can be computed using double precision floating point * arithmetic. we compute the 4 terms, split each into an integer and * fractional part on its own, then sum the fractional parts and integer * parts separately, adding the product of the nanoseconds and x into the * fractional parts when summing them. because the storage locations for * those sums have relatively low dynamic range no care need be taken in * computing the sums. */ addendlo[0] = modf(slo * xlo, &addendhi[0]); addendlo[1] = modf(shi * xlo, &addendhi[1]); addendlo[2] = modf(slo * xhi, &addendhi[2]); addendlo[3] = modf(shi * xhi, &addendhi[3]); /* initialize result with the sum of components that contribute to the * fractional part */ if(!XLALGPSSetREAL8(gps, addendlo[0] + addendlo[1] + addendlo[2] + addendlo[3] + workspace.gpsNanoSeconds * x / XLAL_BILLION_REAL8)) XLAL_ERROR_NULL(XLAL_EFUNC); /* now add the components that contribute only to the integer seconds * part */ if(!XLALGPSSetREAL8(&workspace, addendhi[0] + addendhi[1] + addendhi[2] + addendhi[3])) XLAL_ERROR_NULL(XLAL_EFUNC); return XLALGPSAddGPS(gps, &workspace); }
/** UNDOCUMENTED */ LALUnit * XLALUnitDivide( LALUnit *output, const LALUnit *unit1, const LALUnit *unit2 ) { LALUnit scratch; /* invert unit2 and then multiply by unit1 */ if ( ! XLALUnitInvert( &scratch, unit2 ) ) XLAL_ERROR_NULL( XLAL_EFUNC ); if ( ! XLALUnitMultiply( output, unit1, &scratch ) ) XLAL_ERROR_NULL( XLAL_EFUNC ); return output; }
/* WARNING: returns pointer to memory that is lost when frame is freed */ const char *XLALFrameUFrChanVectorQueryUnitX_FrameL_(const LALFrameUFrChan * channel, size_t dim) { FrVect *vect; vect = XLALFrameUFrChanVectorPtr(channel); if (!vect) XLAL_ERROR_NULL(XLAL_EFUNC); if (dim >= vect->nDim) XLAL_ERROR_NULL(XLAL_EINVAL, "dim = %zu out of range", dim); return vect->unitX[dim]; }
/** * Driver routine to compute the -2 spin-weighted spherical harmonic mode * using TaylorT4 phasing. */ COMPLEX16TimeSeries *XLALSimInspiralTaylorT4PNMode( REAL8 phiRef, /**< reference orbital phase (rad) */ REAL8 v0, /**< tail-term gauge choice (default = 1) */ REAL8 deltaT, /**< sampling interval (s) */ REAL8 m1, /**< mass of companion 1 (kg) */ REAL8 m2, /**< mass of companion 2 (kg) */ REAL8 f_min, /**< starting GW frequency (Hz) */ REAL8 fRef, /**< reference GW frequency (Hz) */ REAL8 r, /**< distance of source (m) */ REAL8 lambda1, /**< (tidal deformability of body 1)/(mass of body 1)^5 */ REAL8 lambda2, /**< (tidal deformability of body 2)/(mass of body 2)^5 */ LALSimInspiralTidalOrder tideO, /**< flag to control spin and tidal effects */ int amplitudeO, /**< twice post-Newtonian amplitude order */ int phaseO, /**< twice post-Newtonian phase order */ int l, /**< l index of mode */ int m /**< m index of mode */ ) { COMPLEX16TimeSeries *hlm; /* The Schwarzschild ISCO frequency - for sanity checking fRef */ REAL8 fISCO = pow(LAL_C_SI,3) / (pow(6.,3./2.)*LAL_PI*(m1+m2)*LAL_G_SI); /* Sanity check fRef value */ if( fRef < 0. ) { XLALPrintError("XLAL Error - %s: fRef = %f must be >= 0\n", __func__, fRef); XLAL_ERROR_NULL(XLAL_EINVAL); } if( fRef != 0. && fRef < f_min ) { XLALPrintError("XLAL Error - %s: fRef = %f must be > fStart = %f\n", __func__, fRef, f_min); XLAL_ERROR_NULL(XLAL_EINVAL); } if( fRef >= fISCO ) { XLALPrintError("XLAL Error - %s: fRef = %f must be < Schwar. ISCO=%f\n", __func__, fRef, fISCO); XLAL_ERROR_NULL(XLAL_EINVAL); } REAL8TimeSeries *V; REAL8TimeSeries *phi; int n; n = XLALSimInspiralTaylorT4PNEvolveOrbit(&V, &phi, phiRef, deltaT, m1, m2, f_min, fRef, lambda1, lambda2, tideO, phaseO); if ( n < 0 ) XLAL_ERROR_NULL(XLAL_EFUNC); hlm = XLALCreateSimInspiralPNModeCOMPLEX16TimeSeries(V, phi, v0, m1, m2, r, amplitudeO, l, m); XLALDestroyREAL8TimeSeries(phi); XLALDestroyREAL8TimeSeries(V); return hlm; }
static FrSimData *XLALFrSimDataCopy(const FrSimData * original) { FrSimData *copy; copy = calloc(1, sizeof(*copy)); if (!copy) XLAL_ERROR_NULL(XLAL_ENOMEM); memcpy(copy, original, sizeof(*copy)); /* in case of failure, set to zero/null the things we need * to allocate separately */ copy->name = NULL; copy->comment = NULL; copy->data = NULL; copy->input = NULL; copy->table = NULL; copy->next = NULL; if (original->name) { copy->name = strdup(original->name); if (!copy->name) goto failure; } if (original->comment) { copy->comment = strdup(original->comment); if (!copy->comment) goto failure; } if (original->data) { copy->data = FrVectCopy(original->data); if (!copy->data) goto failure; } if (original->input) { copy->input = FrVectCopy(original->input); if (!copy->input) goto failure; } if (original->table) { copy->table = FrTableCopy(original->table); if (!copy->table) goto failure; } if (original->next) { copy->next = XLALFrSimDataCopy(original->next); if (!copy->next) goto failure; } /* successful return */ return copy; failure: /* unsuccessful return */ FrSimDataFree(copy); XLAL_ERROR_NULL(XLAL_ENOMEM); }
/** * 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() */
/* stripped-down copy of FrSimDataNew */ static FrSimData *XLALFrameUFrSimDataNew(const char *name) { FrSimData *simData; simData = calloc(1, sizeof(*simData)); if (!simData) XLAL_ERROR_NULL(XLAL_ENOMEM); simData->classe = FrSimDataDef(); simData->name = strdup(name); if (!simData->name) { FrSimDataFree(simData); XLAL_ERROR_NULL(XLAL_ENOMEM); } return simData; }
/* stripped-down copy of FrProcDataNew */ static FrProcData *XLALFrameUFrProcDataNew(const char *name) { FrProcData *procData; procData = calloc(1, sizeof(*procData)); if (!procData) XLAL_ERROR_NULL(XLAL_ENOMEM); procData->classe = FrProcDataDef(); procData->name = strdup(name); if (!procData->name) { FrProcDataFree(procData); XLAL_ERROR_NULL(XLAL_ENOMEM); } return procData; }
VTYPE *READFUNC(LALH5File *file, const char *dset) { VTYPE *vector; LALH5Dataset *dataset; if (!file || !dset) XLAL_ERROR_NULL(XLAL_EFAULT); dataset = XLALH5DatasetRead(file, dset); if (!dataset) XLAL_ERROR_NULL(XLAL_EFUNC); vector = DSETREADFUNC(dataset); XLALH5DatasetFree(dataset); if (!vector) XLAL_ERROR_NULL(XLAL_EFUNC); return vector; }
STYPE *STREAMREADSERIES(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch) { STYPE *series; /* seek to the relevant point in the stream */ if (XLALFrStreamSeek(stream, epoch)) XLAL_ERROR_NULL(XLAL_EFUNC); series = READSERIES(stream->file, chname, stream->pos); if (!series) XLAL_ERROR_NULL(XLAL_EFUNC); return series; }
ATYPE *READFUNC(LALH5File *file, const char *dset) { ATYPE *array; LALH5Dataset *dataset; if (!file || !dset) XLAL_ERROR_NULL(XLAL_EFAULT); dataset = XLALH5DatasetRead(file, dset); if (!dataset) XLAL_ERROR_NULL(XLAL_EFUNC); array = DSETREADFUNC(dataset); XLALH5DatasetFree(dataset); if (!array) XLAL_ERROR_NULL(XLAL_EFUNC); return array; }
/** * Sets GPS time given GPS seconds as a REAL8. Returns epoch on success, * NULL on error. */ LIGOTimeGPS * XLALGPSSetREAL8( LIGOTimeGPS *epoch, REAL8 t ) { INT4 gpssec = floor(t); INT4 gpsnan = nearbyint((t - gpssec) * XLAL_BILLION_REAL8); if(isnan(t)) { XLALPrintError("%s(): NaN", __func__); XLAL_ERROR_NULL(XLAL_EFPINVAL); } if(fabs(t) > 0x7fffffff) { XLALPrintError("%s(): overflow %.17g", __func__, t); XLAL_ERROR_NULL(XLAL_EDOM); } /* use XLALGPSSet() to normalize the nanoseconds */ return XLALGPSSet(epoch, gpssec, gpsnan); }
/** * @brief Opens a LALFrStream associated with a LALCache * @details * This routine creates a #LALFrStream that is a stream associated with * the frame files contained in a LALCache. * @param cache Pointer to a LALCache structure describing the frame files to stream. * @returns Pointer to a newly created #LALFrStream structure. * @retval NULL Failure. */ LALFrStream *XLALFrStreamCacheOpen(LALCache * cache) { LALFrStream *stream; size_t i; if (!cache) XLAL_ERROR_NULL(XLAL_EFAULT); stream = LALCalloc(1, sizeof(*stream)); if (!stream) XLAL_ERROR_NULL(XLAL_ENOMEM); stream->cache = XLALCacheDuplicate(cache); /* check cache entries for t0 and dt; if these are not set then read * the framefile to try to get them */ for (i = 0; i < stream->cache->length; ++i) { if (stream->cache->list[i].t0 == 0 || stream->cache->list[i].dt == 0) { LIGOTimeGPS end; size_t nFrame; if (XLALFrStreamFileOpen(stream, i) < 0) { XLALFrStreamClose(stream); XLAL_ERROR_NULL(XLAL_EIO); } nFrame = XLALFrFileQueryNFrame(stream->file); stream->cache->list[i].t0 = stream->epoch.gpsSeconds; XLALFrFileQueryGTime(&end, stream->file, nFrame - 1); XLALGPSAdd(&end, XLALFrFileQueryDt(stream->file, nFrame - 1)); stream->cache->list[i].dt = ceil(XLALGPSGetREAL8(&end)) - stream->cache->list[i].t0; XLALFrStreamFileClose(stream); } } /* sort and uniqify the cache */ if (XLALCacheSort(stream->cache) || XLALCacheUniq(stream->cache)) { XLALFrStreamClose(stream); XLAL_ERROR_NULL(XLAL_EFUNC); } stream->mode = LAL_FR_STREAM_DEFAULT_MODE; /* open up the first file */ if (XLALFrStreamFileOpen(stream, 0) < 0) { XLALFrStreamClose(stream); XLAL_ERROR_NULL(XLAL_EFUNC); } return stream; }