Changeset 2551 in Sophya for trunk/SophyaExt/XephemAstroLib/misc.c
- Timestamp:
- Jun 15, 2004, 6:54:12 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/XephemAstroLib/misc.c
r1719 r2551 6 6 #include <stdio.h> 7 7 #include <math.h> 8 9 #if defined(__STDC__)10 8 #include <stdlib.h> 11 9 #include <string.h> 12 #else 13 extern double atof(); 14 #endif 15 16 #include "P_.h" 10 17 11 #include "astro.h" 18 #include "circum.h"19 12 20 13 /* zero from loc for len bytes */ 21 14 void 22 zero_mem (loc, len) 23 void *loc; 24 unsigned len; 15 zero_mem (void *loc, unsigned len) 25 16 { 26 17 (void) memset (loc, 0, len); … … 33 24 */ 34 25 int 35 tickmarks (min, max, numdiv, ticks) 36 double min, max; 37 int numdiv; 38 double ticks[]; 26 tickmarks (double min, double max, int numdiv, double ticks[]) 39 27 { 40 28 static int factor[] = { 1, 2, 5 }; … … 47 35 minscale = fabs(max - min); 48 36 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++) { 50 38 double scale; 51 39 double x = delta/factor[n]; … … 67 55 */ 68 56 char * 69 obj_description (op) 70 Obj *op; 71 { 72 static struct { 73 char class; 57 obj_description (Obj *op) 58 { 59 typedef struct { 60 char classcode; 74 61 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[] = { 76 66 {'A', "Cluster of Galaxies"}, 77 {'B', "Binary S tar"},67 {'B', "Binary System"}, 78 68 {'C', "Globular Cluster"}, 79 69 {'D', "Double Star"}, … … 94 84 {'U', "Cluster, with nebulosity"}, 95 85 {'V', "Variable Star"}, 86 {'Y', "Supernova"}, 96 87 }; 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 }; 98 107 99 108 switch (op->o_type) { … … 102 111 int i; 103 112 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) 105 114 return (fixed_class_map[i].desc); 106 115 } 107 return ( op->o_type == FIXED ? "Fixed" : "Field Star");116 return ("Fixed"); 108 117 case PARABOLIC: 109 118 return ("Solar - Parabolic"); … … 112 121 case ELLIPTICAL: 113 122 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 } 116 146 case EARTHSAT: 117 147 return ("Earth Sat"); 118 148 default: 119 149 printf ("obj_description: unknown type: 0x%x\n", op->o_type); 120 exit (1);150 abort(); 121 151 return (NULL); /* for lint */ 122 152 } … … 126 156 */ 127 157 void 128 now_lst (np, lstp) 129 Now *np; 130 double *lstp; 158 now_lst (Now *np, double *lstp) 131 159 { 132 160 static double last_mjd = -23243, last_lng = 121212, last_lst; … … 156 184 */ 157 185 void 158 radec2ha (np, ra, dec, hap) 159 Now *np; 160 double ra, dec; 161 double *hap; 186 radec2ha (Now *np, double ra, double dec, double *hap) 162 187 { 163 188 double ha, lst; … … 182 207 */ 183 208 int 184 lc ( cx, cy, cw, x1, y1, x2, y2, sx1, sy1, sx2, sy2)185 int cx, cy, cw; /* circle boundingbox corner and width */186 int x1, y1, x2, y2;/* line segment endpoints */187 int *sx1, *sy1, *sx2, *sy2;/* segment inside the circle */209 lc ( 210 int cx, int cy, int cw, /* circle bbox corner and width */ 211 int x1, int y1, int x2, int y2, /* line segment endpoints */ 212 int *sx1, int *sy1, int *sx2, int *sy2) /* segment inside the circle */ 188 213 { 189 214 int dx = x2 - x1; … … 240 265 */ 241 266 void 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 ;267 hg_mag ( 268 double h, double g, 269 double rp, /* sun-obj dist, AU */ 270 double rho, /* earth-obj dist, AU */ 271 double rsn, /* sun-earth dist, AU */ 272 double *mp) 248 273 { 249 274 double psi_t, Psi_1, Psi_2, beta; … … 265 290 psi_t = pow (tb2, 1.22); 266 291 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); 268 294 } 269 295 … … 273 299 */ 274 300 int 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 */301 magdiam ( 302 int fmag, /* faintest mag */ 303 int magstp, /* mag range per dot size */ 304 double scale, /* rads per pixel */ 305 double mag, /* magnitude */ 306 double size) /* rads, or 0 */ 281 307 { 282 308 int diam, sized; … … 295 321 */ 296 322 void 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 ;323 gk_mag ( 324 double g, double k, 325 double rp, /* sun-obj dist, AU */ 326 double rho, /* earth-obj dist, AU */ 327 double *mp) 302 328 { 303 329 *mp = g + 5.0*log10(rho) + 2.5*k*log10(rp); … … 309 335 */ 310 336 double 311 atod (buf) 312 char *buf; 313 { 314 return (atof (buf)); 337 atod (char *buf) 338 { 339 return (strtod (buf, NULL)); 315 340 } 316 341 … … 331 356 */ 332 357 void 333 solve_sphere (A, b, cc, sc, cap, Bp) 334 double A, b; 335 double cc, sc; 336 double *cap, *Bp; 358 solve_sphere (double A, double b, double cc, double sc, double *cap, double *Bp) 337 359 { 338 360 double cb = cos(b), sb = sin(b); 339 double cA = cos(A); 361 double sA, cA = cos(A); 362 double x, y; 340 363 double ca; 341 364 double B; … … 350 373 return; 351 374 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); 373 379 374 380 *Bp = B; … … 435 441 */ 436 442 double 437 delra (dra) 438 double dra; 443 delra (double dra) 439 444 { 440 445 double fdra = fmod(fabs(dra), 2*PI); … … 449 454 */ 450 455 int 451 is_deepsky (op) 452 Obj *op; 456 is_deepsky (Obj *op) 453 457 { 454 458 int deepsky = 0; … … 473 477 474 478 /* For RCS Only -- Do Not Edit */ 475 static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: misc.c,v $ $Date: 200 1-10-22 12:08:27 $ $Revision: 1.2$ $Name: not supported by cvs2svn $"};479 static 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.