[1457] | 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 | */
|
---|
| 26 | void
|
---|
| 27 | riset (ra, dec, lat, dis, lstr, lsts, azr, azs, status)
|
---|
| 28 | double ra, dec;
|
---|
| 29 | double lat, dis;
|
---|
| 30 | double *lstr, *lsts;
|
---|
| 31 | double *azr, *azs;
|
---|
| 32 | int *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 */
|
---|
| 105 | static 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 $"};
|
---|