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 comet calculations.
20 
21 Comet Enckle
22 
23 */
24 
25 #include <stdio.h>
26 #include <libnova/comet.h>
27 #include <libnova/julian_day.h>
28 #include <libnova/rise_set.h>
29 #include <libnova/transform.h>
30 #include <libnova/elliptic_motion.h>
31 
print_date(char * title,struct ln_zonedate * date)32 void print_date (char * title, struct ln_zonedate* date)
33 {
34 	printf ("\n%s\n",title);
35 	printf (" Year    : %d\n", date->years);
36 	printf (" Month   : %d\n", date->months);
37 	printf (" Day     : %d\n", date->days);
38 	printf (" Hours   : %d\n", date->hours);
39 	printf (" Minutes : %d\n", date->minutes);
40 	printf (" Seconds : %f\n", date->seconds);
41 	printf("gmtoff %ld\n", date->gmtoff);
42 }
43 
main(int argc,char * argv[])44 int main (int argc, char * argv[])
45 {
46 	struct ln_equ_posn equ;
47 	struct ln_rst_time rst;
48 	struct ln_zonedate rise, set, transit;
49 	struct ln_date epoch_date;
50 	struct ln_lnlat_posn observer;
51 	struct ln_ell_orbit orbit;
52 	struct ln_rect_posn posn;
53 	double JD, e_JD;
54 	double E, v, V, r, l, dist;
55 
56 	/* observers location (Edinburgh), used to calc rst */
57 	observer.lat = 55.92; /* 55.92 N */
58 	observer.lng = -3.18; /* 3.18 W */
59 
60 	/* get Julian day from local time */
61 	JD = ln_get_julian_from_sys();
62 	printf ("JD %f\n", JD);
63 
64 	/* calc epoch JD */
65 	epoch_date.years = 1990;
66 	epoch_date.months = 10;
67 	epoch_date.days = 28;
68 	epoch_date.hours = 12;
69 	epoch_date.minutes = 30;
70 	epoch_date.seconds = 0;
71 	e_JD = ln_get_julian_day (&epoch_date);
72 
73 	/* Enckle orbital elements */
74 	orbit.JD = e_JD;
75 	orbit.a = 2.2091404;
76 	orbit.e = 0.8502196;
77 	orbit.i = 11.94525;
78 	orbit.omega = 334.75006;
79 	orbit.w = 186.23352;
80 	orbit.n = 0;
81 
82 	/* solve kepler for orbit */
83 	E = ln_solve_kepler (0.1, 5.0);
84 	printf("(Equation of kepler) E when e is 0.1 and M is 5.0  %f\n ", E);
85 
86 	/* true anomaly */
87 	v = ln_get_ell_true_anomaly (0.1, E);
88 	printf("(True Anomaly) v when e is 0.1 and E is 5.5545  %f\n ", v);
89 
90 	/* radius vector */
91 	r = ln_get_ell_radius_vector (0.5, 0.1, E);
92 	printf ("(Radius Vector) r when v is , e is 0.1 and E is 5.5545  %f\n ", r);
93 
94 	/* geocentric rect coords */
95 	ln_get_ell_geo_rect_posn (&orbit, JD, &posn);
96 	printf ("(Geocentric Rect Coords X) for comet Enckle  %f\n", posn.X);
97 	printf ("(Geocentric Rect Coords Y) for comet Enckle  %f\n", posn.Y);
98 	printf ("(Geocentric Rect Coords Z) for comet Enckle  %f\n", posn.Z);
99 
100 	/* rectangular coords */
101 	ln_get_ell_helio_rect_posn (&orbit, JD, &posn);
102 	printf ("(Heliocentric Rect Coords X) for comet Enckle  %f\n ", posn.X);
103 	printf ("(Heliocentric Rect Coords Y) for comet Enckle  %f\n ", posn.Y);
104 	printf ("(Heliocentric Rect Coords Z) for comet Enckle  %f\n ", posn.Z);
105 
106 	/* ra, dec */
107 	ln_get_ell_body_equ_coords (JD, &orbit, &equ);
108 	printf ("(RA) for comet Enckle  %f\n ", equ.ra);
109 	printf ("(Dec) for comet Enckle  %f\n ", equ.dec);
110 
111 	/* orbit length */
112 	l = ln_get_ell_orbit_len (&orbit);
113 	printf ("(Orbit Length) for comet Enckle in AU  %f\n ", l);
114 
115 	/* orbital velocity at perihelion */
116 	V = ln_get_ell_orbit_pvel (&orbit);
117 	printf ("(Orbit Perihelion Vel) for comet Enckle in kms  %f\n ", V);
118 
119 	/* orbital velocity at aphelion */
120 	V = ln_get_ell_orbit_avel (&orbit);
121 	printf ("(Orbit Aphelion Vel) for comet Enckle in kms  %f\n ", V);
122 
123 	/* average orbital velocity */
124 	V = ln_get_ell_orbit_vel (JD, &orbit);
125 	printf ("(Orbit Vel JD) for comet Enckle in kms  %f\n ", V);
126 
127 	/* comet sun distance */
128 	dist = ln_get_ell_body_solar_dist (JD, &orbit);
129 	printf ("(Body Solar Dist) for comet Enckle in AU  %f\n ", dist);
130 
131 	/* comet earth distance */
132 	dist = ln_get_ell_body_earth_dist (JD, &orbit);
133 	printf ("(Body Earth Dist) for comet Enckle in AU  %f\n ", dist);
134 
135 	/* rise, set and transit */
136 	if (ln_get_ell_body_rst (JD, &observer, &orbit, &rst) == 1)
137 		printf ("Comet is circumpolar\n");
138 	else {
139 		ln_get_local_date (rst.rise, &rise);
140 		ln_get_local_date (rst.transit, &transit);
141 		ln_get_local_date (rst.set, &set);
142 		print_date ("Rise", &rise);
143 		print_date ("Transit", &transit);
144 		print_date ("Set", &set);
145 	}
146 
147 	return 0;
148 }
149