/* convert ra to ha, in range 0..2*PI * need dec too if not already apparent. */ void radec2ha (Now *np, double ra, double dec, double *hap) { double ha, lst; if (epoch != EOD) as_ap (np, epoch, &ra, &dec); now_lst (np, &lst); ha = hrrad(lst) - ra; if (ha < 0) ha += 2*PI; *hap = ha; }
/* find Greenwich Hour Angle of the given object at the given time, 0..2*PI. */ void gha (Now *np, Obj *op, double *ghap) { Now n = *np; Obj o = *op; double tmp; n.n_epoch = EOD; n.n_lng = 0.0; n.n_lat = 0.0; obj_cir (&n, &o); now_lst (&n, &tmp); tmp = hrrad(tmp) - o.s_ra; if (tmp < 0) tmp += 2*PI; *ghap = tmp; }
int main(int argc, char *argv[]) { Now *np; Now now; ObjF *op = NULL; char msg[256]; char *wfsroot, *filename, ra_hms[50], dec_dms[50]; double ra, dec, fov, mag, dra, ddec, dist, fo_ra, fo_dec; int nop = 0; int i; now.n_mjd = 0.0; now.n_lat = degrad(31.689); now.n_lng = degrad(-110.885); now.n_tz = 7.0; now.n_temp = 20.0; now.n_pressure = 700.0; now.n_elev = 2580.0/ERAD; now.n_dip = 0.0; now.n_epoch = EOD; sprintf(now.n_tznm, "UTC-7"); np = &now; time_fromsys(np); ra = hrrad(atof(argv[1])); dec = degrad(atof(argv[2])); fov = degrad(atof(argv[3])); mag = atof(argv[4]); /* precess(mjd, J2000, &ra, &dec); */ if (getenv("WFSROOT")) { wfsroot = getenv("WFSROOT"); filename = (char *) malloc(strlen(wfsroot) + 20); strcpy(filename, wfsroot); strcat(filename, "/wfscat/tycho.xe2"); } else { filename = "/mmt/shwfs/wfscat/tycho.xe2"; } nop = xe2fetch(filename, np, ra, dec, fov, mag, &op, msg); for (i=0; i<nop; i++) { dist = raddeg( acos( sin(op[i].fo_dec)*sin(dec) + cos(op[i].fo_dec)*cos(dec)*cos(ra-op[i].fo_ra) ) ); dist *= 60.0; fo_ra = radhr(op[i].fo_ra); fo_dec = raddeg(op[i].fo_dec); sprintf(ra_hms, "%02d:%02d:%05.2f", (int) fo_ra, (int) ((fo_ra - (int)fo_ra)*60.0), ( (fo_ra - (int)fo_ra)*60.0 - (int) ((fo_ra - (int)fo_ra)*60.0) )*60.0); if (fo_dec < 0.0 && (int)fo_dec >= 0) { sprintf(dec_dms, "-%02d:%02d:%06.3f", (int)fo_dec, abs( (int) ((fo_dec - (int)fo_dec)*60.0) ), fabs( ( (fo_dec - (int)fo_dec)*60.0 - (int) ((fo_dec - (int)fo_dec)*60.0) )*60.0) ); } else { sprintf(dec_dms, "%+03d:%02d:%06.3f", (int)fo_dec, abs( (int) ((fo_dec - (int)fo_dec)*60.0) ), fabs( ( (fo_dec - (int)fo_dec)*60.0 - (int) ((fo_dec - (int)fo_dec)*60.0) )*60.0) ); } printf("%15s %4.1f mag %2s %c %s %s %+07.3f %+07.2f %9.2f\n", op[i].co_name, op[i].co_mag/MAGSCALE, op[i].fo_spect, op[i].fo_class, ra_hms, dec_dms, 0.1*op[i].fo_pma/cos(op[i].fo_dec), 0.1*op[i].fo_pmd, dist); } return(0); }
/* fill equatoreal and horizontal op-> fields; stern * * input: lam/bet/rho geocentric mean ecliptic and equinox of day * * algorithm at EOD: * ecl_eq --> ra/dec geocentric mean equatoreal EOD (via mean obliq) * deflect --> ra/dec relativistic deflection * nut_eq --> ra/dec geocentric true equatoreal EOD * ab_eq --> ra/dec geocentric apparent equatoreal EOD * if (PREF_GEO) --> output * ta_par --> ra/dec topocentric apparent equatoreal EOD * if (!PREF_GEO) --> output * hadec_aa --> alt/az topocentric horizontal * refract --> alt/az observed --> output * * algorithm at fixed equinox: * ecl_eq --> ra/dec geocentric mean equatoreal EOD (via mean obliq) * deflect --> ra/dec relativistic deflection [for alt/az only] * nut_eq --> ra/dec geocentric true equatoreal EOD [for aa only] * ab_eq --> ra/dec geocentric apparent equatoreal EOD [for aa only] * ta_par --> ra/dec topocentric apparent equatoreal EOD * precess --> ra/dec topocentric equatoreal fixed equinox [eq only] * --> output * hadec_aa --> alt/az topocentric horizontal * refract --> alt/az observed --> output */ static void cir_pos ( Now *np, double bet, /* geo lat (mean ecliptic of date) */ double lam, /* geo long (mean ecliptic of date) */ double *rho, /* in: geocentric dist in AU; out: geo- or topocentic dist */ Obj *op) /* object to set s_ra/dec as per equinox */ { double ra, dec; /* apparent ra/dec, corrected for nut/ab */ double tra, tdec; /* astrometric ra/dec, no nut/ab */ double lsn, rsn; /* solar geocentric (mean ecliptic of date) */ double ha_in, ha_out; /* local hour angle before/after parallax */ double dec_out; /* declination after parallax */ double dra, ddec; /* parallax correction */ double alt, az; /* current alt, az */ double lst; /* local sidereal time */ double rho_topo; /* topocentric distance in earth radii */ /* convert to equatoreal [mean equator, with mean obliquity] */ ecl_eq (mjed, bet, lam, &ra, &dec); tra = ra; /* keep mean coordinates */ tdec = dec; /* precess and save astrometric coordinates */ if (mjed != epoch) precess (mjed, epoch, &tra, &tdec); op->s_astrora = tra; op->s_astrodec = tdec; /* get sun position */ sunpos(mjed, &lsn, &rsn, NULL); /* allow for relativistic light bending near the sun. * (avoid calling deflect() for the sun itself). */ if (!is_planet(op,SUN) && !is_planet(op,MOON)) deflect (mjed, op->s_hlong, op->s_hlat, lsn, rsn, *rho, &ra, &dec); /* correct ra/dec to form geocentric apparent */ nut_eq (mjed, &ra, &dec); if (!is_planet(op,MOON)) ab_eq (mjed, lsn, &ra, &dec); op->s_gaera = ra; op->s_gaedec = dec; /* find parallax correction for equatoreal coords */ now_lst (np, &lst); ha_in = hrrad(lst) - ra; rho_topo = *rho * MAU/ERAD; /* convert to earth radii */ ta_par (ha_in, dec, lat, elev, &rho_topo, &ha_out, &dec_out); /* transform into alt/az and apply refraction */ hadec_aa (lat, ha_out, dec_out, &alt, &az); refract (pressure, temp, alt, &alt); op->s_alt = alt; op->s_az = az; /* Get parallax differences and apply to apparent or astrometric place * as needed. For the astrometric place, rotating the CORRECTIONS * back from the nutated equator to the mean equator will be * neglected. This is an effect of about 0.1" at moon distance. * We currently don't have an inverse nutation rotation. */ if (pref_get(PREF_EQUATORIAL) == PREF_GEO) { /* no topo corrections to eq. coords */ dra = ddec = 0.0; } else { dra = ha_in - ha_out; /* ra sign is opposite of ha */ ddec = dec_out - dec; *rho = rho_topo * ERAD/MAU; /* return topocentric distance in AU */ ra = ra + dra; dec = dec + ddec; } range(&ra, 2*PI); op->s_ra = ra; op->s_dec = dec; }
static int obj_fixed (Now *np, Obj *op) { double lsn, rsn; /* true geoc lng of sun, dist from sn to earth*/ double lam, bet; /* geocentric ecliptic long and lat */ double ha; /* local hour angle */ double el; /* elongation */ double alt, az; /* current alt, az */ double ra, dec; /* ra and dec at equinox of date */ double rpm, dpm; /* astrometric ra and dec with PM to now */ double lst; /* on the assumption that the user will stick with their chosen display * epoch for a while, we move the defining values to match and avoid * precession for every call until it is changed again. * N.B. only compare and store jd's to lowest precission (f_epoch). * N.B. maintaining J2k ref (which is arbitrary) helps avoid accum err */ if (0 /* disabled in PyEphem */ && epoch != EOD && epoch != op->f_epoch) { double pr = op->f_RA, pd = op->f_dec, fe = epoch; /* first bring back to 2k */ precess (op->f_epoch, J2000, &pr, &pd); pr += op->f_pmRA*(J2000-op->f_epoch); pd += op->f_pmdec*(J2000-op->f_epoch); /* then to epoch */ pr += op->f_pmRA*(fe-J2000); pd += op->f_pmdec*(fe-J2000); precess (J2000, fe, &pr, &pd); op->f_RA = pr; op->f_dec = pd; op->f_epoch = fe; } /* apply proper motion .. assume pm epoch reference equals equinox */ rpm = op->f_RA + op->f_pmRA*(mjd-op->f_epoch); dpm = op->f_dec + op->f_pmdec*(mjd-op->f_epoch); /* set ra/dec to astrometric @ equinox of date */ ra = rpm; dec = dpm; if (op->f_epoch != mjed) precess (op->f_epoch, mjed, &ra, &dec); /* compute astrometric @ requested equinox */ op->s_astrora = rpm; op->s_astrodec = dpm; if (op->f_epoch != epoch) precess (op->f_epoch, epoch, &op->s_astrora, &op->s_astrodec); /* convert equatoreal ra/dec to mean geocentric ecliptic lat/long */ eq_ecl (mjed, ra, dec, &bet, &lam); /* find solar ecliptical long.(mean equinox) and distance from earth */ sunpos (mjed, &lsn, &rsn, NULL); /* allow for relativistic light bending near the sun */ deflect (mjed, lam, bet, lsn, rsn, 1e10, &ra, &dec); /* TODO: correction for annual parallax would go here */ /* correct EOD equatoreal for nutation/aberation to form apparent * geocentric */ nut_eq(mjed, &ra, &dec); ab_eq(mjed, lsn, &ra, &dec); op->s_gaera = ra; op->s_gaedec = dec; /* set s_ra/dec -- apparent */ op->s_ra = ra; op->s_dec = dec; /* compute elongation from ecliptic long/lat and sun geocentric long */ elongation (lam, bet, lsn, &el); el = raddeg(el); op->s_elong = (float)el; /* these are really the same fields ... op->s_mag = op->f_mag; op->s_size = op->f_size; */ /* alt, az: correct for refraction; use eod ra/dec. */ now_lst (np, &lst); ha = hrrad(lst) - ra; hadec_aa (lat, ha, dec, &alt, &az); refract (pressure, temp, alt, &alt); op->s_alt = alt; op->s_az = az; return (0); }