Changeset 2551 in Sophya for trunk/SophyaExt/XephemAstroLib/mjd.c
- Timestamp:
- Jun 15, 2004, 6:54:12 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/XephemAstroLib/mjd.c
r1719 r2551 4 4 #include <math.h> 5 5 6 #include "P_.h"7 6 #include "astro.h" 8 7 … … 12 11 */ 13 12 void 14 cal_mjd (mn, dy, yr, mjd) 15 int mn, yr; 16 double dy; 17 double *mjd; 13 cal_mjd (int mn, double dy, int yr, double *mjp) 18 14 { 19 15 static double last_mjd, last_dy; … … 23 19 24 20 if (mn == last_mn && yr == last_yr && dy == last_dy) { 25 *mj d= last_mjd;21 *mjp = last_mjd; 26 22 return; 27 23 } … … 49 45 d = (int)(30.6001*(m+1)); 50 46 51 *mj d= b + c + d + dy - 0.5;47 *mjp = b + c + d + dy - 0.5; 52 48 53 49 last_mn = mn; 54 50 last_dy = dy; 55 51 last_yr = yr; 56 last_mjd = *mj d;52 last_mjd = *mjp; 57 53 } 58 54 59 55 /* 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 */ 58 void 59 mjd_cal (double mj, int *mn, double *dy, int *yr) 60 { 61 static double last_mj, last_dy; 69 62 static int last_mn, last_yr; 70 63 double d, f; … … 74 67 * 0 is noon the last day of 1899. 75 68 */ 76 if (mj d== 0.0) {69 if (mj == 0.0) { 77 70 *mn = 12; 78 71 *dy = 31.5; … … 81 74 } 82 75 83 if (mj d == last_mjd) {76 if (mj == last_mj) { 84 77 *mn = last_mn; 85 78 *yr = last_yr; … … 88 81 } 89 82 90 d = mj d+ 0.5;83 d = mj + 0.5; 91 84 i = floor(d); 92 85 f = d-i; … … 118 111 last_dy = *dy; 119 112 last_yr = *yr; 120 last_mj d = mjd;113 last_mj = mj; 121 114 } 122 115 … … 126 119 */ 127 120 int 128 mjd_dow (mjd, dow) 129 double mjd; 130 int *dow; 121 mjd_dow (double mj, int *dow) 131 122 { 132 123 /* cal_mjd() uses Gregorian dates on or after Oct 15, 1582. … … 137 128 * can not easily be accounted for from the cal_mjd() number... 138 129 */ 139 if (mj d< -53798.5) {130 if (mj < -53798.5) { 140 131 /* pre sept 14, 1752 too hard to correct |:-S */ 141 132 return (-1); 142 133 } 143 *dow = ((long)floor(mj d-.5) + 1) % 7;/* 1/1/1900 (mjd0.5) is a Monday*/134 *dow = ((long)floor(mj-.5) + 1) % 7;/* 1/1/1900 (mj 0.5) is a Monday*/ 144 135 if (*dow < 0) 145 136 *dow += 7; … … 149 140 /* given a year, return whether it is a leap year */ 150 141 int 151 isleapyear (y) 152 int y; 142 isleapyear (int y) 153 143 { 154 144 return ((y%4==0 && y%100!=0) || y%400==0); … … 157 147 /* given a mjd, return the the number of days in the month. */ 158 148 void 159 mjd_dpm (mjd, ndays) 160 double mjd; 161 int *ndays; 149 mjd_dpm (double mj, int *ndays) 162 150 { 163 151 static short dpm[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; … … 165 153 double d; 166 154 167 mjd_cal (mj d, &m, &d, &y);155 mjd_cal (mj, &m, &d, &y); 168 156 *ndays = (m==2 && isleapyear(y)) ? 29 : dpm[m-1]; 169 157 } … … 171 159 /* given a mjd, return the year and number of days since 00:00 Jan 1 */ 172 160 void 173 mjd_dayno (mjd, yr, dy) 174 double mjd; 175 int *yr; 176 double *dy; 161 mjd_dayno (double mj, int *yr, double *dy) 177 162 { 178 163 double yrd; … … 180 165 int dpy; 181 166 182 mjd_year (mj d, &yrd);167 mjd_year (mj, &yrd); 183 168 *yr = yri = (int)yrd; 184 169 dpy = isleapyear(yri) ? 366 : 365; … … 188 173 /* given a mjd, return the year as a double. */ 189 174 void 190 mjd_year (mjd, yr) 191 double mjd; 192 double *yr; 193 { 194 static double last_mjd, last_yr; 175 mjd_year (double mj, double *yr) 176 { 177 static double last_mj, last_yr; 195 178 int m, y; 196 179 double d; 197 180 double e0, e1; /* mjd of start of this year, start of next year */ 198 181 199 if (mj d == last_mjd) {182 if (mj == last_mj) { 200 183 *yr = last_yr; 201 184 return; 202 185 } 203 186 204 mjd_cal (mj d, &m, &d, &y);187 mjd_cal (mj, &m, &d, &y); 205 188 if (y == -1) y = -2; 206 189 cal_mjd (1, 1.0, y, &e0); 207 190 cal_mjd (1, 1.0, y+1, &e1); 208 *yr = y + (mj d- e0)/(e1 - e0);209 210 last_mj d = mjd;191 *yr = y + (mj - e0)/(e1 - e0); 192 193 last_mj = mj; 211 194 last_yr = *yr; 212 195 } … … 214 197 /* given a decimal year, return mjd */ 215 198 void 216 year_mjd (y, mjd) 217 double y; 218 double *mjd; 199 year_mjd (double y, double *mjp) 219 200 { 220 201 double e0, e1; /* mjd of start of this year, start of next year */ … … 224 205 cal_mjd (1, 1.0, yf, &e0); 225 206 cal_mjd (1, 1.0, yf+1, &e1); 226 *mj d= e0 + (y - yf)*(e1-e0);207 *mjp = e0 + (y - yf)*(e1-e0); 227 208 } 228 209 229 210 /* round a time in days, *t, to the nearest second, IN PLACE. */ 230 211 void 231 rnd_second (t) 232 double *t; 212 rnd_second (double *t) 233 213 { 234 214 *t = floor(*t*SPD+0.5)/SPD; … … 237 217 /* given an mjd, truncate it to the beginning of the whole day */ 238 218 double 239 mjd_day(jd) 240 double jd; 241 { 242 return (floor(jd-0.5)+0.5); 219 mjd_day(double mj) 220 { 221 return (floor(mj-0.5)+0.5); 243 222 } 244 223 245 224 /* given an mjd, return the number of hours past midnight of the whole day */ 246 225 double 247 mjd_hr(jd) 248 double jd; 249 { 250 return ((jd-mjd_day(jd))*24.0); 226 mjd_hr(double mj) 227 { 228 return ((mj-mjd_day(mj))*24.0); 251 229 } 252 230 … … 254 232 */ 255 233 void 256 range (v, r) 257 double *v, r; 234 range (double *v, double r) 258 235 { 259 236 *v -= r*floor(*v/r); 260 237 } 261 238 239 /* insure 0 <= ra < 2PI and -PI/2 <= dec <= PI/2. if dec needs 240 * complimenting, reflect ra too 241 */ 242 void 243 radecrange (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 262 255 /* For RCS Only -- Do Not Edit */ 263 static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: mjd.c,v $ $Date: 200 1-10-22 12:08:27 $ $Revision: 1.2$ $Name: not supported by cvs2svn $"};256 static 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.