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 #include <config.h>
00064 #if defined LAL_FFTW3_ENABLED
00065
00066 int main( void ) { return 77; }
00067 #else
00068
00069
00070 #include <lal/LALfct.h>
00071 #include <stdio.h>
00072 #include <lal/AVFactories.h>
00073 #include <lal/LALStatusMacros.h>
00074 #include <lal/LALfct.h>
00075
00076 #include <unistd.h>
00077
00078
00079
00080
00081
00082
00083
00084 NRCSID(LALFCTSAMPLEC,"$Id: LALfctSample.c,v 1.6 2007/06/08 14:41:44 bema Exp $");
00085
00086
00087
00088
00089
00090
00091
00092
00093 #define CODES_(x) #x
00094 #define CODES(x) CODES_(x)
00095
00096
00097
00098
00099
00100
00101 int lalDebugLevel = 0;
00102
00103
00104
00105
00106
00107 LALFCTREAL phaseFunction1(LALFCTREAL x);
00108 void readData(LALFCTCOMPVector *inputDataVector, char *inputFileName);
00109 static void TestStatus( LALStatus *status, const char *ignored, int exitcode );
00110 static INT4 CheckStatus( LALStatus *status);
00111
00112
00113
00114
00115
00116 extern char *optarg;
00117 extern int optind, opterr, optopt;
00118 int indx;
00119 int c;
00120
00121
00122
00123
00124
00125 int main( int argc, char **argv ) {
00126
00127
00128
00129
00130
00131
00132 static LALStatus status;
00133
00134
00135
00136
00137 LALFCTCOMPVector *inputDataVector=0;
00138 LALfctInitParams fctInitParams;
00139 LALfctAddPhaseFuncParams fctAddPhaseFuncParams;
00140 LALfctCalcParams fctCalcParams;
00141 LALfctGenRowIndexParams fctGenRowIndexParams;
00142 LALfctGenRowIndexOutput fctGenRowIndexOutput;
00143 LALfctCalcOutput fctCalcOutput;
00144 LALFCTPlan *fctPlan=0;
00145
00146
00147
00148
00149
00150
00151
00152 LALFCTREAL maxSizeOfOutputArrayInMegs = 0;
00153 LALFCTREAL megsPerRow = 0;
00154 UINT4 numOfIndices = 0;
00155 UINT4 numOfRowsPerIndex = 0;
00156
00157
00158
00159
00160 char inputFileNameDefault[] = "./input.dat";
00161 char outputFileNameDefault[] = "./output.dat";
00162 char outputIndexFileNameDefault[] = "./output.dat.index";
00163 char *inputFileName = inputFileNameDefault;
00164 char *outputFileName = outputFileNameDefault;
00165 char *outputIndexFileName = outputIndexFileNameDefault;
00166 FILE *OUTPUT = NULL;
00167 BOOLEAN outputIndexFileNameMalloced = 0;
00168 UINT2 outputIndexFileNameSize = 0;
00169
00170
00171
00172
00173
00174 UINT4 dataSize=0;
00175 UINT2 numOfDims = 2;
00176
00177
00178
00179
00180
00181 fctCalcOutput.rowIndex = 0;
00182 fctCalcOutput.outputData = 0;
00183
00184
00185
00186
00187
00188
00189
00190
00191 printf("Reading commandline options:\n");
00192 opterr = 0;
00193 while ((c = getopt (argc, argv, "d:m:i:o:")) != -1) {
00194 switch (c) {
00195 case 'd':
00196 dataSize = atoi(optarg);
00197 printf(" dataSize = %d\n", dataSize);
00198 break;
00199 case 'm':
00200 maxSizeOfOutputArrayInMegs = atof(optarg);
00201 printf(" maxSizeOfOutputArrayInMegs = %g\n", 00202 maxSizeOfOutputArrayInMegs);
00203 break;
00204 case 'i':
00205 inputFileName = optarg;
00206 printf(" inputFileName = %s\n", inputFileName);
00207 break;
00208 case 'o':
00209 outputFileName = optarg;
00210 printf(" outputFileName = %s\n", outputFileName);
00211 if (outputIndexFileNameMalloced) {
00212 LALFree(outputIndexFileName);
00213 }
00214 outputIndexFileNameSize = strlen(outputFileName) + strlen(".index");
00215 outputIndexFileName = LALCalloc(outputIndexFileNameSize + 1, 00216 sizeof(char));
00217 strncpy(outputIndexFileName, outputFileName, outputIndexFileNameSize);
00218 strncat(outputIndexFileName, ".index", 6);
00219
00220 break;
00221 case '?':
00222 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
00223 printf("Usage:\n");
00224 printf(" -d X dataSize = X (Where X is an integer)\n");
00225 printf(" -m F maxSizeOfOutputArrayInMegs = F (Where F is a float)\n");
00226 printf(" -i inputFileName\n");
00227 printf(" -o outputFileName\n");
00228
00229 exit(1);
00230 break;
00231 default:
00232 exit(1);
00233 }
00234 }
00235 for (indx = optind; indx < argc; indx++) {
00236 printf ("Non-option argument %s\n", argv[indx]);
00237 }
00238
00239 printf("Done reading commandline options.\n\n");
00240
00241
00242
00243
00244 if (dataSize == 0) {
00245 printf("Please specify the dataSize on the Commandline");
00246 printf("using the -dX option (where X is an integer.)\n");
00247 exit(1);
00248 }
00249
00250 printf("\n");
00251
00252
00253
00254
00255
00256 fctInitParams.numOfDataPoints = dataSize;
00257 fctInitParams.numOfDims = numOfDims;
00258 LALfctInitialize( &status, &fctPlan, &fctInitParams );
00259 TestStatus( &status, CODES( 0 ), 1 );
00260
00261
00262
00263
00264
00265 fctAddPhaseFuncParams.dim = 1;
00266
00267 fctAddPhaseFuncParams.lengthOfDim = 128;
00268
00269
00270 fctAddPhaseFuncParams.phaseFuncForDim = &phaseFunction1;
00271
00272
00273 LALfctAddPhaseFunc(&status, fctPlan, &fctAddPhaseFuncParams);
00274 TestStatus( &status, CODES( 0 ), 1 );
00275
00276
00277
00278
00279
00280 LALFCTCOMPCreateVector ( &status, &inputDataVector, dataSize );
00281 TestStatus( &status, CODES( 0 ), 1 );
00282
00283
00284
00285
00286
00287 readData(inputDataVector, inputFileName);
00288
00289
00290
00291
00292
00293 fctCalcParams.fctPlan = fctPlan;
00294 fctCalcParams.fctGenRowIndexParams = &fctGenRowIndexParams;
00295 fctCalcParams.fctGenRowIndexFunc = 0;
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 fctGenRowIndexParams.fctPlan = fctPlan;
00312 fctGenRowIndexParams.goToEndOfRows = 1;
00313 fctGenRowIndexParams.createIndex = 0;
00314 fctGenRowIndexParams.skipRows = 0;
00315 fctGenRowIndexParams.numOfRows = 0;
00316
00317
00318
00319
00320
00321 if (maxSizeOfOutputArrayInMegs != 0) {
00322 megsPerRow = ((LALFCTREAL) dataSize*sizeof(LALFCTCOMP)) / 1048576.0;
00323
00324
00325
00326
00327
00328 LALfctGenRowIndex(&status, &fctGenRowIndexOutput, &fctGenRowIndexParams);
00329 TestStatus( &status, CODES( 0 ), 1 );
00330
00331
00332
00333
00334 numOfRowsPerIndex = maxSizeOfOutputArrayInMegs / megsPerRow;
00335 numOfIndices = fctGenRowIndexOutput.numOfRows / numOfRowsPerIndex;
00336 if (numOfIndices * numOfRowsPerIndex < fctGenRowIndexOutput.numOfRows) {
00337 numOfIndices++;
00338 }
00339
00340
00341
00342
00343 } else {
00344 numOfIndices = 1;
00345 numOfRowsPerIndex = 0;
00346 }
00347
00348
00349
00350 printf("Calculating the FCT:\n");
00351 fctGenRowIndexParams.createIndex = 1;
00352 fctGenRowIndexParams.numOfRows = numOfRowsPerIndex;
00353
00354
00355
00356 for (indx = 1; indx <= (int)numOfIndices; indx++) {
00357
00358 if (indx == (int)numOfIndices) {
00359 fctGenRowIndexParams.goToEndOfRows = 1;
00360
00361
00362
00363 } else {
00364 fctGenRowIndexParams.goToEndOfRows = 0;
00365 }
00366
00367
00368 fctGenRowIndexParams.skipRows = numOfRowsPerIndex * (indx - 1);
00369
00370
00371 LALfctCalc(&status, &fctCalcOutput, inputDataVector, &fctCalcParams);
00372 TestStatus( &status, CODES( 0 ), 1 );
00373
00374
00375 if (indx == 1) {
00376 OUTPUT = fopen (outputFileName, "w");
00377 } else {
00378 OUTPUT = fopen (outputFileName, "a");
00379 }
00380 fwrite(fctCalcOutput.outputData->data, sizeof(REAL4), 2 * 00381 fctCalcOutput.outputData->dimLength->data[0] * 00382 fctCalcOutput.outputData->dimLength->data[1], OUTPUT);
00383 fclose(OUTPUT);
00384
00385
00386 if (indx == 1) {
00387 OUTPUT = fopen (outputIndexFileName, "w");
00388 } else {
00389 OUTPUT = fopen (outputIndexFileName, "a");
00390 }
00391 fwrite(fctCalcOutput.rowIndex->data, sizeof(UINT2),
00392 fctCalcOutput.rowIndex->dimLength->data[0] * 00393 fctCalcOutput.rowIndex->dimLength->data[1], OUTPUT);
00394 fclose(OUTPUT);
00395
00396
00397 printf(" Calculated chunk %d of %d.\n", indx, numOfIndices);
00398
00399
00400 LALFCTCOMPDestroyArray(&status, &(fctCalcOutput.outputData));
00401 if (CheckStatus(&status)) {
00402 LALU4DestroyArray(&status, &(fctCalcOutput.rowIndex));
00403 TestStatus( &status, CODES( 0 ), 1 );
00404 }
00405 fctCalcOutput.outputData = 0;
00406
00407
00408
00409 LALU4DestroyArray(&status, &(fctCalcOutput.rowIndex));
00410 if (CheckStatus(&status)) {
00411 TestStatus( &status, CODES( 0 ), 1 );
00412 }
00413 fctCalcOutput.rowIndex = 0;
00414
00415 }
00416
00417
00418
00419
00420
00421 LALFCTCOMPDestroyVector(&status, &inputDataVector);
00422
00423
00424 LALfctDestroyPlan(&status, &fctPlan);
00425 TestStatus( &status, CODES( 0 ), 1 );
00426
00427 if (outputIndexFileNameMalloced) {
00428 LALFree(outputIndexFileName);
00429 }
00430
00431
00432
00433
00434 LALCheckMemoryLeaks();
00435
00436 return 0;
00437 }
00438
00439
00440
00441
00442
00443
00444
00445 LALFCTREAL phaseFunction1(LALFCTREAL x) {
00446 return(x*x);
00447 }
00448
00449
00450
00451
00452 void readData(LALFCTCOMPVector *inputDataVector, char *inputFileName) {
00453
00454 FILE *INPUT;
00455 int Check;
00456
00457 INPUT = fopen( inputFileName, "r" );
00458 if (INPUT == NULL) {
00459 printf("Error couldn't read Data File. inputFileName = %s\n", 00460 inputFileName);
00461 exit(1);
00462 }
00463 Check = fread(inputDataVector->data, sizeof(LALFCTREAL), 00464 2 * inputDataVector->length, INPUT);
00465 if ( Check != (int)(2 * inputDataVector->length) ) {
00466 printf("Error couldn't read Data File. Read Check = %d\n", Check);
00467 exit(1);
00468 }
00469 }
00470
00471
00472
00473
00474
00475 static void TestStatus( LALStatus *status, const char *ignored, int exitcode ) {
00476
00477
00478 char str[64];
00479 char *tok;
00480
00481 if ( strncpy( str, ignored, sizeof( str ) ) ) {
00482 if ( (tok = strtok( str, " " ) ) ) {
00483 do {
00484 if ( status->statusCode == atoi( tok ) ) {
00485 return;
00486 }
00487 }
00488 while ( ( tok = strtok( NULL, " " ) ) );
00489 } else {
00490 if ( status->statusCode == atoi( tok ) ) {
00491 return;
00492 }
00493 }
00494 }
00495
00496 REPORTSTATUS( status );
00497 fprintf( stderr, "\nExiting to system with code %d\n", exitcode );
00498 exit( exitcode );
00499 }
00500
00501 static INT4 CheckStatus( LALStatus *status) {
00502
00503 if ( status->statusCode != 0) {
00504 REPORTSTATUS( status );
00505 return(1);
00506 }
00507 return(0);
00508 }
00509
00510 #endif