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 #define PTOLEMETRICTESTC_EMEM 1
00080 #define PTOLEMETRICTESTC_ESUB 2
00081 #define PTOLEMETRICTESTC_ESYS 3
00082
00083 #define PTOLEMETRICTESTC_MSGEMEM "memory (de)allocation error"
00084 #define PTOLEMETRICTESTC_MSGESUB "subroutine failed"
00085 #define PTOLEMETRICTESTC_MSGESYS "system call failed"
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 #include <math.h>
00114 #include <stdio.h>
00115 #include <stdlib.h>
00116 #include <string.h>
00117 #include <sys/types.h>
00118 #include <sys/stat.h>
00119 #include <unistd.h>
00120 #include <lal/AVFactories.h>
00121 #include <lal/LALMalloc.h>
00122 #include <lal/LALStdlib.h>
00123 #include <lal/PtoleMetric.h>
00124 #include <lal/StackMetric.h>
00125 extern char *optarg;
00126
00127 NRCSID( PTOLEMETRICTESTC, "$Id" );
00128
00129 #define DEFAULT_DURATION 1e5
00130 #define NUM_SPINDOWN 0
00131 #define SPOKES 30
00132 #define MAGNIFY 1.0
00133
00134 int lalDebugLevel = 0;
00135
00136 int main( int argc, char *argv[] ) {
00137 static LALStatus status;
00138 PtoleMetricIn in;
00139 REAL4 mismatch;
00140 REAL4Vector *spindown = NULL;
00141 REAL8Vector *metric = NULL;
00142 int j, k;
00143 int opt;
00144 BOOLEAN test = 0;
00145 BOOLEAN grace = 0;
00146 BOOLEAN nongrace = 0;
00147 int ra, dec, i;
00148 FILE *pvc;
00149 FILE *fnongrace;
00150
00151
00152
00153 in.duration = DEFAULT_DURATION;
00154 in.epoch.gpsSeconds = 0.0;
00155 in.epoch.gpsNanoSeconds = 0.0;
00156 mismatch = 0.02;
00157
00158
00159
00160 while ((opt = getopt( argc, argv, "b:em:pt:x" )) != -1) {
00161 switch (opt) {
00162 case 'b':
00163 in.epoch.gpsSeconds = atof( optarg );
00164 break;
00165 case 'e':
00166 test = 1;
00167 lalDebugLevel = 1;
00168 break;
00169 case 'm':
00170 mismatch = atof( optarg );
00171 break;
00172 case 'p':
00173 nongrace = 1;
00174 break;
00175 case 't':
00176 in.duration = atof( optarg );
00177 break;
00178 case 'x':
00179 grace = 1;
00180 break;
00181 }
00182 }
00183
00184 if (test) {
00185 printf("\nTesting bad I/O structures...\n");
00186 LALPtoleMetric( &status, metric, NULL );
00187 printf("\nTesting bad sky position...\n");
00188 in.position.longitude = 1e10;
00189 LALPtoleMetric( &status, metric, &in );
00190 }
00191
00192 in.position.system = COORDINATESYSTEM_EQUATORIAL;
00193 in.position.longitude = 288.25*LAL_PI_180;
00194 in.position.latitude = 16*LAL_PI_180;
00195
00196 if (test){
00197 printf("\nTesting bad spindown parameters...\n");
00198 LALPtoleMetric( &status, metric, &in );
00199 }
00200
00201 if( NUM_SPINDOWN > 0 )
00202 {
00203 LALCreateVector( &status, &spindown, NUM_SPINDOWN );
00204 if( status.statusCode )
00205 {
00206 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00207 PTOLEMETRICTESTC_MSGEMEM );
00208 return PTOLEMETRICTESTC_EMEM;
00209 }
00210 for (j=0; (UINT4)j<spindown->length; j++)
00211 spindown->data[j] = 0;
00212 in.spindown = spindown;
00213 }
00214 else
00215 in.spindown = NULL;
00216
00217
00218
00219 if (test) {
00220 REAL4 old_duration = in.duration;
00221 printf("\nTesting bad duration...\n");
00222 in.duration = -1;
00223 LALPtoleMetric( &status, metric, &in );
00224 in.duration = old_duration;
00225 }
00226
00227 if (test) {
00228 printf("\nTesting bad maximum frequency...\n");
00229 in.maxFreq = 0;
00230 LALPtoleMetric( &status, metric, &in );
00231 }
00232
00233 in.maxFreq = 1e3;
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 in.site = &lalCachedDetectors[LALDetectorIndexGEO600DIFF];
00244
00245 if (test) {
00246 printf("\nTesting bad output contents...\n");
00247 LALPtoleMetric( &status, metric, &in );
00248 }
00249
00250 LALDCreateVector( &status, &metric, (3+NUM_SPINDOWN)*(4+NUM_SPINDOWN)/2 );
00251 if( status.statusCode )
00252 {
00253 printf( "%s line %d: %s\n", __FILE__, __LINE__, PTOLEMETRICTESTC_MSGEMEM );
00254 return PTOLEMETRICTESTC_EMEM;
00255 }
00256
00257
00258 if (argc == 1) {
00259
00260 printf( "\nValid results for duration %e seconds:\n", in.duration );
00261 LALPtoleMetric( &status, metric, &in );
00262 if( status.statusCode )
00263 {
00264 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00265 PTOLEMETRICTESTC_MSGESUB );
00266 return PTOLEMETRICTESTC_ESUB;
00267 }
00268 for (j=0; j<=2+NUM_SPINDOWN; j++) {
00269 for (k=0; k<=j; k++)
00270 printf( " %+.3e", metric->data[k+j*(j+1)/2] );
00271 printf("\n");
00272 }
00273 LALProjectMetric( &status, metric, 0 );
00274 if( status.statusCode )
00275 {
00276 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00277 PTOLEMETRICTESTC_MSGESUB );
00278 return PTOLEMETRICTESTC_ESUB;
00279 }
00280 printf( "With f0 projected out:\n" );
00281 for (j=1; j<=2+NUM_SPINDOWN; j++) {
00282 for (k=1; k<=j; k++)
00283 printf( " %+.3e", metric->data[k+j*(j+1)/2] );
00284 printf( "\n" );
00285 }
00286
00287 #if 0
00288 printf( "\nValid results for duration 1e7 seconds:\n" );
00289 in.duration = 1e7;
00290 LALPtoleMetric( &status, metric, &in );
00291 if( status.statusCode )
00292 {
00293 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00294 PTOLEMETRICTESTC_MSGESUB );
00295 return PTOLEMETRICTESTC_ESUB;
00296 }
00297 for (j=0; j<=2+NUM_SPINDOWN; j++) {
00298 for (k=0; k<=j; k++)
00299 printf( " %+.3e", metric->data[k+j*(j+1)/2] );
00300 printf("\n");
00301 }
00302 LALProjectMetric( &status, metric, 0 );
00303 if( status.statusCode )
00304 {
00305 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00306 PTOLEMETRICTESTC_MSGESUB );
00307 return PTOLEMETRICTESTC_ESUB;
00308 }
00309 printf( "With f0 projected out:\n" );
00310 for (j=1; j<=2+NUM_SPINDOWN; j++) {
00311 for (k=1; k<=j; k++)
00312 printf( " %+.3e", metric->data[k+j*(j+1)/2] );
00313 printf( "\n" );
00314 }
00315 #endif
00316 }
00317
00318
00319
00320 if (grace || nongrace) {
00321
00322
00323 if(grace)
00324 {
00325 pvc = popen( "xmgrace -pipe", "w" );
00326 if( !pvc )
00327 {
00328 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00329 PTOLEMETRICTESTC_MSGESYS );
00330 return PTOLEMETRICTESTC_ESYS;
00331 }
00332 fprintf( pvc, "@xaxis label \"Right ascension (degrees)\"\n" );
00333 fprintf( pvc, "@yaxis label \"Declination (degrees)\"\n" );
00334 }
00335 if(nongrace)
00336 {
00337 fnongrace = fopen( "nongrace.data", "w" );
00338 if( !fnongrace )
00339 {
00340 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00341 PTOLEMETRICTESTC_MSGESYS );
00342 return PTOLEMETRICTESTC_ESYS;
00343 }
00344 }
00345
00346
00347 j = 0;
00348 for (dec=80; dec>0; dec-=10) {
00349 for (ra=0; ra<=90; ra+=15) {
00350 float gaa, gad, gdd, angle, smaj, smin;
00351
00352
00353 in.position.longitude = ra*LAL_PI_180;
00354 in.position.latitude = dec*LAL_PI_180;
00355 LALPtoleMetric( &status, metric, &in );
00356 if( status.statusCode )
00357 {
00358 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00359 PTOLEMETRICTESTC_MSGESUB );
00360 return PTOLEMETRICTESTC_ESUB;
00361 }
00362
00363
00364 LALProjectMetric( &status, metric, 0 );
00365 if( status.statusCode )
00366 {
00367 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00368 PTOLEMETRICTESTC_MSGESUB );
00369 return PTOLEMETRICTESTC_ESUB;
00370 }
00371
00372
00373 gaa = metric->data[2];
00374
00375 gad = metric->data[4];
00376
00377 gdd = metric->data[5];
00378
00379 smin = gaa+gdd + sqrt( pow(gaa-gdd,2) + pow(2*gad,2) );
00380 smin = sqrt(2*mismatch/smin);
00381
00382 smaj = gaa+gdd - sqrt( pow(gaa-gdd,2) + pow(2*gad,2) );
00383 smaj = sqrt(2*mismatch/smaj);
00384
00385 angle = atan2( gad, mismatch/smaj/smaj-gdd );
00386 if (angle <= -LAL_PI_2) angle += LAL_PI;
00387 if (angle > LAL_PI_2) angle -= LAL_PI;
00388
00389 if(grace)
00390 {
00391
00392 fprintf( pvc, "@s%d color (0,0,0)\n", j );
00393 fprintf( pvc, "@target G0.S%d\n@type xy\n", j++ );
00394
00395 fprintf( pvc, "%16.8g %16.8g\n", (float)ra, (float)dec );
00396 }
00397 if(nongrace)
00398
00399 fprintf( fnongrace, "%16.8g %16.8g\n", (float)ra, (float)dec );
00400
00401 for (i=0; i<=SPOKES; i++) {
00402 float c, r;
00403 c = LAL_TWOPI*i/SPOKES;
00404 r = MAGNIFY*LAL_180_PI*smaj*smin/sqrt( pow(smaj*sin(c),2)
00405 + pow(smin*cos(c),2) );
00406 if(grace)
00407 fprintf( pvc, "%e %e\n", ra+r*cos(angle-c), dec+r*sin(angle-c) );
00408 if(nongrace)
00409 fprintf( fnongrace, "%e %e\n", ra+r*cos(angle-c),
00410 dec+r*sin(angle-c) );
00411
00412 }
00413
00414 }
00415 }
00416 if(grace)
00417 fclose( pvc );
00418 if(nongrace)
00419 fclose( fnongrace );
00420 }
00421
00422 printf("\nCleaning up and leaving...\n");
00423 if( spindown )
00424 {
00425 LALDestroyVector( &status, &spindown );
00426 if( status.statusCode )
00427 {
00428 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00429 PTOLEMETRICTESTC_MSGEMEM );
00430 return PTOLEMETRICTESTC_EMEM;
00431 }
00432 }
00433 LALDDestroyVector( &status, &metric );
00434 if( status.statusCode )
00435 {
00436 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00437 PTOLEMETRICTESTC_MSGEMEM );
00438 return PTOLEMETRICTESTC_EMEM;
00439 }
00440 LALCheckMemoryLeaks();
00441 return 0;
00442 }