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
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #include <lal/LALStdlib.h>
00087
00088 #include <math.h>
00089 #include <string.h>
00090 #include <stdio.h>
00091 #include <config.h>
00092
00093 #ifdef HAVE_UNISTD_H
00094 #include <unistd.h>
00095 #endif
00096
00097 #ifdef HAVE_GETOPT_H
00098 #include <getopt.h>
00099 #endif
00100
00101 #include <lal/LALMoment.h>
00102 #include "CheckStatus.h"
00103
00104
00105 NRCSID (LALMOMENTTESTC, "$Id: LALMomentTest.c,v 1.4 2007/06/08 14:41:52 bema Exp $");
00106
00107
00108
00109 #define LALMOMENTTESTC_TRUE 1
00110 #define LALMOMENTTESTC_FALSE 0
00111
00112 extern char *optarg;
00113 extern int optind;
00114
00115
00116
00117 int lalDebugLevel = 0;
00118
00119
00120
00121 BOOLEAN optVerbose = LALMOMENTTESTC_FALSE;
00122 UINT4 optLength = 0;
00123
00124
00125 static void Usage
00126 (
00127 const char *program,
00128 int exitflag
00129 );
00130
00131 static void ParseOptions
00132 (
00133 int argc,
00134 char *argv[]
00135 );
00136
00137
00138
00139 #define LALMOMENTTESTC_ENOM 0
00140 #define LALMOMENTTESTC_EARG 1
00141 #define LALMOMENTTESTC_ECHK 2
00142 #define LALMOMENTTESTC_EFLS 3
00143 #define LALMOMENTTESTC_EUSE 4
00144 #define LALMOMENTTESTC_ENULL 5
00145 #define LALMOMENTTESTC_EALOC 6
00146 #define LALMOMENTTESTC_MSGENOM "Nominal exit"
00147 #define LALMOMENTTESTC_MSGEARG "Error parsing command-line arguments"
00148 #define LALMOMENTTESTC_MSGECHK "Error checking failed to catch bad data"
00149 #define LALMOMENTTESTC_MSGEFLS "Incorrect answer for valid data"
00150 #define LALMOMENTTESTC_MSGEUSE "Bad user-entered data"
00151 #define LALMOMENTTESTC_MSGENULL "Null Pointer."
00152 #define LALMOMENTTESTC_MSGEALOC "Memory Allocation Error"
00153
00154
00155
00156
00157 int main( int argc, char *argv[] )
00158 {
00159
00160 static LALStatus status;
00161
00162
00163 REAL8 data[40];
00164 REAL8 *result;
00165 REAL8 *nullResult;
00166 INT4 length;
00167 INT4 whichMoment;
00168 INT4 iterator;
00169 INT4 code;
00170 REAL8 testOutput[7];
00171 REAL8Sequence *sequence;
00172 REAL8Sequence *nullSequence;
00173
00174
00175 const INT4 constantData[] =
00176 { 2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,
00177 2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4};
00178
00179 const INT4 constantData2[] =
00180 { 10,20,10,20,10,20,10,20,10,20};
00181
00182 length = 40;
00183 nullResult = NULL;
00184 nullSequence = NULL;
00185 whichMoment = 3;
00186
00187 result = (REAL8*) LALMalloc(sizeof(REAL8));
00188
00189 if( !result )
00190 {
00191 return LALMOMENTTESTC_EALOC;
00192 }
00193
00194 sequence = (REAL8Sequence*) LALMalloc(sizeof(REAL8Sequence));
00195
00196 if( !sequence )
00197 {
00198 return LALMOMENTTESTC_EALOC;
00199 }
00200
00201 for ( iterator = 0; iterator < length; iterator++ )
00202 {
00203 data[iterator] = ((REAL8)(20 - iterator));
00204 }
00205
00206 sequence->length = length;
00207
00208 ParseOptions( argc, argv );
00209
00210 printf("\n\nMESG: %s \n",LALMOMENTTESTC);
00211
00212 #ifndef LAL_NDEBUG
00213 if ( ! lalNoDebug )
00214 {
00215
00216 LALDMoment(&status, result, nullSequence, whichMoment);
00217 if ( ( code = CheckStatus(&status, LALMOMENTH_ENULL, LALMOMENTH_MSGENULL,
00218 LALMOMENTTESTC_ECHK, LALMOMENTTESTC_MSGECHK)) )
00219 {
00220 return code;
00221 }
00222 printf("\nPASS: null pointer to input structure results in error:\n");
00223 printf(" \"%s\"\n", LALMOMENTH_MSGENULL);
00224
00225
00226
00227 sequence->length = 0;
00228
00229 LALDMoment(&status, result, sequence, whichMoment);
00230 if ( ( code = CheckStatus(&status, LALMOMENTH_ELNTH, LALMOMENTH_MSGELNTH,
00231 LALMOMENTTESTC_ECHK, LALMOMENTTESTC_MSGECHK)) )
00232 {
00233 return code;
00234 }
00235 printf("\nPASS: null pointer to input structure results in error:\n");
00236 printf(" \"%s\"\n", LALMOMENTH_MSGELNTH);
00237
00238
00239 sequence->length = length;
00240
00241
00242
00243 LALDMoment(&status, nullResult, sequence, whichMoment);
00244 if ( ( code = CheckStatus(&status, LALMOMENTH_ENULL, LALMOMENTH_MSGENULL,
00245 LALMOMENTTESTC_ECHK, LALMOMENTTESTC_MSGECHK)) )
00246 {
00247 return code;
00248 }
00249 printf("\nPASS: non-null pointer to output structure results in error:\n");
00250 printf(" \"%s\"\n", LALMOMENTH_MSGENULL);
00251 }
00252 #endif
00253
00254
00255
00256 sequence->data = data;
00257
00258
00259 for ( iterator = 0; iterator < length; iterator++ )
00260 {
00261 data[iterator] = 5.0;
00262 }
00263
00264
00265 for(whichMoment = 2; whichMoment < 6; whichMoment++)
00266 {
00267 LALDMoment(&status, result, sequence, whichMoment);
00268 testOutput[whichMoment] = *result;
00269
00270 if( lalDebugLevel > 0 )
00271 {
00272 printf("MESG: whichMoment := %d\n",whichMoment);
00273 printf("MESG: testOutput[%d] := %f\n\n",whichMoment, testOutput[whichMoment]);
00274 }
00275 }
00276
00277
00278 for ( iterator = 0; iterator < length; iterator++ )
00279 {
00280 data[iterator] = ((REAL8)(20 - iterator));
00281 }
00282
00283
00284 for(whichMoment = 2; whichMoment < 6; whichMoment++)
00285 {
00286 LALDMoment(&status, result, sequence, whichMoment);
00287 testOutput[whichMoment] = *result;
00288
00289 if( lalDebugLevel > 0 )
00290 {
00291 printf("MESG: whichMoment := %d\n",whichMoment);
00292 printf("MESG: testOutput[%d] := %f\n\n",whichMoment, testOutput[whichMoment]);
00293 }
00294 }
00295
00296
00297 for ( iterator = 0; iterator < length; iterator++ )
00298 {
00299 data[iterator] = ((REAL8)(constantData[iterator]));
00300 }
00301
00302
00303 for(whichMoment = 2; whichMoment < 6; whichMoment++)
00304 {
00305 LALDMoment(&status, result, sequence, whichMoment);
00306 testOutput[whichMoment] = *result;
00307
00308 if( lalDebugLevel > 0 )
00309 {
00310 printf("MESG: whichMoment := %d\n",whichMoment);
00311 printf("MESG: testOutput[%d] := %f\n\n",whichMoment, testOutput[whichMoment]);
00312 }
00313 }
00314
00315
00316 sequence->length = length = 10;
00317
00318
00319 for ( iterator = 0; iterator < length; iterator++ )
00320 {
00321 data[iterator] = ((REAL8)(constantData2[iterator]));
00322 }
00323
00324
00325 for(whichMoment = 2; whichMoment < 6; whichMoment++)
00326 {
00327 LALDMoment(&status, result, sequence, whichMoment);
00328 testOutput[whichMoment] = *result;
00329
00330 if( lalDebugLevel > 0 )
00331 {
00332 printf("MESG: whichMoment := %d\n",whichMoment);
00333 printf("MESG: testOutput[%d] := %f\n\n",whichMoment, testOutput[whichMoment]);
00334 }
00335 }
00336
00337 printf("MESG: More option available from command line.\n");
00338 printf("MESG: Type LALMomentTest -h for options.\n");
00339
00340
00341 return LALMOMENTTESTC_ENOM;
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 static void Usage (const char *program, int exitcode)
00355 {
00356 fprintf (stderr, "Usage: %s [options]\n", program);
00357 fprintf (stderr, "Options:\n");
00358 fprintf (stderr, " -h print this message\n");
00359 fprintf (stderr, " -q quiet: run silently\n");
00360 fprintf (stderr, " -v verbose: print extra information\n");
00361 fprintf (stderr, " -d level set lalDebugLevel to level\n");
00362 exit (exitcode);
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372 static void ParseOptions (int argc, char *argv[])
00373 {
00374 while (1)
00375 {
00376 int c = -1;
00377
00378 c = getopt (argc, argv, "hqvd:");
00379 if (c == -1)
00380 {
00381 break;
00382 }
00383
00384 switch (c)
00385 {
00386 case 'd':
00387 lalDebugLevel = atoi (optarg);
00388 break;
00389
00390 case 'v':
00391 optVerbose = LALMOMENTTESTC_TRUE;
00392 break;
00393
00394 case 'q':
00395 freopen ("/dev/null", "w", stderr);
00396 freopen ("/dev/null", "w", stdout);
00397 break;
00398
00399 case 'h':
00400 Usage (argv[0], 0);
00401 break;
00402
00403 default:
00404 Usage (argv[0], 1);
00405 }
00406
00407 }
00408
00409 if (optind < argc)
00410 {
00411 Usage (argv[0], 1);
00412 }
00413
00414 return;
00415 }