Exemplo n.º 1
0
/**
 * \brief Counts the number of comma separated values in a string
 *
 * This function counts the number of comma separated values in a given input string.
 *
 * \param csvline [in] Any string
 *
 * \return The number of comma separated value in the input string
 */
INT4 count_csv( CHAR *csvline ){
  CHAR *inputstr = NULL;
  INT4 count = 0;

  inputstr = XLALStringDuplicate( csvline );

  /* count number of commas */
  while(1){
    if( XLALStringToken(&inputstr, ",", 0) == NULL ){ XLAL_ERROR( XLAL_EFUNC, "Error... problem counting number of commas!" ); }

    if ( inputstr == NULL ) { break; }

    count++;
  }

  return count+1;
}
Exemplo n.º 2
0
/* sets params to default values and parses the command line arguments */
struct params parseargs(int argc, char **argv)
{
    int degrees = 1;
    int phaseO;
    char *inclination_string = NULL;
    char *phiRef_string = NULL;
    char *meanPerAno_string = NULL;
    char *longAscNodes_string = NULL;
    char *kv;
    struct params p = {
        .verbose = 0,
        .approx = XLALSimInspiralGetApproximantFromString(DEFAULT_APPROX),
        .condition = 0,
        .freq_dom = 0,
        .amp_phase = 0,
        .domain = DEFAULT_DOMAIN,
        .phiRef = DEFAULT_PHIREF * LAL_PI_180,
        .meanPerAno = DEFAULT_MEANPERANO * LAL_PI_180,
        .longAscNodes = DEFAULT_LONGASCNODE * LAL_PI_180,
        .eccentricity = DEFAULT_ECCENTRICITY,
        .fRef = DEFAULT_FREF,
        .srate = DEFAULT_SRATE,
        .m1 = DEFAULT_M1 * LAL_MSUN_SI,
        .m2 = DEFAULT_M2 * LAL_MSUN_SI,
        .f_min = DEFAULT_F_MIN,
        .distance = DEFAULT_DISTANCE * 1e6 * LAL_PC_SI,
        .inclination = DEFAULT_INCLINATION * LAL_PI_180,
        .s1x = DEFAULT_S1X,
        .s1y = DEFAULT_S1Y,
        .s1z = DEFAULT_S1Z,
        .s2x = DEFAULT_S2X,
        .s2y = DEFAULT_S2Y,
        .s2z = DEFAULT_S2Z,
        .params = NULL
    };
    struct LALoption long_options[] = {
        {"help", no_argument, 0, 'h'},
        {"verbose", no_argument, 0, 'v'},
        {"radians", no_argument, 0, 'C'},
        {"frequency-domain", no_argument, 0, 'F'},
        {"condition-waveform", no_argument, 0, 'c'},
        {"amp-phase", no_argument, 0, 'P'},
        {"approximant", required_argument, 0, 'a'},
        {"waveform", required_argument, 0, 'w'},
        {"domain", required_argument, 0, 'D'},
        {"phase-order", required_argument, 0, 'O'},
        {"amp-order", required_argument, 0, 'o'},
        {"phiRef", required_argument, 0, 'u'},
        {"periastron-anomaly", required_argument, 0, 'U'},
        {"longitude-ascending-node", required_argument, 0, 'W'},
        {"eccentricity", required_argument, 0, 'e'},
        {"fRef", required_argument, 0, 'r'},
        {"sample-rate", required_argument, 0, 'R'},
        {"m1", required_argument, 0, 'M'},
        {"m2", required_argument, 0, 'm'},
        {"spin1x", required_argument, 0, 'X'},
        {"spin1y", required_argument, 0, 'Y'},
        {"spin1z", required_argument, 0, 'Z'},
        {"spin2x", required_argument, 0, 'x'},
        {"spin2y", required_argument, 0, 'y'},
        {"spin2z", required_argument, 0, 'z'},
        {"tidal-lambda1", required_argument, 0, 'L'},
        {"tidal-lambda2", required_argument, 0, 'l'},
        {"delta-quad-mon1", required_argument, 0, 'q'},
        {"delta-quad-mon2", required_argument, 0, 'Q'},
        {"spin-order", required_argument, 0, 's'},
        {"tidal-order", required_argument, 0, 't'},
        {"f-min", required_argument, 0, 'f'},
        {"f-max", required_argument, 0, 'F'},
        {"distance", required_argument, 0, 'd'},
        {"inclination", required_argument, 0, 'i'},
        {"axis", required_argument, 0, 'A'},
        {"modes", required_argument, 0, 'n'},
        {"params", required_argument, 0, 'p'},
        {0, 0, 0, 0}
    };
    char args[] = "hvCFcPa:w:D:O:o:u:U:W:e:r:R:M:m:X:x:Y:y:Z:z:L:l:q:Q:s:t:f:d:i:A:n:p:";

    while (1) {
        int option_index = 0;
        int c;

        c = LALgetopt_long_only(argc, argv, args, long_options, &option_index);
        if (c == -1)    /* end of options */
            break;

        switch (c) {
        case 0:        /* if option set a flag, nothing else to do */
            if (long_options[option_index].flag)
                break;
            else {
                fprintf(stderr, "error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg);
                exit(1);
            }
        case 'h':      /* help */
            usage(argv[0]);
            exit(0);
        case 'v':      /* verbose */
            p.verbose = 1;
            break;
        case 'C':      /* radians */
            degrees = 0;
            break;
        case 'F':      /* frequency-domain */
            p.freq_dom = 1;
            break;
        case 'c':      /* condition-waveform */
            p.condition = 1;
            break;
        case 'P':      /* amp-phase */
            p.amp_phase = 1;
            break;
        case 'a':      /* approximant */
            p.approx = XLALSimInspiralGetApproximantFromString(LALoptarg);
            if ((int)p.approx == XLAL_FAILURE) {
                fprintf(stderr, "error: invalid value %s for %s\n", LALoptarg, long_options[option_index].name);
                exit(1);
            }
            break;
        case 'w':      /* waveform */
            p.approx = XLALSimInspiralGetApproximantFromString(LALoptarg);
            if ((int)p.approx == XLAL_FAILURE) {
                fprintf(stderr, "error: could not parse approximant from %s for %s\n", LALoptarg, long_options[option_index].name);
                exit(1);
            }
            phaseO = XLALSimInspiralGetPNOrderFromString(LALoptarg);
            if ((int)phaseO == XLAL_FAILURE) {
                fprintf(stderr, "error: could not parse order from %s for %s\n", LALoptarg, long_options[option_index].name);
                exit(1);
            }
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertPNPhaseOrder(p.params, phaseO);
            break;
        case 'D':      /* domain */
            switch (*LALoptarg) {
            case 'T':
            case 't':
                p.domain = LAL_SIM_DOMAIN_TIME;
                break;
            case 'F':
            case 'f':
                p.domain = LAL_SIM_DOMAIN_FREQUENCY;
                break;
            default:
                fprintf(stderr, "error: invalid value %s for %s\n", LALoptarg, long_options[option_index].name);
                exit(1);
            }
        case 'O':      /* phase-order */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertPNPhaseOrder(p.params, atoi(LALoptarg));
            break;
        case 'o':      /* amp-order */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertPNAmplitudeOrder(p.params, atoi(LALoptarg));
            break;
        case 'u':      /* phiRef */
            phiRef_string = LALoptarg;
            break;
        case 'U':      /* mean-periastron-anomaly */
            meanPerAno_string = LALoptarg;
            break;
        case 'W':      /* longitude-ascending-node */
            longAscNodes_string = LALoptarg;
            break;
        case 'e':      /* eccentricity */
            p.eccentricity = atof(LALoptarg);
            break;
        case 'r':      /* fRef */
            p.fRef = atof(LALoptarg);
            break;
        case 'R':      /* sample-rate */
            p.srate = atof(LALoptarg);
            break;
        case 'M':      /* m1 */
            p.m1 = atof(LALoptarg) * LAL_MSUN_SI;
            break;
        case 'm':      /* m2 */
            p.m2 = atof(LALoptarg) * LAL_MSUN_SI;
            break;
        case 'X':      /* spin1x */
            p.s1x = atof(LALoptarg);
            break;
        case 'Y':      /* spin1y */
            p.s1y = atof(LALoptarg);
            break;
        case 'Z':      /* spin1z */
            p.s1z = atof(LALoptarg);
            break;
        case 'x':      /* spin2x */
            p.s2x = atof(LALoptarg);
            break;
        case 'y':      /* spin2y */
            p.s2y = atof(LALoptarg);
            break;
        case 'z':      /* spin2z */
            p.s2z = atof(LALoptarg);
            break;
        case 'L':      /* tidal-lambda1 */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertTidalLambda1(p.params, atoi(LALoptarg));
            break;
        case 'l':      /* tidal-lambda2 */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertTidalLambda2(p.params, atoi(LALoptarg));
            break;
        case 'q':      /* diff-quad-mon1 */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertdQuadMon1(p.params, atoi(LALoptarg));
            break;
        case 'Q':      /* diff-quad-mon2 */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertdQuadMon2(p.params, atoi(LALoptarg));
            break;
        case 's':      /* spin-order */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertPNSpinOrder(p.params, atoi(LALoptarg));
            break;
        case 't':      /* tidal-order */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertPNTidalOrder(p.params, atoi(LALoptarg));
            break;
        case 'f':      /* f-min */
            p.f_min = atof(LALoptarg);
            break;
        case 'd':      /* distance */
            p.distance = atof(LALoptarg) * 1e6 * LAL_PC_SI;
            break;
        case 'i':      /* inclination */
            inclination_string = LALoptarg;
            break;
        case 'A':      /* axis */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertFrameAxis(p.params, XLALSimInspiralGetFrameAxisFromString(LALoptarg));
            break;
        case 'n':      /* modes */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            XLALSimInspiralWaveformParamsInsertModesChoice(p.params, XLALSimInspiralGetHigherModesFromString(LALoptarg));
            break;
        case 'p':      /* params */
            if (p.params == NULL)
                p.params = XLALCreateDict();
            while ((kv = XLALStringToken(&LALoptarg, ",", 0))) {
                char *key = XLALStringToken(&kv, "=", 0);
                if (kv == NULL || key == NULL || *key == '\0') {
                    fprintf(stderr, "error: invalid key-value pair for %s\n", long_options[option_index].name);
                    exit(1);
                }
                XLALDictInsertREAL8Value(p.params, key, atof(kv));
            }
            break;
        case '?':
        default:
            fprintf(stderr, "unknown error while parsing options\n");
            exit(1);
        }
    }
    if (LALoptind < argc) {
        fprintf(stderr, "extraneous command line arguments:\n");
        while (LALoptind < argc)
            fprintf(stderr, "%s\n", argv[LALoptind++]);
        exit(1);
    }

    /* set angles, converting to degrees to radians if needed */
    if (phiRef_string) {
        p.phiRef = atof(phiRef_string);
        if (degrees)
            p.phiRef *= LAL_PI_180;
    }
    if (inclination_string) {
        p.inclination = atof(inclination_string);
        if (degrees)
            p.inclination *= LAL_PI_180;
    }
    if (meanPerAno_string) {
        p.meanPerAno = atof(meanPerAno_string);
        if (degrees)
            p.meanPerAno *= LAL_PI_180;
    }
    if (longAscNodes_string) {
        p.longAscNodes = atof(longAscNodes_string);
        if (degrees)
            p.longAscNodes *= LAL_PI_180;
    }

    return p;
}