Changeset 2551 in Sophya for trunk/SophyaExt/XephemAstroLib/mjd.c


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/mjd.c

    r1719 r2551  
    44#include <math.h>
    55
    6 #include "P_.h"
    76#include "astro.h"
    87
     
    1211 */
    1312void
    14 cal_mjd (mn, dy, yr, mjd)
    15 int mn, yr;
    16 double dy;
    17 double *mjd;
     13cal_mjd (int mn, double dy, int yr, double *mjp)
    1814{
    1915        static double last_mjd, last_dy;
     
    2319
    2420        if (mn == last_mn && yr == last_yr && dy == last_dy) {
    25             *mjd = last_mjd;
     21            *mjp = last_mjd;
    2622            return;
    2723        }
     
    4945        d = (int)(30.6001*(m+1));
    5046
    51         *mjd = b + c + d + dy - 0.5;
     47        *mjp = b + c + d + dy - 0.5;
    5248
    5349        last_mn = mn;
    5450        last_dy = dy;
    5551        last_yr = yr;
    56         last_mjd = *mjd;
     52        last_mjd = *mjp;
    5753}
    5854
    5955/* given the modified Julian date (number of days elapsed since 1900 jan 0.5,),
    60  * mjd, return the calendar date in months, *mn, days, *dy, and years, *yr.
    61  */
    62 void
    63 mjd_cal (mjd, mn, dy, yr)
    64 double mjd;
    65 int *mn, *yr;
    66 double *dy;
    67 {
    68         static double last_mjd, last_dy;
     56 * mj, return the calendar date in months, *mn, days, *dy, and years, *yr.
     57 */
     58void
     59mjd_cal (double mj, int *mn, double *dy, int *yr)
     60{
     61        static double last_mj, last_dy;
    6962        static int last_mn, last_yr;
    7063        double d, f;
     
    7467         * 0 is noon the last day of 1899.
    7568         */
    76         if (mjd == 0.0) {
     69        if (mj == 0.0) {
    7770            *mn = 12;
    7871            *dy = 31.5;
     
    8174        }
    8275
    83         if (mjd == last_mjd) {
     76        if (mj == last_mj) {
    8477            *mn = last_mn;
    8578            *yr = last_yr;
     
    8881        }
    8982
    90         d = mjd + 0.5;
     83        d = mj + 0.5;
    9184        i = floor(d);
    9285        f = d-i;
     
    118111        last_dy = *dy;
    119112        last_yr = *yr;
    120         last_mjd = mjd;
     113        last_mj = mj;
    121114}
    122115
     
    126119 */
    127120int
    128 mjd_dow (mjd, dow)
    129 double mjd;
    130 int *dow;
     121mjd_dow (double mj, int *dow)
    131122{
    132123        /* cal_mjd() uses Gregorian dates on or after Oct 15, 1582.
     
    137128         * can not easily be accounted for from the cal_mjd() number...
    138129         */
    139         if (mjd < -53798.5) {
     130        if (mj < -53798.5) {
    140131            /* pre sept 14, 1752 too hard to correct |:-S */
    141132            return (-1);
    142133        }
    143         *dow = ((long)floor(mjd-.5) + 1) % 7;/* 1/1/1900 (mjd 0.5) is a Monday*/
     134        *dow = ((long)floor(mj-.5) + 1) % 7;/* 1/1/1900 (mj 0.5) is a Monday*/
    144135        if (*dow < 0)
    145136            *dow += 7;
     
    149140/* given a year, return whether it is a leap year */
    150141int
    151 isleapyear (y)
    152 int y;
     142isleapyear (int y)
    153143{
    154144        return ((y%4==0 && y%100!=0) || y%400==0);
     
    157147/* given a mjd, return the the number of days in the month.  */
    158148void
    159 mjd_dpm (mjd, ndays)
    160 double mjd;
    161 int *ndays;
     149mjd_dpm (double mj, int *ndays)
    162150{
    163151        static short dpm[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
     
    165153        double d;
    166154
    167         mjd_cal (mjd, &m, &d, &y);
     155        mjd_cal (mj, &m, &d, &y);
    168156        *ndays = (m==2 && isleapyear(y)) ? 29 : dpm[m-1];
    169157}
     
    171159/* given a mjd, return the year and number of days since 00:00 Jan 1 */
    172160void
    173 mjd_dayno (mjd, yr, dy)
    174 double mjd;
    175 int *yr;
    176 double *dy;
     161mjd_dayno (double mj, int *yr, double *dy)
    177162{
    178163        double yrd;
     
    180165        int dpy;
    181166
    182         mjd_year (mjd, &yrd);
     167        mjd_year (mj, &yrd);
    183168        *yr = yri = (int)yrd;
    184169        dpy = isleapyear(yri) ? 366 : 365;
     
    188173/* given a mjd, return the year as a double. */
    189174void
    190 mjd_year (mjd, yr)
    191 double mjd;
    192 double *yr;
    193 {
    194         static double last_mjd, last_yr;
     175mjd_year (double mj, double *yr)
     176{
     177        static double last_mj, last_yr;
    195178        int m, y;
    196179        double d;
    197180        double e0, e1;  /* mjd of start of this year, start of next year */
    198181
    199         if (mjd == last_mjd) {
     182        if (mj == last_mj) {
    200183            *yr = last_yr;
    201184            return;
    202185        }
    203186
    204         mjd_cal (mjd, &m, &d, &y);
     187        mjd_cal (mj, &m, &d, &y);
    205188        if (y == -1) y = -2;
    206189        cal_mjd (1, 1.0, y, &e0);
    207190        cal_mjd (1, 1.0, y+1, &e1);
    208         *yr = y + (mjd - e0)/(e1 - e0);
    209 
    210         last_mjd = mjd;
     191        *yr = y + (mj - e0)/(e1 - e0);
     192
     193        last_mj = mj;
    211194        last_yr = *yr;
    212195}
     
    214197/* given a decimal year, return mjd */
    215198void
    216 year_mjd (y, mjd)
    217 double y;
    218 double *mjd;
     199year_mjd (double y, double *mjp)
    219200{
    220201        double e0, e1;  /* mjd of start of this year, start of next year */
     
    224205        cal_mjd (1, 1.0, yf, &e0);
    225206        cal_mjd (1, 1.0, yf+1, &e1);
    226         *mjd = e0 + (y - yf)*(e1-e0);
     207        *mjp = e0 + (y - yf)*(e1-e0);
    227208}
    228209
    229210/* round a time in days, *t, to the nearest second, IN PLACE. */
    230211void
    231 rnd_second (t)
    232 double *t;
     212rnd_second (double *t)
    233213{
    234214        *t = floor(*t*SPD+0.5)/SPD;
     
    237217/* given an mjd, truncate it to the beginning of the whole day */
    238218double
    239 mjd_day(jd)
    240 double jd;
    241 {
    242         return (floor(jd-0.5)+0.5);
     219mjd_day(double mj)
     220{
     221        return (floor(mj-0.5)+0.5);
    243222}
    244223
    245224/* given an mjd, return the number of hours past midnight of the whole day */
    246225double
    247 mjd_hr(jd)
    248 double jd;
    249 {
    250         return ((jd-mjd_day(jd))*24.0);
     226mjd_hr(double mj)
     227{
     228        return ((mj-mjd_day(mj))*24.0);
    251229}
    252230
     
    254232 */
    255233void
    256 range (v, r)
    257 double *v, r;
     234range (double *v, double r)
    258235{
    259236        *v -= r*floor(*v/r);
    260237}
    261238
     239/* insure 0 <= ra < 2PI and -PI/2 <= dec <= PI/2. if dec needs
     240 * complimenting, reflect ra too
     241 */
     242void
     243radecrange (double *ra, double *dec)
     244{
     245        if (*dec < -PI/2) {
     246            *dec = -PI - *dec;
     247            *ra += PI;
     248        } else if (*dec > PI/2) {
     249            *dec = PI - *dec;
     250            *ra += PI;
     251        }
     252        range (ra, 2*PI);
     253}
     254
    262255/* For RCS Only -- Do Not Edit */
    263 static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: mjd.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
     256static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: mjd.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.