ReadLHOData.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="ReadLHODataCV">
00021  * Author: Jolien D. E. Creighton
00022  * $Id: ReadLHOData.c,v 1.6 2007/06/08 14:41:46 bema Exp $
00023  **** </lalVerbatim> */
00024 
00025 /**** <lalLaTeX>
00026  * \subsection{Program \texttt{ReadLHOData.c}}
00027  * 
00028  * Tests the low-level frame stream routines by reading LHO E5 frame data.
00029  *
00030  * \subsubsection*{Usage}
00031  *
00032  * \begin{verbatim}
00033  * ReadLHOData
00034  * \end{verbatim}
00035  *
00036  * \subsubsection*{Description}
00037  *
00038  * This program extracts the channel \verb+H2:LSC-AS_Q+ from all the frames in
00039  * the directory set in the environment \verb+LAL_FRAME_PATH+ (or the current
00040  * directory if this environment is not set) and writes it to new frame files.
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 (READLHODATAC,"$Id: ReadLHOData.c,v 1.6 2007/06/08 14:41:46 bema Exp $");
00054 
00055 #define TESTSTATUS( pstat ) \
00056   if ( (pstat)->statusCode ) { REPORTSTATUS(pstat); return 1; } else ((void)0)
00057 
00058 #ifndef CHANNEL
00059 #define CHANNEL "H2:LSC-AS_Q"
00060 #endif
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 chan;
00069   FrChanIn  chanin = { CHANNEL, ADCDataChannel };
00070   FrStream *stream = NULL;
00071   FrOutPar  outpar = { CHANNEL, "TEST", ADCDataChannel, 6, 0, 0 };
00072   char *dirname = getenv( "LAL_FRAME_PATH" );
00073 
00074   /* open the frame stream */
00075   LALFrOpen( &status, &stream, dirname, "H-*.gwf" );
00076   TESTSTATUS( &status );
00077 
00078   /* get channel info */
00079   chan.data = NULL;
00080   LALFrGetREAL4TimeSeries( &status, &chan, &chanin, stream );
00081   TESTSTATUS( &status );
00082 
00083   /* allocate data storage for channel */
00084   LALSCreateVector( &status, &chan.data, duration / chan.deltaT );
00085   TESTSTATUS( &status );
00086 
00087   /* loop until all data has been read */
00088   while ( 1 )
00089   {
00090     INT8 tacc = 0.1 * 1e9 / 16384;
00091     INT8 texp;
00092     INT8 tact;
00093 
00094     texp  = (INT8)1000000000 * (INT8)chan.epoch.gpsSeconds;
00095     texp += (INT8)chan.epoch.gpsNanoSeconds;
00096     texp += (INT8)( 1e9 * chan.data->length * chan.deltaT );
00097 
00098     LALFrGetREAL4TimeSeries( &status, &chan, &chanin, stream );
00099     if ( status.statusCode == FRAMESTREAMH_EDONE )
00100     {
00101       break;
00102     }
00103     TESTSTATUS( &status );
00104 
00105     tact  = (INT8)1000000000 * (INT8)chan.epoch.gpsSeconds;
00106     tact += (INT8)chan.epoch.gpsNanoSeconds;
00107 
00108     if ( abs( texp - tact ) > tacc )
00109       puts( "Gap in frame data!" );
00110 
00111     printf( "%s-%s-%d-%d.gwf\n", outpar.source, outpar.description,
00112         chan.epoch.gpsSeconds,
00113         (int)ceil( 1e-9 * chan.epoch.gpsNanoSeconds 
00114           + chan.data->length * chan.deltaT ) );    
00115     LALFrWriteREAL4TimeSeries( &status, &chan, &outpar );
00116     TESTSTATUS( &status );
00117   }
00118 
00119   LALFrClose( &status, &stream );
00120   TESTSTATUS( &status );
00121 
00122   LALSDestroyVector( &status, &chan.data );
00123   TESTSTATUS( &status );
00124 
00125   LALCheckMemoryLeaks();
00126   return 0;
00127 }

Generated on Tue Oct 7 02:40:20 2008 for LAL by  doxygen 1.5.2