MakeFrames.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="MakeFramesCV">
00021  * Author: Jolien D. E. Creighton
00022  * $Id: MakeFrames.c,v 1.5 2007/06/08 14:41:46 bema Exp $
00023  **** </lalVerbatim> */
00024 
00025 /**** <lalLaTeX>
00026  * \subsection{Program \texttt{MakeFrames.c}}
00027  *
00028  * Make some frames with random Gaussian noise.
00029  * 
00030  * \subsubsection*{Usage}
00031  *
00032  * \begin{verbatim}
00033  * MakeFrames
00034  * \end{verbatim}
00035  *
00036  * \subsubsection*{Description}
00037  *
00038  * This program makes some frames with one ADC channel containing random
00039  * Gaussian noise.
00040  *
00041  **** </lalLaTeX> */
00042 
00043 #include <stdio.h>
00044 #include <lal/LALStdlib.h>
00045 #include <lal/AVFactories.h>
00046 #include <lal/Random.h>
00047 #include <lal/Units.h>
00048 #include <lal/FrameStream.h>
00049 
00050 #include <lal/LALRCSID.h>
00051 NRCSID (MAKEFRAMESC,"$Id: MakeFrames.c,v 1.5 2007/06/08 14:41:46 bema Exp $");
00052 
00053 #define TESTSTATUS( pstat ) \
00054   if ( (pstat)->statusCode ) { REPORTSTATUS(pstat); return 1; } else ((void)0)
00055 
00056 #ifndef CHANNEL
00057 #define CHANNEL "H1:LSC-AS_Q"
00058 #endif
00059 
00060 INT4 lalDebugLevel = LALMSGLVL3;
00061 
00062 int main( void )
00063 {
00064   static LALStatus      status;
00065   static INT4TimeSeries series;
00066   const UINT4   time = 60;          /* duration of frame file */
00067   const INT4    seed = 10;          /* random number seed     */
00068   const REAL4   rate = 16384;       /* sample rate (Hz)       */
00069   const UINT4   npts = time * rate; /* number of points       */
00070   FrOutPar      opar = { "F", "TEST", ADCDataChannel, 6, 0, 0 };
00071   RandomParams *rpar = NULL;
00072   UINT4 count = 0;
00073   UINT4 i;
00074 
00075   /* initialize */
00076 
00077   LALCreateRandomParams( &status, &rpar, seed );
00078   TESTSTATUS( &status );
00079 
00080   strncpy( series.name, CHANNEL, sizeof( series.name ) );
00081   series.epoch.gpsSeconds = 600000000;
00082   series.sampleUnits = lalADCCountUnit;
00083   series.deltaT = 1 / rate;
00084   LALI4CreateVector( &status, &series.data, npts );
00085   TESTSTATUS( &status );
00086 
00087   /* generate first frame file worth of data and write it */
00088 
00089   /*
00090   LALNormalDeviates( &status, series.data, rpar );
00091   TESTSTATUS( &status );
00092   */
00093   for ( i = 0; i < series.data->length; ++i )
00094   {
00095     INT8 ns;
00096     ns  = (INT8)1000000000 * (INT8)series.epoch.gpsSeconds;
00097     ns += (INT8)series.epoch.gpsNanoSeconds;
00098     ns += (INT8)( 1e9 * i * series.deltaT );
00099     ns %= (INT8)1000000000;
00100     series.data->data[i] = count++;
00101   }
00102 
00103   LALFrWriteINT4TimeSeries( &status, &series, &opar );
00104   TESTSTATUS( &status );
00105 
00106   /* generate second frame file worth of data and write it */
00107 
00108   series.epoch.gpsSeconds += time;
00109   /*
00110   LALNormalDeviates( &status, series.data, rpar );
00111   TESTSTATUS( &status );
00112   */
00113   for ( i = 0; i < series.data->length; ++i )
00114   {
00115     INT8 ns;
00116     ns  = (INT8)1000000000 * (INT8)series.epoch.gpsSeconds;
00117     ns += (INT8)series.epoch.gpsNanoSeconds;
00118     ns += (INT8)( 1e9 * i * series.deltaT );
00119     ns %= (INT8)1000000000;
00120     series.data->data[i] = count++;
00121   }
00122 
00123   LALFrWriteINT4TimeSeries( &status, &series, &opar );
00124   TESTSTATUS( &status );
00125 
00126   /* generate third frame file worth of data and write it */
00127 
00128   series.epoch.gpsSeconds += time;
00129   /*
00130   LALNormalDeviates( &status, series.data, rpar );
00131   TESTSTATUS( &status );
00132   */
00133   for ( i = 0; i < series.data->length; ++i )
00134   {
00135     INT8 ns;
00136     ns  = (INT8)1000000000 * (INT8)series.epoch.gpsSeconds;
00137     ns += (INT8)series.epoch.gpsNanoSeconds;
00138     ns += (INT8)( 1e9 * i * series.deltaT );
00139     ns %= (INT8)1000000000;
00140     series.data->data[i] = count++;
00141   }
00142 
00143   LALFrWriteINT4TimeSeries( &status, &series, &opar );
00144   TESTSTATUS( &status );
00145 
00146   if ( XLALFrWriteINT4TimeSeries( &series, 7 ) < 0 )
00147     return 1;
00148 
00149   /* cleanup */
00150 
00151   LALI4DestroyVector( &status, &series.data );
00152   TESTSTATUS( &status );
00153 
00154   LALDestroyRandomParams( &status, &rpar );
00155   TESTSTATUS( &status );
00156 
00157   LALCheckMemoryLeaks();
00158   return 0;
00159 }

Generated on Mon Oct 13 02:31:56 2008 for LAL by  doxygen 1.5.2