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 #include <math.h>
00028
00029 #include <lal/AVFactories.h>
00030 #include <lal/PulsarDataTypes.h>
00031 #include <lal/ExtrapolatePulsarSpins.h>
00032
00033 NRCSID (PULSARSPINTESTC, "$Id: ExtrapolatePulsarSpinsTest.c,v 1.9 2006/10/20 13:59:07 reinhard Exp $");
00034
00035
00036
00037 #define PULSARSPINTESTC_ENORM 0
00038 #define PULSARSPINTESTC_ESUB 1
00039
00040 #define PULSARSPINTESTC_MSGENORM "Normal exit"
00041 #define PULSARSPINTESTC_MSGESUB "Subroutine failed"
00042
00043
00044
00045 #define RELERROR(x, y) fabs( 2.0 * ((x) - (y)) / ( (x) + (y) ) )
00046
00047
00048
00049
00050
00051
00052 #define ERROR( code, msg, statement ) \
00053 do { \
00054 if ( lalDebugLevel & LALERROR ) \
00055 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
00056 " %s %s\n", (code), *argv, __FILE__, \
00057 __LINE__, PULSARSPINTESTC, statement ? statement : \
00058 "", (msg) ); \
00059 } while (0)
00060
00061 #define INFO( statement ) \
00062 do { \
00063 if ( lalDebugLevel & LALINFO ) \
00064 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
00065 " %s\n", *argv, __FILE__, __LINE__, \
00066 PULSARSPINTESTC, (statement) ); \
00067 } while (0)
00068
00069 #define SUB( func, statusptr ) \
00070 do { \
00071 if ( (func), (statusptr)->statusCode ) { \
00072 ERROR( PULSARSPINTESTC_ESUB, PULSARSPINTESTC_MSGESUB, \
00073 "Function call \"" #func "\" failed:" ); \
00074 return PULSARSPINTESTC_ESUB; \
00075 } \
00076 } while (0)
00077
00078
00079 static LALStatus empty_status;
00080
00081
00082
00083 int main(int argc, char *argv[])
00084 {
00085 LALStatus status = empty_status;
00086 PulsarSpins result;
00087 PulsarSpins fkdot0, fkdot1;
00088 REAL8 tolerance = 1.0e-12;
00089 REAL8 tolerancePhi = 1.0e-6;
00090
00091 PulsarSpinRange range0, range2;
00092 PulsarSpinRange rangeResult;
00093
00094 LIGOTimeGPS epoch0 = {714180733, 0};
00095 LIGOTimeGPS epoch1 = {714180733 + 94608000, 0};
00096 LIGOTimeGPS epoch2 = {714180733 - 94608000, 0};
00097
00098 if ( argc == 1 )
00099 argc = 1;
00100
00101
00102 fkdot0[0] = 300.0;
00103 fkdot0[1] = -1.e-7;
00104 fkdot0[2] = 1e-15;
00105 fkdot0[3] = -1e-22;
00106
00107
00108 result[0] = 2.809011145986047e+02;
00109 result[1] = -4.529256832000000e-07;
00110 result[2] = -8.460800000000001e-15;
00111 result[3] = -1.000000000000000e-22;
00112
00113
00114 printf(" \n ----- Test1: LALExtrapolatePulsarSpins() ----- \n");
00115 printf("Input @ tau0 = %d.%09d : [%.10g, %.10g, %.10g, %.10g ]\n",
00116 epoch0.gpsSeconds, epoch0.gpsNanoSeconds,
00117 fkdot0[0], fkdot0[1], fkdot0[2], fkdot0[3] );
00118
00119 SUB ( LALExtrapolatePulsarSpins (&status, fkdot1, epoch1, fkdot0, epoch0), &status );
00120
00121 printf("Output2@ tau1 = %d.%09d : [%.10g, %.10g, %.10g, %.10g]\n",
00122 epoch1.gpsSeconds, epoch1.gpsNanoSeconds,
00123 fkdot1[0], fkdot1[1], fkdot1[2], fkdot1[3] );
00124
00125 printf ("Reference-result: : [%.10g, %.10g, %.10g, %.10g]\n",
00126 result[0], result[1], result[2], result[3] );
00127
00128 if ( (RELERROR(fkdot1[0], result[0]) > tolerance) ||
00129 (RELERROR(fkdot1[1], result[1]) > tolerance) ||
00130 (RELERROR(fkdot1[2], result[2]) > tolerance) ||
00131 (RELERROR(fkdot1[3], result[3]) > tolerance) )
00132 {
00133 LALPrintError ( "\nRelative error of XLALExtrapolatePulsarSpins() exceeds tolerance of %g \n\n", tolerance);
00134 return -1;
00135 }
00136 else
00137 printf ("\n ==> OK. LALExtrapolatePulsarSpins() lies within %g of the reference-result!\n", tolerance);
00138
00139
00140 {
00141 REAL8 phi1Result = 3.951107892803490;
00142 REAL8 phi0, phi1;
00143
00144 phi0 = 1;
00145 SUB ( LALExtrapolatePulsarPhase ( &status, &phi1, fkdot1, epoch1, phi0, epoch0 ), &status );
00146
00147 printf ("\nExtrapolated phase phi1 = %.16f, Reference-result = %.16f\n", phi1, phi1Result );
00148 if ( RELERROR(phi1, phi1Result) > tolerancePhi )
00149 {
00150 LALPrintError ( "\nRelative error of LALExtrapolatePulsarPhase() exceeds tolerance of %g \n\n", tolerancePhi);
00151 return -1;
00152 }
00153 else
00154 printf ("\n ==> OK. LALExtrapolatePulsarPhase() lies within %g of the reference-result!\n", tolerancePhi);
00155 }
00156
00157
00158
00159 range0.refTime = epoch0;
00160 range0.fkdot[0] = fkdot0[0];
00161 range0.fkdot[1] = fkdot0[1];
00162 range0.fkdot[2] = fkdot0[2];
00163 range0.fkdot[3] = fkdot0[3];
00164
00165 range0.fkdotBand[0] = 0;
00166 range0.fkdotBand[1] = -1.0e-7;
00167 range0.fkdotBand[2] = 1.0e-15;
00168 range0.fkdotBand[3] = -1.0e-22;
00169
00170
00171 rangeResult.refTime.gpsSeconds = 619572733;
00172 rangeResult.refTime.gpsNanoSeconds = 0;
00173
00174 rangeResult.fkdot[0] = 3.280495590653952e+02;
00175 rangeResult.fkdot[1] = -1.284283366400000e-06;
00176 rangeResult.fkdot[2] = 1.046080000000000e-14;
00177 rangeResult.fkdot[3] = -2.000000000000000e-22;
00178
00179 rangeResult.fkdotBand[0] = 2.804955906539521e+01;
00180 rangeResult.fkdotBand[1] = 6.421416832000000e-07;
00181 rangeResult.fkdotBand[2] = 1.046080000000000e-14;
00182 rangeResult.fkdotBand[3] = 1.000000000000000e-22;
00183
00184 printf(" \n ----- Test2: LALExtrapolatePulsarSpinRange() ----- \n");
00185 printf ("Input: epoch = %d.%09d \n", range0.refTime.gpsSeconds, range0.refTime.gpsNanoSeconds );
00186 printf ("Input: fkdot = [%.10g, %.10g, %.10g, %.10g ]\n",
00187 range0.fkdot[0], range0.fkdot[1], range0.fkdot[2], range0.fkdot[3] );
00188 printf ("Input: fkdotBand = [%.10g, %.10g, %.10g, %.10g ]\n",
00189 range0.fkdotBand[0], range0.fkdotBand[1], range0.fkdotBand[2], range0.fkdotBand[3] );
00190
00191 SUB ( LALExtrapolatePulsarSpinRange (&status, &range2, epoch2, &range0 ), &status );
00192
00193 printf ("\n");
00194 printf ("Output: epoch = %d.%09d \n", range2.refTime.gpsSeconds, range2.refTime.gpsNanoSeconds );
00195 printf ("Output: fkdot = [%.10g, %.10g, %.10g, %.10g ]\n",
00196 range2.fkdot[0], range2.fkdot[1], range2.fkdot[2], range2.fkdot[3] );
00197 printf ("Output: fkdotBand = [%.10g, %.10g, %.10g, %.10g ]\n",
00198 range2.fkdotBand[0], range2.fkdotBand[1], range2.fkdotBand[2], range2.fkdotBand[3] );
00199
00200 printf ("\n");
00201 printf ("Octave : fkdot = [%.10g, %.10g, %.10g, %.10g ]\n",
00202 rangeResult.fkdot[0], rangeResult.fkdot[1], rangeResult.fkdot[2], rangeResult.fkdot[3] );
00203 printf ("Octave : fkdotBand = [%.10g, %.10g, %.10g, %.10g ]\n",
00204 rangeResult.fkdotBand[0], rangeResult.fkdotBand[1], rangeResult.fkdotBand[2], rangeResult.fkdotBand[3] );
00205
00206 if ( (range2.refTime.gpsSeconds != rangeResult.refTime.gpsSeconds)
00207 || ( range2.refTime.gpsNanoSeconds != rangeResult.refTime.gpsNanoSeconds ) )
00208 {
00209 LALPrintError ("\nOutput-range has wrong epoch\n");
00210 return -1;
00211 }
00212
00213 if ( (RELERROR(range2.fkdot[0], rangeResult.fkdot[0]) > tolerance) ||
00214 (RELERROR(range2.fkdot[1], rangeResult.fkdot[1]) > tolerance) ||
00215 (RELERROR(range2.fkdot[2], rangeResult.fkdot[2]) > tolerance) ||
00216 (RELERROR(range2.fkdot[3], rangeResult.fkdot[3]) > tolerance) ||
00217
00218 (RELERROR(range2.fkdotBand[0], rangeResult.fkdotBand[0]) > tolerance) ||
00219 (RELERROR(range2.fkdotBand[1], rangeResult.fkdotBand[1]) > tolerance) ||
00220 (RELERROR(range2.fkdotBand[2], rangeResult.fkdotBand[2]) > tolerance) ||
00221 (RELERROR(range2.fkdotBand[3], rangeResult.fkdotBand[3]) > tolerance)
00222 )
00223 {
00224 LALPrintError ( "\nRelative error of LALExtrapolatePulsarSpinRange() exceeds tolerance of %g \n", tolerance );
00225 return -1;
00226 }
00227 else
00228 printf ("\n ==> OK. LALExtrapolatePulsarSpinRange() lies within %g of the reference-result!\n\n", tolerance);
00229
00230 LALCheckMemoryLeaks();
00231
00232 return 0;
00233
00234 }