212 #include <lal/LALStdlib.h>
213 #include <lal/LALgetopt.h>
214 #include <lal/LALString.h>
215 #include <lal/Date.h>
216 #include <lal/FrequencySeries.h>
217 #include <lal/TimeSeries.h>
218 #include <lal/BandPassTimeSeries.h>
219 #include <lal/ResampleTimeSeries.h>
220 #include <lal/Window.h>
221 #include <lal/TimeFreqFFT.h>
222 #include <lal/Audio.h>
223 #include <lal/LALFrStream.h>
224 #include <lal/Units.h>
243 int usage(
const char *program);
253 int main(
int argc,
char *argv[])
283 size_t seglen = 1.0 / (
df * series->
deltaT);
286 if (((2 * series->
data->
length) % seglen) != 0) {
287 size_t newlen = ((2 * series->
data->
length) / seglen) * seglen;
329 char args[] =
"hc:f:g:o:s:t:H:L:P:R:S:";
331 int option_index = 0;
340 if (long_options[option_index].
flag)
343 fprintf(stderr,
"error parsing option %s with argument %s\n",
385 fprintf(stderr,
"unknown error while parsing options\n");
391 fprintf(stderr,
"extraneous command line arguments:\n");
400 fprintf(stderr,
"must specify a channel\n");
405 fprintf(stderr,
"must specify a frame cache or frame files\n");
419 fprintf(stderr,
"\t-h, --help \tprint this message and exit\n");
420 fprintf(stderr,
"\t-c CHAN, --channel=CHAN \tchannel name CHAN\n");
421 fprintf(stderr,
"\t-f CACHE, --frame-cache=CACHE\tframe cache file CACHE\n");
422 fprintf(stderr,
"\t-g GLOB, --frame-glob=GLOB \tframe file glob string GLOB\n");
423 fprintf(stderr,
"\t-o OUTFILE, --output=OUTFILE \toutput to file OUTFILE\n");
424 fprintf(stderr,
"\t-s T0, --start-time=T0 \tGPS start time T0 (s)\n");
425 fprintf(stderr,
"\t-t DT, --duration=DT \tduration DT (s)\n");
426 fprintf(stderr,
"\t-H FMIN, --highpass=FMIN \thighpass filter at frequency FMIN (Hz)\n");
427 fprintf(stderr,
"\t-L FMAX, --lowpass=FMAX \tlowpass filter at frequency FMAX (Hz)\n");
428 fprintf(stderr,
"\t-P PAD, --pad=PAD \tadd PAD data at start and end (s)\n");
429 fprintf(stderr,
"\t-R SRATE, --resample=SRATE \tresample to rate SRATE (Hz)\n");
430 fprintf(stderr,
"\t-S DF, --spectrum=DF \tcompute spectrum with resolution DF (Hz)\n");
431 fprintf(stderr,
"\nOUTPUT FORMATS:\n");
443 fprintf(stderr,
"\nEXAMPLES:\n");
444 fprintf(stderr,
"\n\tOutput 64s of strain data to a WAV file:\n");
445 fprintf(stderr,
"\t\t%s -c \"H1:LSC-STRAIN\" -g H-H1_RDS_C03_L2-864903135-128.gwf -s 864903136 -t 64 -P 1 -H 10 -L 1000 -R 2048 -o data.wav\n",
program);
446 fprintf(stderr,
"\n\tOutput amplitude spectrum to a PDF file:\n");
447 fprintf(stderr,
"\t\t%s -c \"H1:LSC-STRAIN\" -g H-H1_RDS_C03_L2-864903135-128.gwf -s 864903136 -t 64 -P 1 -H 10 -L 1000 -R 2048 -S 0.25 -o spec.pdf\n",
program);
456 ext = strrchr(fname ? fname :
"",
'.');
459 fp = fopen(fname,
"w");
464 fp = fopen(fname,
"w");
483 fp = fname ? fopen(fname,
"w") : stdout;
501 ext = strrchr(fname ? fname :
"",
'.');
504 fprintf(stderr,
"cannot output a spectrum to an audio file\n");
508 fprintf(stderr,
"cannot output a spectrum to an audio file\n");
526 fp = fname ? fopen(fname,
"w") : stdout;
539 FILE *gp = popen(
"gnuplot -persistent",
"w");
542 fprintf(stderr,
"require program gnuplot to output .%s files", fmt);
548 if (units == NULL || *units ==
'\0') {
554 if (strcmp(fmt,
"jpg") == 0)
556 else if (strcmp(fmt,
"ps") == 0)
557 fmt =
"postscript landscape";
558 else if (strcmp(fmt,
"eps") == 0)
559 fmt =
"postscript eps";
562 fprintf(gp,
"set terminal %s\n", fmt);
563 fprintf(gp,
"set output '%s'\n", fname);
566 fprintf(gp,
"set xlabel 'time (s)'\n");
567 fprintf(gp,
"set ylabel 'value (%s)'\n", units);
569 fprintf(gp,
"plot '-' with lines\n");
584 FILE *gp = popen(
"gnuplot -persistent",
"w");
587 fprintf(stderr,
"require program gnuplot to output .%s files", fmt);
594 if (units == NULL || *units ==
'\0') {
600 if (strcmp(fmt,
"jpg") == 0)
602 else if (strcmp(fmt,
"ps") == 0)
603 fmt =
"postscript landscape";
604 else if (strcmp(fmt,
"eps") == 0)
605 fmt =
"postscript eps";
608 fprintf(gp,
"set terminal %s\n", fmt);
609 fprintf(gp,
"set output '%s'\n", fname);
611 fprintf(gp,
"set grid xtics mxtics ytics\n");
612 fprintf(gp,
"set xlabel 'frequency (Hz)'\n");
613 fprintf(gp,
"set ylabel 'amplitude spectral density (%s)'\n", units);
616 fprintf(gp,
"plot '-' with lines\n");
647 fputs(
"<?xml version='1.0' encoding='utf-8'?>\n",
fp);
648 fputs(
"<!DOCTYPE LIGO_LW SYSTEM \"http://ldas-sw.ligo.caltech.edu/doc/ligolwAPI/html/ligolw_dtd.txt\">\n",
fp);
649 fputs(
"<LIGO_LW>\n",
fp);
654 fputs(
"</LIGO_LW>\n",
fp);
660 fputs(
"\t<LIGO_LW Name=\"REAL8FrequencySeries\">\n",
fp);
665 fputs(
"\t<LIGO_LW Name=\"REAL8TimeSeries\">\n",
fp);
670 fputs(
"\t</LIGO_LW>\n",
fp);
678 fprintf(
fp,
"\t\t<Time Type=\"GPS\" Name=\"epoch\">%s</Time>\n", tstr);
683 fprintf(
fp,
"\t\t<Param Type=\"real_8\" Name=\"f0:param\" Unit=\"s^-1\">"
689 const char *dets[] = {
"G1",
"H1",
"H2",
"K1",
"L1",
"T1",
"V1"};
692 fputs(
"\t\t<Param Type=\"lstring\" Name=\"instrument:param\">",
fp);
693 for (d = 0; d < ndet; ++d)
694 if (strncmp(
name, dets[d], 2) == 0) {
700 fputs(
"</Param>\n",
fp);
706 fprintf(
fp,
"\t\t<Array Type=\"real_8\" Name=\"%s:array\" Unit=\"%s\">\n",
708 fprintf(
fp,
"\t\t\t<Dim Start=\"%g\" Scale=\"%.15g\" "
709 "Name=\"Frequency\" Unit=\"s^-1\">%u</Dim>\n", series->
f0,
711 fputs(
"\t\t\t<Dim Name=\"Frequency,Real\">2</Dim>\n",
fp);
716 fprintf(
fp,
"\t\t<Array Type=\"real_8\" Name=\"%s:array\" Unit=\"%s\">\n",
718 fprintf(
fp,
"\t\t\t<Dim Start=\"0\" Scale=\"%.15g\" "
719 "Name=\"Time\" Unit=\"s\">%u</Dim>\n", series->
deltaT,
721 fputs(
"\t\t\t<Dim Name=\"Time,Real\">2</Dim>\n",
fp);
726 fputs(
"\t\t</Array>\n",
fp);
734 fputs(
"\t\t\t<Stream Delimiter=\"" DELIM "\" Type=\"Local\">\n",
fp);
735 for (i = 0; i < vector->
length; ++i)
738 fputs(
"\t\t\t</Stream>\n",
fp);
745 FILE *
fp = fopen(fname,
"w");
771 FILE *
fp = fopen(fname,
"w");
int XLALLowPassREAL8TimeSeries(REAL8TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
int XLALHighPassREAL8TimeSeries(REAL8TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
int XLALAudioAURecordREAL8TimeSeries(FILE *fp, REAL8TimeSeries *series)
int XLALAudioWAVRecordREAL8TimeSeries(FILE *fp, REAL8TimeSeries *series)
char * XLALGPSToStr(char *s, const LIGOTimeGPS *t)
REAL8FrequencySeries * XLALCreateREAL8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
REAL8FrequencySeries * XLALResizeREAL8FrequencySeries(REAL8FrequencySeries *series, int first, size_t length)
void XLALDestroyREAL8FrequencySeries(REAL8FrequencySeries *series)
LALCache * XLALCacheImport(const char *fname)
LALCache * XLALCacheGlob(const char *dirstr, const char *fnptrn)
int XLALFrStreamClose(LALFrStream *stream)
Closes a LALFrStream.
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
Opens a LALFrStream associated with a LALCache.
REAL8TimeSeries * XLALFrStreamInputREAL8TimeSeries(LALFrStream *stream, const char *channel, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
Reads a time series channel from a LALFrStream stream with a specified start time and duration,...
int XLALStringCaseCompare(const char *s1, const char *s2)
char char * XLALStringDuplicate(const char *s)
void XLALDestroyREAL8FFTPlan(REAL8FFTPlan *plan)
REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan(UINT4 size, int measurelvl)
int XLALResampleREAL8TimeSeries(REAL8TimeSeries *series, REAL8 dt)
int XLALREAL8AverageSpectrumWelch(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan)
REAL8TimeSeries * XLALResizeREAL8TimeSeries(REAL8TimeSeries *series, int first, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
char * XLALUnitToString(const LALUnit *input)
const LALUnit lalDimensionlessUnit
LALUnit * XLALUnitSqrt(LALUnit *output, const LALUnit *input)
void XLALDestroyREAL8Window(REAL8Window *window)
REAL8Window * XLALCreateHannREAL8Window(UINT4 length)
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
This structure details the state of the frame stream.
int main(int argc, char *argv[])
void xml_begin_time_series(FILE *fp)
void xml_begin_time_array(REAL8TimeSeries *series, FILE *fp)
void xml_begin_xml(FILE *fp)
int usage(const char *program)
int parseargs(int argc, char **argv)
void xml_put_det(const char *name, FILE *fp)
void xml_output_ts(const char *fname, REAL8TimeSeries *series)
void xml_put_stream(REAL8Vector *vector, double dx, FILE *fp)
void xml_begin_freq_series(FILE *fp)
void xml_end_xml(FILE *fp)
void xml_put_f0(double f0, FILE *fp)
void xml_end_array(FILE *fp)
void gnuplot_output_ts(const char *fname, const char *fmt, REAL8TimeSeries *series)
void output_ts(const char *fname, REAL8TimeSeries *series)
void xml_end_series(FILE *fp)
void xml_put_gps(LIGOTimeGPS *epoch, FILE *fp)
void xml_output_fs(const char *fname, REAL8FrequencySeries *series)
void gnuplot_output_fs(const char *fname, const char *fmt, REAL8FrequencySeries *series)
void output_fs(const char *fname, REAL8FrequencySeries *series)
void xml_begin_freq_array(REAL8FrequencySeries *series, FILE *fp)