Ignore:
Timestamp:
Jun 15, 2004, 6:54:12 PM (21 years ago)
Author:
cmv
Message:

nouvelle version de xephem/libastro (3.6) cmv 15/6/04

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/XephemAstroLib/misc.c

    r1719 r2551  
    66#include <stdio.h>
    77#include <math.h>
    8 
    9 #if defined(__STDC__)
    108#include <stdlib.h>
    119#include <string.h>
    12 #else
    13 extern double atof();
    14 #endif
    15 
    16 #include "P_.h"
     10
    1711#include "astro.h"
    18 #include "circum.h"
    1912
    2013/* zero from loc for len bytes */
    2114void
    22 zero_mem (loc, len)
    23 void *loc;
    24 unsigned len;
     15zero_mem (void *loc, unsigned len)
    2516{
    2617        (void) memset (loc, 0, len);
     
    3324 */
    3425int
    35 tickmarks (min, max, numdiv, ticks)
    36 double min, max;
    37 int numdiv;
    38 double ticks[];
     26tickmarks (double min, double max, int numdiv, double ticks[])
    3927{
    4028        static int factor[] = { 1, 2, 5 };
     
    4735        minscale = fabs(max - min);
    4836        delta = minscale/numdiv;
    49         for (n=0; n < sizeof(factor)/sizeof(factor[0]); n++) {
     37        for (n=0; n < (int)(sizeof(factor)/sizeof(factor[0])); n++) {
    5038            double scale;
    5139            double x = delta/factor[n];
     
    6755 */
    6856char *
    69 obj_description (op)
    70 Obj *op;
    71 {
    72         static struct {
    73             char class;
     57obj_description (Obj *op)
     58{
     59        typedef struct {
     60            char classcode;
    7461            char *desc;
    75         } fixed_class_map[] = {
     62        } CC;
     63
     64#define NFCM    ((int)(sizeof(fixed_class_map)/sizeof(fixed_class_map[0])))
     65        static CC fixed_class_map[] = {
    7666            {'A', "Cluster of Galaxies"},
    77             {'B', "Binary Star"},
     67            {'B', "Binary System"},
    7868            {'C', "Globular Cluster"},
    7969            {'D', "Double Star"},
     
    9484            {'U', "Cluster, with nebulosity"},
    9585            {'V', "Variable Star"},
     86            {'Y', "Supernova"},
    9687        };
    97 #define NFCM    (sizeof(fixed_class_map)/sizeof(fixed_class_map[0]))
     88
     89#define NBCM    ((int)(sizeof(binary_class_map)/sizeof(binary_class_map[0])))
     90        static CC binary_class_map[] = {
     91            {'a', "Astrometric binary"},
     92            {'c', "Cataclysmic variable"},
     93            {'e', "Eclipsing binary"},
     94            {'x', "High-mass X-ray binary"},
     95            {'y', "Low-mass X-ray binary"},
     96            {'o', "Occultation binary"},
     97            {'s', "Spectroscopic binary"},
     98            {'t', "1-line spectral binary"},
     99            {'u', "2-line spectral binary"},
     100            {'v', "Spectrum binary"},
     101            {'b', "Visual binary"},
     102            {'d', "Visual binary, apparent"},
     103            {'q', "Visual binary, optical"},
     104            {'r', "Visual binary, physical"},
     105            {'p', "Exoplanet"},
     106        };
    98107
    99108        switch (op->o_type) {
     
    102111                int i;
    103112                for (i = 0; i < NFCM; i++)
    104                     if (fixed_class_map[i].class == op->f_class)
     113                    if (fixed_class_map[i].classcode == op->f_class)
    105114                        return (fixed_class_map[i].desc);
    106115            }
    107             return (op->o_type == FIXED ? "Fixed" : "Field Star");
     116            return ("Fixed");
    108117        case PARABOLIC:
    109118            return ("Solar - Parabolic");
     
    112121        case ELLIPTICAL:
    113122            return ("Solar - Elliptical");
    114         case PLANET:
    115             return ("Planet");
     123        case BINARYSTAR:
     124            if (op->f_class) {
     125                int i;
     126                for (i = 0; i < NFCM; i++)
     127                    if (binary_class_map[i].classcode == op->f_class)
     128                        return (binary_class_map[i].desc);
     129            }
     130            return ("Binary system");
     131        case PLANET: {
     132            static char nsstr[16];
     133            static Obj *biop;
     134
     135            if (op->pl_code == SUN)
     136                return ("Star");
     137            if (op->pl_code == MOON)
     138                return ("Moon of Earth");
     139            if (op->pl_moon == X_PLANET)
     140                return ("Planet");
     141            if (!biop)
     142                getBuiltInObjs (&biop);
     143            sprintf (nsstr, "Moon of %s", biop[op->pl_code].o_name);
     144            return (nsstr);
     145            }
    116146        case EARTHSAT:
    117147            return ("Earth Sat");
    118148        default:
    119149            printf ("obj_description: unknown type: 0x%x\n", op->o_type);
    120             exit (1);
     150            abort();
    121151            return (NULL);      /* for lint */
    122152        }
     
    126156 */
    127157void
    128 now_lst (np, lstp)
    129 Now *np;
    130 double *lstp;
     158now_lst (Now *np, double *lstp)
    131159{
    132160        static double last_mjd = -23243, last_lng = 121212, last_lst;
     
    156184 */
    157185void
    158 radec2ha (np, ra, dec, hap)
    159 Now *np;
    160 double ra, dec;
    161 double *hap;
     186radec2ha (Now *np, double ra, double dec, double *hap)
    162187{
    163188        double ha, lst;
     
    182207 */
    183208int
    184 lc (cx, cy, cw, x1, y1, x2, y2, sx1, sy1, sx2, sy2)
    185 int cx, cy, cw;                 /* circle bounding box corner and width */
    186 int x1, y1, x2, y2;             /* line segment endpoints */
    187 int *sx1, *sy1, *sx2, *sy2;     /* segment inside the circle */
     209lc (
     210int cx, int cy, int cw,                 /* circle bbox corner and width */
     211int x1, int y1, int x2, int y2,         /* line segment endpoints */
     212int *sx1, int *sy1, int *sx2, int *sy2) /* segment inside the circle */
    188213{
    189214        int dx = x2 - x1;
     
    240265 */
    241266void
    242 hg_mag (h, g, rp, rho, rsn, mp)
    243 double h, g;
    244 double rp;      /* sun-obj dist, AU */
    245 double rho;     /* earth-obj dist, AU */
    246 double rsn;     /* sun-earth dist, AU */
    247 double *mp;
     267hg_mag (
     268double h, double g,
     269double rp,      /* sun-obj dist, AU */
     270double rho,     /* earth-obj dist, AU */
     271double rsn,     /* sun-earth dist, AU */
     272double *mp)
    248273{
    249274        double psi_t, Psi_1, Psi_2, beta;
     
    265290        psi_t = pow (tb2, 1.22);
    266291        Psi_2 = exp(-1.87*psi_t);
    267         *mp = h + 5.0*log10(rp*rho) - 2.5*log10((1-g)*Psi_1 + g*Psi_2);
     292        *mp = h + 5.0*log10(rp*rho);
     293        if (Psi_1 || Psi_2) *mp -= 2.5*log10((1-g)*Psi_1 + g*Psi_2);
    268294}
    269295
     
    273299 */
    274300int
    275 magdiam (fmag, magstp, scale, mag, size)
    276 int fmag;       /* faintest mag */
    277 int magstp;     /* mag range per dot size */
    278 double scale;   /* rads per pixel */
    279 double mag;     /* magnitude */
    280 double size;    /* rads, or 0 */
     301magdiam (
     302int fmag,       /* faintest mag */
     303int magstp,     /* mag range per dot size */
     304double scale,   /* rads per pixel */
     305double mag,     /* magnitude */
     306double size)    /* rads, or 0 */
    281307{
    282308        int diam, sized;
     
    295321 */
    296322void
    297 gk_mag (g, k, rp, rho, mp)
    298 double g, k;
    299 double rp;      /* sun-obj dist, AU */
    300 double rho;     /* earth-obj dist, AU */
    301 double *mp;
     323gk_mag (
     324double g, double k,
     325double rp,      /* sun-obj dist, AU */
     326double rho,     /* earth-obj dist, AU */
     327double *mp)
    302328{
    303329        *mp = g + 5.0*log10(rho) + 2.5*k*log10(rp);
     
    309335 */
    310336double
    311 atod (buf)
    312 char *buf;
    313 {
    314         return (atof (buf));
     337atod (char *buf)
     338{
     339        return (strtod (buf, NULL));
    315340}
    316341
     
    331356 */
    332357void
    333 solve_sphere (A, b, cc, sc, cap, Bp)
    334 double A, b;
    335 double cc, sc;
    336 double *cap, *Bp;
     358solve_sphere (double A, double b, double cc, double sc, double *cap, double *Bp)
    337359{
    338360        double cb = cos(b), sb = sin(b);
    339         double cA = cos(A);
     361        double sA, cA = cos(A);
     362        double x, y;
    340363        double ca;
    341364        double B;
     
    350373            return;
    351374
    352         if (cc > .99999) {
    353             /* as c approaches 0, B approaches pi - A */
    354             B = PI - A;
    355         } else if (cc < -.99999) {
    356             /* as c approaches PI, B approaches A */
    357             B = A;
    358         } else {
    359             /* compute cB and sB and remove common factor of sa from quotient.
    360              * be careful where B causes atan to blow.
    361              */
    362             double sA = sin(A);
    363             double x, y;
    364 
    365             y = sA*sb*sc;
    366             x = cb - ca*cc;
    367        
    368             if (fabs(x) < 1e-5)
    369                 B = y < 0 ? 3*PI/2 : PI/2;
    370             else
    371                 B = atan2 (y, x);
    372         }
     375        sA = sin(A);
     376        y = sA*sb*sc;
     377        x = cb - ca*cc;
     378        B = y ? (x ? atan2(y,x) : (y>0 ? PI/2 : -PI/2)) : (x>=0 ? 0 : PI);
    373379
    374380        *Bp = B;
     
    435441 */
    436442double
    437 delra (dra)
    438 double dra;
     443delra (double dra)
    439444{
    440445        double fdra = fmod(fabs(dra), 2*PI);
     
    449454 */
    450455int
    451 is_deepsky (op)
    452 Obj *op;
     456is_deepsky (Obj *op)
    453457{
    454458        int deepsky = 0;
     
    473477
    474478/* For RCS Only -- Do Not Edit */
    475 static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: misc.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
     479static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: misc.c,v $ $Date: 2004-06-15 16:52:39 $ $Revision: 1.3 $ $Name: not supported by cvs2svn $"};
Note: See TracChangeset for help on using the changeset viewer.