Geo Stars Library  0.9.3
Geodetic and Astrometry library
geoAstro.c
Go to the documentation of this file.
1 /*!
2 \file geoAstro.c
3 \brief This file contains the wrapper routines to interface to the
4  Novas (Naval Observatory Vector Astrometry Subroutine) Library.
5 
6  http://aa.usno.navy.mil/software/novas/novas_info.html
7 
8 */
9 
10 #include <stdio.h>
11 #include <time.h>
12 #include "geoStars.h"
13 #include "novas.h"
14 
15 int geoSunError = 0;
16 struct tm tError;
17 
18 
19 //-----------------------------------------------------------------
20 /*!
21 \brief this routine uses ANSI C time routines to obtain the current time
22 and then get the az and el of the sun at this location
23 
24 \param GEO_LOCATION *loc : Location structure
25 \param double *az : Azimuth in decimal degrees
26 \param double *el : Elevation in decimal degrees
27 \retval GEO_OK on success
28 \retval GEO_ERROR on error
29 */
30 
31 int DLL_CALLCONV geoSunAzElNow(GEO_LOCATION *loc, double *az, double *el)
32 {
33  struct tm *newtime;
34  long ltime=0L;
35 
36  /* Obtain coordinated universal time: */
37  time( &ltime );
38  newtime = gmtime( &ltime );
39 
40  return ( geoSunAzEltm(loc, az, el, newtime) );
41 }
42 
43 //-----------------------------------------------------------------
44 /*!
45 \brief this routine uses the location and current time
46 to get the elevation of the sun at this location
47 
48 \param double lat : Latitude in degrees
49 \param double lon : Longitude in degrees
50 \param double hgt : Height in meters
51 \retval double : Elevation in decimal degrees
52 */
53 
54 double DLL_CALLCONV geoSunNowEl(double lat, double lon, double hgt)
55 {
56  GEO_LOCATION loc;
57  double az,el;
58 
59  geoInitLocation(&loc, lat, lon, hgt, GEO_DATUM_DEFAULT, "now");
60  geoSunAzElNow(&loc, &az, &el);
61  return(el);
62 }
63 
64 //-----------------------------------------------------------------
65 /*!
66 \brief this routine uses the location and current time
67 to get the azimuth of the sun at this location
68 
69 \param double lat : Latitude in degrees
70 \param double lon : Longitude in degrees
71 \param double hgt : Height in meters
72 \retval double : Azimuth in decimal degrees
73 */
74 
75 double DLL_CALLCONV geoSunNowAz(double lat, double lon, double hgt)
76 {
77  GEO_LOCATION loc;
78  double az,el;
79 
80  geoInitLocation(&loc, lat, lon, hgt, GEO_DATUM_DEFAULT, "now");
81  geoSunAzElNow(&loc, &az, &el);
82  return(az);
83 }
84 
85 
86 //-----------------------------------------------------------------
87 /*!
88 \brief this routine ingests an ANSI C time structure and then gets the
89 az and el of the sun at this location based on this time.
90 
91 \param GEO_LOCATION *loc : Location structure
92 \param double *az : Azimuth in decimal degrees
93 \param double *el : Elevation in decimal degrees
94 \retval GEO_OK on success
95 \retval GEO_ERROR on error
96 */
97 
98 int DLL_CALLCONV geoSunAzEltm(GEO_LOCATION *loc, double *az, double *el, struct tm *newtime)
99 {
100  /* Obtain coordinated universal time: */
101  double tjd_now;
102 
103  tError.tm_year=newtime->tm_year;
104  tError.tm_mon=newtime->tm_mon;
105  tError.tm_mday=newtime->tm_mday;
106 
107  tjd_now = julian_date((short)(newtime->tm_year+1900),
108  (short)(newtime->tm_mon+1),
109  (short)newtime->tm_mday,
110  newtime->tm_hour + (newtime->tm_min/60.0)+(newtime->tm_sec/3600.0));
111 
112  return ( geoSunAzElJD(loc, az, el,tjd_now) );
113 }
114 
115 
116 int DLL_CALLCONV geoGettm(int part)
117 {
118  switch(part)
119  {
120  case 1: return(tError.tm_year);
121  case 2: return(tError.tm_mon);
122  case 3: return(tError.tm_mday);
123  }
124  return(-999);
125 }
126 
127 
128 #define MAJOR_PLANET 0 //! \internal major planet, sun or moon
129 #define BODY_EARTH 3 //! \internal Earth
130 #define BODY_SUN 10 //! \internal Sun
131 #define REDUCED_ACC 1 //! \internal Reduced Accuracy (0=full, 1=reduced)
132 
133 
134 //-----------------------------------------------------------------
135 /*!
136 \brief This routine uses a previously determined \e Julian \e date and then gets the
137 Az and El of the sun at this location based on the Julian date.
138 
139 \param GEO_LOCATION *loc : Location structure
140 \param double *az : Azimuth in decimal degrees
141 \param double *el : Elevation in decimal degrees
142 \retval GEO_OK on success
143 \retval GEO_ERROR on error
144 */
145 
146 
147 int DLL_CALLCONV geoSunAzElJD(GEO_LOCATION *loc, double *az, double *el, double tjd_now)
148 {
149  on_surface geo_loc;
150  cat_entry dummy_star;
151  object sun;
152  double deltat = 60.0; // 'deltat' is the difference in time scales, TT - UT1.
153  double ra, dec, dis;
154  double rar,decr;
155  // int error;
156 
157  /* Convert geo library info into Novas info */
158  // geo_loc.latitude = loc->lat;
159  // geo_loc.longitude = loc->lon;
160  // geo_loc.height = loc->hgt;
161  // geo_loc.temperature = 30.0; // degrees celcius
162  // geo_loc.pressure = 1000.0; // pressure in millibars
163  make_on_surface(loc->lat, loc->lon, loc->hgt, 30.0, 1000.0, &geo_loc);
164 
165 
166  /* Set the planetary bodies to be worked with */
167  /*geoSunError = set_body (MAJOR_PLANET,BODY_EARTH,"Earth", &earth);
168  if(geoSunError)
169  {
170  // printf ("Error %d from set_body.\n", geoSunError);
171  return(GEO_ERROR);
172  }
173 */
174 
175  geoSunError = make_object (MAJOR_PLANET,BODY_SUN,"Sun",&dummy_star, &sun);
176  if(geoSunError)
177  {
178  //printf ("Error %d from make_object.\n", geoSunError);
179  return(GEO_ERROR);
180  }
181 
182  /* Compute the Sun's position */
183  // geoSunError = topo_planet (tjd_now,&sun,&earth,deltat,&geo_loc, &ra,&dec,&dis);
184  geoSunError = topo_planet (tjd_now,&sun,deltat,&geo_loc, REDUCED_ACC, &ra,&dec,&dis);
185  if(geoSunError)
186  {
187  // printf ("Error %d from topo_planet.\n", geoSunError);
188  return(GEO_ERROR);
189  }
190 
191  /* Convert to Azimuth and Elevation */
192  equ2hor(tjd_now,deltat,REDUCED_ACC,0,0,&geo_loc,ra,dec,0,el,az,&rar,&decr);
193  *el = 90.0 - *el; // correct elevation from zenith
194 
195  return(GEO_OK);
196 }
197 
199 {
200  return(geoSunError);
201 }
202 
203 
204