예제 #1
0
int main( int argc, char *argv[] )
{
	LALFILE *outfile = NULL;
	LALCache *cache;
	int arg = 1;
	XLALSetErrorHandler( XLALExitErrorHandler );
	if ( argc > 1 && ! strcmp(argv[1],"-o") ) {
		outfile = XLALFileOpen( argv[2], "w" );
		arg += 2;
	}
	cache = XLALCacheGlob( NULL, argc == 1 ? NULL : argv[arg] );
	for ( ; arg < argc; ++arg ) {
		LALCache *tmp = cache;
		LALCache *add;
		add = XLALCacheGlob( NULL, argv[arg] );
		cache = XLALCacheMerge( tmp, add );
		XLALDestroyCache( add );
		XLALDestroyCache( tmp );
	}
	XLALCacheFileWrite( outfile ? outfile : LALSTDOUT, cache );
	XLALFileClose( outfile );
	XLALDestroyCache( cache );
	LALCheckMemoryLeaks();
	return 0;
}
예제 #2
0
int main(void)
{
	XLALSetErrorHandler(XLALAbortErrorHandler);
	test_orf();
	LALCheckMemoryLeaks();
	return 0;
}
예제 #3
0
파일: vis.c 프로젝트: Solaro/lalsuite
int main(int argc, char *argv[])
{
    LALFrStream *stream;
    REAL8TimeSeries *series;
    LIGOTimeGPS start;

    XLALSetErrorHandler(XLALAbortErrorHandler);

    parseargs(argc, argv);

    /* get the data */
    stream = XLALFrStreamCacheOpen(cache);
    XLALGPSSetREAL8(&start, t0 - pad);
    series = XLALFrStreamInputREAL8TimeSeries(stream, channel, &start, dt + 2.0 * pad, 0);
    XLALFrStreamClose(stream);

    /* manipulate the data */
    if (srate > 0)
        XLALResampleREAL8TimeSeries(series, 1.0 / srate);
    if (minfreq > 0)
        XLALHighPassREAL8TimeSeries(series, minfreq, 0.9, 8);
    if (maxfreq > 0)
        XLALLowPassREAL8TimeSeries(series, maxfreq, 0.9, 8);
    if (pad > 0)
        series = XLALResizeREAL8TimeSeries(series, pad / series->deltaT, dt / series->deltaT);

    if (df > 0) { /* we are computing a spectrum */
        REAL8FrequencySeries *spectrum;
        REAL8FFTPlan *plan;
        REAL8Window *window;
        size_t seglen = 1.0 / (df * series->deltaT);

        /* make sure that the time series length is commensurate with seglen */
        if (((2 * series->data->length) % seglen) != 0) {
            size_t newlen = ((2 * series->data->length) / seglen) * seglen;
            series = XLALResizeREAL8TimeSeries(series, 0, newlen);
        }

        spectrum = XLALCreateREAL8FrequencySeries(series->name, &series->epoch, 0.0, df, &lalDimensionlessUnit, seglen/2 + 1);
        plan = XLALCreateForwardREAL8FFTPlan(seglen, 0);
        window = XLALCreateHannREAL8Window(seglen);
        XLALREAL8AverageSpectrumWelch(spectrum, series, seglen, seglen/2, window, plan);
        if (minfreq > 0 || maxfreq > 0) {
            size_t first = minfreq / spectrum->deltaF;
            size_t last = maxfreq > 0 ? maxfreq / spectrum->deltaF : spectrum->data->length;
            spectrum = XLALResizeREAL8FrequencySeries(spectrum, first, last - first);
        }
        output_fs(outfile, spectrum);
        XLALDestroyREAL8Window(window);
        XLALDestroyREAL8FFTPlan(plan);
        XLALDestroyREAL8FrequencySeries(spectrum);
    } else { /* we are outputting a time series */
        output_ts(outfile, series);
    }

    XLALDestroyREAL8TimeSeries(series);
    return 0;
}
예제 #4
0
파일: sgwb.c 프로젝트: ahnitz/lalsuite
int main(int argc, char *argv[])
{
	char tstr[32]; // string to hold GPS time -- 31 characters is enough
	const double H0 = 0.72 * LAL_H0FAC_SI; // Hubble's constant in seconds
	const size_t length = 65536; // number of points in a segment
	const size_t stride = length / 2; // number of points in a stride
	size_t i, n;
	REAL8FrequencySeries *OmegaGW = NULL;
	REAL8TimeSeries **seg = NULL;
	LIGOTimeGPS epoch;
	gsl_rng *rng;

	XLALSetErrorHandler(XLALAbortErrorHandler);

	parseargs(argc, argv);

	XLALGPSSetREAL8(&epoch, tstart);
	gsl_rng_env_setup();
	rng = gsl_rng_alloc(gsl_rng_default);
	OmegaGW = XLALSimSGWBOmegaGWFlatSpectrum(Omega0, flow, srate/length, length/2 + 1);

	n = duration * srate;
	seg = LALCalloc(numDetectors, sizeof(*seg));
	printf("# time (s)");
	for (i = 0; i < numDetectors; ++i) {
		char name[LALNameLength];
		snprintf(name, sizeof(name), "%s:STRAIN", detectors[i].frDetector.prefix);
		seg[i] = XLALCreateREAL8TimeSeries(name, &epoch, 0.0, 1.0/srate, &lalStrainUnit, length);
		printf("\t%s (strain)", name);
	}
	printf("\n");

	XLALSimSGWB(seg, detectors, numDetectors, 0, OmegaGW, H0, rng); // first time to initilize

	while (1) { // infinite loop
		size_t j;
		for (j = 0; j < stride; ++j, --n) { // output first stride points
			LIGOTimeGPS t = seg[0]->epoch;
			if (n == 0) // check if we're done
				goto end;
			printf("%s", XLALGPSToStr(tstr, XLALGPSAdd(&t, j * seg[0]->deltaT)));
			for (i = 0; i < numDetectors; ++i)
				printf("\t%e", seg[i]->data->data[j]);
			printf("\n");
		}
		XLALSimSGWB(seg, detectors, numDetectors, stride, OmegaGW, H0, rng); // make more data
	}

end:
	for (i = 0; i < numDetectors; ++i)
		XLALDestroyREAL8TimeSeries(seg[i]);
	XLALFree(seg);
	XLALDestroyREAL8FrequencySeries(OmegaGW);
	LALCheckMemoryLeaks();

	return 0;
}
예제 #5
0
파일: sgwb.c 프로젝트: smirshekari/lalsuite
int main(int argc, char *argv[])
{
	const double H0 = 0.72 * LAL_H0FAC_SI; // Hubble's constant in seconds
	const double srate = 16384.0; // sampling rate in Hertz
	const size_t length = 65536; // number of points in a segment
	const size_t stride = length / 2; // number of points in a stride
	size_t i, n;
	REAL8FrequencySeries *OmegaGW = NULL;
	REAL8TimeSeries **seg = NULL;
	LIGOTimeGPS epoch;
	gsl_rng *rng;

	XLALSetErrorHandler(XLALAbortErrorHandler);

	parseargs(argc, argv);

	XLALGPSSetREAL8(&epoch, tstart);
	gsl_rng_env_setup();
	rng = gsl_rng_alloc(gsl_rng_default);
	OmegaGW = XLALSimSGWBOmegaGWFlatSpectrum(Omega0, flow, srate/length, length/2 + 1);

	n = duration * srate;
	seg = LALCalloc(numDetectors, sizeof(*seg));
	for (i = 0; i < numDetectors; ++i)
		seg[i] = XLALCreateREAL8TimeSeries("STRAIN", &epoch, 0.0, 1.0/srate, &lalStrainUnit, length);

	XLALSimSGWB(seg, detectors, numDetectors, 0, OmegaGW, H0, rng); // first time to initilize
	while (1) { // infinite loop
		double t0 = XLALGPSGetREAL8(&seg[0]->epoch);
		size_t j;
		for (j = 0; j < stride; ++j, --n) { // output first stride points
			if (n == 0) // check if we're done
				goto end;
			printf("%.9f", t0 + j * seg[0]->deltaT);
			for (i = 0; i < numDetectors; ++i)
				printf("\t%e", seg[i]->data->data[j]);
			printf("\n");
		}
		XLALSimSGWB(seg, detectors, numDetectors, stride, OmegaGW, H0, rng); // make more data
	}

end:
	for (i = 0; i < numDetectors; ++i)
		XLALDestroyREAL8TimeSeries(seg[i]);
	XLALFree(seg);
	XLALDestroyREAL8FrequencySeries(OmegaGW);
	LALCheckMemoryLeaks();

	return 0;
}
예제 #6
0
int main(void)
{
	XLALSetErrorHandler(XLALAbortErrorHandler);

	test_CHARVector();
	test_INT2Vector();
	test_INT4Vector();
 	test_INT8Vector();
	test_UINT2Vector();
	test_UINT4Vector();
	test_UINT8Vector();
	test_REAL4Vector();
	test_REAL8Vector();
	test_COMPLEX8Vector();
	test_COMPLEX16Vector();

	test_INT2Array();
	test_INT4Array();
	test_INT8Array();
	test_UINT2Array();
	test_UINT4Array();
	test_UINT8Array();
	test_REAL4Array();
	test_REAL8Array();
	test_COMPLEX8Array();
	test_COMPLEX16Array();

	test_INT2TimeSeries();
	test_INT4TimeSeries();
	test_INT8TimeSeries();
	test_UINT2TimeSeries();
	test_UINT4TimeSeries();
	test_UINT8TimeSeries();
	test_REAL4TimeSeries();
	test_REAL8TimeSeries();
	test_COMPLEX8TimeSeries();
	test_COMPLEX16TimeSeries();

	test_REAL4FrequencySeries();
	test_REAL8FrequencySeries();
	test_COMPLEX8FrequencySeries();
	test_COMPLEX16FrequencySeries();

	LALCheckMemoryLeaks();
	return 0;
}
예제 #7
0
int main( int argc, char *argv[] )
{
    XLALSetErrorHandler(XLALBacktraceErrorHandler);

    parseargs(argc, argv);

    if (theta == theta_invalid) { /* make a table */
        fprintf(stdout, "# theta(deg)\t    Re(S)   \t    Im(S)\n");
        for (theta = 0.0; theta <= 180.0; theta += 10.0) {
            COMPLEX16 sphwf = XLALSimBlackHoleRingdownSpheroidalWaveFunction(LAL_PI_180 * theta, a, l, m, s);
            fprintf(stdout, "%8g\t%e\t%e\n", theta, creal(sphwf), cimag(sphwf));
        }
    } else { /* evaluate at specified value */
        COMPLEX16 sphwf = XLALSimBlackHoleRingdownSpheroidalWaveFunction(LAL_PI_180 * theta, a, l, m, s);
        fprintf(stdout, "Spheroidal wave function (s)S(l,m)(cos(theta),a):\n");
        fprintf(stdout, "(%d)S(%d,%d)(cos(%g deg),%g) = %g + %g i\n", s, l, m, theta, a, creal(sphwf), cimag(sphwf));
    }
    return 0;
}
예제 #8
0
int main(int argc, char *argv[])
{
  	LIGOTimeGPS epoch = {0, 0};
	REAL8TimeSeries *hplus;
	REAL8TimeSeries *hcross;
	size_t j;

	XLALSetErrorHandler(XLALBacktraceErrorHandler);

	parseargs(argc, argv);

	XLALSimBlackHoleRingdown(&hplus, &hcross, &epoch, q, dt, M, a, e, r, i, l, m);

	fprintf(stdout, "# time (s)\th_plus      \th_cross\n");
	for (j = 0; j < hplus->data->length; ++j)
		fprintf(stdout, "%.9f\t%e\t%e\n", j*dt, hplus->data->data[j], hcross->data->data[j]);

	XLALDestroyREAL8TimeSeries(hcross);
	XLALDestroyREAL8TimeSeries(hplus);
	LALCheckMemoryLeaks();

	return 0;
}
예제 #9
0
int main(int argc, char *argv[])
{
    struct params p;
    int istd, isfd;

    XLALSetErrorHandler(XLALBacktraceErrorHandler);

    p = parseargs(argc, argv);
    print_params(p);

    /* sanity check on domain; set to natural value if unspecified */
    istd = XLALSimInspiralImplementedTDApproximants(p.approx);
    isfd = XLALSimInspiralImplementedFDApproximants(p.approx);
    if (!istd && !isfd) {
        fprintf(stderr, "error: approximant not supported\n");
        exit(1);
    }
    switch (p.domain) {
    case LAL_SIM_DOMAIN_TIME:
        if (!istd) {
            fprintf(stderr, "error: approximant not supported in time domain\n");
            exit(1);
        }
        break;
    case LAL_SIM_DOMAIN_FREQUENCY:
        if (!isfd) {
            fprintf(stderr, "error: approximant not supported in frequency domain\n");
            exit(1);
        }
        break;
    default:
        switch (p.freq_dom) {
        case 0:
            p.domain = istd ? LAL_SIM_DOMAIN_TIME : LAL_SIM_DOMAIN_FREQUENCY;
            break;
        case 1:
            p.domain = isfd ? LAL_SIM_DOMAIN_FREQUENCY : LAL_SIM_DOMAIN_TIME;
            break;
        }
        break;
    }

    /* generate and output the waveform in appropriate domain */
    if (p.freq_dom) {
        COMPLEX16FrequencySeries *htilde_plus = NULL;
        COMPLEX16FrequencySeries *htilde_cross = NULL;
        create_fd_waveform(&htilde_plus, &htilde_cross, p);
        output_fd_waveform(htilde_plus, htilde_cross, p);
        XLALDestroyCOMPLEX16FrequencySeries(htilde_cross);
        XLALDestroyCOMPLEX16FrequencySeries(htilde_plus);
    } else {
        REAL8TimeSeries *h_plus = NULL;
        REAL8TimeSeries *h_cross = NULL;
        create_td_waveform(&h_plus, &h_cross, p);
        output_td_waveform(h_plus, h_cross, p);
        XLALDestroyREAL8TimeSeries(h_cross);
        XLALDestroyREAL8TimeSeries(h_plus);
    }

    /* cleanup */
    XLALDestroyDict(p.params);
    LALCheckMemoryLeaks();
    return 0;
}
예제 #10
0
/*
 * main
 */
int main (int argc , char **argv) {
    FILE *f;
    int status;
    int start_time;
    COMPLEX16FrequencySeries *hptilde = NULL, *hctilde = NULL;
    REAL8TimeSeries *hplus = NULL;
    REAL8TimeSeries *hcross = NULL;
    GSParams *params;

    /* set us up to fail hard */
    XLALSetErrorHandler(XLALAbortErrorHandler);

    /* parse commandline */
    params = parse_args(argc, argv);

    /* generate waveform */
    start_time = time(NULL);
    switch (params->domain) {
    case LAL_SIM_DOMAIN_FREQUENCY:
        XLALSimInspiralChooseFDWaveform(&hptilde, &hctilde, params->phiRef,
                                        params->deltaF, params->m1, params->m2, params->s1x,
                                        params->s1y, params->s1z, params->s2x, params->s2y,
                                        params->s2z, params->f_min, params->f_max, params->fRef,
                                        params->distance, params->inclination, params->lambda1,
                                        params->lambda2, params->waveFlags, params->nonGRparams,
                                        params->ampO, params->phaseO, params->approximant);
        break;
    case LAL_SIM_DOMAIN_TIME:
        XLALSimInspiralChooseTDWaveform(&hplus, &hcross, params->phiRef,
                                        params->deltaT, params->m1, params->m2, params->s1x,
                                        params->s1y, params->s1z, params->s2x, params->s2y,
                                        params->s2z, params->f_min, params->fRef,
                                        params->distance, params->inclination, params->lambda1,
                                        params->lambda2, params->waveFlags,
                                        params->nonGRparams, params->ampO, params->phaseO,
                                        params->approximant);
        break;
    default:
        XLALPrintError("Error: domain must be either TD or FD\n");
    }
    if (params->verbose)
        XLALPrintInfo("Generation took %.0f seconds\n",
                      difftime(time(NULL), start_time));
    if (((params->domain == LAL_SIM_DOMAIN_FREQUENCY) && (!hptilde || !hctilde)) ||
            ((params->domain == LAL_SIM_DOMAIN_TIME) && (!hplus || !hcross))) {
        XLALPrintError("Error: waveform generation failed\n");
        goto fail;
    }

    /* dump file */
    if ( strlen(params->outname) > 0 ) {
        f = fopen(params->outname, "w");
        if (f==NULL) {
            printf("**ERROR** Impossible to write file %s\n",params->outname);
            exit(1);
        }
        else {
            if (params->domain == LAL_SIM_DOMAIN_FREQUENCY)
                if (params->ampPhase == 1)
                    status = dump_FD2(f, hptilde, hctilde);
                else
                    status = dump_FD(f, hptilde, hctilde);
            else if (params->ampPhase == 1)
                status = dump_TD2(f, hplus, hcross);
            else
                status = dump_TD(f, hplus, hcross);
            fclose(f);
        }
        if (status) goto fail;
    }

    /* clean up */
    XLALSimInspiralDestroyWaveformFlags(params->waveFlags);
    XLALSimInspiralDestroyTestGRParam(params->nonGRparams);
    XLALFree(params);
    XLALDestroyCOMPLEX16FrequencySeries(hptilde);
    XLALDestroyCOMPLEX16FrequencySeries(hctilde);
    return 0;

fail:
    XLALSimInspiralDestroyWaveformFlags(params->waveFlags);
    XLALSimInspiralDestroyTestGRParam(params->nonGRparams);
    XLALFree(params);
    XLALDestroyCOMPLEX16FrequencySeries(hptilde);
    XLALDestroyCOMPLEX16FrequencySeries(hctilde);
    return 1;
}
예제 #11
0
int main(int argc, char **argv)
{
	REAL8TimeSeries *hplus = NULL;
	REAL8TimeSeries *hcross = NULL;
	struct params p;
	int status = 0;
	gsl_rng *rng = NULL;

	XLALSetErrorHandler(XLALAbortErrorHandler);

	p = parseargs(argc, argv);

	if ((int)(p.waveform) < 0 || (int)(p.waveform) >= NumWaveforms) {
		fprintf(stderr, "error: must specify valid waveform\n");
		exit(1);
	}

	if (p.waveform == BLTWNB) { /* set up gsl random number generator */
		gsl_rng_env_setup();
		rng = gsl_rng_alloc(gsl_rng_default);
	}

	if (IS_INVALID_DOUBLE(p.srate) || p.srate <= 0.0) {
		fprintf(stderr, "error: must specify valid sample rate\n");
		status = 1;
	}

	verbose_output("Input parameters:\n");
	verbose_output("%-31s `%s' - %s\n", "waveform:", waveform_names[p.waveform], waveform_long_names[p.waveform]);
	verbose_output("%-31s %g (Hz)\n", "sample rate:", p.srate);

	switch (p.waveform) {

	case BLTWNB:

		/* sanity check relevant parameters */
		if (IS_INVALID_DOUBLE(p.duration) || p.duration < 0.0) {
			fprintf(stderr, "error: must specify valid duration for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.frequency) || p.frequency < 0.0) {
			fprintf(stderr, "error: must specify valid frequency for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.bandwidth) || p.bandwidth < 0.0) {
			fprintf(stderr, "error: must specify valid bandwidth for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.eccentricity) || p.eccentricity < 0.0 || p.eccentricity > 1.0) {
			fprintf(stderr, "error: must specify valid eccentricity in domain [0,1] for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.fluence) || p.fluence < 0.0) {
			fprintf(stderr, "error: must specify valid fluence for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}

		/* detect set but ignored parameters */
		if (!IS_INVALID_DOUBLE(p.q))
			fprintf(stderr, "warning: quality-factor parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.phase != DEFAULT_PHASE)
			fprintf(stderr, "warning: phase parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.amplitude))
			fprintf(stderr, "warning: amplitude parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.hrss))
			fprintf(stderr, "warning: hrss parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);

		if (!status) {
			double int_hdot_squared_dt;
			int_hdot_squared_dt = p.fluence * LAL_GMSUN_SI * 4 / LAL_C_SI / LAL_PC_SI / LAL_PC_SI;

			verbose_output("%-31s %g (s)\n", "duration:", p.duration);
			verbose_output("%-31s %g (Hz)\n", "frequency:", p.frequency);
			verbose_output("%-31s %g (Hz)\n", "bandwidth:", p.bandwidth);
			verbose_output("%-31s %g\n", "eccentricity:", p.eccentricity);
			verbose_output("%-31s %g (Msun c^2 pc^-2)\n", "fluence:", p.fluence);
			verbose_output("%-31s %g (s^-1)\n", "integral (dh/dt)^2 dt:", int_hdot_squared_dt);
			verbose_output("%-31s GSL_RNG_TYPE=%s\n", "GSL random number generator:", gsl_rng_name(rng));
			verbose_output("%-31s GSL_RNG_SEED=%lu\n", "GSL random number seed:", gsl_rng_default_seed);
			status = XLALGenerateBandAndTimeLimitedWhiteNoiseBurst(&hplus, &hcross, p.duration, p.frequency, p.bandwidth, p.eccentricity, int_hdot_squared_dt, 1.0/p.srate, rng);
		}
		break;

	case StringCusp:

		/* sanity check relevant parameters */
		if (IS_INVALID_DOUBLE(p.amplitude) || p.amplitude < 0.0) {
			fprintf(stderr, "error: must specify valid amplitude for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.frequency) || p.frequency < 0.0) {
			fprintf(stderr, "error: must specify valid frequency for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}

		/* detect set but ignored parameters */
		if (!IS_INVALID_DOUBLE(p.duration))
			fprintf(stderr, "warning: duration parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.bandwidth))
			fprintf(stderr, "warning: bandwidth parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.q))
			fprintf(stderr, "warning: quality-factor parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.eccentricity != DEFAULT_ECCENTRICITY)
			fprintf(stderr, "warning: eccentricity parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.phase != DEFAULT_PHASE)
			fprintf(stderr, "warning: phase parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.hrss))
			fprintf(stderr, "warning: hrss parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.fluence))
			fprintf(stderr, "warning: fluence parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);

		if (!status) {
			verbose_output("%-31s %g (s^-1/3)\n", "amplitude:", p.amplitude);
			verbose_output("%-31s %g (Hz)\n", "frequency:", p.frequency);
			status = XLALGenerateStringCusp(&hplus, &hcross, p.amplitude, p.frequency, 1.0/p.srate);
		}
		break;

	case SineGaussian:

		/* sanity check relevant parameters */
		if (IS_INVALID_DOUBLE(p.q) || p.q < 0.0) {
			fprintf(stderr, "error: must specify valid quality factor for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.frequency) || p.frequency < 0.0) {
			fprintf(stderr, "error: must specify valid frequency for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.hrss) || p.hrss < 0.0) {
			fprintf(stderr, "error: must specify valid hrss for waveform `%s\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.eccentricity) || p.eccentricity < 0.0 || p.eccentricity > 1.0) {
			fprintf(stderr, "error: must specify valid eccentricity in domain [0,1] for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.phase)) {
			fprintf(stderr, "error: must specify valid phase for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}

		/* detect set but ignored parameters */
		if (!IS_INVALID_DOUBLE(p.duration))
			fprintf(stderr, "warning: duration parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.bandwidth))
			fprintf(stderr, "warning: bandwidth parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.amplitude))
			fprintf(stderr, "warning: amplitude parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.fluence))
			fprintf(stderr, "warning: fluence parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);

		if (!status) {
			verbose_output("%-31s %g\n", "quality-factor:", p.q);
			verbose_output("%-31s %g (Hz)\n", "frequency:", p.frequency);
			verbose_output("%-31s %g (Hz^-1/2)\n", "root-sum-squared strain:", p.hrss);
			verbose_output("%-31s %g\n", "eccentricity:", p.eccentricity);
			verbose_output("%-31s %g (degrees)\n", "phase:", p.phase / LAL_PI_180);
			status = XLALSimBurstSineGaussian(&hplus, &hcross, p.q, p.frequency, p.hrss, p.eccentricity, p.phase, 1.0/p.srate);
		}
		break;

	case Gaussian:

		/* sanity check relevant parameters */
		if (IS_INVALID_DOUBLE(p.duration) || p.duration < 0.0) {
			fprintf(stderr, "error: must specify valid duration for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		if (IS_INVALID_DOUBLE(p.hrss) || p.hrss < 0.0) {
			fprintf(stderr, "error: must specify valid hrss for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}
		/* detect set but ignored parameters */
		if (!IS_INVALID_DOUBLE(p.frequency))
			fprintf(stderr, "warning: frequency parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.bandwidth))
			fprintf(stderr, "warning: bandwidth parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.q))
			fprintf(stderr, "warning: quality-factor parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.eccentricity != DEFAULT_ECCENTRICITY)
			fprintf(stderr, "warning: eccentricity parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.phase != DEFAULT_PHASE)
			fprintf(stderr, "warning: phase parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.amplitude))
			fprintf(stderr, "warning: amplitude parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.fluence))
			fprintf(stderr, "warning: fluence parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!status) {
			verbose_output("%-31s %g (s)\n", "duration:", p.duration);
			verbose_output("%-31s %g (Hz^-1/2)\n", "root-sum-squared strain:", p.hrss);
			status = XLALSimBurstGaussian(&hplus, &hcross, p.duration, p.hrss, 1.0/p.srate);
		}

		break;

	case Impulse:

		/* sanity check relevant parameters */
		if (IS_INVALID_DOUBLE(p.amplitude) || p.amplitude < 0.0) {
			fprintf(stderr, "error: must specify valid amplitude for waveform `%s'\n", waveform_names[p.waveform]);
			status = 1;
		}

		/* detect set but ignored parameters */
		if (!IS_INVALID_DOUBLE(p.duration))
			fprintf(stderr, "warning: duration parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.frequency))
			fprintf(stderr, "warning: frequency parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.bandwidth))
			fprintf(stderr, "warning: bandwidth parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.q))
			fprintf(stderr, "warning: quality-factor parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.eccentricity != DEFAULT_ECCENTRICITY)
			fprintf(stderr, "warning: eccentricity parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (p.phase != DEFAULT_PHASE)
			fprintf(stderr, "warning: phase parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.hrss))
			fprintf(stderr, "warning: hrss parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);
		if (!IS_INVALID_DOUBLE(p.fluence))
			fprintf(stderr, "warning: fluence parameter is set but ignored for waveform `%s'\n", waveform_names[p.waveform]);

		if (!status) {
			verbose_output("%-31s %g (dimensionless)\n", "amplitude:", p.amplitude);
			status = XLALGenerateImpulseBurst(&hplus, &hcross, p.amplitude, 1.0/p.srate);
		}
		break;

	default:
		fprintf(stderr, "error: unrecognized waveform\n");
		exit(1);
	};

	if (status)
		exit(1);

	if (verbose) {
		char peak_time[32]; // GPS time string - 31 characters is enough
		LIGOTimeGPS tpeak;
		COMPLEX16 hpeak;
		double hrss;
		double fluence;
		unsigned ipeak;
		hpeak = XLALMeasureHPeak(hplus, hcross, &ipeak);
		tpeak = hplus->epoch;
		XLALGPSAdd(&tpeak, ipeak * hplus->deltaT);
		XLALGPSToStr(peak_time, &tpeak);
		hrss = XLALMeasureHrss(hplus, hcross);
		fluence = XLALMeasureEoverRsquared(hplus, hcross);
		verbose_output("Measured parameters:\n");
		verbose_output("%-31s %s (s)\n", "peak time:", peak_time);
		verbose_output("%-31s (h+, hx) = (%g, %g)\n", "peak strain amplitude:", creal(hpeak), cimag(hpeak));
		verbose_output("%-31s abs(h+, hx) = %g\n", "peak strain amplitude:", cabs(hpeak));
		verbose_output("%-31s arg(h+, hx) = %g (rad)\n", "peak strain amplitude:", carg(hpeak));
		verbose_output("%-31s %g (Hz^-1/2)\n", "root-sum-squared strain:", hrss);
		verbose_output("%-31s %g (J m^-2)\n", "isotropic energy fluence:", fluence);
		verbose_output("%-31s %g (Msun c^2 pc^-2)\n", "isotropic energy fluence:", fluence * LAL_PC_SI * LAL_PC_SI / LAL_MSUN_SI / LAL_C_SI / LAL_C_SI);
	}

	output(hplus, hcross);

	XLALDestroyREAL8TimeSeries(hcross);
	XLALDestroyREAL8TimeSeries(hplus);
	LALCheckMemoryLeaks();
	return 0;
}
예제 #12
0
int
main(int argc, char **argv)
{
  static LALStatus stat; /* LALStatus pointer */
  CHAR *infile = NULL;   /* The input filename */
  CHAR *outfile = NULL;  /* The output filename */
  INT4 arg;              /* Argument counter */
  UINT4 npts = NPTS;     /* Number of points in time series */
  UINT4 offset = OFFSET; /* Position of delta function */
  REAL8 dt = DT;         /* Sampling interval. */
  static REAL4TimeSeries series;    /* Time series */
  static PassBandParamStruc params; /* Filter parameters */

  XLALSetErrorHandler( XLALAbortErrorHandler );

  /* Set up the default filter parameters. */
  params.f1 = F1;
  params.f2 = F2;
  params.a1 = A1;
  params.a2 = A2;
  params.nMax = ORDER;

  /* Parse argument list.  i stores the current position. */
  arg = 1;
  while ( arg < argc ) {
    /* Parse debuglevel option. */
    if ( !strcmp( argv[arg], "-d" ) ) {
      if ( argc > arg + 1 ) {
        arg++;
      } else {
	ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
        LALPrintError( USAGE, *argv );
        return BANDPASSTESTC_EARG;
      }
    }
    /* Parse input file option. */
    else if ( !strcmp( argv[arg], "-i" ) ) {
      if ( argc > arg + 1 ) {
        arg++;
        infile = argv[arg++];
      } else {
	ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
        LALPrintError( USAGE, *argv );
        return BANDPASSTESTC_EARG;
      }
    }
    /* Parse output file option. */
    else if ( !strcmp( argv[arg], "-o" ) ) {
      if ( argc > arg + 1 ) {
        arg++;
        outfile = argv[arg++];
      } else {
	ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
        LALPrintError( USAGE, *argv );
        return BANDPASSTESTC_EARG;
      }
    }
    /* Parse filter options. */
    else if ( !strcmp( argv[arg], "-f" ) ) {
      if ( argc > arg + 5 ) {
        arg++;
	params.f1=atof(argv[arg++]);
	params.f2=atof(argv[arg++]);
	params.a1=atof(argv[arg++]);
	params.a2=atof(argv[arg++]);
	params.nMax=atoi(argv[arg++]);
      } else {
	ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
        LALPrintError( USAGE, *argv );
        return BANDPASSTESTC_EARG;
      }
    }
    /* Parse time series options. */
    else if ( !strcmp( argv[arg], "-n" ) ) {
      if ( argc > arg + 3 ) {
        arg++;
	npts=atoi(argv[arg++]);
	dt=atof(argv[arg++]);
	offset=atoi(argv[arg++]);
      } else {
	ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
        LALPrintError( USAGE, *argv );
        return BANDPASSTESTC_EARG;
      }
    }
    /* Unrecognized option. */
    else {
      ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
      LALPrintError( USAGE, *argv );
      return BANDPASSTESTC_EARG;
    }
  } /* End of argument parsing loop. */

  /* Check input values. */
  if ( !infile ) {
    if ( offset >= npts ) {
      ERROR( BANDPASSTESTC_EBAD, BANDPASSTESTC_MSGEBAD, 0 );
      LALPrintError( "\toffset=%i must be less than npts=%i\n", offset,
		     npts );
      return BANDPASSTESTC_EBAD;
    }
  }

  /* Create the time series. */
  if ( infile ) {
    FILE *fp = fopen( infile, "r" );
    if ( !fp ) {
      ERROR( BANDPASSTESTC_EFILE, BANDPASSTESTC_MSGEFILE, infile );
      return BANDPASSTESTC_EFILE;
    }
    SUB( LALSReadTSeries( &stat, &series, fp ), &stat );
    fclose( fp );
  } else {
    snprintf( series.name, LALNameLength, "%s", "Impulse" );
    series.deltaT = dt;
    SUB( LALSCreateVector( &stat, &(series.data), npts ), &stat );
    memset( series.data->data, 0, npts*sizeof(REAL4) );
    series.data->data[offset] = 1.0;
  }

  /* Filter the time series. */
  SUB( LALDButterworthREAL4TimeSeries( &stat, &series, &params ),
       &stat );

  /* Print the output, if the -o option was given. */
  if ( outfile ) {
    FILE *fp = fopen( outfile, "w" );
    if ( !fp ){
      ERROR( BANDPASSTESTC_EFILE, BANDPASSTESTC_MSGEFILE, outfile );
      return BANDPASSTESTC_EFILE;
    }
    SUB( LALSWriteTSeries( &stat, fp, &series ), &stat );
    fclose( fp );
  }

  /* Free memory and exit. */
  SUB( LALSDestroyVector( &stat, &(series.data) ), &stat );
  LALCheckMemoryLeaks();
  INFO( BANDPASSTESTC_MSGENORM );
  return BANDPASSTESTC_ENORM;
}
예제 #13
0
int main(int argc, char *argv[])
{
	char tstr[32]; // string to hold GPS time -- 31 characters is enough
	size_t length;
	size_t stride;
	size_t n;
	REAL8FrequencySeries *psd = NULL;
	REAL8TimeSeries *seg = NULL;
	gsl_rng *rng;

	XLALSetErrorHandler(XLALAbortErrorHandler);

	parseargs(argc, argv);
	if (overrideflow > 0.0)
		flow = overrideflow;
	length = segdur * srate;
	stride = length / 2;

	/* handle 0noise case first */
	if (strcmp(detector, "0noise") == 0) {
		/* just print out a bunch of zeros */
		if (psdonly) {
			double deltaF = srate / length;
			size_t klow = flow / deltaF;
			size_t k;
			fprintf(stdout, "# freq (s^-1)\tPSD (strain^2 s)\n");
			for (k = klow; k < length/2 - 1; ++k)
				fprintf(stdout, "%e\t%e\n", k * deltaF, 0.0);
		} else {
			size_t j;
			fprintf(stdout, "# time (s)\tNOISE (strain)\n");
			n = duration * srate;
			for (j = 0; j < n; ++j) { 
				LIGOTimeGPS t = tstart;
				fprintf(stdout, "%s\t%e\n", XLALGPSToStr(tstr, XLALGPSAdd(&t, j/srate)), 0.0);
			}
		}
		return 0;
	}

	gsl_rng_env_setup();
	rng = gsl_rng_alloc(gsl_rng_default);
	psd = XLALCreateREAL8FrequencySeries(detector, &tstart, 0.0, srate/length, &strainSquaredPerHertzUnit, length/2 + 1);
	if (asdfile)
		XLALSimNoisePSDFromFile(psd, flow, asdfile);
	else if (official && opsdfunc)
		opsdfunc(psd, flow);
	else
		XLALSimNoisePSD(psd, flow, psdfunc);
	if (verbose) {
		double Mpc = 1e6 * LAL_PC_SI;
		double horizon_distance;
		fprintf(stderr, "%-39s %s\n", "detector: ", detector);
		fprintf(stderr, "%-39s %g Hz\n", "low-frequency cutoff: ", flow);
		horizon_distance = XLALMeasureStandardSirenHorizonDistance(psd, flow, -1.0);
		fprintf(stderr, "%-39s %g Mpc\n", "standard siren horizon distance: ", horizon_distance / Mpc);
		fprintf(stderr, "%-39s %g Mpc\n", "sense-monitor range: ", horizon_distance / Mpc / LAL_HORIZON_DISTANCE_OVER_SENSEMON_RANGE);
		fprintf(stderr, "%-39s GSL_RNG_TYPE=%s\n", "GSL random number generator:", gsl_rng_name(rng));
		fprintf(stderr, "%-39s GSL_RNG_SEED=%lu\n", "GSL random number seed:", gsl_rng_default_seed);
	}
	if (psdonly) { // output PSD and exit
		size_t klow = flow / psd->deltaF;
		size_t k;
		fprintf(stdout, "# freq (s^-1)\tPSD (strain^2 s)\n");
		for (k = klow; k < length/2 - 1; ++k)
			fprintf(stdout, "%e\t%e\n", k * psd->deltaF, sqrt(psd->data->data[k]));
		goto end;
	}

	n = duration * srate;
	seg = XLALCreateREAL8TimeSeries("STRAIN", &tstart, 0.0, 1.0/srate, &lalStrainUnit, length);
	XLALSimNoise(seg, 0, psd, rng); // first time to initialize
	fprintf(stdout, "# time (s)\tNOISE (strain)\n");
	while (1) { // infinite loop
		size_t j;
		for (j = 0; j < stride; ++j, --n) { // output first stride points
			LIGOTimeGPS t = seg->epoch;
			if (n == 0) // check if we're done
				goto end;
			fprintf(stdout, "%s\t%e\n", XLALGPSToStr(tstr, XLALGPSAdd(&t, j * seg->deltaT)), seg->data->data[j]);
		}
		XLALSimNoise(seg, stride, psd, rng); // make more data
	}

end:
	XLALDestroyREAL8TimeSeries(seg);
	XLALDestroyREAL8FrequencySeries(psd);
	LALCheckMemoryLeaks();

	return 0;
}