Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
view.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/* vim: set noet ts=4 sw=4: */
21#include <complex.h>
22#include <math.h>
23#include <stdarg.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28#include <lal/LALFrameIO.h>
29#include <lal/LALgetopt.h>
30#include <lal/LALCache.h>
31#include <lal/LALFrStream.h>
32#include <lal/BandPassTimeSeries.h>
33#include <lal/Date.h>
34#include <lal/TimeSeries.h>
35#include <lal/FrequencySeries.h>
36#include <lal/ResampleTimeSeries.h>
37#include <lal/Audio.h>
38#include <lal/Window.h>
39#include <lal/RealFFT.h>
40#include <lal/TimeFreqFFT.h>
41#include <lal/Units.h>
42#include <lal/LIGOMetadataTables.h>
43#include <lal/LIGOMetadataUtils.h>
44#include <lal/SnglBurstUtils.h>
45#include <lal/LIGOLwXML.h>
46#include <lal/LIGOLwXMLRead.h>
47#include <lal/FindChirp.h>
48#include <lal/GenerateBurst.h>
49
50
51
52/* output type enumeration */
54
55/* input data enumeration */
57
63const char *channel_ = NULL;
64const char *datafile_ = NULL;
65const char *calibfile_ = NULL;
66const char *inspinjfile_ = NULL;
67const char *burstinjfile_ = NULL;
68const char *outfile_ = NULL;
71int texactflg_ = 0;
73int calibflg_ = 0;
77int debugflg_ = 0;
78
79int verbose( const char *fmt, ... );
80int usage( const char *program );
81int parseopts( int argc, char **argv );
82int dbg_tsdump( REAL4TimeSeries *series, const char *fname );
85REAL4TimeSeries * setdata( int intype, const char *channel, LIGOTimeGPS *start, REAL8 duration, REAL8 samplerate );
86REAL4TimeSeries * getdata( const char *path, int cachefileflg, const char *channel, LIGOTimeGPS *start, REAL8 duration );
87// COMPLEX8FrequencySeries * getresp( const char *calibfile, const char *channel, LIGOTimeGPS *epoch, REAL4 deltaF, UINT4 seglen, REAL8 dynrange );
88int inspinj( REAL4TimeSeries *series, const char *inspinjfile, const char *calfile );
89int burstinj( REAL4TimeSeries *series, const char *burstinjfile, const char *calfile );
91int filter( REAL4TimeSeries *series, REAL8 minfreq, REAL8 maxfreq );
92int calibrate( REAL4TimeSeries *tseries, const char *calfile, REAL8 f_min );
93REAL4FrequencySeries * powerspec( REAL4TimeSeries *series, REAL8 segdur, LIGOTimeGPS *epoch, const char *calibfile, int intype );
95int output( const char *outfile, int outtype, REAL4TimeSeries *series );
96
97
98int main( int argc, char *argv[] )
99{
101 REAL8 segdur = 0.0;
102 REAL8 discard;
103 UINT4 ndiscard;
104
106
107 parseopts( argc, argv );
108
109 discard = duration_;
110 if ( outtype_ == PSD_OUTPUT ) {
111 /* power spectrum: acutal duration required is more */
113 duration_ = ( duration_ * ( numave_ + 1 ) ) / 2;
114 }
115 duration_ += discard; /* we'll discard data from beginning and end */
116
117 /* if we want result to start at exactly the right time, need to start
118 * reading so much earlier */
119 if ( texactflg_ )
120 XLALGPSAdd( &start_, -0.5*discard );
121
122 /* get the data */
123 if ( intype_ == READ_INPUT )
125 else
127
128 dbg_tsdump( series, "tseries0.dat" );
129
130 /* inject inspirals and bursts */
133
134 dbg_tsdump( series, "tseries1.dat" );
135
136 /* condition the data */
139 if ( calibflg_ && outtype_ != PSD_OUTPUT ) /* calibrate elsewhere if doing a psd */
141
142 dbg_tsdump( series, "tseries2.dat" );
143
144 /* discarding extra data from beginning and end */
145 ndiscard = 0.5 * discard / series->deltaT;
146 XLALResizeREAL4TimeSeries( series, ndiscard, series->data->length - 2*ndiscard);
147
148 /* output results */
149 if ( outtype_ == PSD_OUTPUT ) { /* power spectrum */
150 REAL4FrequencySeries *spectrum;
151 if ( calibflg_ )
152 spectrum = powerspec( series, segdur, &start_, calibfile_, intype_ );
153 else
154 spectrum = powerspec( series, segdur, &start_, NULL, intype_ );
155 output_psd( outfile_, spectrum );
156 } else
158
159 return 0;
160}
161
162
163int parseopts( int argc, char **argv )
164{
165 struct LALoption long_options[] = {
166 { "help", no_argument, 0, 'h' },
167 { "power-spectrum", required_argument, 0, 'P' },
168 { "gps-start-time", required_argument, 0, 't' },
169 { "exact-gps-start-time", required_argument, 0, 'T' },
170 { "duration", required_argument, 0, 'd' },
171 { "min-frequency", required_argument, 0, 'm' },
172 { "max-frequency", required_argument, 0, 'M' },
173 { "channel-name", required_argument, 0, 'c' },
174 { "calibration-file", required_argument, 0, 'C' },
175 { "frame-files", required_argument, 0, 'f' },
176 { "cache-file", required_argument, 0, 'F' },
177 { "output-file", required_argument, 0, 'o' },
178 { "output-type", required_argument, 0, 'O' },
179 { "sample-rate", required_argument, 0, 's' },
180 { "inject-inspiral", required_argument, 0, 'I' },
181 { "inject-burst", required_argument, 0, 'B' },
182 { "unit-impulse", no_argument, 0, '1' },
183 { "zero-data", no_argument, 0, '0' },
184 { "no-calibration", no_argument, &calibflg_, 0 },
185 { "verbose", no_argument, &verboseflg_, 1 },
186 { "debug", no_argument, &debugflg_, 1 },
187 { 0, 0, 0, 0 } };
188 char args[] = "01P:t:T:d:m:M:c:C:f:F:o:O:s:I:B:";
189
190 while ( 1 ) {
191 int option_index = 0;
192 int c;
193 c = LALgetopt_long_only( argc, argv, args, long_options, &option_index );
194 if ( c == -1 )
195 break;
196 switch ( c ) {
197 case 0:
198 if ( long_options[option_index].flag )
199 break; /* option set flag: nothing else to do */
200 fprintf( stderr, "error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg );
201 exit( 1 );
202 case '0':
204 break;
205 case '1':
207 break;
208 case 'h':
209 usage( argv[0] );
210 exit( 0 );
211 case 'P':
212 numave_ = atoi( LALoptarg );
214 break;
215 case 't':
216 XLALStrToGPS( &start_, LALoptarg, NULL );
217 texactflg_ = 0;
218 break;
219 case 'T':
220 XLALStrToGPS( &start_, LALoptarg, NULL );
221 texactflg_ = 1;
222 break;
223 case 'c':
225 break;
226 case 'C':
228 calibflg_ = 1;
229 break;
230 case 'f':
231 cachefileflg_ = 0;
233 break;
234 case 'F':
235 cachefileflg_ = 1;
237 break;
238 case 'I':
240 break;
241 case 'B':
243 break;
244 case 'd':
245 duration_ = atof( LALoptarg );
246 break;
247 case 'o':
249 break;
250 case 'O':
251 if ( strstr( LALoptarg, "ASC" ) || strstr( LALoptarg, "asc" ) )
253 else if ( strstr( LALoptarg, "WAV" ) || strstr( LALoptarg, "wav" ) )
255 else if ( strstr( LALoptarg, "AU" ) || strstr( LALoptarg, "au" ) )
257 else {
258 fprintf( stderr, "error: unrecognized output type\n" );
259 exit( 1 );
260 }
261 break;
262 case 's':
263 srate_ = atof( LALoptarg );
264 break;
265 case 'm':
266 minfreq_ = atof( LALoptarg );
267 break;
268 case 'M':
269 maxfreq_ = atof( LALoptarg );
270 break;
271 case '?':
272 default:
273 fprintf( stderr, "unknown error while parsing options\n" );
274 exit( 1 );
275 }
276 }
277
278 if ( LALoptind < argc ) {
279 fprintf( stderr, "extraneous command line arguments:\n" );
280 while ( LALoptind < argc )
281 fprintf( stderr, "%s\n", argv[LALoptind++] );
282 exit( 1 );
283 }
284
285 return 0;
286}
287
288
289REAL4TimeSeries * setdata( int intype, const char *channel, LIGOTimeGPS *start, REAL8 duration, REAL8 samplerate )
290{
292 UINT4 length;
293 UINT4 i;
294
295 verbose( "generating %g seconds of %s data starting at time %d.%09d\n",
296 duration, channel, start->gpsSeconds, start->gpsNanoSeconds );
297
298 length = duration * samplerate;
299 series = XLALCreateREAL4TimeSeries( channel, start, 0, 1.0/samplerate, &lalADCCountUnit, length );
300 for ( i = 0; i < series->data->length; ++i )
301 series->data->data[i] = 0;
302 if ( intype == IMPULSE_INPUT )
303 series->data->data[series->data->length/2] = 1.0;
304 return series;
305}
306
307REAL4TimeSeries * getdata( const char *path, int cachefileflg, const char *channel, LIGOTimeGPS *start, REAL8 duration )
308{
309 LALCache *cache = NULL;
310 LALFrStream *stream = NULL;
312 int tstype;
314
315 verbose( "reading %g seconds of %s data starting at time %d.%09d\n",
316 duration, channel, start->gpsSeconds, start->gpsNanoSeconds );
317
318 /* open the data cache and use it to get a frame stream */
319 if ( cachefileflg ) {
320 verbose( "importing cache file %s\n", path );
322 } else {
323 char pathcpy[FILENAME_MAX];
324 char *basename;
325 char *dirname = NULL;
326 strncpy( pathcpy, path, sizeof(pathcpy) - 1 );
327 basename = strrchr( pathcpy, '/' );
328 if ( basename ) {
329 *basename++ = 0;
330 dirname = pathcpy;
331 } else {
332 basename = pathcpy;
333 dirname = NULL;
334 }
335 verbose( "using data file(s) %s\n", path );
336 cache = XLALCacheGlob( dirname, basename );
337 }
338 stream = XLALFrStreamCacheOpen( cache );
340
341 /* set the mode of the frame stream */
342 XLALFrStreamSetMode( stream, mode );
343
344 tstype = XLALFrStreamGetTimeSeriesType( channel, stream );
345 if ( tstype == LAL_S_TYPE_CODE ) {
347 } else if ( tstype == LAL_D_TYPE_CODE ) { /* assume strain data */
348 REAL8TimeSeries *dblseries;
349 UINT4 i;
350 dynrange_ = 1e20;
351 dblseries = XLALFrStreamReadREAL8TimeSeries( stream, channel, start, duration, 0 );
352 /* TODO: this shouldn't be hard-coded! */
353 XLALHighPassREAL8TimeSeries( dblseries, 40.0, 0.9, 8 );
354 series = XLALCreateREAL4TimeSeries( dblseries->name, &dblseries->epoch, dblseries->f0, dblseries->deltaT, &dblseries->sampleUnits, dblseries->data->length );
355 for ( i = 0; i < series->data->length; ++i )
356 series->data->data[i] = dynrange_ * dblseries->data->data[i];
357 } else {
358 return NULL;
359 }
360
361 /* close the stream */
362 XLALFrStreamClose( stream );
363
364 return series;
365}
366
367#if 0
368COMPLEX8FrequencySeries * getresp( const char *calibfile, const char *channel, LIGOTimeGPS *epoch, REAL4 deltaF, UINT4 seglen, REAL8 dynrange )
369{
370 if ( ! calibfile )
371 return NULL;
372
373 XLAL_ERROR_NULL(XLAL_EERR, "Calibration frames no longer supported");
374}
375#endif
376
377
378int inspinj( REAL4TimeSeries *series, const char *inspinjfile, const char *calfile )
379{
380 static LALStatus status;
382 COMPLEX8FrequencySeries *response;
383 REAL4TimeSeries keep;
384 // REAL8 deltaF;
385
386 if ( ! inspinjfile )
387 return 0;
388 if ( ! calfile ) {
389 fprintf( stderr, "warning: cannot perform injections without calibration\n" );
390 return 0;
391 }
392
394
395 if ( !injections ) {
396 fprintf( stderr, "error: could not read file %s\n", inspinjfile );
397 exit( 1 );
398 }
399 verbose( "injecting inspirals listed in file %s\n", inspinjfile );
400
401 // deltaF = 1.0 / ( series->deltaT * series->data->length );
402 // response = getresp( calfile, series->name, &series->epoch, deltaF, series->data->length, 1.0 );
403 response = NULL;
404 keep = *series;
406 *series = keep;
407 if ( status.statusCode ) {
408 fprintf( stderr, "error: signal injection failed\n" );
409 exit( 1 );
410 }
411
412 while ( injections ) {
413 SimInspiralTable *thisInjection = injections;
415 LALFree( thisInjection );
416 }
418
419 return 0;
420}
421
422
423int burstinj( REAL4TimeSeries *series, const char *burstinjfile, const char *calfile )
424{
425 TimeSlide *time_slide;
426 SimBurst *sim_burst;
428 COMPLEX8FrequencySeries *response;
429 // REAL8 deltaF;
430 unsigned i;
431
432 if ( ! burstinjfile )
433 return 0;
434 if ( ! calfile ) {
435 fprintf( stderr, "warning: cannot perform injections without calibration\n" );
436 return 0;
437 }
438
439 time_slide = XLALTimeSlideTableFromLIGOLw( burstinjfile );
440 sim_burst = XLALSimBurstTableFromLIGOLw( burstinjfile );
441 if ( !sim_burst || !time_slide ) {
442 fprintf( stderr, "error: could not read file %s\n", burstinjfile );
443 exit( 1 );
444 }
445
446 verbose( "injecting bursts listed in file %s\n", burstinjfile );
447
448 // deltaF = 1.0 / ( series->deltaT * series->data->length );
449 // response = getresp( calfile, series->name, &series->epoch, deltaF, series->data->length, 1.0 );
450 response = NULL;
451
452 injections = XLALCreateREAL8TimeSeries(series->name, &series->epoch, series->f0, series->deltaT, &series->sampleUnits, series->data->length);
453 /* FIXME: new injection code requires double precision respose */
454 //if(XLALBurstInjectSignals( injections, sim_burst, time_slide, /*response*/ NULL )) {
455 // fprintf( stderr, "error: signal injection failed\n" );
456 // exit( 1 );
457 //}
458 for(i = 0; i < series->data->length; i++)
459 series->data->data[i] += injections->data->data[i];
461
462 XLALDestroyTimeSlideTable(time_slide);
463 XLALDestroySimBurstTable(sim_burst);
465
466 return 0;
467}
468
469
471{
472 if ( srate > 0 ) {
473 verbose( "resampling to rate %g Hz\n", srate );
475 }
476 return 0;
477}
478
479int filter( REAL4TimeSeries *series, REAL8 minfreq, REAL8 maxfreq )
480{
481 const INT4 filtorder = 8;
482 const REAL8 amplitude = 0.9; /* 10% attenuation at specified frequency */
483
484 if ( minfreq > 0 ) {
485 verbose( "high-pass filtering at frequency %g Hz\n", minfreq );
486 XLALHighPassREAL4TimeSeries( series, minfreq, amplitude, filtorder );
487 }
488 if ( maxfreq > 0 ) {
489 verbose( "low-pass filtering at frequency %g Hz\n", maxfreq );
490 XLALLowPassREAL4TimeSeries( series, maxfreq, amplitude, filtorder );
491 }
492
493 return 0;
494}
495
496int calibrate( REAL4TimeSeries *tseries, const char *calfile, REAL8 f_min )
497{
498 COMPLEX8FrequencySeries *response;
500 REAL4FFTPlan *pfwd, *prev;
501 // REAL8 deltaF;
502 UINT4 kmin, k;
503
504 if ( ! calfile )
505 return 0;
506
507 verbose( "calibrating data\n" );
508
509 pfwd = XLALCreateForwardREAL4FFTPlan( tseries->data->length, 0 );
510 prev = XLALCreateReverseREAL4FFTPlan( tseries->data->length, 0 );
511
512 fseries = XLALCreateCOMPLEX8FrequencySeries( tseries->name, &tseries->epoch, 0, 1.0/tseries->deltaT, &lalDimensionlessUnit, tseries->data->length/2 + 1 );
513 XLALREAL4TimeFreqFFT( fseries, tseries, pfwd );
514
515 // deltaF = 1.0 / ( tseries->deltaT * tseries->data->length );
516 dynrange_ = 1e20;
517 // response = getresp( calfile, tseries->name, &tseries->epoch, deltaF, tseries->data->length, dynrange_ );
518 response = NULL;
519
520 if ( f_min < 30.0 ) {
521 fprintf( stderr, "warning: setting minimum frequency to 30 Hz for calibration\n" );
522 f_min = 30.0;
523 }
524 kmin = f_min / fseries->deltaF;
525 for ( k = 0; k < kmin; ++k )
526 fseries->data->data[k] = 0.0;
527 for ( k = kmin; k < fseries->data->length; ++k )
528 fseries->data->data[k] = fseries->data->data[k] * response->data->data[k];
529 XLALREAL4FreqTimeFFT( tseries, fseries, prev );
530
535 return 0;
536}
537
538REAL4FrequencySeries * powerspec( REAL4TimeSeries *series, REAL8 segdur, LIGOTimeGPS *epoch, const char *calibfile, int intype )
539{
540 REAL4FrequencySeries *spectrum;
542 UINT4 stride;
543 seglen = segdur / series->deltaT;
544 stride = seglen / 2;
545
546
547 spectrum = XLALCreateREAL4FrequencySeries( "spectrum", epoch, 0.0, 1.0/segdur, &lalDimensionlessUnit, seglen/2 + 1 );
548 if ( intype != IMPULSE_INPUT ) {
549 REAL4FFTPlan *plan;
550 REAL4Window *window;
551 verbose( "computing power spectrum\n" );
554 XLALREAL4AverageSpectrumWelch( spectrum, series, seglen, stride, window, plan );
555 XLALDestroyREAL4Window( window );
557 } else { /* impulse input: set spectrum to unity */
558 UINT4 k;
559 verbose( "setting spectrum to be unity\n" );
560 spectrum->data->data[0] = 0.0;
561 for ( k = 1; k < spectrum->data->length; ++k )
562 spectrum->data->data[k] = 1.0;
563 }
564
565 if ( ! calibfile )
566 return spectrum;
567 else {
568 COMPLEX8FrequencySeries *response;
569 UINT4 k;
570 dynrange_ = 1e20;
571 // response = getresp( calibfile, series->name, &series->epoch, spectrum->deltaF, seglen, dynrange_ );
572 response = NULL;
573 for ( k = 1; k < spectrum->data->length; ++k ) {
574 REAL4 re = crealf(response->data->data[k]);
575 REAL4 im = cimagf(response->data->data[k]);
576 spectrum->data->data[k] *= re*re + im*im;
577 }
579 }
580
581 return spectrum;
582}
583
585{
586 UINT4 i;
587 FILE *fp;
588 fp = outfile ? fopen( outfile, "w" ) : stdout;
589
590 verbose( "output psd of %s data beginning at GPS time %d.%09d to file %s\n",
591 series->name, series->epoch.gpsSeconds,
592 series->epoch.gpsNanoSeconds, outfile );
593
594 /* note: omit DC */
595 for ( i = 1; i < series->data->length; ++i )
596 fprintf( fp, "%e\t%e\n", i * series->deltaF, sqrt( series->data->data[i] ) / dynrange_ );
597
598 if ( fp != stdout )
599 fclose( fp );
600 return 0;
601}
602
603int output( const char *outfile, int outtype, REAL4TimeSeries *series )
604{
605 UINT4 i;
606 FILE *fp;
607 fp = outfile ? fopen( outfile, "w" ) : stdout;
608
609 verbose( "output %s data beginning at GPS time %d.%09d to file %s\n",
610 series->name, series->epoch.gpsSeconds,
611 series->epoch.gpsNanoSeconds, outfile );
612
613 switch ( outtype ) {
614 case ASCII_OUTPUT:
615 for ( i = 0; i < series->data->length; ++i ) {
616 REAL8 val;
617 val = series->data->data[i];
618 val /= dynrange_;
619 fprintf( fp, "%.9f\t%e\n", i * series->deltaT, val );
620 }
621 break;
622 case WAVE_OUTPUT:
624 break;
625 case AU_OUTPUT:
627 break;
628 default:
629 fprintf( stderr, "error: invalid output type\n" );
630 exit( 1 );
631 }
632
633 if ( fp != stdout )
634 fclose( fp );
635 return 0;
636}
637
638int usage( const char * program )
639{
640 fprintf( stderr, "USAGE\n" );
641
642 fprintf( stderr, "\n" );
643 fprintf( stderr, "\t%s [options]\n", program );
644
645 fprintf( stderr, "\n" );
646 fprintf( stderr, "OPTIONS\n" );
647
648 fprintf( stderr, "\n" );
649 fprintf( stderr, "\t-c CHANNEL\n\t--channel-name=CHANNEL\n" );
650 fprintf( stderr, "\t\tread channel CHANNEL\n" );
651
652 fprintf( stderr, "\n" );
653 fprintf( stderr, "\t-C CALFILE\n\t--calibration-file=CALFILE\n" );
654 fprintf( stderr, "\t\tuse calibration file CALFILE\n" );
655 fprintf( stderr, "\t\tthis means that data will be calibrated\n" );
656 fprintf( stderr, "\t\tunless the --no-calibration option is used\n" );
657
658 fprintf( stderr, "\n" );
659 fprintf( stderr, "\t-d DURATION\n\t--duration=DURATION\n" );
660 fprintf( stderr, "\t\tread DURATION seconds of data\n" );
661
662 fprintf( stderr, "\n" );
663 fprintf( stderr, "\t-f FILES\n\t--frame-files=FILES\n" );
664 fprintf( stderr, "\t\tread data from frame files FILES\n" );
665
666 fprintf( stderr, "\n" );
667 fprintf( stderr, "\t-F CACHE\n\t--cache-file=CACHE\n" );
668 fprintf( stderr, "\t\tread data from files in frame cache file CACHE\n" );
669
670 fprintf( stderr, "\n" );
671 fprintf( stderr, "\t-h\n\t--help\n\t\tprint this message\n\n" );
672
673 fprintf( stderr, "\n" );
674 fprintf( stderr, "\t-m MINFREQ\n\t--min-frequency=MINFREQ\n" );
675 fprintf( stderr, "\t\thighpass data at MINFREQ hertz\n" );
676
677 fprintf( stderr, "\n" );
678 fprintf( stderr, "\t-M MAXFREQ\n\t--max-frequency=MAXNFREQ\n" );
679 fprintf( stderr, "\t\tlowpass data at MAXFREQ hertz\n" );
680
681 fprintf( stderr, "\n" );
682 fprintf( stderr, "\t-o OUTFILE\n\t--output-file=OUTFILE\n" );
683 fprintf( stderr, "\t\toutput to file OUTFILE\n" );
684
685 fprintf( stderr, "\n" );
686 fprintf( stderr, "\t-O OTYPE\n\t--output-type=OTYPE\n" );
687 fprintf( stderr, "\t\toutput data type OTYPE [ \"ASCII\" | \"AU\" | \"WAVE\" ]\n" );
688
689 fprintf( stderr, "\n" );
690 fprintf( stderr, "\t-P NUMAVG\n\t--power-spectrum=NUMAVE\n" );
691 fprintf( stderr, "\t\tcompute power spectrum with NUMAVE averages\n" );
692
693 fprintf( stderr, "\n" );
694 fprintf( stderr, "\t-s SRATE\n\t--sample-rate=SRATE\n" );
695 fprintf( stderr, "\t\tresample to sample rate SRATE hertz\n" );
696
697 fprintf( stderr, "\n" );
698 fprintf( stderr, "\t-t GPSTIME\n\t--gps-start-time=GPSTIME\n" );
699 fprintf( stderr, "\t\tstart reading data at time GPSTIME\n" );
700 fprintf( stderr, "\t\tnote: output results for data a little later\n" );
701
702 fprintf( stderr, "\n" );
703 fprintf( stderr, "\t-T GPSTIME\n\t--exact-gps-start-time=GPSTIME\n" );
704 fprintf( stderr, "\t\tdata output for EXACTLY time GPSTIME\n" );
705 fprintf( stderr, "\t\tnote: data must exist before this time\n" );
706
707 fprintf( stderr, "\n" );
708 fprintf( stderr, "\t--no-calibration\n" );
709 fprintf( stderr, "\t\tdo not apply response function to data\n" );
710 fprintf( stderr, "\t\t(it may still be required for injections)\n" );
711
712 fprintf( stderr, "\n" );
713 fprintf( stderr, "\t--verbose\n" );
714 fprintf( stderr, "\t\tprint messages describing actions that are taken\n" );
715
716 fprintf( stderr, "\n" );
717 fprintf( stderr, "\t--debug\n" );
718 fprintf( stderr, "\t\tdump intermediate products to data files\n" );
719
720 fprintf( stderr, "\n" );
721 fprintf( stderr, "EXAMPLES\n" );
722
723 fprintf( stderr, "\n" );
724 fprintf( stderr, "\tRead some data, condition it, and write it as an audio file\n" );
725 fprintf( stderr, "\n\t\t%s --verbose --channel L1:LSC-DARM_ERR --frame-files=L-RDS_R_L3-795259680-256.gwf --min-frequency=80 --max-frequency=500 --sample-rate=1024 --output-file=data.au --output-type=au --gps-start-time=795259680\n", program );
726
727 fprintf( stderr, "\n" );
728 fprintf( stderr, "\tImpulse response of the response function\n" );
729 fprintf( stderr, "\n\t\t%s --verbose --channel L1:LSC-DARM_ERR --calibration-file=L-L1_CAL_S4_V4-793128493-2801040.gwf --min-frequency=30 --max-frequency=500 --unit-impulse --output-file=resp.dat --gps-start-time=795259680", program );
730
731 fprintf( stderr, "\n" );
732 fprintf( stderr, "\tPower spectrum of the response function\n" );
733 fprintf( stderr, "\n\t\t%s --verbose --channel L1:LSC-DARM_ERR --calibration-file=L-L1_CAL_S4_V4-793128493-2801040.gwf --unit-impulse --output-file=rpsd.dat --gps-start-time=795259680 --power-spectrum=1", program );
734
735 fprintf( stderr, "\n" );
736 fprintf( stderr, "\tMake a strain sensitivity curve with 32 averages\n" );
737 fprintf( stderr, "\n\t\t%s --channel=L1:LSC-DARM_ERR --calibration-file=L-L1_CAL_S4_V4-793128493-2801040.gwf --duration=16 --frame-file=\"L-RDS_R_L3-*.gwf\" --output-file=spec.dat --gps-start-time=795259680 --power-spectrum=32\n", program );
738 fprintf( stderr, "\n\t(note quotes around wildcard in --frame-file option)\n" );
739 fprintf( stderr, "\n" );
740 fprintf( stderr, "\tMake an audio file of a chirp injected into strain data\n"
741 "\tresampled to 1024 Hz and high-pass filtered at 70 Hz\n" );
742 fprintf( stderr, "\n\t\t%s -c L1:LSC-DARM_ERR -C L-L1_CAL_S4_V4-793128493-2801040.gwf -d 16 -f L-RDS_R_L3-795259680-256.gwf -m 70 -o chirph.au -s 1024 -t 795259680 -I inj.xml -O au\n", program );
743 fprintf( stderr, "\n" );
744 fprintf( stderr, "\tAs above but in terms of ADC counts rather than strain\n" );
745 fprintf( stderr, "\n\t\t%s -c L1:LSC-DARM_ERR -C L-L1_CAL_S4_V4-793128493-2801040.gwf -d 16 -f L-RDS_R_L3-795259680-256.gwf -m 70 -o chirpv.au -s 1024 -t 795259680 -I inj.xml -O au --no-cal\n", program );
746 fprintf( stderr, "\n" );
747 fprintf( stderr, "\tAs above but just with the injection (no data!)\n" );
748 fprintf( stderr, "\n\t\t%s -c L1:LSC-DARM_ERR -C L-L1_CAL_S4_V4-793128493-2801040.gwf -d 16 -m 70 -o chirph.au -s 1024 -t 795259680 -I inj.xml -O au --no-cal -0\n", program );
749
750 return 0;
751}
752
753
755{
756 if ( debugflg_ ) {
757 UINT4 j;
758 FILE *fp;
759 fp = fopen( fname, "w" );
760 for ( j = 0; j < series->data->length; ++j )
761 fprintf( fp, "%.9f\t%e\n", j * series->deltaT, series->data->data[j] );
762 fclose( fp );
763 }
764 return 0;
765}
766
768{
769 if ( debugflg_ ) {
770 UINT4 k;
771 FILE *fp;
772 fp = fopen( fname, "w" );
773 for ( k = 1; k < series->data->length; ++k )
774 fprintf( fp, "%e\t%e\t%e\n", k * series->deltaF,
775 cabsf(series->data->data[k]), cargf(series->data->data[k]) );
776 fclose( fp );
777 }
778 return 0;
779}
780
782{
783 if ( debugflg_ ) {
784 UINT4 k;
785 FILE *fp;
786 fp = fopen( fname, "w" );
787 for ( k = 1; k < series->data->length; ++k )
788 fprintf( fp, "%e\t%e\n", k * series->deltaF, series->data->data[k] );
789 fclose( fp );
790 }
791 return 0;
792}
793
794int verbose( const char *fmt, ... )
795{
796 if ( verboseflg_ ) {
797 va_list ap;
798 va_start( ap, fmt );
799 fprintf( stderr, "verbose: " );
800 vfprintf( stderr, fmt, ap );
801 va_end( ap );
802 }
803 return 0;
804}
int XLALHighPassREAL4TimeSeries(REAL4TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
int XLALLowPassREAL4TimeSeries(REAL4TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
int XLALHighPassREAL8TimeSeries(REAL8TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
const char * program
int XLALStrToGPS(LIGOTimeGPS *t, const char *nptr, char **endptr)
void LALFindChirpInjectSignals(LALStatus *status, REAL4TimeSeries *chan, SimInspiralTable *events, COMPLEX8FrequencySeries *resp)
int j
int k
#define LALFree(p)
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALoptind
char * LALoptarg
#define no_argument
#define required_argument
TimeSlide * XLALTimeSlideTableFromLIGOLw(const char *filename)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(const char *fileName)
SimBurst * XLALSimBurstTableFromLIGOLw(const char *filename)
void XLALDestroyTimeSlideTable(TimeSlide *)
void XLALDestroySimBurstTable(SimBurst *head)
#define fprintf
INT4 duration
Definition: blindinj.c:123
double segdur
int XLALAudioWAVRecordREAL4TimeSeries(FILE *fp, REAL4TimeSeries *series)
int XLALAudioAURecordREAL4TimeSeries(FILE *fp, REAL4TimeSeries *series)
void XLALDestroyCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries *series)
REAL4FrequencySeries * XLALCreateREAL4FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
COMPLEX8FrequencySeries * XLALCreateCOMPLEX8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheGlob(const char *dirstr, const char *fnptrn)
LALCache * XLALCacheImport(const char *fname)
double REAL8
uint32_t UINT4
int32_t INT4
float REAL4
LAL_S_TYPE_CODE
LAL_D_TYPE_CODE
int XLALFrStreamClose(LALFrStream *stream)
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
int XLALFrStreamSetMode(LALFrStream *stream, int mode)
LAL_FR_STREAM_VERBOSE_MODE
LALTYPECODE XLALFrStreamGetTimeSeriesType(const char *chname, LALFrStream *stream)
REAL8TimeSeries * XLALFrStreamReadREAL8TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
REAL4TimeSeries * XLALFrStreamReadREAL4TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
REAL4FFTPlan * XLALCreateReverseREAL4FFTPlan(UINT4 size, int measurelvl)
REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan(UINT4 size, int measurelvl)
void XLALDestroyREAL4FFTPlan(REAL4FFTPlan *plan)
int XLALResampleREAL4TimeSeries(REAL4TimeSeries *series, REAL8 dt)
int XLALREAL4AverageSpectrumWelch(REAL4FrequencySeries *spectrum, const REAL4TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL4Window *window, const REAL4FFTPlan *plan)
int XLALREAL4FreqTimeFFT(REAL4TimeSeries *tser, const COMPLEX8FrequencySeries *freq, const REAL4FFTPlan *plan)
int XLALREAL4TimeFreqFFT(COMPLEX8FrequencySeries *freq, const REAL4TimeSeries *tser, const REAL4FFTPlan *plan)
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
REAL4TimeSeries * XLALResizeREAL4TimeSeries(REAL4TimeSeries *series, int first, size_t length)
const LALUnit lalADCCountUnit
const LALUnit lalDimensionlessUnit
void XLALDestroyREAL4Window(REAL4Window *window)
REAL4Window * XLALCreateHannREAL4Window(UINT4 length)
#define XLAL_ERROR_NULL(...)
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
XLAL_EERR
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
SimInspiralTable * injections
Definition: inspfrinj.c:339
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
args
fmt
path
c
seglen
fseries
string mode
kmin
start
CHAR fname[256]
Definition: spininj.c:211
char * channel
COMPLEX8Sequence * data
COMPLEX8 * data
INT4 statusCode
int * flag
REAL4Sequence * data
CHAR name[LALNameLength]
REAL4Sequence * data
LIGOTimeGPS epoch
REAL4 * data
REAL8Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
CHAR name[LALNameLength]
REAL8 * data
struct tagSimInspiralTable * next
Definition: series.h:36
char * name
Definition: series.h:37
float f0
Definition: series.h:43
float * data
Definition: series.h:46
FILE * fp
enum @1 epoch
double f_min
int inspinj(REAL4TimeSeries *series, const char *inspinjfile, const char *calfile)
Definition: view.c:378
int verboseflg_
Definition: view.c:76
@ AU_OUTPUT
Definition: view.c:53
@ WAVE_OUTPUT
Definition: view.c:53
@ PSD_OUTPUT
Definition: view.c:53
@ ASCII_OUTPUT
Definition: view.c:53
int main(int argc, char *argv[])
Definition: view.c:98
const char * inspinjfile_
Definition: view.c:66
int verbose(const char *fmt,...)
Definition: view.c:794
const char * datafile_
Definition: view.c:64
REAL4TimeSeries * setdata(int intype, const char *channel, LIGOTimeGPS *start, REAL8 duration, REAL8 samplerate)
Definition: view.c:289
int parseopts(int argc, char **argv)
Definition: view.c:163
int usage(const char *program)
Definition: view.c:638
int dbg_fsdump(COMPLEX8FrequencySeries *series, const char *fname)
Definition: view.c:767
int texactflg_
Definition: view.c:71
int debugflg_
Definition: view.c:77
const char * burstinjfile_
Definition: view.c:67
REAL4FrequencySeries * powerspec(REAL4TimeSeries *series, REAL8 segdur, LIGOTimeGPS *epoch, const char *calibfile, int intype)
Definition: view.c:538
REAL8 maxfreq_
Definition: view.c:60
REAL8 dynrange_
Definition: view.c:70
const char * calibfile_
Definition: view.c:65
int calibflg_
Definition: view.c:73
REAL8 srate_
Definition: view.c:61
const char * channel_
Definition: view.c:63
int cachefileflg_
Definition: view.c:72
int burstinj(REAL4TimeSeries *series, const char *burstinjfile, const char *calfile)
Definition: view.c:423
REAL4TimeSeries * getdata(const char *path, int cachefileflg, const char *channel, LIGOTimeGPS *start, REAL8 duration)
Definition: view.c:307
int dbg_specdump(REAL4FrequencySeries *series, const char *fname)
Definition: view.c:781
UINT4 numave_
Definition: view.c:69
int calibrate(REAL4TimeSeries *tseries, const char *calfile, REAL8 f_min)
Definition: view.c:496
int dbg_tsdump(REAL4TimeSeries *series, const char *fname)
Definition: view.c:754
int resample(REAL4TimeSeries *series, REAL8 srate)
Definition: view.c:470
int filter(REAL4TimeSeries *series, REAL8 minfreq, REAL8 maxfreq)
Definition: view.c:479
const char * outfile_
Definition: view.c:68
int outtype_
Definition: view.c:74
int output_psd(const char *outfile, REAL4FrequencySeries *series)
Definition: view.c:584
REAL8 duration_
Definition: view.c:62
int intype_
Definition: view.c:75
@ IMPULSE_INPUT
Definition: view.c:56
@ ZERO_INPUT
Definition: view.c:56
@ READ_INPUT
Definition: view.c:56
LIGOTimeGPS start_
Definition: view.c:58
REAL8 minfreq_
Definition: view.c:59
int output(const char *outfile, int outtype, REAL4TimeSeries *series)
Definition: view.c:603
double maxfreq
double srate
double minfreq