00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #define BANDPASSTESTC_ENORM 0
00069 #define BANDPASSTESTC_ESUB 1
00070 #define BANDPASSTESTC_EARG 2
00071 #define BANDPASSTESTC_EBAD 3
00072 #define BANDPASSTESTC_EFILE 4
00073
00074 #define BANDPASSTESTC_MSGENORM "Normal exit"
00075 #define BANDPASSTESTC_MSGESUB "Subroutine failed"
00076 #define BANDPASSTESTC_MSGEARG "Error parsing arguments"
00077 #define BANDPASSTESTC_MSGEBAD "Bad argument values"
00078 #define BANDPASSTESTC_MSGEFILE "Could not open file"
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #include <lal/LALStdio.h>
00097 #include <lal/LALStdlib.h>
00098 #include <string.h>
00099 #include <stdlib.h>
00100 #include <stdio.h>
00101 #include <lal/AVFactories.h>
00102 #include <lal/BandPassTimeSeries.h>
00103 #include <lal/StreamInput.h>
00104 #include <lal/StreamOutput.h>
00105
00106 NRCSID(BANDPASSTESTC,"$Id: BandPassTest.c,v 1.16 2007/06/08 14:41:56 bema Exp $");
00107
00108
00109 INT4 lalDebugLevel=0;
00110 #define NPTS 4096
00111 #define DT 1.0
00112 #define OFFSET 1024
00113 #define F1 0.01
00114 #define F2 0.015
00115 #define A1 0.9
00116 #define A2 0.1
00117 #define ORDER 20
00118
00119
00120 #define USAGE "Usage: %s [-d debuglevel] [-i infile | -n npts dt offset]\n" \
00121 "\t[-o outfile] [-f f1 f2 a1 a2 order]\n"
00122
00123
00124 #define ERROR( code, msg, statement ) \
00125 do { \
00126 if ( lalDebugLevel & LALERROR ) \
00127 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
00128 " %s %s\n", (code), *argv, __FILE__, \
00129 __LINE__, BANDPASSTESTC, statement ? statement : \
00130 "", (msg) ); \
00131 } while (0)
00132
00133 #define INFO( statement ) \
00134 do { \
00135 if ( lalDebugLevel & LALINFO ) \
00136 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
00137 " %s\n", *argv, __FILE__, __LINE__, \
00138 BANDPASSTESTC, (statement) ); \
00139 } while (0)
00140
00141 #define SUB( func, statusptr ) \
00142 do { \
00143 if ( (func), (statusptr)->statusCode ) { \
00144 ERROR( BANDPASSTESTC_ESUB, BANDPASSTESTC_MSGESUB, \
00145 "Function call \"" #func "\" failed:" ); \
00146 return BANDPASSTESTC_ESUB; \
00147 } \
00148 } while (0)
00149
00150
00151 #ifndef NDEBUG
00152 char *lalWatch;
00153 #endif
00154
00155 int
00156 main(int argc, char **argv)
00157 {
00158 static LALStatus stat;
00159 CHAR *infile = NULL;
00160 CHAR *outfile = NULL;
00161 INT4 arg;
00162 UINT4 npts = NPTS;
00163 UINT4 offset = OFFSET;
00164 REAL8 dt = DT;
00165 static REAL4TimeSeries series;
00166 static PassBandParamStruc params;
00167
00168 XLALSetErrorHandler( XLALAbortErrorHandler );
00169
00170
00171 params.f1 = F1;
00172 params.f2 = F2;
00173 params.a1 = A1;
00174 params.a2 = A2;
00175 params.nMax = ORDER;
00176
00177
00178 arg = 1;
00179 while ( arg < argc ) {
00180
00181 if ( !strcmp( argv[arg], "-d" ) ) {
00182 if ( argc > arg + 1 ) {
00183 arg++;
00184 lalDebugLevel = atoi( argv[arg++] );
00185 } else {
00186 ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
00187 LALPrintError( USAGE, *argv );
00188 return BANDPASSTESTC_EARG;
00189 }
00190 }
00191
00192 else if ( !strcmp( argv[arg], "-i" ) ) {
00193 if ( argc > arg + 1 ) {
00194 arg++;
00195 infile = argv[arg++];
00196 } else {
00197 ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
00198 LALPrintError( USAGE, *argv );
00199 return BANDPASSTESTC_EARG;
00200 }
00201 }
00202
00203 else if ( !strcmp( argv[arg], "-o" ) ) {
00204 if ( argc > arg + 1 ) {
00205 arg++;
00206 outfile = argv[arg++];
00207 } else {
00208 ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
00209 LALPrintError( USAGE, *argv );
00210 return BANDPASSTESTC_EARG;
00211 }
00212 }
00213
00214 else if ( !strcmp( argv[arg], "-f" ) ) {
00215 if ( argc > arg + 5 ) {
00216 arg++;
00217 params.f1=atof(argv[arg++]);
00218 params.f2=atof(argv[arg++]);
00219 params.a1=atof(argv[arg++]);
00220 params.a2=atof(argv[arg++]);
00221 params.nMax=atoi(argv[arg++]);
00222 } else {
00223 ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
00224 LALPrintError( USAGE, *argv );
00225 return BANDPASSTESTC_EARG;
00226 }
00227 }
00228
00229 else if ( !strcmp( argv[arg], "-n" ) ) {
00230 if ( argc > arg + 3 ) {
00231 arg++;
00232 npts=atoi(argv[arg++]);
00233 dt=atof(argv[arg++]);
00234 offset=atoi(argv[arg++]);
00235 } else {
00236 ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
00237 LALPrintError( USAGE, *argv );
00238 return BANDPASSTESTC_EARG;
00239 }
00240 }
00241
00242 else {
00243 ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 );
00244 LALPrintError( USAGE, *argv );
00245 return BANDPASSTESTC_EARG;
00246 }
00247 }
00248
00249
00250 if ( !infile ) {
00251 if ( offset >= npts ) {
00252 ERROR( BANDPASSTESTC_EBAD, BANDPASSTESTC_MSGEBAD, 0 );
00253 LALPrintError( "\toffset=%i must be less than npts=%i\n", offset,
00254 npts );
00255 return BANDPASSTESTC_EBAD;
00256 }
00257 }
00258
00259
00260 if ( infile ) {
00261 FILE *fp = fopen( infile, "r" );
00262 if ( !fp ) {
00263 ERROR( BANDPASSTESTC_EFILE, BANDPASSTESTC_MSGEFILE, infile );
00264 return BANDPASSTESTC_EFILE;
00265 }
00266 SUB( LALSReadTSeries( &stat, &series, fp ), &stat );
00267 fclose( fp );
00268 } else {
00269 LALSnprintf( series.name, LALNameLength, "%s", "Impulse" );
00270 series.deltaT = dt;
00271 SUB( LALSCreateVector( &stat, &(series.data), npts ), &stat );
00272 memset( series.data->data, 0, npts*sizeof(REAL4) );
00273 series.data->data[offset] = 1.0;
00274 }
00275
00276
00277 SUB( LALDButterworthREAL4TimeSeries( &stat, &series, ¶ms ),
00278 &stat );
00279
00280
00281 if ( outfile ) {
00282 FILE *fp = fopen( outfile, "w" );
00283 if ( !fp ){
00284 ERROR( BANDPASSTESTC_EFILE, BANDPASSTESTC_MSGEFILE, outfile );
00285 return BANDPASSTESTC_EFILE;
00286 }
00287 SUB( LALSWriteTSeries( &stat, fp, &series ), &stat );
00288 fclose( fp );
00289 }
00290
00291
00292 SUB( LALSDestroyVector( &stat, &(series.data) ), &stat );
00293 LALCheckMemoryLeaks();
00294 INFO( BANDPASSTESTC_MSGENORM );
00295 return BANDPASSTESTC_ENORM;
00296 }