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 #define PULSARCATTESTC_ENORM 0
00102 #define PULSARCATTESTC_ESUB 1
00103 #define PULSARCATTESTC_EARG 2
00104 #define PULSARCATTESTC_EVAL 3
00105 #define PULSARCATTESTC_EMEM 4
00106 #define PULSARCATTESTC_EFILE 5
00107
00108 #define PULSARCATTESTC_MSGENORM "Normal exit"
00109 #define PULSARCATTESTC_MSGESUB "Subroutine failed"
00110 #define PULSARCATTESTC_MSGEARG "Error parsing arguments"
00111 #define PULSARCATTESTC_MSGEVAL "Input argument out of valid range"
00112 #define PULSARCATTESTC_MSGEMEM "Out of memory"
00113 #define PULSARCATTESTC_MSGEFILE "Could not open file"
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
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
00155
00156
00157 #include <stdlib.h>
00158 #include <lal/LALStdio.h>
00159 #include <lal/LALStdlib.h>
00160 #include <lal/LALConstants.h>
00161 #include <lal/StringInput.h>
00162 #include <lal/StreamInput.h>
00163 #include <lal/AVFactories.h>
00164 #include <lal/SeqFactories.h>
00165 #include <lal/Random.h>
00166 #include <lal/LALInitBarycenter.h>
00167 #include <lal/Date.h>
00168 #include <lal/StringInput.h>
00169 #include <lal/DetectorSite.h>
00170 #include <lal/PulsarCat.h>
00171
00172 NRCSID( PULSARCATTESTC, "$Id: PulsarCatTest.c,v 1.6 2007/06/08 14:41:52 bema Exp $" );
00173
00174
00175 int lalDebugLevel = 0;
00176 #define J2000GPS 630763213
00177 #define J2000JD 2451545
00178
00179
00180 #define USAGE "Usage: %s [-p posepoch ra dec pmra pmdec]\n" \
00181 "\t[-l site earthfile sunfile] [-h]\n" \
00182 "\t[-t newepoch] [-i infile] [-o outfile] [-d debuglevel]\n" \
00183 "\t[fepoch f0 [f1 ...]]\n"
00184
00185
00186 #define WHITESPACES " \b\f\n\r\t\v"
00187
00188
00189
00190 #define MAXLEN 1024
00191
00192
00193 #define ERROR( code, msg, statement ) \
00194 do \
00195 if ( lalDebugLevel & LALERROR ) \
00196 { \
00197 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
00198 " %s %s\n", (code), *argv, __FILE__, \
00199 __LINE__, PULSARCATTESTC, \
00200 statement ? statement : "", (msg) ); \
00201 } \
00202 while (0)
00203
00204 #define INFO( statement ) \
00205 do \
00206 if ( lalDebugLevel & LALINFO ) \
00207 { \
00208 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
00209 " %s\n", *argv, __FILE__, __LINE__, \
00210 PULSARCATTESTC, (statement) ); \
00211 } \
00212 while (0)
00213
00214 #define WARNING( statement ) \
00215 do \
00216 if ( lalDebugLevel & LALWARNING ) \
00217 { \
00218 LALPrintError( "Warning[0]: program %s, file %s, line %d, %s\n" \
00219 " %s\n", *argv, __FILE__, __LINE__, \
00220 PULSARCATTESTC, (statement) ); \
00221 } \
00222 while (0)
00223
00224 #define SUB( func, statusptr ) \
00225 do \
00226 if ( (func), (statusptr)->statusCode ) \
00227 { \
00228 ERROR( PULSARCATTESTC_ESUB, PULSARCATTESTC_MSGESUB, \
00229 "Function call \"" #func "\" failed:" ); \
00230 return PULSARCATTESTC_ESUB; \
00231 } \
00232 while (0)
00233
00234 #define CHECKVAL( val, lower, upper ) \
00235 do \
00236 if ( ( (val) < (lower) ) || ( (val) > (upper) ) ) \
00237 { \
00238 ERROR( PULSARCATTESTC_EVAL, PULSARCATTESTC_MSGEVAL, \
00239 "Value of " #val " out of range:" ); \
00240 if ( lalDebugLevel & LALERROR ) \
00241 LALPrintError( #val " = %f, range = [%f,%f]\n", (REAL8)(val), \
00242 (REAL8)(lower), (REAL8)(upper) ); \
00243 return PULSARCATTESTC_EVAL; \
00244 } \
00245 while (0)
00246
00247
00248 #ifndef NDEBUG
00249 char *lalWatch;
00250 #endif
00251
00252
00253 static void
00254 ParseEpoch( LALStatus *stat, LIGOTimeGPS *epoch, const CHAR *string );
00255
00256
00257
00258 int
00259 fprintderr( FILE *fp, REAL8 x, REAL8 dx );
00260
00261
00262 int
00263 fprintepoch( FILE *fp, LIGOTimeGPS epoch );
00264
00265
00266 int
00267 main(int argc, char **argv)
00268 {
00269 static LALStatus stat;
00270 int arg;
00271 BOOLEAN posGiven = 0;
00272 CHAR *infile = NULL;
00273 CHAR *outfile = NULL;
00274 CHAR *earthfile = NULL;
00275 CHAR *sunfile = NULL;
00276 CHAR *site = NULL;
00277 PulsarCatNode node;
00278 LIGOTimeGPS epoch;
00279 LALPlaceAndGPS detectorTime;
00280 EphemerisData *edat = NULL;
00281
00282
00283 memset( &node, 0, sizeof(PulsarCatNode) );
00284 epoch.gpsSeconds = J2000GPS;
00285 epoch.gpsNanoSeconds = 0;
00286 detectorTime.p_gps = &epoch;
00287 detectorTime.p_detector = NULL;
00288
00289
00290
00291
00292
00293
00294 arg = 1;
00295 while ( arg < argc ) {
00296
00297 if ( !strcmp( argv[arg], "-p" ) ) {
00298 if ( argc > arg + 5 ) {
00299 arg++;
00300 SUB( ParseEpoch( &stat, &(node.posepoch), argv[arg++] ),
00301 &stat );
00302 node.pos.system = COORDINATESYSTEM_EQUATORIAL;
00303 node.pos.longitude = atof( argv[arg++] );
00304 node.pos.latitude = atof( argv[arg++] );
00305 node.pm.system = COORDINATESYSTEM_EQUATORIAL;
00306 node.pm.longitude = atof( argv[arg++] );
00307 node.pm.latitude = atof( argv[arg++] );
00308 posGiven = 1;
00309 } else {
00310 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00311 LALPrintError( USAGE, *argv );
00312 return PULSARCATTESTC_EARG;
00313 }
00314 }
00315
00316 else if ( !strcmp( argv[arg], "-l" ) ) {
00317 if ( argc > arg + 3 ) {
00318 arg++;
00319 site = argv[arg++];
00320 earthfile = argv[arg++];
00321 sunfile = argv[arg++];
00322 } else {
00323 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00324 LALPrintError( USAGE, *argv );
00325 return PULSARCATTESTC_EARG;
00326 }
00327 }
00328
00329 else if ( !strcmp( argv[arg], "-t" ) ) {
00330 if ( argc > arg + 1 ) {
00331 arg++;
00332 SUB( ParseEpoch( &stat, &epoch, argv[arg++] ), &stat );
00333 } else {
00334 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00335 LALPrintError( USAGE, *argv );
00336 return PULSARCATTESTC_EARG;
00337 }
00338 }
00339
00340 else if ( !strcmp( argv[arg], "-i" ) ) {
00341 if ( argc > arg + 1 ) {
00342 arg++;
00343 infile = argv[arg++];
00344 } else {
00345 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00346 LALPrintError( USAGE, *argv );
00347 return PULSARCATTESTC_EARG;
00348 }
00349 }
00350
00351 else if ( !strcmp( argv[arg], "-o" ) ) {
00352 if ( argc > arg + 1 ) {
00353 arg++;
00354 outfile = argv[arg++];
00355 } else {
00356 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00357 LALPrintError( USAGE, *argv );
00358 return PULSARCATTESTC_EARG;
00359 }
00360 }
00361
00362 else if ( !strcmp( argv[arg], "-d" ) ) {
00363 if ( argc > arg + 1 ) {
00364 arg++;
00365 lalDebugLevel = atoi( argv[arg++] );
00366 } else {
00367 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00368 LALPrintError( USAGE, *argv );
00369 return PULSARCATTESTC_EARG;
00370 }
00371 }
00372
00373 else if ( !strcmp( argv[arg], "-h" ) ) {
00374 INFO( PULSARCATTESTC_MSGENORM );
00375 LALPrintError( USAGE, *argv );
00376 return PULSARCATTESTC_ENORM;
00377 }
00378
00379 else if ( argc >= arg + 2 ) {
00380 REAL8 *f;
00381 SUB( ParseEpoch( &stat, &(node.fepoch), argv[arg++] ), &stat );
00382 SUB( LALDCreateVector( &stat, &(node.f), argc - arg ), &stat );
00383 for ( f = node.f->data; arg < argc; f++ )
00384 *f = atof( argv[arg++] );
00385 }
00386
00387 else {
00388 ERROR( PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG, 0 );
00389 LALPrintError( USAGE, *argv );
00390 return PULSARCATTESTC_EARG;
00391 }
00392 }
00393
00394
00395
00396
00397
00398
00399 if ( !posGiven ) {
00400 RandomParams *params = NULL;
00401 REAL4 x;
00402 SUB( LALCreateRandomParams( &stat, ¶ms, 0 ), &stat );
00403 node.pos.system = COORDINATESYSTEM_EQUATORIAL;
00404 SUB( LALUniformDeviate( &stat, &x, params ), &stat );
00405 node.pos.longitude = LAL_TWOPI*x;
00406 SUB( LALUniformDeviate( &stat, &x, params ), &stat );
00407 node.pos.latitude = LAL_PI*( x - 0.5 );
00408 SUB( LALDestroyRandomParams( &stat, ¶ms ), &stat );
00409 node.posepoch.gpsSeconds = J2000GPS;
00410 node.posepoch.gpsNanoSeconds = 0;
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 }
00459
00460
00461 if ( site ) {
00462 UINT4 i;
00463 if ( !strcmp( site, "LHO" ) )
00464 i = LALDetectorIndexLHODIFF;
00465 else if ( !strcmp( site, "LLO" ) )
00466 i = LALDetectorIndexLLODIFF;
00467 else if ( !strcmp( site, "VIRGO" ) )
00468 i = LALDetectorIndexVIRGODIFF;
00469 else if ( !strcmp( site, "GEO600" ) )
00470 i = LALDetectorIndexGEO600DIFF;
00471 else if ( !strcmp( site, "TAMA300" ) )
00472 i = LALDetectorIndexTAMA300DIFF;
00473 else if ( !strcmp( site, "CIT40" ) )
00474 i = LALDetectorIndexCIT40DIFF;
00475 else {
00476 ERROR( PULSARCATTESTC_EVAL, PULSARCATTESTC_MSGEVAL,
00477 "Unrecognized site:" );
00478 if ( lalDebugLevel & LALERROR )
00479 LALPrintError( "%s", site );
00480 return PULSARCATTESTC_EVAL;
00481 }
00482 detectorTime.p_detector =
00483 (LALDetector *)LALMalloc( sizeof(LALDetector) );
00484 if ( !(detectorTime.p_detector) ) {
00485 ERROR( PULSARCATTESTC_EMEM, PULSARCATTESTC_MSGEMEM, 0 );
00486 return PULSARCATTESTC_EMEM;
00487 }
00488 *(detectorTime.p_detector) = lalCachedDetectors[i];
00489
00490
00491 edat = (EphemerisData *)LALMalloc( sizeof(EphemerisData) );
00492 if ( !(edat) ) {
00493 ERROR( PULSARCATTESTC_EMEM, PULSARCATTESTC_MSGEMEM, 0 );
00494 return PULSARCATTESTC_EMEM;
00495 }
00496 edat->ephiles.earthEphemeris = earthfile;
00497 edat->ephiles.sunEphemeris = sunfile;
00498 SUB( LALInitBarycenter( &stat, edat ), &stat );
00499 }
00500
00501
00502
00503 if ( infile ) {
00504 UINT4 i = 0;
00505 UINT4 n = 0;
00506 CHAR msg[MAXLEN];
00507 CHARVectorSequence *file = NULL;
00508 TokenList *list = NULL;
00509 INT4 indx[PULSARCATINDEX_NUM];
00510 PulsarCatNode *here = &node;
00511 FILE *fp = NULL;
00512
00513
00514 if ( !strcmp( infile, "stdin" ) )
00515 fp = stdin;
00516 else
00517 fp = fopen( infile, "r" );
00518 if ( fp == NULL ) {
00519 ERROR( PULSARCATTESTC_EFILE, PULSARCATTESTC_MSGEFILE, infile );
00520 return PULSARCATTESTC_EFILE;
00521 }
00522 SUB( LALCHARReadVectorSequence( &stat, &file, fp ), &stat );
00523 fclose( fp );
00524
00525
00526 SUB( LALCreateTokenList( &stat, &list, file->data, WHITESPACES ),
00527 &stat );
00528 while ( list->nTokens < 3 && ++i < file->length ) {
00529 SUB( LALDestroyTokenList( &stat, &list ), &stat );
00530 SUB( LALCreateTokenList( &stat, &list, file->data +
00531 i*file->vectorLength, WHITESPACES ),
00532 &stat );
00533 }
00534 if ( i >= file->length ) {
00535 WARNING( "No header found in input file" );
00536 } else {
00537 SUB( LALReadPulsarCatHead( &stat, indx, list ), &stat );
00538 }
00539 SUB( LALDestroyTokenList( &stat, &list ), &stat );
00540
00541
00542 while ( ++i < file->length ) {
00543 SUB( LALCreateTokenList( &stat, &list, file->data +
00544 i*file->vectorLength, WHITESPACES ),
00545 &stat );
00546 while ( list->nTokens < 3 && ++i < file->length ) {
00547 SUB( LALDestroyTokenList( &stat, &list ), &stat );
00548 SUB( LALCreateTokenList( &stat, &list, file->data +
00549 i*file->vectorLength, WHITESPACES ),
00550 &stat );
00551 }
00552 if ( i < file->length ) {
00553 if ( !( here->next = (PulsarCatNode *)
00554 LALMalloc( sizeof(PulsarCatNode) ) ) ) {
00555 ERROR( PULSARCATTESTC_EMEM, PULSARCATTESTC_MSGEMEM, 0 );
00556 return PULSARCATTESTC_EMEM;
00557 }
00558 memset( here->next, 0, sizeof(PulsarCatNode) );
00559
00560
00561 LALReadPulsarCatLine( &stat, here->next, list, indx );
00562 if ( stat.statusCode ) {
00563 LALSnprintf( msg, MAXLEN, "Error reading line %i of %s:"
00564 " skipping", i, infile );
00565 ERROR( 0, msg, 0 );
00566 if ( stat.statusPtr ) {
00567 FREESTATUSPTR( &stat );
00568 }
00569 memset( &stat, 0, sizeof(LALStatus) );
00570 SUB( LALDestroyPulsarCat( &stat, &(here->next) ), &stat );
00571 } else {
00572 here = here->next;
00573 n++;
00574 }
00575 }
00576 SUB( LALDestroyTokenList( &stat, &list ), &stat );
00577 }
00578 LALSnprintf( msg, MAXLEN, "File %s had %i lines and %i parseable"
00579 " pulsars", infile, i, n );
00580 INFO( msg );
00581 SUB( LALCHARDestroyVectorSequence( &stat, &file ), &stat );
00582 }
00583
00584
00585
00586
00587
00588
00589
00590 SUB( LALUpdatePulsarCat( &stat, &node, &detectorTime, edat ),
00591 &stat );
00592
00593
00594 if ( outfile ) {
00595 PulsarCatNode *here = &node;
00596 FILE *fp = NULL;
00597 if ( !strcmp( outfile, "stdout" ) )
00598 fp = stdout;
00599 else if ( !strcmp( outfile, "stderr" ) )
00600 fp = stderr;
00601 else
00602 fp = fopen( outfile, "w" );
00603 if ( fp == NULL ) {
00604 ERROR( PULSARCATTESTC_EFILE, PULSARCATTESTC_MSGEFILE, outfile );
00605 return PULSARCATTESTC_EFILE;
00606 }
00607 if ( infile )
00608 here = here->next;
00609
00610
00611 if ( site ) {
00612 fprintf( fp, "%s time = ", site );
00613 fprintepoch( fp, epoch );
00614 fprintf( fp, "\n" );
00615 }
00616
00617
00618 while ( here ) {
00619 CompanionNode *companion = here->companion;
00620 UINT4 compNo = 0;
00621 fprintf( fp, "\n" );
00622 if ( here->jname[0] != '\0' ) {
00623 fprintf( fp, "PULSAR %s", here->jname );
00624 if ( here->bname[0] != '\0' )
00625 fprintf( fp, " (%s)", here->bname );
00626 fprintf( fp, "\n" );
00627 } else if ( here->bname[0] != '\0' )
00628 fprintf( fp, "PULSAR %s\n", here->bname );
00629 else
00630 fprintf( fp, "PULSAR (Unknown)\n" );
00631 fprintf( fp, "epoch = " );
00632 fprintepoch( fp, here->posepoch );
00633 fprintf( fp, "\n" );
00634 fprintf( fp, "ra = " );
00635 fprintderr( fp, here->pos.longitude, here->dpos.longitude );
00636 fprintf( fp, " rad\n" );
00637 fprintf( fp, "dec = " );
00638 fprintderr( fp, here->pos.latitude, here->dpos.latitude );
00639 fprintf( fp, " rad\n" );
00640 fprintf( fp, "pmra = " );
00641 fprintderr( fp, here->pm.longitude, here->dpm.longitude );
00642 fprintf( fp, " rad/s\n" );
00643 fprintf( fp, "pmdec = " );
00644 fprintderr( fp, here->pm.latitude, here->dpm.latitude );
00645 fprintf( fp, " rad/s\n" );
00646
00647
00648 if ( here->f ) {
00649 UINT4 i;
00650 fprintf( fp, "f0 = " );
00651 fprintderr( fp, 2.0*here->f->data[0], 2.0*here->df->data[0] );
00652 fprintf( fp, " Hz\n" );
00653 for ( i = 1; i < here->f->length; i++ ) {
00654 fprintf( fp, "f%i = ", i );
00655 fprintderr( fp, 2.0*here->f->data[i], 2.0*here->df->data[i] );
00656 fprintf( fp, " Hz^%i\n", i+1 );
00657 }
00658
00659
00660 }
00661 if ( here->dist > 0.0 )
00662 fprintf( fp, "dist = %15.8e m\n", here->dist );
00663 if ( here->dmin > 0.0 )
00664 fprintf( fp, "dmin = %15.8e m\n", here->dmin );
00665 if ( here->dmax > 0.0 )
00666 fprintf( fp, "dmax = %15.8e m\n", here->dmax );
00667 if ( here->lcode >= 'a' && here->lcode <= 'd' )
00668 fprintf( fp, "lcode = %c\n", here->lcode );
00669 if ( here->ucode >= 'a' && here->ucode <= 'd' )
00670 fprintf( fp, "ucode = %c\n", here->ucode );
00671
00672 while ( companion ) {
00673 fprintf( fp, "Companion %i\n", ++compNo );
00674
00675
00676 fprintf( fp, " epoch = " );
00677 fprintepoch( fp, companion->epoch );
00678 fprintf( fp, "\n" );
00679 fprintf( fp, " x = %23.16e s\n", companion->x );
00680 fprintf( fp, " p = %23.16e s\n", companion->p );
00681 fprintf( fp, " pDot = %23.16e\n", companion->pDot );
00682 fprintf( fp, " w = %23.16e rad\n", companion->w );
00683 fprintf( fp, " wDot = %23.16e rad/s\n", companion->wDot );
00684 fprintf( fp, " ecc = %23.16e\n", companion->ecc );
00685 fprintf( fp, " gamma = %23.16e s\n", companion->gamma );
00686 fprintf( fp, " sin = %23.16e\n", companion->sin );
00687 fprintf( fp, " r = %23.16e\n", companion->r );
00688 companion = companion->next;
00689 }
00690 here = here->next;
00691 }
00692 fclose( fp );
00693 }
00694
00695
00696
00697
00698
00699
00700
00701 if ( node.next ) {
00702 SUB( LALDestroyPulsarCat( &stat, &(node.next) ), &stat );
00703 }
00704 if ( node.f ) {
00705 SUB( LALDDestroyVector( &stat, &(node.f) ), &stat );
00706 }
00707 if ( node.df ) {
00708 SUB( LALDDestroyVector( &stat, &(node.df) ), &stat );
00709 }
00710 if ( edat ) {
00711 if ( edat->ephemE )
00712 LALFree( edat->ephemE );
00713 if ( edat->ephemS )
00714 LALFree( edat->ephemS );
00715 LALFree( edat );
00716 }
00717 if ( detectorTime.p_detector )
00718 LALFree( detectorTime.p_detector );
00719
00720
00721 LALCheckMemoryLeaks();
00722 INFO( PULSARCATTESTC_MSGENORM );
00723 return PULSARCATTESTC_ENORM;
00724 }
00725
00726
00727
00728 static void
00729 ParseEpoch( LALStatus *stat, LIGOTimeGPS *epoch, const CHAR *string )
00730 {
00731 INT8 gpsNan;
00732 CHAR *endptr;
00733
00734 INITSTATUS( stat, "ParseEpoch", PULSARCATTESTC );
00735 ATTATCHSTATUSPTR( stat );
00736
00737
00738 if ( string[0] == 'J' ) {
00739 REAL8 julianDay;
00740 INT4 leap1, leap2;
00741 LALLeapSecFormatAndAcc acc;
00742 if ( string[1] == 'D' ) {
00743 TRY( LALStringToD( stat->statusPtr, &julianDay, string+2,
00744 &endptr ), stat );
00745 if ( endptr == string+2 ) {
00746 ABORT( stat, PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG );
00747 }
00748 } else {
00749 TRY( LALStringToD( stat->statusPtr, &julianDay, string+1,
00750 &endptr ), stat );
00751 if ( endptr == string+1 ) {
00752 ABORT( stat, PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG );
00753 }
00754 julianDay -= 2000.0;
00755 julianDay *= 365.25;
00756 julianDay += J2000JD;
00757 }
00758
00759
00760 acc.accuracy = LALLEAPSEC_STRICT;
00761 acc.format = LALLEAPSEC_GPSUTC;
00762 gpsNan = (INT8)( ( julianDay - 2444244.5 )*(8.64e13L) );
00763 TRY( LALINT8toGPS( stat->statusPtr, epoch, &gpsNan ), stat );
00764 leap2 = 0;
00765 do {
00766 leap1 = leap2;
00767 TRY( LALLeapSecs( stat->statusPtr, &leap2, epoch, &acc ),
00768 stat );
00769 epoch->gpsSeconds += leap2 - leap1;
00770 } while ( leap2 != leap1 );
00771 }
00772
00773
00774 else {
00775 TRY( LALStringToI8( stat->statusPtr, &gpsNan, string, &endptr ),
00776 stat );
00777 if ( endptr == string ) {
00778 ABORT( stat, PULSARCATTESTC_EARG, PULSARCATTESTC_MSGEARG );
00779 }
00780 TRY( LALINT8toGPS( stat->statusPtr, epoch, &gpsNan ), stat );
00781 }
00782
00783
00784 DETATCHSTATUSPTR( stat );
00785 RETURN( stat );
00786 }
00787
00788
00789 int
00790 fprintderr( FILE *fp, REAL8 x, REAL8 dx ) {
00791 CHAR format[MAXLEN];
00792 INT4 gsd = 0;
00793 INT4 lsd = 0;
00794 REAL8 norm;
00795
00796
00797 if ( dx < LAL_REAL8_EPS*fabs( x ) )
00798 dx = 0.0;
00799 if ( dx > 0.0 ) {
00800 REAL8 lsdd = log( 0.5*dx )/log( 10.0 );
00801 if ( lsdd >= 0.0 )
00802 lsd = (INT4)( lsdd );
00803 else
00804 lsd = (INT4)( lsdd ) - 1;
00805 }
00806 if ( x != 0.0 ) {
00807 REAL8 gsdd = log( fabs( x ) )/log( 10.0 );
00808 if ( gsdd >= 0.0 )
00809 gsd = (INT4)( gsdd );
00810 else
00811 gsd = (INT4)( gsdd ) - 1;
00812 }
00813
00814
00815 if ( x == 0.0 ) {
00816 if ( dx <= 0.0 )
00817 return fprintf( fp, "0" );
00818 if ( abs( lsd ) > 3 ) {
00819 norm = pow( 10.0, -lsd );
00820 return fprintf( fp, "( 0 +/- %.0f )e%+i", dx*norm, lsd );
00821 }
00822 if ( lsd <= 0 ) {
00823 LALSnprintf( format, MAXLEN, "%%.%if +/- %%.%if", -lsd, -lsd );
00824 return fprintf( fp, format, 0.0, dx );
00825 }
00826 norm = pow( 10.0, -lsd );
00827 LALSnprintf( format, MAXLEN, "0 +/- %%.0f%%0%ii", lsd );
00828 return fprintf( fp, format, dx*norm, 0 );
00829 }
00830
00831
00832 if ( dx <= 0.0 ) {
00833 if ( abs( gsd ) > 3 )
00834 return fprintf( fp, "%.16e", x );
00835 LALSnprintf( format, MAXLEN, "%%.%if", 16 - gsd );
00836 return fprintf( fp, format, x );
00837 }
00838
00839
00840 if ( gsd < lsd )
00841 gsd = lsd;
00842 if ( lsd > 3 || gsd < -3 ) {
00843 norm = pow( 10.0, -gsd );
00844 LALSnprintf( format, MAXLEN, "( %%.%if +/- %%.%if )e