VBMicrolensing 5.1.1__cp312-cp312-musllinux_1_2_i686.whl → 5.3.1__cp312-cp312-musllinux_1_2_i686.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of VBMicrolensing might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
- // VBMicrolensing v5.1.1 (2025)
1
+ // VBMicrolensing v5.3 (2025)
2
2
  //
3
3
  // This code has been developed by Valerio Bozza (University of Salerno) and collaborators.
4
4
  // Check the repository at https://github.com/valboz/VBMicrolensing
@@ -252,7 +252,8 @@ public:
252
252
 
253
253
  #pragma endregion
254
254
 
255
- char VBMicrolensing::ESPLtablefile[1024] = "fatto";
255
+ char VBMicrolensing::ESPLtablefile[1024] = "placeholder";
256
+ char VBMicrolensing::Suntablefile[1024] = "placeholder";
256
257
 
257
258
  #pragma region Constructor/destructor
258
259
 
@@ -277,13 +278,16 @@ VBMicrolensing::VBMicrolensing() {
277
278
  t0old = 0.;
278
279
  Tol = 1.e-2;
279
280
  RelTol = 0;
281
+ suntable = false;
282
+ parallaxephemeris = true;
280
283
  tsat = 0;
281
284
  possat = 0;
282
285
  nsat = 0;
283
286
  ndatasat = 0;
284
287
  satellite = 0;
285
288
  parallaxsystem = 1;
286
- t0_par_fixed = -1;
289
+ t0_par_fixed = 0;
290
+ coordinates_set = false;
287
291
  t0_par = 7000;
288
292
  minannuli = 1;
289
293
  maxannuli = 100;
@@ -328,6 +332,8 @@ VBMicrolensing::VBMicrolensing() {
328
332
  CumulativeFunction = &VBDefaultCumulativeFunction;
329
333
  SelectedMethod = Method::Nopoly;
330
334
  turn_off_secondary_source = turn_off_secondary_lens = false;
335
+ t_in_HJD = true;
336
+ parallaxextrapolation = 0;
331
337
  // testnewcoefs = true;
332
338
  }
333
339
 
@@ -342,6 +348,10 @@ VBMicrolensing::~VBMicrolensing() {
342
348
  free(possat);
343
349
  free(ndatasat);
344
350
  }
351
+ if (suntable) {
352
+ for (int j = 0; j < ndataEar; j++) free(posEar[j]);
353
+ free(posEar);
354
+ }
345
355
 
346
356
  if (m) {
347
357
  free(m);
@@ -460,7 +470,7 @@ VBMicrolensing::~VBMicrolensing() {
460
470
  #pragma region single-source-mag
461
471
 
462
472
 
463
- void VBMicrolensing::LoadESPLTable(char* filename) {
473
+ void VBMicrolensing::LoadESPLTable(const char* filename) {
464
474
  FILE* f;
465
475
 
466
476
  if ((f = fopen(filename, "rb")) != 0) {
@@ -4845,8 +4855,8 @@ void VBMicrolensing::ComputeCentroids(double* pr, double t, double* c1s, double*
4845
4855
  c1 = c1prov; // Now centroid coordinates are in North-East system, but still relative to lens
4846
4856
 
4847
4857
  // Lens centroid in the sky
4848
- c1l[0] = muL1 * (t - t0_par) + paiL * (Ehel[0] - Et0[0]); // Note that Ehel is in South-West system
4849
- c2l[0] = muL2 * (t - t0_par) + paiL * (Ehel[1] - Et0[1]);
4858
+ c1l[0] = muL1 * (t +lighttravel - t0_par - lighttravel0) + paiL * (Ehel[0] - Et0[0]); // Note that Ehel is in South-West system
4859
+ c2l[0] = muL2 * (t +lighttravel - t0_par - lighttravel0) + paiL * (Ehel[1] - Et0[1]);
4850
4860
  // Image centroid is finally composed with lens centroid
4851
4861
  c1s[0] = c1 + c1l[0];
4852
4862
  c2s[0] = c2 + c2l[0];
@@ -4872,10 +4882,11 @@ void VBMicrolensing::PSPLAstroLightCurve(double* pr, double* ts, double* mags, d
4872
4882
  iastro = 5;
4873
4883
  dPosAng = 0;
4874
4884
  t0old = 1.e200;
4885
+ parallaxextrapolation = 0;
4875
4886
 
4876
4887
  for (int i = 0; i < np; i++) {
4877
4888
  ComputeParallax(ts[i], t0);
4878
- tn = (ts[i] - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
4889
+ tn = (ts[i] + lighttravel - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
4879
4890
  u1 = u0 + pai1 * Et[1] - pai2 * Et[0];
4880
4891
  u = sqrt(tn * tn + u1 * u1);
4881
4892
 
@@ -4903,10 +4914,11 @@ void VBMicrolensing::ESPLAstroLightCurve(double* pr, double* ts, double* mags, d
4903
4914
  iastro = 6;
4904
4915
  dPosAng = 0;
4905
4916
  t0old = 1.e200;
4917
+ parallaxextrapolation = 0;
4906
4918
 
4907
4919
  for (int i = 0; i < np; i++) {
4908
4920
  ComputeParallax(ts[i], t0);
4909
- tn = (ts[i] - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
4921
+ tn = (ts[i] +lighttravel - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
4910
4922
  u1 = u0 + pai1 * Et[1] - pai2 * Et[0];
4911
4923
  u = sqrt(tn * tn + u1 * u1);
4912
4924
 
@@ -4934,10 +4946,11 @@ void VBMicrolensing::BinaryAstroLightCurve(double* pr, double* ts, double* mags,
4934
4946
  double salpha = sin(pr[3]), calpha = cos(pr[3]);
4935
4947
  dPosAng = 0;
4936
4948
  t0old = 1.e200;
4949
+ parallaxextrapolation = 0;
4937
4950
 
4938
4951
  for (int i = 0; i < np; i++) {
4939
4952
  ComputeParallax(ts[i], t0);
4940
- tn = (ts[i] - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
4953
+ tn = (ts[i] + lighttravel - t0_par) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
4941
4954
  u = u0 + pai1 * Et[1] - pai2 * Et[0];
4942
4955
 
4943
4956
  y1s[i] = u * salpha - tn * calpha;
@@ -4969,6 +4982,7 @@ void VBMicrolensing::BinaryAstroLightCurveOrbital(double* pr, double* ts, double
4969
4982
  double w, phi0, inc, phi, Cinc, Sinc, Cphi, Sphi, Cphi0, Sphi0, pphi0, COm, SOm, s_true;
4970
4983
  double w13, w123, den, den0;
4971
4984
  t0old = 1.e200;
4985
+ parallaxextrapolation = 0;
4972
4986
 
4973
4987
  w13 = w1 * w1 + w3 * w3;
4974
4988
  w123 = sqrt(w13 + w2 * w2);
@@ -4997,14 +5011,14 @@ void VBMicrolensing::BinaryAstroLightCurveOrbital(double* pr, double* ts, double
4997
5011
  for (int i = 0; i < np; i++) {
4998
5012
  ComputeParallax(ts[i], t0);
4999
5013
 
5000
- phi = (ts[i] - t0_par) * w + phi0;
5014
+ phi = (ts[i] + lighttravel - t0_par - lighttravel0) * w + phi0;
5001
5015
  Cphi = cos(phi);
5002
5016
  Sphi = sin(phi);
5003
5017
  den = sqrt(Cphi * Cphi + Cinc * Cinc * Sphi * Sphi);
5004
5018
  seps[i] = s_true * den; // projected separation at time ts[i]
5005
5019
 
5006
5020
  u = u0 + pai1 * Et[1] - pai2 * Et[0];
5007
- tn = (ts[i] - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5021
+ tn = (ts[i] + lighttravel - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5008
5022
  y1s[i] = (Cphi * (u * SOm - tn * COm) + Cinc * Sphi * (u * COm + tn * SOm)) / den;
5009
5023
  y2s[i] = (-Cphi * (u * COm + tn * SOm) - Cinc * Sphi * (tn * COm - u * SOm)) / den;
5010
5024
  mags[i] = BinaryMag2(seps[i], q, y1s[i], y2s[i], rho);
@@ -5037,6 +5051,7 @@ void VBMicrolensing::BinaryAstroLightCurveKepler(double* pr, double* ts, double*
5037
5051
  double arm1, arm2;
5038
5052
  double X[3], Y[3], Z[3], r[2], x[2];
5039
5053
  t0old = 1.e200;
5054
+ parallaxextrapolation = 0;
5040
5055
 
5041
5056
  smix = 1 + szs * szs;
5042
5057
  sqsmix = sqrt(smix);
@@ -5081,7 +5096,7 @@ void VBMicrolensing::BinaryAstroLightCurveKepler(double* pr, double* ts, double*
5081
5096
 
5082
5097
  for (int i = 0; i < np; i++) {
5083
5098
  ComputeParallax(ts[i], t0);
5084
- M = n * (ts[i] - tperi);
5099
+ M = n * (ts[i] + lighttravel - tperi - lighttravel0);
5085
5100
  while (M > M_PI) M -= 2 * M_PI;
5086
5101
  while (M < -M_PI) M += 2 * M_PI;
5087
5102
  EE = M + e * sin(M);
@@ -5102,7 +5117,7 @@ void VBMicrolensing::BinaryAstroLightCurveKepler(double* pr, double* ts, double*
5102
5117
  St = sqrt(x[0] * x[0] + x[1] * x[1]);
5103
5118
  psi = atan2(x[1], x[0]);// +((ar > 1) ? 0 : M_PI);
5104
5119
  u = u0 + pai1 * Et[1] - pai2 * Et[0];
5105
- tn = (ts[i] - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5120
+ tn = (ts[i] + lighttravel - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5106
5121
  y1s[i] = -tn * cos(alpha + psi) + u * sin(alpha + psi);
5107
5122
  y2s[i] = -u * cos(alpha + psi) - tn * sin(alpha + psi);
5108
5123
  seps[i] = St;
@@ -5137,6 +5152,7 @@ void VBMicrolensing::BinSourceAstroLightCurveXallarap(double* pr, double* ts, do
5137
5152
  iastro = 12;
5138
5153
  dPosAng = 0;
5139
5154
  t0old = 1.e200;
5155
+ parallaxextrapolation = 0;
5140
5156
 
5141
5157
  s[2] = -(s[0] * w[0] + s[1] * w[1]) / w[2]; // Impose velocity orthogonal to position
5142
5158
  s3D = sqrt(s[0] * s[0] + s[1] * s[1] + s[2] * s[2]);
@@ -5200,11 +5216,11 @@ void VBMicrolensing::BinSourceAstroLightCurveXallarap(double* pr, double* ts, do
5200
5216
  paiuB = pai1 * Et[1] - pai2 * Et[0]; // Parallax correction referred to tB
5201
5217
 
5202
5218
  // Position of barycenter
5203
- tnB = (ts[i] - t0) * vt0B - t0B + paitB * cos(alpha) - paiuB * sin(alpha);
5204
- uB = u0B + vuB * (ts[i] - t0) + paitB * sin(alpha) + paiuB * cos(alpha);
5219
+ tnB = (ts[i] + lighttravel - t0) * vt0B - t0B + paitB * cos(alpha) - paiuB * sin(alpha);
5220
+ uB = u0B + vuB * (ts[i]+ lighttravel - t0) + paitB * sin(alpha) + paiuB * cos(alpha);
5205
5221
 
5206
5222
  // Position of relative particle
5207
- phi = wtot * (ts[i] - t0) + phi0;
5223
+ phi = wtot * (ts[i] + lighttravel - t0) + phi0;
5208
5224
  xt = (Om[0] * cos(phi) + Y[0] * sin(phi));
5209
5225
  xu = (Om[1] * cos(phi) + Y[1] * sin(phi));
5210
5226
 
@@ -5247,6 +5263,183 @@ void VBMicrolensing::BinSourceAstroLightCurveXallarap(double* pr, double* ts, do
5247
5263
  }
5248
5264
 
5249
5265
  }
5266
+
5267
+
5268
+ void VBMicrolensing::BinSourceBinLensAstroLightCurve(double* pr, double* ts, double* mags, double* c1s, double* c2s, double* c1l, double* c2l, double* y1s, double* y2s, double* y1s2, double* y2s2, double *seps, int np) {
5269
+ double tn, u, FRl, s = exp(pr[0]), q = exp(pr[1]), w1 = pr[9], w2 = pr[10], w3 = pr[11];
5270
+ tE_inv = exp(-pr[5]);
5271
+
5272
+ double ws[3] = { pr[15] + 1.01e-15, pr[16] + 1.01e-15, pr[17] + 1.01e-15 };
5273
+ double t01 = pr[6], t02 = pr[13] + ws[0] * (pr[13] - pr[6]) / tE_inv, u1 = pr[2], u2 = pr[12] + ws[1] * (pr[6] - pr[13]), FR = exp(pr[14]), rho2, xt, xu;
5274
+ double ss[3] = { (t01 - t02) * tE_inv,u2 - u1,0 };
5275
+ double L[3], Om[3], Y[3], norm, normOm, s3D, wstot, qs,phis0;
5276
+ double u0B, t0B, vuB, vt0B, s1, s2, uB, tnB, paitB, paiuB, alphas;
5277
+ parallaxextrapolation = 0;
5278
+
5279
+ // Binary lens calculations
5280
+ u0 = pr[2];
5281
+ t0 = pr[6];
5282
+ rho = exp(pr[4]);
5283
+ pai1 = pr[7];
5284
+ pai2 = pr[8];
5285
+ alpha = pr[3];
5286
+ iastro = 18;
5287
+ double salpha = sin(pr[3]), calpha = cos(pr[3]);
5288
+ double w, phi0, inc, phi, Cinc, Sinc, Cphi, Sphi, Cphi0, Sphi0, pphi0, COm, SOm, s_true;
5289
+ double w13, w123, den, den0;
5290
+ t0old = 1.e200;
5291
+
5292
+ w13 = w1 * w1 + w3 * w3;
5293
+ w123 = sqrt(w13 + w2 * w2);
5294
+ w13 = sqrt(w13);
5295
+ if (w13 > 1.e-8) {
5296
+ w3 = (w3 > 1.e-8) ? w3 : 1.e-8;
5297
+ w = w3 * w123 / w13;
5298
+ inc = acos(w2 * w3 / w13 / w123);
5299
+ phi0 = atan2(-w1 * w123, w3 * w13);
5300
+ }
5301
+ else {
5302
+ w = w2;
5303
+ inc = 0.;
5304
+ phi0 = 0.;
5305
+ }
5306
+ Cphi0 = cos(phi0);
5307
+ Sphi0 = sin(phi0);
5308
+ Cinc = cos(inc);
5309
+ Sinc = sin(inc);
5310
+ den0 = sqrt(Cphi0 * Cphi0 + Cinc * Cinc * Sphi0 * Sphi0);
5311
+ s_true = s / den0; // orbital radius
5312
+ COm = (Cphi0 * calpha + Cinc * salpha * Sphi0) / den0;
5313
+ SOm = (Cphi0 * salpha - Cinc * calpha * Sphi0) / den0;
5314
+ pphi0 = atan2(Cinc * Sphi0, Cphi0);
5315
+
5316
+ // Binary source calculations
5317
+
5318
+ ss[2] = -(ss[0] * ws[0] + ss[1] * ws[1]) / ws[2]; // Impose velocity orthogonal to position
5319
+ s3D = sqrt(ss[0] * ss[0] + ss[1] * ss[1] + ss[2] * ss[2]);
5320
+ wstot = sqrt(ws[0] * ws[0] + ws[1] * ws[1] + ws[2] * ws[2]) / s3D; // Angular velocity
5321
+
5322
+ // Angular momentum
5323
+ L[0] = ss[1] * ws[2] - ss[2] * ws[1];
5324
+ L[1] = ss[2] * ws[0] - ss[0] * ws[2];
5325
+ L[2] = ss[0] * ws[1] - ss[1] * ws[0];
5326
+ normOm = L[0] * L[0] + L[1] * L[1];
5327
+ norm = sqrt(normOm + L[2] * L[2]);
5328
+ normOm = sqrt(normOm);
5329
+ // Node line
5330
+ if (normOm > 0) {
5331
+ Om[0] = -L[1] / normOm;
5332
+ Om[1] = L[0] / normOm;
5333
+ Om[2] = 0;
5334
+ for (int i = 0; i < 3; i++) L[i] /= norm;
5335
+ }
5336
+ else {
5337
+ Om[0] = 1;
5338
+ Om[1] = 0 / normOm;
5339
+ Om[2] = 0;
5340
+ L[0] = 0;
5341
+ L[1] = -1;
5342
+ L[2] = 0;
5343
+ }
5344
+
5345
+
5346
+ // Orthogonal axis
5347
+ Y[0] = -L[2] * Om[1];
5348
+ Y[1] = L[2] * Om[0];
5349
+ Y[2] = L[0] * Om[1] - L[1] * Om[0];
5350
+
5351
+ // Phase at time t0
5352
+ norm = (ss[0] * Om[0] + ss[1] * Om[1]) / s3D;
5353
+ if (norm >= 1) norm = 0.99999999999999;
5354
+ if (norm <= -1) norm = -0.99999999999999;
5355
+ phis0 = acos(norm);
5356
+ if (ss[2] < 0) phis0 = -phis0;
5357
+
5358
+ // Mass ratio
5359
+ qs = exp(pr[14] / mass_luminosity_exponent);
5360
+ // Position of barycenter at t0
5361
+ t0B = (t01 + t02 * qs) / (1 + qs);
5362
+ u0B = (u1 + u2 * qs) / (1 + qs);
5363
+ t0B = (t0B - t0) * tE_inv;
5364
+ // Velocity of barycenter
5365
+ vt0B = ws[0] * qs / (1 + qs) + tE_inv;
5366
+ vuB = ws[1] * qs / (1 + qs);
5367
+ alphas = atan2(vuB, vt0B);
5368
+ alpha += alphas;
5369
+ tE_inv = sqrt(vuB * vuB + vt0B * vt0B);
5370
+ // Relative distances from barycenter
5371
+ s2 = s3D / (1 + qs);
5372
+ s1 = s2 * qs;
5373
+
5374
+
5375
+ for (int i = 0; i < np; i++) {
5376
+ ComputeParallax(ts[i], t0);
5377
+
5378
+ // Binary lens calculation
5379
+ phi = (ts[i] + lighttravel - t0) * w + phi0;
5380
+ Cphi = cos(phi);
5381
+ Sphi = sin(phi);
5382
+ den = sqrt(Cphi * Cphi + Cinc * Cinc * Sphi * Sphi);
5383
+ seps[i] = s_true * den; // projected separation at time ts[i]
5384
+
5385
+ // Binary source calculations
5386
+ paitB = pai1 * Et[0] + pai2 * Et[1]; // Parallax correction referred to tB
5387
+ paiuB = pai1 * Et[1] - pai2 * Et[0]; // Parallax correction referred to tB
5388
+
5389
+ // Position of barycenter
5390
+ tnB = (ts[i] + lighttravel - t0) * vt0B - t0B + paitB * cos(alphas) - paiuB * sin(alphas);
5391
+ uB = u0B + vuB * (ts[i] + lighttravel - t0) + paitB * sin(alphas) + paiuB * cos(alphas);
5392
+
5393
+ // Position of relative particle
5394
+ phi = wstot * (ts[i]+lighttravel - t0) + phis0;
5395
+ xt = (Om[0] * cos(phi) + Y[0] * sin(phi));
5396
+ xu = (Om[1] * cos(phi) + Y[1] * sin(phi));
5397
+
5398
+ // Position of source 1
5399
+ tn = tnB - xt * s1;
5400
+ u = uB - xu * s1;
5401
+ //y1s[i] = -tn;
5402
+ //y2s[i] = -u;
5403
+ y1s[i] = (Cphi * (u * SOm - tn * COm) + Cinc * Sphi * (u * COm + tn * SOm)) / den;
5404
+ y2s[i] = (-Cphi * (u * COm + tn * SOm) - Cinc * Sphi * (tn * COm - u * SOm)) / den;
5405
+
5406
+ mags[i] = BinaryMag2(seps[i], q, y1s[i], y2s[i], rho);
5407
+ if (astrometry) {
5408
+ c1s[i] = astrox1;
5409
+ c2s[i] = astrox2;
5410
+ }
5411
+
5412
+ // Position of source 2
5413
+ tn = tnB + xt * s2;
5414
+ u = uB + xu * s2;
5415
+ //y1s2[i] = -tn;
5416
+ //y2s2[i] = -u;
5417
+ y1s2[i] = (Cphi * (u * SOm - tn * COm) + Cinc * Sphi * (u * COm + tn * SOm)) / den;
5418
+ y2s2[i] = (-Cphi * (u * COm + tn * SOm) - Cinc * Sphi * (tn * COm - u * SOm)) / den;
5419
+
5420
+ if (!turn_off_secondary_source) {
5421
+ rho2 = rho * exp(pr[1] * mass_radius_exponent / mass_luminosity_exponent);
5422
+ // Combine magnifications
5423
+ mags[i] += FR * BinaryMag2(seps[i], q, y1s2[i], y2s2[i], rho2);
5424
+ mags[i] /= (1 + FR);
5425
+ }
5426
+ if (astrometry) {
5427
+ if (!turn_off_secondary_source) {
5428
+ c1s[i] += FR * astrox1;
5429
+ c2s[i] += FR * astrox2;
5430
+ c1s[i] /= (1 + FR);
5431
+ c2s[i] /= (1 + FR);
5432
+ }
5433
+ dPosAng = -atan2(Cinc * Sphi, Cphi) + pphi0;
5434
+ ComputeCentroids(pr, ts[i], &c1s[i], &c2s[i], &c1l[i], &c2l[i]);
5435
+ FRl = (turn_off_secondary_lens) ? 0 : pow(q, lens_mass_luminosity_exponent); // Flux ratio between the two lenses
5436
+ c1l[i] += (-q + FRl) * s * thetaE / (1 + q) * cos(PosAng) / (1 + FRl); // Flux center of the two lenses from barycenter
5437
+ c2l[i] += (-q + FRl) * s * thetaE / (1 + q) * sin(PosAng) / (1 + FRl);
5438
+ }
5439
+ }
5440
+ }
5441
+
5442
+
5250
5443
  void VBMicrolensing::TripleAstroLightCurve(double* pr, double* ts, double* mags, double* c1s, double* c2s, double* c1l, double* c2l, double* y1s, double* y2s, int np) {
5251
5444
  double rho = exp(pr[4]), tn, tE_inv = exp(-pr[5]), di, mindi, u, u0 = pr[2], t0 = pr[6], pai1 = pr[10], pai2 = pr[11];
5252
5445
  double q[3] = { 1, exp(pr[1]),exp(pr[8]) };
@@ -5257,6 +5450,7 @@ void VBMicrolensing::TripleAstroLightCurve(double* pr, double* ts, double* mags,
5257
5450
  double Et[2];
5258
5451
  iastro = 12;
5259
5452
  dPosAng = 0;
5453
+ parallaxextrapolation = 0;
5260
5454
 
5261
5455
  s[0] = exp(pr[0]) / (q[0] + q[1]);
5262
5456
  s[1] = s[0] * q[0];
@@ -5274,7 +5468,7 @@ void VBMicrolensing::TripleAstroLightCurve(double* pr, double* ts, double* mags,
5274
5468
 
5275
5469
  for (int i = 0; i < np; i++) {
5276
5470
  ComputeParallax(ts[i], t0);
5277
- tn = (ts[i] - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5471
+ tn = (ts[i] +lighttravel - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5278
5472
  u = u0 + pai1 * Et[1] - pai2 * Et[0];
5279
5473
  y1s[i] = u * salpha - tn * calpha;
5280
5474
  y2s[i] = -u * calpha - tn * salpha;
@@ -5436,11 +5630,12 @@ void VBMicrolensing::BinSourceLightCurve(double* pr, double* ts, double* mags, d
5436
5630
  void VBMicrolensing::BinSourceLightCurveParallax(double* pr, double* ts, double* mags, double* y1s, double* y2s, int np) {
5437
5631
  double u1 = pr[2], u2 = pr[3], t01 = pr[4], t02 = pr[5], tE_inv = exp(-pr[0]), FR = exp(pr[1]), tn, u, u0, pai1 = pr[6], pai2 = pr[7], w1 = pr[8], w2 = pr[9], w3 = pr[10];
5438
5632
  t0old = 0;
5633
+ parallaxextrapolation = 0;
5439
5634
 
5440
5635
  for (int i = 0; i < np; i++) {
5441
5636
  ComputeParallax(ts[i], t0);
5442
5637
 
5443
- tn = (ts[i] - t01) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5638
+ tn = (ts[i] + lighttravel - t01) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5444
5639
  u0 = u1 + pai1 * Et[1] - pai2 * Et[0];
5445
5640
  u = tn * tn + u0 * u0;
5446
5641
 
@@ -5448,7 +5643,7 @@ void VBMicrolensing::BinSourceLightCurveParallax(double* pr, double* ts, double*
5448
5643
  y2s[i] = -u0;
5449
5644
  mags[i] = (u + 2) / sqrt(u * (u + 4));
5450
5645
 
5451
- tn = (ts[i] - t02) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5646
+ tn = (ts[i] + lighttravel - t02) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5452
5647
  u0 = u2 + pai1 * Et[1] - pai2 * Et[0];
5453
5648
  u = tn * tn + u0 * u0;
5454
5649
 
@@ -5466,6 +5661,7 @@ void VBMicrolensing::BinSourceLightCurveXallarap(double* pr, double* ts, double*
5466
5661
  double s, s_true, w, phi0, inc, phi, Cinc, Sinc, Cphi, Sphi, Cphi0, Sphi0, COm, SOm;
5467
5662
  double w13, w123, den, den0, du0, dt0;
5468
5663
  t0old = 0;
5664
+ parallaxextrapolation = 0;
5469
5665
 
5470
5666
 
5471
5667
  s = sqrt((u1 - u2) * (u1 - u2) + (t01 - t02) * (t01 - t02) * (tE_inv * tE_inv));
@@ -5502,7 +5698,7 @@ void VBMicrolensing::BinSourceLightCurveXallarap(double* pr, double* ts, double*
5502
5698
  for (int i = 0; i < np; i++) {
5503
5699
  ComputeParallax(ts[i], t0);
5504
5700
 
5505
- phi = (ts[i] - t0_par) * w + phi0;
5701
+ phi = (ts[i] + lighttravel - t0_par-lighttravel0) * w + phi0;
5506
5702
  Cphi = cos(phi);
5507
5703
  Sphi = sin(phi);
5508
5704
  den = sqrt(Cphi * Cphi + Cinc * Cinc * Sphi * Sphi);
@@ -5511,7 +5707,7 @@ void VBMicrolensing::BinSourceLightCurveXallarap(double* pr, double* ts, double*
5511
5707
  dt0 = s_true * (COm * Cphi - Cinc * SOm * Sphi) / (1 + q) * q; //Position of the primary component with respect to center of mass
5512
5708
  du0 = s_true * (SOm * Cphi + Cinc * COm * Sphi) / (1 + q) * q;
5513
5709
 
5514
- tn = -((ts[i] - t0_par) * tE_inv + dt0 + pai1 * Et[0] + pai2 * Et[1]);
5710
+ tn = -((ts[i] + lighttravel - t0_par- lighttravel0) * tE_inv + dt0 + pai1 * Et[0] + pai2 * Et[1]);
5515
5711
  u = -(u0 + du0 + pai1 * Et[1] - pai2 * Et[0]);
5516
5712
  y1s[i] = tn;
5517
5713
  y2s[i] = u;
@@ -5519,7 +5715,7 @@ void VBMicrolensing::BinSourceLightCurveXallarap(double* pr, double* ts, double*
5519
5715
 
5520
5716
  mags[i] = (u + 2) / sqrt(u * (u + 4));
5521
5717
 
5522
- tn = -((ts[i] - t0_par) * tE_inv - dt0 / q + pai1 * Et[0] + pai2 * Et[1]); // Position of the secondary component
5718
+ tn = -((ts[i] + lighttravel - t0_par- lighttravel0) * tE_inv - dt0 / q + pai1 * Et[0] + pai2 * Et[1]); // Position of the secondary component
5523
5719
  u = -(u0 - du0 / q + pai1 * Et[1] - pai2 * Et[0]);
5524
5720
  u = tn * tn + u * u;
5525
5721
 
@@ -5652,6 +5848,11 @@ void VBMicrolensing::BinSourceSingleLensXallarap(double* pr, double* ts, double*
5652
5848
  }
5653
5849
 
5654
5850
 
5851
+ void VBMicrolensing::BinSourceBinLensLightCurve(double* pr, double* ts, double* mags, double* y1s, double* y2s, double* y1s2, double* y2s2, double *seps, int np) {
5852
+ astrometry = false;
5853
+ BinSourceBinLensAstroLightCurve(pr, ts, mags, NULL, NULL, NULL, NULL, y1s, y2s, y1s2, y2s2, seps, np);
5854
+ }
5855
+
5655
5856
 
5656
5857
 
5657
5858
  void VBMicrolensing::TripleLightCurve(double* pr, double* ts, double* mags, double* y1s, double* y2s, int np) {
@@ -5842,91 +6043,14 @@ double VBMicrolensing::BinSourceSingleLensXallarap(double* pr, double t) {
5842
6043
  return mag;
5843
6044
  }
5844
6045
 
5845
-
5846
- double VBMicrolensing::BinSourceBinLensPOX(double* pr, double t) {
5847
- double s = exp(pr[0]), q = exp(pr[1]), u0 = pr[2], rho = exp(pr[4]), tE_inv = exp(-pr[5]), t0 = pr[6];
5848
- double pai1 = pr[7], pai2 = pr[8], w1 = pr[9], w2 = pr[10], w3 = pr[11];
5849
- double salpha = sin(pr[3]), calpha = cos(pr[3]);
5850
- double tn, w, phi0, phil, incl, Cinc, Sinc, Cphi, Sphi, Cphi0, Sphi0, COm, SOm, s_true;
5851
- double w13, w123, den, den0, u;
5852
-
5853
- double xi1 = pr[12], xi2 = pr[13], omega = pr[14], inc = pr[15], phi = pr[16], qs = exp(pr[17]);
5854
- double Xal[2], phit, disp[2], Xal2[2], disp2[2];
5855
- double Mag, Mag2, u01, u02, rho2, tn1, tn2, mags, qs4;
5856
-
5857
- w13 = w1 * w1 + w3 * w3;
5858
- w123 = sqrt(w13 + w2 * w2);
5859
- w13 = sqrt(w13);
5860
- if (w13 > 1.e-8) {
5861
- w3 = (w3 > 1.e-8) ? w3 : 1.e-8;
5862
- w = w3 * w123 / w13;
5863
- incl = acos(w2 * w3 / w13 / w123);
5864
- phi0 = atan2(-w1 * w123, w3 * w13);
5865
- }
5866
- else {
5867
- w = w2;
5868
- incl = 0.;
5869
- phi0 = 0.;
5870
- }
5871
-
5872
- Cphi0 = cos(phi0);
5873
- Sphi0 = sin(phi0);
5874
- Cinc = cos(incl);
5875
- Sinc = sin(incl);
5876
- den0 = sqrt(Cphi0 * Cphi0 + Cinc * Cinc * Sphi0 * Sphi0);
5877
- s_true = s / den0;
5878
- COm = (Cphi0 * calpha + Cinc * salpha * Sphi0) / den0;
5879
- SOm = (Cphi0 * salpha - Cinc * calpha * Sphi0) / den0;
5880
-
5881
- ComputeParallax(t, t0);
5882
-
5883
- phil = (t - t0_par) * w + phi0;
5884
- Cphi = cos(phil);
5885
- Sphi = sin(phil);
5886
- den = sqrt(Cphi * Cphi + Cinc * Cinc * Sphi * Sphi);
5887
- av = s_true * den;
5888
- u = u0 + pai1 * Et[1] - pai2 * Et[0];
5889
- tn = (t - t0) * tE_inv + pai1 * Et[0] + pai2 * Et[1];
5890
-
5891
- phit = omega * (t - t0_par);
5892
-
5893
- disp[0] = sin(inc) * (-cos(phi) + cos(phi + phit) + phit * sin(phi));
5894
- disp[1] = -phit * cos(phi) - sin(phi) + sin(phi + phit);
5895
- disp2[0] = -sin(inc) * (cos(phi) + cos(phi + phit) / qs - phit * sin(phi));
5896
- disp2[1] = phit * cos(phi) + sin(phi) + sin(phi + phit) / qs;
5897
-
5898
- Xal[0] = xi1 * disp[0] + xi2 * disp[1];
5899
- Xal[1] = xi2 * disp[0] - xi1 * disp[1];
5900
- Xal2[0] = xi1 * disp2[0] - xi2 * disp2[1];
5901
- Xal2[1] = xi2 * disp2[0] + xi1 * disp2[1];
5902
-
5903
- tn1 = tn + Xal[0];
5904
- u01 = u + Xal[1];
5905
- tn2 = tn + Xal2[0];
5906
- u02 = u + Xal2[1];
5907
- rho2 = rho * pow(qs, mass_radius_exponent);
5908
- qs4 = pow(qs, mass_luminosity_exponent);
5909
-
5910
-
5911
- /* y1s = u01 * salpha - tn1 * calpha;
5912
- y2s = -u01 * calpha - tn1 * salpha;
5913
- y1s2 = u02 * salpha - tn2 * calpha;
5914
- y2s2 = -u02 * calpha - tn2 * salpha;*/
5915
-
5916
- y_1 = (Cphi * (u02 * SOm - tn2 * COm) + Cinc * Sphi * (u02 * COm + tn2 * SOm)) / den;
5917
- y_2 = (-Cphi * (u02 * COm + tn2 * SOm) - Cinc * Sphi * (tn2 * COm - u02 * SOm)) / den;
5918
- Mag2 = BinaryMag2(av, q, y_1, y_2, rho2);
5919
-
5920
- y_1 = (Cphi * (u01 * SOm - tn1 * COm) + Cinc * Sphi * (u01 * COm + tn1 * SOm)) / den;
5921
- y_2 = (-Cphi * (u01 * COm + tn1 * SOm) - Cinc * Sphi * (tn1 * COm - u01 * SOm)) / den;
5922
- Mag = BinaryMag2(av, q, y_1, y_2, rho);
5923
-
5924
- mags = (Mag + qs4 * Mag2) / (1 + qs4);
5925
-
5926
- return mags;
6046
+ double VBMicrolensing::BinSourceBinLensLightCurve(double* pr, double t) {
6047
+ double mag, y1, y2, y21, y22, sep;
6048
+ BinSourceBinLensLightCurve(pr, &t, &mag, &y1, &y2, &y21, &y22, &sep, 1);
6049
+ return mag;
5927
6050
  }
5928
6051
 
5929
6052
 
6053
+
5930
6054
  double VBMicrolensing::TripleLightCurve(double* pr, double t) {
5931
6055
  double mag, y1, y2;
5932
6056
  TripleLightCurve(pr, &t, &mag, &y1, &y2, 1);
@@ -6154,6 +6278,113 @@ void VBMicrolensing::SetLDprofile(LDprofiles LDval) {
6154
6278
  //////////////////////////////
6155
6279
  //////////////////////////////
6156
6280
 
6281
+ void VBMicrolensing::LoadSunTable(char* filename) {
6282
+ FILE* f;
6283
+ double RA, Dec, dis, phiprec;
6284
+
6285
+ if ((f = fopen(filename, "r")) != 0) {
6286
+ if (suntable) {
6287
+ // Removing existing table if any
6288
+ for (int j = 0; j < ndataEar; j++) free(posEar[j]);
6289
+ free(posEar);
6290
+ suntable = false;
6291
+ }
6292
+ // Reading Sun table files
6293
+ int flag2 = 0;
6294
+ // long startpos = 0;
6295
+ char teststring[1000];
6296
+ ndataEar = 1;
6297
+
6298
+ // Finding start of data
6299
+ while (!feof(f)) {
6300
+ fscanf(f, "%s", teststring);
6301
+ if (!feof(f)) {
6302
+ fgetc(f); //fseek(f, 1, SEEK_CUR);
6303
+ teststring[5] = 0;
6304
+ if (strcmp(teststring, "$$SOE") == 0) {
6305
+ flag2 = 1;
6306
+ break;
6307
+ }
6308
+ }
6309
+ }
6310
+ // Finding end of data
6311
+ if (flag2) {
6312
+ flag2 = 0;
6313
+ // startpos = ftell(f);
6314
+ while (!feof(f)) {
6315
+ fscanf(f, "%[^\n]s", teststring);
6316
+ if (!feof(f)) {
6317
+ //fseek(f, 1, SEEK_CUR);
6318
+ fgetc(f);
6319
+ teststring[5] = 0;
6320
+ if (strcmp(teststring, "$$EOE") == 0) {
6321
+ flag2 = 1;
6322
+ break;
6323
+ }
6324
+ else {
6325
+ ndataEar++;
6326
+ }
6327
+ }
6328
+ }
6329
+ }
6330
+
6331
+ // Allocating memory according to the length of the table
6332
+ posEar = (double**)malloc(sizeof(double*) * ndataEar);
6333
+
6334
+ for (int j = 0; j < ndataEar; j++) {
6335
+ posEar[j] = (double*)malloc(sizeof(double) * 3);
6336
+ }
6337
+ ndataEar--;
6338
+ fclose(f);
6339
+
6340
+ // Reading data
6341
+ f = fopen(filename, "r");
6342
+ double tcur;
6343
+ startEar = stepEar = -1;
6344
+ // fseek(f, startpos, SEEK_SET);
6345
+
6346
+ // Finding start of data
6347
+ while (!feof(f)) {
6348
+ fscanf(f, "%s", teststring);
6349
+ if (!feof(f)) {
6350
+ fgetc(f); //fseek(f, 1, SEEK_CUR);
6351
+ teststring[5] = 0;
6352
+ if (strcmp(teststring, "$$SOE") == 0) {
6353
+ flag2 = 1;
6354
+ break;
6355
+ }
6356
+ }
6357
+ }
6358
+ for (int id = 0; id < ndataEar; id++) {
6359
+ if (fscanf(f, "%lf %lf %lf %lf %lf", &tcur, &RA, &Dec, &dis, &phiprec) == 5) {
6360
+ if (stepEar < 0) {
6361
+ if (startEar < 0) {
6362
+ startEar = tcur;
6363
+ }
6364
+ else {
6365
+ stepEar = tcur - startEar;
6366
+ startEar -= 2450000.0;
6367
+ }
6368
+ }
6369
+ RA *= M_PI / 180;
6370
+ Dec *= M_PI / 180;
6371
+ for (int i = 0; i < 3; i++) {
6372
+ posEar[id][i] = -dis * (cos(RA) * cos(Dec) * Eq2000[i] + sin(RA) * cos(Dec) * Quad2000[i] + sin(Dec) * North2000[i]);
6373
+ }
6374
+ }
6375
+ else {
6376
+ ndataEar = id;
6377
+ break;
6378
+ }
6379
+ }
6380
+ fclose(f);
6381
+ suntable = true;
6382
+ }
6383
+ else {
6384
+ printf("\nSun ephemeris table not found !");
6385
+ suntable = false;
6386
+ }
6387
+ }
6157
6388
 
6158
6389
  void VBMicrolensing::SetObjectCoordinates(char* modelfile, char* sateltabledir) {
6159
6390
  double RA, Dec, dis, phiprec;
@@ -6167,7 +6398,18 @@ void VBMicrolensing::SetObjectCoordinates(char* modelfile, char* sateltabledir)
6167
6398
  fscanf(f, "%[^\n]s", CoordinateString);
6168
6399
  fclose(f);
6169
6400
  SetObjectCoordinates(CoordinateString);
6170
-
6401
+
6402
+ // Removing any preiovusly loaded satellite table files
6403
+ if (nsat) {
6404
+ for (int i = 0; i < nsat; i++) {
6405
+ for (int j = 0; j < ndatasat[i]; j++) free(possat[i][j]);
6406
+ free(tsat[i]);
6407
+ free(possat[i]);
6408
+ }
6409
+ free(tsat);
6410
+ free(possat);
6411
+ free(ndatasat);
6412
+ }
6171
6413
  // Looking for satellite table files in the specified directory
6172
6414
  sprintf(filename, "%s%csatellite*.txt", sateltabledir, systemslash);
6173
6415
  nsat = 0;
@@ -6192,7 +6434,6 @@ void VBMicrolensing::SetObjectCoordinates(char* modelfile, char* sateltabledir)
6192
6434
  f = fopen(filename, "r");
6193
6435
  if (f != 0) {
6194
6436
  int flag2 = 0;
6195
- long startpos = 0;
6196
6437
  char teststring[1000];
6197
6438
  ndatasat[ic] = 1;
6198
6439
 
@@ -6211,7 +6452,6 @@ void VBMicrolensing::SetObjectCoordinates(char* modelfile, char* sateltabledir)
6211
6452
  // Finding end of data
6212
6453
  if (flag2) {
6213
6454
  flag2 = 0;
6214
- startpos = ftell(f);
6215
6455
  while (!feof(f)) {
6216
6456
  fscanf(f, "%[^\n]s", teststring);
6217
6457
  if (!feof(f)) {
@@ -6228,18 +6468,34 @@ void VBMicrolensing::SetObjectCoordinates(char* modelfile, char* sateltabledir)
6228
6468
  }
6229
6469
  }
6230
6470
  }
6471
+ fclose(f);
6231
6472
 
6232
6473
  // Allocating memory according to the length of the table
6233
6474
  tsat[ic] = (double*)malloc(sizeof(double) * ndatasat[ic]);
6234
6475
  possat[ic] = (double**)malloc(sizeof(double*) * ndatasat[ic]);
6476
+
6235
6477
  for (int j = 0; j < ndatasat[ic]; j++) {
6236
6478
  possat[ic][j] = (double*)malloc(sizeof(double) * 3);
6237
6479
  }
6238
6480
  ndatasat[ic]--;
6239
6481
 
6482
+ f = fopen(filename, "r");
6483
+ // Finding start of data
6484
+ while (!feof(f)) {
6485
+ fscanf(f, "%s", teststring);
6486
+ if (!feof(f)) {
6487
+ fgetc(f); //fseek(f, 1, SEEK_CUR);
6488
+ teststring[5] = 0;
6489
+ if (strcmp(teststring, "$$SOE") == 0) {
6490
+ flag2 = 1;
6491
+ break;
6492
+ }
6493
+ }
6494
+ }
6495
+
6240
6496
  // Reading data
6241
6497
  if (f) {
6242
- fseek(f, startpos, SEEK_SET);
6498
+ double tcur;
6243
6499
  for (int id = 0; id < ndatasat[ic]; id++) {
6244
6500
 
6245
6501
  if (fscanf(f, "%lf %lf %lf %lf %lf", &(tsat[ic][id]), &RA, &Dec, &dis, &phiprec) == 5) {
@@ -6268,34 +6524,44 @@ void VBMicrolensing::SetObjectCoordinates(char* modelfile, char* sateltabledir)
6268
6524
  }
6269
6525
 
6270
6526
  void VBMicrolensing::SetObjectCoordinates(char* CoordinateString) {
6271
- double RA, Dec, hr, mn, sc, deg, pr, ssc;
6527
+ double RA, Dec, hr, mn, sc, deg, pr, ssc, sp, r;
6272
6528
 
6273
- if (nsat) {
6274
- for (int i = 0; i < nsat; i++) {
6275
- for (int j = 0; j < ndatasat[i]; j++) free(possat[i][j]);
6276
- free(tsat[i]);
6277
- free(possat[i]);
6278
- }
6279
- free(tsat);
6280
- free(possat);
6281
- free(ndatasat);
6282
- }
6529
+ hr = mn = sc = deg = pr = ssc = -1.e100;
6283
6530
  sscanf(CoordinateString, "%lf:%lf:%lf %lf:%lf:%lf", &hr, &mn, &sc, &deg, &pr, &ssc);
6284
- RA = (hr + mn / 60 + sc / 3600) * M_PI / 12,
6531
+ if (hr >= 0 && hr < 24 && mn >= 0 && mn < 60 && sc >= 0 && sc < 60 && deg >= -90 && deg <= 90 && pr >= 0 && pr < 60 && ssc >= 0 && ssc < 60) {
6532
+ RA = (hr + mn / 60 + sc / 3600) * M_PI / 12;
6285
6533
  Dec = (fabs(deg) + pr / 60 + ssc / 3600) * M_PI / 180;
6286
- if (deg < 0) Dec = -Dec;
6534
+ if (deg < 0) Dec = -Dec;
6287
6535
 
6288
- for (int i = 0; i < 3; i++) {
6289
- Obj[i] = (cos(RA) * cos(Dec) * Eq2000[i] + sin(RA) * cos(Dec) * Quad2000[i] + sin(Dec) * North2000[i]);
6290
- rad[i] = Eq2000[i];
6291
- tang[i] = North2000[i];
6292
- }
6536
+ for (int i = 0; i < 3; i++) {
6537
+ Obj[i] = (cos(RA) * cos(Dec) * Eq2000[i] + sin(RA) * cos(Dec) * Quad2000[i] + sin(Dec) * North2000[i]);
6538
+ //rad[i] = Eq2000[i];
6539
+ //tang[i] = North2000[i];
6540
+ }
6541
+ sp = 0;
6542
+ for (int i = 0; i < 3; i++) sp += North2000[i] * Obj[i];
6543
+ for (int i = 0; i < 3; i++) rad[i] = -North2000[i] + sp * Obj[i];
6544
+
6545
+ r = sqrt(rad[0] * rad[0] + rad[1] * rad[1] + rad[2] * rad[2]); // Celestial South projected orthogonal to LOS
6546
+ rad[0] /= r;
6547
+ rad[1] /= r;
6548
+ rad[2] /= r;
6549
+ tang[0] = rad[1] * Obj[2] - rad[2] * Obj[1]; // Celestial West projected orthogonal to LOS
6550
+ tang[1] = rad[2] * Obj[0] - rad[0] * Obj[2];
6551
+ tang[2] = rad[0] * Obj[1] - rad[1] * Obj[0];
6293
6552
 
6294
- if (t0_par_fixed == -1) t0_par_fixed = 0;
6553
+ coordinates_set = true;
6554
+ }
6555
+ else coordinates_set = false;
6556
+ }
6295
6557
 
6558
+ bool VBMicrolensing::AreCoordinatesSet() {
6559
+ return coordinates_set;
6296
6560
  }
6297
6561
 
6298
6562
  void VBMicrolensing::ComputeParallax(double t, double t0) {
6563
+ static double dtflight = 0.0000993512; // = angle covered by Earth as light covers 1 au.
6564
+ static double au_c = 0.005775518331436995; // au/c in days.
6299
6565
  static double a0 = 1.00000261, adot = 0.00000562; // Ephemeris from JPL website
6300
6566
  static double e0 = 0.01671123, edot = -0.00004392;
6301
6567
  static double inc0 = -0.00001531, incdot = -0.01294668;
@@ -6304,15 +6570,120 @@ void VBMicrolensing::ComputeParallax(double t, double t0) {
6304
6570
  static double deg = M_PI / 180;
6305
6571
  static double a, e, inc, L, om, M, EE, dE, dM;
6306
6572
  static double x1, y1, vx, vy, Ear[3], vEar[3];
6307
- static double r, sp, ty, Spit;
6573
+ static double r, sp, ty, Spit, dLtof;
6308
6574
  int c = 0, ic;
6575
+
6576
+ if (!coordinates_set) {
6577
+ printf("\nUse SetObjectCoordinates to input target coordinates");
6578
+ return;
6579
+ }
6580
+ if (satellite > nsat) {
6581
+ printf("\nSatellite %d not available", satellite);
6582
+ return;
6583
+ }
6309
6584
 
6310
6585
  if (t0_par_fixed == 0) t0_par = t0;
6311
- if (t0_par_fixed == -1) {
6312
- printf("\nUse SetObjectCoordinates to input target coordinates");
6586
+
6587
+ if (parallaxephemeris) {
6588
+ // Calculation with lookup ephemeris table
6589
+ if (!suntable) {
6590
+ LoadSunTable(Suntablefile);
6591
+ }
6592
+ if (t0_par != t0old) {
6593
+ t0old = t0_par;
6594
+ ty = (t0_par - startEar) / stepEar;
6595
+ ic = (int)floor(ty);
6596
+ ty -= ic;
6597
+ for (int i = 0; i < 3; i++) Ear[i] = posEar[ic][i] * (1 - ty) + posEar[ic + 1][i] * ty;
6598
+ if (t_in_HJD) {
6599
+ double told = t, tnew;
6600
+ lighttravel0 = 0;
6601
+ for (int i = 0; i < 3; i++) lighttravel0 += Ear[i] * Obj[i];
6602
+ lighttravel0 *= au_c;
6603
+ tnew = t0_par - lighttravel0;
6604
+ while (fabs(told - tnew) > 1.e-8) {
6605
+ told = tnew;
6606
+ ty = (told - startEar) / stepEar;
6607
+ ic = (int)floor(ty);
6608
+ ty -= ic;
6609
+ for (int i = 0; i < 3; i++) Ear[i] = posEar[ic][i] * (1 - ty) + posEar[ic + 1][i] * ty;
6610
+ lighttravel0 = 0;
6611
+ for (int i = 0; i < 3; i++) lighttravel0 += Ear[i] * Obj[i];
6612
+ lighttravel0 *= au_c;
6613
+ tnew = t0_par - lighttravel0;
6614
+ }
6615
+ }
6616
+ for (int i = 0; i < 3; i++) {
6617
+ if (ty > 0.5) {
6618
+ vEar[i] = ((posEar[ic+2][i]- posEar[ic+1][i]) * (ty-0.5) + (posEar[ic+1][i] - posEar[ic][i]) * (1.5-ty)) / stepEar;
6619
+ }
6620
+ else {
6621
+ vEar[i] = ((posEar[ic][i] - posEar[ic-1][i]) * (0.5 - ty) + (posEar[ic+1][i] - posEar[ic][i]) * (ty+0.5)) / stepEar;
6622
+ }
6623
+ }
6624
+ if (parallaxsystem != 1) {
6625
+ sp = 0;
6626
+ for (int i = 0; i < 3; i++) sp += Ear[i] * Obj[i];
6627
+ for (int i = 0; i < 3; i++) rad[i] = Ear[i] - sp * Obj[i];
6628
+ r = sqrt(rad[0] * rad[0] + rad[1] * rad[1] + rad[2] * rad[2]); // Celestial South projected orthogonal to LOS
6629
+ rad[0] /= r;
6630
+ rad[1] /= r;
6631
+ rad[2] /= r;
6632
+ tang[0] = rad[1] * Obj[2] - rad[2] * Obj[1]; // Celestial West projected orthogonal to LOS
6633
+ tang[1] = rad[2] * Obj[0] - rad[0] * Obj[2];
6634
+ tang[2] = rad[0] * Obj[1] - rad[1] * Obj[0];
6635
+ }
6636
+
6637
+
6638
+ Et0[0] = Et0[1] = vt0[0] = vt0[1] = 0;
6639
+ lighttravel0 = 0;
6640
+ for (int i = 0; i < 3; i++) {
6641
+ Et0[0] += Ear[i] * rad[i]; // Earth position projected along South at time t0_par
6642
+ Et0[1] += Ear[i] * tang[i]; // Earth position projected along West at time t0_par
6643
+ lighttravel0 += Ear[i] * Obj[i];
6644
+ vt0[0] += vEar[i] * rad[i]; // Earth velocity projected along South at time t0_par
6645
+ vt0[1] += vEar[i] * tang[i]; // Earth velocity projected along West at time t0_par
6646
+ }
6647
+ lighttravel0 *= (t_in_HJD) ? 0 : au_c; // Light travel time from Earth projection to Sun: HJD = JD + lighttravel.
6648
+ }
6649
+ ty = (t - startEar) / stepEar;
6650
+ ic = (int)floor(ty);
6651
+ ty -= ic;
6652
+ if (ic < 0) { parallaxextrapolation = 1; ic = 0; ty = 0; }
6653
+ if (ic >= ndataEar) { parallaxextrapolation = 1; ic = ndataEar - 1; ty = 1; }
6654
+ for (int i = 0; i < 3; i++) Ear[i] = posEar[ic][i] * (1 - ty) + posEar[ic + 1][i] * ty;
6655
+ lighttravel = 0;
6656
+ for (int i = 0; i < 3; i++) lighttravel += Ear[i] * Obj[i];
6657
+ lighttravel *= au_c;
6658
+ if (t_in_HJD) {
6659
+ double told = t, tnew;
6660
+ tnew = t - lighttravel;
6661
+ while (fabs(told - tnew) > 1.e-8) {
6662
+ told = tnew;
6663
+ ty = (told - startEar) / stepEar;
6664
+ ic = (int)floor(ty);
6665
+ ty -= ic;
6666
+ if (ic < 0) { parallaxextrapolation = 1; ic = 0; ty = 0; }
6667
+ if (ic >= ndataEar) { parallaxextrapolation = 1; ic = ndataEar - 1; ty = 1; }
6668
+ for (int i = 0; i < 3; i++) Ear[i] = posEar[ic][i] * (1 - ty) + posEar[ic + 1][i] * ty;
6669
+ lighttravel = 0;
6670
+ for (int i = 0; i < 3; i++) lighttravel += Ear[i] * Obj[i];
6671
+ lighttravel *= au_c;
6672
+ tnew = t - lighttravel;
6673
+ }
6674
+ lighttravel = 0;
6675
+ }
6676
+ Ehel[0] = Ehel[1] = 0;
6677
+ for (int i = 0; i < 3; i++) {
6678
+ Ehel[0] += Ear[i] * rad[i]; // Ehel is the heliocentric position of Earth along South and West at time t
6679
+ Ehel[1] += Ear[i] * tang[i];
6680
+ }
6681
+ Et[0] = Ehel[0] - Et0[0] - vt0[0] * (t+lighttravel - t0_par-lighttravel0); // Earth shift along South wrt extrapolation from t0_par
6682
+ Et[1] = Ehel[1] - Et0[1] - vt0[1] * (t+lighttravel - t0_par-lighttravel0); // Earth shift along West wrt extrapolation from t0_par
6683
+
6313
6684
  }
6314
6685
  else {
6315
-
6686
+ // Calculation with Kepler equation
6316
6687
  if (t0_par != t0old) {
6317
6688
  t0old = t0_par;
6318
6689
  ty = (t0_par - 1545) / 36525.0;
@@ -6328,8 +6699,20 @@ void VBMicrolensing::ComputeParallax(double t, double t0) {
6328
6699
 
6329
6700
  EE = M + e * sin(M);
6330
6701
  dE = 1;
6702
+ dLtof = 0;
6331
6703
  while (fabs(dE) > 1.e-8) {
6332
- dM = M - (EE - e * sin(EE));
6704
+ if (t_in_HJD) {
6705
+ // Correction to calculate Earth position at JD not HJD
6706
+ x1 = a * (cos(EE) - e);
6707
+ y1 = a * sqrt(1 - e * e) * sin(EE);
6708
+ Ear[0] = x1 * cos(om) - y1 * sin(om);
6709
+ Ear[1] = x1 * sin(om) * cos(inc) + y1 * cos(om) * cos(inc);
6710
+ Ear[2] = x1 * sin(om) * sin(inc) + y1 * cos(om) * sin(inc);
6711
+ dLtof = 0;
6712
+ for (int i = 0; i < 3; i++) dLtof -= Ear[i] * Obj[i];
6713
+ dLtof *= dtflight;
6714
+ }
6715
+ dM = M + dLtof - (EE - e * sin(EE));
6333
6716
  dE = dM / (1 - e * cos(EE));
6334
6717
  EE += dE;
6335
6718
  }
@@ -6348,33 +6731,30 @@ void VBMicrolensing::ComputeParallax(double t, double t0) {
6348
6731
  // Ear is the Earth position in AU in ecliptic coordinates at time t0_par
6349
6732
  // vEar is the Earth velocity vector in AU/day in ecliptic coordinates at time t0_par
6350
6733
 
6351
- sp = 0;
6352
- switch (parallaxsystem) {
6353
- case 1:
6354
- for (int i = 0; i < 3; i++) sp += North2000[i] * Obj[i];
6355
- for (int i = 0; i < 3; i++) rad[i] = -North2000[i] + sp * Obj[i];
6356
- break;
6357
- default:
6734
+ if (parallaxsystem != 1) {
6735
+ sp = 0;
6358
6736
  for (int i = 0; i < 3; i++) sp += Ear[i] * Obj[i];
6359
6737
  for (int i = 0; i < 3; i++) rad[i] = Ear[i] - sp * Obj[i];
6360
- break;
6738
+ r = sqrt(rad[0] * rad[0] + rad[1] * rad[1] + rad[2] * rad[2]); // Celestial South projected orthogonal to LOS
6739
+ rad[0] /= r;
6740
+ rad[1] /= r;
6741
+ rad[2] /= r;
6742
+ tang[0] = rad[1] * Obj[2] - rad[2] * Obj[1]; // Celestial West projected orthogonal to LOS
6743
+ tang[1] = rad[2] * Obj[0] - rad[0] * Obj[2];
6744
+ tang[2] = rad[0] * Obj[1] - rad[1] * Obj[0];
6361
6745
  }
6362
6746
 
6363
- r = sqrt(rad[0] * rad[0] + rad[1] * rad[1] + rad[2] * rad[2]); // Celestial South projected orthogonal to LOS
6364
- rad[0] /= r;
6365
- rad[1] /= r;
6366
- rad[2] /= r;
6367
- tang[0] = rad[1] * Obj[2] - rad[2] * Obj[1]; // Celestial West projected orthogonal to LOS
6368
- tang[1] = rad[2] * Obj[0] - rad[0] * Obj[2];
6369
- tang[2] = rad[0] * Obj[1] - rad[1] * Obj[0];
6370
6747
 
6371
6748
  Et0[0] = Et0[1] = vt0[0] = vt0[1] = 0;
6749
+ lighttravel0 = 0;
6372
6750
  for (int i = 0; i < 3; i++) {
6373
6751
  Et0[0] += Ear[i] * rad[i]; // Earth position projected along South at time t0_par
6374
6752
  Et0[1] += Ear[i] * tang[i]; // Earth position projected along West at time t0_par
6753
+ lighttravel0 += Ear[i] * Obj[i];
6375
6754
  vt0[0] += vEar[i] * rad[i]; // Earth velocity projected along South at time t0_par
6376
6755
  vt0[1] += vEar[i] * tang[i]; // Earth velocity projected along West at time t0_par
6377
6756
  }
6757
+ lighttravel0 *= (t_in_HJD) ? 0 : au_c; // Light travel time from Earth projection to Sun: HJD = JD + lighttravel.
6378
6758
  }
6379
6759
 
6380
6760
  ty = (t - 1545) / 36525.0;
@@ -6390,8 +6770,21 @@ void VBMicrolensing::ComputeParallax(double t, double t0) {
6390
6770
 
6391
6771
  EE = M + e * sin(M);
6392
6772
  dE = 1;
6393
- while (dE > 1.e-8) {
6394
- dM = M - (EE - e * sin(EE));
6773
+ dLtof = 0;
6774
+ while (fabs(dE) > 1.e-8) {
6775
+ if (t_in_HJD) {
6776
+ // Correction to calculate Earth position at JD not HJD
6777
+ x1 = a * (cos(EE) - e);
6778
+ y1 = a * sqrt(1 - e * e) * sin(EE);
6779
+ Ear[0] = x1 * cos(om) - y1 * sin(om);
6780
+ Ear[1] = x1 * sin(om) * cos(inc) + y1 * cos(om) * cos(inc);
6781
+ Ear[2] = x1 * sin(om) * sin(inc) + y1 * cos(om) * sin(inc);
6782
+ dLtof = 0;
6783
+ for (int i = 0; i < 3; i++) dLtof -= Ear[i] * Obj[i];
6784
+ dLtof *= dtflight;
6785
+ }
6786
+
6787
+ dM = M + dLtof - (EE - e * sin(EE));
6395
6788
  dE = dM / (1 - e * cos(EE));
6396
6789
  EE += dE;
6397
6790
  }
@@ -6406,45 +6799,68 @@ void VBMicrolensing::ComputeParallax(double t, double t0) {
6406
6799
  Ear[2] = x1 * sin(om) * sin(inc) + y1 * cos(om) * sin(inc);
6407
6800
  // Ear is the Earth position in AU in ecliptic coordinates at time t
6408
6801
 
6409
- Ehel[0] = Ehel[1] = 0;
6802
+ Ehel[0] = Ehel[1] = lighttravel = 0;
6410
6803
  for (int i = 0; i < 3; i++) {
6411
6804
  Ehel[0] += Ear[i] * rad[i]; // Ehel is the heliocentric position of Earth along South and West at time t
6412
6805
  Ehel[1] += Ear[i] * tang[i];
6806
+ lighttravel += Ear[i] * Obj[i];
6413
6807
  }
6414
- Et[0] = Ehel[0] - Et0[0] - vt0[0] * (t - t0_par); // Earth shift along South wrt extrapolation from t0_par
6415
- Et[1] = Ehel[1] - Et0[1] - vt0[1] * (t - t0_par); // Earth shift along West wrt extrapolation from t0_par
6808
+ lighttravel *= (t_in_HJD) ? 0 : au_c; // Light travel time from Earth projection to Sun: HJD = JD + lighttravel.
6809
+ Et[0] = Ehel[0] - Et0[0] - vt0[0] * (t + lighttravel - t0_par - lighttravel0); // Earth shift along South wrt extrapolation from t0_par
6810
+ Et[1] = Ehel[1] - Et0[1] - vt0[1] * (t + lighttravel - t0_par - lighttravel0); // Earth shift along West wrt extrapolation from t0_par
6416
6811
 
6417
- if (satellite > 0 && satellite <= nsat) {
6418
- if (ndatasat[satellite - 1] > 2) {
6419
- int left, right;
6420
- if (t < tsat[satellite - 1][0]) {
6421
- ic = 0;
6812
+ }
6813
+
6814
+
6815
+ //// For debugging: writes Sun coordinates from Earth to file for comparison with exact ephemerides.
6816
+ //{
6817
+ // FILE* f = fopen("C:\\Users\\valboz\\Personali\\MicroModels\\test-dev\\ephemeris_test\\outapp.txt", "a");
6818
+ // double RA, Dec, ran,x,y,z;
6819
+ // ran = a * (1 - e * cos(EE));
6820
+ // z = x = y = 0;
6821
+ // for (int i = 0; i < 3; i++) z += Ear[i] * North2000[i];
6822
+ // for (int i = 0; i < 3; i++) x += Ear[i] * Eq2000[i];
6823
+ // for (int i = 0; i < 3; i++) y += Ear[i] * Quad2000[i];
6824
+ // Dec = -asin(z / ran)/deg;
6825
+ // RA = 180 + atan2(y, x)/deg;
6826
+ // if (RA < 0) RA += 360;
6827
+ // fprintf(f,"%lf %lf %lf %lf\n", t, RA, Dec, ran);
6828
+ // fclose(f);
6829
+ //}
6830
+
6831
+
6832
+ if (satellite > 0 && satellite <= nsat) {
6833
+ if (ndatasat[satellite - 1] > 2) {
6834
+ int left, right;
6835
+ if (t < tsat[satellite - 1][0]) {
6836
+ ic = 0;
6837
+ parallaxextrapolation = 2;
6838
+ }
6839
+ else {
6840
+ if (t > tsat[satellite - 1][ndatasat[satellite - 1] - 1]) {
6841
+ ic = ndatasat[satellite - 1] - 2;
6842
+ parallaxextrapolation = 2;
6422
6843
  }
6423
6844
  else {
6424
- if (t > tsat[satellite - 1][ndatasat[satellite - 1] - 1]) {
6425
- ic = ndatasat[satellite - 1] - 2;
6426
- }
6427
- else {
6428
- left = 0;
6429
- right = ndatasat[satellite - 1] - 1;
6430
- while (right - left > 1) {
6431
- ic = (right + left) / 2;
6432
- if (tsat[satellite - 1][ic] > t) {
6433
- right = ic;
6434
- }
6435
- else {
6436
- left = ic;
6437
- }
6845
+ left = 0;
6846
+ right = ndatasat[satellite - 1] - 1;
6847
+ while (right - left > 1) {
6848
+ ic = (right + left) / 2;
6849
+ if (tsat[satellite - 1][ic] > t) {
6850
+ right = ic;
6851
+ }
6852
+ else {
6853
+ left = ic;
6438
6854
  }
6439
- ic = left;
6440
6855
  }
6856
+ ic = left;
6441
6857
  }
6442
- ty = (t - tsat[satellite - 1][ic])/(tsat[satellite - 1][ic+1]- tsat[satellite - 1][ic]);
6443
- for (int i = 0; i < 3; i++) {
6444
- Spit = possat[satellite - 1][ic][i] * (1 - ty) + possat[satellite - 1][ic + 1][i] * ty;
6445
- Et[0] += Spit * rad[i];
6446
- Et[1] += Spit * tang[i];
6447
- }
6858
+ }
6859
+ ty = t - tsat[satellite - 1][ic];
6860
+ for (int i = 0; i < 3; i++) {
6861
+ Spit = possat[satellite - 1][ic][i] * (1 - ty) + possat[satellite - 1][ic + 1][i] * ty;
6862
+ Et[0] += Spit * rad[i];
6863
+ Et[1] += Spit * tang[i];
6448
6864
  }
6449
6865
  }
6450
6866
  }