sweph 2.10.2-4 → 2.10.3-2

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.
Files changed (61) hide show
  1. package/README.md +12 -11
  2. package/deps/swisseph/swecl.c +32 -42
  3. package/deps/swisseph/swehouse.c +5 -1
  4. package/deps/swisseph/sweph.c +194 -288
  5. package/deps/swisseph/sweph.h +3 -6
  6. package/deps/swisseph/swephexp.h +3 -3
  7. package/deps/swisseph/swephlib.c +11 -12
  8. package/deps/swisseph/swephlib.h +0 -2
  9. package/index.d.ts +7 -7
  10. package/package.json +2 -2
  11. package/src/functions/calc.cpp +1 -1
  12. package/src/functions/calc_pctr.cpp +1 -1
  13. package/src/functions/calc_ut.cpp +1 -1
  14. package/src/functions/deltat_ex.cpp +1 -1
  15. package/src/functions/fixstar.cpp +1 -1
  16. package/src/functions/fixstar2.cpp +1 -1
  17. package/src/functions/fixstar2_mag.cpp +1 -1
  18. package/src/functions/fixstar2_ut.cpp +1 -1
  19. package/src/functions/fixstar_mag.cpp +1 -1
  20. package/src/functions/fixstar_ut.cpp +1 -1
  21. package/src/functions/gauquelin_sector.cpp +1 -1
  22. package/src/functions/get_ayanamsa_ex.cpp +1 -1
  23. package/src/functions/get_ayanamsa_ex_ut.cpp +1 -1
  24. package/src/functions/get_orbital_elements.cpp +1 -1
  25. package/src/functions/heliacal_pheno_ut.cpp +1 -1
  26. package/src/functions/heliacal_ut.cpp +1 -1
  27. package/src/functions/helio_cross.cpp +1 -1
  28. package/src/functions/helio_cross_ut.cpp +1 -1
  29. package/src/functions/house_pos.cpp +1 -1
  30. package/src/functions/houses_armc_ex2.cpp +1 -1
  31. package/src/functions/houses_ex2.cpp +1 -1
  32. package/src/functions/lat_to_lmt.cpp +1 -1
  33. package/src/functions/lmt_to_lat.cpp +1 -1
  34. package/src/functions/lun_eclipse_how.cpp +1 -1
  35. package/src/functions/lun_eclipse_when.cpp +1 -1
  36. package/src/functions/lun_eclipse_when_loc.cpp +1 -1
  37. package/src/functions/lun_occult_when_glob.cpp +1 -1
  38. package/src/functions/lun_occult_when_loc.cpp +1 -1
  39. package/src/functions/lun_occult_where.cpp +1 -1
  40. package/src/functions/mooncross.cpp +1 -1
  41. package/src/functions/mooncross_node.cpp +1 -1
  42. package/src/functions/mooncross_node_ut.cpp +1 -1
  43. package/src/functions/mooncross_ut.cpp +1 -1
  44. package/src/functions/nod_aps.cpp +1 -1
  45. package/src/functions/nod_aps_ut.cpp +1 -1
  46. package/src/functions/orbit_max_min_true_distance.cpp +1 -1
  47. package/src/functions/pheno.cpp +1 -1
  48. package/src/functions/pheno_ut.cpp +1 -1
  49. package/src/functions/rise_trans.cpp +1 -1
  50. package/src/functions/rise_trans_true_hor.cpp +1 -1
  51. package/src/functions/set_ephe_path.cpp +1 -1
  52. package/src/functions/set_jpl_file.cpp +1 -1
  53. package/src/functions/sol_eclipse_how.cpp +1 -1
  54. package/src/functions/sol_eclipse_when_glob.cpp +1 -1
  55. package/src/functions/sol_eclipse_when_loc.cpp +1 -1
  56. package/src/functions/sol_eclipse_where.cpp +1 -1
  57. package/src/functions/solcross.cpp +1 -1
  58. package/src/functions/solcross_ut.cpp +1 -1
  59. package/src/functions/time_equ.cpp +1 -1
  60. package/src/functions/utc_to_jd.cpp +1 -1
  61. package/src/functions/vis_limit_mag.cpp +1 -1
@@ -96,13 +96,8 @@ struct meff_ele {double r,m;};
96
96
  TLS struct swe_data swed = {FALSE, /* ephe_path_is_set = FALSE */
97
97
  FALSE, /* jpl_file_is_open = FALSE */
98
98
  NULL, /* fixfp, fixed stars file pointer */
99
- #if 0
100
- SE_EPHE_PATH, /* ephepath, ephemeris path */
101
- SE_FNAME_DFT, /* jplfnam, JPL file name, default */
102
- #else
103
99
  "", /* ephepath, ephemeris path */
104
100
  "", /* jplfnam, JPL file name, default */
105
- #endif
106
101
  0, /* jpldenum */
107
102
  0, /* last_epheflag */
108
103
  FALSE, /* geopos_is_set, for topocentric */
@@ -378,12 +373,13 @@ int32 CALL_CONV swe_calc(double tjd, int ipl, int32 iflag,
378
373
  * or vice-versa.
379
374
  */
380
375
  epheflag = iflag & SEFLG_EPHMASK;
381
- if (epheflag & SEFLG_MOSEPH)
376
+ if (epheflag & SEFLG_MOSEPH) {
382
377
  epheflag = SEFLG_MOSEPH;
383
- else if (epheflag & SEFLG_JPLEPH)
378
+ } else if (epheflag & SEFLG_JPLEPH) {
384
379
  epheflag = SEFLG_JPLEPH;
385
- else
380
+ } else {
386
381
  epheflag = SEFLG_SWIEPH;
382
+ }
387
383
  if (swi_init_swed_if_start() == 1 && !(epheflag & SEFLG_MOSEPH) && serr != NULL) {
388
384
  strcpy(serr, "Please call swe_set_ephe_path() or swe_set_jplfile() before calling swe_calc() or swe_calc_ut()");
389
385
  }
@@ -515,10 +511,11 @@ int32 CALL_CONV swe_calc(double tjd, int ipl, int32 iflag,
515
511
  }
516
512
  if (iflag & SEFLG_XYZ)
517
513
  xs = xs+6; /* cartesian coordinates */
518
- if (ipl == SE_ECL_NUT)
514
+ if (ipl == SE_ECL_NUT) {
519
515
  i = 4;
520
- else
516
+ } else {
521
517
  i = 3;
518
+ }
522
519
  for (j = 0; j < i; j++)
523
520
  x[j] = *(xs + j);
524
521
  for (j = i; j < 6; j++)
@@ -596,11 +593,7 @@ static int32 swecalc(double tjd, int ipl, int32 iplmoon, int32 iflag, double *x,
596
593
  struct plan_data *pdp;
597
594
  struct plan_data *pedp = &swed.pldat[SEI_EARTH];
598
595
  struct plan_data *psdp = &swed.pldat[SEI_SUNBARY];
599
- #if 0
600
- struct node_data *ndp;
601
- #else
602
596
  struct plan_data *ndp;
603
- #endif
604
597
  double *xp, *xp2;
605
598
  double ss[3];
606
599
  char serr2[AS_MAXCH];
@@ -702,18 +695,8 @@ static int32 swecalc(double tjd, int ipl, int32 iplmoon, int32 iflag, double *x,
702
695
  break;
703
696
  case SEFLG_SWIEPH:
704
697
  sweph_moon:
705
- #if 0
706
- /* for hel. or bary. position, we need earth and sun as well;
707
- * this is done by sweplan(), but not by swemoon() */
708
- if (iflag & (SEFLG_HELCTR | SEFLG_BARYCTR | SEFLG_NOABERR))
709
- retc = sweplan(tjd, ipli, SEI_FILE_MOON, iflag, DO_SAVE,
710
- NULL, NULL, NULL, NULL, serr);
711
- else
712
- retc = swemoon(tjd, iflag, DO_SAVE, pdp->x, serr);/**/
713
- #else
714
698
  retc = sweplan(tjd, ipli, SEI_FILE_MOON, iflag, DO_SAVE,
715
699
  NULL, NULL, NULL, NULL, serr);
716
- #endif
717
700
  if (retc == ERR)
718
701
  goto return_error;
719
702
  /* if sweph file not found, switch to moshier */
@@ -814,9 +797,6 @@ static int32 swecalc(double tjd, int ipl, int32 iplmoon, int32 iflag, double *x,
814
797
  /* pedp->teval = tjd; */
815
798
  break;
816
799
  default:
817
- #if 0
818
- moshier_sbar:
819
- #endif
820
800
  return ERR;
821
801
  break;
822
802
  }
@@ -1046,34 +1026,28 @@ static int32 swecalc(double tjd, int ipl, int32 iplmoon, int32 iflag, double *x,
1046
1026
  || ipl > SE_AST_OFFSET // obsolete after previous condition
1047
1027
  ) {
1048
1028
  /* internal planet number */
1049
- if (ipl < SE_NPLANETS)
1029
+ if (ipl < SE_NPLANETS) {
1050
1030
  ipli = pnoext2int[ipl];
1051
- else if (ipl <= SE_AST_OFFSET + MPC_VESTA && ipl > SE_AST_OFFSET) {
1031
+ } else if (ipl <= SE_AST_OFFSET + MPC_VESTA && ipl > SE_AST_OFFSET) {
1052
1032
  ipli = SEI_CERES + ipl - SE_AST_OFFSET - 1;
1053
1033
  ipl = SE_CERES + ipl - SE_AST_OFFSET - 1;
1054
- #if 0
1055
- } else if (ipl == SE_AST_OFFSET + MPC_CHIRON) {
1056
- ipli = SEI_CHIRON;
1057
- ipl = SE_CHIRON;
1058
- } else if (ipl == SE_AST_OFFSET + MPC_PHOLUS) {
1059
- ipli = SEI_PHOLUS;
1060
- ipl = SE_PHOLUS;
1061
- #endif
1062
1034
  } else { /* any asteroid except*/
1063
1035
  ipli = SEI_ANYBODY;
1064
1036
  }
1065
- if (ipli == SEI_ANYBODY)
1037
+ if (ipli == SEI_ANYBODY) {
1066
1038
  ipli_ast = ipl;
1067
- else
1039
+ } else {
1068
1040
  ipli_ast = ipli;
1041
+ }
1069
1042
  pdp = &swed.pldat[ipli];
1070
1043
  xp = pdp->xreturn;
1071
- if (ipli_ast > SE_AST_OFFSET)
1044
+ if (ipli_ast > SE_AST_OFFSET) {
1072
1045
  ifno = SEI_FILE_ANY_AST;
1073
- else if (ipli_ast > SE_PLMOON_OFFSET)
1046
+ } else if (ipli_ast > SE_PLMOON_OFFSET) {
1074
1047
  ifno = SEI_FILE_ANY_AST;
1075
- else
1048
+ } else {
1076
1049
  ifno = SEI_FILE_MAIN_AST;
1050
+ }
1077
1051
  if (ipli == SEI_CHIRON && (tjd < CHIRON_START || tjd > CHIRON_END)) {
1078
1052
  if (serr != NULL)
1079
1053
  sprintf(serr, "Chiron's ephemeris is restricted to JD %8.1f - JD %8.1f",
@@ -1130,19 +1104,6 @@ static int32 swecalc(double tjd, int ipl, int32 iplmoon, int32 iflag, double *x,
1130
1104
  * (Isis-Transpluto and Uranian planets) *
1131
1105
  ***********************************************/
1132
1106
  } else if (ipl >= SE_FICT_OFFSET && ipl <= SE_FICT_MAX) {
1133
- #if 0
1134
- ipl == SE_CUPIDO
1135
- || ipl == SE_HADES
1136
- || ipl == SE_ZEUS
1137
- || ipl == SE_KRONOS
1138
- || ipl == SE_APOLLON
1139
- || ipl == SE_ADMETOS
1140
- || ipl == SE_VULKANUS
1141
- || ipl == SE_POSEIDON
1142
- || ipl == SE_ISIS
1143
- || ipl == SE_NEPTUNE_LEVERRIER
1144
- || ipl == SE_NEPTUNE_ADAMS)
1145
- #endif
1146
1107
  /* internal planet number */
1147
1108
  ipli = SEI_ANYBODY;
1148
1109
  pdp = &swed.pldat[ipli];
@@ -1211,11 +1172,7 @@ static void free_planets(void)
1211
1172
  memset((void *) &swed.savedat[i], 0, sizeof(struct save_positions));
1212
1173
  /* clear node data space */
1213
1174
  for (i = 0; i < SEI_NNODE_ETC; i++) {
1214
- #if 0
1215
- memset((void *) &swed.nddat[i], 0, sizeof(struct node_data));
1216
- #else
1217
1175
  memset((void *) &swed.nddat[i], 0, sizeof(struct plan_data));
1218
- #endif
1219
1176
  }
1220
1177
  }
1221
1178
 
@@ -1355,7 +1312,7 @@ void CALL_CONV swe_close(void)
1355
1312
  * won't return planet positions previously computed from other
1356
1313
  * ephemerides
1357
1314
  */
1358
- void CALL_CONV swe_set_ephe_path(char *path)
1315
+ void CALL_CONV swe_set_ephe_path(const char *path)
1359
1316
  {
1360
1317
  int i, iflag;
1361
1318
  char s[AS_MAXCH];
@@ -1377,15 +1334,6 @@ void CALL_CONV swe_set_ephe_path(char *path)
1377
1334
  } else {
1378
1335
  strcpy(s, SE_EPHE_PATH);
1379
1336
  }
1380
- /*
1381
- #if MSDOS
1382
- if (strchr(s, '/') != NULL)
1383
- strcpy(s, SE_EPHE_PATH);
1384
- #else
1385
- if (strchr(s, '\\') != NULL)
1386
- strcpy(s, SE_EPHE_PATH);
1387
- #endif
1388
- */
1389
1337
  i = (int) strlen(s);
1390
1338
  if (*(s + i - 1) != *DIR_GLUE && *s != '\0')
1391
1339
  strcat(s, DIR_GLUE);
@@ -1404,10 +1352,11 @@ void CALL_CONV swe_set_ephe_path(char *path)
1404
1352
  if (swi_trace_count < TRACE_COUNT_MAX) {
1405
1353
  if (swi_fp_trace_c != NULL) {
1406
1354
  fputs("\n/*SWE_SET_EPHE_PATH*/\n", swi_fp_trace_c);
1407
- if (path == NULL)
1355
+ if (path == NULL) {
1408
1356
  fputs(" *s = '\\0';\n", swi_fp_trace_c);
1409
- else
1357
+ } else {
1410
1358
  fprintf(swi_fp_trace_c, " strcpy(s, \"%s\");\n", path);
1359
+ }
1411
1360
  fputs(" swe_set_ephe_path(s);\n", swi_fp_trace_c);
1412
1361
  fputs(" printf(\"swe_set_ephe_path: path_in = \");", swi_fp_trace_c);
1413
1362
  fputs(" printf(s);\n", swi_fp_trace_c);
@@ -1522,22 +1471,29 @@ void load_dpsi_deps(void)
1522
1471
  * won't return planet positions previously computed from other
1523
1472
  * ephemerides
1524
1473
  */
1525
- void CALL_CONV swe_set_jpl_file(char *fname)
1474
+ void CALL_CONV swe_set_jpl_file(const char *fname)
1526
1475
  {
1527
- char *sp;
1476
+ char *sp, s[AS_MAXCH];
1528
1477
  int retc;
1529
1478
  double ss[3];
1530
1479
  /* close all open files and delete all planetary data */
1531
1480
  swi_close_keep_topo_etc();
1532
1481
  swi_init_swed_if_start();
1533
- /* if path is contained in fnam, it is filled into the path variable */
1534
- sp = strrchr(fname, (int) *DIR_GLUE);
1535
- if (sp == NULL)
1536
- sp = fname;
1537
- else
1482
+ /* if path is contained in fname, it is filled into the path variable */
1483
+ if (strlen(fname) >= AS_MAXCH) {
1484
+ strncpy(s, fname, AS_MAXCH - 1);
1485
+ s[AS_MAXCH - 1] = '\0';
1486
+ } else {
1487
+ strcpy(s, fname);
1488
+ }
1489
+ sp = strrchr(s, (int) *DIR_GLUE);
1490
+ if (sp == NULL) {
1491
+ sp = s;
1492
+ } else {
1538
1493
  sp = sp + 1;
1494
+ }
1539
1495
  if (strlen(sp) >= AS_MAXCH)
1540
- sp[AS_MAXCH] = '\0';
1496
+ sp[AS_MAXCH - 1] = '\0';
1541
1497
  strcpy(swed.jplfnam, sp);
1542
1498
  /* open ephemeris */
1543
1499
  retc = open_jpl_file(ss, swed.jplfnam, swed.ephepath, NULL);
@@ -1677,10 +1633,11 @@ static int main_planet(double tjd, int ipli, int iplmoon, int32 epheflag, int32
1677
1633
  return ERR;
1678
1634
  }
1679
1635
  /* geocentric, lighttime etc. */
1680
- if (ipli == SEI_SUN)
1636
+ if (ipli == SEI_SUN) {
1681
1637
  retc = app_pos_etc_sun(iflag, serr)/**/;
1682
- else
1638
+ } else {
1683
1639
  retc = app_pos_etc_plan(ipli, iplmoon, iflag, serr);
1640
+ }
1684
1641
  if (retc == ERR)
1685
1642
  return ERR;
1686
1643
  /* if sweph file for t(lighttime) not found, switch to moshier */
@@ -1700,10 +1657,11 @@ static int main_planet(double tjd, int ipli, int iplmoon, int32 epheflag, int32
1700
1657
  if (retc == ERR)
1701
1658
  return ERR;
1702
1659
  /* geocentric, lighttime etc. */
1703
- if (ipli == SEI_SUN)
1660
+ if (ipli == SEI_SUN) {
1704
1661
  retc = app_pos_etc_sun(iflag, serr)/**/;
1705
- else
1662
+ } else {
1706
1663
  retc = app_pos_etc_plan(ipli, iplmoon, iflag, serr);
1664
+ }
1707
1665
  if (retc == ERR)
1708
1666
  return ERR;
1709
1667
  break;
@@ -1758,10 +1716,7 @@ static int main_planet_bary(double tjd, int ipli, int32 epheflag, int32 iflag, A
1758
1716
  sweph_planet:
1759
1717
  /* compute barycentric planet (+ earth, sun, moon) */
1760
1718
  retc = sweplan(tjd, ipli, SEI_FILE_PLANET, iflag, do_save, xp, xe, xs, xm, serr);
1761
- #if 0
1762
- if (retc == ERR || retc == NOT_AVAILABLE)
1763
- return retc;
1764
- #else /* if barycentric moshier calculation were implemented */
1719
+ /* if barycentric moshier calculation were implemented */
1765
1720
  if (retc == ERR)
1766
1721
  return ERR;
1767
1722
  /* if sweph file not found, switch to moshier */
@@ -1775,12 +1730,9 @@ static int main_planet_bary(double tjd, int ipli, int32 epheflag, int32 iflag, A
1775
1730
  return ERR;
1776
1731
  }
1777
1732
  }
1778
- #endif
1779
1733
  break;
1780
1734
  case SEFLG_MOSEPH:
1781
- #if 1
1782
1735
  moshier_planet:
1783
- #endif
1784
1736
  retc = swi_moshplan(tjd, ipli, do_save, xp, xe, serr);/**/
1785
1737
  if (retc == ERR)
1786
1738
  return ERR;
@@ -1810,10 +1762,11 @@ static int swemoon(double tjd, int32 iflag, AS_BOOL do_save, double *xpret, char
1810
1762
  struct plan_data *pdp = &swed.pldat[SEI_MOON];
1811
1763
  int32 speedf1, speedf2;
1812
1764
  double xx[6], *xp;
1813
- if (do_save)
1765
+ if (do_save) {
1814
1766
  xp = pdp->x;
1815
- else
1767
+ } else {
1816
1768
  xp = xx;
1769
+ }
1817
1770
  /* if planet has already been computed for this date, return
1818
1771
  * if speed flag has been turned on, recompute planet */
1819
1772
  speedf1 = pdp->xflgs & SEFLG_SPEED;
@@ -1886,15 +1839,8 @@ static int sweplan(double tjd, int ipli, int ifno, int32 iflag, AS_BOOL do_save,
1886
1839
  if (do_save || ipli == SEI_EARTH || xperet != NULL)
1887
1840
  do_earth = TRUE;
1888
1841
  if (ipli == SEI_MOON) {
1889
- #if 0
1890
- if (iflag & (SEFLG_HELCTR | SEFLG_BARYCTR | SEFLG_NOABERR))
1891
- do_earth = TRUE;
1892
- if (iflag & (SEFLG_HELCTR | SEFLG_NOABERR))
1893
- do_sunbary = TRUE;
1894
- #else
1895
1842
  do_earth = TRUE;
1896
1843
  do_sunbary = TRUE;
1897
- #endif
1898
1844
  }
1899
1845
  if (do_save || ipli == SEI_MOON || ipli == SEI_EARTH || xperet != NULL || xpmret != NULL)
1900
1846
  do_moon = TRUE;
@@ -2193,10 +2139,11 @@ static int sweph(double tjd, int ipli, int ifno, int32 iflag, double *xsunb, AS_
2193
2139
  if (ipli > SE_PLMOON_OFFSET)
2194
2140
  ipl = SEI_ANYBODY;
2195
2141
  pdp = &swed.pldat[ipl];
2196
- if (do_save)
2142
+ if (do_save) {
2197
2143
  xp = pdp->x;
2198
- else
2144
+ } else {
2199
2145
  xp = xx;
2146
+ }
2200
2147
  /* if planet has already been computed for this date, return.
2201
2148
  * if speed flag has been turned on, recompute planet */
2202
2149
  speedf1 = pdp->xflgs & SEFLG_SPEED;
@@ -2287,10 +2234,11 @@ again:
2287
2234
  if (tjd < fdp->tfstart || tjd > fdp->tfend) {
2288
2235
  if (serr != NULL) {
2289
2236
  sp = strrchr(fname, (int) *DIR_GLUE);
2290
- if (sp != NULL)
2237
+ if (sp != NULL) {
2291
2238
  sp++;
2292
- else
2239
+ } else {
2293
2240
  sp = fname;
2241
+ }
2294
2242
  if (ipli > SE_AST_OFFSET) {
2295
2243
  sprintf(s, "asteroid No. %d (%s): ", ipli - SE_AST_OFFSET, sp);
2296
2244
  } else if (ipli > SE_PLMOON_OFFSET) {
@@ -2305,12 +2253,13 @@ again:
2305
2253
  } else {
2306
2254
  sprintf(s, "moon eph. file (%s): ", sp);
2307
2255
  }
2308
- if (tjd < fdp->tfstart)
2256
+ if (tjd < fdp->tfstart) {
2309
2257
  sprintf(s + strlen(s), "jd %f < lower limit %f;",
2310
2258
  tjd, fdp->tfstart);
2311
- else
2259
+ } else {
2312
2260
  sprintf(s + strlen(s), "jd %f > upper limit %f;",
2313
2261
  tjd, fdp->tfend);
2262
+ }
2314
2263
  if (strlen(serr) + strlen(s) < AS_MAXCH)
2315
2264
  strcat(serr, s);
2316
2265
  }
@@ -2326,10 +2275,11 @@ again:
2326
2275
  return(retc);
2327
2276
  /* rotate cheby coeffs back to equatorial system.
2328
2277
  * if necessary, add reference orbit. */
2329
- if (pdp->iflg & SEI_FLG_ROTATE)
2278
+ if (pdp->iflg & SEI_FLG_ROTATE) {
2330
2279
  rot_back(ipl); /**/
2331
- else
2280
+ } else {
2332
2281
  pdp->neval = pdp->ncoe;
2282
+ }
2333
2283
  }
2334
2284
  /* evaluate chebyshew polynomial for tjd */
2335
2285
  t = (tjd - pdp->tseg0) / pdp->dseg;
@@ -2343,10 +2293,11 @@ again:
2343
2293
  need_speed = (do_save || (iflag & SEFLG_SPEED));
2344
2294
  for (i = 0; i <= 2; i++) {
2345
2295
  xp[i] = swi_echeb (t, pdp->segp+(i*pdp->ncoe), pdp->neval);
2346
- if (need_speed)
2296
+ if (need_speed) {
2347
2297
  xp[i+3] = swi_edcheb(t, pdp->segp+(i*pdp->ncoe), pdp->neval) / pdp->dseg * 2;
2348
- else
2298
+ } else {
2349
2299
  xp[i+3] = 0; /* von Alois als billiger fix, evtl. illegal */
2300
+ }
2350
2301
  }
2351
2302
  /* if planet wanted is barycentric sun:
2352
2303
  * current sepl* files have do not have barycentric sun,
@@ -2393,10 +2344,11 @@ again:
2393
2344
  if (do_save) {
2394
2345
  pdp->teval = tjd;
2395
2346
  pdp->xflgs = -1; /* do new computation of light-time etc. */
2396
- if (ifno == SEI_FILE_PLANET || ifno == SEI_FILE_MOON)
2347
+ if (ifno == SEI_FILE_PLANET || ifno == SEI_FILE_MOON) {
2397
2348
  pdp->iephe = SEFLG_SWIEPH;/**/
2398
- else
2349
+ } else {
2399
2350
  pdp->iephe = psdp->iephe;
2351
+ }
2400
2352
  }
2401
2353
  if (xpret != NULL)
2402
2354
  for (i = 0; i <= 5; i++)
@@ -2457,10 +2409,11 @@ int32 swi_get_denum(int32 ipli, int32 iflag)
2457
2409
  if (iflag & SEFLG_MOSEPH)
2458
2410
  return 403;
2459
2411
  if (iflag & SEFLG_JPLEPH) {
2460
- if (swed.jpldenum > 0)
2412
+ if (swed.jpldenum > 0) {
2461
2413
  return swed.jpldenum;
2462
- else
2414
+ } else {
2463
2415
  return SE_DE_NUMBER;
2416
+ }
2464
2417
  }
2465
2418
  if (ipli > SE_AST_OFFSET) {
2466
2419
  fdp = &swed.fidat[SEI_FILE_ANY_AST];
@@ -2479,10 +2432,11 @@ int32 swi_get_denum(int32 ipli, int32 iflag)
2479
2432
  fdp = &swed.fidat[SEI_FILE_PLANET];
2480
2433
  }
2481
2434
  if (fdp != NULL) {
2482
- if (fdp->sweph_denum != 0)
2435
+ if (fdp->sweph_denum != 0) {
2483
2436
  return fdp->sweph_denum;
2484
- else
2437
+ } else {
2485
2438
  return SE_DE_NUMBER;
2439
+ }
2486
2440
  }
2487
2441
  return SE_DE_NUMBER;
2488
2442
  }
@@ -2541,13 +2495,6 @@ static int app_pos_etc_plan(int ipli, int iplmoon, int32 iflag, char *serr)
2541
2495
  pdp = &swed.pldat[ipli];
2542
2496
  }
2543
2497
  t = pdp->teval;
2544
- #if 0
2545
- {
2546
- struct plan_data *psp = &swed.pldat[SEI_SUNBARY];
2547
- printf("planet %.14f %.14f %.14f\n", pdp->x[0], pdp->x[1], pdp->x[2]);
2548
- printf("sunbary %.14f %.14f %.14f\n", psp->x[0], psp->x[1], psp->x[2]);
2549
- }
2550
- #endif
2551
2498
  /* if the same conversions have already been done for the same
2552
2499
  * date, then return */
2553
2500
  flg1 = iflag & ~SEFLG_EQUATORIAL & ~SEFLG_XYZ;
@@ -2596,10 +2543,11 @@ static int app_pos_etc_plan(int ipli, int iplmoon, int32 iflag, char *serr)
2596
2543
  *******************************/
2597
2544
  if (!(iflag & SEFLG_TRUEPOS)) {
2598
2545
  /* number of iterations - 1 */
2599
- if (pdp->iephe == SEFLG_JPLEPH || pdp->iephe == SEFLG_SWIEPH)
2546
+ if (pdp->iephe == SEFLG_JPLEPH || pdp->iephe == SEFLG_SWIEPH) {
2600
2547
  niter = 1;
2601
- else /* SEFLG_MOSEPH or planet from osculating elements */
2548
+ } else { /* SEFLG_MOSEPH or planet from osculating elements */
2602
2549
  niter = 0;
2550
+ }
2603
2551
  if (iflag & SEFLG_SPEED) {
2604
2552
  /*
2605
2553
  * Apparent speed is influenced by the fact that dt changes with
@@ -2713,12 +2661,6 @@ static int app_pos_etc_plan(int ipli, int iplmoon, int32 iflag, char *serr)
2713
2661
  * with moshier or other ephemerides, subtraction of dt * speed
2714
2662
  * is sufficient (has been done in light-time iteration above)
2715
2663
  */
2716
- #if 0
2717
- for (i = 0; i <= 2; i++) {
2718
- xx[i] = pdp->x[i] - dt * pdp->x[i+3];/**/
2719
- xx[i+3] = pdp->x[i+3];
2720
- }
2721
- #endif
2722
2664
  /* if speed flag is true, we call swi_moshplan() for new t.
2723
2665
  * this does not increase position precision,
2724
2666
  * but speed precision, which becomes better than 0.01"/day.
@@ -2771,14 +2713,6 @@ static int app_pos_etc_plan(int ipli, int iplmoon, int32 iflag, char *serr)
2771
2713
  /* subtract earth */
2772
2714
  for (i = 0; i <= 5; i++)
2773
2715
  xx[i] -= xobs[i];
2774
- #if 0
2775
- /* earth and planets are barycentric with jpl and swisseph,
2776
- * but asteroids are heliocentric. therefore, add baryctr. sun */
2777
- if (ibody != IS_PLANET && !(iflag & SEFLG_MOSEPH)) {
2778
- for (i = 0; i <= 5; i++)
2779
- xx[i] += swed.pldat[SEI_SUNBARY].x[i];
2780
- }
2781
- #endif
2782
2716
  if ((iflag & SEFLG_TRUEPOS) == 0 ) {
2783
2717
  /*
2784
2718
  * Apparent speed is also influenced by
@@ -2818,11 +2752,6 @@ static int app_pos_etc_plan(int ipli, int iplmoon, int32 iflag, char *serr)
2818
2752
  if (!(iflag & SEFLG_SPEED))
2819
2753
  for (i = 3; i <= 5; i++)
2820
2754
  xx[i] = 0;
2821
- #if 0
2822
- swi_cartpol(xx, xx);
2823
- xx[0] -= 0.053 / 3600.0 * DEGTORAD;
2824
- swi_polcart(xx, xx);
2825
- #endif
2826
2755
  /* ICRS to J2000 */
2827
2756
  if (!(iflag & SEFLG_ICRS) && swi_get_denum(ipli, epheflag) >= 403) {
2828
2757
  swi_bias(xx, t, iflag, FALSE);
@@ -2963,6 +2892,7 @@ void CALL_CONV swe_set_sid_mode(int32 sid_mode, double t0, double ayan_t0)
2963
2892
  //sip->sid_mode &= ~(SE_SIDBIT_ECL_T0 | SE_SIDBIT_SSY_PLANE | SE_SIDBIT_USER_UT);
2964
2893
  sip->sid_mode = sid_mode;
2965
2894
  }
2895
+ // make sure that sid_mode is either SE_SIDM_USER or < SE_NSIDM_PREDEF
2966
2896
  if (sid_mode >= SE_NSIDM_PREDEF && sid_mode != SE_SIDM_USER)
2967
2897
  sip->sid_mode = sid_mode = SE_SIDM_FAGAN_BRADLEY;
2968
2898
  swed.ayana_is_set = TRUE;
@@ -2978,7 +2908,7 @@ void CALL_CONV swe_set_sid_mode(int32 sid_mode, double t0, double ayan_t0)
2978
2908
  sip->t0_is_UT = ayanamsa[sid_mode].t0_is_UT;
2979
2909
  }
2980
2910
  // test feature: ayanamsha using its original precession model
2981
- if ((sip->sid_mode & SE_SIDBIT_PREC_ORIG) && ayanamsa[sid_mode].prec_offset > 0) {
2911
+ if (sid_mode < SE_NSIDM_PREDEF && (sip->sid_mode & SE_SIDBIT_PREC_ORIG) && ayanamsa[sid_mode].prec_offset > 0) {
2982
2912
  swed.astro_models[SE_MODEL_PREC_LONGTERM] = ayanamsa[sid_mode].prec_offset;
2983
2913
  swed.astro_models[SE_MODEL_PREC_SHORTTERM] = ayanamsa[sid_mode].prec_offset;
2984
2914
  // add a corresponding nutation model
@@ -3009,6 +2939,7 @@ int32 CALL_CONV swe_get_ayanamsa_ex(double tjd_et, int32 iflag, double *daya, ch
3009
2939
  swi_nutation(tjd_et, iflag, nutp->nutlo);
3010
2940
  }
3011
2941
  *daya += nutp->nutlo[0] * RADTODEG;
2942
+ retval &= (~SEFLG_NONUT); // must remove flag which was added internally in swi_get_ayanamsa_ex()
3012
2943
  }
3013
2944
  return retval;
3014
2945
  }
@@ -3038,7 +2969,8 @@ static int get_aya_correction(int iflag, double *corr, char *serr) {
3038
2969
  return 0;
3039
2970
  if (sip->sid_mode & SE_SIDBIT_NO_PREC_OFFSET)
3040
2971
  return 0;
3041
- prec_offset = ayanamsa[sid_mode].prec_offset;
2972
+ if (sid_mode < SE_NSIDM_PREDEF)
2973
+ prec_offset = ayanamsa[sid_mode].prec_offset;
3042
2974
  if (prec_offset < 0) prec_offset = 0;
3043
2975
  if (prec_model == prec_offset)
3044
2976
  return 0;
@@ -3442,12 +3374,13 @@ static int app_pos_etc_plan_osc(int ipl, int ipli, int32 iflag, char *serr)
3442
3374
  struct epsilon *oe = &swed.oec2000;
3443
3375
  int32 epheflag = SEFLG_DEFAULTEPH;
3444
3376
  dt = dtsave_for_defl = 0; /* dummy assign to silence gcc */
3445
- if (iflag & SEFLG_MOSEPH)
3377
+ if (iflag & SEFLG_MOSEPH) {
3446
3378
  epheflag = SEFLG_MOSEPH;
3447
- else if (iflag & SEFLG_SWIEPH)
3379
+ } else if (iflag & SEFLG_SWIEPH) {
3448
3380
  epheflag = SEFLG_SWIEPH;
3449
- else if (iflag & SEFLG_JPLEPH)
3381
+ } else if (iflag & SEFLG_JPLEPH) {
3450
3382
  epheflag = SEFLG_JPLEPH;
3383
+ }
3451
3384
  /* the conversions will be done with xx[]. */
3452
3385
  for (i = 0; i <= 5; i++)
3453
3386
  xx[i] = pdp->x[i];
@@ -3660,39 +3593,42 @@ void swi_nutate(double *xx, int32 iflag, AS_BOOL backward)
3660
3593
  int i;
3661
3594
  double x[6], xv[6];
3662
3595
  for (i = 0; i <= 2; i++) {
3663
- if (backward)
3596
+ if (backward) {
3664
3597
  x[i] = xx[0] * swed.nut.matrix[i][0] +
3665
3598
  xx[1] * swed.nut.matrix[i][1] +
3666
3599
  xx[2] * swed.nut.matrix[i][2];
3667
- else
3600
+ } else {
3668
3601
  x[i] = xx[0] * swed.nut.matrix[0][i] +
3669
3602
  xx[1] * swed.nut.matrix[1][i] +
3670
3603
  xx[2] * swed.nut.matrix[2][i];
3604
+ }
3671
3605
  }
3672
3606
  if (iflag & SEFLG_SPEED) {
3673
3607
  /* correct speed:
3674
3608
  * first correct rotation */
3675
3609
  for (i = 0; i <= 2; i++) {
3676
- if (backward)
3610
+ if (backward) {
3677
3611
  x[i+3] = xx[3] * swed.nut.matrix[i][0] +
3678
3612
  xx[4] * swed.nut.matrix[i][1] +
3679
3613
  xx[5] * swed.nut.matrix[i][2];
3680
- else
3614
+ } else {
3681
3615
  x[i+3] = xx[3] * swed.nut.matrix[0][i] +
3682
3616
  xx[4] * swed.nut.matrix[1][i] +
3683
3617
  xx[5] * swed.nut.matrix[2][i];
3618
+ }
3684
3619
  }
3685
3620
  /* then apparent motion due to change of nutation during day.
3686
3621
  * this makes a difference of 0.01" */
3687
3622
  for (i = 0; i <= 2; i++) {
3688
- if (backward)
3623
+ if (backward) {
3689
3624
  xv[i] = xx[0] * swed.nutv.matrix[i][0] +
3690
3625
  xx[1] * swed.nutv.matrix[i][1] +
3691
3626
  xx[2] * swed.nutv.matrix[i][2];
3692
- else
3627
+ } else {
3693
3628
  xv[i] = xx[0] * swed.nutv.matrix[0][i] +
3694
3629
  xx[1] * swed.nutv.matrix[1][i] +
3695
3630
  xx[2] * swed.nutv.matrix[2][i];
3631
+ }
3696
3632
  /* new speed */
3697
3633
  xx[3+i] = x[3+i] + (x[i] - xv[i]) / NUT_SPEED_INTV;
3698
3634
  }
@@ -3825,12 +3761,13 @@ void swi_deflect_light(double *xx, double dt, int32 iflag)
3825
3761
  for (i = 0; i <= 2; i++)
3826
3762
  u[i] = xx[i];
3827
3763
  /* Eh = earthbary(t) - sunbary(t) = earthhel */
3828
- if (iephe == SEFLG_JPLEPH || iephe == SEFLG_SWIEPH)
3764
+ if (iephe == SEFLG_JPLEPH || iephe == SEFLG_SWIEPH) {
3829
3765
  for (i = 0; i <= 2; i++)
3830
3766
  e[i] = xearth[i] - psdp->x[i];
3831
- else
3767
+ } else {
3832
3768
  for (i = 0; i <= 2; i++)
3833
3769
  e[i] = xearth[i];
3770
+ }
3834
3771
  /* Q = planetbary(t-tau) - sunbary(t-tau) = 'planethel' */
3835
3772
  /* first compute sunbary(t-tau) for */
3836
3773
  if (iephe == SEFLG_JPLEPH || iephe == SEFLG_SWIEPH) {
@@ -3868,10 +3805,11 @@ void swi_deflect_light(double *xx, double dt, int32 iflag)
3868
3805
  */
3869
3806
  sina = sqrt(1 - ue * ue); /* sin(angle) between sun and planet */
3870
3807
  sin_sunr = SUN_RADIUS / re; /* sine of sun radius (= sun radius) */
3871
- if (sina < sin_sunr)
3808
+ if (sina < sin_sunr) {
3872
3809
  meff_fact = meff(sina / sin_sunr);
3873
- else
3810
+ } else {
3874
3811
  meff_fact = 1;
3812
+ }
3875
3813
  g1 = 2.0 * HELGRAVCONST * meff_fact / CLIGHT / CLIGHT / AUNIT / re;
3876
3814
  g2 = 1.0 + qe;
3877
3815
  /* compute deflected position */
@@ -3930,10 +3868,11 @@ void swi_deflect_light(double *xx, double dt, int32 iflag)
3930
3868
  qe = dot_prod(q,e);
3931
3869
  sina = sqrt(1 - ue * ue); /* sin(angle) between sun and planet */
3932
3870
  sin_sunr = SUN_RADIUS / re; /* sine of sun radius (= sun radius) */
3933
- if (sina < sin_sunr)
3871
+ if (sina < sin_sunr) {
3934
3872
  meff_fact = meff(sina / sin_sunr);
3935
- else
3873
+ } else {
3936
3874
  meff_fact = 1;
3875
+ }
3937
3876
  g1 = 2.0 * HELGRAVCONST * meff_fact / CLIGHT / CLIGHT / AUNIT / re;
3938
3877
  g2 = 1.0 + qe;
3939
3878
  for (i = 0; i <= 2; i++)
@@ -4001,12 +3940,13 @@ static int app_pos_etc_sun(int32 iflag, char *serr)
4001
3940
  /***************************************
4002
3941
  * true heliocentric position of earth *
4003
3942
  ***************************************/
4004
- if (pedp->iephe == SEFLG_MOSEPH || (iflag & SEFLG_BARYCTR))
3943
+ if (pedp->iephe == SEFLG_MOSEPH || (iflag & SEFLG_BARYCTR)) {
4005
3944
  for (i = 0; i <= 5; i++)
4006
3945
  xx[i] = xobs[i];
4007
- else
3946
+ } else {
4008
3947
  for (i = 0; i <= 5; i++)
4009
3948
  xx[i] = xobs[i] - psdp->x[i];
3949
+ }
4010
3950
  /*******************************
4011
3951
  * light-time *
4012
3952
  *******************************/
@@ -4063,10 +4003,11 @@ static int app_pos_etc_sun(int32 iflag, char *serr)
4063
4003
  /*
4064
4004
  retc = sweph(t, SEI_SUN, SEI_FILE_PLANET, iflag, NULL, NO_SAVE, xearth, serr);
4065
4005
  */
4066
- if ((iflag & SEFLG_HELCTR) || (iflag & SEFLG_BARYCTR))
4006
+ if ((iflag & SEFLG_HELCTR) || (iflag & SEFLG_BARYCTR)) {
4067
4007
  retc = sweplan(t, SEI_EARTH, SEI_FILE_PLANET, iflag, NO_SAVE, xearth, NULL, xsun, NULL, serr);
4068
- else
4008
+ } else {
4069
4009
  retc = sweph(t, SEI_SUNBARY, SEI_FILE_PLANET, iflag, NULL, NO_SAVE, xsun, serr);
4010
+ }
4070
4011
  break;
4071
4012
  case SEFLG_MOSEPH:
4072
4013
  if ((iflag & SEFLG_HELCTR) || (iflag & SEFLG_BARYCTR))
@@ -4370,11 +4311,7 @@ static int app_pos_etc_mean(int ipl, int32 iflag, char *serr)
4370
4311
  int i;
4371
4312
  int32 flg1, flg2;
4372
4313
  double xx[6], xxsv[6];
4373
- #if 0
4374
- struct node_data *pdp = &swed.nddat[ipl];
4375
- #else
4376
4314
  struct plan_data *pdp = &swed.nddat[ipl];
4377
- #endif
4378
4315
  struct epsilon *oe;
4379
4316
  /* if the same conversions have already been done for the same
4380
4317
  * date, then return */
@@ -4391,16 +4328,6 @@ static int app_pos_etc_mean(int ipl, int32 iflag, char *serr)
4391
4328
  swi_polcart_sp(xx, xx);
4392
4329
  swi_coortrf2(xx, xx, -swed.oec.seps, swed.oec.ceps);
4393
4330
  swi_coortrf2(xx+3, xx+3, -swed.oec.seps, swed.oec.ceps);
4394
- #if 0
4395
- /****************************************************
4396
- * light-time, this is only a few milliarcseconds *
4397
- ***************************************************/
4398
- if ((iflag & SEFLG_TRUEPOS) == 0) {
4399
- dt = pdp->x[3] * AUNIT / CLIGHT / 86400;
4400
- for (i = 0; i <= 2; i++)
4401
- xx[i] -= dt * xx[i+3];
4402
- }
4403
- #endif
4404
4331
  if (!(iflag & SEFLG_SPEED))
4405
4332
  for (i = 3; i <= 5; i++)
4406
4333
  xx[i] = 0;
@@ -4565,13 +4492,6 @@ static int get_new_segment(double tjd, int ipli, int ifno, char *serr)
4565
4492
  }
4566
4493
  }
4567
4494
  }
4568
- #if 0
4569
- if (ipli == SEI_SUNBARY) {
4570
- printf("%d, %x\n", fpos, fpos);
4571
- for (i = 0; i < pdp->ncoe; i++)
4572
- printf("%e, %e, %e\n", pdp->segp[i], pdp->segp[i+pdp->ncoe], pdp->segp[i+2*pdp->ncoe]);
4573
- }
4574
- #endif
4575
4495
  return(OK);
4576
4496
  return_error_gns:
4577
4497
  fclose(fdp->fptr);
@@ -4636,10 +4556,11 @@ static int read_const(int ifno, char *serr)
4636
4556
  }
4637
4557
  /* file name, without path */
4638
4558
  sp = strrchr(fdp->fnam, (int) *DIR_GLUE);
4639
- if (sp == NULL)
4559
+ if (sp == NULL) {
4640
4560
  sp = fdp->fnam;
4641
- else
4561
+ } else {
4642
4562
  sp++;
4563
+ }
4643
4564
  strcpy(s2, sp);
4644
4565
  /* to lower case */
4645
4566
  for (sp = s2; *sp != '\0'; sp++)
@@ -4697,23 +4618,6 @@ static int read_const(int ifno, char *serr)
4697
4618
  /* estimate the diameter from magnitude; assume albedo = 0.15 */
4698
4619
  swed.ast_diam = 1329/sqrt(0.15) * pow(10, -0.2 * swed.ast_H);
4699
4620
  }
4700
- #if 0
4701
- i = 5;
4702
- while (*(sp+i) != ' ')
4703
- i++;
4704
- j = i - 5;
4705
- strncpy(sastnam, sp, lastnam+i);
4706
- *(sastnam+lastnam+i) = 0;
4707
- /* save elements, they are required for swe_plan_pheno() */
4708
- strcpy(swed.astelem, s);
4709
- /* required for magnitude */
4710
- swed.ast_G = atof(sp + 40 + j);
4711
- swed.ast_H = atof(sp + 46 + j);
4712
- /* diameter in kilometers, not always given: */
4713
- strncpy(s2, sp+56+j, 7);
4714
- *(s2 + 7) = '\0';
4715
- swed.ast_diam = atof(s2);
4716
- #endif
4717
4621
  }
4718
4622
  /*************************************
4719
4623
  * one int32 for test of byte order *
@@ -4740,10 +4644,11 @@ static int read_const(int ifno, char *serr)
4740
4644
  * test first byte of test integer, which is highest if bigendian */
4741
4645
  c = (char *) &testendian;
4742
4646
  c2 = SEI_FILE_TEST_ENDIAN / 16777216L;
4743
- if (*c == c2)
4647
+ if (*c == c2) {
4744
4648
  fendian = SEI_FILE_BIGENDIAN;
4745
- else
4649
+ } else {
4746
4650
  fendian = SEI_FILE_LITENDIAN;
4651
+ }
4747
4652
  fdp->iflg = (int32) freord | fendian;
4748
4653
  /*************************************
4749
4654
  * length of file correct? *
@@ -4892,12 +4797,13 @@ fendian, ifno, serr);
4892
4797
  for (kpl = 0; kpl < fdp->npl; kpl++) {
4893
4798
  /* get SEI_ planet number */
4894
4799
  ipli = fdp->ipl[kpl];
4895
- if (ipli >= SE_AST_OFFSET)
4800
+ if (ipli >= SE_AST_OFFSET) {
4896
4801
  pdp = &swed.pldat[SEI_ANYBODY];
4897
- else if (ipli >= SE_PLMOON_OFFSET)
4802
+ } else if (ipli >= SE_PLMOON_OFFSET) {
4898
4803
  pdp = &swed.pldat[SEI_ANYBODY];
4899
- else
4804
+ } else {
4900
4805
  pdp = &swed.pldat[ipli];
4806
+ }
4901
4807
  pdp->ibdy = ipli;
4902
4808
  /* file position of planet's index */
4903
4809
  retc = do_fread((void *) &pdp->lndx0, 4, 1, 4, fp, SEI_CURR_FPOS,
@@ -5030,14 +4936,16 @@ static int do_fread(void *trg, int size, int count, int corrsize, FILE *fp, int3
5030
4936
  }
5031
4937
  for(i = 0; i < count; i++) {
5032
4938
  for (j = size-1; j >= 0; j--) {
5033
- if (freord)
4939
+ if (freord) {
5034
4940
  k = size-j-1;
5035
- else
4941
+ } else {
5036
4942
  k = j;
5037
- if (size != corrsize)
4943
+ }
4944
+ if (size != corrsize) {
5038
4945
  if ((fendian == SEI_FILE_BIGENDIAN && !freord) ||
5039
4946
  (fendian == SEI_FILE_LITENDIAN && freord))
5040
4947
  k += corrsize - size;
4948
+ }
5041
4949
  targ[i*corrsize+k] = space[i*size+j];
5042
4950
  }
5043
4951
  }
@@ -5264,11 +5172,7 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5264
5172
  int retc = ERR;
5265
5173
  int32 flg1, flg2;
5266
5174
  double daya[2];
5267
- #if 0
5268
- struct node_data *ndp, *ndnp, *ndap;
5269
- #else
5270
5175
  struct plan_data *ndp, *ndnp, *ndap;
5271
- #endif
5272
5176
  struct epsilon *oe;
5273
5177
  double speed_intv = NODE_CALC_INTV; /* to silence gcc warning */
5274
5178
  double a, b;
@@ -5281,14 +5185,16 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5281
5185
  #ifdef SID_TNODE_FROM_ECL_T0
5282
5186
  struct sid_data *sip = &swed.sidd;
5283
5187
  struct epsilon oectmp;
5188
+ #endif
5189
+ oe = &swed.oec;
5190
+ #ifdef SID_TNODE_FROM_ECL_T0
5284
5191
  if (iflag & SEFLG_SIDEREAL) {
5285
5192
  calc_epsilon(sip->t0, iflag, &oectmp);
5286
5193
  oe = &oectmp;
5287
- } else if (iflag & SEFLG_J2000)
5194
+ } else if (iflag & SEFLG_J2000) {
5288
5195
  oe = &swed.oec2000;
5289
- else
5196
+ }
5290
5197
  #endif
5291
- oe = &swed.oec;
5292
5198
  ndp = &swed.nddat[ipl];
5293
5199
  /* if elements have already been computed for this date, return
5294
5200
  * if speed flag has been turned on, recompute */
@@ -5324,19 +5230,21 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5324
5230
  /*********************************************
5325
5231
  * now three lunar positions with speeds *
5326
5232
  *********************************************/
5327
- if (iflag & SEFLG_MOSEPH)
5233
+ if (iflag & SEFLG_MOSEPH) {
5328
5234
  epheflag = SEFLG_MOSEPH;
5329
- else if (iflag & SEFLG_SWIEPH)
5235
+ } else if (iflag & SEFLG_SWIEPH) {
5330
5236
  epheflag = SEFLG_SWIEPH;
5331
- else if (iflag & SEFLG_JPLEPH)
5237
+ } else if (iflag & SEFLG_JPLEPH) {
5332
5238
  epheflag = SEFLG_JPLEPH;
5239
+ }
5333
5240
  /* there may be a moon of wrong ephemeris in save area
5334
5241
  * force new computation: */
5335
5242
  swed.pldat[SEI_MOON].teval = 0;
5336
- if (iflag & SEFLG_SPEED)
5243
+ if (iflag & SEFLG_SPEED) {
5337
5244
  istart = 0;
5338
- else
5245
+ } else {
5339
5246
  istart = 2;
5247
+ }
5340
5248
  if (serr != NULL)
5341
5249
  *serr = '\0';
5342
5250
  three_positions:
@@ -5344,12 +5252,13 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5344
5252
  case SEFLG_JPLEPH:
5345
5253
  speed_intv = NODE_CALC_INTV;
5346
5254
  for (i = istart; i <= 2; i++) {
5347
- if (i == 0)
5255
+ if (i == 0) {
5348
5256
  t = tjd - speed_intv;
5349
- else if (i == 1)
5257
+ } else if (i == 1) {
5350
5258
  t = tjd + speed_intv;
5351
- else
5259
+ } else {
5352
5260
  t = tjd;
5261
+ }
5353
5262
  xp = xpos[i];
5354
5263
  retc = jplplan(t, ipli, iflag, NO_SAVE, xp, NULL, NULL, serr);
5355
5264
  /* read error or corrupt file */
@@ -5390,17 +5299,15 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5390
5299
  }
5391
5300
  break;
5392
5301
  case SEFLG_SWIEPH:
5393
- #if 0
5394
- sweph_moon:
5395
- #endif
5396
5302
  speed_intv = NODE_CALC_INTV;
5397
5303
  for (i = istart; i <= 2; i++) {
5398
- if (i == 0)
5304
+ if (i == 0) {
5399
5305
  t = tjd - speed_intv;
5400
- else if (i == 1)
5306
+ } else if (i == 1) {
5401
5307
  t = tjd + speed_intv;
5402
- else
5308
+ } else {
5403
5309
  t = tjd;
5310
+ }
5404
5311
  retc = swemoon(t, iflag | SEFLG_SPEED, NO_SAVE, xpos[i], serr);/**/
5405
5312
  if (retc == ERR)
5406
5313
  return(ERR);
@@ -5426,30 +5333,20 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5426
5333
  }
5427
5334
  break;
5428
5335
  case SEFLG_MOSEPH:
5429
- #if 0
5430
- moshier_moon:
5431
- #endif
5432
5336
  /* with moshier moon, we need a greater speed_intv, because here the
5433
5337
  * node and apogee oscillate wildly within small intervals */
5434
5338
  speed_intv = NODE_CALC_INTV_MOSH;
5435
5339
  for (i = istart; i <= 2; i++) {
5436
- if (i == 0)
5340
+ if (i == 0) {
5437
5341
  t = tjd - speed_intv;
5438
- else if (i == 1)
5342
+ } else if (i == 1) {
5439
5343
  t = tjd + speed_intv;
5440
- else
5344
+ } else {
5441
5345
  t = tjd;
5346
+ }
5442
5347
  retc = swi_moshmoon(t, NO_SAVE, xpos[i], serr);/**/
5443
5348
  if (retc == ERR)
5444
5349
  return(retc);
5445
- #if 0
5446
- /* light-time-corrected moon for apparent node.
5447
- * can be neglected with moshier */
5448
- if ((iflag & SEFLG_TRUEPOS) == 0 && retc >= OK) {
5449
- dt = sqrt(square_sum(xpos[i])) * AUNIT / CLIGHT / 86400;
5450
- retc = swi_moshmoon(t-dt, NO_SAVE, xpos[i], serr);/**/
5451
- }
5452
- #endif
5453
5350
  /* precession and nutation etc. */
5454
5351
  retc = swi_plan_for_osc_elem(iflag|SEFLG_SPEED, t, xpos[i]); /* retc is always ok */
5455
5352
  }
@@ -5557,18 +5454,20 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5557
5454
  for (i = 0; i <= 2; i++) {
5558
5455
  /* apogee */
5559
5456
  ndap->x[i] = xxa[2][i];
5560
- if (iflag & SEFLG_SPEED)
5457
+ if (iflag & SEFLG_SPEED) {
5561
5458
  ndap->x[i+3] = (xxa[1][i] - xxa[0][i]) / speed_intv / 2;
5562
- else
5459
+ } else {
5563
5460
  ndap->x[i+3] = 0;
5461
+ }
5564
5462
  ndap->teval = tjd;
5565
5463
  ndap->iephe = epheflag;
5566
5464
  /* node */
5567
5465
  ndnp->x[i] = xx[2][i];
5568
- if (iflag & SEFLG_SPEED)
5466
+ if (iflag & SEFLG_SPEED) {
5569
5467
  ndnp->x[i+3] = (xx[1][i] - xx[0][i]) / speed_intv / 2;/**/
5570
- else
5468
+ } else {
5571
5469
  ndnp->x[i+3] = 0;
5470
+ }
5572
5471
  }
5573
5472
  /**********************************************************************
5574
5473
  * precession and nutation have already been taken into account
@@ -5579,10 +5478,11 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5579
5478
  **********************************************************************/
5580
5479
  for (j = 0; j <= 1; j++) {
5581
5480
  double x[6];
5582
- if (j == 0)
5481
+ if (j == 0) {
5583
5482
  ndp = &swed.nddat[SEI_TRUE_NODE];
5584
- else
5483
+ } else {
5585
5484
  ndp = &swed.nddat[SEI_OSCU_APOG];
5485
+ }
5586
5486
  memset((void *) ndp->xreturn, 0, 24 * sizeof(double));
5587
5487
  /* cartesian ecliptic */
5588
5488
  for (i = 0; i <= 5; i++)
@@ -5637,11 +5537,12 @@ static int lunar_osc_elem(double tjd, int ipl, int32 iflag, char *serr)
5637
5537
  swi_precess(x, tjd, iflag, J_TO_J2000);
5638
5538
  if (iflag & SEFLG_SPEED)
5639
5539
  swi_precess_speed(x, tjd, iflag, J_TO_J2000);
5640
- if (swed.sidd.sid_mode & SE_SIDBIT_ECL_T0)
5540
+ if (swed.sidd.sid_mode & SE_SIDBIT_ECL_T0) {
5641
5541
  swi_trop_ra2sid_lon(x, ndp->xreturn+6, ndp->xreturn+18, iflag);
5642
- /* project onto solar system equator */
5643
- else if (swed.sidd.sid_mode & SE_SIDBIT_SSY_PLANE)
5542
+ /* project onto solar system equator */
5543
+ } else if (swed.sidd.sid_mode & SE_SIDBIT_SSY_PLANE) {
5644
5544
  swi_trop_ra2sid_lon_sosy(x, ndp->xreturn+6, iflag);
5545
+ }
5645
5546
  /* to polar */
5646
5547
  swi_cartpol_sp(ndp->xreturn+6, ndp->xreturn);
5647
5548
  swi_cartpol_sp(ndp->xreturn+18, ndp->xreturn+12);
@@ -5772,11 +5673,12 @@ static int intp_apsides(double tjd, int ipl, int32 iflag, char *serr)
5772
5673
  swi_precess(x, tjd, iflag, J_TO_J2000);
5773
5674
  if (iflag & SEFLG_SPEED)
5774
5675
  swi_precess_speed(x, tjd, iflag, J_TO_J2000);
5775
- if (swed.sidd.sid_mode & SE_SIDBIT_ECL_T0)
5676
+ if (swed.sidd.sid_mode & SE_SIDBIT_ECL_T0) {
5776
5677
  swi_trop_ra2sid_lon(x, ndp->xreturn+6, ndp->xreturn+18, iflag);
5777
5678
  /* project onto solar system equator */
5778
- else if (swed.sidd.sid_mode & SE_SIDBIT_SSY_PLANE)
5679
+ } else if (swed.sidd.sid_mode & SE_SIDBIT_SSY_PLANE) {
5779
5680
  swi_trop_ra2sid_lon_sosy(x, ndp->xreturn+6, iflag);
5681
+ }
5780
5682
  /* to polar */
5781
5683
  swi_cartpol_sp(ndp->xreturn+6, ndp->xreturn);
5782
5684
  swi_cartpol_sp(ndp->xreturn+18, ndp->xreturn+12);
@@ -5884,17 +5786,18 @@ int swi_plan_for_osc_elem(int32 iflag, double tjd, double *xx)
5884
5786
  swi_precess(xx, tjd, iflag, J2000_TO_J);
5885
5787
  swi_precess(xx+3, tjd, iflag, J2000_TO_J);
5886
5788
  /* epsilon */
5887
- if (tjd == swed.oec.teps)
5789
+ if (tjd == swed.oec.teps) {
5888
5790
  oe = &swed.oec;
5889
- else if (tjd == J2000)
5791
+ } else if (tjd == J2000) {
5890
5792
  oe = &swed.oec2000;
5891
- else {
5793
+ } else {
5892
5794
  calc_epsilon(tjd, iflag, &oectmp);
5893
5795
  oe = &oectmp;
5894
5796
  }
5895
5797
  #ifdef SID_TNODE_FROM_ECL_T0
5896
- } else /* if SEFLG_J2000 */
5798
+ } else { /* if SEFLG_J2000 */
5897
5799
  oe = &swed.oec2000;
5800
+ }
5898
5801
  #endif
5899
5802
  /************************************************
5900
5803
  * nutation *
@@ -6064,10 +5967,11 @@ static double meff(double r)
6064
5967
  {
6065
5968
  double f, m;
6066
5969
  int i;
6067
- if (r <= 0)
5970
+ if (r <= 0) {
6068
5971
  return 0.0;
6069
- else if (r >= 1)
5972
+ } else if (r >= 1) {
6070
5973
  return 1.0;
5974
+ }
6071
5975
  for (i = 0; eff_arr[i].r > r; i++)
6072
5976
  ; /* empty body */
6073
5977
  f = (r - eff_arr[i-1].r) / (eff_arr[i].r - eff_arr[i-1].r);
@@ -6358,10 +6262,11 @@ int32 fixstar_cut_string(char *srecord, char *star, struct fixed_star *stardata,
6358
6262
  ****************************************/
6359
6263
  /* ra and de in degrees */
6360
6264
  ra = (ra_s / 3600.0 + ra_m / 60.0 + ra_h) * 15.0;
6361
- if (strchr(sde_d, '-') == NULL)
6265
+ if (strchr(sde_d, '-') == NULL) {
6362
6266
  de = de_s / 3600.0 + de_m / 60.0 + de_d;
6363
- else
6267
+ } else {
6364
6268
  de = -de_s / 3600.0 - de_m / 60.0 + de_d;
6269
+ }
6365
6270
  /* speed in ra and de, degrees per century */
6366
6271
  if (swed.is_old_starfile == TRUE) {
6367
6272
  ra_pm = ra_pm * 15 / 3600.0;
@@ -6372,10 +6277,11 @@ int32 fixstar_cut_string(char *srecord, char *star, struct fixed_star *stardata,
6372
6277
  parall /= 1000.0;
6373
6278
  }
6374
6279
  /* parallax, degrees */
6375
- if (parall > 1)
6280
+ if (parall > 1) {
6376
6281
  parall = (1 / parall / 3600.0);
6377
- else
6282
+ } else {
6378
6283
  parall /= 3600;
6284
+ }
6379
6285
  /* radial velocity in AU per century */
6380
6286
  radv *= KM_S_TO_AU_CTY;
6381
6287
  /*printf("ra=%.17f,de=%.17f,ma=%.17f,md=%.17f,pa=%.17f,rv=%.17f\n",ra,de,ra_pm,de_pm,parall,radv);*/
@@ -6550,10 +6456,11 @@ static int32 fixstar_calc_from_struct(struct fixed_star *stardata, double tjd, i
6550
6456
  ra_pm = stardata->ramot; de_pm = stardata->demot;
6551
6457
  radv = stardata->radvel; parall = stardata->parall;
6552
6458
  ra = stardata->ra; de = stardata->de;
6553
- if (epoch == 1950)
6459
+ if (epoch == 1950) {
6554
6460
  t= (tjd - B1950); /* days since 1950.0 */
6555
- else /* epoch == 2000 */
6461
+ } else { /* epoch == 2000 */
6556
6462
  t= (tjd - J2000); /* days since 2000.0 */
6463
+ }
6557
6464
  x[0] = ra;
6558
6465
  x[1] = de;
6559
6466
  x[2] = 1;
@@ -6927,12 +6834,6 @@ int32 CALL_CONV swe_fixstar2(char *star, double tjd, int32 iflag,
6927
6834
  trace_swe_fixstar(1, star, tjd, iflag, xx, serr);
6928
6835
  #endif /* TRACE */
6929
6836
  load_all_fixed_stars(serr); // loads stars unless loaded with an earlier call of function
6930
- #if 0
6931
- for (i = 0; i < swed.n_fixstars_records; i++) {
6932
- printf("%s, %s, %s, %f\n", swed.fixed_stars[i].skey, swed.fixed_stars[i].starname, swed.fixed_stars[i].starbayer, swed.fixed_stars[i].mag);
6933
- }
6934
- exit(0);
6935
- #endif
6936
6837
  retc = fixstar_format_search_name(star, sstar, serr);
6937
6838
  if (retc == ERR)
6938
6839
  goto return_err;
@@ -7153,10 +7054,11 @@ char *CALL_CONV swe_get_planet_name(int ipl, char *s)
7153
7054
  if (retc != ERR && retc != NOT_AVAILABLE) {
7154
7055
  strcpy(s, swed.fidat[SEI_FILE_ANY_AST].astnam);
7155
7056
  } else {
7156
- if (ipl > SE_AST_OFFSET)
7057
+ if (ipl > SE_AST_OFFSET) {
7157
7058
  sprintf(s, "%d: not found (asteroid)", ipl - SE_AST_OFFSET);
7158
- else
7059
+ } else {
7159
7060
  sprintf(s, "%d: not found (planetary moon)", ipl);
7061
+ }
7160
7062
  }
7161
7063
  }
7162
7064
  /* If there is a provisional designation only in ephemeris file,
@@ -7624,10 +7526,11 @@ static int32 swi_fixstar_load_record(char *star, char *srecord, char *sname, cha
7624
7526
  if (*s == '#') continue;
7625
7527
  line++;
7626
7528
  // search string is star number in sefstars.txt
7627
- if (star_nr == line)
7529
+ if (star_nr == line) {
7628
7530
  goto found;
7629
- else if (star_nr > 0)
7531
+ } else if (star_nr > 0) {
7630
7532
  continue;
7533
+ }
7631
7534
  // invalid line without comma
7632
7535
  if ((sp = strchr(s, ',')) == NULL) {
7633
7536
  if (serr != NULL) {
@@ -7637,15 +7540,17 @@ static int32 swi_fixstar_load_record(char *star, char *srecord, char *sname, cha
7637
7540
  }
7638
7541
  // search string is Bayer or Flamsteed designation
7639
7542
  if (is_bayer) {
7640
- if (strncmp(sp, sstar, cmplen) == 0)
7543
+ if (strncmp(sp, sstar, cmplen) == 0) {
7641
7544
  goto found;
7642
- else
7545
+ } else {
7643
7546
  continue;
7547
+ }
7644
7548
  }
7645
7549
  // search string is traditional name
7646
7550
  *sp = '\0'; /* cut off after first field to get star name, ',' -> '\0' */
7647
- //strncpy(fstar, s, SWI_STAR_LENGTH);
7648
- slen = swi_strnlen(s, SE_MAX_STNAME);
7551
+ //slen = swi_strnlen(s, SE_MAX_STNAME);
7552
+ slen = strlen(s);
7553
+ if (slen > SE_MAX_STNAME) slen = SE_MAX_STNAME;
7649
7554
  memcpy(fstar, s, slen);
7650
7555
  fstar[slen] = '\0'; /* force termination */
7651
7556
  *sp = ','; /* add comma again */
@@ -7719,8 +7624,8 @@ static int32 swi_fixstar_calc_from_record(char *srecord, double tjd, int32 iflag
7719
7624
  int32 epheflag, iflgsave;
7720
7625
  // char s[AS_MAXCH];
7721
7626
  struct epsilon *oe = &swed.oec2000;
7722
- iflag |= SEFLG_SPEED; /* we need this in order to work correctly */
7723
7627
  iflgsave = iflag;
7628
+ iflag |= SEFLG_SPEED; /* we need this in order to work correctly */
7724
7629
  if (serr != NULL)
7725
7630
  *serr = '\0';
7726
7631
  iflag = plaus_iflag(iflag, -1, tjd, serr);
@@ -7760,10 +7665,11 @@ static int32 swi_fixstar_calc_from_record(char *srecord, double tjd, int32 iflag
7760
7665
  ra_pm = stardata.ramot; de_pm = stardata.demot;
7761
7666
  radv = stardata.radvel; parall = stardata.parall;
7762
7667
  ra = stardata.ra; de = stardata.de;
7763
- if (epoch == 1950)
7668
+ if (epoch == 1950) {
7764
7669
  t= (tjd - B1950); /* days since 1950.0 */
7765
- else /* epoch == 2000 */
7670
+ } else { /* epoch == 2000 */
7766
7671
  t= (tjd - J2000); /* days since 2000.0 */
7672
+ }
7767
7673
  x[0] = ra;
7768
7674
  x[1] = de;
7769
7675
  x[2] = 1;
@@ -7964,13 +7870,13 @@ if ((0)) {
7964
7870
  for (i = 0; i <= 5; i++)
7965
7871
  xx[i] = x[i];
7966
7872
  if (!(iflgsave & SEFLG_SPEED)) {
7873
+ iflag = iflag & ~SEFLG_SPEED;
7967
7874
  for (i = 3; i <= 5; i++)
7968
7875
  xx[i] = 0;
7969
7876
  }
7970
7877
  /* if no ephemeris has been specified, do not return chosen ephemeris */
7971
7878
  if ((iflgsave & SEFLG_EPHMASK) == 0)
7972
7879
  iflag = iflag & ~SEFLG_DEFAULTEPH;
7973
- iflag = iflag & ~SEFLG_SPEED;
7974
7880
  return iflag;
7975
7881
  }
7976
7882