LALApps 10.1.0.1-eeff03c
calfacs.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Patrick Brady
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/**
21 * \author Jolien D. E. Creighton
22 * \file
23 * \ingroup lalapps_frametools
24 */
25
26#include <stdio.h>
27#include <math.h>
28
29#include <lal/LALStdlib.h>
30#include <lal/LALConstants.h>
31#include <lal/AVFactories.h>
32#include <lal/PrintFTSeries.h>
33#include <lal/LALFrStream.h>
34#include <lal/Units.h>
35#include <lal/BandPassTimeSeries.h>
36
37#define TRUE 1
38#define FALSE 0
39
40#define FRAMEHEARSEEC_ENORM 0
41#define FRAMEHEARSEEC_EARG 2
42
43#define FRAMEHEARSEEC_MSGENORM "Normal exit"
44#define FRAMEHEARSEEC_MSGEARG "Error parsing arguments"
45
46/* Usage format string. */
47#define USAGE "Usage: %s [options] | xmgr -pipe\n"\
48 " --help Print this help message\n" \
49 " --channel name Name of frame channel\n" \
50 " [--duration secs] How many seconds to look at\n"\
51 " [--epoch sec nsec] The starting epoch\n"\
52 " [--framedir dirname] Directory containing frame files\n"\
53 " [--freq frequency] Frequency of line\n"\
54 " [--numpts npoints] Points to use\n"
55
56
57#include <config.h>
58#ifndef HAVE_LIBLALFRAME
59int main( void )
60{
61 fputs( "Disabled: LALApps compiled with non-frame-enabled LAL\n", stderr );
62 return 77;
63}
64#else
65
66#if 0
67/* This routine is pipes output into the xmgr graphing program */
68void graphout(float x1,float x2,int thistime, int last) {
69 static int count=0;
70 printf("&\n"); /* end of set marker */
71 /* first time we draw the plot */
72 if (count==0) {
73 printf("@doublebuffer true\n"); /* keeps display from flashing */
74 printf("@s0 color 3\n"); /* IFO graph is green */
75 printf("@view 0.1, 0.1, 0.9, 0.45\n"); /* set the viewport for IFO */
76 printf("@with g1\n"); /* reset the current graph to FFT */
77 printf("@view 0.1, 0.6, 0.9, 0.95\n");/* set the viewport FFT */
78 printf("@with g0\n"); /* reset the current graph to IFO */
79 printf("@world xmin %f\n",x1); /* set min x */
80 printf("@world xmax %f\n",x2); /* set max x */
81 printf("@autoscale\n"); /* autoscale first time through */
82 printf("@focus off\n"); /* turn off the focus markers */
83 printf("@xaxis label \"t (sec)\"\n"); /* IFO axis label */
84 printf("@fft(s0, 1)\n"); /* compute the spectrum */
85 printf("@s1 color 2\n"); /* FFT is red */
86 printf("@move g0.s1 to g1.s0\n"); /* move FFT to graph 1 */
87 printf("@with g1\n"); /* set the focus on FFT */
88 printf("@g1 type logy\n"); /* set FFT to log freq axis */
89 printf("@autoscale\n"); /* autoscale FFT */
90 printf("@subtitle \"Spectrum\"\n"); /* set the subtitle */
91 printf("@xaxis label \"f (Hz)\"\n"); /* FFT axis label */
92 printf("@with g0\n"); /* reset the current graph IFO */
93 printf("@subtitle \"IFO output %d\"\n",thistime);/* set IFO subtitle */
94 count++;/* set IFO subtitle */
95 if (!last) printf("@kill s0\n"); /* kill IFO; ready to read again */
96 }
97 else {
98 /* other times we redraw the plot */
99 printf("@s0 color 3\n"); /* set IFO green */
100 printf("@fft(s0, 1)\n"); /* FFT it */
101 printf("@s1 color 2\n"); /* set FFT red */
102 printf("@move g0.s1 to g1.s0\n"); /* move FFT to graph 1 */
103 printf("@subtitle \"IFO output %d\"\n",thistime);/* set IFO subtitle */
104 count++;
105 printf("@world xmin %f\n",x1); /* set min x */
106 printf("@world xmax %f\n",x2); /* set max x */
107 printf("@autoscale yaxes\n"); /* autoscale IFO */
108 printf("@clear stack\n"); /* clear the stack */
109 if (!last) printf("@kill s0\n"); /* kill IFO data */
110 printf("@with g1\n"); /* switch to FFT */
111 printf("@g1 type logy\n"); /* set FFT to log freq axis */
112 printf("@clear stack\n"); /* clear stack */
113 if (!last) printf("@kill s0\n"); /* kill FFT */
114 printf("@with g0\n"); /* ready to read IFO again */
115 }
116 return;
117}
118#endif
119
120int main( int argc, char *argv[] )
121{
122 static LALStatus status;
123 LALFrStream *stream = NULL;
124 FrChanIn channelIn;
125 REAL4 numSeconds = 2.0, oreal, oimag, dt, omega = 0.0;
126 INT4 i, numPoints=4096, inarg = 1;
127 CHAR *dirname;
129 LIGOTimeGPS epoch = {0,0};
130 BOOLEAN epochSet = FALSE;
131 BOOLEAN highpass = FALSE;
132 PassBandParamStruc highpassParam;
133
134 /* set default values for input */
135 dirname = getenv( "LAL_FRAME_PATH" );
136
137 /* Set up for a highpass filter */
138 highpassParam.nMax = 4;
139 highpassParam.f1 = -1.0;
140 highpassParam.a1 = -1.0;
141
142 /*******************************************************************
143 * PARSE ARGUMENTS (arg stores the current position) *
144 *******************************************************************/
145
146 if (argc <= 1){
147 LALPrintError( USAGE, *argv );
148 return 0;
149 }
150
151 while ( inarg < argc ) {
152 /* Parse output file option. */
153 if ( !strcmp( argv[inarg], "--help" ) ) {
154 if ( argc > inarg + 1 ) {
155 inarg++;
156 fprintf(stderr,"Should be a usage message\n");
157 exit(0);
158 }else{
159 LALPrintError( USAGE , *argv );
160 return FRAMEHEARSEEC_EARG;
161 }
162 }
163 else if ( !strcmp( argv[inarg], "--epoch" ) ) {
164 if ( argc > inarg + 1 ) {
165 inarg++;
166 epoch.gpsSeconds = atoi( argv[inarg++] );
167 epoch.gpsNanoSeconds = atoi( argv[inarg++] );
168 epochSet = TRUE;
169 }else{
170 LALPrintError( USAGE, *argv );
171 return FRAMEHEARSEEC_EARG;
172 }
173 }
174 else if ( !strcmp( argv[inarg], "--numpts" ) ) {
175 if ( argc > inarg + 1 ) {
176 inarg++;
177 numPoints = atoi( argv[inarg++] );
178 }else{
179 LALPrintError( USAGE, *argv );
180 return FRAMEHEARSEEC_EARG;
181 }
182 }
183 else if ( !strcmp( argv[inarg], "--freq" ) ) {
184 if ( argc > inarg + 1 ) {
185 inarg++;
186 omega = 2.0* LAL_PI * atof( argv[inarg++] );
187 }else{
188 LALPrintError( USAGE, *argv );
189 return FRAMEHEARSEEC_EARG;
190 }
191 }
192 else if ( !strcmp( argv[inarg], "--highpass" ) ) {
193 if ( argc > inarg + 1 ) {
194 inarg++;
195 highpass = TRUE;
196 highpassParam.f2 = atof( argv[inarg++] );
197 highpassParam.a2 = atof( argv[inarg++] );
198 }else{
199 LALPrintError( USAGE, *argv );
200 return FRAMEHEARSEEC_EARG;
201 }
202 }
203 else if ( !strcmp( argv[inarg], "--duration" ) ) {
204 if ( argc > inarg + 1 ) {
205 inarg++;
206 numSeconds = atof( argv[inarg++] );
207 }else{
208 LALPrintError( USAGE, *argv );
209 return FRAMEHEARSEEC_EARG;
210 }
211 }
212 else if ( !strcmp( argv[inarg], "--channel" ) ) {
213 if ( argc > inarg + 1 ) {
214 inarg++;
215 channelIn.name = argv[inarg++];
216 channelIn.type = ADCDataChannel;
217 }else{
218 LALPrintError( USAGE, *argv );
219 return FRAMEHEARSEEC_EARG;
220 }
221 }
222 else if ( !strcmp( argv[inarg], "--framedir" ) ) {
223 if ( argc > inarg + 1 ) {
224 inarg++;
225 dirname = argv[inarg++];
226 }else{
227 LALPrintError( USAGE, *argv );
228 return FRAMEHEARSEEC_EARG;
229 }
230 }
231 /* Check for unrecognized options. */
232 else if ( argv[inarg][0] == '-' ) {
233 LALPrintError( USAGE, *argv );
234 return FRAMEHEARSEEC_EARG;
235 }
236 } /* End of argument parsing loop. */
237
238 /* Open frame stream */
239 LALFrOpen( &status, &stream, dirname, "*.gwf" );
240
241 /* Determine information about the channel */
242 series.data = NULL;
243 LALFrGetREAL4TimeSeries( &status, &series, &channelIn, stream);
244 if (epochSet ){
245 series.epoch.gpsSeconds = epoch.gpsSeconds;
246 series.epoch.gpsNanoSeconds = epoch.gpsNanoSeconds;
247 }
248 LALFrSeek(&status, &(series.epoch), stream);
249
250 /* allocate time series */
252
253 /* get the data */
254 LALFrGetREAL4TimeSeries( &status, &series, &channelIn, stream);
255 dt=series.deltaT;
256
257 while ( !(status.statusCode) &&
258 (series.epoch.gpsSeconds < epoch.gpsSeconds + (INT4)(numSeconds))){
259
260 /* filter it if the highpass parameters were set */
261 if (highpass){
262 LALButterworthREAL4TimeSeries(&status, &series, &highpassParam);
263 }
264
265 oreal = oimag = 0.0;
266 for (i=0; i<numPoints ; i++){
267 oreal += cos( omega*i*dt ) * series.data->data[i];
268 oimag += sin( omega*i*dt ) * series.data->data[i];
269 }
270
271 fprintf(stdout,"%i %i %e %e %e\n", epoch.gpsSeconds, (INT4)(numSeconds),
272 oreal, oimag, sqrt(oreal*oreal + oimag*oimag));
273
274 /* get the data */
275 LALFrGetREAL4TimeSeries( &status, &series, &channelIn, stream);
276 }
277
278 /* close the frame stream */
279 LALFrClose( &status, &stream );
280
281 /*
282 * output the sound file
283 * sprintf(fname, "%s", channelIn.name);
284 * LALTimeSeriesToSound( &status, tSeries, fname, 1);
285 */
286
287 /* clean up */
290 return 0;
291}
292
293#endif
void LALFrSeek(LALStatus *status, const LIGOTimeGPS *epoch, LALFrStream *stream)
#define ADCDataChannel
void LALFrOpen(LALStatus *status, LALFrStream **stream, const CHAR *dirname, const CHAR *pattern)
void LALFrGetREAL4TimeSeries(LALStatus *status, REAL4TimeSeries *series, FrChanIn *chanin, LALFrStream *stream)
void LALFrClose(LALStatus *status, LALFrStream **stream)
void LALCheckMemoryLeaks(void)
#define fprintf
#define USAGE
Definition: calfacs.c:47
int main(void)
Definition: calfacs.c:59
#define TRUE
Definition: calfacs.c:37
#define FALSE
Definition: calfacs.c:38
#define FRAMEHEARSEEC_EARG
Definition: calfacs.c:41
void LALButterworthREAL4TimeSeries(LALStatus *stat, REAL4TimeSeries *series, PassBandParamStruc *params)
#define LAL_PI
unsigned char BOOLEAN
char CHAR
int32_t INT4
float REAL4
int LALPrintError(const char *fmt,...)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALCreateVector(LALStatus *, REAL4Vector **, UINT4)
long long count
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
ChannelType type
const CHAR * name
INT4 statusCode
Definition: series.h:36
float * data
Definition: series.h:46
enum @1 epoch
INT4 numPoints
Definition: tmpltbank.c:399