95_Astro.pm 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. ########################################################################################
  2. #
  3. # 95_Astro.pm
  4. #
  5. # Collection of various routines for astronomical data
  6. # Prof. Dr. Peter A. Henning
  7. #
  8. # Equations from "Practical Astronomy with your Calculator" by Peter Duffett-Smith
  9. # Program skeleton (with some errors) by Arnold Barmettler
  10. # http://lexikon.astronomie.info/java/sunmoon/
  11. #
  12. # $Id: 95_Astro.pm 15508 2017-11-27 15:24:42Z phenning $
  13. #
  14. ########################################################################################
  15. #
  16. # This programm is free software; you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation; either version 2 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # The GNU General Public License can be found at
  22. # http://www.gnu.org/copyleft/gpl.html.
  23. # A copy is found in the textfile GPL.txt and important notices to the license
  24. # from the author is found in LICENSE.txt distributed with these scripts.
  25. #
  26. # This script is distributed in the hope that it will be useful,
  27. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. # GNU General Public License for more details.
  30. #
  31. ########################################################################################
  32. package main;
  33. use strict;
  34. use warnings;
  35. use POSIX;
  36. use Math::Trig;
  37. use Time::Local;
  38. #use Data::Dumper;
  39. my $DEG = pi/180.0;
  40. my $RAD = 180./pi;
  41. my $deltaT = 65; # Correction time in s
  42. my %Astro;
  43. my %Date;
  44. my $astroversion = 1.42;
  45. #-- These we may get on request
  46. my %gets = (
  47. "version" => "V",
  48. "json" => "J",
  49. "text" => "T"
  50. );
  51. my $astro_tt;
  52. my %astro_transtable_EN = (
  53. "overview" => "Summary",
  54. "name" => "Name",
  55. "time" => "Time",
  56. "action" => "Action",
  57. "type" => "Type",
  58. "description" => "Description",
  59. "profile" => "Profile",
  60. #--
  61. "coord" => "Coordinates",
  62. "position" => "Position",
  63. "longitude" => "Longitude",
  64. "latitude" => "Latitude",
  65. "altitude" => "Height above sea",
  66. "lonecl" => "Ecliptical longitude",
  67. "latecl" => "Ecliptical latitude",
  68. "ra" => "Right ascension",
  69. "dec" => "Declination",
  70. "az" => "Azimuth",
  71. "alt" => "Horizontal altitude",
  72. "age" => "Age",
  73. "rise" => "Rise",
  74. "set" => "Set",
  75. "transit" => "Transit",
  76. "distance" => "Distance",
  77. "diameter" => "Diameter",
  78. "toobs" => "to observer",
  79. "toce" => "to Earth center",
  80. "twilightcivil" => "Civil twilight",
  81. "twilightnautic" => "Nautical twilight",
  82. "twilightastro" => "Astronomical twilight",
  83. "twilightcustom" => "Custom twilight",
  84. "sign" => "Zodiac sign",
  85. #--
  86. "today" => "Today",
  87. "tomorrow" => "Tomorrow",
  88. "weekday" => "Day of Week",
  89. "date" => "Date",
  90. "jdate" => "Julian date",
  91. "dayofyear" => "day of year",
  92. "days" => "days",
  93. "timezone" => "Time Zone",
  94. "lmst" => "Local Sidereal Time",
  95. #--
  96. "monday" => ["Monday","Mon"],
  97. "tuesday" => ["Tuesday","Tue"],
  98. "wednesday" => ["Wednesday","Wed"],
  99. "thursday" => ["Thursday","Thu"],
  100. "friday" => ["Friday","Fri"],
  101. "saturday" => ["Saturday","Sat"],
  102. "sunday" => ["Sunday","Sun"],
  103. #--
  104. "season" => "Season",
  105. "spring" => "Spring",
  106. "summer" => "Summer",
  107. "fall" => "Fall",
  108. "winter" => "Winter",
  109. #--
  110. "aries" => "Ram",
  111. "taurus" => "Bull",
  112. "gemini" => "Twins",
  113. "cancer" => "Crab",
  114. "leo" => "Lion",
  115. "virgo" => "Maiden",
  116. "libra" => "Scales",
  117. "scorpio" => "Scorpion",
  118. "sagittarius" => "Archer",
  119. "capricorn" => "Goat",
  120. "aquarius" => "Water Bearer",
  121. "pisces" => "Fish",
  122. #--
  123. "sun" => "Sun",
  124. #--
  125. "moon" => "Moon",
  126. "phase" => "Phase",
  127. "newmoon" => "New Moon",
  128. "waxingcrescent" => "Waxing Crescent",
  129. "firstquarter" => "First Quarter",
  130. "waxingmoon" => "Waxing Moon",
  131. "fullmoon" => "Full Moon",
  132. "waningmoon" => "Waning Moon",
  133. "lastquarter" => "Last Quarter",
  134. "waningcrescent" => "Waning Crescent"
  135. );
  136. my %astro_transtable_DE = (
  137. "overview" => "Zusammenfassung",
  138. "name" => "Name",
  139. "time" => "Zeit",
  140. "action" => "Aktion",
  141. "type" => "Typ",
  142. "description" => "Beschreibung",
  143. "profile" => "Profil",
  144. #--
  145. "coord" => "Koordinaten",
  146. "position" => "Position",
  147. "longitude" => "Länge",
  148. "latitude" => "Breite",
  149. "altitude" => "Höhe ü.M.",
  150. "lonecl" => "Eklipt. Länge",
  151. "latecl" => "Eklipt. Breite",
  152. "ra" => "Rektaszension",
  153. "dec" => "Deklination",
  154. "az" => "Azimut",
  155. "alt" => "Horizontwinkel",
  156. "age" => "Alter",
  157. "phase" => "Phase",
  158. "rise" => "Aufgang",
  159. "set" => "Untergang",
  160. "transit" => "Kulmination",
  161. "distance" => "Entfernung",
  162. "diameter" => "Durchmesser",
  163. "toobs" => "z. Beobachter",
  164. "toce" => "z. Erdmittelpunkt",
  165. "twilightcivil" => "Bürgerliche Dämmerung",
  166. "twilightnautic" => "Nautische Dämmerung",
  167. "twilightastro" => "Astronomische Dämmerung",
  168. "twilightcustom" => "Konfigurierte Dämmerung",
  169. "sign" => "Tierkreiszeichen",
  170. #--
  171. "today" => "Heute",
  172. "tomorrow" => "Morgen",
  173. "weekday" => "Wochentag",
  174. "date" => "Datum",
  175. "jdate" => "Julianisches Datum",
  176. "dayofyear" => "Tag d. Jahres",
  177. "days" => "Tage",
  178. "timezone" => "Zeitzone",
  179. "lmst" => "Lokale Sternzeit",
  180. #--
  181. "monday" => ["Montag","Mo"],
  182. "tuesday" => ["Dienstag","Di"],
  183. "wednesday" => ["Mittwoch","Mi"],
  184. "thursday" => ["Donnerstag","Do"],
  185. "friday" => ["Freitag","Fr"],
  186. "saturday" => ["Samstag","Sa"],
  187. "sunday" => ["Sonntag","So"],
  188. #--
  189. "season" => "Jahreszeit",
  190. "spring" => "Frühling",
  191. "summer" => "Sommer",
  192. "fall" => "Herbst",
  193. "winter" => "Winter",
  194. #--
  195. "aries" => "Widder",
  196. "taurus" => "Stier",
  197. "gemini" => "Zwillinge",
  198. "cancer" => "Krebs",
  199. "leo" => "Löwe",
  200. "virgo" => "Jungfrau",
  201. "libra" => "Waage",
  202. "scorpio" => "Skorpion",
  203. "sagittarius" => "Schütze",
  204. "capricorn" => "Steinbock",
  205. "aquarius" => "Wassermann",
  206. "pisces" => "Fische",
  207. #--
  208. "sun" => "Sonne",
  209. #--
  210. "moon" => "Mond",
  211. "phase" => "Phase",
  212. "newmoon" => "Neumond",
  213. "waxingcrescent" => "Zunehmende Sichel",
  214. "firstquarter" => "Erstes Viertel",
  215. "waxingmoon" => "Zunehmender Mond",
  216. "fullmoon" => "Vollmond",
  217. "waningmoon" => "Abnehmender Mond",
  218. "lastquarter" => "Letztes Viertel",
  219. "waningcrescent" => "Abnehmende Sichel"
  220. );
  221. my @zodiac=("aries","taurus","gemini","cancer","leo","virgo",
  222. "libra","scorpio","sagittarius","capricorn","aquarius","pisces");
  223. my @phases = ("newmoon","waxingcrescent", "firstquarter", "waxingmoon",
  224. "fullmoon", "waningmoon", "lastquarter", "waningcrescent");
  225. my @seasons = (
  226. "winter","spring","summer","fall");
  227. my %seasonn = (
  228. "spring" => [80,172], #21./22.3. - 20.6.
  229. "summer" => [173,265], #21.06. bis 21./22.09.
  230. "fall" => [266,353], #22./23.09. bis 20./21.12.
  231. "winter" => [354,79]
  232. );
  233. sub Astro_SunRise($$$$$$);
  234. sub Astro_MoonRise($$$$$$$);
  235. ########################################################################################################
  236. #
  237. # Astro_Initialize
  238. #
  239. # Parameter hash = hash of device addressed
  240. #
  241. ########################################################################################################
  242. sub Astro_Initialize ($) {
  243. my ($hash) = @_;
  244. $hash->{DefFn} = "Astro_Define";
  245. #$hash->{SetFn} = "Astro_Set";
  246. $hash->{GetFn} = "Astro_Get";
  247. $hash->{UndefFn} = "Astro_Undef";
  248. $hash->{AttrFn} = "Astro_Attr";
  249. $hash->{AttrList} = "interval longitude latitude altitude horizon ".$readingFnAttributes;;
  250. $data{FWEXT}{"/Astro_moonwidget"}{FUNC} = "Astro_moonwidget";
  251. $data{FWEXT}{"/Astr_moonwidget"}{FORKABLE} = 0;
  252. return undef;
  253. }
  254. ########################################################################################################
  255. #
  256. # Astro_Define - Implements DefFn function
  257. #
  258. # Parameter hash = hash of device addressed, def = definition string
  259. #
  260. ########################################################################################################
  261. sub Astro_Define ($$) {
  262. my ($hash, $def) = @_;
  263. #my $now = time();
  264. my $name = $hash->{NAME};
  265. $hash->{VERSION} = $astroversion;
  266. readingsSingleUpdate( $hash, "state", "Initialized", 1 );
  267. $modules{Astro}{defptr}{$name} = $hash;
  268. RemoveInternalTimer($hash);
  269. #-- Call us in n seconds again.
  270. InternalTimer(gettimeofday()+ 60, "Astro_Update", $hash,0);
  271. return undef;
  272. }
  273. ########################################################################################################
  274. #
  275. # Astro_Undef - Implements Undef function
  276. #
  277. # Parameter hash = hash of device addressed, def = definition string
  278. #
  279. ########################################################################################################
  280. sub Astro_Undef ($$) {
  281. my ($hash,$arg) = @_;
  282. RemoveInternalTimer($hash);
  283. return undef;
  284. }
  285. ########################################################################################################
  286. #
  287. # Astro_Attr - Implements Attr function
  288. #
  289. # Parameter hash = hash of device addressed, ???
  290. #
  291. ########################################################################################################
  292. sub Astro_Attr(@) {
  293. my ($do,$name,$key,$value) = @_;
  294. my $hash = $defs{$name};
  295. my $ret;
  296. if ( $do eq "set") {
  297. ARGUMENT_HANDLER: {
  298. #-- interval modified at runtime
  299. $key eq "interval" and do {
  300. #-- check value
  301. return "[Astro] set $name interval must be >= 0" if(int($value) < 0);
  302. #-- update timer
  303. $hash->{INTERVAL} = int($value);
  304. if ($init_done) {
  305. RemoveInternalTimer($hash);
  306. InternalTimer(gettimeofday()+$hash->{INTERVAL}, "Astro_Update", $hash, 0);
  307. }
  308. last;
  309. };
  310. }
  311. }
  312. return $ret;
  313. }
  314. sub Astro_mod($$) { my ($a,$b)=@_;if( $a =~ /\d*\.\d*/){return($a-floor($a/$b)*$b)}else{return undef}; }
  315. sub Astro_mod2Pi($) { my ($x)=@_;$x = Astro_mod($x, 2.*pi);return($x); }
  316. sub Astro_round($$) { my ($x,$n)=@_; return int(10**$n*$x+0.5)/10**$n};
  317. sub Astro_tzoffset($) {
  318. my ($t) = @_;
  319. my $utc = mktime(gmtime($t));
  320. my $local = mktime(localtime($t));
  321. return (($local - $utc)/36);
  322. }
  323. ########################################################################################################
  324. #
  325. # time fragments into minutes, seconds
  326. #
  327. ########################################################################################################
  328. sub Astro_HHMM($){
  329. my ($hh) = @_;
  330. return("")
  331. if (!defined($hh) || $hh !~ /\d*\.\d*/) ;
  332. my $h = floor($hh);
  333. my $m = ($hh-$h)*60.;
  334. return sprintf("%02d:%02d",$h,$m);
  335. }
  336. sub Astro_HHMMSS($){
  337. my ($hh) = @_;
  338. return("")
  339. if ($hh==0) ;
  340. my $m = ($hh-floor($hh))*60.;
  341. my $s = ($m-floor($m))*60;
  342. my $h = floor($hh);
  343. return sprintf("%02d:%02d:%02d",$h,$m,$s);
  344. }
  345. ########################################################################################################
  346. #
  347. # Astro_CalcJD - Calculate Julian date: valid only from 1.3.1901 to 28.2.2100
  348. #
  349. ########################################################################################################
  350. sub Astro_CalcJD($$$) {
  351. my ($day,$month,$year) = @_;
  352. my $jd = 2415020.5-64; # 1.1.1900 - correction of algorithm
  353. if ($month<=2) {
  354. $year--;
  355. $month += 12;
  356. }
  357. $jd += int( ($year-1900)*365.25 );
  358. $jd += int( 30.6001*(1+$month) );
  359. return($jd + $day);
  360. }
  361. ########################################################################################################
  362. #
  363. # Astro_GMST - Julian Date to Greenwich Mean Sidereal Time
  364. #
  365. ########################################################################################################
  366. sub Astro_GMST($){
  367. my ($JD) = @_;
  368. my $UT = ($JD-0.5) - int($JD-0.5);
  369. $UT = $UT*24.; # UT in hours
  370. $JD = floor($JD-0.5)+0.5; # JD at 0 hours UT
  371. my $T = ($JD-2451545.0)/36525.0;
  372. my $T0 = 6.697374558 + $T*(2400.051336 + $T*0.000025862);
  373. return( Astro_mod($T0+$UT*1.002737909,24.));
  374. }
  375. ########################################################################################################
  376. #
  377. # Astro_GMST2UT - Convert Greenweek mean sidereal time to UT
  378. #
  379. ########################################################################################################
  380. sub Astro_GMST2UT($$){
  381. my ($JD, $gmst) = @_;
  382. $JD = floor($JD-0.5)+0.5; # JD at 0 hours UT
  383. my $T = ($JD-2451545.0)/36525.0;
  384. my $T0 = Astro_mod(6.697374558 + $T*(2400.051336 + $T*0.000025862), 24.);
  385. my $UT = 0.9972695663*(($gmst-$T0));
  386. return($UT);
  387. }
  388. ########################################################################################################
  389. #
  390. # Astro_GMST2LMST - Local Mean Sidereal Time, geographical longitude in radians,
  391. # East is positive
  392. #
  393. ########################################################################################################
  394. sub Astro_GMST2LMST($$){
  395. my ($gmst, $lon) = @_;
  396. my $lmst = Astro_mod($gmst+$RAD*$lon/15, 24.);
  397. return( $lmst );
  398. }
  399. ########################################################################################################
  400. #
  401. # Astro_Ecl2Equ - Transform ecliptical coordinates (lon/lat) to equatorial coordinates (RA/dec)
  402. #
  403. ########################################################################################################
  404. sub Astro_Ecl2Equ($$$){
  405. my ($lon, $lat, $TDT) = @_;
  406. my $T = ($TDT-2451545.0)/36525.; # Epoch 2000 January 1.5
  407. my $eps = (23.+(26+21.45/60.)/60. + $T*(-46.815 +$T*(-0.0006 + $T*0.00181) )/3600. )*$DEG;
  408. my $coseps = cos($eps);
  409. my $sineps = sin($eps);
  410. my $sinlon = sin($lon);
  411. my $ra = Astro_mod2Pi(atan2( ($sinlon*$coseps-tan($lat)*$sineps), cos($lon) ));
  412. my $dec = asin( sin($lat)*$coseps + cos($lat)*$sineps*$sinlon );
  413. return ($ra,$dec);
  414. }
  415. ########################################################################################################
  416. #
  417. # Astro_Equ2Altaz - Transform equatorial coordinates (RA/Dec) to horizonal coordinates
  418. # (azimuth/altitude). Refraction is ignored
  419. #
  420. ########################################################################################################
  421. sub Astro_Equ2Altaz($$$$$){
  422. my ($ra, $dec, $TDT, $lat, $lmst)=@_;
  423. my $cosdec = cos($dec);
  424. my $sindec = sin($dec);
  425. my $lha = $lmst - $ra;
  426. my $coslha = cos($lha);
  427. my $sinlha = sin($lha);
  428. my $coslat = cos($lat);
  429. my $sinlat = sin($lat);
  430. my $N = -$cosdec * $sinlha;
  431. my $D = $sindec * $coslat - $cosdec * $coslha * $sinlat;
  432. my $az = Astro_mod2Pi( atan2($N, $D) );
  433. my $alt = asin( $sindec * $sinlat + $cosdec * $coslha * $coslat );
  434. return ($az,$alt);
  435. }
  436. ########################################################################################################
  437. #
  438. # Astro_GeoEqu2TopoEqu - Transform geocentric equatorial coordinates (RA/Dec) to
  439. # topocentric equatorial coordinates
  440. #
  441. ########################################################################################################
  442. sub Astro_GeoEqu2TopoEqu($$$$$$$){
  443. my ($ra, $dec, $distance, $lon, $lat, $radius, $lmst) = @_;
  444. my $cosdec = cos($dec);
  445. my $sindec = sin($dec);
  446. my $coslst = cos($lmst);
  447. my $sinlst = sin($lmst);
  448. my $coslat = cos($lat); # we should use geocentric latitude, not geodetic latitude
  449. my $sinlat = sin($lat);
  450. my $rho = $radius; # observer-geocenter in km
  451. my $x = $distance*$cosdec*cos($ra) - $rho*$coslat*$coslst;
  452. my $y = $distance*$cosdec*sin($ra) - $rho*$coslat*$sinlst;
  453. my $z = $distance*$sindec - $rho*$sinlat;
  454. my $distanceTopocentric = sqrt($x*$x + $y*$y + $z*$z);
  455. my $decTopocentric = asin($z/$distanceTopocentric);
  456. my $raTopocentric = Astro_mod2Pi( atan2($y, $x) );
  457. return ( ($distanceTopocentric,$decTopocentric,$raTopocentric) );
  458. }
  459. ########################################################################################################
  460. #
  461. # Astro_EquPolar2Cart - Calculate cartesian from polar coordinates
  462. #
  463. ########################################################################################################
  464. sub Astro_EquPolar2Cart($$$){
  465. my ($lon,$lat,$distance) = @_;
  466. my $rcd = cos($lat)*$distance;
  467. my $x = $rcd*cos($lon);
  468. my $y = $rcd*sin($lon);
  469. my $z = sin($lat)*$distance;
  470. return( ($x,$y,$z) );
  471. }
  472. ########################################################################################################
  473. #
  474. # Astro_Observer2EquCart - Calculate observers cartesian equatorial coordinates (x,y,z in celestial frame)
  475. # from geodetic coordinates (longitude, latitude, height above WGS84 ellipsoid)
  476. # Currently only used to calculate distance of a body from the observer
  477. #
  478. ########################################################################################################
  479. sub Astro_Observer2EquCart($$$$){
  480. my ($lon, $lat, $height, $gmst ) = @_;
  481. my $flat = 298.257223563; # WGS84 flatening of earth
  482. my $aearth = 6378.137; # GRS80/WGS84 semi major axis of earth ellipsoid
  483. #-- Calculate geocentric latitude from geodetic latitude
  484. my $co = cos ($lat);
  485. my $si = sin ($lat);
  486. $si = $si * $si;
  487. my $fl = 1.0 - 1.0 / $flat;
  488. $fl = $fl * $fl;
  489. my $u = 1.0 / sqrt ($co * $co + $fl * $si);
  490. my $a = $aearth * $u + $height;
  491. my $b = $aearth * $fl * $u + $height;
  492. my $radius = sqrt ($a * $a * $co *$co + $b *$b * $si); # geocentric distance from earth center
  493. my $y = acos ($a * $co / $radius); # geocentric latitude, rad
  494. my $x = $lon; # longitude stays the same
  495. my $z;
  496. if ($lat < 0.0) { $y = -$y; } # adjust sign
  497. #-- convert from geocentric polar to geocentric cartesian, with regard to Greenwich
  498. ($x,$y,$z) = Astro_EquPolar2Cart( $x, $y, $radius );
  499. #-- rotate around earth's polar axis to align coordinate system from Greenwich to vernal equinox
  500. my $rotangle = $gmst/24*2*pi; # sideral time gmst given in hours. Convert to radians
  501. my $x2 = $x*cos($rotangle) - $y*sin($rotangle);
  502. my $y2 = $x*sin($rotangle) + $y*cos($rotangle);
  503. return( ($x2,$y2,$z,$radius) );
  504. }
  505. ########################################################################################################
  506. #
  507. # Astro_SunPosition - Calculate coordinates for Sun
  508. # Coordinates are accurate to about 10s (right ascension)
  509. # and a few minutes of arc (declination)
  510. #
  511. ########################################################################################################
  512. sub Astro_SunPosition($$$){
  513. my ($TDT, $observerlat, $lmst)=@_;
  514. my $D = $TDT-2447891.5;
  515. my $eg = 279.403303*$DEG;
  516. my $wg = 282.768422*$DEG;
  517. my $e = 0.016713;
  518. my $a = 149598500; # km
  519. #-- mean angular diameter of sun
  520. my $diameter0 = 0.533128*$DEG;
  521. my $MSun = 360*$DEG/365.242191*$D+$eg-$wg;
  522. my $nu = $MSun + 360.*$DEG/pi*$e*sin($MSun);
  523. my %sunCoor;
  524. $sunCoor{lon} = Astro_mod2Pi($nu+$wg);
  525. $sunCoor{lat} = 0;
  526. $sunCoor{anomalyMean} = $MSun;
  527. my $distance = (1-$e*$e)/(1+$e*cos($nu)); # distance in astronomical units
  528. $sunCoor{diameter} = $diameter0/$distance; # angular diameter
  529. $sunCoor{distance} = $distance*$a; # distance in km
  530. $sunCoor{parallax} = 6378.137/$sunCoor{distance}; # horizonal parallax
  531. ($sunCoor{ra},$sunCoor{dec}) = Astro_Ecl2Equ($sunCoor{lon}, $sunCoor{lat}, $TDT);
  532. #-- calculate horizonal coordinates of sun, if geographic positions is given
  533. if (defined($observerlat) && defined($lmst) ) {
  534. ($sunCoor{az},$sunCoor{alt}) = Astro_Equ2Altaz($sunCoor{ra}, $sunCoor{dec}, $TDT, $observerlat, $lmst);
  535. }
  536. $sunCoor{sig} = $zodiac[floor($sunCoor{lon}*$RAD/30)];
  537. return ( \%sunCoor );
  538. }
  539. ########################################################################################################
  540. #
  541. # Astro_MoonPosition - Calculate data and coordinates for the Moon
  542. # Coordinates are accurate to about 1/5 degree (in ecliptic coordinates)
  543. #
  544. ########################################################################################################
  545. sub Astro_MoonPosition($$$$$$$){
  546. my ($sunlon, $sunanomalyMean, $TDT, $observerlon, $observerlat, $observerradius, $lmst) = @_;
  547. my $D = $TDT-2447891.5;
  548. #-- Mean Moon orbit elements as of 1990.0
  549. my $l0 = 318.351648*$DEG;
  550. my $P0 = 36.340410*$DEG;
  551. my $N0 = 318.510107*$DEG;
  552. my $i = 5.145396*$DEG;
  553. my $e = 0.054900;
  554. my $a = 384401; # km
  555. my $diameter0 = 0.5181*$DEG; # angular diameter of Moon at a distance
  556. my $parallax0 = 0.9507*$DEG; # parallax at distance a
  557. my $l = 13.1763966*$DEG*$D+$l0;
  558. my $MMoon = $l-0.1114041*$DEG*$D-$P0; # Moon's mean anomaly M
  559. my $N = $N0-0.0529539*$DEG*$D; # Moon's mean ascending node longitude
  560. my $C = $l-$sunlon;
  561. my $Ev = 1.2739*$DEG*sin(2*$C-$MMoon);
  562. my $Ae = 0.1858*$DEG*sin($sunanomalyMean);
  563. my $A3 = 0.37*$DEG*sin($sunanomalyMean);
  564. my $MMoon2 = $MMoon+$Ev-$Ae-$A3; # corrected Moon anomaly
  565. my $Ec = 6.2886*$DEG*sin($MMoon2); # equation of centre
  566. my $A4 = 0.214*$DEG*sin(2*$MMoon2);
  567. my $l2 = $l+$Ev+$Ec-$Ae+$A4; # corrected Moon's longitude
  568. my $V = 0.6583*$DEG*sin(2*($l2-$sunlon));
  569. my $l3 = $l2+$V; # true orbital longitude;
  570. my $N2 = $N-0.16*$DEG*sin($sunanomalyMean);
  571. my %moonCoor;
  572. $moonCoor{lon} = Astro_mod2Pi( $N2 + atan2( sin($l3-$N2)*cos($i), cos($l3-$N2) ) );
  573. $moonCoor{lat} = asin( sin($l3-$N2)*sin($i) );
  574. $moonCoor{orbitLon} = $l3;
  575. ($moonCoor{ra},$moonCoor{dec}) = Astro_Ecl2Equ($moonCoor{lon},$moonCoor{lat},$TDT);
  576. #-- relative distance to semi mayor axis of lunar oribt
  577. my $distance = (1-$e*$e) / (1+$e*cos($MMoon2+$Ec) );
  578. $moonCoor{diameter} = $diameter0/$distance; # angular diameter in radians
  579. $moonCoor{parallax} = $parallax0/$distance; # horizontal parallax in radians
  580. $moonCoor{distance} = $distance*$a; # distance in km
  581. #-- Calculate horizonal coordinates of moon, if geographic positions is given
  582. #-- backup geocentric coordinates
  583. $moonCoor{raGeocentric} = $moonCoor{ra};
  584. $moonCoor{decGeocentric} = $moonCoor{dec};
  585. $moonCoor{distanceGeocentric} = $moonCoor{distance};
  586. if (defined($observerlat) && defined($observerlon) && defined($lmst) ) {
  587. #-- transform geocentric coordinates into topocentric (==observer based) coordinates
  588. my ($distanceTopocentric,$decTopocentric,$raTopocentric) =
  589. Astro_GeoEqu2TopoEqu($moonCoor{ra}, $moonCoor{dec}, $moonCoor{distance}, $observerlon, $observerlat, $observerradius, $lmst);
  590. #-- now ra and dec are topocentric
  591. $moonCoor{ra} = $raTopocentric;
  592. $moonCoor{dec} = $decTopocentric;
  593. ($moonCoor{az},$moonCoor{alt})= Astro_Equ2Altaz($moonCoor{ra}, $moonCoor{dec}, $TDT, $observerlat, $lmst);
  594. }
  595. #-- Age of Moon in radians since New Moon (0) - Full Moon (pi)
  596. $moonCoor{age} = Astro_mod2Pi($l3-$sunlon);
  597. $moonCoor{phasen} = 0.5*(1-cos($moonCoor{age})); # Moon phase numerical, 0-1
  598. my $mainPhase = 1./29.53*360*$DEG; # show 'Newmoon, 'Quarter' for +/-1 day around the actual event
  599. my $p = Astro_mod($moonCoor{age}, 90.*$DEG);
  600. if ($p < $mainPhase || $p > 90*$DEG-$mainPhase){
  601. $p = 2*floor($moonCoor{age} / (90.*$DEG)+0.5);
  602. }else{
  603. $p = 2*floor($moonCoor{age} / (90.*$DEG))+1;
  604. }
  605. $p = $p % 8;
  606. $moonCoor{phases} = $phases[$p];
  607. $moonCoor{phasei} = $p;
  608. $moonCoor{sig} = $zodiac[floor($moonCoor{lon}*$RAD/30)];
  609. return ( \%moonCoor );
  610. }
  611. ########################################################################################################
  612. #
  613. # Astro_Refraction - Input true altitude in radians, Output: increase in altitude in degrees
  614. #
  615. ########################################################################################################
  616. sub Astro_Refraction($){
  617. my ($alt) = @_;
  618. my $altdeg = $alt*$RAD;
  619. if ($altdeg<-2 || $altdeg>=90){
  620. return(0);
  621. }
  622. my $pressure = 1015;
  623. my $temperature = 10;
  624. if ($altdeg>15){
  625. return( 0.00452*$pressure/( (273+$temperature)*tan($alt)) );
  626. }
  627. my $y = $alt;
  628. my $D = 0.0;
  629. my $P = ($pressure-80.)/930.;
  630. my $Q = 0.0048*($temperature-10.);
  631. my $y0 = $y;
  632. my $D0 = $D;
  633. my $N;
  634. for (my $i=0; $i<3; $i++) {
  635. $N = $y+(7.31/($y+4.4));
  636. $N = 1./tan($N*$DEG);
  637. $D = $N*$P/(60.+$Q*($N+39.));
  638. $N = $y-$y0;
  639. $y0 = $D-$D0-$N;
  640. if (($N != 0.) && ($y0 != 0.)) {
  641. $N = $y-$N*($alt+$D-$y)/$y0;
  642. } else {
  643. $N = $alt+$D;
  644. }
  645. $y0 = $y;
  646. $D0 = $D;
  647. $y = $N;
  648. }
  649. return( $D );
  650. }
  651. ########################################################################################################
  652. #
  653. # Astro_GMSTRiseSet - returns Greenwich sidereal time (hours) of time of rise
  654. # and set of object with coordinates ra/dec
  655. # at geographic position lon/lat (all values in radians)
  656. # Correction for refraction and semi-diameter/parallax of body is taken care of in function RiseSet
  657. # h is used to calculate the twilights. It gives the required elevation of the disk center of the sun
  658. #
  659. ########################################################################################################
  660. sub Astro_GMSTRiseSet($$$$$){
  661. my ($ra, $dec, $lon, $lat, $h) = @_;
  662. $h = (defined($h)) ? $h : 0.0; # set default value
  663. #Log 1,"-------------------> Called Astro_GMSTRiseSet with $ra $dec $lon $lat $h";
  664. # my $tagbogen = acos(-tan(lat)*tan(coor.dec)); // simple formula if twilight is not required
  665. my $tagbogen = acos((sin($h) - sin($lat)*sin($dec)) / (cos($lat)*cos($dec)));
  666. my $transit = $RAD/15*( +$ra-$lon);
  667. my $rise = 24.+$RAD/15*(-$tagbogen+$ra-$lon); # calculate GMST of rise of object
  668. my $set = $RAD/15*(+$tagbogen+$ra-$lon); # calculate GMST of set of object
  669. #--Using the modulo function Astro_mod, the day number goes missing. This may get a problem for the moon
  670. $transit = Astro_mod($transit, 24);
  671. $rise = Astro_mod($rise, 24);
  672. $set = Astro_mod($set, 24);
  673. return( ($transit, $rise, $set) );
  674. }
  675. ########################################################################################################
  676. #
  677. # Astro_InterpolateGMST - Find GMST of rise/set of object from the two calculated
  678. # (start)points (day 1 and 2) and at midnight UT(0)
  679. #
  680. ########################################################################################################
  681. sub Astro_InterpolateGMST($$$$){
  682. my ($gmst0, $gmst1, $gmst2, $timefactor) = @_;
  683. return( ($timefactor*24.07*$gmst1- $gmst0*($gmst2-$gmst1)) / ($timefactor*24.07+$gmst1-$gmst2) );
  684. }
  685. ########################################################################################################
  686. #
  687. # Astro_RiseSet
  688. # // JD is the Julian Date of 0h UTC time (midnight)
  689. #
  690. ########################################################################################################
  691. sub Astro_RiseSet($$$$$$$$$$$){
  692. my ($jd0UT, $diameter, $parallax, $ra1, $dec1, $ra2, $dec2, $lon, $lat, $timeinterval, $altip) = @_;
  693. #--altitude of sun center: semi-diameter, horizontal parallax and (standard) refraction of 34'
  694. # true height of sun center for sunrise and set calculation. Is kept 0 for twilight (ie. altitude given):
  695. my $alt = (!defined($altip)) ? 0.5*$diameter-$parallax+34./60*$DEG : 0.;
  696. my $altitude = (!defined($altip)) ? 0. : $altip;
  697. my ($transit1, $rise1, $set1) = Astro_GMSTRiseSet($ra1, $dec1, $lon, $lat, $altitude);
  698. my ($transit2, $rise2, $set2) = Astro_GMSTRiseSet($ra2, $dec2, $lon, $lat, $altitude);
  699. #-- unwrap GMST in case we move across 24h -> 0h
  700. $transit2 += 24
  701. if ($transit1 > $transit2 && abs($transit1-$transit2)>18);
  702. $rise2 += 24
  703. if ($rise1 > $rise2 && abs($rise1-$rise2)>18);
  704. $set2 += 24
  705. if ($set1 > $set2 && abs($set1-$set2)>18);
  706. my $T0 = Astro_GMST($jd0UT);
  707. # my $T02 = T0-zone*1.002738; // Greenwich sidereal time at 0h time zone (zone: hours)
  708. #-- Greenwich sidereal time for 0h at selected longitude
  709. my $T02 = $T0-$lon*$RAD/15*1.002738;
  710. $T02 +=24 if ($T02 < 0);
  711. if ($transit1 < $T02) {
  712. $transit1 += 24;
  713. $transit2 += 24;
  714. }
  715. if ($rise1 < $T02) {
  716. $rise1 += 24;
  717. $rise2 += 24;
  718. }
  719. if ($set1 < $T02) {
  720. $set1 += 24;
  721. $set2 += 24;
  722. }
  723. #-- Refraction and Parallax correction
  724. my $decMean = 0.5*($dec1+$dec2);
  725. my $psi = acos(sin($lat)/cos($decMean));
  726. my $y = asin(sin($alt)/sin($psi));
  727. my $dt = 240*$RAD*$y/cos($decMean)/3600; # time correction due to refraction, parallax
  728. my $transit = Astro_GMST2UT( $jd0UT, Astro_InterpolateGMST( $T0, $transit1, $transit2, $timeinterval) );
  729. my $rise = Astro_GMST2UT( $jd0UT, Astro_InterpolateGMST( $T0, $rise1, $rise2, $timeinterval) - $dt );
  730. my $set = Astro_GMST2UT( $jd0UT, Astro_InterpolateGMST( $T0, $set1, $set2, $timeinterval) + $dt );
  731. return( ($transit,$rise,$set) );
  732. }
  733. ########################################################################################################
  734. #
  735. # Astro_SunRise - Find (local) time of sunrise and sunset, and twilights
  736. # JD is the Julian Date of 0h local time (midnight)
  737. # Accurate to about 1-2 minutes
  738. # recursive: 1 - calculate rise/set in UTC in a second run
  739. # recursive: 0 - find rise/set on the current local day.
  740. # This is set when doing the first call to this function
  741. #
  742. ########################################################################################################
  743. sub Astro_SunRise($$$$$$){
  744. my ($JD, $deltaT, $lon, $lat, $zone, $recursive) = @_;
  745. my $jd0UT = floor($JD-0.5)+0.5; # JD at 0 hours UT
  746. #-- calculations for noon
  747. my $sunCoor1 = Astro_SunPosition($jd0UT+ $deltaT/24./3600.,undef,undef);
  748. #-- calculations for next day's UTC midnight
  749. my $sunCoor2 = Astro_SunPosition($jd0UT+1.+$deltaT/24./3600.,undef,undef);
  750. #-- rise/set time in UTC
  751. my ($transit,$rise,$set) = Astro_RiseSet($jd0UT, $sunCoor1->{diameter}, $sunCoor1->{parallax},
  752. $sunCoor1->{ra}, $sunCoor1->{dec}, $sunCoor2->{ra}, $sunCoor2->{dec}, $lon, $lat, 1,undef);
  753. my ($transittemp,$risetemp,$settemp);
  754. #-- check and adjust to have rise/set time on local calendar day
  755. if ( $recursive==0 ) {
  756. if ($zone>0) {
  757. #rise time was yesterday local time -> calculate rise time for next UTC day
  758. if ($rise >=24-$zone || $transit>=24-$zone || $set>=24-$zone) {
  759. ($transittemp,$risetemp,$settemp) = Astro_SunRise($JD+1, $deltaT, $lon, $lat, $zone, 1);
  760. $transit = $transittemp
  761. if ($transit>=24-$zone);
  762. $rise = $risetemp
  763. if ($rise>=24-$zone);
  764. $set = $settemp
  765. if ($set>=24-$zone);
  766. }
  767. }elsif ($zone<0) {
  768. #rise time was yesterday local time -> calculate rise time for previous UTC day
  769. if ($rise<-$zone || $transit<-zone || $set<-zone) {
  770. ($transittemp,$risetemp,$settemp) = Astro_SunRise($JD-1, $deltaT, $lon, $lat, $zone, 1);
  771. $rise = $risetemp
  772. if ($rise<-$zone);
  773. $transit = $transittemp
  774. if ($transit<-$zone);
  775. $set = $settemp
  776. if ($set <-$zone);
  777. }
  778. }
  779. $transit = Astro_mod($transit+$zone, 24.);
  780. $rise = Astro_mod($rise +$zone, 24.);
  781. $set = Astro_mod($set +$zone, 24.);
  782. #-- Twilight calculation
  783. #-- civil twilight time in UTC.
  784. ($transittemp,$risetemp,$settemp) = Astro_RiseSet($jd0UT, $sunCoor1->{diameter}, $sunCoor1->{parallax},
  785. $sunCoor1->{ra}, $sunCoor1->{dec}, $sunCoor2->{ra}, $sunCoor2->{dec}, $lon, $lat, 1, -6.*$DEG);
  786. my $CivilTwilightMorning = Astro_mod($risetemp +$zone, 24.);
  787. my $CivilTwilightEvening = Astro_mod($settemp +$zone, 24.);
  788. #-- nautical twilight time in UTC.
  789. ($transittemp,$risetemp,$settemp) = Astro_RiseSet($jd0UT, $sunCoor1->{diameter}, $sunCoor1->{parallax},
  790. $sunCoor1->{ra}, $sunCoor1->{dec}, $sunCoor2->{ra}, $sunCoor2->{dec}, $lon, $lat, 1, -12.*$DEG);
  791. my $NauticTwilightMorning = Astro_mod($risetemp +$zone, 24.);
  792. my $NauticTwilightEvening = Astro_mod($settemp +$zone, 24.);
  793. #-- astronomical twilight time in UTC.
  794. ($transittemp,$risetemp,$settemp) = Astro_RiseSet($jd0UT, $sunCoor1->{diameter}, $sunCoor1->{parallax},
  795. $sunCoor1->{ra}, $sunCoor1->{dec}, $sunCoor2->{ra}, $sunCoor2->{dec}, $lon, $lat, 1, -18.*$DEG);
  796. my $AstroTwilightMorning = Astro_mod($risetemp +$zone, 24.);
  797. my $AstroTwilightEvening = Astro_mod($settemp +$zone, 24.);
  798. #-- custom twilight time in UTC
  799. ($transittemp,$risetemp,$settemp) = Astro_RiseSet($jd0UT, $sunCoor1->{diameter}, $sunCoor1->{parallax},
  800. $sunCoor1->{ra}, $sunCoor1->{dec}, $sunCoor2->{ra}, $sunCoor2->{dec}, $lon, $lat, 1, $Astro{ObsHor}*$DEG);
  801. my $CustomTwilightMorning = Astro_mod($risetemp +$zone, 24.);
  802. my $CustomTwilightEvening = Astro_mod($settemp +$zone, 24.);
  803. return( ($transit,$rise,$set,$CivilTwilightMorning,$CivilTwilightEvening,
  804. $NauticTwilightMorning,$NauticTwilightEvening,$AstroTwilightMorning,$AstroTwilightEvening,$CustomTwilightMorning,$CustomTwilightEvening) );
  805. }else{
  806. return( ($transit,$rise,$set) );
  807. }
  808. }
  809. ########################################################################################################
  810. #
  811. # Astro_MoonRise - Find local time of moonrise and moonset
  812. # JD is the Julian Date of 0h local time (midnight)
  813. # Accurate to about 5 minutes or better
  814. # recursive: 1 - calculate rise/set in UTC
  815. # recursive: 0 - find rise/set on the current local day (set could also be first)
  816. # returns '' for moonrise/set does not occur on selected day
  817. #
  818. ########################################################################################################
  819. sub Astro_MoonRise($$$$$$$){
  820. my ($JD, $deltaT, $lon, $lat, $radius, $zone, $recursive) = @_;
  821. my $timeinterval = 0.5;
  822. my $jd0UT = floor($JD-0.5)+0.5; # JD at 0 hours UT
  823. #-- calculations for noon
  824. my $sunCoor1 = Astro_SunPosition($jd0UT+ $deltaT/24./3600.,undef,undef);
  825. my $moonCoor1 = Astro_MoonPosition($sunCoor1->{lon}, $sunCoor1->{anomalyMean}, $jd0UT+ $deltaT/24./3600.,undef,undef,undef,undef);
  826. #-- calculations for next day's midnight
  827. my $sunCoor2 = Astro_SunPosition($jd0UT +$timeinterval + $deltaT/24./3600.,undef,undef);
  828. my $moonCoor2 = Astro_MoonPosition($sunCoor2->{lon}, $sunCoor2->{anomalyMean}, $jd0UT +$timeinterval + $deltaT/24./3600.,undef,undef,undef,undef);
  829. # rise/set time in UTC, time zone corrected later.
  830. # Taking into account refraction, semi-diameter and parallax
  831. my ($transit,$rise,$set) = Astro_RiseSet($jd0UT, $moonCoor1->{diameter}, $moonCoor1->{parallax},
  832. $moonCoor1->{ra}, $moonCoor1->{dec}, $moonCoor2->{ra}, $moonCoor2->{dec}, $lon, $lat, $timeinterval,undef);
  833. my ($transittemp,$risetemp,$settemp);
  834. my ($transitprev,$riseprev,$setprev);
  835. # check and adjust to have rise/set time on local calendar day
  836. if ( $recursive==0 ) {
  837. if ($zone>0) {
  838. # recursive call to MoonRise returns events in UTC
  839. ($transitprev,$riseprev,$setprev) = Astro_MoonRise($JD-1., $deltaT, $lon, $lat, $radius, $zone, 1);
  840. if ($transit >= 24.-$zone || $transit < -$zone) { # transit time is tomorrow local time
  841. if ($transitprev < 24.-$zone){
  842. $transit = ""; # there is no moontransit today
  843. }else{
  844. $transit = $transitprev;
  845. }
  846. }
  847. if ($rise >= 24.-$zone || $rise < -$zone) { # rise time is tomorrow local time
  848. if ($riseprev < 24.-$zone){
  849. $rise = ""; # there is no moontransit today
  850. }else{
  851. $rise = $riseprev;
  852. }
  853. }
  854. if ($set >= 24.-$zone || $set < -$zone) { # set time is tomorrow local time
  855. if ($setprev < 24.-$zone){
  856. $set = ""; # there is no moontransit today
  857. }else{
  858. $set = $setprev;
  859. }
  860. }
  861. }elsif ($zone<0) { # rise/set time was tomorrow local time -> calculate rise time for previous UTC day
  862. if ($rise<-$zone || $set<-$zone || $transit<-$zone) {
  863. ($transittemp,$risetemp,$settemp) = Astro_MoonRise($JD+1., $deltaT, $lon, $lat, $radius, $zone, 1);
  864. if ($rise < -$zone) {
  865. if ($risetemp > -$zone){
  866. $rise = ''; # there is no moonrise today
  867. }else{
  868. $rise = $risetemp;
  869. }
  870. }
  871. if ($transit < -zone){
  872. if ($transittemp > -zone){
  873. $transit = ''; # there is no moonset today
  874. }else{
  875. $transit = $transittemp;
  876. }
  877. }
  878. if ($set < -zone){
  879. if ($settemp > -zone){
  880. $set = ''; # there is no moonset today
  881. }else{
  882. $set = $settemp;
  883. }
  884. }
  885. }
  886. }
  887. #-- correct for time zone, if time is valid
  888. $transit = Astro_mod($transit +$zone, 24.)
  889. if( $transit ne "");
  890. $rise = Astro_mod($rise +$zone, 24.)
  891. if ($rise ne "");
  892. $set = Astro_mod($set +$zone, 24.)
  893. if ($set ne "");
  894. }
  895. return( ($transit,$rise,$set) );
  896. }
  897. ########################################################################################################
  898. #
  899. # Astro_Compute - sequential calculation of properties
  900. #
  901. ########################################################################################################
  902. sub Astro_Compute($){
  903. my ($hash) = @_;
  904. my $name = $hash->{NAME};
  905. #-- readjust language
  906. my $lang = AttrVal("global","language","EN");
  907. if( $lang eq "DE"){
  908. $astro_tt = \%astro_transtable_DE;
  909. }else{
  910. $astro_tt = \%astro_transtable_EN;
  911. }
  912. return undef if( !$init_done );
  913. #-- geodetic latitude and longitude of observer on WGS84
  914. if( defined($attr{$name}{"latitude"}) ){
  915. $Astro{ObsLat} = $attr{$name}{"latitude"};
  916. }elsif( defined($attr{"global"}{"latitude"}) ){
  917. $Astro{ObsLat} = $attr{"global"}{"latitude"};
  918. }else{
  919. $Astro{ObsLat} = 50.0;
  920. Log3 $name,3,"[Astro] No latitude attribute set in global device, using 50.0°";
  921. }
  922. if( defined($attr{$name}{"longitude"}) ){
  923. $Astro{ObsLon} = $attr{$name}{"longitude"};
  924. }elsif( defined($attr{"global"}{"longitude"}) ){
  925. $Astro{ObsLon} = $attr{"global"}{"longitude"};
  926. }else{
  927. $Astro{ObsLon} = 10.0;
  928. Log3 $name,3,"[Astro] No longitude attribute set in global device, using 10.0°";
  929. }
  930. #-- altitude of observer in meters above WGS84 ellipsoid
  931. if( defined($attr{$name}{"altitude"}) ){
  932. $Astro{ObsAlt} = $attr{$name}{"altitude"};
  933. }elsif( defined($attr{"global"}{"altitude"}) ){
  934. $Astro{ObsAlt} = $attr{"global"}{"altitude"};
  935. }else{
  936. $Astro{ObsAlt} = 0.0;
  937. Log3 $name,3,"[Astro] No altitude attribute set in global device, using 0.0 m above sea level";
  938. }
  939. #-- custom horizon of observer in degrees
  940. if( defined($attr{$name}{"horizon"}) ){
  941. $Astro{ObsHor} = $attr{$name}{"horizon"};
  942. }else{
  943. $Astro{ObsHor} = 0.0;
  944. Log3 $name,5,"[Astro] No horizon attribute defined, using 0.0°";
  945. }
  946. #-- internal variables converted to Radians and km
  947. my $lat = $Astro{ObsLat}*$DEG;
  948. my $lon = $Astro{ObsLon}*$DEG;
  949. my $height = $Astro{ObsAlt} * 0.001;
  950. #if (eval(form.Year.value)<=1900 || eval(form.Year.value)>=2100 ) {
  951. # alert("Dies Script erlaubt nur Berechnungen"+
  952. # return;
  953. #}
  954. my $JD0 = Astro_CalcJD( $Date{day}, $Date{month}, $Date{year} );
  955. my $JD = $JD0 + ( $Date{hour} - $Date{zonedelta} + $Date{min}/60. + $Date{sec}/3600.)/24;
  956. my $TDT = $JD + $deltaT/86400.0;
  957. $Astro{ObsJD} = Astro_round($JD,2);
  958. my $gmst = Astro_GMST($JD);
  959. $Astro{ObsGMST} = Astro_HHMMSS($gmst);
  960. my $lmst = Astro_GMST2LMST($gmst, $lon);
  961. $Astro{ObsLMST} = Astro_HHMMSS($lmst);
  962. #-- geocentric cartesian coordinates of observer
  963. my ($x,$y,$z,$radius) = Astro_Observer2EquCart($lon, $lat, $height, $gmst);
  964. #-- calculate data for the sun at given time
  965. my $sunCoor = Astro_SunPosition($TDT, $lat, $lmst*15.*$DEG);
  966. $Astro{SunLon} = Astro_round($sunCoor->{lon}*$RAD,1);
  967. #$Astro{SunLat} = $sunCoor->{lat}*$RAD;
  968. $Astro{SunRa} = Astro_round($sunCoor->{ra} *$RAD/15,1);
  969. $Astro{SunDec} = Astro_round($sunCoor->{dec}*$RAD,1);
  970. $Astro{SunAz} = Astro_round($sunCoor->{az} *$RAD,1);
  971. $Astro{SunAlt} = Astro_round($sunCoor->{alt}*$RAD + Astro_Refraction($sunCoor->{alt}),1); # including refraction WARNUNG => *RAD ???
  972. $Astro{SunSign} = $astro_tt->{$sunCoor->{sig}};
  973. $Astro{SunDiameter}=Astro_round($sunCoor->{diameter}*$RAD*60,1); #angular diameter in arc seconds
  974. $Astro{SunDistance}=Astro_round($sunCoor->{distance},0);
  975. #-- calculate distance from the observer (on the surface of earth) to the center of the sun
  976. my ($xs,$ys,$zs) = Astro_EquPolar2Cart($sunCoor->{ra}, $sunCoor->{dec}, $sunCoor->{distance});
  977. $Astro{SunDistanceObserver} = Astro_round(sqrt( ($xs-$x)**2 + ($ys-$y)**2 + ($zs-$z)**2 ),0);
  978. my ($suntransit,$sunrise,$sunset,$CivilTwilightMorning,$CivilTwilightEvening,
  979. $NauticTwilightMorning,$NauticTwilightEvening,$AstroTwilightMorning,$AstroTwilightEvening,$CustomTwilightMorning,$CustomTwilightEvening) =
  980. Astro_SunRise($JD0, $deltaT, $lon, $lat, $Date{zonedelta}, 0);
  981. $Astro{SunTransit} = Astro_HHMM($suntransit);
  982. $Astro{SunRise} = Astro_HHMM($sunrise);
  983. $Astro{SunSet} = Astro_HHMM($sunset);
  984. $Astro{CivilTwilightMorning} = Astro_HHMM($CivilTwilightMorning);
  985. $Astro{CivilTwilightEvening} = Astro_HHMM($CivilTwilightEvening);
  986. $Astro{NauticTwilightMorning} = Astro_HHMM($NauticTwilightMorning);
  987. $Astro{NauticTwilightEvening} = Astro_HHMM($NauticTwilightEvening);
  988. $Astro{AstroTwilightMorning} = Astro_HHMM($AstroTwilightMorning);
  989. $Astro{AstroTwilightEvening} = Astro_HHMM($AstroTwilightEvening);
  990. $Astro{CustomTwilightMorning} = Astro_HHMM($CustomTwilightMorning);
  991. $Astro{CustomTwilightEvening} = Astro_HHMM($CustomTwilightEvening);
  992. #-- calculate data for the moon at given time
  993. my $moonCoor = Astro_MoonPosition($sunCoor->{lon}, $sunCoor->{anomalyMean}, $TDT, $lon, $lat, $radius, $lmst*15.*$DEG);
  994. $Astro{MoonLon} = Astro_round($moonCoor->{lon}*$RAD,1);
  995. $Astro{MoonLat} = Astro_round($moonCoor->{lat}*$RAD,1);
  996. $Astro{MoonRa} = Astro_round($moonCoor->{ra} *$RAD/15.,1);
  997. $Astro{MoonDec} = Astro_round($moonCoor->{dec}*$RAD,1);
  998. $Astro{MoonAz} = Astro_round($moonCoor->{az} *$RAD,1);
  999. $Astro{MoonAlt} = Astro_round($moonCoor->{alt}*$RAD + Astro_Refraction($moonCoor->{alt}),1); # including refraction WARNUNG => *RAD ???
  1000. $Astro{MoonSign} = $astro_tt->{$moonCoor->{sig}};
  1001. $Astro{MoonDistance} = Astro_round($moonCoor->{distance},0);
  1002. $Astro{MoonDiameter} = Astro_round($moonCoor->{diameter}*$RAD*60.,1); # angular diameter in arc seconds
  1003. $Astro{MoonAge} = Astro_round($moonCoor->{age}*$RAD,1);
  1004. $Astro{MoonPhaseN} = Astro_round($moonCoor->{phasen},2);
  1005. $Astro{MoonPhaseI} = $astro_tt->{$moonCoor->{phasei}};
  1006. $Astro{MoonPhaseS} = $astro_tt->{$moonCoor->{phases}};
  1007. #-- calculate distance from the observer (on the surface of earth) to the center of the moon
  1008. my ($xm,$ym,$zm) = Astro_EquPolar2Cart($moonCoor->{ra}, $moonCoor->{dec}, $moonCoor->{distance});
  1009. #Log 1," distance=".$moonCoor->{distance}." test=".sqrt( ($xm)**2 + ($ym)**2 + ($zm)**2 )." $xm $ym $zm";
  1010. #Log 1," distance=".$radius." test=".sqrt( ($x)**2 + ($y)**2 + ($z)**2 )." $x $y $z";
  1011. $Astro{MoonDistanceObserver} = Astro_round(sqrt( ($xm-$x)**2 + ($ym-$y)**2 + ($zm-$z)**2 ),0);
  1012. my ($moontransit,$moonrise,$moonset) = Astro_MoonRise($JD0, $deltaT, $lon, $lat, $radius, $Date{zonedelta}, 0);
  1013. $Astro{MoonTransit} = Astro_HHMM($moontransit);
  1014. $Astro{MoonRise} = Astro_HHMM($moonrise);
  1015. $Astro{MoonSet} = Astro_HHMM($moonset);
  1016. #-- fix date
  1017. $Astro{ObsDate}= sprintf("%02d.%02d.%04d",$Date{day},$Date{month},$Date{year});
  1018. $Astro{ObsTime}= sprintf("%02d:%02d:%02d",$Date{hour},$Date{min},$Date{sec});
  1019. $Astro{ObsTimezone}= $Date{zonedelta};
  1020. #-- check season
  1021. my $doj = $Date{dayofyear};
  1022. $Astro{ObsDayofyear} = $doj;
  1023. for( my $i=0;$i<4;$i++){
  1024. my $key = $seasons[$i];
  1025. if( (($seasonn{$key}[0] < $seasonn{$key}[1]) && ($seasonn{$key}[0] <= $doj) && ($seasonn{$key}[1] >= $doj))
  1026. || (($seasonn{$key}[0] > $seasonn{$key}[1]) && (($seasonn{$key}[0] <= $doj) || ($seasonn{$key}[1] >= $doj))) ){
  1027. $Astro{ObsSeason} = $astro_tt->{$key};
  1028. $Astro{ObsSeasonN} = $i;
  1029. last;
  1030. }
  1031. }
  1032. return( undef );
  1033. };
  1034. ########################################################################################
  1035. #
  1036. # Astro_moonwidget - SVG picture of the moon
  1037. #
  1038. # Parameter hash = hash of the bus master a = argument array
  1039. #
  1040. ########################################################################################
  1041. sub Astro_moonwidget($){
  1042. my ($arg) = @_;
  1043. my $name = $FW_webArgs{name};
  1044. $name =~ s/'//g;
  1045. my $hash = $defs{$name};
  1046. my $mooncolor = 'rgb(255,220,100)';
  1047. my $moonshadow = 'rgb(70,70,100)';
  1048. ;
  1049. my $colorscheme = ($FW_webArgs{color} ? $FW_webArgs{color} : 'none');
  1050. if( $colorscheme eq 'light' ){
  1051. $mooncolor = 'rgb(255,220,180)';
  1052. $moonshadow = 'rgb(210,210,210)';
  1053. }
  1054. $mooncolor = $FW_webArgs{mooncolor}
  1055. if ($FW_webArgs{mooncolor} );
  1056. $moonshadow = $FW_webArgs{moonshadow}
  1057. if ($FW_webArgs{moonshadow} );
  1058. my @size = split('x', ($FW_webArgs{size} ? $FW_webArgs{size} : '400x400'));
  1059. $FW_RETTYPE = "image/svg+xml";
  1060. $FW_RET="";
  1061. FW_pO '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 800" width="'.$size[0].'px" height="'.$size[1].'px">';
  1062. my $ma = Astro_Get($hash,("","text","MoonAge"));
  1063. my $mb = Astro_Get($hash,("","text","MoonPhaseS"));
  1064. my ($radius,$axis,$dir,$start,$middle);
  1065. $radius = 250;
  1066. $axis = sin(($ma+90)*$DEG)*$radius;
  1067. $axis = -$axis
  1068. if ($axis < 0);
  1069. if( (0.0 <= $ma && $ma <= 90) || (270.0 < $ma && $ma <= 360.0) ){
  1070. $dir = 1;
  1071. }else{
  1072. $dir = 0;
  1073. }
  1074. if( 0.0 < $ma && $ma <= 180 ){
  1075. $start = $radius;
  1076. $middle = -$radius;
  1077. }else{
  1078. $start = -$radius;
  1079. $middle = $radius;
  1080. }
  1081. FW_pO '<g transform="translate(400,400) scale(-1,1)">';
  1082. FW_pO '<circle cx="0" cy="0" r="250" fill="'.$moonshadow.'"/>';
  1083. FW_pO '<path d="M 0 '.$start.' A '.$axis.' '.$radius.' 0 0 '.$dir.' 0 '.$middle.' A '.$radius.' '.$radius.' 0 0 0 0 '.$start.' Z" fill="'.$mooncolor.'"/>';
  1084. FW_pO '</g>';
  1085. #FW_pO '<text x="100" y="710" style="font-family:Helvetica;font-size:60px;font-weight:bold" fill="black">'.$mb.'</text>';
  1086. FW_pO '</svg>';
  1087. return ($FW_RETTYPE, $FW_RET);
  1088. }
  1089. ########################################################################################
  1090. #
  1091. # Astro_Update - Update readings
  1092. #
  1093. # Parameter hash = hash of the bus master a = argument array
  1094. #
  1095. ########################################################################################
  1096. sub Astro_Update($@) {
  1097. my ($hash) = @_;
  1098. my $name = $hash->{NAME};
  1099. RemoveInternalTimer($hash);
  1100. my $interval = ( defined($hash->{INTERVAL})) ? $hash->{INTERVAL} : 3600;
  1101. InternalTimer(gettimeofday()+ $interval, "Astro_Update", $hash,1)
  1102. if( $interval > 0 );
  1103. #-- Current time will be used
  1104. my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime(time);
  1105. $year += 1900;
  1106. $month += 1;
  1107. $Date{year} = $year;
  1108. $Date{month}= $month;
  1109. $Date{day} = $day;
  1110. $Date{hour} = $hour;
  1111. $Date{min} = $min;
  1112. $Date{sec} = $sec;
  1113. #-- broken on windows
  1114. #$Date{zonedelta} = (strftime "%z", localtime)/100;
  1115. $Date{zonedelta} = Astro_tzoffset(time)/100;
  1116. #-- half broken in windows
  1117. $Date{dayofyear} = 1*strftime("%j", localtime);
  1118. Astro_Compute($hash);
  1119. readingsBeginUpdate($hash);
  1120. foreach my $key (keys %Astro){
  1121. readingsBulkUpdate($hash,$key,$Astro{$key});
  1122. }
  1123. readingsEndUpdate($hash,1);
  1124. }
  1125. ########################################################################################
  1126. #
  1127. # Astro_Get - Implements GetFn function
  1128. #
  1129. # Parameter hash = hash of the bus master a = argument array
  1130. #
  1131. ########################################################################################
  1132. sub Astro_Get($@) {
  1133. my ($hash, @a) = @_;
  1134. my $name = $hash->{NAME};
  1135. my $wantsreading = 0;
  1136. #-- second parameter may be a reading
  1137. if( (int(@a)>2) && exists($Astro{$a[2]})) {
  1138. $wantsreading = 1;
  1139. #Log 1,"=================> WANT as ".$a[1]." READING ".$a[2]." GET READING ".$Astro{$a[2]};
  1140. }
  1141. if( int(@a) > (2+$wantsreading) ) {
  1142. my $str = (int(@a) == (4+$wantsreading)) ? $a[2+$wantsreading]." ".$a[3+$wantsreading] : $a[2+$wantsreading];
  1143. if( $str =~ /(\d{4})-(\d{2})-(\d{2})(\D*(\d{2}):(\d{2})(:(\d{2}))?)?/){
  1144. $Date{year} = $1;
  1145. $Date{month}= $2;
  1146. $Date{day} = $3;
  1147. $Date{hour} = (defined($5)) ? $5 : 12;
  1148. $Date{min} = (defined($6)) ? $6 : 0;
  1149. $Date{sec} = (defined($8)) ? $8 : 0;
  1150. my $fTot = timelocal($Date{sec},$Date{min},$Date{hour},$Date{day},$Date{month}-1,$Date{year});
  1151. #-- broken on windows
  1152. #$Date{zonedelta} = (strftime "%z", localtime($fTot))/100;
  1153. $Date{zonedelta} = Astro_tzoffset($fTot)/100;
  1154. #-- half broken in windows
  1155. $Date{dayofyear} = 1*strftime("%j", localtime($fTot));
  1156. }else{
  1157. return "[Astro_Get] $name has improper time specification $str, use YYYY-MM-DD HH:MM:SS";
  1158. }
  1159. }else{
  1160. #-- Current time will be used
  1161. my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime(time);
  1162. $year += 1900;
  1163. $month += 1;
  1164. $Date{year} = $year;
  1165. $Date{month}= $month;
  1166. $Date{day} = $day;
  1167. $Date{hour} = $hour;
  1168. $Date{min} = $min;
  1169. $Date{sec} = $sec;
  1170. #-- broken on windows
  1171. #$Date{zonedelta} = (strftime "%z", localtime)/100;
  1172. $Date{zonedelta} = Astro_tzoffset(time)/100;
  1173. #-- half broken in windows
  1174. $Date{dayofyear} = 1*strftime("%j", localtime);
  1175. }
  1176. if( $a[1] eq "version") {
  1177. return $astroversion;
  1178. }elsif( $a[1] eq "json") {
  1179. Astro_Compute($hash);
  1180. if( $wantsreading==1 ){
  1181. return toJSON($Astro{$a[2]});
  1182. }else{
  1183. return toJSON(\%Astro);
  1184. }
  1185. }elsif( $a[1] eq "text") {
  1186. Astro_Compute($hash);
  1187. if( $wantsreading==1 ){
  1188. return $Astro{$a[2]};
  1189. }else{
  1190. my $ret=sprintf("%s %s %s \n",$astro_tt->{"date"},$Astro{ObsDate},$Astro{ObsTime});
  1191. $ret .= sprintf("%s %.2f %s, %d %s\n",$astro_tt->{"jdate"},$Astro{ObsJD},$astro_tt->{"days"},$Astro{ObsDayofyear},$astro_tt->{"dayofyear"});
  1192. $ret .= sprintf("%s %s, %s %2d\n",$astro_tt->{"season"},$Astro{ObsSeason},$astro_tt->{"timezone"},$Astro{ObsTimezone});
  1193. $ret .= sprintf("%s %.5f° %s, %.5f° %s, %.0fm %s\n",$astro_tt->{"coord"},$Astro{ObsLon},$astro_tt->{"longitude"},
  1194. $Astro{ObsLat},$astro_tt->{"latitude"},$Astro{ObsAlt},$astro_tt->{"altitude"});
  1195. $ret .= sprintf("%s %s \n\n",$astro_tt->{"lmst"},$Astro{ObsLMST});
  1196. $ret .= "\n".$astro_tt->{"sun"}."\n";
  1197. $ret .= sprintf("%s %s %s %s %s %s\n",$astro_tt->{"rise"},$Astro{SunRise},$astro_tt->{"set"},$Astro{SunSet},$astro_tt->{"transit"},$Astro{SunTransit});
  1198. $ret .= sprintf("%s %s - %s\n",$astro_tt->{"twilightcivil"},$Astro{CivilTwilightMorning},$Astro{CivilTwilightEvening});
  1199. $ret .= sprintf("%s %s - %s\n",$astro_tt->{"twilightnautic"},$Astro{NauticTwilightMorning},$Astro{NauticTwilightEvening});
  1200. $ret .= sprintf("%s %s - %s\n",$astro_tt->{"twilightastro"},$Astro{AstroTwilightMorning},$Astro{AstroTwilightEvening});
  1201. $ret .= sprintf("%s: %.0fkm %s (%.0fkm %s)\n",$astro_tt->{"distance"},$Astro{SunDistance},$astro_tt->{"toce"},$Astro{SunDistanceObserver},$astro_tt->{"toobs"});
  1202. $ret .= sprintf("%s: %s %2.1f°, %s %2.2fh, %s %2.1f°; %s %2.1f°, %s %2.1f°\n",
  1203. $astro_tt->{"position"},$astro_tt->{"lonecl"},$Astro{SunLon},$astro_tt->{"ra"},
  1204. $Astro{SunRa},$astro_tt->{"dec"},$Astro{SunDec},$astro_tt->{"az"},$Astro{SunAz},$astro_tt->{"alt"},$Astro{SunAlt});
  1205. $ret .= sprintf("%s %2.1f', %s %s\n\n",$astro_tt->{"diameter"},$Astro{SunDiameter},$astro_tt->{"sign"},$Astro{SunSign});
  1206. $ret .= "\n".$astro_tt->{"moon"}."\n";
  1207. $ret .= sprintf("%s %s %s %s %s %s\n",$astro_tt->{"rise"},$Astro{MoonRise},$astro_tt->{"set"},$Astro{MoonSet},$astro_tt->{"transit"},$Astro{MoonTransit});
  1208. $ret .= sprintf("%s: %.0fkm %s (%.0fkm %s)\n",$astro_tt->{"distance"},$Astro{MoonDistance},$astro_tt->{"toce"},$Astro{MoonDistanceObserver},$astro_tt->{"toobs"});
  1209. $ret .= sprintf("%s: %s %2.1f°, %s %2.1f°; %s %2.2fh, %s %2.1f°; %s %2.1f°, %s %2.1f°\n",
  1210. $astro_tt->{"position"},$astro_tt->{"lonecl"},$Astro{MoonLon},$astro_tt->{"latecl"},$Astro{MoonLat},$astro_tt->{"ra"},
  1211. $Astro{MoonRa},$astro_tt->{"dec"},$Astro{MoonDec},$astro_tt->{"az"},$Astro{MoonAz},$astro_tt->{"alt"},$Astro{MoonAlt});
  1212. $ret .= sprintf("%s %2.1f', %s %2.1f°, %s %1.2f = %s, %s %s\n",$astro_tt->{"diameter"},
  1213. $Astro{MoonDiameter},$astro_tt->{"age"},$Astro{MoonAge},$astro_tt->{"phase"},$Astro{MoonPhaseN},$Astro{MoonPhaseS},$astro_tt->{"sign"},$Astro{MoonSign});
  1214. return $ret;
  1215. }
  1216. }else {
  1217. return "[Astro_Get] $name with unknown argument $a[1], choose one of ".
  1218. join(" ", sort keys %gets);
  1219. }
  1220. }
  1221. 1;
  1222. =pod
  1223. =item helper
  1224. =item summary collection of various routines for astronomical data
  1225. =item summary_DE Sammlung verschiedener Routinen für astronomische Daten
  1226. =begin html
  1227. <a name="Astro"></a>
  1228. <h3>Astro</h3>
  1229. <ul>
  1230. <p> FHEM module with a collection of various routines for astronomical data</p>
  1231. <a name="Astrodefine"></a>
  1232. <h4>Define</h4>
  1233. <p>
  1234. <code>define &lt;name&gt; Astro</code>
  1235. <br />Defines the Astro device (only one is needed per FHEM installation). </p>
  1236. <p>
  1237. Readings with prefix <i>Sun</i> refer to the sun, with prefix <i>Moon</i> refer to the moon.
  1238. The suffixes for these readings are
  1239. <ul>
  1240. <li><i>Age</i> = angle (in degrees) of body along its track</li>
  1241. <li><i>Az,Alt</i> = azimuth and altitude angle (in degrees) of body above horizon</li>
  1242. <li><i>Dec,Ra</i> = declination (in degrees) and right ascension (in HH:MM) of body position</li>
  1243. <li><i>Lat,Lon</i> = latitude and longituds (in degrees) of body position</li>
  1244. <li><i>Diameter</i> = virtual diameter (in arc minutes) of body</li>
  1245. <li><i>Distance,DistanceObserver</i> = distance (in km) of body to center of earth or to observer</li>
  1246. <li><i>PhaseN,PhaseS</i> = Numerical and string value for phase of body</li>
  1247. <li><i>Sign</i> = Circadian sign for body along its track</li>
  1248. <li><i>Rise,Transit,Set</i> = times (in HH:MM) for rise and set as well as for highest position of body</li>
  1249. </ul>
  1250. <p>
  1251. Readings with prefix <i>Obs</i> refer to the observer.
  1252. In addition to some of the suffixes gives above, the following may occur
  1253. <ul>
  1254. <li><i>Date,Dayofyear</i> = date</li>
  1255. <li><i>JD</i> = Julian date</li>
  1256. <li><i>Season,SeasonN</i> = String and numerical (0..3) value of season</li>
  1257. <li><i>Time,Timezone</i> obvious meaning</li>
  1258. <li><i>GMST,ÖMST</i> = Greenwich and Local Mean Sidereal Time (in HH:MM)</li>
  1259. </ul>
  1260. <p>
  1261. An SVG image of the current moon phase may be obtained under the link
  1262. <code>&lt;ip address of fhem&gt;/fhem/Astro_moonwidget?name='&lt;device name&gt;'&amp;size='&lt;width&gt;x&lt;height&gt;'</code>
  1263. <p>
  1264. Notes: <ul>
  1265. <li>Calculations are only valid between the years 1900 and 2100</li>
  1266. <li>Attention: Timezone is taken from the local Perl settings, NOT automatically defined for a location</li>
  1267. <li>This module uses the global attribute <code>language</code> to determine its output data<br/>
  1268. (default: EN=english). For German output set <code>attr global language DE</code>.</li>
  1269. <li>The time zone is determined automatically from the local settings of the <br/>
  1270. operating system. If geocordinates from a different time zone are used, the results are<br/>
  1271. not corrected automatically.
  1272. <li>Some definitions determining the observer position are used<br/>
  1273. from the global device, i.e.<br/>
  1274. <code>attr global longitude &lt;value&gt;</code><br/>
  1275. <code>attr global latitude &lt;value&gt;</code><br/>
  1276. <code>attr global altitude &lt;value&gt;</code> (in m above sea level)<br/>
  1277. These definitions are only used when there are no corresponding local attribute settings.
  1278. </li>
  1279. <li>
  1280. It is not necessary to define an Astro device to use the data provided by this module<br/>
  1281. To use its data in any other module, you just need to put <code>require "95_Astro.pm";</code> <br/>
  1282. at the start of your own code, and then may call, for example, the function<br/>
  1283. <code>Astro_Get( SOME_HASH_REFERENCE,"dummy","text", "SunRise","2019-12-24");</code><br/>
  1284. to acquire the sunrise on Christmas Eve 2019</li>
  1285. </ul>
  1286. <a name="Astroget"></a>
  1287. <h4>Get</h4>
  1288. Attention: Get-calls are NOT written into the readings of the device ! Readings change only through periodic updates !<br/>
  1289. </li>
  1290. <ul>
  1291. <li><a name="astro_json"></a>
  1292. <code>get &lt;name&gt; json [&lt;reading&gt;]</code><br/>
  1293. <code>get &lt;name&gt; json [&lt;reading&gt;] YYYY-MM-DD</code><br/>
  1294. <code>get &lt;name&gt; json [&lt;reading&gt;] YYYY-MM-DD HH:MM:[SS]</code>
  1295. <br />returns the complete set or an individual reading of astronomical data either for the current time, or for a day and time given in the argument.</li>
  1296. <li><a name="astro_text"></a>
  1297. <code>get &lt;name&gt; text [&lt;reading&gt;]</code><br/>
  1298. <code>get &lt;name&gt; text [&lt;reading&gt;] YYYY-MM-DD</code><br/>
  1299. <code>get &lt;name&gt; text [&lt;reading&gt;] YYYY-MM-DD HH:MM:[SS]</code>
  1300. <br />returns the complete set or an individual reading of astronomical data either for the current time, or for a day and time given in the argument.</li>
  1301. <li><a name="astro_version"></a>
  1302. <code>get &lt;name&gt; version</code>
  1303. <br />Display the version of the module</li>
  1304. </ul>
  1305. <a name="Astroattr"></a>
  1306. <h4>Attributes</h4>
  1307. <ul>
  1308. <li><a name="astro_interval">
  1309. <code>&lt;interval&gt;</code>
  1310. <br />Update interval in seconds. The default is 3600 seconds, a value of 0 disables the automatic update. </li>
  1311. <li>Some definitions determining the observer position:<br/>
  1312. <code>attr &lt;name&gt; longitude &lt;value&gt;</code><br/>
  1313. <code>attr &lt;name&gt; latitude &lt;value&gt;</code><br/>
  1314. <code>attr &lt;name&gt; altitude &lt;value&gt;</code> (in m above sea level)<br/>
  1315. <code>attr &lt;name&gt; horizon &lt;value&gt;</code> custom horizon angle in degrees, default 0<br/>
  1316. These definitions take precedence over global attribute settings.
  1317. </li>
  1318. <li>Standard attributes <a href="#alias">alias</a>, <a href="#comment">comment</a>, <a
  1319. href="#event-on-update-reading">event-on-update-reading</a>, <a
  1320. href="#event-on-change-reading">event-on-change-reading</a>, <a href="#room"
  1321. >room</a>, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>,
  1322. <a href="#webCmd">webCmd</a></li>
  1323. </ul>
  1324. </ul>
  1325. =end html
  1326. =begin html_DE
  1327. <a name="Astro"></a>
  1328. <h3>Astro</h3>
  1329. <ul>
  1330. Absichtlich keine deutsche Dokumentation vorhanden, die englische Version gibt es hier: <a href="/fhem/docs/commandref.html#Astro">Astro</a>
  1331. </ul>
  1332. =end html_DE
  1333. =cut