static ProcessParamsTable *addCommandLineOption(ProcessParamsTable *ppt, char *oName, char *oValue) {
  ProcessParamsTable *current = NULL;

  current = calloc(1, sizeof(ProcessParamsTable));

  XLALStringCopy(current->program, "OCamlLALInference", LIGOMETA_PROGRAM_MAX);
  XLALStringCopy(current->param, oName, LIGOMETA_PARAM_MAX);
  XLALStringCopy(current->type, "string", LIGOMETA_TYPE_MAX);
  if (oValue != NULL) {
    XLALStringCopy(current->value, oValue, LIGOMETA_VALUE_MAX);
  }
  current->next = ppt;

  return current;
}
/**
 * Set the numreldata string within a LALSimInspiralWaveformFlags struct
 */
void XLALSimInspiralSetNumrelData(
    LALSimInspiralWaveformFlags *waveFlags, /**< Struct whose value will be set */
    const char* numreldata /**< value to set numreldata to */
)
{
    XLALStringCopy(waveFlags->numreldata, numreldata, sizeof(waveFlags->numreldata));
    return;
}
/**
 * Returns a deepcopy of the pointer of the numeraldata attribute of the
 * waveFlags structure. If this is NULL then NULL will be returned.
 * The returned value is independent of the waveFlags structure and will
 * need to be LALFree-d.
 */
char* XLALSimInspiralGetNumrelData(
    LALSimInspiralWaveformFlags *waveFlags
)
{
    char *ret_string;
    if ( waveFlags )
    {
        ret_string = XLALMalloc(FILENAME_MAX * sizeof(char));
        XLALStringCopy(ret_string, waveFlags->numreldata, sizeof(waveFlags->numreldata));
        return ret_string;
    }
    else
    {
        return NULL;
    }
}
Example #4
0
/*
 * TestStatus ()
 *
 * Routine to check that the status code status->statusCode agrees with one of
 * the codes specified in the space-delimited string ignored; if not,
 * exit to the system with code exitcode.
 *
 */
static void
TestStatus (LALStatus *status, const char *ignored, int exitcode)
{
  char  str[64];
  char *tok;

  if (verbose)
  {
    REPORTSTATUS (status);
  }

  if (XLALStringCopy(str, ignored, sizeof(str)))
  {
    if ((tok = strtok (str, " ")))
    {
      do
      {
        if (status->statusCode == atoi (tok))
        {
          return;
        }
      }
      while ((tok = strtok (NULL, " ")));
    }
    else
    {
      if (status->statusCode == atoi (tok))
      {
        return;
      }
    }
  }

  fprintf (stderr, "\nExiting to system with code %d\n", exitcode);
  exit (exitcode);
}
Example #5
0
/**
 * \brief Automatically set the solar system ephemeris file based on environment variables and data time span
 *
 * This function will attempt to find Earth and Sun ephemeris files based on LAL environment variables (as set up by
 * <code> lalpulsar-user-env.(c)sh </code>) and a given start and end GPS time (presumably taken from the data that is
 * to be analysed). It requires \c LALPULSAR is installed and the \c LALPULSAR_PREFIX variable is set, which should mean
 * that ephemeris files are installed in the directory \c ${LALPULSAR_PREFIX}/share/lalpulsar/.
 *
 * \param efile [in] a string that will return the Earth ephemeris file
 * \param sfile [in] a string that will return the Sun ephemeris file
 * \param tfile [in] a string that will return the time correction file
 * \param pulsar [in] the pulsar parameters read from a .par file
 * \param gpsstart [in] the GPS time of the start of the data
 * \param gpsend [in] the GPS time of the end of the data
 *
 * \return The TimeCorrectionType e.g. TDB or TCB
 */
TimeCorrectionType XLALAutoSetEphemerisFiles( CHAR *efile, CHAR *sfile, CHAR *tfile, BinaryPulsarParams  pulsar,
                                              INT4 gpsstart, INT4 gpsend ){
  /* set the times that the ephemeris files span */
  INT4 ephemstart = 630720013; /* GPS time of Jan 1, 2000, 00:00:00 UTC */
  INT4 ephemend = 1261872015; /* GPS time of Jan 1, 2020, 00:00:00 UTC */
  CHAR *eftmp = NULL, *sftmp = NULL, *tftmp = NULL;
  TimeCorrectionType ttype = TIMECORRECTION_NONE;

  CHAR *lalpath = NULL, *lalpulsarpath = NULL;

  if( gpsstart < ephemstart || gpsend < ephemstart || gpsstart > ephemend || gpsend > ephemend ){
    XLALPrintError("Start and end times are outside the ephemeris file ranges!\n");
    XLAL_ERROR(XLAL_EFUNC);
  }

  /* first check that the path to the Ephemeris files is available in the
     environment variables */
  if((lalpath = getenv("LALPULSAR_PREFIX")) == NULL){
    XLALPrintError("LALPULSAR_PREFIX environment variable not set. Cannot automatically generate ephemeris files!\n");
    XLAL_ERROR(XLAL_EFUNC);
  }

  lalpulsarpath = XLALStringDuplicate( lalpath );

  if ( (lalpulsarpath = XLALStringAppend(lalpulsarpath, "/share/lalpulsar/")) == NULL ) { XLAL_ERROR(XLAL_EFUNC); }

  eftmp = XLALStringDuplicate(lalpulsarpath);
  sftmp = XLALStringDuplicate(lalpulsarpath);
  tftmp = XLALStringDuplicate(lalpulsarpath);

  eftmp = XLALStringAppend(eftmp, "earth00-19-");
  sftmp = XLALStringAppend(sftmp, "sun00-19-");

  if( pulsar.ephem == NULL ){
    /* default to use DE405 */
    eftmp = XLALStringAppend(eftmp, "DE405");
    sftmp = XLALStringAppend(sftmp, "DE405");
  }
  else{
    if( !strcmp(pulsar.ephem, "DE405") || !strcmp(pulsar.ephem, "DE200") ||
        !strcmp(pulsar.ephem, "DE414") ){
      eftmp = XLALStringAppend(eftmp, pulsar.ephem);
      sftmp = XLALStringAppend(sftmp, pulsar.ephem);
    }
    else{
      XLALPrintError("Unknown ephemeris %s in par file\n", pulsar.ephem);
      XLAL_ERROR(XLAL_EFUNC);
    }
  }

  /* add .dat extension */
  eftmp = XLALStringAppend(eftmp, ".dat.gz");
  sftmp = XLALStringAppend(sftmp, ".dat.gz");

  if ( eftmp == NULL || sftmp == NULL ) { XLAL_ERROR(XLAL_EFUNC); }

  XLALStringCopy( efile, eftmp, strlen(eftmp)+1 );
  XLALStringCopy( sfile, sftmp, strlen(sftmp)+1 );

  /* double check that the files exist */
  if( fopen(sfile, "r") == NULL || fopen(efile, "r") == NULL ){
    XLALPrintError("Error... ephemeris files not, or incorrectly, defined!\n");
    XLAL_ERROR(XLAL_EFUNC);
  }

  if( pulsar.units == NULL ){
    /* default to using TCB units */
    tftmp = XLALStringAppend(tftmp, "te405_2000-2019.dat.gz");
    ttype = TIMECORRECTION_TCB;
  }
  else{
    if ( !strcmp( pulsar.units, "TDB" ) ){
      tftmp = XLALStringAppend(tftmp, "tdb_2000-2019.dat.gz");
      ttype = TIMECORRECTION_TDB;
    }
    else{
      XLALPrintError("Error... unknown units %s in par file!\n", pulsar.units);
      XLAL_ERROR(XLAL_EFUNC);
    }
  }

  if ( tftmp == NULL ) { XLAL_ERROR(XLAL_EFUNC); }

  XLALStringCopy( tfile, tftmp, strlen(tftmp)+1 );

  if( fopen(tfile, "r") == NULL ){
    XLALPrintError("Error... time ephemeris files not, or incorrectly, defined!\n");
    XLAL_ERROR(XLAL_EFUNC);
  }

  return ttype;
}
int XLALCalRefFileNameDescriptionParse( LALCalRefFileNameDescriptionFields *fields, const char *description )
{
  char dsc[FILENAME_MAX];
  char *dsc_channel_start;
  char *dsc_version_start;
  char *dsc_run_start;
  char *dsc_ifo_start;
  int c;

  if ( ! fields || ! description )
    XLAL_ERROR( XLAL_EFAULT );
  if ( strlen( description ) > FILENAME_MAX )
  {
    XLALPrintError( "XLAL Error - %s: Description string %s too long\n", __func__, description );
    XLAL_ERROR( XLAL_EBADLEN );
  }

  XLALStringCopy( dsc, description, sizeof( dsc ) );
  dsc_ifo_start = dsc;

  /* find start of channel string */
  dsc_channel_start = strchr( dsc, '_' );
  if ( ! dsc_channel_start )
  {
    XLALPrintError( "XLAL Error - %s: Could not parse description field %s\n\tinto <ifo>_CAL_REF_<channelpostfix>_<run>_<version> format\n", __func__, description );
    XLAL_ERROR( XLAL_EINVAL );
  }
  *dsc_channel_start++ = 0;
  /* now skip the CAL_REF_ */
  if ( dsc_channel_start != strstr( dsc_channel_start, "CAL_REF_" ) )
  {
    XLALPrintError( "XLAL Error - %s: Could not parse description field %s\n\tinto <ifo>_CAL_REF_<channelpostfix>_<run>_<version> format\n", __func__, description );
    XLAL_ERROR( XLAL_EINVAL );
  }
  dsc_channel_start += strlen( "CAL_REF" );
  *dsc_channel_start++ = 0;

  /* find start of version string */
  dsc_version_start = strrchr( dsc_channel_start, '_' );
  if ( ! dsc_version_start )
  {
    XLALPrintError( "XLAL Error - %s: Could not parse description field %s\n\tinto <ifo>_CAL_REF_<channelpostfix>_<run>_<version> format\n", __func__, description );
    XLAL_ERROR( XLAL_EINVAL );
  }
  *dsc_version_start++ = 0;

  /* find start of run string */
  dsc_run_start = strrchr( dsc_channel_start, '_' );
  if ( ! dsc_run_start )
  {
    XLALPrintError( "XLAL Error - %s: Could not parse description field %s\n\tinto <ifo>_CAL_REF_<channelpostfix>_<run>_<version> format\n", __func__, description );
    XLAL_ERROR( XLAL_EINVAL );
  }
  *dsc_run_start++ = 0;

  XLALStringCopy( fields->ifo, dsc_ifo_start, sizeof( fields->ifo ) );
  XLALStringCopy( fields->channelPostfix, dsc_channel_start, sizeof( fields->channelPostfix ) );
  XLALStringCopy( fields->run, dsc_run_start, sizeof( fields->run ) );
  c = sscanf( dsc_version_start, "V%d", &fields->version );
  if ( c != 1 )
  {
    if ( ! strcmp( dsc_version_start, "VU" ) )
      fields->version = -1; /* means unity */
    else
    {
      XLALPrintError( "XLAL Error - %s: Could not parse description field %s\n\tinto <ifo>_CAL_REF_<channelpostfix>_<run>_<version> format\n", __func__, description );
      XLAL_ERROR( XLAL_EINVAL );
    }
  }
  return 0;
}
int XLALASCIIFileReadCalRef( COMPLEX8FrequencySeries **series, REAL8 *duration, const char *fname )
{
  const REAL8 fuzzfactor = 1e-3; /* fraction of a sample of fuzziness */
  REAL8 fuzz; /* possible discrepancies in times */
  LALDataFileNameFields              fileFields;
  LALCalRefFileNameDescriptionFields descFields;
  REAL8VectorSequence *data;
  LIGOTimeGPS epoch;
  LALUnit unit;
  char channel[FILENAME_MAX];
  REAL4 deltaF;
  REAL8 fstart;
  REAL8 fend;
  REAL8 df;
  int ndat;
  int nrow;
  int row;

  if ( ! series )
    XLAL_ERROR( XLAL_EFAULT );
  if ( *series )
    XLAL_ERROR( XLAL_EINVAL );

  if ( XLALDataFileNameParse( &fileFields, fname ) < 0 )
  {
    XLALPrintError( "XLAL Error - %s: invalid file name %s\n", __func__, fname );
    XLAL_ERROR( XLAL_EINVAL );
  }
  *duration = fileFields.duration;

  if ( XLALCalRefFileNameDescriptionParse( &descFields, fileFields.description ) < 0 )
  {
    XLALPrintError( "XLAL Error - %s: invalid description part of file name %s\n", __func__, fname );
    XLAL_ERROR( XLAL_EINVAL );
  }

  XLALPrintInfo( "XLAL Info - %s: Reading calibration factors from file %s\n", __func__, fname );

  /* setup units */
  if ( strstr( descFields.channelPostfix, "RESPONSE" ) )
    XLALUnitDivide( &unit, &lalStrainUnit, &lalADCCountUnit );
  else if ( strstr( descFields.channelPostfix, "CAV_GAIN" ) )
    XLALUnitDivide( &unit, &lalADCCountUnit, &lalStrainUnit );
  else if ( strstr( descFields.channelPostfix, "OLOOP_GAIN" ) )
    unit = lalDimensionlessUnit;
  else if ( strstr( descFields.channelPostfix, "ACTUATION" ) )
    XLALUnitDivide( &unit, &lalADCCountUnit, &lalStrainUnit );
  else if ( strstr( descFields.channelPostfix, "DIGFLT" ) )
    unit = lalDimensionlessUnit;
  else
  {
    XLALPrintError( "XLAL Error - %s: invalid channel %s\n", __func__, descFields.channelPostfix );
    XLAL_ERROR( XLAL_EINVAL );
  }

  /* setup channel names */
  XLALStringCopy( channel, descFields.ifo, sizeof( channel ) );
  XLALStringConcatenate( channel, ":CAL-", sizeof( channel ) );
  XLALStringConcatenate( channel, descFields.channelPostfix, sizeof( channel ) );

  /* read header */
  deltaF = XLALASCIIFileReadCalRefHeader( fname );
  if ( XLAL_IS_REAL4_FAIL_NAN( deltaF ) )
    XLAL_ERROR( XLAL_EFUNC );

  if ( deltaF <= 0 ) /* bad time step */
    XLAL_ERROR( XLAL_EDATA );


  /* read three columns */
  data = XLALASCIIFileReadColumns( 3, fname );
  if ( ! data )
    XLAL_ERROR( XLAL_EFUNC );
  if ( ! data->length )
  {
    XLALPrintError( "XLAL Error - %s: no rows of data\n", __func__ );
    XLAL_ERROR( XLAL_EFAILED );
  }
  nrow = data->length;

  /* sanity checks on time stamps */
  fstart = ELEM(data,0,1);
  fend   = ELEM(data,nrow-1,1);
  ndat   = 1 + (int)floor( (fend - fstart)/deltaF + 0.5 );
  df     = (fend - fstart) / (ndat - 1);

  if ( nrow != ndat ) /* this should be impossible */
  {
    XLALDestroyREAL8VectorSequence( data );
    XLAL_ERROR( XLAL_EDATA );
  }

  XLALGPSSetREAL8( &epoch, fileFields.tstart );

  *series = XLALCreateCOMPLEX8FrequencySeries( channel, &epoch, fstart, df, &unit, ndat );
  if ( ! *series )
  {
    XLALDestroyREAL8VectorSequence( data );
    XLAL_ERROR( XLAL_EFUNC );
  }

  fuzz = fuzzfactor * deltaF;
  for ( row = 0; row < nrow; ++row )
  {
    int   line = ELEM(data,row,0);
    REAL8 freq = ELEM(data,row,1);
    REAL8 mod  = ELEM(data,row,2);
    REAL8 arg  = ELEM(data,row,3);
    REAL8 fexp = fstart + row * df;
    if ( fabs( freq - fexp ) / fexp > fuzz )
    {
      XLALPrintError( "XLAL Error - %s: error on line %d of file %s\n\tunexpected frequency\n", __func__, line, fname );
      XLALDestroyCOMPLEX8FrequencySeries( *series );
      XLALDestroyREAL8VectorSequence( data );
      XLAL_ERROR( XLAL_EDATA );
    }
    (*series)->data->data[row] = crectf( mod * cos( arg ), mod * sin( arg ) );
  }

  XLALDestroyREAL8VectorSequence( data );
  return 0;
}