source: Sophya/trunk/SophyaExt/XephemAstroLib/riset.c@ 3166

Last change on this file since 3166 was 3111, checked in by cmv, 19 years ago

mise en conformite xephem 3.7.2 cmv 22/11/2006

File size: 3.0 KB
RevLine 
[1457]1#include <stdio.h>
2#include <math.h>
3
4#include "astro.h"
5
6/* given the true geocentric ra and dec of an object, the observer's latitude,
[2551]7 * lt, and a horizon displacement correction, dis, all in radians, find the
[1457]8 * local sidereal times and azimuths of rising and setting, lstr/s
9 * and azr/s, also all in radians, respectively.
10 * dis is the vertical displacement from the true position of the horizon. it
11 * is positive if the apparent position is higher than the true position.
12 * said another way, it is positive if the shift causes the object to spend
13 * longer above the horizon. for example, atmospheric refraction is typically
14 * assumed to produce a vertical shift of 34 arc minutes at the horizon; dis
15 * would then take on the value +9.89e-3 (radians). On the other hand, if
16 * your horizon has hills such that your apparent horizon is, say, 1 degree
17 * above sea level, you would allow for this by setting dis to -1.75e-2
18 * (radians).
19 *
20 * This version contributed by Konrad Bernloehr, Nov. 1996
21 *
22 * status: 0=normal; 1=never rises; -1=circumpolar.
23 * In case of non-zero status, all other returned variables are undefined.
24 */
25void
[2551]26riset (double ra, double dec, double lt, double dis, double *lstr,
27double *lsts, double *azr, double *azs, int *status)
[1457]28{
29#define EPS (1e-9) /* math rounding fudge - always the way, eh? */
30 double h; /* hour angle */
31 double cos_h; /* cos h */
32 double z; /* zenith angle */
33 double zmin, zmax; /* Minimum and maximum zenith angles */
34 double xaz, yaz; /* components of az */
35 int shemi; /* flag for southern hemisphere reflection */
36
[2551]37 /* reflect lt and dec if in southern hemisphere, then az back later */
38 if ((shemi= (lt < 0.)) != 0) {
39 lt = -lt;
[1457]40 dec = -dec;
41 }
42
43 /* establish zenith angle, and its extrema */
44 z = (PI/2.) + dis;
[2551]45 zmin = fabs (dec - lt);
46 zmax = PI - fabs(dec + lt);
[1457]47
48 /* first consider special cases.
49 * these also avoid any boundary problems in subsequent computations.
50 */
51 if (zmax <= z + EPS) {
52 *status = -1; /* never sets */
53 return;
54 }
55 if (zmin >= z - EPS) {
56 *status = 1; /* never rises */
57 return;
58 }
59
60 /* compute rising hour angle -- beware found off */
[2551]61 cos_h = (cos(z)-sin(lt)*sin(dec))/(cos(lt)*cos(dec));
[1457]62 if (cos_h >= 1.)
63 h = 0.;
64 else if (cos_h <= -1.)
65 h = PI;
66 else
67 h = acos (cos_h);
68
69 /* compute setting azimuth -- beware found off */
[2551]70 xaz = sin(dec)*cos(lt)-cos(dec)*cos(h)*sin(lt);
[1457]71 yaz = -1.*cos(dec)*sin(h);
72 if (xaz == 0.) {
73 if (yaz > 0)
74 *azs = PI/2;
75 else
76 *azs = -PI/2;
77 } else
78 *azs = atan2 (yaz, xaz);
79
80 /* reflect az back if southern */
81 if (shemi)
82 *azs = PI - *azs;
83 range(azs, 2.*PI);
84
85 /* rising is just the opposite side */
86 *azr = 2.*PI - *azs;
87 range(azr, 2.*PI);
88
89 /* rise and set are just ha either side of ra */
90 *lstr = radhr(ra-h);
91 range(lstr,24.0);
92 *lsts = radhr(ra+h);
93 range(lsts,24.0);
94
95 /* OK */
96 *status = 0;
97}
98
99/* For RCS Only -- Do Not Edit */
[3111]100static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: riset.c,v $ $Date: 2006-11-22 13:53:30 $ $Revision: 1.6 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.