ReadGEOData.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Bernd Machenschalk, Jolien Creighton
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="Read40mDataCV">
00021  * Author: Jolien D. E. Creighton
00022  * $Id: ReadGEOData.c,v 1.6 2007/06/08 14:41:46 bema Exp $
00023  **** </lalVerbatim> */
00024 
00025 /**** <lalLaTeX>
00026  * \subsection{Program \texttt{ReadGEOData.c}}
00027  * 
00028  * Tests the low-level frame stream routines by reading GEO frame data.
00029  *
00030  * \subsubsection*{Usage}
00031  *
00032  * \begin{verbatim}
00033  * ReadGEOData
00034  * \end{verbatim}
00035  *
00036  * \subsubsection*{Description}
00037  *
00038  * This program reads the channel \verb+IFO_DMRO+ from all the frames in the
00039  * directory set in the environment \verb+LAL_FRAME_PATH+ (or the current
00040  * directory if this environment is not set) and prints them as an ascii file.
00041  *
00042  **** </lalLaTeX> */
00043 
00044 #include <math.h>
00045 #include <stdio.h>
00046 #include <unistd.h>
00047 #include <lal/LALStdlib.h>
00048 #include <lal/AVFactories.h>
00049 #include <lal/PrintFTSeries.h>
00050 #include <lal/FrameStream.h>
00051 
00052 #include <lal/LALRCSID.h>
00053 NRCSID (READGEODATAC,"$Id: ReadGEOData.c,v 1.6 2007/06/08 14:41:46 bema Exp $");
00054 
00055 #ifndef CHANNEL
00056 #define CHANNEL "LSC_MID_EP-P"
00057 #endif
00058 
00059 #define TESTSTATUS( pstat ) \
00060   if ( (pstat)->statusCode ) { REPORTSTATUS(pstat); return 1; } else ((void)0)
00061 
00062 INT4 lalDebugLevel = LALMSGLVL3;
00063 
00064 int main( void )
00065 {
00066   static LALStatus status;
00067   const float duration = 60.0; /* seconds of data to read at a time */
00068   REAL4TimeSeries tser;
00069   INT2TimeSeries  chan;
00070   FrChanIn  chanin = { CHANNEL, ADCDataChannel };
00071   FrStream *stream = NULL;
00072   FrOutPar  outpar = { "G:" CHANNEL, "TEST", ADCDataChannel, 6, 0, 0 };
00073   char *dirname = getenv( "LAL_FRAME_PATH" );
00074 
00075   /* open the frame stream */
00076   LALFrOpen( &status, &stream, dirname, "GEO_*.fr" );
00077   TESTSTATUS( &status );
00078 
00079   /* get channel info */
00080   chan.data = NULL;
00081   LALFrGetINT2TimeSeries( &status, &chan, &chanin, stream );
00082   TESTSTATUS( &status );
00083 
00084   /* allocate data storage for channel */
00085   LALI2CreateVector( &status, &chan.data, duration / chan.deltaT );
00086   TESTSTATUS( &status );
00087 
00088   /* the temporary time series */
00089   memcpy( &tser, &chan, sizeof( tser ) );
00090   tser.data = NULL;
00091   LALSCreateVector( &status, &tser.data, duration / tser.deltaT );
00092   TESTSTATUS( &status );
00093 
00094   /* loop until all data has been read */
00095   while ( 1 )
00096   {
00097     INT8  tacc = 0.1 * 1e9 / 16384;
00098     INT8  texp;
00099     INT8  tact;
00100     UINT4 i;
00101 
00102     texp  = (INT8)1000000000 * (INT8)chan.epoch.gpsSeconds;
00103     texp += (INT8)chan.epoch.gpsNanoSeconds;
00104     texp += (INT8)( 1e9 * chan.data->length * chan.deltaT );
00105 
00106     LALFrGetINT2TimeSeries( &status, &chan, &chanin, stream );
00107     if ( status.statusCode == FRAMESTREAMH_EDONE )
00108     {
00109       break;
00110     }
00111     TESTSTATUS( &status );
00112 
00113     tact  = (INT8)1000000000 * (INT8)chan.epoch.gpsSeconds;
00114     tact += (INT8)chan.epoch.gpsNanoSeconds;
00115 
00116     if ( abs( texp - tact ) > tacc )
00117       puts( "Gap in frame data!" );
00118 
00119     tser.epoch = chan.epoch;
00120     printf( "%s-%s-%d-%d.gwf\n", outpar.source, outpar.description,
00121         tser.epoch.gpsSeconds,
00122         (int)ceil( 1e-9 * tser.epoch.gpsNanoSeconds
00123           + tser.data->length * tser.deltaT ) );
00124     for ( i = 0; i < tser.data->length; ++i )
00125     {
00126       tser.data->data[i] = chan.data->data[i];
00127     }
00128     LALFrWriteREAL4TimeSeries( &status, &tser, &outpar );
00129     TESTSTATUS( &status );
00130   }
00131 
00132   LALFrClose( &status, &stream );
00133   TESTSTATUS( &status );
00134 
00135   LALI2DestroyVector( &status, &chan.data );
00136   TESTSTATUS( &status );
00137 
00138   LALSDestroyVector( &status, &tser.data );
00139   TESTSTATUS( &status );
00140 
00141   LALCheckMemoryLeaks();
00142   return 0;
00143 }

Generated on Sat Sep 6 03:07:26 2008 for LAL by  doxygen 1.5.2