Exemplo n.º 1
0
/* transform local time to UTC or UTC to local time
 *
 * input 
 *   iyear ... dsec     date and time
 *   d_timezone		timezone offset
 * output
 *   iyear_out ... dsec_out
 * 
 * For time zones east of Greenwich, d_timezone is positive.
 * For time zones west of Greenwich, d_timezone is negative.
 * 
 * For conversion from local time to utc, use +d_timezone.
 * For conversion from utc to local time, use -d_timezone.
 */
void FAR PASCAL_CONV swe_utc_time_zone(
        int32 iyear, int32 imonth, int32 iday,
        int32 ihour, int32 imin, double dsec,
        double d_timezone,
        int32 *iyear_out, int32 *imonth_out, int32 *iday_out,
        int32 *ihour_out, int32 *imin_out, double *dsec_out
        )
{
  double tjd, d;
  AS_BOOL have_leapsec = FALSE;
  double dhour;
  if (dsec >= 60.0) {
    have_leapsec = TRUE;
    dsec -= 1.0;
  }
  dhour = ((double) ihour) + ((double) imin) / 60.0 + dsec / 3600.0;
  tjd = swe_julday(iyear, imonth, iday, 0, SE_GREG_CAL);
  dhour -= d_timezone;
  if (dhour < 0.0) {
    tjd -= 1.0;
    dhour += 24.0;
  }
  if (dhour >= 24.0) {
    tjd += 1.0;
    dhour -= 24.0;
  }
  swe_revjul(tjd + 0.001, SE_GREG_CAL, iyear_out, imonth_out, iday_out, &d);
  *ihour_out = (int) dhour;
  d = (dhour - (double) *ihour_out) * 60;
  *imin_out = (int) d;
  *dsec_out = (d - (double) *imin_out) * 60;
  if (have_leapsec)
    *dsec_out += 1.0;
}
Exemplo n.º 2
0
int main() {
    char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
    int jday = 1, jmon = 1, jyear = 2000;
    double jut = 0.0;
    double tjd, te, x2[6];
    int32 iflag, iflgret;
    int p;
    iflag = SEFLG_SPEED;
    while (TRUE) {
        printf("\nDate (d.m.y) ?");
        gets(sdate);
        /*
         * stop if a period . is entered
         */
        if (*sdate == '.')
            return OK;
        if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1)
            exit(1);
        /*
         * we have day, month and year and convert to Julian day number
         */
        tjd = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
        /*
         * compute Ephemeris time from Universal time by adding delta_t
         */
        te = tjd + swe_deltat(tjd);
        printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);
        printf("planet     \tlongitude\tlatitude\tdistance\tspeed long.\n");
        /*
         * a loop over all planets
         */
        for (p = SE_SUN; p <= SE_CHIRON; p++) {
            if (p == SE_EARTH)
                continue;
            /*
             * do the coordinate calculation for this planet p
             */
            iflgret = swe_calc(te, p, iflag, x2, serr);
            /*
             * if there is a problem, a negative value is returned and an
             * errpr message is in serr.
             */
            if (iflgret < 0)
                printf("error: %s\n", serr);
            else if (iflgret != iflag)
                printf("warning: iflgret != iflag. %s\n", serr);
            /*
             * get the name of the planet p
             */
            swe_get_planet_name(p, snam);
            /*
             * print the coordinates
             */
            printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
                   snam, x2[0], x2[1], x2[2], x2[3]);
        }
    }
    return OK;
}
Exemplo n.º 3
0
static PyObject* astrology_swe_julday(PyObject *self, PyObject *args)
{
	int y, m, d;
	double hour;
	int gregflag;

	if (!PyArg_ParseTuple(args, "iiidi", &y, &m, &d, &hour, &gregflag))
		return NULL;

	double ret = swe_julday(y, m, d, hour, gregflag);

	return Py_BuildValue("d", ret);
}
Exemplo n.º 4
0
int FAR PASCAL_CONV swe_date_conversion(int y,
		     int m,
		     int d,		/* day, month, year */
		     double uttime, 	/* UT in hours (decimal) */
		     char c,		/* calendar g[regorian]|j[ulian] */
		     double *tjd)
{
  int rday, rmon, ryear;
  double rut, jd;
  int gregflag = SE_JUL_CAL;
  if (c == 'g')
    gregflag = SE_GREG_CAL;
  rut = uttime;		/* hours UT */
  jd = swe_julday(y, m, d, rut, gregflag);
  swe_revjul(jd, gregflag, &ryear, &rmon, &rday, &rut);
  *tjd = jd;
  if (rmon == m && rday == d && ryear == y) {
    return OK;
  } else {
    return ERR;
  }
}	/* end date_conversion */
Exemplo n.º 5
0
//--------------------------------------------------------------------  
// Eine Datenzeile einlesen
// Julianisches Datum in ET und UT berechnen
// Geographische Länge und Breite einlesen
//--------------------------------------------------------------------  
  int get_data( char *line, struct _hordat *hordat ) {
  char name[255],*s, *t, gregflag, corrflag, lonflag, latflag;
  double ut,ct;
  int i=0,n=0,ut_sec,
      day,month,year,hrs,min,sec,hc,mc,sc, 
      lon_d, lon_m, lat_d, lat_m ;

// Beispielformat:
// 24.3.1920;G;14:15:0;1E0:0;7E34;47N32;Rene Acht
    i=sscanf(line, "%d.%d.%d;%c;%d:%d:%d;%d%c%d:%d;%d%c%d;%d%c%d;",
                      &day, &month, &year, &gregflag,
                      &hrs, &min, &sec, 
                      &hc, &corrflag, &mc, &sc,
                      &lon_d, &lonflag, &lon_m,
                      &lat_d, &latflag, &lat_m);

// Korrektur Kalenderzeit -> Weltzeit in h merken
   hordat->ctime = ((corrflag == 'E') ? -1 : 1) *
                   (sc + 60*(mc + 60*hc)) / .36e4;

// Weltzeit (in h) ermitteln...
   ut = ( sec + 60*(min + 60*hrs) )/.36e4 + hordat->ctime;


// ... und Julianisches Datum ermitteln                          
   hordat->jd_ut = swe_julday( year, month, day, ut, 
                               (gregflag == 'J') ? 0 : 1);
   hordat->jd    = hordat->jd_ut + swe_deltat( hordat->jd_ut );

// Länge
   hordat->lon = ( lon_m + 60 * lon_d ) *
                 ( (lonflag == 'E') ? 1 : -1 ) / .6e2;
                  
                  
// Breite
    hordat->lat = ( lat_m + 60 * lat_d )  *
                  ( (latflag == 'N') ? 1 : -1 ) / .6e2;  
                  
    }
Exemplo n.º 6
0
/*
 * Input:  tjd_et   Julian day number, terrestrial time (ephemeris time).
 *         gregfalg Calendar flag
 * Output: UTC year, month, day, hour, minute, second (decimal).
 *
 * - Before 1 jan 1972 UTC, output UT1.
 *   Note: UTC was introduced in 1961. From 1961 - 1971, the length of the
 *   UTC second was regularly changed, so that UTC remained very close to UT1.
 * - From 1972 on, output is UTC.
 * - If delta_t - nleap - 32.184 > 1, the output is UT1.
 *   Note: Like this we avoid errors greater than 1 second in case that
 *   the leap seconds table (or the Swiss Ephemeris version) has not been
 *   updated for a long time.
 */
void FAR PASCAL_CONV swe_jdet_to_utc(double tjd_et, int32 gregflag, int32 *iyear, int32 *imonth, int32 *iday, int32 *ihour, int32 *imin, double *dsec) 
{
  int i;
  int second_60 = 0;
  int iyear2, imonth2, iday2, nleap, ndat, tabsiz_nleap;
  double d, tjd, tjd_et_1972, tjd_ut, dret[10];
  /* 
   * if tjd_et is before 1 jan 1972 UTC, return UT1
   */
  tjd_et_1972 = J1972 + (32.184 + NLEAP_INIT) / 86400.0; 
  d = swe_deltat(tjd_et);
  tjd_ut = tjd_et - swe_deltat(tjd_et - d);
  if (tjd_et < tjd_et_1972) {
    swe_revjul(tjd_ut, gregflag, iyear, imonth, iday, &d);
    *ihour = (int32) d;
    d -= (double) *ihour;
    d *= 60;
    *imin = (int32) d;
    *dsec = (d - (double) *imin) * 60.0;
    return;
  }
  /* 
   * minimum number of leap seconds since 1972; we may be missing one leap
   * second
   */
  tabsiz_nleap = init_leapsec();
  swe_revjul(tjd_ut-1, SE_GREG_CAL, &iyear2, &imonth2, &iday2, &d);
  ndat = iyear2 * 10000 + imonth2 * 100 + iday2;
  nleap = 0; 
  for (i = 0; i < tabsiz_nleap; i++) {
    if (ndat <= leap_seconds[i])
      break;
    nleap++;
  }
  /* date of potentially missing leapsecond */
  if (nleap < tabsiz_nleap) {
    i = leap_seconds[nleap];
    iyear2 = i / 10000;
    imonth2 = (i % 10000) / 100;;
    iday2 = i % 100;
    tjd = swe_julday(iyear2, imonth2, iday2, 0, SE_GREG_CAL);
    swe_revjul(tjd+1, SE_GREG_CAL, &iyear2, &imonth2, &iday2, &d);
    swe_utc_to_jd(iyear2,imonth2,iday2, 0, 0, 0, SE_GREG_CAL, dret, NULL);
    d = tjd_et - dret[0];
    if (d >= 0) {
      nleap++;
    } else if (d < 0 && d > -1.0/86400.0) {
      second_60 = 1;
    }
  }
  /*
   * UTC, still unsure about one leap second
   */
  tjd = J1972 + (tjd_et - tjd_et_1972) - ((double) nleap + second_60) / 86400.0;
  swe_revjul(tjd, SE_GREG_CAL, iyear, imonth, iday, &d);
  *ihour = (int32) d;
  d -= (double) *ihour;
  d *= 60;
  *imin = (int32) d;
  *dsec = (d - (double) *imin) * 60.0 + second_60;
  /*
   * For input dates > today:
   * If leap seconds table is not up to date, we'd better interpret the
   * input time as UT1, not as UTC. How do we find out? 
   * Check, if delta_t - nleap - 32.184 > 0.9
   */
  d = swe_deltat(tjd_et);
  d = swe_deltat(tjd_et - d);
  if (d * 86400.0 - (double) (nleap + NLEAP_INIT) - 32.184 >= 1.0) {
    swe_revjul(tjd_et - d, SE_GREG_CAL, iyear, imonth, iday, &d);
    *ihour = (int32) d;
    d -= (double) *ihour;
    d *= 60;
    *imin = (int32) d;
    *dsec = (d - (double) *imin) * 60.0;
  }
  if (gregflag == SE_JUL_CAL) {
    tjd = swe_julday(*iyear, *imonth, *iday, 0, SE_GREG_CAL);
    swe_revjul(tjd, gregflag, iyear, imonth, iday, &d);
  }
}
Exemplo n.º 7
0
/*
 * Input:  Clock time UTC, year, month, day, hour, minute, second (decimal).
 *         gregflag  Calendar flag
 *         serr      error string
 * Output: An array of doubles:
 *         dret[0] = Julian day number TT (ET)
 *         dret[1] = Julian day number UT1
 *
 * Function returns OK or Error.
 *
 * - Before 1972, swe_utc_to_jd() treats its input time as UT1.
 *   Note: UTC was introduced in 1961. From 1961 - 1971, the length of the
 *   UTC second was regularly changed, so that UTC remained very close to UT1.
 * - From 1972 on, input time is treated as UTC.
 * - If delta_t - nleap - 32.184 > 1, the input time is treated as UT1.
 *   Note: Like this we avoid errors greater than 1 second in case that
 *   the leap seconds table (or the Swiss Ephemeris version) is not updated
 *   for a long time.
*/
int32 FAR PASCAL_CONV swe_utc_to_jd(int32 iyear, int32 imonth, int32 iday, int32 ihour, int32 imin, double dsec, int32 gregflag, double *dret, char *serr)
{
  double tjd_ut1, tjd_et, tjd_et_1972, dhour, d;
  int iyear2, imonth2, iday2;
  int i, j, ndat, nleap, tabsiz_nleap;
  /* 
   * error handling: invalid iyear etc. 
   */
  tjd_ut1 = swe_julday(iyear, imonth, iday, 0, gregflag);
  swe_revjul(tjd_ut1, gregflag, &iyear2, &imonth2, &iday2, &d);
  if (iyear != iyear2 || imonth != imonth2 || iday != iday2) {
    if (serr != NULL)
      sprintf(serr, "invalid date: year = %d, month = %d, day = %d", iyear, imonth, iday);
    return ERR;
  }
  if (ihour < 0 || ihour > 23 
   || imin < 0 || imin > 59 
   || dsec < 0 || dsec >= 61
   || (dsec >= 60 && (imin < 59 || ihour < 23 || tjd_ut1 < J1972))) {
    if (serr != NULL)
      sprintf(serr, "invalid time: %d:%d:%.2f", ihour, imin, dsec);
    return ERR;
  }
  dhour = (double) ihour + ((double) imin) / 60.0 + dsec / 3600.0;
  /* 
   * before 1972, we treat input date as UT1 
   */
  if (tjd_ut1 < J1972) {
    dret[1] = swe_julday(iyear, imonth, iday, dhour, gregflag);
    dret[0] = dret[1] + swe_deltat(dret[1]);
    return OK;
  }
  /* 
   * if gregflag = Julian calendar, convert to gregorian calendar 
   */
  if (gregflag == SE_JUL_CAL) {
    gregflag = SE_GREG_CAL;
    swe_revjul(tjd_ut1, gregflag, &iyear, &imonth, &iday, &d);
  }
  /* 
   * number of leap seconds since 1972: 
   */
  tabsiz_nleap = init_leapsec();
  nleap = NLEAP_INIT; /* initial difference between UTC and TAI in 1972 */
  ndat = iyear * 10000 + imonth * 100 + iday;
  for (i = 0; i < tabsiz_nleap; i++) {
    if (ndat <= leap_seconds[i])
      break;
    nleap++;
  }
  /*
   * For input dates > today:
   * If leap seconds table is not up to date, we'd better interpret the
   * input time as UT1, not as UTC. How do we find out? 
   * Check, if delta_t - nleap - 32.184 > 0.9
   */
  d = swe_deltat(tjd_ut1) * 86400.0;
  if (d - (double) nleap - 32.184 >= 1.0) {
    dret[1] = tjd_ut1 + dhour / 24.0;
    dret[0] = dret[1] + swe_deltat(dret[1]);
    return OK;
  }
  /* 
   * if input second is 60: is it a valid leap second ? 
   */
  if (dsec >= 60) {
    j = 0;
    for (i = 0; i < tabsiz_nleap; i++) {
      if (ndat == leap_seconds[i]) {
	j = 1;
	break;
      }
    }
    if (j != 1) {
      if (serr != NULL)
	sprintf(serr, "invalid time (no leap second!): %d:%d:%.2f", ihour, imin, dsec);
      return ERR;
    }
  }
  /* 
   * convert UTC to ET and UT1 
   */
  /* the number of days between input date and 1 jan 1972: */
  d = tjd_ut1 - J1972;
  /* SI time since 1972, ignoring leap seconds: */
  d += (double) ihour / 24.0 + (double) imin / 1440.0 + dsec / 86400.0; 
  /* ET (TT) */
  tjd_et_1972 = J1972 + (32.184 + NLEAP_INIT) / 86400.0;
  tjd_et = tjd_et_1972 + d + ((double) (nleap - NLEAP_INIT)) / 86400.0;
  d = swe_deltat(tjd_et);
  tjd_ut1 = tjd_et - swe_deltat(tjd_et - d);
  dret[0] = tjd_et;
  dret[1] = tjd_ut1;
  return OK;
}
Exemplo n.º 8
0
static int swisseph(char *buf)
{
  char serr[AS_MAXCH*2], serr_save[AS_MAXCH], serr_warn[AS_MAXCH];
  char s[AS_MAXCH]; 
  char s1[AS_MAXCH], s2[AS_MAXCH];
  char star[AS_MAXCH];
  char *sp, *sp2;
  char se_pname[AS_MAXCH];
  char *spnam, *spnam2 = "";
  char *fmt = "PZBRS";
  char *plsel, *psp;
  char *gap = " ";
  double jut = 0.0, y_frac;
  int i, j;
  double hpos;
  int jday, jmon, jyear, jhour, jmin, jsec;
  int ipl, ipldiff = SE_SUN;
  double x[6], xequ[6], xcart[6], xcartq[6];
  double cusp[12+1];    /* cusp[0] + 12 houses */
  double ascmc[10];		/* asc, mc, vertex ...*/
  double ar, sinp;
  double a, sidt, armc, lon, lat;
  double eps_true, eps_mean, nutl, nuto;
  char ephepath[AS_MAXCH];
  char fname[AS_MAXCH];
  char splan[100], sast[AS_MAXCH];
  int nast, iast;
  long astno[100];
  long iflag = 0, iflag2;              /* external flag: helio, geo... */
  long iflgret;
  long whicheph = SEFLG_SWIEPH;
  AS_BOOL universal_time = FALSE;
  AS_BOOL calc_house_pos = FALSE;
  short gregflag;
  AS_BOOL diff_mode = FALSE;
  int round_flag = 0;
  double tjd_ut = 2415020.5;
  double tjd_et, t2;
  double delt;
  char bc[20];
  char *jul;
  int hsys = (int) *pd.hsysname;
  *serr = *serr_save = *serr_warn = '\0';
  strcpy(ephepath, SE_EPHE_PATH);
  if (strcmp(pd.ephe, ephe[1]) == 0) {
    whicheph = SEFLG_JPLEPH;
    strcpy(fname, SE_FNAME_DE406);
  } else if (strcmp(pd.ephe, ephe[0]) == 0) 
    whicheph = SEFLG_SWIEPH;
  else
    whicheph = SEFLG_MOSEPH;
  if (strcmp(pd.etut, "UT") == 0)
    universal_time = TRUE;
  if (strcmp(pd.plansel, plansel[0]) == 0) {
    plsel = PLSEL_D;
  } else if (strcmp(pd.plansel, plansel[1]) == 0) {
    plsel = PLSEL_P;
  } else if (strcmp(pd.plansel, plansel[2]) == 0) {
    plsel = PLSEL_A;
  }
  if (strcmp(pd.ctr, ctr[0]) == 0)
    calc_house_pos = TRUE;
  else if (strcmp(pd.ctr, ctr[1]) == 0) {
    iflag |= SEFLG_TOPOCTR;
    calc_house_pos = TRUE;
  } else if (strcmp(pd.ctr, ctr[2]) == 0) {
    iflag |= SEFLG_HELCTR;
  } else if (strcmp(pd.ctr, ctr[3]) == 0) {
    iflag |= SEFLG_BARYCTR;
  } else if (strcmp(pd.ctr, ctr[4]) == 0) {
    iflag |= SEFLG_SIDEREAL;
	swe_set_sid_mode(SE_SIDM_FAGAN_BRADLEY, 0, 0);
  } else if (strcmp(pd.ctr, ctr[5]) == 0) {
    iflag |= SEFLG_SIDEREAL;
	swe_set_sid_mode(SE_SIDM_LAHIRI, 0, 0);
#if 0
  } else {
    iflag &= ~(SEFLG_HELCTR | SEFLG_BARYCTR | SEFLG_TOPOCTR);
#endif
  }
  lon = pd.lon_deg + pd.lon_min / 60.0 + pd.lon_sec / 3600.0;
  if (*pd.lon_e_w == 'W')
    lon = -lon;
  lat = pd.lat_deg + pd.lat_min / 60.0 + pd.lat_sec / 3600.0;
  if (*pd.lat_n_s == 'S')
    lat = -lat;
  sprintf(s, "Planet Positions from %s \n\n", pd.ephe);
  do_print(buf, s);                               
  if (whicheph & SEFLG_JPLEPH)
    swe_set_jpl_file(fname);
  iflag = (iflag & ~SEFLG_EPHMASK) | whicheph;
  iflag |= SEFLG_SPEED;
#if 0
  if (pd.helio) iflag |= SEFLG_HELCTR;
#endif
  if ((long) pd.year * 10000L + (long) pd.mon * 100L + (long) pd.mday < 15821015L) 
    gregflag = FALSE;
  else
    gregflag = TRUE;
  jday = pd.mday;
  jmon = pd.mon;
  jyear = pd.year;
  jhour = pd.hour;
  jmin = pd.min;
  jsec = pd.sec;
  jut = jhour + jmin / 60.0 + jsec / 3600.0;
  tjd_ut = swe_julday(jyear,jmon,jday,jut,gregflag);
  swe_revjul(tjd_ut, gregflag, &jyear, &jmon, &jday, &jut);
  jut += 0.5 / 3600;
  jhour = (int) jut;
  jmin = (int) fmod(jut * 60, 60);
  jsec = (int) fmod(jut * 3600, 60);
  *bc = '\0';
  if (pd.year <= 0)
    sprintf(bc, "(%d B.C.)", 1 - jyear);
  if (jyear * 10000L + jmon * 100L + jday <= 15821004)
    jul = "jul.";
  else
    jul = "";
  sprintf(s, "%d.%d.%d %s %s    %#02d:%#02d:%#02d %s\n",
    jday, jmon, jyear, bc, jul,
    jhour, jmin, jsec, pd.etut);
  do_print(buf, s);
  jut = jhour + jmin / 60.0 + jsec / 3600.0;
  if (universal_time) {
    delt = swe_deltat(tjd_ut);
    sprintf(s, " delta t: %f sec", delt * 86400.0);
    do_print(buf, s);
    tjd_et = tjd_ut + delt;
  } else
    tjd_et = tjd_ut;
  sprintf(s, " jd (ET) = %f\n", tjd_et);
  do_print(buf, s);
  iflgret = swe_calc(tjd_et, SE_ECL_NUT, iflag, x, serr);
  eps_true = x[0];
  eps_mean = x[1];
  strcpy(s1, dms(eps_true, round_flag));
  strcpy(s2, dms(eps_mean, round_flag));
  sprintf(s, "\n%-15s %s%s%s    (true, mean)", "Ecl. obl.", s1, gap, s2);
  do_print(buf, s);
  nutl = x[2];
  nuto = x[3];
  strcpy(s1, dms(nutl, round_flag));
  strcpy(s2, dms(nuto, round_flag));
  sprintf(s, "\n%-15s %s%s%s    (dpsi, deps)", "Nutation", s1, gap, s2);
  do_print(buf, s);
  do_print(buf, "\n\n");
  do_print(buf, "               ecl. long.       ecl. lat.   ");
  do_print(buf, "    dist.          speed");
  if (calc_house_pos)
    do_print(buf, "          house");
  do_print(buf, "\n");
  if (iflag & SEFLG_TOPOCTR)
    swe_set_topo(lon, lat, pd.alt);
  sidt = swe_sidtime(tjd_ut) + lon / 15;
  if (sidt >= 24)
    sidt -= 24;
  if (sidt < 0)
    sidt += 24;
  armc = sidt * 15;
  /* additional asteroids */
  strcpy(splan, plsel);
  if (strcmp(plsel,PLSEL_P) == 0) {
    char *cpos[40];
    strcpy(sast, pd.sast);
    j = cut_str_any(sast, ",;. \t", cpos, 40);
    for (i = 0, nast = 0; i < j; i++) {
      if ((astno[nast] = atol(cpos[i])) > 0) {
	nast++;
	strcat(splan, "+");
      }
    }
  }
  for (psp = splan, iast = 0; *psp != '\0'; psp++) {
    if (*psp == '+') {
      ipl = SE_AST_OFFSET + (int) astno[iast];
	  iast++;
    } else
      ipl = letter_to_ipl(*psp);
    if (iflag & SEFLG_HELCTR) {
      if (ipl == SE_SUN
        || ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE
        || ipl == SE_MEAN_APOG || ipl == SE_OSCU_APOG)
      continue;
    } else if (iflag & SEFLG_BARYCTR) {
      if (ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE
        || ipl == SE_MEAN_APOG || ipl == SE_OSCU_APOG)
      continue;
    } else          /* geocentric */
      if (ipl == SE_EARTH)
        continue;
    /* ecliptic position */
    if (ipl == SE_FIXSTAR) {
      iflgret = swe_fixstar(star, tjd_et, iflag, x, serr);
      strcpy(se_pname, star);
    } else {
      iflgret = swe_calc(tjd_et, ipl, iflag, x, serr);
      swe_get_planet_name(ipl, se_pname);
	  if (ipl > SE_AST_OFFSET) {
   	    sprintf(s, "#%d", (int) astno[iast-1]);
		strcat(se_pname, "            ");
		strcpy(se_pname + 11 - strlen(s), s);
	  }
    }
    if (iflgret >= 0) {
      if (calc_house_pos) {
        hpos = swe_house_pos(armc, lat, eps_true, hsys, x, serr);
        if (hpos == 0)
          iflgret = ERR;
      }
    }
    if (iflgret < 0) {
      if (*serr != '\0' && strcmp(serr, serr_save) != 0) {
        strcpy (serr_save, serr);
        do_print(buf, "error: ");
        do_print(buf, serr);
        do_print(buf, "\n");
      }
    } else if (*serr != '\0' && *serr_warn == '\0')
      strcpy(serr_warn, serr);
    /* equator position */
    if (strpbrk(fmt, "aADdQ") != NULL) {
      iflag2 = iflag | SEFLG_EQUATORIAL;
      if (ipl == SE_FIXSTAR)
        iflgret = swe_fixstar(star, tjd_et, iflag2, xequ, serr);
      else
        iflgret = swe_calc(tjd_et, ipl, iflag2, xequ, serr);
    }
    /* ecliptic cartesian position */
    if (strpbrk(fmt, "XU") != NULL) {
      iflag2 = iflag | SEFLG_XYZ;
      if (ipl == SE_FIXSTAR)
        iflgret = swe_fixstar(star, tjd_et, iflag2, xcart, serr);
      else
        iflgret = swe_calc(tjd_et, ipl, iflag2, xcart, serr);
    }
    /* equator cartesian position */
    if (strpbrk(fmt, "xu") != NULL) {
      iflag2 = iflag | SEFLG_XYZ | SEFLG_EQUATORIAL;
      if (ipl == SE_FIXSTAR)
        iflgret = swe_fixstar(star, tjd_et, iflag2, xcartq, serr);
      else
        iflgret = swe_calc(tjd_et, ipl, iflag2, xcartq, serr);
    }
    spnam = se_pname;
    /*
     * The string fmt contains a sequence of format specifiers;
     * each character in fmt creates a column, the columns are
     * sparated by the gap string.
     */
    for (sp = fmt; *sp != '\0'; sp++) {
      if (sp != fmt) 
        do_print(buf, gap);
      switch(*sp) {
      case 'y':
          sprintf(s, "%d", jyear);
          do_print(buf, s);
          break;
      case 'Y':
          jut = 0;
          t2 = swe_julday(jyear,1,1,jut,gregflag);
          y_frac = (tjd_ut - t2) / 365.0;
          sprintf(s, "%.2lf", jyear + y_frac);
          do_print(buf, s);
          break;
      case 'p':
          if (diff_mode)
            sprintf(s, "%d-%d", ipl, ipldiff);
          else
            sprintf(s, "%d", ipl);
          do_print(buf, s);
          break;
      case 'P':
          if (diff_mode)
            sprintf(s, "%.3s-%.3s", spnam, spnam2);
          else
            sprintf(s, "%-11s", spnam);
          do_print(buf, s);
          break;
      case 'J':
      case 'j':
          sprintf(s, "%.2f", tjd_ut);
          do_print(buf, s);
          break;
      case 'T':
          sprintf(s, "%02d.%02d.%d", jday, jmon, jyear);
          do_print(buf, s);
          break;
      case 't':
          sprintf(s, "%02d%02d%02d", jyear % 100, jmon, jday);
          do_print(buf, s);
          break;
      case 'L':
          do_print(buf, dms(x[0], round_flag));
          break;
      case 'l':
          sprintf(s, "%# 11.7f", x[0]);
          do_print(buf, s);
          break;
      case 'Z':
          do_print(buf, dms(x[0], round_flag|BIT_ZODIAC));
          break;
      case 'S':
      case 's':
          if (*(sp+1) == 'S' || *(sp+1) == 's' || strpbrk(fmt, "XUxu") != NULL) {
            for (sp2 = fmt; *sp2 != '\0'; sp2++) {
              if (sp2 != fmt) 
                do_print(buf, gap);
              switch(*sp2) {
                case 'L':       /* speed! */
                case 'Z':       /* speed! */
                  do_print(buf, dms(x[3], round_flag));
                  break;
                case 'l':       /* speed! */
                  sprintf(s, "%11.7f", x[3]);
                  do_print(buf, s);
                  break;
                case 'B':       /* speed! */
                  do_print(buf, dms(x[4], round_flag));
                  break;
                case 'b':       /* speed! */
                  sprintf(s, "%11.7f", x[4]);
                  do_print(buf, s);
                  break;
                case 'A':       /* speed! */
                  do_print(buf, dms(xequ[3]/15, round_flag|SEFLG_EQUATORIAL));
                  break;
                case 'a':       /* speed! */
                  sprintf(s, "%11.7f", xequ[3]);
                  do_print(buf, s);
                  break;
                case 'D':       /* speed! */
                  do_print(buf, dms(xequ[4], round_flag));
                  break;
                case 'd':       /* speed! */
                  sprintf(s, "%11.7f", xequ[4]);
                  do_print(buf, s);
                  break;
                case 'R':       /* speed! */
                case 'r':       /* speed! */
                  sprintf(s, "%# 14.9f", x[5]);
                  do_print(buf, s);
                  break;
                case 'U':       /* speed! */
                case 'X':       /* speed! */
                  if (*sp =='U') 
                    ar = sqrt(square_sum(xcart));
                  else 
                    ar = 1;
                  sprintf(s, "%# 14.9f%s", xcart[3]/ar, gap);
                  do_print(buf, s);
                  sprintf(s, "%# 14.9f%s", xcart[4]/ar, gap);
                  do_print(buf, s);
                  sprintf(s, "%# 14.9f", xcart[5]/ar);
                  do_print(buf, s);
                  break;
                case 'u':       /* speed! */
                case 'x':       /* speed! */
                  if (*sp =='u') 
                    ar = sqrt(square_sum(xcartq));
                  else 
                    ar = 1;
                  sprintf(s, "%# 14.9f%s", xcartq[3]/ar, gap);
                  do_print(buf, s);
                  sprintf(s, "%# 14.9f%s", xcartq[4]/ar, gap);
                  do_print(buf, s);
                  sprintf(s, "%# 14.9f", xcartq[5]/ar);
                  do_print(buf, s);
                  break;
                default:
                  break;
              }
            }
            if (*(sp+1) == 'S' || *(sp+1) == 's')
              sp++;
          } else {
            do_print(buf, dms(x[3], round_flag));
          }
          break;
      case 'B':
          do_print(buf, dms(x[1], round_flag));
          break;
      case 'b':
          sprintf(s, "%# 11.7f", x[1]);
          do_print(buf, s);
          break;
      case 'A': /* rectascensio */
          do_print(buf, dms(xequ[0]/15, round_flag|SEFLG_EQUATORIAL));
          break;
      case 'a': /* rectascensio */
          sprintf(s, "%# 11.7f", xequ[0]);
          do_print(buf, s);
          break;
      case 'D': /* declination */
          do_print(buf, dms(xequ[1], round_flag));
          break;
      case 'd': /* declination */
          sprintf(s, "%# 11.7f", xequ[1]);
          do_print(buf, s);
          break;
      case 'R':
          sprintf(s, "%# 14.9f", x[2]);
          do_print(buf, s);
          break;
      case 'r':
          if ( ipl == SE_MOON ) { /* for moon print parallax */
            sinp = 8.794 / x[2];        /* in seconds of arc */
            ar = sinp * (1 + sinp * sinp * 3.917402e-12);
            /* the factor is 1 / (3600^2 * (180/pi)^2 * 6) */
            sprintf(s, "%# 13.5f\"", ar);       
          } else {
            sprintf(s, "%# 14.9f", x[2]);
          }
          do_print(buf, s);
          break;
      case 'U':
      case 'X':
          if (*sp =='U') 
            ar = sqrt(square_sum(xcart));
          else 
            ar = 1;
          sprintf(s, "%# 14.9f%s", xcart[0]/ar, gap);
          do_print(buf, s);
          sprintf(s, "%# 14.9f%s", xcart[1]/ar, gap);
          do_print(buf, s);
          sprintf(s, "%# 14.9f", xcart[2]/ar);
          do_print(buf, s);
          break;
      case 'u':
      case 'x':
          if (*sp =='u') 
            ar = sqrt(square_sum(xcartq));
          else 
            ar = 1;
          sprintf(s, "%# 14.9f%s", xcartq[0]/ar, gap);
          do_print(buf, s);
          sprintf(s, "%# 14.9f%s", xcartq[1]/ar, gap);
          do_print(buf, s);
          sprintf(s, "%# 14.9f", xcartq[2]/ar);
          do_print(buf, s);
          break;
      case 'Q':
          sprintf(s, "%-15s", spnam);
          do_print(buf, s);
          do_print(buf, dms(x[0], round_flag));
          do_print(buf, dms(x[1], round_flag));
          sprintf(s, "  %# 14.9f", x[2]);
          do_print(buf, s);
          do_print(buf, dms(x[3], round_flag));
          do_print(buf, dms(x[4], round_flag));
          sprintf(s, "  %# 14.9f\n", x[5]);
          do_print(buf, s);
          sprintf(s, "               %s", dms(xequ[0], round_flag));
          do_print(buf, s);
          do_print(buf, dms(xequ[1], round_flag));
          sprintf(s, "                %s", dms(xequ[3], round_flag));
          do_print(buf, s);
          do_print(buf, dms(xequ[4], round_flag));
          break;
      } /* switch */
    }   /* for sp */
    if (calc_house_pos) {
      sprintf(s, "  %# 6.4f", hpos);
          sprintf(s, "%# 9.4f", hpos);
      do_print(buf, s);
    }
    do_print(buf, "\n");
  }     /* for psp */
  if (*serr_warn != '\0') {
    do_print(buf, "\nwarning: ");
    do_print(buf, serr_warn);
    do_print(buf, "\n");
  }
  /* houses */
  sprintf(s, "\nHouse Cusps (%s)\n\n", pd.hsysname);
  do_print(buf, s);
  a = sidt + 0.5 / 3600;
  sprintf(s, "sid. time : %4d:%#02d:%#02d  ",
        (int) a, (int) fmod(a * 60, 60), (int) fmod(a * 3600, 60));
  do_print(buf, s);
  a = armc + 0.5 / 3600;
  sprintf(s, "armc      : %4d%c%#02d'%#02d\"\n",
        (int) armc, ODEGREE_CHAR, (int) fmod(armc * 60, 60),
        (int) fmod(a * 3600, 60));
  do_print(buf, s);
  sprintf(s, "geo. lat. : %4d%c%#02d'%#02d\" ",
        pd.lat_deg, *pd.lat_n_s, pd.lat_min, pd.lat_sec);
  do_print(buf, s);
  sprintf(s, "geo. long.: %4d%c%#02d'%#02d\"\n\n",
        pd.lon_deg, *pd.lon_e_w, pd.lon_min, pd.lon_sec);
  do_print(buf, s);
  swe_houses_ex(tjd_ut, iflag, lat, lon, hsys, cusp, ascmc);
  round_flag |= BIT_ROUND_SEC;
#if FALSE
  sprintf(s, "AC        : %s\n", dms(ascmc[0], round_flag));
  do_print(buf, s);
  sprintf(s, "MC        : %s\n", dms(ascmc[1], round_flag));
  do_print(buf, s);
  for (i = 1; i <= 12; i++) {
	sprintf(s, "house   %2d: %s\n", i, dms(cusp[i], round_flag));
    do_print(buf, s);
  }
  sprintf(s, "Vertex    : %s\n", dms(ascmc[3], round_flag));
  do_print(buf, s);
#else
  sprintf(s, "AC        : %s\n", dms(ascmc[0], round_flag|BIT_ZODIAC));
  do_print(buf, s);
  sprintf(s, "MC        : %s\n", dms(ascmc[1], round_flag|BIT_ZODIAC));
  do_print(buf, s);
  for (i = 1; i <= 12; i++) {
	sprintf(s, "house   %2d: %s\n", i, dms(cusp[i], round_flag|BIT_ZODIAC));
    do_print(buf, s);
  }
  sprintf(s, "Vertex    : %s\n", dms(ascmc[3], round_flag|BIT_ZODIAC));
  do_print(buf, s);
#endif  
  return 0;
}
Exemplo n.º 9
0
Arquivo: sb.c Projeto: musalisa/se
int main()
{
  swe_set_ephe_path("./SWEP/");
  char snam[40], serr[AS_MAXCH]; 
  int jday = 07, jmon = 11, jyear = 1964;
  int ora = 23;
  int min = 3;
  double jut = ora + min / 60;
  static double geopos[3], armc;

  /* Alessandra 44°54′48″N 8°37′12″E 95m */
  top_long = 44.916; top_lat = 8.616; top_elev = 95;
  /* Milano 45°27′50.98″N 9°11′25.21″E 122m */
  /* top_long = 45.464; top_lat = 9.19; top_elev = 122;a */
  geopos[0] = top_long;
  geopos[1] = top_lat;
  geopos[2] = top_elev;
  swe_set_topo(top_long, top_lat, top_elev);

  double tjd, te, x2[6];
  int32 iflag, iflgret;
  int p;
  iflag = SEFLG_SPEED;
  /*
   * we have day, month and year and convert to Julian day number
   */
  tjd = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);        
  /*
   * compute Ephemeris time from Universal time by adding delta_t
   */
   te = tjd + swe_deltat(tjd);
   printf("date: %02d.%02d.%d at %02d:%02d Universal time\n", jday, jmon, jyear, ora, min);
   printf("planet     \tlongitude\tlatitude\tdistance\tspeed long.\n");
	    /*
	     * a loop over all planets
	     */
    for (p = SE_SUN; p <= SE_SATURN; p++) {
      if (p == SE_EARTH) continue;
		/*
		 * do the coordinate calculation for this planet p
		 */
      iflgret = swe_calc(te, p, iflag, x2, serr);
	      /*
	       * if there is a problem, a negative value is returned and an 
	       * errpr message is in serr.
	       */
      if (iflgret < 0) 
	printf("error: %s\n", serr);
      else if (iflgret != iflag)
	printf("warning: iflgret != iflag. %s\n", serr);
	      /*
	       * get the name of the planet p
	       */
      swe_get_planet_name(p, snam);
	      /*
	       * print the coordinates
	       */
      printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
	     snam, x2[0], x2[1], x2[2], x2[3]);
    }
    /* iflag = SEFLG_SWIEPH | SEFLG_SPEED | SEFLG_EQUATORIAL; */
    iflag = SEFLG_SPEED | SEFLG_EQUATORIAL;
    printf("planet   \tasc retta \tdeclinazione\n");
	    /*
	     * a loop over all planets
	     */
    for (p = SE_SUN; p <= SE_SATURN; p++) {
      if (p == SE_EARTH) continue;
		/*
		 * do the coordinate calculation for this planet p
		 */
      iflgret = swe_calc(te, p, iflag, x2, serr);
	      /*
	       * if there is a problem, a negative value is returned and an 
	       * errpr message is in serr.
	       */
      if (iflgret < 0) 
	printf("error: %s\n", serr);
      else if (iflgret != iflag)
	printf("warning: iflgret != iflag. %s\n", serr);
	      /*
	       * get the name of the planet p
	       */
      swe_get_planet_name(p, snam);
	      /*
	       * print the coordinates
	       */
      printf("%10s\t%11.3f\t%10.3f\n",
	     snam, x2[0], x2[1]);
    }
  return OK;
}
Exemplo n.º 10
0
/*************** julday ******************
  get absolute julian day number (author: Marc Pottenger)
  with bug fix for year < -4711   15-aug-88
*/
double juldays(int gregflag, ADATE *adp ) 
{
  return swe_julday(adp->year, adp->month, adp->day, adp->csec / 360000.0, gregflag);
}
Exemplo n.º 11
0
double julday(int month, int day, int year, double hour, int gregflag) 
{
  double jd;
  jd = swe_julday(year, month, day, hour, gregflag);
  return jd;
}
Exemplo n.º 12
0
Arquivo: swe4r.c Projeto: aakara/swe4r
/*
 * Get the Julian day number from year, month, day, hour
 * http://www.astro.com/swisseph/swephprg.htm#_Toc283735468
	double swe_julday(
 		int year, 
		int month, 
		int day, 
		double hour,
		int gregflag	// Gregorian calendar: 1, Julian calendar: 0 
	);
 */
static VALUE t_swe_julday(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour)
{
	double julday = swe_julday( NUM2INT(year), NUM2INT(month), NUM2INT(day), NUM2DBL(hour), SE_GREG_CAL );
	return rb_float_new(julday);
}