animate.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Jolien Creighton, Patrick Brady
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /**** <lalVerbatim file="FrameStreamTestCV">
00021  * Author: Jolien D. E. Creighton
00022  * $Id: animate.c,v 1.3 2007/06/08 15:29:44 bema Exp $
00023  **** </lalVerbatim> */
00024 
00025 #include <stdio.h>
00026 #include <unistd.h>
00027 #include <FrameL.h>
00028 #include <math.h>
00029 #include <lal/LALStdlib.h>
00030 #include <lal/AVFactories.h>
00031 #include <lal/PrintFTSeries.h>
00032 #include <lal/FrameStream.h>
00033 #include <lal/LALMoment.h>
00034 #include <lal/Units.h>
00035 #include <lal/BandPassTimeSeries.h>
00036 
00037 #define TRUE       1
00038 #define FALSE      0
00039 
00040 #define FRAMEHEARSEEC_ENORM  0
00041 #define FRAMEHEARSEEC_EARG   2
00042 
00043 #define FRAMEHEARSEEC_MSGENORM  "Normal exit"
00044 #define FRAMEHEARSEEC_MSGEARG   "Error parsing arguments"
00045 
00046 /* Usage format string. */
00047 #define USAGE "Usage: %s [options] | xmgr -pipe\n"\
00048               "    --help                Print this help message\n" \
00049               "    --channel name        Name of frame channel\n" \
00050               "   [--duration secs]      How many seconds to look at\n"\
00051               "   [--epoch sec nsec]     The starting epoch\n"\
00052               "   [--framedir dirname]   Directory containing frame files\n"\
00053               "   [--highpass freq attenuation]  High-pass filter parameters \n"\
00054               "   [--numpts npoints]     Points per graph displayed\n"
00055 
00056 INT4 lalDebugLevel = LALMSGLVL3;
00057 
00058 #include <config.h>
00059 #ifndef HAVE_LIBLALFRAME
00060 int main( void )
00061 {
00062   fputs( "Disabled: LALApps compiled with non-frame-enabled LAL\n", stderr );
00063   return 77;
00064 }
00065 #else
00066 
00067 /* This routine is pipes output into the xmgr graphing program */
00068 void graphout(float x1,float x2,int thistime, int last) {
00069    static int count=0;
00070    printf("&\n");                            /* end of set marker             */
00071    /* first time we draw the plot */
00072    if (count==0) {
00073       printf("@doublebuffer true\n");       /* keeps display from flashing    */
00074       printf("@s0 color 3\n");              /* IFO graph is green             */
00075       printf("@view 0.1, 0.1, 0.9, 0.45\n"); /* set the viewport for IFO       */
00076       printf("@with g1\n");                 /* reset the current graph to FFT */
00077       printf("@view 0.1, 0.6, 0.9, 0.95\n");/* set the viewport FFT           */
00078       printf("@with g0\n");                 /* reset the current graph to IFO */
00079       printf("@world xmin %f\n",x1);        /* set min x                      */
00080       printf("@world xmax %f\n",x2);        /* set max x                      */
00081       printf("@autoscale\n");               /* autoscale first time through   */
00082       printf("@focus off\n");               /* turn off the focus markers     */
00083       printf("@xaxis label \"t (sec)\"\n"); /* IFO axis label                 */
00084       printf("@fft(s0, 1)\n");              /* compute the spectrum           */
00085       printf("@s1 color 2\n");              /* FFT is red                     */
00086       printf("@move g0.s1 to g1.s0\n");     /* move FFT to graph 1            */
00087       printf("@with g1\n");                 /* set the focus on FFT           */
00088       printf("@g1 type logy\n");            /* set FFT to log freq axis       */
00089       printf("@autoscale\n");               /* autoscale FFT                  */
00090       printf("@subtitle \"Spectrum\"\n");   /* set the subtitle               */
00091       printf("@xaxis label \"f (Hz)\"\n");  /* FFT axis label                 */
00092       printf("@with g0\n");                 /* reset the current graph IFO    */
00093       printf("@subtitle \"IFO output %d\"\n",thistime);/* set IFO subtitle       */
00094       count++;/* set IFO subtitle       */
00095       if (!last) printf("@kill s0\n");      /* kill IFO; ready to read again  */
00096    }
00097    else {
00098       /* other times we redraw the plot */
00099       printf("@s0 color 3\n");              /* set IFO green                   */
00100       printf("@fft(s0, 1)\n");              /* FFT it                          */
00101       printf("@s1 color 2\n");              /* set FFT red                     */
00102       printf("@move g0.s1 to g1.s0\n");     /* move FFT to graph 1             */
00103       printf("@subtitle \"IFO output %d\"\n",thistime);/* set IFO subtitle        */
00104       count++;
00105       printf("@world xmin %f\n",x1);        /* set min x                       */
00106       printf("@world xmax %f\n",x2);        /* set max x                       */
00107       printf("@autoscale yaxes\n");         /* autoscale IFO                   */
00108       printf("@clear stack\n");             /* clear the stack                 */
00109       if (!last) printf("@kill s0\n");      /* kill IFO data                   */
00110       printf("@with g1\n");                 /* switch to FFT                   */
00111       printf("@g1 type logy\n");            /* set FFT to log freq axis       */
00112       printf("@clear stack\n");             /* clear stack                     */
00113       if (!last) printf("@kill s0\n");      /* kill FFT                        */
00114       printf("@with g0\n");                 /* ready to read IFO again         */
00115    }
00116    return;
00117 }
00118 
00119 
00120 
00121 int main( int argc, char *argv[] )
00122 {
00123     static LALStatus  status;
00124     FrStream         *stream = NULL;
00125     FrChanIn          channelIn;
00126     REAL4             time, numSeconds;
00127     INT4              i, numPoints=4096, inarg = 1;
00128     CHAR             *dirname;
00129     REAL4TimeSeries   series;
00130     LIGOTimeGPS       epoch;
00131     BOOLEAN           epochSet = FALSE;
00132     BOOLEAN           highpass = FALSE;
00133     PassBandParamStruc highpassParam;
00134 
00135     /* test files are version 4 frames */
00136     if ( FRAMELIB_VERSION < 4 )
00137         return 77;
00138 
00139     /* set default values for input */
00140     dirname = getenv( "LAL_FRAME_PATH" );
00141 
00142     /* Set up for a highpass filter */
00143     highpassParam.nMax = 4;
00144     highpassParam.f1 = -1.0;
00145     highpassParam.a1 = -1.0;
00146     
00147     /*******************************************************************
00148     * PARSE ARGUMENTS (arg stores the current position)               *
00149     *******************************************************************/
00150 
00151     if (argc <= 1){
00152         LALPrintError( USAGE, *argv );
00153         return 0;
00154     }
00155     
00156     while ( inarg < argc ) {
00157         /* Parse output file option. */
00158         if ( !strcmp( argv[inarg], "--help" ) ) {
00159             if ( argc > inarg + 1 ) {
00160                 inarg++;
00161                 fprintf(stderr,"Should be a usage message\n");
00162                 exit(0);
00163             }else{
00164                 LALPrintError( USAGE , *argv );
00165                 return FRAMEHEARSEEC_EARG;
00166             }
00167         }
00168         else if ( !strcmp( argv[inarg], "--epoch" ) ) {
00169             if ( argc > inarg + 1 ) {
00170                 inarg++;
00171                 epoch.gpsSeconds = atoi( argv[inarg++] );
00172                 epoch.gpsNanoSeconds = atoi( argv[inarg++] );
00173                 epochSet = TRUE;
00174             }else{
00175                 LALPrintError( USAGE, *argv );
00176                 return FRAMEHEARSEEC_EARG;
00177             }
00178         }
00179         else if ( !strcmp( argv[inarg], "--numpts" ) ) {
00180             if ( argc > inarg + 1 ) {
00181                 inarg++;
00182                 numPoints = atoi( argv[inarg++] );
00183             }else{
00184                 LALPrintError( USAGE, *argv );
00185                 return FRAMEHEARSEEC_EARG;
00186             }
00187         }
00188         else if ( !strcmp( argv[inarg], "--highpass" ) ) {
00189             if ( argc > inarg + 1 ) {
00190                 inarg++;
00191                 highpass = TRUE;
00192                 highpassParam.f2 = atof( argv[inarg++] );
00193                 highpassParam.a2 = atof( argv[inarg++] );
00194             }else{
00195                 LALPrintError( USAGE, *argv );
00196                 return FRAMEHEARSEEC_EARG;
00197             }
00198         }
00199         else if ( !strcmp( argv[inarg], "--duration" ) ) {
00200             if ( argc > inarg + 1 ) {
00201                 inarg++;
00202                 numSeconds = atof( argv[inarg++] );
00203             }else{
00204                 LALPrintError( USAGE, *argv );
00205                 return FRAMEHEARSEEC_EARG;
00206             }
00207         }
00208          else if ( !strcmp( argv[inarg], "--channel" ) ) {
00209             if ( argc > inarg + 1 ) {
00210                 inarg++;
00211                 channelIn.name = argv[inarg++];
00212                 channelIn.type = ADCDataChannel;
00213             }else{
00214                 LALPrintError( USAGE, *argv );
00215                 return FRAMEHEARSEEC_EARG;
00216             }
00217         }
00218         else if ( !strcmp( argv[inarg], "--framedir" ) ) {
00219             if ( argc > inarg + 1 ) {
00220                 inarg++;
00221                 dirname = argv[inarg++];
00222             }else{
00223                 LALPrintError( USAGE, *argv );
00224                 return FRAMEHEARSEEC_EARG;
00225             }
00226         }
00227         /* Check for unrecognized options. */
00228         else if ( argv[inarg][0] == '-' ) {
00229             LALPrintError( USAGE, *argv );
00230             return FRAMEHEARSEEC_EARG;
00231         }
00232     } /* End of argument parsing loop. */
00233 
00234     /* Open frame stream */
00235     LALFrOpen( &status, &stream, dirname, "*.gwf" );
00236 
00237     /* Determine information about the channel */
00238     series.data = NULL;
00239     LALFrGetREAL4TimeSeries( &status, &series, &channelIn, stream);
00240     if (epochSet ){
00241         series.epoch.gpsSeconds = epoch.gpsSeconds;
00242         series.epoch.gpsNanoSeconds = epoch.gpsNanoSeconds;
00243     }
00244     LALFrSeek(&status, &(series.epoch), stream);
00245 
00246     /* allocate time series */
00247     LALCreateVector( &status, &series.data, numPoints);
00248 
00249     /* get the data */
00250     LALFrGetREAL4TimeSeries( &status, &series, &channelIn, stream);
00251 
00252     while ( !(status.statusCode) && 
00253             (series.epoch.gpsSeconds < epoch.gpsSeconds + (INT4)(numSeconds))){
00254 
00255         /* filter it if the highpass parameters were set */
00256         if (highpass){ 
00257             LALButterworthREAL4TimeSeries(&status, &series, &highpassParam);
00258         }
00259 
00260         /* print out the contents */
00261         for (i=0 ; i<32 ; i++ ){
00262             time= i * series.deltaT;
00263             printf("%e\t%e\n", time,0.0);
00264         }
00265         for (i=32 ; i<numPoints ; i++) {
00266             time= i * series.deltaT;
00267             printf("%e\t%e\n", time, series.data->data[i]);
00268         }
00269 
00270         /* put out information for the graphing program */
00271         graphout(0, 0+numPoints * series.deltaT, series.epoch.gpsSeconds,
00272                 (status.statusCode == FRAMESTREAMH_EDONE || 
00273                  (series.epoch.gpsSeconds + (INT4)(numPoints*series.deltaT) 
00274                   >= epoch.gpsSeconds + (INT4)(numSeconds)) ));
00275 
00276         /* get the data */
00277         LALFrGetREAL4TimeSeries( &status, &series, &channelIn, stream);
00278     }
00279 
00280     /* close the frame stream */
00281     LALFrClose( &status, &stream );
00282 
00283     /* 
00284     * output the sound file 
00285     * sprintf(fname, "%s", channelIn.name); 
00286     * LALTimeSeriesToSound( &status, tSeries, fname, 1);
00287      */
00288 
00289     /* clean up */
00290     LALSDestroyVector( &status, &(series.data) );
00291     LALCheckMemoryLeaks();
00292     return 0;
00293 }
00294 
00295 #endif

Generated on Sat Sep 6 03:06:35 2008 for LAL by  doxygen 1.5.2