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

Last change on this file since 1681 was 1457, checked in by cmv, 24 years ago

import de la partie libastro de Xephem cmv+rz 10/4/2001

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