Cppcheck - HTML report - digiKam-master-rev-960d3ce42d

# Cppcheck report - digiKam-master-rev-960d3ce42d: ../../core/utilities/geolocation/engine/astro/eclsolar.cpp

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269
     270
     271
     272
     273
     274
     275
     276
     277
     278
     279
     280
     281
     282
     283
     284
     285
     286
     287
     288
     289
     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
     300
     301
     302
     303
     304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
     744
     745
     746
     747
     748
     749
     750
     751
     752
     753
     754
     755
     756
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
     783
     784
     785
     786
     787
     788
     789
     790
     791
     792
     793
     794
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
     866
     867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
     883
     884
     885
     886
     887
     888
     889
     890
     891
     892
     893
     894
     895
     896
     897
     898
     899
     900
     901
     902
     903
     904
     905
     906
     907
     908
     909
     910
     911
     912
     913
     914
     915
     916
     917
     918
     919
     920
     921
     922
     923
     924
     925
     926
     927
     928
     929
     930
     931
     932
     933
     934
     935
     936
     937
     938
     939
     940
     941
     942
     943
     944
     945
     946
     947
     948
     949
     950
     951
     952
     953
     954
     955
     956
     957
     958
     959
     960
     961
     962
     963
     964
     965
     966
     967
     968
     969
     970
     971
     972
     973
     974
     975
     976
     977
     978
     979
     980
     981
     982
     983
     984
     985
     986
     987
     988
     989
     990
     991
     992
     993
     994
     995
     996
     997
     998
     999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    1424
    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    1452
    1453
    1454
    1455
    1456
    1457
    1458
    1459
    1460
    1461
    1462
    1463
    1464
    1465
    1466
    1467
    1468
    1469
    1470
    1471
    1472
    1473
    1474
    1475
    1476
    1477
    1478
    1479
    1480
    1481
    1482
    1483
    1484
    1485
    1486
    1487
    1488
    1489
    1490
    1491
    1492
    1493
    1494
    1495
    1496
    1497
    1498
    1499
    1500
    1501
    1502
    1503
    1504
    1505
    1506
    1507
    1508
    1509
    1510
    1511
    1512
    1513
    1514
    1515
    1516
    1517
    1518
    1519
    1520
    1521
    1522
    1523
    1524
    1525
    1526
    1527
    1528
    1529
    1530
    1531
    1532
    1533
    1534
    1535
    1536
    1537
    1538
    1539
    1540
    1541
    1542
    1543
    1544
    1545
    1546
    1547
    1548
    1549
    1550
    1551
    1552
    1553
    1554
    1555
    1556
    1557
    1558
    1559
    1560
    1561
    1562
    1563
    1564
    1565
    1566
    1567
    1568
    1569
    1570
    1571
    1572
    1573
    1574
    1575
    1576
    1577
    1578
    1579
    1580
    1581
    1582
    1583
    1584
    1585
    1586
    1587
    1588
    1589
    1590
    1591
    1592
    1593
    1594
    1595
    1596
    1597
    1598
    1599
    1600
    1601
    1602
    1603
    1604
    1605
    1606
    1607
    1608
    1609
    1610
    1611
    1612
    1613
    1614
    1615
    1616
    1617
    1618
    1619
    1620
    1621
    1622
    1623
    1624
    1625
    1626
    1627
    1628
    1629
    1630
    1631
    1632
    1633
    1634
    1635
    1636
    1637
    1638
    1639
    1640
    1641
    1642
    1643
    1644
    1645
    1646
    1647
    1648
    1649
    1650
    1651
    1652
    1653
    1654
    1655
    1656
    1657
    1658
    1659
    1660
    1661
    1662
    1663
    1664
    1665
    1666
    1667
    1668
    1669
    1670
    1671
    1672
    1673
    1674
    1675
    1676
    1677
    1678
    1679
    1680
    1681
    1682
    1683
    1684
    1685
    1686
    1687
    1688
    1689
    1690
    1691
    1692
    1693
    1694
    1695
    1696
    1697
    1698
    1699
    1700
    1701
    1702
    1703
    1704
    1705
    1706
    1707
    1708
    1709
    1710
    1711
    1712
    1713
    1714
    1715
    1716
    1717
    1718
    1719
    1720
    1721
    1722
    1723
    1724
    1725
    1726
    1727
    1728
    1729
    1730
    1731
    1732
    1733
    1734
    1735
    1736
    1737
    1738
    1739
    1740
    1741
    1742
    1743
    1744
    1745
    1746
    1747
    1748
    1749
    1750
    1751
    1752
    1753
    1754
    1755
    1756
    1757
    1758
    1759
    1760
    1761
    1762
    1763
    1764
    1765
    1766
    1767
    1768
    1769
    1770
    1771
    1772
    1773
    1774
    1775
    1776
    1777
    1778
    1779
    1780
    1781
    1782
    1783
    1784
    1785
    1786
    1787
    1788
    1789
    1790
    1791
    1792
    1793
    1794
    1795
    1796
    1797
    1798
    1799
    1800
    1801
    1802
    1803
    1804
    1805
    1806
    1807
    1808
    1809
    1810
    1811
    1812
    1813
    1814
    1815
    1816
    1817
    1818
    1819
    1820
    1821
    1822
    1823
    1824
    1825
    1826
    1827
    1828
    1829
    1830
    1831
    1832
    1833
    1834
    1835
    1836
    1837
    1838
    1839
    1840
    1841
    1842
    1843
    1844
    1845
    1846
    1847
    1848
    1849
    1850
    1851
    1852
    1853
    1854
    1855
    1856
    1857
    1858
    1859
    1860
    1861
    1862
    1863
    1864
    1865
    1866
    1867
    1868
    1869
    1870
    1871
    1872
    1873
    1874
    1875
    1876
    1877
    1878
    1879
    1880
    1881
    1882
    1883
    1884
    1885
    1886
    1887
    1888
    1889
    1890
    1891
    1892
    1893
    1894
    1895
    1896
    1897
    1898
    1899
    1900
    1901
    1902
    1903
    1904
    1905
    1906
    1907
    1908
    1909
    1910
    1911
    1912
    1913
    1914
    1915
    1916
    1917
    1918
    1919
    1920
    1921
    1922
    1923
    1924
    1925
    1926
    1927
    1928
    1929
    1930
    1931
    1932
    1933
    1934
    1935
    1936
    1937
    1938
    1939
    1940
    1941
    1942
    1943
    1944
    1945
    1946
    1947
    1948
    1949
    1950
    1951
    1952
    1953
    1954
    1955
    1956
    1957
    1958
    1959
    1960
    1961
    1962
    1963
    1964
    1965
    1966
    1967
    1968
    1969
    1970
    1971
    1972
    1973
    1974
    1975
    1976
    1977
    1978
    1979
    1980
    1981
    1982
    1983
    1984
    1985
    1986
    1987
    1988
    1989
    1990
    1991
    1992
    1993
    1994
    1995
    1996
    1997
    1998
    1999
    2000
    2001
    2002
    2003
    2004
    2005
    2006
    2007
    2008
    2009
    2010
    2011
    2012
    2013
    2014
    2015
    2016
    2017
    2018
    2019
    2020
    2021
    2022
    2023
    2024
    2025
    2026
    2027
    2028
    2029
    2030
    2031
    2032
    2033
    2034
    2035
    2036
    2037
    2038
    2039
    2040
    2041
    2042
    2043
    2044
    2045
    2046
    2047
    2048
    2049
    2050
    2051
    2052
    2053
    2054
    2055
    2056
    2057
    2058
    2059
    2060
    2061
    2062
    2063
    2064
    2065
    2066
    2067
    2068
    2069
    2070
    2071
    2072
    2073
    2074
    2075
    2076
    2077
    2078
    2079
    2080
    2081
    2082
    2083
    2084
    2085
    2086
    2087
    2088
    2089
    2090
    2091
    2092
    2093
    2094
    2095
    2096
    2097
    2098
    2099
    2100
    2101
    2102
    2103
    2104
    2105
    2106
    2107
    2108
    2109
    2110
    2111
    2112
    2113
    2114
    2115
    2116
    2117
    2118
    2119
    2120
    2121
    2122
    2123
    2124
    2125
    2126
    2127
    2128
    2129
    2130
    2131
    2132
    2133
    2134
    2135
    2136
    2137
    2138
    2139
    2140
    2141
    2142
    2143
    2144
    2145
    2146
    2147
    2148
    2149
    2150
    2151
    2152
    2153
    2154
    2155
    2156
    2157
    2158
    2159
    2160
    2161
    2162
    2163
    2164
    2165
    2166
    2167
    2168
    2169
    2170
    2171
    2172
    2173
    2174
    2175
    2176
    2177
    2178
    2179
    2180
    2181
    2182
    2183
    2184
    2185
    2186
    2187
    2188
    2189
    2190
    2191
    2192
    2193
    2194
    2195
    2196
    2197
    2198
    2199
    2200
    2201
    2202
    2203
    2204
    2205
    2206
    2207
    2208
    2209
    2210
    2211
    2212
    2213
    2214
    2215
    2216
    2217
    2218
    2219
    2220
    2221
    2222
    2223
    2224
    2225
    2226
    2227
    2228
    2229
    2230
    2231
    2232
    2233
    2234
    2235
    2236
    2237
    2238
    2239
    2240
    2241
    2242
    2243
    2244
    2245
    2246
    2247
    2248
    2249
    2250
    2251
    2252
    2253
    2254
    2255
    2256
    2257
    2258
    2259
    2260
    2261
    2262
    2263
    2264
    2265
    2266
    2267
    2268
    2269
    2270
    2271
    2272
    2273
    2274
    2275
    2276
    2277
    2278
    2279
    2280
    2281
    2282
    2283
    2284
    2285
    2286
    2287
    2288
    2289
    2290
    2291
    2292
    2293
    2294
    2295
    2296
    2297
    2298
    2299
    2300
    2301
    2302
    2303
    2304
    2305
    2306
    2307
    2308
    2309
    2310
    2311
    2312
    2313
    2314
    2315
    2316
    2317
    2318
    2319
    2320
    2321
    2322
    2323
    2324
    2325
    2326
    2327
    2328
    2329
    2330
    2331
    2332
    2333
    2334
    2335
    2336
    2337
    2338
    2339
    2340
    2341
    2342
    2343
    2344
    2345
    2346
    2347
    2348
    2349
    2350
    2351
    2352
    2353
    2354
    2355
    2356
    2357
    2358
    2359
    2360
    2361
    2362
    2363
    2364
    2365
    2366
    2367
    2368
    2369
    2370
    2371
    2372
    2373
    2374
    2375
    2376
    2377
    2378
    2379
    2380
    2381
    2382
    2383
    2384
    2385
    2386
    2387
    2388
    2389
    2390
    2391
    2392
    2393
    2394
    2395
    2396
    2397
    2398
    2399
    2400
    2401
    2402
    2403
    2404
    2405
    2406
    2407
    2408
    2409
    2410
    2411
    2412
    2413
    2414
    2415
    2416
    2417
    2418
    2419
    2420
    2421
    2422
    2423
    2424
    2425
    2426
    2427
    2428
    2429
    2430
    2431
    2432
    2433
    2434
    2435
    2436
    2437
    2438
    2439
    2440
    2441
    2442
    2443
    2444
    2445
    2446
    2447
    2448
    2449
    2450
    2451
    2452
    2453
    2454
    2455
    2456
    2457
    2458
    2459
    2460
    2461
    2462
    2463
    2464
    2465
    2466
    2467
    2468
    2469
    2470
    2471
    2472
    2473
    2474
    2475
    2476
    2477
    2478
    2479
    2480
    2481
    2482
    2483
    2484
    2485
    2486
    2487
    2488
    2489
    2490
    2491
    2492
    2493
    2494
    2495
    2496
    2497
    2498
    2499
    2500
    2501
    2502
    2503
    2504
    2505
    2506
    2507
    2508
    2509
    2510
    2511
    2512
    2513
    2514
    2515
    2516
    2517
    2518
    2519
    2520
    2521
    2522
    2523
    2524
    2525
    2526
    2527
    2528
    2529
    2530
    2531
    2532
    2533
    2534
    2535
    2536
    2537
    2538
    2539
    2540
    2541
    2542
    2543
    2544
    2545
    2546
    2547
    2548
    2549
    2550
    2551
    2552
    2553
    2554
    2555
    2556
    2557
    2558
    2559
    2560
    2561
    2562
    2563
    2564
    2565
    2566
    2567
    2568
    2569
    2570
    2571
    2572
    2573
    2574
    2575
    2576
    2577
    2578
    2579
    2580
    2581
    2582
    2583
    2584
    2585
    2586
    2587
    2588
    2589
    2590
    2591
    2592
    2593
    2594
    2595
    2596
    2597
    2598
    2599
    2600
    2601
    2602
    2603
    2604
    2605
    2606
    2607
    2608
    2609
    2610
    2611
    2612
    2613
    2614
    2615
    2616
    2617
    2618
    2619
    2620
    2621
    2622
    2623
    2624
    2625
    2626
    2627
    2628
    2629
    2630
    2631
    2632
    2633
    2634
    2635
    2636
    2637
    2638
    2639
    2640
    2641
    2642
    2643
    2644
    2645
    2646
    2647
    2648
    2649
    2650
    2651
    2652
    2653
    2654
    2655
    2656
    2657
    2658
    2659
    2660
    2661
    2662
    2663
    2664
    2665
    2666
    2667
    2668
    2669
    2670
    2671
    2672
    2673
    2674
    2675
    2676
    2677
    2678
    2679
    2680
    2681
    2682
    2683
    2684
    2685
    2686
    2687
    2688
    2689
    2690
    2691
    2692
    2693
    2694
    2695
    2696
    2697
    2698
    2699
    2700
    2701
    2702
    2703
    2704
    2705
    2706
    2707
    2708
    2709
    2710
    2711
    2712
    2713
    2714
    2715
    2716
    2717
    2718
    2719
    2720
    2721
    2722
    2723
    2724
    2725
    2726
    2727
    2728
    2729
    2730
    2731
    2732
    2733
    2734
    2735
    2736
    2737
    2738
    2739
    2740
    2741
    2742
    2743
    2744
    2745
    2746
    2747
    2748
    2749
    2750
    2751
    2752
    2753
    2754
    2755
    2756
    2757
    2758
    2759
    2760
    2761
    2762
    2763
    2764
    2765
    2766
    2767
    2768
    2769
    2770
    2771
    2772
    2773
    2774
    2775
    2776
    2777
    2778
    2779
    2780
    2781
    2782
    2783
    2784
    2785
    2786
    2787
    2788
    2789
    2790
    2791
    2792
    2793
    2794
    2795
    2796
    2797
    2798
    2799
    2800
    2801
    2802
    2803
    2804
    2805
    2806
    2807
    2808
    2809
    2810
    2811
    2812
    2813
    2814
    2815
    2816
    2817
    2818
    2819
    2820
    2821
    2822
    2823
    2824
    2825
    2826
    2827
    2828
    2829
    2830
    2831
    2832
    2833
    2834
    2835
    2836
    2837
    2838
    2839
    2840
    2841
    2842
    2843
    2844
    2845
    2846
    2847
    2848
    2849
    2850
    2851
    2852
    2853
    2854
    2855
    2856
    2857
    2858
    2859
    2860
    2861
    2862
    2863
    2864
    2865
    2866
    2867
    2868
    2869
    2870
    2871
    2872
    2873
    2874
    2875
    2876
    2877
    2878
    2879
    2880
    2881
    2882
    2883
    2884
    2885
    2886
    2887
    2888
    2889
    2890
    2891
    2892
    2893
    2894
    2895
    2896
    2897
    2898
    2899
    2900
    2901
    2902
    2903
    2904
    2905
    2906
    2907
    2908
    2909
    2910
    2911
    2912
    2913
    2914
    2915
    2916
    2917
    2918
    2919
    2920
    2921
    2922
    2923
    2924
    2925
    2926
    2927
    2928
    2929
    2930
    2931
    2932
    2933
    2934
    2935
    2936
    2937
    2938
    2939
    2940
    2941
    2942
    2943
    2944
    2945
    2946
    2947
    2948
    2949
    2950
    2951
    2952
    2953
    2954
    2955
    2956
    2957
    2958
    2959
    2960
    2961
    2962
    2963
    2964
    2965
    2966
    2967
    2968
    2969
    2970
    2971
    2972
    2973
    2974
    2975
    2976
    2977
    2978
    2979
    2980
    2981
    2982
    2983
    2984
    2985
    2986
    2987
    2988
    2989
    2990
    2991
    2992
    2993
    2994
    2995
    2996
    2997
    2998
    2999
    3000
    3001
    3002
    3003
    3004
    3005
    3006
    3007
    3008
    3009
    3010
    3011
    3012
    3013
    3014
    3015
    3016
    3017
    3018
    3019
    3020
    3021
    3022
    3023
    3024
    3025
    3026
    3027
    3028
    3029
    3030
    3031
    3032
    3033
    3034
    3035
    3036
    3037
    3038
    3039
    3040
    3041
    3042
    3043
    3044
    3045
    3046
    3047
    3048
    3049
    3050
    3051
    3052
    3053
    3054
    3055
    3056
    3057
    3058
    3059
    3060
    3061
    3062
    3063
    3064
    3065
    3066
    3067
    3068
    3069
    3070
    3071
    3072
    3073
    3074
    3075
    3076
    3077
    3078
    3079
    3080
    3081
    3082
    3083
    3084
    3085
    3086
    3087
    3088
    3089
    3090
    3091
    3092
    3093
    3094
    3095
    3096
    3097
    3098
    3099
    3100
    3101
    3102
    3103
    3104
    3105
    3106
    3107
    3108
    3109
    3110
    3111
    3112
    3113
    3114
    3115
    3116
    3117
    3118
    3119
    3120
    3121
    3122
    3123
    3124
    3125
    3126
    3127
    3128
    3129
    3130
    3131
    3132
    3133
    3134
    3135
    3136
    3137
    3138
    3139
    3140
    3141
    3142
    3143
    3144
    3145
    3146
    3147
    3148
    3149
    3150
    3151
    3152
    3153
    3154
    3155
    3156
    3157
    3158
    3159
    3160
    3161
    3162
    3163
    3164
    3165
    3166
    3167
    3168
    3169
    3170
    3171
    3172
    3173
    3174
    3175
    3176
    3177
    3178
    3179
    3180
    3181
    3182
    3183
    3184
    3185
    3186
    3187
    3188
    3189
    3190
    3191
    3192
    3193
    3194
    3195
    3196
    3197
    3198
    3199
    3200
    3201
    3202
    3203
    3204
    3205
    3206
    3207
    3208
    3209
    3210
    3211
    3212
    3213
    3214
    3215
    3216
    3217
    3218
    3219
    3220
    3221
    3222
    3223
    3224
    3225
    3226
    3227
    3228
    3229
    3230
    3231
    3232
    3233
    3234
    3235
    3236
    3237
    3238
    3239
    3240
    3241
    3242
    3243
    3244
    3245
    3246
    3247
    3248
    3249
    3250
    3251
    3252
    3253
    3254
    3255
    3256
    3257
    3258
    3259
    3260
    3261
    3262
    3263
    3264
    3265
    3266
    3267
    3268
    3269
    3270
    3271
    3272
    3273
    3274
    3275
    3276
    3277
    3278
    3279
    3280
    3281
    3282
    3283
    3284
    3285
    3286
    3287
    3288
    3289
    3290
    3291
    3292
    3293
    3294
    3295
    3296
    3297
    3298
    3299
    3300
    3301
    3302
    3303
    3304
    3305
    3306
    3307
    3308
    3309
    3310
    3311
    3312
    3313
    3314
    3315
    3316
    3317
    3318
    3319
    3320
    3321
    3322
    3323
    3324
    3325
    3326
    3327
    3328
    3329
    3330
    3331
    3332
    3333
    3334
    3335
    3336
    3337
    3338
    3339
    3340
    3341
    3342
    3343
    3344
    3345
    3346
    3347
    3348
    3349
    3350
    3351
    3352
    3353
    3354
    3355
    3356
    3357
    3358
    3359
    3360
    3361
    3362
    3363
    3364
    3365
    3366
    3367
    3368
    3369
    3370
    3371
    3372
    3373
    3374
    3375
    3376
    3377
    3378
    3379
    3380
    3381
    3382
    3383
    3384
    3385
    3386
    3387
    3388
    3389
    3390
    3391
    3392
    3393
    3394
    3395
    3396
    3397
    3398
    3399
    3400
    3401
    3402
    3403
    3404
    3405
    3406
    3407
    3408
    3409
    3410
    3411
    3412
    3413
    3414
    3415
    3416
    3417
    3418
    3419
    3420
    3421
    3422
    3423
    3424
    3425
    3426
    3427
    3428
    3429
    3430
    3431
    3432
    3433
    3434
    3435
    3436
    3437
    3438
    3439
    3440
    3441
    3442
    3443
    3444
    3445
    3446
    3447
    3448
    3449
    3450
    3451
    3452
    3453
    3454
    3455
    3456
    3457
    3458
    3459
    3460
    3461
    3462
    3463
    3464
    3465
    3466
    3467
    3468
    3469
    3470
    3471
    3472
    3473
    3474
    3475
    3476
    3477
    3478
    3479
    3480
    3481
    3482
    3483
    3484
    3485
    3486
    3487
    3488
    3489
    3490
    3491
    3492
    3493
    3494
    3495
    3496
    3497
    3498
    3499
    3500
    3501
    3502
    3503
    3504
    3505
    3506
    3507
    3508
    3509
    3510
    3511
    3512
    3513
    3514
    3515
    3516
    3517
    3518
    3519
    3520
    3521
    3522
    3523
    3524
    3525
    3526
    3527
    3528
    3529
    3530
    3531
    3532
    3533
    3534
    3535
    3536
    3537
    3538
    3539
    3540
    3541
    3542
    3543
    3544
    3545
    3546
    3547
    3548
    3549
    3550
    3551
    3552
    3553
    3554
    3555
    3556
    3557
    3558
    3559
    3560
    3561
    3562
    3563
    3564
    3565
    3566
    3567
    3568
    3569
    3570
    3571
    3572
    3573
    3574
    3575
    3576
    3577
    3578
    3579
    3580
    3581
    3582
    3583
    3584
    3585
    3586
    3587
    3588
    3589
    3590
    3591
    3592
    3593
    3594
    3595
    3596
    3597
    3598
    3599
    3600
    3601
    3602
    3603
    3604
    3605
    3606
    3607
    3608
    3609
    3610
    3611
    3612
    3613
    3614
    3615
    3616
    3617
    3618
    3619
    3620
    3621
    3622
    3623
    3624
    3625
    3626
    3627
    3628
    3629
    3630
    3631
    3632
    3633
    3634
    3635
    3636
    3637
    3638
    3639
    3640
    3641
    3642
    3643
    3644
    3645
    3646
    3647
    3648
    3649
    3650
    3651
    3652
    3653
    3654
    3655
    3656
    3657
    3658
    3659
    3660
    3661
    3662
    3663
    3664
    3665
    3666
    3667
    3668
    3669
    3670
    3671
    3672
    3673
    3674
    3675
    3676
    3677
    3678
    3679
    3680
    3681
    3682
    3683
    3684
    3685
    3686
    3687
    3688
    3689
    3690
    3691
    3692
    3693
    3694
    3695
    3696
    3697
    3698
    3699
    3700
    3701
    3702
    3703
    3704
    3705
    3706
    3707
    3708
    3709
    3710
    3711
    3712
    3713
    3714
    3715
    3716
    3717
    3718
    3719
    3720
    3721
    3722
    3723
    3724
    3725
    3726
    3727
    3728
    3729
    3730
    3731
    3732
    3733
    3734
    3735
    3736
    3737
    3738
    3739
    3740
    3741
    3742
    3743
    3744
    3745
    3746
    3747
    3748
    3749
    3750
    3751
    3752
    3753
    3754
    3755
    3756
    3757
    3758
    3759
    3760
    3761
    3762
    3763
    3764
    3765
    3766
    3767
    3768
    3769
    3770
    3771
    3772
    3773
    3774
    3775
    3776
    3777
    3778
    3779
    3780
    3781
    3782
    3783
    3784
    3785
    3786
    3787
    3788
    3789
    3790
    3791
    3792
    3793
    3794
    3795
    3796
    3797
    3798
    3799
    3800
    3801
    3802
    3803
    3804
    3805
    3806
    3807
    3808
    3809
    3810
    3811
    3812
    3813
    3814
    3815
    3816
    3817
    3818
    3819
    3820
    3821
    3822
    3823
    3824
    3825
    3826
    3827
    3828
    3829
    3830
    3831
    3832
    3833
    3834
    3835
    3836
    3837
    3838
    3839
    3840
    3841
    3842
    3843
    3844
    3845
    3846
    3847
    3848
    3849
    3850
    3851
    3852
    3853
    3854
    3855
    3856
    3857
    3858
    3859
    3860
    3861
    3862
    3863
    3864
    3865
    3866
    3867
    3868
    3869
    3870
    3871
    3872
    3873
    3874
    3875
    3876
    3877
    3878
    3879
    3880
    3881
    3882
    3883
    3884
    3885
    3886
    3887
    3888
    3889
    3890
    3891
    3892
    3893
    3894
    3895
    3896
    3897
    3898
    3899
    3900
    3901
    3902
    3903
    3904
    3905
    3906
    3907
    3908
    3909
    3910
    3911
    3912
    3913
    3914
    3915
    3916
    3917
    3918
    3919
    3920
    3921
    3922
    3923
    3924
    3925
    3926
    3927
    3928
    3929
    3930
    3931
    3932
    3933
    3934
    3935
    3936
    3937
    3938
    3939
    3940
    3941
    3942
    3943
    3944
    3945
    3946
    3947
    3948
    3949
    3950
    3951
    3952
    3953
    3954
    3955
    3956
    3957
    3958
    3959
    3960
    3961
    3962
    3963
    3964
    3965
    3966
    3967
    3968
    3969
    3970
    3971
    3972
    3973
    3974
    3975
    3976
    3977
    3978
    3979
    3980
    3981
    3982
    3983
    3984
    3985
    3986
    3987
    3988
    3989
    3990
    3991
    3992
    3993
    3994
    3995
    3996
    3997
    3998
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2023-05-15
     * Description : geolocation engine based on Marble.
     *               (c) 2007-2022 Marble Team
     *               https://invent.kde.org/education/marble/-/raw/master/data/credits_authors.html
     *
     * SPDX-FileCopyrightText: 2023-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: LGPL-2.1-or-later
     *
     * ============================================================ */

    /***************************************************************************
    * Calculate Solar Eclipses                                                 *
    *                                                                          *
    * The algorithm for the phases of the Moon and of the dates for the        *
    * equinoxes and solstices of the Sun as well as the dates of eclipses      *
    * are based on Jean Meeus "Astronomical Formulae for Calculators",         *
    * Willman-Bell, Inc., Richmond, Virginia, 1988                             *
    *                                                                          *
    * The algorithm for the Modified Julian Date and the calendar as well as   *
    * the detailed eclipse calculations are based on                           *
    * O.Montebruck and T.Pfleger, "Astronomy with a PC",                       *
    * Springer Verlag, Berlin, Heidelberg, New York, 1989                      *
    * and on the                                                               *
    * "Explanatory Supplement to the Astronomical Almanac"                     *
    * University Science Books, Mill Valley, CA, 1992                          *
    ***************************************************************************/

    #include "eclsolar.h"

    // C++ includes

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>

    using namespace std;

    // Local includes

    #include "astrolib.h"

    #if defined(Q_CC_CLANG)
    #   pragma clang diagnostic push
    #   pragma clang diagnostic ignored "-Wdeprecated-declarations"
    #endif

    namespace Marble
    {

    const double degrad = M_PI / 180.0;

    // ################ Solar Eclipse Class ####################

    EclSolar::EclSolar()
    {
        esinit();
    }

    EclSolar::~EclSolar()
    {
    }

    double EclSolar::atan23(double y, double x)
    {
        /* redefine atan2 so that it doesn't crash when both x and y are 0 */
        double result;

        if ((x == 0) && (y == 0))
        {
            result = 0;
        }

        else
        {
            result = atan2(y, x);
        }

        return result;
    }

    void EclSolar::esinit()
    {
        // initialize eclipse data

        eb_start_called = false;
        eb_moonph_called = false;
        eb_lunecl = true;
        eb_lunactive = false;
        eb_local_called = false;

        eb_day = 1;
        eb_month = 1;
        eb_year = 2012;
        eb_hour = 0;
        eb_minute = 0;
        eb_second = 0;
        eb_tzone = 0;
        eb_del_auto = 1;
        DefTime();
        eb_time = 0;
        eb_del_tdut = DefTdUt(eb_year);
        eb_geolat = 0;
        eb_geolong = 0;
        eb_geoheight = 0;
        eb_lstcall = 0;
        eb_locecl = 0;
        eb_lastyear = -9999;
        eb_numecl = 0;
        eb_lasttz = eb_tzone;
        eb_lastdlt = eb_del_tdut;
        eb_cstep = 1.0;
        eb_cmxlat = 0;
        eb_cmxlng = 0;
        eb_penangle = 1.0;
        eb_penamode = 0;
    }

    void EclSolar::DefTime()   // Get System Time and Date
    {
        time_t tt;
        int hh, mm, ss;
        double jd, hr;

        tt = time(NULL);
        jd = 40587.0 + tt / 86400.0; // seconds since 1-JAN-1970

        caldat(jd, hh, mm, ss, hr);
        eb_year = ss;
        eb_month = mm;
        eb_day = hh;

        dms(hr, hh, mm, jd);
        eb_hour = hh;
        eb_minute = mm;
        eb_second = int(jd);

        if (eb_del_auto)
        {
            eb_del_tdut = DefTdUt(eb_year);
        }
    };

    int EclSolar::getYear() const
    {
        return eb_year;
    }

    void EclSolar::putYear(int yr)
    {
        eb_start_called = false;
        eb_moonph_called = false;
        eb_local_called = false;
        eb_lunactive = false;

        eb_year = yr;

        if (eb_del_auto)
        {
            eb_del_tdut = DefTdUt(eb_year);
        }

        moonph();

    }

    int EclSolar::getNumberEclYear()
    {
        // RETURN the number of eclipses of the currently selected year

        int j, k;

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        if (eb_lunecl)
        {
            return eb_numecl;
        }

        k = 0;

        for (j = 0; j < eb_numecl; j++)
        {
            if (eb_phase[j] > 0)
            {
                k++;
            }
        }

        return k;
    }
    void EclSolar::setLunarEcl(bool lecl)
    {
        // if lecl = true include lunar eclipses in addition to solar ones
        if (lecl)
        {
            eb_lunecl = true;
        }

        else
        {
            eb_lunecl = false;
        }

        eb_start_called = false;
        eb_local_called = false;
    }

    void EclSolar::setStepWidth(double s)
    {
        // set the step width (in minutes) used for calculations
        if (s < 0.01)
        {
            eb_cstep = 0.01;
        }

        else
        {
            eb_cstep = s;
        }
    }

    void EclSolar::setTimezone(double d)
    {
        // set the timezone to d (hours difference from UTC) for I/O
        eb_tzone = d;
    }

    void EclSolar::setDeltaTAI_UTC(double d)
    {
        // c is the difference between TAI and UTC according to the IERS
        // we have to add 32.184 sec to get to the difference TT - UT
        // which is used in the calculations here

        eb_del_tdut = d + 32.184;
        eb_del_auto = 0;
    }

    void EclSolar::setAutoTAI_UTC()
    {
        // set the difference between TAI and UTC according to the IERS
        eb_del_auto = true;
        eb_del_tdut = DefTdUt(eb_year);
    }

    void EclSolar::setLocalPos(double lat, double lng, double hgt)
    {
        // set the geographic coordinates for the position of the local info
        // latitude lat, longitude lng in decimal degrees
        // height hgt in meters

        eb_geolat = lat;
        eb_geolong = lng;
        eb_geoheight = hgt;

        eb_local_called = false;
    }

    int EclSolar::getLocalVisibility(double& mjd_start, double& mjd_stop)
    {
        // local start and stop times (MJD) for eclipse
        // RETURN 0 if not locally visible

        char wbuf[700];

        if (!eb_local_called)
        {
            getLocalDetails(wbuf);
        }

        mjd_start = eb_lcb1;
        mjd_stop = eb_lce1;

        return eb_lccnt;
    }

    int EclSolar::getLocalTotal(double& mjd_start, double& mjd_stop)
    {
        // local start and stop times (MJD) for totality/annularity
        // RETURN 0 if not locally visible

        int k, j;
        char wbuf[700];

        if (!eb_local_called)
        {
            getLocalDetails(wbuf);
        }

        mjd_start = 0;
        mjd_stop = 0;

        if (eb_lccnt == 0)
        {
            return 0;
        }

        k = 0;

        if (eb_lunactive)
        {
            for (j = 0; j < eb_nphase; j++)
            {
                if ((k == 0) && (eb_spp[j] > 3))
                {
                    mjd_start = eb_spt[j];
                    mjd_stop  = eb_ept[j];
                    k = 1;
                }
            }

            if (mjd_start < eb_lcb1)
            {
                mjd_start = eb_lcb1;
            }

            if (mjd_start > eb_lce1)
            {
                k = 0;
            }

            if (mjd_stop > eb_lce1)
            {
                mjd_stop = eb_lce1;
            }

            if (mjd_stop < eb_lcb1)
            {
                k = 0;
            }

            eb_ltotb = mjd_start;
            eb_ltote = mjd_stop;

        }

        else
        {
            k = eb_lccnt;
        }

        mjd_start = eb_ltotb;
        mjd_stop = eb_ltote;

        return k;
    }

    int EclSolar::getLocalMax(double& mjdmax, double& magmax, double& elmax)
    {
        // get local (solar) eclipse maximum
        // mjdmax : Modified Julian Date of maximum eclipse
        // magmax : maximum (local) magnitude of eclipse
        // elmax : local Sun elevation at maximum

        // RETURN : 0 if eclipse not visible

        int k;

        mjdmax = 0;
        magmax = 0;
        elmax = 0;

        if (eb_lunactive)
        {
            return 0;
        }

        k = getLocalVisibility(mjdmax, magmax);

        if (k != 0)
        {
            mjdmax = eb_jdmaxps;
            magmax = eb_maxps;
            elmax = eb_maxelv;
        }

        return k;
    }

    int EclSolar::getPenumbra(double& mjd_start, double& mjd_stop)
    {
        // start and stop times (MJD) for penumbral eclipse of Moon
        // RETURN 0 if no lunar eclipse

        int j, k;

        if (!eb_start_called)
        {
            eclStart();
        }

        mjd_start = 0;
        mjd_stop = 0;

        if (!eb_lunactive)
        {
            return 0;
        }

        if (eb_nphase <= 0)
        {
            return 0;
        }

        k = 0 ;

        for (j = 0; j < eb_nphase; j++)
        {
            if (eb_spp[j] == 1)
            {
                mjd_start = eb_spt[j];
                mjd_stop  = eb_ept[j];
                k = 1;
            }
        }

        return k;
    }

    int EclSolar::getPartial(double& mjd_start, double& mjd_stop)
    {
        // (global) start and stop times (MJD) for partial phase
        // RETURN 0 if no lunar eclipse

        int j, k;

        if (!eb_start_called)
        {
            eclStart();
        }

        mjd_start = 0;
        mjd_stop = 0;

        if (eb_nphase <= 0)
        {
            return 0;
        }

        k = 0;

        if (eb_lunactive)
        {
            for (j = 0; j < eb_nphase; j++)
            {
                if ((k == 0) && (eb_spp[j] == 3))
                {
                    mjd_start = eb_spt[j];
                    mjd_stop  = eb_ept[j];
                    k = 1;
                }
            }
        }

        else
        {
            for (j = 0; j < eb_nphase; j++)
            {
                if ((k == 0) && (eb_spp[j] == 1))
                {
                    mjd_start = eb_spt[j];
                    mjd_stop  = eb_ept[j];
                    k = 1;
                }
            }
        }

        return k;

    }

    int EclSolar::getTotal(double& mjd_start, double& mjd_stop)
    {
        // (global) start and stop times (MJD) for totality/annularity
        // RETURN 0 if no lunar eclipse

        int j, k;

        if (!eb_start_called)
        {
            eclStart();
        }

        mjd_start = 0;
        mjd_stop = 0;

        if (eb_nphase <= 0)
        {
            return 0;
        }

        k = 0;

        if (eb_lunactive)
        {
            for (j = 0; j < eb_nphase; j++)
            {
                if ((k == 0) && (eb_spp[j] > 3))
                {
                    mjd_start = eb_spt[j];
                    mjd_stop  = eb_ept[j];
                    k = 1;
                }
            }
        }

        else
        {
            for (j = 0; j < eb_nphase; j++)
            {
                if ((k == 0) && (eb_spp[j] > 1))
                {
                    mjd_start = eb_spt[j];
                    mjd_stop  = eb_ept[j];
                    k = 1;
                }
            }
        }

        return k;

    }

    void EclSolar::setCurrentMJD(int year, int month, int day, int hour, int min, double sec)
    {
        // set the (MJD-) time currently used for calculations to year, month, day, hour, min, sec
        // corrected for timezone

        double jd;

        jd = ddd(hour, min, sec) - eb_tzone;
        jd = mjd(day, month, year, jd);

        eb_lastjd = jd;

    }

    void EclSolar::getDatefromMJD(double mjd, int& year, int& month, int& day, int& hour, int& min, double& sec) const
    {
        // convert times given in Modified Julian Date (MJD) into conventional date and time
        // correct for timezone

        double magn;

        caldat((mjd + eb_tzone / 24.0), day, month, year, magn);
        dms(magn, hour, min, sec);

        if (sec > 30.0)
        {
            min++;
        }

        if (min > 59)
        {
            hour++;
            min = 0;
        };

    }

    //---------------------- getEclYearInfo--------------------------------

    void EclSolar::getEclYearInfo(char* wbuf)
    {
        // output the eclipse dates in buffer wbuf accurate to the minute.

        char dts[15];
        char outbuf[127];
        char magbuf[30];
        int j, p, kecl;

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        sprintf(wbuf, "Solar Eclipses for %4i  UTC +%4.1f", eb_year, eb_tzone);

        kecl = 1;

        for (j = 0; j < eb_numecl; j++)
        {
            snprintf(dts, sizeof(dts), "%1i : ", kecl);
            strcpy(outbuf, dts);
            dtmstr((eb_eclmjd[j] + eb_tzone / 24.0), dts);
            dts[12] = '\0';
            strcat(outbuf, dts);
            p = eb_phase[j];

            switch (p)
            {
                case 1:
                    strcat(outbuf, "\t Partial Sun");
                    snprintf(magbuf, sizeof(magbuf), "  (magnitude:%5.2f)", eb_magnitude[j]);
                    strcat(outbuf, magbuf);
                    break;

                case 2:
                    strcat(outbuf, "\t non-central Annular Sun");
                    break;

                case 4:
                    strcat(outbuf, "\t Annular Sun");
                    break;

                case 3:
                    strcat(outbuf, "\t non-central Total Sun");
                    break;

                case 5:
                    strcat(outbuf, "\t Total Sun");
                    break;

                case 6:
                    strcat(outbuf, "\t Annular/Total Sun");
                    break;

                case -1:
                case -2:
                    strcat(outbuf, "\t Penumbral Moon");
                    snprintf(magbuf, sizeof(magbuf), "  (magnitude:%5.2f)", eb_magnitude[j]);
                    strcat(outbuf, magbuf);
                    break;

                case -3:
                    strcat(outbuf, "\t Partial Moon");
                    snprintf(magbuf, sizeof(magbuf), "  (magnitude:%5.2f)", eb_magnitude[j]);
                    strcat(outbuf, magbuf);
                    break;

                case -4:
                    strcat(outbuf, "\t Total Moon");
                    snprintf(magbuf, sizeof(magbuf), "  (magnitude:%5.2f)", eb_magnitude[j]);
                    strcat(outbuf, magbuf);
                    break;
            };

            if ((p > 0) || eb_lunecl)  // solar eclipse only or also lunar eclipses
            {
                strcat(wbuf, "\n");
                strcat(wbuf, outbuf);
                kecl++;
            };
        }
    }

    int EclSolar::getEclYearInfo(int k, int& yr, int& month, int& day,
                                 int& hour, int& min, double& sec, double& tzone, double& magn)
    {
        /* output the eclipse info for k-th eclipse

           year, month, day, hour, minutes, seconds and timezone
           magn = magnitude of eclipse

         RETURN: phase of eclipse. 0 if no k-th eclipse

            1: Partial Sun
            2: non-central Annular Sun
            3: non-central Total Sun
            4: Annular Sun
            5: Total Sun
            6: Annular/Total Sun

           -1, -2: Penumbral Moon
           -3: Partial Moon
           -4: Total Moon

        */
        bool nls;
        int j, p, kecl;

        nls = true;

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        if (k < 1)
        {
            k = eb_eclselect;  // select current eclipse as default
            nls = false;
        };

        if ((k < 1) && (k > eb_numecl))
        {
            return 0;
        }

        p = k - 1;

        if (nls && (!eb_lunecl))
        {
            kecl = 0;
            p = -1;

            for (j = 0; j < eb_numecl; j++)
            {
                if (eb_phase[j] > 0)
                {
                    kecl++;

                    if (kecl == k)
                    {
                        p = j;
                    }
                };
            };
        };

        if (p < 0)
        {
            return 0;
        }

        j = p;

        // convert MJD into corresponding date and time
        caldat((eb_eclmjd[j] + eb_tzone / 24.0), day, month, yr, magn);
        dms(magn, hour, min, sec);

        if (sec > 30.0)
        {
            min++;
        }

        if (min > 59)
        {
            hour++;
            min = 0;
        };

        magn = eb_magnitude[j];

        tzone = eb_tzone;

        return eb_phase[j];
    }

    int EclSolar::getEclTxt(int k, char* jtxt)
    {
        // get the data / kind of eclipse info for the j-th eclipse
        // and place it into jtxt

        // RETURN : the phase of the eclipse. 0 if no j-th eclipse

        int p, j;
        char dts[13];

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        if (k < 1)
        {
            k = eb_eclselect;    // select current eclipse as default
        }

        if ((k < 1) && (k > eb_numecl))
        {
            return 0;
        }

        j = k - 1;

        sprintf(jtxt, "%2i :", (j + 1));
        snprintf(dts, sizeof(dts), "%5i ", eb_year);
        strcat(jtxt, dts);
        dtmstr((eb_eclmjd[j] + eb_tzone / 24.0), dts);
        dts[6] = '\0';
        strcat(jtxt, dts);

        p = eb_phase[j];

        switch (p)
        {
            case 1:
                strcat(jtxt, " Par.Sun");
                break;

            case 2:
                strcat(jtxt, " non-centr.Ann.Sun");
                break;

            case 4:
                strcat(jtxt, " Ann.Sun");
                break;

            case 3:
                strcat(jtxt, " non-centr.Tot.Sun");
                break;

            case 5:
                strcat(jtxt, " Tot.Sun");
                break;

            case 6:
                strcat(jtxt, " Ann/Tot.");
                break;

            case -1:
            case -2:
                strcat(jtxt, " Pen.Moon");
                break;

            case -3:
                strcat(jtxt, " Par.Moon");
                break;

            case -4:
                strcat(jtxt, " Tot.Moon");
                break;
        };

        return p;
    }

    // ----------------------------- Select Eclipse -------------------------

    void EclSolar::putEclSelect(int es)
    {
        // store the number of the eclipse selected for detailed calculations
        int k, j;

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        k = 0;

        eb_lunactive = false;
        eb_eclselect = 1;

        for (j = 0; j < eb_numecl; j++)
        {
            if ((eb_phase[j] > 0) || eb_lunecl)  // only solar eclipses if set
            {
                k++;

                if (k == es)
                {
                    eb_eclselect = j + 1;

                    if (eb_phase[j] < 0)
                    {
                        eb_lunactive = true;
                    }
                };
            };
        };

        eb_start_called = false;
    }

    void EclSolar::nextEcl()
    {
        // select the next eclipse for detailed calculations
        int k, j, es;

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        eb_start_called = false;

        k = eb_eclselect + 1;

        if (k > eb_numecl)
        {
            k = eb_year + 1;
            putYear(k);
            k = 1;
            putEclSelect(k);

            return;
        };

        if (eb_lunecl)  // easier when lunar eclipses are included
        {
            putEclSelect(k);

            return;
        };

        eb_lunactive = false;

        es = eb_eclselect;

        k = 0;

        for (j = es; j < eb_numecl; j++)
        {
            if ((k == 0) && (eb_phase[j] > 0))
            {
                k = j + 1;
            }
        };

        if (k > 0)
        {
            eb_eclselect = k;
            return;
        }

        k = eb_year + 1;
        putYear(k);
        es = 1;
        putEclSelect(es);

    }

    void EclSolar::previousEcl()
    {
        // select the previous eclipse for detailed calculations
        int k, j, es;

        if (!eb_moonph_called)
        {
            moonph();    // calculate the eclipses of the year
        }

        eb_start_called = false;

        k = eb_eclselect - 1;

        if (k <= 0)
        {
            k = eb_year - 1;
            putYear(k);
            k = eb_numecl;
        };

        if (eb_lunecl)  // easier when lunar eclipses are included
        {
            putEclSelect(k);

            return;
        };

        eb_lunactive = false;

        es = 0;

        k--;

        for (j = k; j >= 0; j--)
        {
            if ((es == 0) && (eb_phase[j] > 0))
            {
                es = j + 1;
            }
        };

        if (es > 0)
        {
            eb_eclselect = es;
        }

        else
        {
            putEclSelect(0);    // this case should never happen!
        }

    }

    double EclSolar::getLastMJD() const
    {
        // RETURN the MJD last used in calculations

        return eb_lastjd;
    }

    void EclSolar::setPenumbraAngle(double pa, int mode)
    {
        /* set the Penumbra Angle
           if mode == 0 the angle will be set to pa-times the maximum angle
           (pa < 1.0). Set pa = 1 for the normal penumbra boundaries

           if mode == 1 the angle will be set such that the penumbra line
           marks magnitude pa. pa == 0 will mark normal penumbra boundaries

           if mode == 2 the angle will be set such that the penumbra line
           marks the obscuration pa. pa == 0.5 will mean that 50% of the Sun's
           disk is covered by the Moon etc.
        */

        double mjd, dpn1, dpn2, pan1, pan2;<--- Shadow variable
        double mag, m1, m2, s, ps;
        int j;
        Vec3 ubm, ube;
        Eclipse eclp;

        if (mode == 0)
        {
            eb_penangle = pa;
            eb_penamode = 0;

            if (pa > 1.0)
            {
                eb_penangle = 1.0;
            }

            if (pa < 0)
            {
                eb_penangle = 1.0;
            }

            return;
        }

        if (!eb_start_called)
        {
            eclStart();
        }

        if (mode == 1)
        {
            eb_penamode = 1;
            mjd = eb_eclmjd[eb_eclselect - 1];
            eclp.umbra(mjd, eb_del_tdut, ubm, ube, dpn1, pan1);
            eclp.penumd(mjd, eb_del_tdut, ubm, ube, dpn2, pan2);

            if (dpn2 > 0)
            {
                eb_penangle = fabs(pa);

                if (eb_penangle > 1.0)
                {
                    eb_penangle = 1.0;
                }

                eb_penangle = 1.0 - eb_penangle * (1.0 + dpn1 / dpn2);
            }

            else
            {
                eb_penangle = 1.0;
            }

            return;
        }

        if (mode == 2)
        {
            eb_penamode = 2;
            mjd = eb_eclmjd[eb_eclselect - 1];
            eclp.umbra(mjd, eb_del_tdut, ubm, ube, dpn1, pan1);
            eclp.penumd(mjd, eb_del_tdut, ubm, ube, dpn2, pan2);

            ps = pa;  // find the magnitude that corresponds to the obscuration

            if (ps > 1.0)
            {
                ps = 1.0;
            }

            if (ps < 0)
            {
                ps = 0;
            }

            for (j = 1; j < 11; j++)
            {
                mag = double(j) * 0.1;
                s = sunObscure(dpn2, dpn1, mag);

                if (s >= ps)
                {
                    break;
                }
            }

            m1 = mag - 0.1;
            m2 = mag;

            for (j = 0; j < 8; j++) // 8 iterations should be plenty
            {
                mag = (m2 + m1) * 0.5;
                s = sunObscure(dpn2, dpn1, mag);

                if (s > ps)
                {
                    m2 = mag;
                }

                else
                {
                    m1 = mag;
                }
            }

            if (dpn2 > 0)
            {
                eb_penangle = fabs(mag);

                if (eb_penangle > 1.0)
                {
                    eb_penangle = 1.0;
                }

                eb_penangle = 1.0 - eb_penangle * (1.0 + dpn1 / dpn2);
            }

            else
            {
                eb_penangle = 1.0;
            }

            return;
        }

        eb_penamode = 0;
        eb_penangle = 1.0;

    }

    // -------- auxiliary functions --------------------------------
    void EclSolar::GetMonth(int mm, char* mchr)
    {
        // get three letter designation of month
        // mm is the number of the month
        // mchr is a char[4] array to receive the three letters of the month

        switch (mm)
        {
            case 1 :
                strcpy(mchr, "JAN");
                break;

            case 2 :
                strcpy(mchr, "FEB");
                break;

            case 3 :
                strcpy(mchr, "MAR");
                break;

            case 4 :
                strcpy(mchr, "APR");
                break;

            case 5 :
                strcpy(mchr, "MAY");
                break;

            case 6 :
                strcpy(mchr, "JUN");
                break;

            case 7 :
                strcpy(mchr, "JUL");
                break;

            case 8 :
                strcpy(mchr, "AUG");
                break;

            case 9 :
                strcpy(mchr, "SEP");
                break;

            case 10 :
                strcpy(mchr, "OCT");
                break;

            case 11 :
                strcpy(mchr, "NOV");
                break;

            case 12 :
                strcpy(mchr, "DEC");
                break;

            default:
                strcpy(mchr, "ERR");
        };
    }

    double EclSolar::phmjd(double yearf, double phase, double tdut,
                           int& eph, double& ejd, double& emag)
    /*
      Calculate the Modified Julian Date of the occurrence of the specified
      phase of the Moon and check for possible eclipses.
      yearf : year.fraction of date close to the Moon phase
      phase : 0    for New Moon,
              0.25 for First Quarter,
              0.5  for Full Moon,
              0.75 for Last Quarter.
      tdut = TDT - UT in sec

      RETURN: the MJD of the lunar phase event

      OUTPUT:
      eph : phase of the eclipse on that date
            0 = no eclipse, 1 = partial solar eclipse,
            2 = non-central annular, 3 = non-central total
            4 = annular solar, 5 = total solar,
            6 = annular/total solar, -1 =partial penumbral lunar,
            -2 = total penumbral lunar, -3 = partial umbral lunar,
            -4 = total umbral lunar
      ejd : Modified Julian Date of the maximum of the eclipse (if any)
      emag : magnitude of the eclipse (if any)
    */
    {
        double tt, jd, k, m, p, f;
        double s, c, gam, u;
        int tst;
        Eclipse eclp;

        // preliminary (modified) Julian Date
        k = floor((yearf - 1900.0) * 12.3685) + phase;
        tt = k / 1236.85;
        jd = 166.56 + (132.87 - 0.009173 * tt) * tt;
        jd = 15020.25933 + 29.53058868 * k
             + (0.0001178 - 0.000000155 * tt) * tt * tt
             + 0.00033 * sin(degrad * jd);

        eph = 0;   // assume no eclipse

        // Sun's mean anomaly
        m = degrad * (359.2242 + 29.10535608 * k
                      - (0.0000333 - 0.00000347 * tt) * tt * tt);
        // Moon's mean anomaly
        p = degrad * (306.0253 + 385.81691808 * k
                      + (0.0107306 + 0.00001236 * tt) * tt * tt);
        // 2* Moon's argument of latitude
        f = 2.0 * degrad * (21.2964 + 390.67050646 * k
                            - (0.0016528 - 0.00000239 * tt) * tt * tt);

        if ((phase == 0) || (phase == 0.5))  // for Full and New Moon
        {
            k = (0.1734 - 0.000393 * tt) * sin(m)
                + 0.0021 * sin(2.0 * m)
                - 0.4068 * sin(p)
                + 0.0161 * sin(2.0 * p)
                - 0.0004 * sin(3.0 * p)
                + 0.0104 * sin(f)
                - 0.0051 * sin(m + p)
                - 0.0074 * sin(m - p)
                + 0.0004 * sin(f + m)
                - 0.0004 * sin(f - m)
                - 0.0006 * sin(f + p)
                + 0.0010 * sin(f - p)
                + 0.0005 * sin(m + 2.0 * p);

            // check for possible eclipses.
            f = f / 2.0;

            if (fabs(sin(f)) <= 0.36)   // eclipses are possible
            {
                ejd = (0.1734 - 0.000393 * tt) * sin(m)
                      + 0.0021 * sin(2.0 * m)
                      - 0.4068 * sin(p)
                      + 0.0161 * sin(2.0 * p)
                      - 0.0051 * sin(m + p)
                      - 0.0074 * sin(m - p)
                      - 0.0104 * sin(2.0 * f);
                ejd += jd;

                s = 5.19595 - 0.0048 * cos(m) + 0.0020 * cos(2.0 * m) - 0.3283 * cos(p)
                    - 0.0060 * cos(m + p) + 0.0041 * cos(m - p);

                c = 0.2070 * sin(m) + 0.0024 * sin(2.0 * m) - 0.0390 * sin(p)
                    + 0.0115 * sin(2.0 * p) - 0.0073 * sin(m + p)
                    - 0.0067 * sin(m - p) + 0.0117 * sin(2.0 * f);

                gam = s * sin(f) + c * cos(f);
                u = 0.0059 + 0.0046 * cos(m) - 0.0182 * cos(p)
                    + 0.0004 * cos(2.0 * p) - 0.0005 * cos(m + p);

                if (phase == 0)          // check for solar eclipse
                {
                    if (fabs(gam) <= (1.5432 + u))
                    {
                        if (fabs(gam) < 0.9972)    // central eclipse
                        {
                            emag = 1.0;

                            if (u < 0)
                            {
                                eph = 5;    // total eclipse
                            }

                            else
                            {
                                if (u > 0.0047)
                                {
                                    eph = 4;    // annular eclipse
                                }

                                else
                                {
                                    if (u < (0.00464 * cos(asin(gam))))
                                    {
                                        eph = 6;    // annular/total
                                    }

                                    else
                                    {
                                        eph = 4;    // annular
                                    }
                                }; // end if u>0.0047
                            }; // end if u<0
                        }  // end if fabs(gam) if

                        else      // non-central eclipse
                        {
                            eph = 1;   // assume partial eclipse

                            if (fabs(gam) < (0.9972 + fabs(u))) // non-central annular or total
                            {
                                eph = eclp.solar(ejd, tdut, s, c);
                                emag = 1.0;
                            };

                            if (eph == 1)     // get magnitude of partial eclipse
                            {
                                emag = (1.5432 + u - fabs(gam)) / (0.5460 + 2.0 * u);
                            }

                            if (emag < 0.025) // check if low mag eclipse is OK
                            {
                                eph = 0;
                                u = 1.0 / 720; // 2 min steps

                                for (int j = 0; j < 288; j++)
                                {
                                    tt = ejd - 0.2 + double(j) * u;
                                    tst = eclp.solar(tt, tdut, s, c);

                                    if (tst > 0)
                                    {
                                        eph = tst;
                                    }
                                };
                            };
                        }
                    }
                } // end of solar eclipse check

                if (phase == 0.5)        // check for lunar eclipse
                {
                    c = (1.5572 + u - fabs(gam)) / 0.5450;

                    if (c > 0)
                    {
                        s = (1.0129 - u - fabs(gam)) / 0.5450;

                        if (s < 0)   // penumbral eclipse
                        {
                            emag = c;

                            if (emag > 1)
                            {
                                eph = -2;
                            }

                            else
                            {
                                eph = -1;
                            }
                        }

                        else         // umbral eclipse
                        {
                            emag = s;

                            if (emag > 1)
                            {
                                eph = -4;
                            }

                            else
                            {
                                eph = -3;
                            }
                        }
                    }
                }
            }
        };

        if ((phase == 0.25) || (phase == 0.75)) // for first and last quarter
        {
            k = (0.1721 - 0.0004 * tt) * sin(m)
                + 0.0021 * sin(2.0 * m)
                - 0.6280 * sin(p)
                + 0.0089 * sin(2.0 * p)
                - 0.0004 * sin(3.0 * p)
                + 0.0079 * sin(f)
                - 0.0119 * sin(m + p)
                - 0.0047 * sin(m - p)
                + 0.0003 * sin(f + m)
                - 0.0004 * sin(f - m)
                - 0.0006 * sin(f + p)
                + 0.0021 * sin(f - p)
                + 0.0003 * sin(m + 2.0 * p)
                + 0.0004 * sin(m - 2.0 * p)
                - 0.0003 * sin(2.0 * m + p);

            if (phase == 0.25)
            {
                k += 0.0028 - 0.0004 * cos(m) + 0.0003 * cos(p);
            };

            if (phase == 0.75)
            {
                k += -0.0028 + 0.0004 * cos(m) - 0.0003 * cos(p);
            };
        };

        jd = jd + k;

        return jd;
    }

    void EclSolar::ckphase(double minmjd, double maxmjd, double yr,
                           double deltdut, int& mp, PMJD p, double phase)
    /* calculate the respective phase for one (MJD-) date and check whether
       this date is within the limits given by minmjd and maxmjd.
       Use yr as the year.fraction close to the desired date.
       If the date is within the limits store the result in the
       respective array.
       Also check for possible occurrences of eclipses and store the
       respective data in an array
    */
    {
        double td, ejd, emag;
        int j, eph;

        td = phmjd(yr, phase, deltdut * 86400.0, eph, ejd, emag);
        // correct difference between UT and TDT
        td = td - deltdut;  // correct for difference between TDT and UT.

        // check whether the date is within the respective year

        if ((td >= minmjd) && (td <= maxmjd) && (mp < MAXLUN))
        {
            if (mp == 0)
            {
                p[0] = td;
                mp = 1;
            }

            else
            {
                if (p[mp - 1] < (td - 0.1))
                {
                    p[mp] = td;
                    mp = mp + 1;
                };
            };
        };

        // now the eclipses
        if (eph != 0)
        {
            td = ejd;
            td = td - deltdut;  // correct for difference between TDT and UT.

            // check whether the date is within the respective year
            if ((td >= minmjd) && (td <= maxmjd) && (eb_numecl < GBL_ECLBUF))
            {
                if (eb_numecl == 0)
                {
                    eb_eclmjd[0] = td;
                    eb_magnitude[0] = emag;
                    eb_phase[0] = eph;
                    eb_numecl = 1;
                }

                else
                {
                    for (j = 0; j < eb_numecl; j++)
                    {
                        // check whether the date is already stored
                        if (fabs(eb_eclmjd[j] - td) < 0.01)
                        {
                            eph = 0;
                        }
                    };

                    if (eph != 0)
                    {
                        j = eb_numecl;
                        eb_eclmjd[j] = td;
                        eb_magnitude[j] = emag;
                        eb_phase[j] = eph;
                        eb_numecl += 1;
                    };
                }
            }
        }
    }

    void EclSolar::dtmstr(double jdmoon, char* dts)
    //  Convert the Modified Julian Date jdmoon into a corresponding string
    //  *dts which has the format "MMM DD HH:MM"
    {
        int dd, mm, yy, deg, mnt;
        double hh, sec;
        char mchr[4];

        // convert MJD into corresponding date and time
        caldat(jdmoon, dd, mm, yy, hh);
        dms(hh, deg, mnt, sec);

        if (sec > 30.0)
        {
            mnt++;
        };

        if (mnt > 59)
        {
            deg++;
            mnt = 0;
        };

        // store data in their positions
        GetMonth(mm, mchr);

        dts[0] = mchr[0];

        dts[1] = mchr[1];

        dts[2] = mchr[2];

        dts[3] = ' ';

        sprintf(&dts[4], "%2i %2i:%02i", dd, deg, mnt);

        dts[12] = ' ';
    }

    //------------------------- moonph ---------------------------------

    void EclSolar::moonph()
    {
        int mp0, mp25, mp5, mp75;  // counter of respective phase entries
        PMJD p0, p25, p5, p75;
        int day, month, year, j;
        double yr, yx, hour, deltdut;
        double minmjd, maxmjd;
        double glatsv, glongsv, gheightsv, lat, lng;
        char wbuf[700];

        eb_moonph_called = true;

        // assign input data from Window Input Structure
        year = eb_year;
        deltdut = eb_del_tdut / 86400.0;  // difference TDT - UT in days
        eb_lastyear = year;
        eb_lasttz = eb_tzone;
        eb_lastdlt = eb_del_tdut;

        // initializing counters
        eb_numecl = 0;
        mp0 = 0;
        mp25 = 0;
        mp5 = 0;
        mp75 = 0;

        yr = year - 0.2;
        yx = year + 1.2;
        day = 1;
        month = 1;
        hour = 0;
        minmjd = mjd(day, month, year, hour);
        day = 31;
        month = 12;
        hour = 24.0;
        maxmjd = mjd(day, month, year, hour);

        /* As the function phmjd finds the respective phases of the Moon
           only to within a few weeks of the time given by the input
           parameter (year.faction) the following loop starts well ahead of
           the beginning of the year in question and ends well after.
           The time step of two weeks utilized to increment the year.fraction
           parameter assures that we catch all the different lunations */

        while (yr < yx)
        {
            // calculate and check the phases
            ckphase(minmjd, maxmjd, yr, deltdut, mp0, p0, 0.0);
            ckphase(minmjd, maxmjd, yr, deltdut, mp25, p25, 0.25);
            ckphase(minmjd, maxmjd, yr, deltdut, mp5, p5, 0.5);
            ckphase(minmjd, maxmjd, yr, deltdut, mp75, p75, 0.75);
            yr += 0.02; // increase by 1/50th of a year (about two weeks)
        };

        for (j = 0; j < eb_numecl; j++)
        {
            if ((eb_phase[j] == 1) && (eb_magnitude[j] > 0.98))  // check for possible non-central eclipse
            {
                glatsv = eb_geolat;
                glongsv = eb_geolong;
                gheightsv = eb_geoheight;
                eb_eclselect = j + 1;
                eb_start_called = false;
                eb_local_called = false;

                getMaxPos(lat, lng);
                eb_geolat = lat;
                eb_geolong = lng;
                eb_geoheight = 0;

                getLocalDetails(wbuf);

                if ((eb_spp[0] == 2) || (eb_spp[1] == 2))
                {
                    eb_phase[j] = 2;
                }

                if ((eb_spp[0] == 3) || (eb_spp[1] == 3))
                {
                    eb_phase[j] = 3;
                }

                eb_geolat = glatsv;
                eb_geolong = glongsv;
                eb_geoheight = gheightsv;
                eb_start_called = false;
                eb_local_called = false;

            }

        };

        eb_eclselect = 0;
    }

    double EclSolar::getlocmag(double jd, double ep2, double phi, double lamda,
                               double height, const Vec3& rs, const Vec3& rm, int& totflg)
    {
        /* get magnitude of solar eclipse at local position.
           jd : MJD (UT) of event
           ep2 : correction for apparent sidereal time (in sec)
           phi, lamda : latitude and longitude of observer in radians
           height : height of observer in m
           rs, rm : geocentric position vector of the sun and the moon
           totflg : 1 if total or annular, 0 otherwise

           RETURN: The magnitude of the eclipse (0 if no eclipse)
        */

        const double ds = 218.245445;  // diameter of Sun in Earth radii
        const double dm = 0.544986;   // diameter of Moon in Earth radii
        Vec3  gm, gs, s;
        double dsun, dmoon, asep;
        double elev;

        gm = GeoPos(jd, ep2, phi, lamda, height);
        gs = rs - gm;
        gm = rm - gm;

        // correct for refraction
        s = EquHor(jd, ep2, phi, lamda, gs);
        s = carpol(s);
        elev = s[2];

        if (elev > -3.5e-2)   // cutoff of -2 deg for calculating refraction
        {
            elev = Refract(elev);
            s[2] = s[2] + elev;
            s = polcar(s);
            gs = HorEqu(jd, ep2, phi, lamda, s);
        };

        s = EquHor(jd, ep2, phi, lamda, gm);

        s = carpol(s);

        elev = s[2];

        if (elev > -3.5e-2)   // cutoff of -2 deg for calculating refraction
        {
            elev = Refract(elev);
            s[2] = s[2] + elev;
            s = polcar(s);
            gm = HorEqu(jd, ep2, phi, lamda, s);
        };

        dsun = atan(0.5 * ds / abs(gs)); // apparent radius of the Sun

        dmoon = atan(0.5 * dm / abs(gm)); // apparent radius of the Moon

        gs = vnorm(gs);

        gm = vnorm(gm);

        asep = fabs(dot(gs, gm));

        if (asep > 1.0)
        {
            asep = 1.0;
        }

        asep = acos(asep);    // apparent distance between Sun and Moon

        totflg = 0;

        if ((dsun + dmoon) > asep) // we have an eclipse
        {
            if (fabs(dsun - dmoon) > asep)
            {
                totflg = 1;
            }

            asep = fabs(dsun + dmoon - asep) / (2.0 * dsun);
        }

        else
        {
            asep = 0;
        }

        return asep;
    }

    //------------------------- eclStart ---------------------------------

    void EclSolar::eclStart()
    {
        /* get start and end times of the various phases of the eclipse
           j = index of the eclipse
           eb_spt[i] = start time in MJD for phase i
           eb_ept[i] = end time in MJD for phase i
           eb_spp[i] = kind of phase i

           Also set the global eb_jdstart and eb_jdstop
           to the (global jd times) of eclipse start and end.

         */
        int nump, eflg, pcur, pold, maxp, i, j, npflg, p;
        double jd, step, jd2, jdf, d1, d2;
        double azim, elev, dist, phi, lamda;
        bool eclstarted;
        Vec3 gx;
        Eclipse eclp;

        if (!eb_moonph_called)  // just in case - this should never happen!
        {
            moonph();
            putEclSelect(1);
        };

        eb_local_called = false;

        eb_start_called = true;

        j = eb_eclselect - 1;

        eclstarted = false;

        nump = 0;

        maxp = 0;

        eflg = 0;  // end flag

        pold = 0;

        elev = 0;

        eb_maxps = -1.0;

        eb_maxelv = -1.0;

        p = eb_phase[j];

        jd = eb_eclmjd[j] - 0.5;  // start 12 hours before maximum

        jdf = jd + 1.5;  // emergency stop if something goes wrong with the loop

        step = eb_cstep / (24.0 * 60.0); // stepwidth (best set to 1 minute)

        do
        {
            if (eb_lunactive)
            {
                pcur = eclp.lunar(jd, eb_del_tdut);
            }

            else
            {
                pcur = eclp.solar(jd, eb_del_tdut, d1, d2);
            }

            // now check the start and stop times for the phases
            if (pcur > pold)
            {
                eclstarted = true;

                if (nump < 4)
                {
                    eb_spt[nump] = jd;
                    eb_spp[nump] = pcur;
                    nump++;
                    maxp++;
                    pold = pcur;
                    // get time accurate to the second
                    jd2 = jd - 1.0 / 86400.0; // go in seconds steps

                    for (i = 0; i < 60; i++)
                    {
                        if (eb_lunactive)
                        {
                            pcur = eclp.lunar(jd, eb_del_tdut);
                        }

                        else
                        {
                            pcur = eclp.solar(jd2, eb_del_tdut, d1, d2);
                        }

                        if (pcur == pold)
                        {
                            eb_spt[nump] = jd2;
                        }

                        else
                        {
                            break;
                        }

                        jd2 = jd2 - 1.0 / 86400.0; // go in seconds steps
                    };
                }
            }

            else if (eclstarted && (pcur < pold))
            {
                pold = pcur;
                // get time accurate to the second
                jd2 = jd - 1.0 / 86400.0; // go in seconds steps

                for (i = 0; i < 60; i++)
                {
                    if (eb_lunactive)
                    {
                        pcur = eclp.lunar(jd, eb_del_tdut);
                    }

                    else
                    {
                        pcur = eclp.solar(jd2, eb_del_tdut, d1, d2);
                    }

                    if (pcur == pold)
                    {
                        jd = jd2;
                    }

                    else
                    {
                        break;
                    }

                    jd2 = jd2 - 1.0 / 86400.0; // go in seconds steps
                };

                pcur = pold;

                npflg = 1;

                if (nump > 1)
                {
                    if (pcur > eb_spp[nump - 2])
                    {
                        npflg = 0;
                    }
                }

                if (npflg)
                {
                    nump--;

                    if (nump >= 0)
                    {
                        eb_ept[nump] = jd;
                    }

                    if (nump > 1)
                    {
                        if (pcur < eb_spp[nump - 1])
                        {
                            nump--;
                            eb_ept[nump] = jd;
                        }
                    }

                    if (nump <= 0)
                    {
                        eflg = 1;
                    }
                }
            };

            jd += step;

            if (jd > jdf)
            {
                eflg = 1;
            }

        }
        while (eflg != 1);

        // now check for maximum eclipse conditions

        calcMaxPos(phi, lamda);

        if ((eb_lunactive == false) && (p > 3))  // central solar eclipse
        {
            eb_jdmaxps = eb_eclmjd[j];
            jd = eb_eclmjd[j] - 600.0 / 86400.0; // start 10 min before approximate max time
            phi = eb_cmxlat * degrad;
            lamda = eb_cmxlng * degrad;

            for (i = 0; i < 1200; i++)
            {
                jd += 1.0 / 86400.0; // go in seconds steps
                pcur = eclp.solar(jd, eb_del_tdut, d1, d2);

                if (pcur > 3)
                {
                    gx = eclp.GetRSun();
                    AppPos(jd, eclp.GetEp2(), d1, d2, 0.0, 1, gx, azim, elev, dist);

                    if (elev > eb_maxelv)
                    {
                        eb_maxelv = elev;
                        eb_jdmaxps = jd;
                        phi = d1;
                        lamda = d2;
                    };
                }
            }

            eb_maxelv = elev / degrad;
            eb_cmxlat = phi / degrad;
            eb_cmxlng = lamda / degrad;

            if (eb_cmxlng < 0)
            {
                eb_cmxlng += 360.0;
            }
        };

        eb_jdstart = eb_spt[0];

        eb_jdstop = eb_ept[0];

        eb_nphase = maxp;

    }

    void EclSolar::calcMaxPos(double& lat, double& lng)
    {
        // Get the geographic position of the maximum eclipse
        // in case of a central eclipse the position is approximate
        // lat and lng are in decimal degrees

        int j, p;
        double t, mp2;
        Vec3 rm;
        Vec3 s2;
        Eclipse eclp;

        mp2 = 2.0 * M_PI;

        j = eb_eclselect - 1;

        t = eb_eclmjd[j];

        if (eb_lunactive)
        {
            eclp.lunar(t, eb_del_tdut);
            rm = eclp.GetRMoon();

            // get sub lunar point at maximum
            s2 = carpol(rm);
            lat = s2[2];   // just preliminary
            lng = s2[1] - lsidtim(t, 0, eclp.GetEp2()) * M_PI / 12.0;

            if (lng > mp2)
            {
                lng -= mp2;
            }

            if (lng < -M_PI)
            {
                lng += mp2;
            }

            if (lng > M_PI)
            {
                lng -= mp2;
            }

            if (fabs(lat) < 1.53589)
            {
                lat = atan(1.00674 * tan(lat));
            }

            lat /= degrad;
            lng /= degrad;

            if (lng < 0)
            {
                lng += 360.0;
            }

            eb_cmxlat = lat;
            eb_cmxlng = lng;
            return;
        }

        else
        {
            p = eclp.solar(t, eb_del_tdut, lat, lng);
        }

        if (p > 3)
        {
            eb_cmxlat = lat;
            eb_cmxlng = lng;
            eb_cmxlat /= degrad;
            eb_cmxlng /= degrad;
        }

        else
        {
            eclp.maxpos(t, eb_del_tdut, eb_cmxlat, eb_cmxlng);
            eb_cmxlat /= degrad;
            eb_cmxlng /= degrad;
        };

        if (eb_cmxlng < 0)
        {
            eb_cmxlng += 360.0;
        }

        lat = eb_cmxlat;
        lng = eb_cmxlng;
    }

    void EclSolar::getMaxPos(double& lat, double& lng)
    {
        // Get the geographic position of the maximum eclipse

        if (!eb_start_called)
        {
            eclStart();
        }

        lat = eb_cmxlat;
        lng = eb_cmxlng;
    }

    double EclSolar::sunObscure(double l1, double l2, double mag)
    {
        // get the Obscuration of the Sun from penumbra l1, umbra l2 and
        // magnitude mag

        double s, a, b, c, m;

        m = l1 - mag * (l1 + l2);
        s = (l1 - l2) / (l1 + l2);
        c = (l1 * l1 + l2 * l2 - 2 * m * m) / (l1 * l1 - l2 * l2);
        c = acos(c);
        b = (l1 * l2 + m * m) / (m * (l1 + l2));
        b = acos(b);
        a = M_PI - (b + c);
        s = (s * s * a + b) - s * sin(c);

        return s / M_PI;
    }

    /*------------------------- EclCentral ---------------------------------*/

    int EclSolar::eclPltCentral(bool firstc, double& lat, double& lng)
    {
        /* get next coordinates for central eclipse position
           first = 1 for first call (first point will be found)
           lat, lng : latitude and longitude in decimal degrees

           RETURN: phase (= 4 annular, = 5 total, = 6 annular/total
                          0 if there was no central eclipse)
        */
        double phi, lamda, d1, d2, jd, jd2;
        int kp, kp2, i;
        Eclipse eclp;

        if (!eb_start_called)
        {
            eclStart();
        }

        if (eb_lunactive)  // just in case
        {
            eb_finished2 = true;
            lat = 0.0;
            lng = 0.0;
            return 0;
        };

        eb_cphs = 0;

        if (firstc)   // find the first occurrence compliant with the step width
        {
            jd = eb_jdstart;
            kp = eclp.solar(jd, eb_del_tdut, phi, lamda);

            while ((kp < 4) && (jd < eb_jdstop))
            {
                jd += double(eb_cstep) / (24.0 * 60.0);
                eb_lastjd = jd;
                kp = eclp.solar(jd, eb_del_tdut, phi, lamda);
            };

            jd2 = jd;

            for (i = 0; i < 60; i++) // get it right to the second
            {
                jd2 = jd2 - 1.0 / 86400.0; // go in seconds steps
                kp2 = eclp.solar(jd2, eb_del_tdut, d1, d2);

                if (kp2 == kp)
                {
                    phi = d1;
                    lamda = d2;
                }

                else
                {
                    break;
                }
            };

            eb_finished2 = false;

        }  // end of firstc

        else
        {
            if (eb_finished2)
            {
                return 0;
            }

            jd = eb_lastjd + double(eb_cstep) / (24.0 * 60.0);
            eb_lastjd = jd;

            if (jd > eb_jdstop)
            {
                eb_finished2 = true;
                return 0;
            };

            kp = eclp.solar(jd, eb_del_tdut, phi, lamda);

            if (kp <= 3)  // end of central eclipse.
            {
                eb_finished = true;

                for (i = 0; i < 60; i++) // get it right to the second
                {
                    jd -= 1.0 / 86400.0; // go in seconds steps
                    kp = eclp.solar(jd, eb_del_tdut, phi, lamda);

                    if (kp > 3)
                    {
                        break;
                    }
                };
            };
        };

        if (kp > 3)   // central eclipse
        {
            eb_cphs = kp;

            phi /= degrad;
            lamda /= degrad;

            if (lamda < 0.0)
            {
                lamda += 360.0;
            }

            if (lamda > 360.0)
            {
                lamda -= 360.0;
            }

            eb_clat = phi;
            eb_clng = lamda;
            lat = eb_clat;
            lng = eb_clng;

            //  djd = eclp.duration(jd, indata->del_tdut, width);
        }

        return kp;
    }

    //--------------------Northern and Southern Boundaries -------------------------

    void EclSolar::InitBound()
    {
        /* Initialize the calculation for the northern and southern boundaries
           of solar eclipses (umbra or penumbra).
           The function EclStart must have been called first to enable InitBound
           to get the right eclipse.
           The calculation is done in Earth radii.

           OUTPUT:
                  eb_ubm : Penumbra base vector
                  eb_ube : Shadod base vector for upper boundary
                  eb_udm : Penumbra base delta vector
                  eb_ude : Shadow delta vector for upper boundary
                  eb_lbe : Shadod base vector for lower boundary
                  eb_lde : Shadow delta vector for lower boundary
        */

        //  const double dm = 0.272493;   // radius of Moon in Earth radii
        double dpn1, dpn2, pan1, pan2, s0;
        Vec3 shmv, u2m, u2e;
        Vec3 ax1, ax2;
        Eclipse eclp;

        if (!eb_start_called)
        {
            eclStart();
        }

        if (eb_lunactive)
        {
            return;    // only for solar eclipses
        }

        // beginning of the eclipse
        eclp.penumd(eb_jdstart, eb_del_tdut, eb_ubm, eb_ube, dpn1, pan1);

        // end of the eclipse
        eclp.penumd(eb_jdstop, eb_del_tdut, u2m, u2e, dpn2, pan2);

        dpn1 *= 0.5;
        dpn2 *= 0.5;

        if (eb_penamode == 0)
        {
            dpn1 *= eb_penangle;
            pan1 *= eb_penangle;
            dpn2 *= eb_penangle;
            pan2 *= eb_penangle;
        }

        if (eb_penamode > 0)
        {
            s0 = eb_penangle * tan(pan1);
            s0 = atan(s0);

            if (pan1 > 0)
            {
                dpn1 = dpn1 * s0 / pan1;
                pan1 = s0;
            }

            s0 = eb_penangle * tan(pan2);
            s0 = atan(s0);

            if (pan2 > 0)
            {
                dpn2 = dpn2 * s0 / pan2;
                pan2 = s0;
            }
        }

        // get apex of penumbra cone
        pan1 = tan(pan1);

        if (pan1 != 0)
        {
            dpn1 = dpn1 / pan1;
        }

        else
        {
            dpn1 = 1.2 * abs(eb_ubm);    // avoid a crash
        }

        pan2 = tan(pan2);

        if (pan2 != 0)
        {
            dpn2 = dpn2 / pan2;
        }

        else
        {
            dpn2 = dpn1;    // avoid a crash
        }

        // get vector perpendicular to movement of shadow
        s0 = - dot(eb_ubm, eb_ube);
        ax1 = eb_ubm + s0 * eb_ube;
        eb_ubm = eb_ubm + (s0 - dpn1) * eb_ube;
        s0 = - dot(u2m, u2e);
        ax2 = u2m + s0 * u2e;
        u2m = u2m + (s0 - dpn2) * u2e;
        shmv = ax1 - ax2;
        ax2 = ax1 * ax2;
        shmv = shmv * ax2;
        shmv = vnorm(shmv);

        // now get the delta vectors
        eb_udm = u2m - eb_ubm;
        eb_lbe = eb_ube - pan1 * shmv;
        eb_ube = eb_ube + pan1 * shmv;
        eb_ude = u2e + pan2 * shmv;
        eb_lde = u2e - pan2 * shmv;
        eb_ube = vnorm(eb_ube);
        eb_lbe = vnorm(eb_lbe);
        eb_ude = vnorm(eb_ude);
        eb_lde = vnorm(eb_lde);
        eb_lde = eb_lde - eb_lbe;
        eb_ude = eb_ude - eb_ube;

        // scale the delta vectors
        dpn1 = eb_jdstop - eb_jdstart;

        if (dpn1 == 0)
        {
            dpn1 = 1.0;
        }

        else
        {
            dpn1 = 1.0 / dpn1;
        }

        eb_udm *= dpn1;
        eb_ude *= dpn1;
        eb_lde *= dpn1;
    }

    int EclSolar::GNSBound(bool firstc, bool north, double& lat, double& lng)
    {
        /* Get the geographic coordinates of the northern or southern boundaries
           at time t.
           INPUT:  firstc :true for first call
                   north : true for southern boundary
                   see also InitBound
           OUTPUT:
                  lat, lng : latitude and longitude of penumbra boundary.
                  If lat > 90 no northern boundary exists.

           RETURN: 1 if time within eclipse, 0 if end of eclipse
         */
        const double flat = 0.996633;  // flatting of the Earth

        double s0, s, r0, r2, dlt, t;
        Vec3 vrm, vre;

        if (eb_lunactive)  // only solar eclipses
        {
            lng = 0.0;
            lat = 100.0;
            return 0;
        };

        if (firstc)
        {
            InitBound();
            t = eb_jdstart;
            eb_lastjd = t;
        }

        else
        {
            t = eb_lastjd + double(eb_cstep) / (24.0 * 60.0);
            eb_lastjd = t;
        };

        if (t >= eb_jdstop)
        {
            lng = 0.0;
            lat = 100.0;
            return 0;
        };

        // get shadow vector at time t
        vrm = eb_ubm + (t - eb_jdstart) * eb_udm;

        if (north)
        {
            vre = eb_ube + (t - eb_jdstart) * eb_ude;
        }

        else
        {
            vre = eb_lbe + (t - eb_jdstart) * eb_lde;
        }

        vre = vnorm(vre);   // direction of penumbra boundary

        s0 = - dot(vrm, vre);   // distance Moon - fundamental plane
        r2 = dot(vrm, vrm);
        dlt = s0 * s0 + 1.0 - r2;
        r0 = 1.0 - dlt;

        if (r0 > 0)
        {
            r0 = sqrt(r0);
        }

        else
        {
            r0 = 0;    // distance center of Earth - shadow axis
        }

        // calculate the coordinates if there is an intersection
        if (r0 < 1.0)  // there should be an intersection
        {
            if (dlt > 0)
            {
                dlt = sqrt(dlt);
            }

            else
            {
                dlt = 0;
            }

            s = s0 - dlt;  // distance Moon - fundamental plane
            vrm = vrm + s * vre;
            vrm = vnorm(vrm);
            vrm[2] *= flat;    // vector to intersection
            vre = carpol(vrm);
            lng = vre[1] - lsidtim(t, 0, 0) * 0.261799387799; // geographic coordinates

            if (lng > 2 * M_PI)
            {
                lng -= 2.0 * M_PI;
            }

            if (lng < 0.0)
            {
                lng += 2.0 * M_PI;
            }

            lat = sqrt(vrm[0] * vrm[0] + vrm[1] * vrm[1]) * 0.993305615;
            lat = atan23(vrm[2], lat);
            lat /= degrad;
            lng /= degrad;

            if (lng < 0.0)
            {
                lng += 360.0;
            }

            if (lng > 360.0)
            {
                lng -= 360.0;
            }
        }

        else
        {
            lat = 100.0;
            lng = 0;
        };

        return 1;
    }

    //------------------ Sunrise / Sunset Boundaries ---------------------------

    void EclSolar::InRSBound()
    {
        /* Initialize the calculation for the sunrise and sunset boundaries
           of solar eclipses.
           The function EclStart must have been called first to enable InRSBound
           to get the right eclipse.
           The calculation is done in Earth radii.

           OUTPUT:
                  eb_ubm : Moon base vector
                  eb_ube : Shadod base vector
                  eb_udm : Moon delta vector
                  eb_ude : Shadow delta vector for
                  eb_dpb : Base value for diameter of penumbra
                  eb_dpd : delta value for diameter of penumbra
        */

        double pan;
        Vec3 u2m, u2e;
        Eclipse eclp;

        if (!eb_start_called)
        {
            eclStart();
        }

        // beginning of the eclipse
        eclp.penumd(eb_jdstart, eb_del_tdut, eb_ubm, eb_ube, eb_dpb, pan);

        // end of the eclipse
        eclp.penumd(eb_jdstop, eb_del_tdut, u2m, u2e, eb_dpd, pan);

        // get the delta vectors
        eb_udm = u2m - eb_ubm;
        eb_ude = u2e - eb_ube;
        eb_dpd = eb_dpd - eb_dpb;

        // scale the delta vectors

        pan = eb_jdstop - eb_jdstart;

        if (pan == 0)
        {
            pan = 1.0;
        }

        else
        {
            pan = 1.0 / pan;
        }

        eb_udm *= pan;
        eb_ude *= pan;
        eb_dpd *= pan;
    }

    int EclSolar::iscrs(double vrc0, double vrc1, double dpn,
                        double& vrx0, double& vrx1, double& vrx20, double& vrx21)
    {
        /* calculate intersection vectors of the penumbral cone with the
           Earth in the fundamental plane to find the locations of rise
           and set.

           INPUT : components of vectors vrc (pointing to the center of the
                   penumbra), vre (unit vector perpendicular to the
                   fundamental plane).
                   dpn : half diameter of penumbra in Earth radii

           OUTPUT: components of the intersection vectors vrx and vrx2 if
                   successful.

           RETURN: 1 if intersection successful, 0 otherwise.
        */
        int rtn;
        double a, b, c, f1, f2, f3, f4;

        rtn = 1;
        f1 = vrc0 * vrc0;

        if (f1 < 1.0e-60)
        {
            rtn = 0;
        }

        else
        {
            f2 = 1.0 - dpn * dpn + f1 + vrc1 * vrc1;
            f3 = f2 / (2.0 * vrc0);
            f4 = vrc1 / vrc0;
            a = 1.0 + vrc1 * vrc1 / f1;
            b = f2 * vrc1 / f1;
            c = f2 * f2 / (4.0 * f1) - 1.0;

            if (fabs(a) < 1.0e-60)
            {
                rtn = 0;
            }

            else
            {
                vrx21 = -0.5 * b / a; ;
                vrx0 = vrx21 * vrx21 - c / a;

                if (vrx0 < 0)
                {
                    rtn = 0;
                }

                else
                {
                    vrx0 = sqrt(vrx0);
                    vrx1 = vrx21 + vrx0;
                    vrx21 = vrx21 - vrx0;
                    vrx0 = f3 + f4 * vrx1;
                    vrx20 = f3 + f4 * vrx21;
                    vrx1 = -vrx1;
                    vrx21 = -vrx21;
                };
            };
        };

        return rtn;
    }

    int EclSolar::GRSBound(bool firstc, double& lat1, double& lng1, double& lat2, double& lng2)
    {
        /* Get the geographic coordinates of the boundaries for rise/set
           at time t.

           INPUT: firstc : true for first call

           OUTPUT:
                  lat1, lng1; lat2, lng2  : latitude and longitude of first
                                            and second point ofboundary.
                                            If lat > 90 no respective point exists.

          RETURN: 0 if end of eclipse, 1 otherwise
        */
        const double flat = 0.996633;  // flatting of the Earth

        double s0, r0, dpn, t;
        Vec3 vrm, vre, vrc, vrx, vrx2;
        Mat3 m1, m2;

        if (eb_lunactive)  // only solar eclipses
        {
            lng1 = 0.0;
            lat1 = 100.0;
            lng2 = 0.0;
            lat2 = 100.0;
            eb_finished = true;
            return 0;
        };

        if (firstc)
        {
            InRSBound();
            t = eb_jdstart + 1.0 / 86400.0; // just add a second to be beyond the limit
            eb_lastjd = t;
            eb_finished = false;
        }

        else
        {
            t = eb_lastjd + double(eb_cstep) / (24.0 * 60.0);
            eb_lastjd = t;
        };

        if (t >= eb_jdstop)
        {
            if (eb_finished)
            {
                lng1 = 0.0;
                lat1 = 100.0;
                lng2 = 0.0;
                lat2 = 100.0;
                return 0;
            };

            t = eb_jdstop - 1.0 / 86400.0; // just to go to the very end and then stop

            eb_lastjd = t;

            eb_finished = true;
        };

        // get position of penumbra and shadow cone
        vrm = eb_ubm + (t - eb_jdstart) * eb_udm;

        vre = eb_ube + (t - eb_jdstart) * eb_ude;

        vre = vnorm(vre);   // direction of penumbra boundary

        dpn = eb_dpb + (t - eb_jdstart) * eb_dpd;

        dpn *= 0.5;  // half cone diameter

        vrx = carpol(vre);

        m1 = zrot(vrx[1] + M_PI / 2.0);

        m2 = xrot(M_PI / 2.0 - vrx[2]);

        m1 = m2 * m1;   // rotation from equatorial into fundamental plane

        m2 = mxtrn(m1); // rotation from fundamental plane into equatorial

        // get vector to center of shadow in the fundamental plane
        s0 = - dot(vrm, vre);

        vrc = vrm + s0 * vre;

        r0 = abs(vrc);  // distance between center of Earth and center of shadow

        vrc = mxvct(m1, vrc);

        lng1 = 0;

        lat1 = 100.0;

        lng2 = 0;

        lat2 = 100.0;

        // check whether intersection of Earth and shadow cone are possible
        // in fundamental plane
        if ((r0 > fabs(1.0 - dpn)) && (r0 < fabs(1.0 + dpn)))
        {
            // now find the intersections
            if (iscrs(vrc[0], vrc[1], dpn, vrx[0], vrx[1], vrx2[0], vrx2[1]))
            {
                lat1 = 0;
            }

            else
            {
                if (iscrs(vrc[1], vrc[0], dpn, vrx[1], vrx[0], vrx2[1], vrx2[0]))
                {
                    lat1 = 0;
                }
            };
        };

        // calculate the coordinates if there is an intersection
        if (lat1 < 100.0)  // there should be an intersection
        {
            vrx[2] = 0;
            vrx = mxvct(m2, vrx);
            vrx = vnorm(vrx);
            vrx[2] *= flat;    // vector to intersection
            vre = carpol(vrx);
            lng1 = vre[1] - lsidtim(t, 0, 0) * 0.261799387799; // geographic coordinates

            if (lng1 > M_PI)
            {
                lng1 -= 2.0 * M_PI;
            }

            if (lng1 < (-M_PI))
            {
                lng1 += 2.0 * M_PI;
            }

            lat1 = sqrt(vrx[0] * vrx[0] + vrx[1] * vrx[1]) * 0.993305615;
            lat1 = atan23(vrx[2], lat1);
            lat1 /= degrad;
            lng1 /= degrad;
        };

        if (lat2 < 100.0)  // intersection #2
        {
            vrx2[2] = 0;
            vrx2 = mxvct(m2, vrx2);
            vrx2 = vnorm(vrx2);
            vrx2[2] *= flat;    // vector to intersection
            vre = carpol(vrx2);
            lng2 = vre[1] - lsidtim(t, 0, 0) * 0.261799387799; // geographic coordinates

            if (lng2 > M_PI)
            {
                lng2 -= 2.0 * M_PI;
            }

            if (lng2 < (-M_PI))
            {
                lng2 += 2.0 * M_PI;
            }

            lat2 = sqrt(vrx2[0] * vrx2[0] + vrx2[1] * vrx2[1]) * 0.993305615;
            lat2 = atan23(vrx2[2], lat2);
            lat2 /= degrad;
            lng2 /= degrad;
        };

        return 1;
    }

    /*------------------------- EclDetails ---------------------------------*/

    double EclSolar::DegFDms(double h)
    {
        /* convert degrees from d.fff -> d.mmsss where .mm are the minutes
           and sss are seconds (and fractions of seconds).
        */
        int mm, deg;
        double hh, t, sec;

        hh = fabs(h);
        dms(hh, deg, mm, sec);

        if (sec >= 59.5)
        {
            mm++;
            sec = 0;
        };

        if (mm > 59)
        {
            deg++;
            mm = 0;
        };

        hh = double(deg);

        t = double(mm) / 100.0;

        hh += t;

        t = sec / 10000.0;

        hh += t;

        if (h < 0)
        {
            hh = -hh;
        }

        return hh;
    }

    int EclSolar::localStart(int j, double* spt, double* ept, int* spp,
                             int p, char* otxt)
    {
        /* get start and end times of the various phases of the eclipse
           j = index of the eclipse
           spt[i] = start time in MJD for phase i
           ept[i] = end time in MJD for phase i
           spp[i] = kind of phase i
            p = phase

            RETURN: the number of different phases of this eclipse.

           The step width will be 1 min
         */
        int nump, eflg, pcur, pold, maxp, i, npflg;
        double magecl;  // local magnitude of eclipse at jd
        double jd, step, jdf, d1, d2, elrise;
        double azim, elev, dist, phi, lamda;
        char dts[13];
        char outb[127];
        Vec3 gx;
        Eclipse eclp;

        nump = 0;
        maxp = 0;
        eflg = 0;  // end flag
        pold = 0;
        elev = 0;
        eb_lccnt = 0;
        eb_maxps = -1.0;
        eb_maxelv = -1.0;
        phi = eb_geolat * M_PI / 180.0;
        lamda = eb_geolong * M_PI / 180.0;
        jd = eb_eclmjd[j] - 0.5;  // start 12 hours before maximum
        jdf = jd + 1.5;  // emergency stop if something goes wrong with the loop
        step = 1.0 / (24.0 * 60.0); // stepwidth 1 minute
        eb_ltotb = jd;
        eb_ltote = jd - 1.0;

        do
        {
            if (p < 0)
            {
                pcur = eclp.lunar(jd, eb_del_tdut);
                gx = eclp.GetRMoon();
                magecl = 1.0;  // just set it 1. It's not needed for lunar eclipses.
                elrise = -9.89e-3;  // allow for refraction during rise/set
            }

            else
            {
                pcur = eclp.solar(jd, eb_del_tdut, d1, d2);
                gx = eclp.GetRSun();
                magecl = 0;
                elrise = -1.45e-2;  // allow for refraction during rise/set
            };

            // check whether body is visible from local position.
            if (pcur > 0)
            {
                AppPos(jd, eclp.GetEp2(), phi, lamda, eb_geoheight, 1, gx,
                       azim, elev, dist);

                if ((p > 0) && (elev >= elrise))
                {
                    magecl = getlocmag(jd, eclp.GetEp2(), phi, lamda, eb_geoheight,
                                       eclp.GetRSun(), eclp.GetRMoon(), i);

                    if (magecl > eb_maxps)
                    {
                        eb_maxps = magecl;
                        eb_maxelv = elev;
                        eb_jdmaxps = jd;
                    }
                }
            }

            if ((eb_lccnt == 0) && (pcur != 0))
            {
                if ((elev >= elrise) && (magecl > 0))
                {
                    eb_lcb1 = jd;
                    eb_lccnt = 1;
                }
            }

            if (eb_lccnt == 1)
            {
                if ((elev < elrise) || (pcur == 0) || (magecl == 0))
                {
                    eb_lce1 = jd;
                    eb_lccnt = 2;
                }
            }

            if ((eb_lccnt == 2) && (pcur != 0))
            {
                if ((elev >= elrise) && (magecl > 0))
                {
                    eb_lcb2 = jd;
                    eb_lccnt = 3;
                }
            }

            if (eb_lccnt == 3)
            {
                if ((elev < elrise) || (pcur == 0) || (magecl == 0))
                {
                    eb_lce2 = jd;
                    eb_lccnt = 4;
                }
            }

            // now check the start and stop times for the phases
            if (pcur > pold)
            {
                if (nump < 4)
                {
                    spt[nump] = jd;
                    spp[nump] = pcur;
                    nump++;
                    maxp++;
                    pold = pcur;
                }
            }

            else if (pcur < pold)
            {
                npflg = 1;

                if (nump > 1)
                {
                    if (pcur > spp[nump - 2])
                    {
                        npflg = 0;
                    }
                }

                if (npflg)
                {
                    nump--;

                    if (nump >= 0)
                    {
                        ept[nump] = jd;
                    }

                    if (nump > 1)
                    {
                        if (pcur < spp[nump - 1])
                        {
                            nump--;
                            ept[nump] = jd;
                        }
                    }

                    if (nump <= 0)
                    {
                        eflg = 1;
                    }
                }

                pold = pcur;
            };

            jd += step;

            if (jd > jdf)
            {
                eflg = 1;
            }

        }
        while (eflg != 1);

        //  put the respective info into textfile otxt
        if (maxp > 0)
        {
            for (i = 0; i < maxp; i++)
            {
                if (p < 0)
                {
                    switch (spp[i])
                    {
                        case 1:
                            strcpy(outb, "penumbral   ");
                            break;

                        case 2:
                            strcpy(outb, "tot.penumb  ");
                            break;

                        case 3:
                            strcpy(outb, "partial     ");
                            break;

                        case 4:
                            strcpy(outb, "totality    ");
                            break;
                    }
                }

                else
                {
                    switch (spp[i])
                    {
                        case 1:
                            strcpy(outb, "partial     ");
                            break;

                        case 2:
                            strcpy(outb, "n-centr.Ann ");
                            break;

                        case 3:
                            strcpy(outb, "n-centr.Tot ");
                            break;

                        case 4:
                            strcpy(outb, "annularity  ");
                            break;

                        case 5:
                            strcpy(outb, "totality    ");
                            break;
                    }
                }

                strcat(otxt, "\n ");
                strcat(otxt, outb);
                strcat(otxt, "\tbegins ");
                dtmstr((spt[i] + eb_tzone / 24.0), dts);
                dts[12] = '\0';
                strcat(otxt, dts);
                strcat(otxt, "\tends ");
                dtmstr((ept[i] + eb_tzone / 24.0), dts);
                dts[12] = '\0';
                strcat(otxt, dts);
            }
        }

        if (maxp > 0)   // cppcheck-suppress duplicateCondition
        {
            if (eb_lccnt == 1)
            {
                eb_lce1 = ept[0];
            }

            if (eb_lccnt == 3)
            {
                eb_lce2 = ept[0];
            }
        }

        if (eb_maxps > 0.8)  // check for local central phase
        {
            jd = eb_jdmaxps - 16.0 / (24.0 * 60.0);
            eb_ltote = jd + 32.0 / (24.0 * 60.0);
            eflg = 0;

            do
            {
                jd += 1.0 / 86400.0; // go in seconds steps
                eclp.solar(jd, eb_del_tdut, d1, d2);
                gx = eclp.GetRSun();
                AppPos(jd, eclp.GetEp2(), phi, lamda, eb_geoheight, 1, gx,
                       azim, elev, dist);

                if (elev >= elrise)
                {
                    magecl = getlocmag(jd, eclp.GetEp2(), phi, lamda, eb_geoheight,
                                       eclp.GetRSun(), eclp.GetRMoon(), i);

                    if (magecl > eb_maxps)
                    {
                        eb_maxelv = elev;
                        eb_maxps = magecl;
                        eb_jdmaxps = jd;
                    }

                    if (i > 0)
                    {
                        eb_ltotb = jd;
                        eflg = 1;
                    }
                }

                if (jd > eb_ltote)
                {
                    eflg = 1;
                }

            }
            while (!eflg);

            if (jd < eb_ltote)
            {
                eflg = 0;

                do
                {
                    jd += 1.0 / 86400.0; // go in seconds steps
                    eclp.solar(jd, eb_del_tdut, d1, d2);
                    gx = eclp.GetRSun();
                    AppPos(jd, eclp.GetEp2(), phi, lamda, eb_geoheight, 1, gx,
                           azim, elev, dist);

                    if (elev < elrise)
                    {
                        eflg = 1;
                    }

                    magecl = getlocmag(jd, eclp.GetEp2(), phi, lamda, eb_geoheight,
                                       eclp.GetRSun(), eclp.GetRMoon(), i);

                    if (magecl > eb_maxps)
                    {
                        eb_maxelv = elev;
                        eb_maxps = magecl;
                        eb_jdmaxps = jd;
                    }

                    if (i == 0)
                    {
                        eflg = 1;
                    }

                    if (jd > eb_ltote)
                    {
                        eflg = 1;
                    }

                }
                while (!eflg);

                eb_ltote = jd;
            }

            else
            {
                eb_ltote = eb_ltotb - 1.0;
            }
        }

        return maxp;
    }

    void EclSolar::getLocalDetails(char* otxt)
    {
        /*
         * Get the details of the eclipse selected in eclbuf.select
         * and place the output into otxt.
         */
        int j, p, i, ecloutbn;
        int dd, mm, yy, deg, mnt;
        double sec, hh;

        int spp[4]     = { 0 }, nump;
        double spt[4]  = { 0.0 }, ept[4] = { 0.0 };
        double jd      = 0.0, jdf = 0.0;
        char dts[13]   = { 0 };
        char outb[127] = { 0 };

        if (!eb_start_called)
        {
            eclStart();
        }

        eb_local_called = true;

        j = eb_eclselect - 1;
        p = eb_phase[j];

        ecloutbn = 3;
        sprintf(otxt, "+++ Timezone: %g +++  TT - UTC: %g (sec) +++ Year: %5i +++\n\n", eb_tzone, eb_del_tdut, eb_year);

        switch (p)
        {
            case 1:
                strcpy(outb, "\t\tPartial Eclipse of the Sun");
                break;

            case 2:
                strcpy(outb, "\t\tNon-Central Annular Eclipse of the Sun");
                break;

            case 3:
                strcpy(outb, "\t\tNon-Central Total Eclipse of the Sun");
                break;

            case 4:
                strcpy(outb, "\t\tAnnular Eclipse of the Sun");
                break;

            case 5:
                strcpy(outb, "\t\tTotal Eclipse of the Sun");
                break;

            case 6:
                strcpy(outb, "\t\tAnnular/Total Solar Eclipse");
                break;

            case -1:
            case -2:
                strcpy(outb, "\t\tPenumbral Eclipse of the Moon");
                break;

            case -3:
                strcpy(outb, "\t\tPartial eclipse of the Moon");
                break;

            case -4:
                strcpy(outb, "\t\tTotal eclipse of the Moon");
                break;
        };

        strcat(otxt, outb);

        snprintf(outb, sizeof(outb), "\n\nMaximum Eclipse at ");

        strcat(otxt, outb);

        dtmstr((eb_eclmjd[j] + eb_tzone / 24.0), dts);

        dts[12] = '\0';

        strcat(otxt, dts);

        if (p < 4)
        {
            snprintf(outb, sizeof(outb), "   with magnitude:%5.2f", eb_magnitude[j]);
            strcat(otxt, outb);
        }

        strcat(otxt, "\n");
        nump = localStart(j, spt, ept, spp, p, otxt);

        if ((p < 4) || (nump < 1))
        {
            ecloutbn = 5;
        }

        if (ecloutbn == 3)
        {
            // get start and stop dates for central phase
            jd = spt[nump - 1];

            for (i = 0; i < nump; i++)
                if ((spt[i] < jd) && (spp[i] > 3))
                {
                    jd = spt[i];    // start of central phase
                }

            caldat(jd, dd, mm, yy, hh);
            dms(hh, deg, mnt, sec);
            sec = 0;
            i = (int)(mnt / eb_cstep);
            mnt = i * int(eb_cstep);  // cut to proper time step
            hh = ddd(deg, mnt, sec);
            jdf = ept[nump - 1];

            for (i = 0; i < nump; i++)
                if ((ept[i] > jdf) && (spp[i] > 3))
                {
                    jdf = ept[i];    // end of central phase
                }
        }

        // local circumstances
        strcat(otxt, "\n\n\nLocal Circumstances for ");
        jd = eb_geolat;
        jdf = eb_geolong;
        snprintf(outb, sizeof(outb), "\nLat: %g   Long: %g   height: %g m\n\n",
                jd, jdf, eb_geoheight);
        strcat(otxt, outb);

        if (p != 0)
        {
            if (eb_lccnt > 0)
            {
                snprintf(outb, sizeof(outb), "Eclipse visible from ");
                dtmstr((eb_lcb1 + eb_tzone / 24.0), dts);
                dts[12] = '\0';
                strcat(outb, " ");
                strcat(outb, dts);
                strcat(outb, " to ");
                dtmstr((eb_lce1 + eb_tzone / 24.0), dts);
                dts[12] = '\0';
                strcat(outb, dts);

                if (eb_lccnt > 2)  // this case almost never happens
                {
                    strcat(otxt, outb);
                    strcpy(outb, "\n\tand from ");
                    dtmstr((eb_lcb2 + eb_tzone / 24.0), dts);
                    dts[12] = '\0';
                    strcat(outb, " ");
                    strcat(outb, dts);
                    strcat(outb, " to ");
                    dtmstr((eb_lce2 + eb_tzone / 24.0), dts);
                    dts[12] = '\0';
                    strcat(outb, dts);
                }
            }

            else
            {
                snprintf(outb, sizeof(outb), "Eclipse not visible");
            }

            strcat(otxt, outb);
        }

        // local solar eclipse magnitude
        if ((p > 0) && (eb_lccnt > 0))
        {
            snprintf(outb, sizeof(outb), "\nMaximum Eclipse at ");
            strcat(otxt, outb);
            dtmstr((eb_jdmaxps + eb_tzone / 24.0), dts);
            dts[12] = '\0';
            strcat(otxt, dts);
            snprintf(outb, sizeof(outb), "   with magnitude %6.3f", eb_maxps);
            strcat(otxt, outb);
            snprintf(outb, sizeof(outb), "   elev:%4.1f", 180.0 * eb_maxelv / M_PI);
            strcat(otxt, outb);

            if (eb_ltotb <= eb_ltote)
            {
                // local central eclipse
                if ((p % 2) == 0)
                {
                    strcpy(outb, "\nannularity from");
                }

                else
                {
                    strcpy(outb, "\ntotality from");
                }

                if ((p == 1) || (p == 6))
                {
                    strcpy(outb, "\ntotality/annularity from");
                }

                strcat(otxt, outb);
                caldat((eb_ltotb + eb_tzone / 24.0), dd, mm, yy, hh);
                caldat((eb_ltote + eb_tzone / 24.0), dd, mm, yy, jd);
                hh = DegFDms(hh);
                jd = DegFDms(jd);
                jdf = (eb_ltote - eb_ltotb) * 86400.0;
                snprintf(outb, sizeof(outb), "%8.4f  to%8.4f   del.t:%3.0f sec \n", hh, jd, jdf);
                strcat(otxt, outb);
            }
        }

        eb_maxelv /= degrad;
    }

    //---------Northern and Southern Umbra Boundaries ---------------------

    double EclSolar::navCourse(double lat1, double lng1, double lat2, double lng2)
    {
        // get course (in radians) from (lat1, lng1) to (lat2, lng2) over the Earth surface
        // the geographic coordinates are in decimal degrees

        double lt1, ln1, lt2, ln2, cd, an;

        lt1 = lat1 * degrad;
        ln1 = lng1 * degrad;
        lt2 = lat2 * degrad;
        ln2 = lng2 * degrad;

        cd = sin(lt1) * sin(lt2) + cos(lt1) * cos(lt2) * cos(ln2 - ln1);
        an = acos(cd);
        an = cos(lt1) * sin(an);

        if (an == 0)
        {
            return 0;    // same spot. didn't move
        }

        cd = (sin(lt2) - sin(lt1) * cd) / an;
        an = acos(cd);

        if (sin(ln2 - ln1) < 0)
        {
            an = -an;
        }

        return an;
    }

    void EclSolar::navNewPos(double d, double an, double lat1, double lng1, double& lat2, double& lng2)
    {
        /*
           starting from (lat1, lng1) along the great circle for d (radians) with course an (in radians)
           get the new position (lat2, lng2) (in decimal degrees) at the Earth surface
        */

        double cd, sd, lt1, ag;

        ag = an;

        if (ag > M_PI)
        {
            ag -= 2 * M_PI;
        }

        if (ag < -M_PI)
        {
            ag += 2 * M_PI;
        }

        cd = cos(d);
        lt1 = lat1 * degrad;

        sd = cd * sin(lt1) + sin(d) * cos(lt1) * cos(ag);
        lat2 = asin(sd);

        lng2 = cos(lt1) * cos(lat2);

        if (lng2 == 0)  // just in case to avoid a crash
        {
            lat2 = lat1;
            lng2 = lng1;
            return;
        }

        lng2 = (cd - sin(lt1) * sd) / lng2;
        lng2 = acos(lng2);
        lng2 /= degrad;

        if (ag > 0)
        {
            lng2 = lng1 + lng2;
        }

        else
        {
            lng2 = lng1 - lng2;
        }

        if (lng2 > 360.0)
        {
            lng2 -= 360.0;
        }

        if (lng2 < 0)
        {
            lng2 += 360.0;
        }

        lat2 /= degrad;

    }

    int EclSolar::centralBound(bool firstc, double& lat1, double& lng1, double& lat2, double& lng2)
    {
        /* Get the geographic coordinates of the northern or southern boundaries
           of the umbra at time t.
           INPUT:  firstc :true for first call

           OUTPUT:
                  lat, lng : latitude and longitude of umbra boundary in decimal degrees.
                  If lat > 90 no boundary exists.

           RETURN: current phase if time within eclipse, <=3 if no central eclipse
         */

        bool lastp;
        int k;
        double dpn1, t;
        double lt1, ln1, lt2, ln2, an;
        Eclipse eclp;

        if (!eb_start_called)
        {
            eclStart();
        }

        lng1 = 0.0;
        lat1 = 100.0;
        lng2 = 0.0;
        lat2 = 100.0;

        lastp = false;

        if (eb_lunactive)
        {
            return 0;    // only solar eclipses
        }

        if (firstc)
        {
            k = eclPltCentral(true, lt1, ln1);
        }

        else
        {
            k = eclPltCentral(false, lt1, ln1);
        }

        t = eb_lastjd;

        if (k <= 3)
        {
            return k;    // no central eclipse
        }

        k = eclPltCentral(false, lt2, ln2);  // next step
        eb_lastjd = t;  // go back to the original step

        if (k <= 3)  // try the last step instead at the end
        {
            eb_lastjd -= 2.0 * eb_cstep / (24.0 * 60.0);
            k = eclPltCentral(false, lt2, ln2);
            eb_lastjd = t;
            lastp = true;
        };

        if (k <= 3)
        {
            return k;    // no central eclipse
        }

        eclp.solar(t, eb_del_tdut, lat1, lng1);
        lat1 = 100.0;
        lng1 = 0;

        an = navCourse(lt1, ln1, lt2, ln2);   // direction of shadow along Earth surface
        an += 0.5 * M_PI; // direction perpendicular to shadow movement (right boundary)

        eclp.duration(t, eb_del_tdut, dpn1);  // dpn1 is width of umbra in km
        dpn1 = (dpn1 / 111.1) * 0.0174533;  // radians of umbra width
        dpn1 /= 2.0;
        navNewPos(dpn1, an, lt1, ln1, lat1, lng1);

        an -= M_PI;  // find opposite boundary

        navNewPos(dpn1, an, lt1, ln1, lat2, lng2);

        if (lastp)  // we went the opposite way at the end
        {
            lt1 = lat2;
            ln1 = lng2;
            lat2 = lat1;
            lng2 = lng1;
            lat1 = lt1;
            lng1 = ln1;
            return 0;  // end of eclipse
        }

        else
        {
            return k;
        }
    }

    //-------------------- Shadow Cone -------------------------

    void EclSolar::getShadowCone(double mjd, bool umbra, int numpts, double* lat, double* lng)
    {
        /*  Get the geographic coordinates of the shadow cone at MJD-time mjd.
            if umbra is true the umbra cone will be returned
            if umbra is false the penumbra will be returned

           OUTPUT:
                  lat and lng must be arrays of length numpts into which the numpts points will be placed
                  if there is no (total) eclipse at the time, lat will be set 100.0, lng 0.
        */

        const double flat = 0.996633;  // flatting of the Earth

        int j, k1, k2, kmiss;
        double dpn1, pan1, s0, dlt, dta, ag;
        double s, r0, r2, dt1, dt2;
        Vec3 vrm, vre;
        Vec3 ubm, ube;
        Vec3 ax1, ax2;
        Mat3 mx1, mx2;
        Eclipse eclp;

        if (numpts < 2)
        {
            return;
        }

        for (j = 0; j < numpts; j++) // just in case you got to return empty-handed
        {
            lat[j] = 100.0;
            lng[j] = 0;
        }

        if (!eb_start_called)
        {
            eclStart();
        }

        if (eb_lunactive)
        {
            return;    // only for solar eclipses
        }

        if (umbra && (eb_phase[eb_eclselect - 1] < 1))
        {
            return;
        }

        // get the shadow details
        if (umbra)
        {
            eclp.umbra(mjd, eb_del_tdut, ubm, ube, dpn1, pan1);
        }

        else
        {
            eclp.penumd(mjd, eb_del_tdut, ubm, ube, dpn1, pan1);
        }

        dpn1 *= 0.5;

        if (!umbra)
        {
            if (eb_penamode == 0)
            {
                dpn1 *= eb_penangle;
                pan1 *= eb_penangle;
            }

            if (eb_penamode > 0)
            {
                s0 = eb_penangle * tan(pan1);
                s0 = atan(s0);

                if (pan1 > 0)
                {
                    dpn1 = dpn1 * s0 / pan1;
                    pan1 = s0;
                }
            }
        };

        // get apex of umbra/penumbra cone
        pan1 = tan(pan1);

        if (pan1 < 0.0000174533)
        {
            return;    // if cone is smaller that 0.001°
        }

        dpn1 = dpn1 / pan1;

        s0 = - dot(ubm, ube);
        ubm = ubm + (s0 - dpn1) * ube;

        // get any vector perpendicular to the shadow
        ax1[0] = 0;
        ax1[1] = 0;
        ax1[2] = 1.0;
        ax2 = ax1 * ube;
        ax1 = vnorm(ax2) * pan1;

        ax2 = carpol(ube);
        mx1 = zrot(ax2[1]);
        mx2 = yrot(ax2[2]) * mx1;  // transform to a system where x points into the direction of the shadow
        mx1 = mxtrn(mx1);  // to get back to equatorial system after rotation

        ax2 = mxvct(mx2, ax1); // vector which we will rotate numpts times

        // now loop for numpts points
        dta = 2.0 * M_PI / double(numpts);

        for (j = 0; j < numpts; j++)
        {
            ag = double(j) * dta;  // rotation angle of the cone vector
            mx2  = xrot(ag);
            ax1 = mxvct(mx2, ax2);
            ax1 = mxvct(mx1, ax1);

            vre = ube + ax1;
            vre = vnorm(vre);  // direction in which to find an intersection
            vrm[0] = ubm[0];
            vrm[1] = ubm[1];
            vrm[2] = ubm[2];

            s0 = - dot(vrm, vre); // distance Apex - fundamental plane
            r2 = dot(vrm, vrm);
            dlt = s0 * s0 + 1.0 - r2;
            r0 = 1.0 - dlt;

            if (r0 > 0)
            {
                r0 = sqrt(r0);
            }

            else
            {
                r0 = 0;    // distance center of Earth - shadow axis
            }

            // calculate the coordinates if there is an intersection
            if (r0 < 1.0)  // there should be an intersection
            {
                if (dlt > 0)
                {
                    dlt = sqrt(dlt);
                }

                else
                {
                    dlt = 0;
                }

                s = s0 - dlt;  // distance Apex - fundamental plane
                vrm = vrm + s * vre;
                vrm = vnorm(vrm);
                vrm[2] *= flat;    // vector to intersection
                vre = carpol(vrm);
                lng[j] = vre[1] - lsidtim(mjd, 0, 0) * 0.261799387799; // geographic coordinates

                if (lng[j] > 2 * M_PI)
                {
                    lng[j] -= 2.0 * M_PI;
                }

                if (lng[j] < 0.0)
                {
                    lng[j] += 2.0 * M_PI;
                }

                lat[j] = sqrt(vrm[0] * vrm[0] + vrm[1] * vrm[1]) * 0.993305615;
                lat[j] = atan23(vrm[2], lat[j]);
                lat[j] /= degrad;
                lng[j] /= degrad;

                if (lng[j] < 0.0)
                {
                    lng[j] += 360.0;
                }

                if (lng[j] > 360.0)
                {
                    lng[j] -= 360.0;
                }
            }

            else  // no intersection.
            {
                lat[j] = 100.0;
                lng[j] = 0;
            };
        }

        k1 = -1;
        k2 = -1;
        kmiss = 0;

        for (j = 0; j < numpts; j++) // check for missing points
        {
            if (lat[j] < 100.0)
            {
                if (k1 < 0)
                {
                    k1 = j;    // first valid point
                }

                k2 = j;              // last valid point
            }

            else
            {
                kmiss++;
            }
        }

        if ((kmiss < 2) || (kmiss >= (numpts - 1)))
        {
            return;    // cone completely on Earth surface or not at all
        }

        dt1 = double(k1) * dta;
        dt2 = double(k2) * dta;
        k1--;
        k2++;

        if (k1 < 0)
        {
            k1 = numpts - 1;    // wrap around
        }

        if (k2 >= (numpts - 1))
        {
            k2 = 0;
        }

        dta = 2.0 * M_PI / double(numpts * 20);

        for (j = 1; j < 20; j++) // go in smaller steps to get closer to the borderline
        {
            ag = dt1 - double(j) * dta;  // rotation angle of the cone vector
            mx2  = xrot(ag);
            ax1 = mxvct(mx2, ax2);
            ax1 = mxvct(mx1, ax1);

            vre = ube + ax1;
            vre = vnorm(vre);  // direction in which to find an intersection
            vrm[0] = ubm[0];
            vrm[1] = ubm[1];
            vrm[2] = ubm[2];

            s0 = - dot(vrm, vre); // distance Apex - fundamental plane
            r2 = dot(vrm, vrm);
            dlt = s0 * s0 + 1.0 - r2;
            r0 = 1.0 - dlt;

            if (r0 > 0)
            {
                r0 = sqrt(r0);
            }

            else
            {
                r0 = 0;    // distance center of Earth - shadow axis
            }

            // calculate the coordinates if there is an intersection
            if (r0 < 1.0)  // there should be an intersection
            {
                if (dlt > 0)
                {
                    dlt = sqrt(dlt);
                }

                else
                {
                    dlt = 0;
                }

                s = s0 - dlt;  // distance Apex - fundamental plane
                vrm = vrm + s * vre;
                vrm = vnorm(vrm);
                vrm[2] *= flat;    // vector to intersection
                vre = carpol(vrm);
                lng[k1] = vre[1] - lsidtim(mjd, 0, 0) * 0.261799387799; // geographic coordinates

                if (lng[k1] > 2 * M_PI)
                {
                    lng[k1] -= 2.0 * M_PI;
                }

                if (lng[k1] < 0.0)
                {
                    lng[k1] += 2.0 * M_PI;
                }

                lat[k1] = sqrt(vrm[0] * vrm[0] + vrm[1] * vrm[1]) * 0.993305615;
                lat[k1] = atan23(vrm[2], lat[k1]);
                lat[k1] /= degrad;
                lng[k1] /= degrad;

                if (lng[k1] < 0.0)
                {
                    lng[k1] += 360.0;
                }

                if (lng[k1] > 360.0)
                {
                    lng[k1] -= 360.0;
                }
            }

            else
            {
                break;
            }
        }

        for (j = 1; j < 20; j++) // go in smaller steps to get closer to the borderline
        {
            ag = dt2 + double(j) * dta;  // rotation angle of the cone vector
            mx2  = xrot(ag);
            ax1 = mxvct(mx2, ax2);
            ax1 = mxvct(mx1, ax1);

            vre = ube + ax1;
            vre = vnorm(vre);  // direction in which to find an intersection
            vrm[0] = ubm[0];
            vrm[1] = ubm[1];
            vrm[2] = ubm[2];

            s0 = - dot(vrm, vre); // distance Apex - fundamental plane
            r2 = dot(vrm, vrm);
            dlt = s0 * s0 + 1.0 - r2;
            r0 = 1.0 - dlt;

            if (r0 > 0)
            {
                r0 = sqrt(r0);
            }

            else
            {
                r0 = 0;    // distance center of Earth - shadow axis
            }

            // calculate the coordinates if there is an intersection
            if (r0 < 1.0)  // there should be an intersection
            {
                if (dlt > 0)
                {
                    dlt = sqrt(dlt);
                }

                else
                {
                    dlt = 0;
                }

                s = s0 - dlt;  // distance Apex - fundamental plane
                vrm = vrm + s * vre;
                vrm = vnorm(vrm);
                vrm[2] *= flat;    // vector to intersection
                vre = carpol(vrm);
                lng[k2] = vre[1] - lsidtim(mjd, 0, 0) * 0.261799387799; // geographic coordinates

                if (lng[k2] > 2 * M_PI)
                {
                    lng[k2] -= 2.0 * M_PI;
                }

                if (lng[k2] < 0.0)
                {
                    lng[k2] += 2.0 * M_PI;
                }

                lat[k2] = sqrt(vrm[0] * vrm[0] + vrm[1] * vrm[1]) * 0.993305615;
                lat[k2] = atan23(vrm[2], lat[k2]);
                lat[k2] /= degrad;
                lng[k2] /= degrad;

                if (lng[k2] < 0.0)
                {
                    lng[k2] += 360.0;
                }

                if (lng[k2] > 360.0)
                {
                    lng[k2] -= 360.0;
                }
            }

            else
            {
                break;
            }
        }
    }

    } // namespace Marble

    #if defined(Q_CC_CLANG)
    #   pragma clang diagnostic pop
    #endif