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 #include <lal/Velocity.h>
00102
00103
00104 NRCSID (VELOCITYC, "$Id: Velocity.c,v 1.11 2006/02/11 09:45:11 badri Exp $");
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 void LALAvgDetectorVel( LALStatus *status,
00116 REAL8 v[3],
00117 VelocityPar *in )
00118 {
00119
00120 REAL8 pos1[3], pos2[3];
00121 REAL8 tBase;
00122 LIGOTimeGPS t0gps, tgps;
00123 REAL8 t0;
00124 REAL8 t, ts, tn;
00125 INT4 n;
00126 LALDetector detector;
00127 EphemerisData *edat;
00128
00129
00130
00131 INITSTATUS (status, "LALAvgDetectorVel", VELOCITYC);
00132 ATTATCHSTATUSPTR (status);
00133
00134
00135 ASSERT(in, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00136
00137
00138 tBase = in->tBase;
00139 t0gps = in->startTime;
00140 detector = in->detector;
00141 edat = in->edat;
00142
00143
00144 ASSERT(tBase > 0.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00145
00146
00147 ts = (REAL8)(t0gps.gpsSeconds) * 1.00;
00148 tn = (REAL8)(t0gps.gpsNanoSeconds) * 1.00E-9;
00149 t0 = ts + tn;
00150
00151
00152 t = t0 + tBase;
00153 TRY( LALFloatToGPS( status->statusPtr, &tgps, &t), status);
00154
00155
00156 TRY( LALDetectorPos( status->statusPtr, pos1, &t0gps, detector, edat), status);
00157 TRY( LALDetectorPos( status->statusPtr, pos2, &tgps, detector, edat), status);
00158
00159
00160 for (n=0; n<3; n++)
00161 {
00162 v[n] = (pos2[n] - pos1[n])/tBase;
00163 }
00164
00165 DETATCHSTATUSPTR (status);
00166
00167 RETURN (status);
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177 void LALAvgDetectorPos( LALStatus *status,
00178 REAL8 x[3],
00179 VelocityPar *in)
00180 {
00181
00182 REAL8 trapSum[3], average[3], tempVel[3];
00183 REAL8 tBase, vTol, rTol, oldVeloMod, newVeloMod;
00184 LIGOTimeGPS t0gps, tgps;
00185 REAL8 t0;
00186 REAL8 t, ts, tn;
00187 INT4 n, k, points;
00188 LALDetector detector;
00189 EphemerisData *edat;
00190
00191
00192
00193
00194
00195 INITSTATUS (status, "LALAvgDetectorPos", VELOCITYC);
00196 ATTATCHSTATUSPTR (status);
00197
00198
00199 ASSERT(in, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00200
00201
00202 tBase = in->tBase;
00203 vTol = in->vTol;
00204 t0gps = in->startTime;
00205 detector = in->detector;
00206 edat = in->edat;
00207
00208
00209 ASSERT(tBase > 0.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00210 ASSERT(vTol > 0.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00211 ASSERT(vTol < 1.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00212
00213
00214
00215 ts = (REAL8)(t0gps.gpsSeconds) * 1.00;
00216 tn = (REAL8)(t0gps.gpsNanoSeconds) * 1.00E-9;
00217 t0 = ts + tn;
00218
00219
00220 t = t0 + tBase;
00221 TRY( LALFloatToGPS( status->statusPtr, &tgps, &t), status);
00222
00223
00224
00225
00226 TRY( LALDetectorPos( status->statusPtr, tempVel, &t0gps, detector, edat), status);
00227 for (n=0; n<3; n++) trapSum[n] = 0.5 * tempVel[n];
00228
00229
00230
00231 TRY( LALDetectorPos( status->statusPtr, tempVel, &tgps, detector, edat), status);
00232
00233
00234 for (n=0; n<3; n++)
00235 {
00236 trapSum[n] += 0.5 * tempVel[n];
00237 average[n] = trapSum[n];
00238 }
00239
00240 points = 1;
00241
00242 do {
00243 points *= 2;
00244 for (k=1; k<points; k+=2)
00245 {
00246 t = t0 + 1.0 * k * tBase / (1.0 * points);
00247 TRY( LALFloatToGPS( status->statusPtr, &tgps, &t), status);
00248 TRY( LALDetectorPos( status->statusPtr, tempVel, &tgps, detector, edat), status);
00249 for (n=0; n<3; n++) trapSum[n] += tempVel[n];
00250 }
00251 oldVeloMod = newVeloMod = 0.0;
00252 for (n=0; n<3; n++)
00253 {
00254 oldVeloMod += average[n]*average[n];
00255 average[n] = trapSum[n] / (1.0*points);
00256 newVeloMod += average[n]*average[n];
00257 }
00258
00259
00260
00261 rTol = fabs((sqrt(oldVeloMod) - sqrt(newVeloMod))) / (sqrt(oldVeloMod));
00262 } while (rTol > vTol);
00263
00264
00265 for (n=0; n<3; n++) x[n] = average[n];
00266
00267 DETATCHSTATUSPTR (status);
00268
00269 RETURN (status);
00270 }
00271
00272
00273
00274
00275
00276
00277
00278 void LALDetectorVel(LALStatus *status,
00279 REAL8 v[3],
00280 LIGOTimeGPS *time0,
00281 LALDetector detector,
00282 EphemerisData *edat)
00283 {
00284
00285 INT4 i;
00286 EmissionTime *emit=NULL;
00287 EarthState *earth=NULL;
00288 BarycenterInput baryinput;
00289
00290
00291
00292 INITSTATUS ( status, "LALDetectorVel", VELOCITYC);
00293 ATTATCHSTATUSPTR (status);
00294
00295 ASSERT (time0, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00296 ASSERT (edat, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00297
00298 emit = (EmissionTime *)LALMalloc(sizeof(EmissionTime));
00299 earth = (EarthState *)LALMalloc(sizeof(EarthState));
00300
00301
00302 baryinput.site.location[0] = detector.location[0]/LAL_C_SI;
00303 baryinput.site.location[1] = detector.location[1]/LAL_C_SI;
00304 baryinput.site.location[2] = detector.location[2]/LAL_C_SI;
00305
00306
00307 baryinput.tgps = *time0;
00308 baryinput.dInv = 0.0;
00309
00310
00311
00312
00313
00314 baryinput.alpha = 0.0;
00315 baryinput.delta = 0.0;
00316
00317
00318 TRY( LALBarycenterEarth( status->statusPtr, earth, time0, edat), status);
00319 TRY( LALBarycenter( status->statusPtr, emit, &baryinput, earth), status);
00320
00321
00322 for (i=0; i < 3; i++) { v[i] = emit->vDetector[i]; }
00323
00324 LALFree(emit);
00325 LALFree(earth);
00326
00327 DETATCHSTATUSPTR (status);
00328 RETURN (status);
00329 }
00330
00331
00332
00333
00334
00335
00336 void LALDetectorPos(LALStatus *status,
00337 REAL8 x[3],
00338 LIGOTimeGPS *time0,
00339 LALDetector detector,
00340 EphemerisData *edat)
00341 {
00342
00343 INT4 i;
00344 EmissionTime *emit=NULL;
00345 EarthState *earth=NULL;
00346 BarycenterInput baryinput;
00347
00348
00349
00350 INITSTATUS ( status, "LALDetectorPos", VELOCITYC);
00351 ATTATCHSTATUSPTR (status);
00352
00353 ASSERT (time0, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00354 ASSERT (edat, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00355
00356 emit = (EmissionTime *)LALMalloc(sizeof(EmissionTime));
00357 earth = (EarthState *)LALMalloc(sizeof(EarthState));
00358
00359
00360 baryinput.site.location[0] = detector.location[0]/LAL_C_SI;
00361 baryinput.site.location[1] = detector.location[1]/LAL_C_SI;
00362 baryinput.site.location[2] = detector.location[2]/LAL_C_SI;
00363
00364
00365 baryinput.tgps = *time0;
00366 baryinput.dInv = 0;
00367
00368
00369
00370
00371
00372 baryinput.alpha = 0.0;
00373 baryinput.delta = 0.0;
00374
00375
00376 TRY( LALBarycenterEarth( status->statusPtr, earth, time0, edat), status);
00377 TRY( LALBarycenter( status->statusPtr, emit, &baryinput, earth), status);
00378
00379
00380 for (i=0; i < 3; i++) { x[i] = emit->rDetector[i]; }
00381
00382 LALFree(emit);
00383 LALFree(earth);
00384
00385 DETATCHSTATUSPTR (status);
00386 RETURN (status);
00387 }
00388
00389
00390
00391
00392
00393
00394
00395
00396