| [1457] | 1 | /* function to convert between alt/az and ha/dec.
 | 
|---|
 | 2 |  */
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | #include <stdio.h>
 | 
|---|
 | 5 | #include <math.h>
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | #include "astro.h"
 | 
|---|
 | 8 | 
 | 
|---|
| [2551] | 9 | static void aaha_aux (double lt, double x, double y, double *p, double *q);
 | 
|---|
| [1457] | 10 | 
 | 
|---|
| [2551] | 11 | /* given geographical latitude (n+, radians), lt, altitude (up+, radians),
 | 
|---|
| [1457] | 12 |  * alt, and azimuth (angle round to the east from north+, radians),
 | 
|---|
 | 13 |  * return hour angle (radians), ha, and declination (radians), dec.
 | 
|---|
 | 14 |  */
 | 
|---|
 | 15 | void
 | 
|---|
| [2551] | 16 | aa_hadec (
 | 
|---|
 | 17 | double lt,
 | 
|---|
 | 18 | double alt, double az,
 | 
|---|
 | 19 | double *ha, double *dec)
 | 
|---|
| [1457] | 20 | {
 | 
|---|
| [2551] | 21 |         aaha_aux (lt, az, alt, ha, dec);
 | 
|---|
| [1457] | 22 |         if (*ha > PI)
 | 
|---|
 | 23 |             *ha -= 2*PI;
 | 
|---|
 | 24 | }
 | 
|---|
 | 25 | 
 | 
|---|
| [2551] | 26 | /* given geographical (n+, radians), lt, hour angle (radians), ha, and
 | 
|---|
| [1457] | 27 |  * declination (radians), dec, return altitude (up+, radians), alt, and
 | 
|---|
 | 28 |  * azimuth (angle round to the east from north+, radians),
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | void
 | 
|---|
| [2551] | 31 | hadec_aa (
 | 
|---|
 | 32 | double lt,
 | 
|---|
 | 33 | double ha, double dec,
 | 
|---|
 | 34 | double *alt, double *az)
 | 
|---|
| [1457] | 35 | {
 | 
|---|
| [2551] | 36 |         aaha_aux (lt, ha, dec, az, alt);
 | 
|---|
| [1457] | 37 | }
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | #ifdef NEED_GEOC
 | 
|---|
 | 40 | /* given a geographic (surface-normal) latitude, phi, return the geocentric
 | 
|---|
 | 41 |  * latitude, psi.
 | 
|---|
 | 42 |  */
 | 
|---|
 | 43 | double
 | 
|---|
| [2551] | 44 | geoc_lat (
 | 
|---|
 | 45 | double phi)
 | 
|---|
| [1457] | 46 | {
 | 
|---|
 | 47 | #define MAXLAT  degrad(89.9999) /* avoid tan() greater than this */
 | 
|---|
 | 48 |         return (fabs(phi)>MAXLAT ? phi : atan(tan(phi)/1.00674));
 | 
|---|
 | 49 | }
 | 
|---|
 | 50 | #endif
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | /* the actual formula is the same for both transformation directions so
 | 
|---|
 | 53 |  * do it here once for each way.
 | 
|---|
 | 54 |  * N.B. all arguments are in radians.
 | 
|---|
 | 55 |  */
 | 
|---|
 | 56 | static void
 | 
|---|
| [2551] | 57 | aaha_aux (
 | 
|---|
 | 58 | double lt,
 | 
|---|
 | 59 | double x, double y,
 | 
|---|
 | 60 | double *p, double *q)
 | 
|---|
| [1457] | 61 | {
 | 
|---|
| [2551] | 62 |         static double last_lt = -3434, slt, clt;
 | 
|---|
| [1457] | 63 |         double cap, B;
 | 
|---|
 | 64 | 
 | 
|---|
| [2551] | 65 |         if (lt != last_lt) {
 | 
|---|
 | 66 |             slt = sin(lt);
 | 
|---|
 | 67 |             clt = cos(lt);
 | 
|---|
 | 68 |             last_lt = lt;
 | 
|---|
| [1457] | 69 |         }
 | 
|---|
 | 70 | 
 | 
|---|
| [2551] | 71 |         solve_sphere (-x, PI/2-y, slt, clt, &cap, &B);
 | 
|---|
| [1457] | 72 |         *p = B;
 | 
|---|
 | 73 |         *q = PI/2 - acos(cap);
 | 
|---|
 | 74 | }
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 | /* For RCS Only -- Do Not Edit */
 | 
|---|
| [3111] | 77 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: aa_hadec.c,v $ $Date: 2006-11-22 13:53:27 $ $Revision: 1.6 $ $Name: not supported by cvs2svn $"};
 | 
|---|