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
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
00114
00115
00116
00117
00118
00119 #define GENERALMETRICTESTC_EMEM 1
00120 #define GENERALMETRICTESTC_ESUB 2
00121 #define GENERALMETRICTESTC_ESYS 3
00122 #define GENERALMETRICTESTC_EMET 4
00123
00124 #define GENERALMETRICTESTC_MSGEMEM "memory (de)allocation error"
00125 #define GENERALMETRICTESTC_MSGESUB "subroutine failed"
00126 #define GENERALMETRICTESTC_MSGESYS "system call failed"
00127 #define GENERALMETRICTESTC_MSGEMET "determinant of projected metric negative"
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 #include <math.h>
00155 #include <stdio.h>
00156 #include <stdlib.h>
00157 #include <string.h>
00158 #include <sys/types.h>
00159 #include <sys/stat.h>
00160 #include <unistd.h>
00161 #include <lal/AVFactories.h>
00162 #include <lal/LALMalloc.h>
00163 #include <lal/LALStdlib.h>
00164 #include <lal/PtoleMetric.h>
00165 #include <lal/StackMetric.h>
00166 #include <lal/LALBarycenter.h>
00167 #include <lal/LALInitBarycenter.h>
00168
00169 extern char *optarg;
00170
00171 NRCSID( GENERALMETRICTESTC, "$Id" );
00172
00173 #define DEFAULT_DURATION 39600
00174 #define SPOKES 30
00175 #define MAGNIFY 1.0
00176
00177 int lalDebugLevel = 0;
00178
00179 int main( int argc, char *argv[] ) {
00180 static LALStatus status;
00181 PtoleMetricIn in;
00182 REAL8 mismatch;
00183 REAL8Vector *metric;
00184 int j, k;
00185 int opt;
00186 BOOLEAN grace;
00187 BOOLEAN nongrace;
00188 int ra, dec, i;
00189 FILE *pvc = NULL;
00190 FILE *fnongrace = NULL;
00191 int metric_code;
00192
00193
00194
00195 REAL8Vector *tevlambda;
00196 MetricParamStruc tevparam;
00197 PulsarTimesParamStruc tevpulse;
00198
00199 EphemerisData *eph;
00200 int detector;
00201
00202
00203 REAL8 ra_point;
00204 REAL8 dec_point;
00205 float a,b,c,d,e,f;
00206 int ra_min, ra_max;
00207 int dec_min, dec_max;
00208 float f1;
00209 float tau;
00210 float c_ellipse;
00211 float r_ellipse;
00212 REAL8 determinant;
00213 REAL4 f0;
00214 UINT2 numSpindown;
00215 char earth[] = "earth00-04.dat";
00216 char sun[] = "sun00-04.dat";
00217
00218
00219 metric_code = 1;
00220 in.epoch.gpsSeconds = tevpulse.epoch.gpsSeconds = 731265908;
00221 in.epoch.gpsNanoSeconds = tevpulse.epoch.gpsNanoSeconds = 0.0;
00222 mismatch = 0.02;
00223 nongrace = 0;
00224 in.duration = tevparam.deltaT = DEFAULT_DURATION;
00225 grace = 0;
00226 detector = 4;
00227 ra_point = (24.1/60)*LAL_PI_180;
00228 dec_point = -(72+5./60)*LAL_PI_180;
00229 ra_min = 0;
00230 ra_max = 90;
00231 dec_min = 0;
00232 dec_max = 85;
00233 tau=1e10;
00234 f1 = tevparam.deltaT/tau;
00235 f0 = 1000;
00236 numSpindown = 0;
00237
00238
00239 while ((opt = getopt( argc, argv, "a:b:c:d:ef:l:m:n:pt:s:x" )) != -1) {
00240 switch (opt) {
00241 case 'a':
00242 metric_code = atoi( optarg );
00243 break;
00244 case 'b':
00245 in.epoch.gpsSeconds = tevpulse.epoch.gpsSeconds = atoi( optarg );
00246 break;
00247 case 'c':
00248 if( sscanf( optarg, "%f:%f:%f:%f:%f:%f", &a, &b, &c, &d, &e, &f ) != 6)
00249 {
00250 fprintf( stderr, "coordinates should be hh:mm:ss:dd:mm:ss\n" );
00251 }
00252 ra_point = (15*a+b/4+c/240)*LAL_PI_180;
00253 dec_point = (d+e/60+f/3600)*LAL_PI_180;
00254 break;
00255 case 'd':
00256 detector = atoi( optarg );
00257 break;
00258 case 'e':
00259 lalDebugLevel = 1;
00260 break;
00261 case 'f':
00262 f0 = atof( optarg );
00263 break;
00264 case 'l':
00265 if( sscanf( optarg, "%d:%d:%d:%d",
00266 &ra_min, &ra_max, &dec_min, &dec_max) != 4)
00267 {
00268 fprintf( stderr, "coordinates should be ra_min, ra_max, dec_min, dec_max all in degrees" );
00269 }
00270 break;
00271 case 'm':
00272 mismatch = atof( optarg );
00273 break;
00274 case 'n':
00275 numSpindown = atoi( optarg );
00276 break;
00277 case 'p':
00278 nongrace = 1;
00279 break;
00280 case 's':
00281 tau = atof( optarg );
00282 f1 = tevparam.deltaT/tau;
00283 break;
00284 case 't':
00285 in.duration = tevparam.deltaT = atof( optarg );
00286 break;
00287 case 'x':
00288 grace = 1;
00289 break;
00290 }
00291 }
00292
00293
00294 metric = NULL;
00295 LALDCreateVector( &status, &metric, (3+numSpindown)*(4+numSpindown)/2 );
00296 if( status.statusCode )
00297 {
00298 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00299 GENERALMETRICTESTC_MSGEMEM );
00300 return GENERALMETRICTESTC_EMEM;
00301 }
00302 tevlambda = NULL;
00303 LALDCreateVector( &status, &tevlambda, 3+numSpindown );
00304 if( status.statusCode )
00305 {
00306 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00307 GENERALMETRICTESTC_MSGEMEM );
00308 return GENERALMETRICTESTC_EMEM;
00309 }
00310
00311
00312 in.position.system = COORDINATESYSTEM_EQUATORIAL;
00313 in.position.longitude = tevlambda->data[1] = ra_point;
00314 in.position.latitude = tevlambda->data[2] = dec_point;
00315 in.maxFreq = tevlambda->data[0] = f0;
00316 in.spindown = NULL;
00317 if( numSpindown > 0 ) {
00318 LALCreateVector( &status, &(in.spindown), numSpindown );
00319 if( status.statusCode ) {
00320 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00321 GENERALMETRICTESTC_MSGEMEM );
00322 return GENERALMETRICTESTC_EMEM;
00323 }
00324 for( i=0; i<numSpindown; i++ ) {
00325 in.spindown->data[i] = 0;
00326 tevlambda->data[i+3] = 0;
00327 }
00328 }
00329
00330
00331 if(detector==1)
00332 tevpulse.site = &lalCachedDetectors[LALDetectorIndexLHODIFF];
00333 if(detector==2)
00334 tevpulse.site = &lalCachedDetectors[LALDetectorIndexLLODIFF];
00335 if(detector==3)
00336 tevpulse.site = &lalCachedDetectors[LALDetectorIndexVIRGODIFF];
00337 if(detector==4)
00338 tevpulse.site = &lalCachedDetectors[LALDetectorIndexGEO600DIFF];
00339 if(detector==5)
00340 tevpulse.site = &lalCachedDetectors[LALDetectorIndexTAMA300DIFF];
00341 in.site = tevpulse.site;
00342 tevpulse.latitude = in.site->frDetector.vertexLatitudeRadians;
00343 tevpulse.longitude = in.site->frDetector.vertexLongitudeRadians;
00344
00345
00346 tevparam.constants = &tevpulse;
00347 tevparam.n = 1;
00348 tevparam.errors = 0;
00349 tevparam.start = 0;
00350 tevpulse.t0 = 0.0;
00351
00352
00353 LALGetEarthTimes( &status, &tevpulse );
00354 if( status.statusCode )
00355 {
00356 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00357 GENERALMETRICTESTC_MSGESUB );
00358 return GENERALMETRICTESTC_ESUB;
00359 }
00360
00361
00362 eph = (EphemerisData *)LALMalloc(sizeof(EphemerisData));
00363 eph->ephiles.earthEphemeris = earth;
00364 eph->ephiles.sunEphemeris = sun;
00365 eph->leap = 13;
00366 LALInitBarycenter( &status, eph );
00367 if( status.statusCode )
00368 {
00369 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00370 GENERALMETRICTESTC_MSGESUB );
00371 return GENERALMETRICTESTC_ESUB;
00372 }
00373 tevpulse.ephemeris = eph;
00374
00375
00376 if( metric_code == 2 ) {
00377 tevpulse.t1 = LALTBaryPtolemaic;
00378 tevpulse.dt1 = LALDTBaryPtolemaic;
00379 }
00380 if( metric_code == 3 ) {
00381 tevpulse.t1 = LALTEphemeris;
00382 tevpulse.dt1 = LALDTEphemeris;
00383 }
00384 tevpulse.t2 = LALTSpin;
00385 tevpulse.dt2 = LALDTSpin;
00386 tevpulse.constants1 = &tevpulse;
00387 tevpulse.constants2 = &tevpulse;
00388 tevpulse.nArgs = 2;
00389 if( numSpindown > 0 ) {
00390 tevparam.dtCanon = LALDTComp;
00391 }
00392 else {
00393 if( metric_code == 2 )
00394 tevparam.dtCanon = LALDTBaryPtolemaic;
00395 if( metric_code == 3 )
00396 tevparam.dtCanon = LALDTEphemeris;
00397 }
00398
00399
00400 if(metric_code==1)
00401 {
00402 LALPtoleMetric( &status, metric, &in );
00403 if( status.statusCode )
00404 {
00405 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00406 GENERALMETRICTESTC_MSGESUB );
00407 return GENERALMETRICTESTC_ESUB;
00408 }
00409 }
00410 if(metric_code==2 || metric_code==3)
00411 {
00412 LALCoherentMetric( &status, metric, tevlambda, &tevparam );
00413 if( status.statusCode )
00414 {
00415 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00416 GENERALMETRICTESTC_MSGESUB );
00417 return GENERALMETRICTESTC_ESUB;
00418 }
00419 }
00420
00421
00422 printf("\nmetric (f0, alpha, delta, ...) at the requested point\n");
00423 for (j=0; j<=2+numSpindown; j++) {
00424 for (k=0; k<=j; k++)
00425 printf( " %+.4e", metric->data[k+j*(j+1)/2] );
00426 printf("\n");
00427 }
00428
00429
00430 determinant = metric->data[5]*metric->data[2] - pow(metric->data[4],2);
00431 printf( "\nSky-determinant %e\n", determinant );
00432 if( numSpindown == 1 ) {
00433 determinant = metric->data[2] * metric->data[5] * metric->data[9]
00434 - metric->data[2] * metric->data[8] * metric->data[8]
00435 + metric->data[4] * metric->data[8] * metric->data[7]
00436 - metric->data[4] * metric->data[4] * metric->data[9]
00437 + metric->data[7] * metric->data[4] * metric->data[8]
00438 - metric->data[7] * metric->data[7] * metric->data[5];
00439 printf( "S&S determinant %e\n", determinant );
00440 }
00441
00442
00443 LALProjectMetric( &status, metric, 0 );
00444 if( status.statusCode )
00445 {
00446 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00447 GENERALMETRICTESTC_MSGESUB );
00448 return GENERALMETRICTESTC_ESUB;
00449 }
00450
00451
00452 printf("\nf-projected metric (alpha, delta, ...) at the requested point\n");
00453 for (j=1; j<=2+numSpindown; j++) {
00454 for (k=1; k<=j; k++)
00455 printf( " %+.4e", metric->data[k+j*(j+1)/2] );
00456 printf( "\n" );
00457 }
00458
00459
00460 determinant = metric->data[5]*metric->data[2] - pow(metric->data[4],2);
00461 printf( "\nSky-determinant %e\n", determinant );
00462 if( numSpindown == 1 ) {
00463 determinant = metric->data[2] * metric->data[5] * metric->data[9]
00464 - metric->data[2] * metric->data[8] * metric->data[8]
00465 + metric->data[4] * metric->data[8] * metric->data[7]
00466 - metric->data[4] * metric->data[4] * metric->data[9]
00467 + metric->data[7] * metric->data[4] * metric->data[8]
00468 - metric->data[7] * metric->data[7] * metric->data[5];
00469 printf( "S&S determinant %e\n", determinant );
00470 }
00471
00472
00473
00474 if (grace || nongrace) {
00475
00476
00477 if(grace)
00478 {
00479 pvc = popen( "xmgrace -pipe", "w" );
00480 if( !pvc )
00481 {
00482 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00483 GENERALMETRICTESTC_MSGESYS );
00484 return GENERALMETRICTESTC_ESYS;
00485 }
00486 fprintf( pvc, "@xaxis label \"Right ascension (degrees)\"\n" );
00487 fprintf( pvc, "@yaxis label \"Declination (degrees)\"\n" );
00488 }
00489 if(nongrace)
00490 {
00491 fnongrace = fopen( "nongrace.data", "w" );
00492 if( !fnongrace )
00493 {
00494 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00495 GENERALMETRICTESTC_MSGESYS );
00496 return GENERALMETRICTESTC_ESYS;
00497 }
00498 }
00499
00500
00501 j = 0;
00502 for (dec=dec_max; dec>=dec_min; dec-=10) {
00503 for (ra=ra_min; ra<=ra_max; ra+=15) {
00504 REAL8 gaa, gad, gdd, angle, smaj, smin;
00505
00506
00507 in.position.longitude = tevlambda->data[1] = ra*LAL_PI_180;
00508 in.position.latitude = tevlambda->data[2] = dec*LAL_PI_180;
00509
00510
00511 if(metric_code==1)
00512 {
00513 LALPtoleMetric( &status, metric, &in );
00514 if( status.statusCode )
00515 {
00516 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00517 GENERALMETRICTESTC_MSGESUB );
00518 return GENERALMETRICTESTC_ESUB;
00519 }
00520 }
00521 if(metric_code==2 || metric_code==3)
00522 {
00523 LALCoherentMetric( &status, metric, tevlambda, &tevparam );
00524 if( status.statusCode )
00525 {
00526 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00527 GENERALMETRICTESTC_MSGESUB );
00528 return GENERALMETRICTESTC_ESUB;
00529 }
00530 }
00531
00532
00533 LALProjectMetric( &status, metric, 0 );
00534 if( status.statusCode )
00535 {
00536 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00537 GENERALMETRICTESTC_MSGESUB );
00538 return GENERALMETRICTESTC_ESUB;
00539 }
00540 determinant = metric->data[5]*metric->data[2]-pow(metric->data[4],2.0);
00541 if(determinant < 0.0)
00542 {
00543 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00544 GENERALMETRICTESTC_MSGEMET );
00545 return GENERALMETRICTESTC_EMET;
00546 }
00547
00548
00549
00550
00551 gaa = metric->data[2];
00552
00553 gad = metric->data[4];
00554
00555 gdd = metric->data[5];
00556
00557 smin = gaa+gdd + sqrt( pow(gaa-gdd,2) + pow(2*gad,2) );
00558 smin = sqrt(2*mismatch/smin);
00559
00560 smaj = gaa+gdd - sqrt( pow(gaa-gdd,2) + pow(2*gad,2) );
00561
00562 smaj = sqrt(2*mismatch/smaj);
00563
00564 angle = atan2( gad, mismatch/smaj/smaj-gdd );
00565 if (angle <= -LAL_PI_2) angle += LAL_PI;
00566 if (angle > LAL_PI_2) angle -= LAL_PI;
00567
00568 if(grace)
00569 {
00570
00571 fprintf( pvc, "@s%d color (0,0,0)\n", j );
00572 fprintf( pvc, "@target G0.S%d\n@type xy\n", j++ );
00573
00574 fprintf( pvc, "%16.8g %16.8g\n", (float)ra, (float)dec );
00575 }
00576 if(nongrace)
00577
00578 fprintf( fnongrace, "%16.8g %16.8g\n", (float)ra, (float)dec );
00579
00580 for (i=0; i<=SPOKES; i++) {
00581 c_ellipse = LAL_TWOPI*i/SPOKES;
00582 r_ellipse = MAGNIFY*LAL_180_PI*smaj*smin /
00583 sqrt( pow(smaj*sin(c_ellipse),2) + pow(smin*cos(c_ellipse),2) );
00584 if(grace)
00585 fprintf( pvc, "%e %e\n", ra+r_ellipse*cos(angle-c_ellipse),
00586 dec+r_ellipse*sin(angle-c_ellipse) );
00587 if(nongrace)
00588 fprintf( fnongrace, "%e %e\n", ra+r_ellipse*cos(angle-c_ellipse),
00589 dec+r_ellipse*sin(angle-c_ellipse) );
00590
00591 }
00592
00593 }
00594 }
00595 if(grace)
00596 fclose( pvc );
00597 if(nongrace)
00598 fclose( fnongrace );
00599 }
00600
00601 printf("\nCleaning up and leaving...\n");
00602
00603 LALFree( eph->ephemE );
00604 if( status.statusCode )
00605 {
00606 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00607 GENERALMETRICTESTC_MSGEMEM );
00608 return GENERALMETRICTESTC_EMEM;
00609 }
00610 LALFree( eph->ephemS );
00611 if( status.statusCode )
00612 {
00613 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00614 GENERALMETRICTESTC_MSGEMEM );
00615 return GENERALMETRICTESTC_EMEM;
00616 }
00617 LALFree( eph );
00618 if( status.statusCode )
00619 {
00620 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00621 GENERALMETRICTESTC_MSGEMEM );
00622 return GENERALMETRICTESTC_EMEM;
00623 }
00624
00625 LALDDestroyVector( &status, &metric );
00626 if( status.statusCode )
00627 {
00628 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00629 GENERALMETRICTESTC_MSGEMEM );
00630 return GENERALMETRICTESTC_EMEM;
00631 }
00632 LALDDestroyVector( &status, &tevlambda );
00633 if( status.statusCode )
00634 {
00635 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00636 GENERALMETRICTESTC_MSGEMEM );
00637 return GENERALMETRICTESTC_EMEM;
00638 }
00639 if( in.spindown )
00640 LALDestroyVector( &status, &(in.spindown) );
00641
00642 if( status.statusCode )
00643 {
00644 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00645 GENERALMETRICTESTC_MSGEMEM );
00646 return GENERALMETRICTESTC_EMEM;
00647 }
00648 LALCheckMemoryLeaks();
00649 return 0;
00650 }