1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU Library General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
16 Copyright (C) 2003 Liam Girdwood <liam@gnova.org>
17
18
19 A simple example showing some lunar calculations.
20
21 */
22
23 #include <stdio.h>
24 #include <libnova/lunar.h>
25 #include <libnova/julian_day.h>
26 #include <libnova/rise_set.h>
27 #include <libnova/transform.h>
28
print_date(char * title,struct ln_zonedate * date)29 void print_date (char * title, struct ln_zonedate* date)
30 {
31 printf ("\n%s\n",title);
32 printf (" Year : %d\n", date->years);
33 printf (" Month : %d\n", date->months);
34 printf (" Day : %d\n", date->days);
35 printf (" Hours : %d\n", date->hours);
36 printf (" Minutes : %d\n", date->minutes);
37 printf (" Seconds : %f\n", date->seconds);
38 }
39
main(int argc,char * argv[])40 int main (int argc, char* argv[])
41 {
42 double JD;
43 struct ln_rect_posn moon;
44 struct ln_equ_posn equ;
45 struct ln_lnlat_posn ecl;
46 struct ln_lnlat_posn observer;
47 struct ln_rst_time rst;
48 struct ln_zonedate rise, transit, set;
49
50 /* observers location (Edinburgh), used to calc rst */
51 observer.lat = 55.92; /* 55.92 N */
52 observer.lng = -3.18; /* 3.18 W */
53
54 /* get the julian day from the local system time */
55 JD = ln_get_julian_from_sys();
56 printf ("JD %f\n",JD);
57
58 /* get the lunar geopcentric position in km, earth is at 0,0,0 */
59 ln_get_lunar_geo_posn (JD, &moon, 0);
60 printf ("lunar x %f y %f z %f\n",moon.X, moon.Y, moon.Z);
61
62 /* Long Lat */
63 ln_get_lunar_ecl_coords (JD, &ecl, 0);
64 printf ("lunar long %f lat %f\n",ecl.lng, ecl.lat);
65
66 /* RA, DEC */
67 ln_get_lunar_equ_coords (JD, &equ);
68 printf ("lunar RA %f Dec %f\n",equ.ra, equ.dec);
69
70 /* moon earth distance */
71 printf ("lunar distance km %f\n", ln_get_lunar_earth_dist(JD));
72
73 /* lunar disk, phase and bright limb */
74 printf ("lunar disk %f\n", ln_get_lunar_disk(JD));
75 printf ("lunar phase %f\n", ln_get_lunar_phase(JD));
76 printf ("lunar bright limb %f\n", ln_get_lunar_bright_limb(JD));
77
78 /* rise, set and transit time */
79 if (ln_get_lunar_rst (JD, &observer, &rst) == 1)
80 printf ("Moon is circumpolar\n");
81 else {
82 ln_get_local_date (rst.rise, &rise);
83 ln_get_local_date (rst.transit, &transit);
84 ln_get_local_date (rst.set, &set);
85 print_date ("Rise", &rise);
86 print_date ("Transit", &transit);
87 print_date ("Set", &set);
88 }
89
90 /* rise, set and transit time */
91 if (ln_get_lunar_rst (JD - 24, &observer, &rst) == 1)
92 printf ("Moon is circumpolar\n");
93 else {
94 ln_get_local_date (rst.rise, &rise);
95 ln_get_local_date (rst.transit, &transit);
96 ln_get_local_date (rst.set, &set);
97 print_date ("Rise", &rise);
98 print_date ("Transit", &transit);
99 print_date ("Set", &set);
100 }
101
102 /* rise, set and transit time */
103 if (ln_get_lunar_rst (JD - 25, &observer, &rst) == 1)
104 printf ("Moon is circumpolar\n");
105 else {
106 ln_get_local_date (rst.rise, &rise);
107 ln_get_local_date (rst.transit, &transit);
108 ln_get_local_date (rst.set, &set);
109 print_date ("Rise", &rise);
110 print_date ("Transit", &transit);
111 print_date ("Set", &set);
112 }
113
114 return 0;
115 }
116