Ejemplo n.º 1
0
//--------------------------------------------------------------------  
// Compute planetary longitude for a jd_et
// Buffer the results
//--------------------------------------------------------------------  
double zodiacalLength( int pl, double jd_et) {
  
  int i;     
  long iflag=0, iret=0;
  double xx[6];  
  char serr[256];
  
  assert(pl_buf != 0); // Buffer for planetary positions not assigned

// Switching to a new jd: reset buffer  
  if (jd_et != jd_pl_buf) {
    jd_pl_buf = jd_et;      
    for (i=0;i<scoreFunction.cdata.pl2ipl_size;i++) pl_buf[i].computed = false;         
    }
// Compute longitude if necessary    
  if (!pl_buf[pl].computed) {
    iret = swe_calc(jd_et, scoreFunction.cdata.pl2ipl[pl], iflag, xx, serr);
    if ( iret < 0 || 
         ( iret > 0 && ! params.continue_with_moshier ) ) {
      fprintf(stderr, "%s\n", serr);
      exit(EXIT.EPHEMERIS_CALL_ERROR);
      }
    pl_buf[pl].x = xx[0];
    pl_buf[pl].computed = true;
    }
  return pl_buf[pl].x; 
  }
Ejemplo n.º 2
0
//--------------------------------------------------------------------  
// Compute the house position, as mundane position, 
// i.e. 0 = cusp I, 90 = cusp IV, 180 = cusp VII, 270 = cusp X
//--------------------------------------------------------------------  
double mundanePosition( int pl, _hordat* hor) {

  int rc;
	double xpin[2],xx[6];
	char serr[256];

  assert(mp_buf != 0); // Buffer for mundane positions not assigned

// Switching to a new horoscope: reset buffer  
  if (!memcmp(hor,&hor_mp_buf,sizeof(_hordat))) {
    hor_mp_buf = *hor;      
    for (int i=0;i<scoreFunction.cdata.pl2ipl_size;i++) {
      mp_buf[i].computed = false;         
      }
    mp_buf_armc = red360( swe_sidtime( hor->jd_ut )*15 + hor->lon );
    rc = swe_calc(hor->jd, SE_ECL_NUT, 0, xx, serr);
    if (rc!=0) {
      fprintf(stderr,"%s",serr);
      exit(EXIT.EPHEMERIS_CALL_ERROR);
      }
    mp_buf_eps = xx[0];
    }
    
// Compute mundane position if necessary    
  if (!mp_buf[pl].computed) {    
    xpin[0] = zodiacalLength( pl, hor->jd );
    xpin[1] = 0;
    mp_buf[pl].x = 30 * ( swe_house_pos( mp_buf_armc, hor->lat, mp_buf_eps, params.hsys, xpin, serr) - 1);
    mp_buf[pl].computed = true;        
    }

  return mp_buf[pl].x;

  }
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/* planets, moon, nodes etc. */
static PyObject* astrology_swe_calc(PyObject *self, PyObject *args)
{
	double tjd;
	int ipl;
	int iflag;

	if (!PyArg_ParseTuple(args, "dii", &tjd, &ipl, &iflag))
		return NULL;

	double xx[6];
	char serr[AS_MAXCH];
	int ret = swe_calc(tjd, ipl, iflag, xx, serr);

	return Py_BuildValue("(l)(dddddd)(s)", ret, xx[0], xx[1], xx[2], xx[3], xx[4], xx[5], serr);
}
Ejemplo n.º 5
0
//--------------------------------------------------------------------  
// Mit Swiss Ephemeris die Länge eines Planeten ipl
// zum julianischen Datum jd (in Ephemeridenzeit) berechnen   
//--------------------------------------------------------------------  
double planet( int ipl, double jd) {
  int i;     
  long iflag=0, iret=0;
  static double xx[6];  
  static char serr[256];
// Gepufferter Zugriff  
  static double pl_buf[10] = {-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.};
  static double jd_buf = 0.;
  if (jd != jd_buf) {
    jd_buf = jd;      
    for (i=0;i<10;i++) pl_buf[i] = -1.;         
    }
  if (pl_buf[ipl] < 0) {
    iret = swe_calc(jd, ipl, iflag, xx, serr);
    if (iret != 0) {
      fprintf(stderr, "%s\n", serr);
      }
    pl_buf[ipl] = xx[0];
    }
  return pl_buf[ipl];  
  }
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
/******************************************************************
   function calc(): 
   This is the main routine for computing a planets position.
   The function has several modes, which are controlled by bits in
   the parameter 'flag'. The normal mode (flag == 0) computes
   a planets apparent geocentric position in ecliptic coordinates relative to
   the true equinox of date, without speed

   Explanation of the arguments: see the functions header.

   Returns OK or ERR (if some planet out of time range). OK and ERR are
   defined in ourdef.h and must not be confused with TRUE and FALSE.
   OK and ERR are of type int, not of type AS_BOOL.

   Bits used in flag:
   CALC_BIT_HELIO  		0 = geocentric, 1 = heliocentric
   CALC_BIT_NOAPP 	   	0 = apparent positions, 1 = true positions
   CALC_BIT_NONUT 		0 = do nutation (true equinox of date)
				1 = don't do nutation (mean equinox of date).

   CALC_BIT_SPEED 		0 = don't calc speed,
				1 = calc speed

   Time range:
   The function can be used savely in the time range 3000 BC to
   3000 AD. 

   Getting ecliptic and nutation:
   calc(CALC_ONLY_ECL_NUT,teph,0,&nutv,&meaneklv,&eklv,NULL);
   will return the values for time teph.

******************************************************************/
int calc(int  planet,  	/* planet index as defined in placalc.h,
			 SUN = 0, MOON = 1 etc.
			 planet == -1 calc calculates only nut, ekl, meanekl */
	 double jd_ad,	/* relative Astrodienst Juldate, ephemeris time.
			 Astrodienst Juldate is relative 31 Dec 1949, noon. */
	 int  flag,	/* See definition of flag bits above */
	 double *alng,
	 double *arad,
	 double *alat,
	 double *alngspeed)
      /* pointers to the return variables:
	 alng = ecliptic longitude in degrees
	 arad = radius vector in AU (astronomic units)
	 alat = ecliptic latitude in degrees
	 alngspeed = speed of planet in degrees per day
       */
{
  double tjd = jd_ad + JUL_OFFSET;
  double x[6];
  int32 iflagret = 0, iflag = 0;
  int ipl;
  /* planet number 
   */
  /* ecliptic and nutation */
  if (planet == CALC_ONLY_ECL_NUT)
    ipl = SE_ECL_NUT;
  /* earth: placalc makes no difference between sun and earth, 
   *        swisseph does */
  else if (planet == SUN && (flag & CALC_BIT_HELIO))
    ipl = SE_EARTH;	
  else if (planet >= SUN && planet <= VESTA)
    ipl = plac2swe[planet];
  else {
    sprintf(perrtx, "invalid planet number %d. ", planet);
    return ERR;
  }
  /* flag */
  if (flag & CALC_BIT_HELIO)
    if (ipl != SE_MEAN_NODE && ipl != SE_TRUE_NODE && ipl != SE_MEAN_APOG)
      iflag |= SEFLG_HELCTR; /* lunar node and apogee is always geocentric */
  if (flag & CALC_BIT_NOAPP)
    iflag |= SEFLG_TRUEPOS;
  if (flag & CALC_BIT_NONUT)
    iflag |= SEFLG_NONUT;
  if (flag & CALC_BIT_SPEED)
    iflag |= SEFLG_SPEED;
  /* ecliptic and nutation */
  if ((iflagret = swe_calc(tjd, ipl, iflag, x, perrtx)) == ERR)
    return iflagret;
  if (ipl == SE_ECL_NUT) {
    *alng = nut = x[2];
    *arad = x[1];
    *alat = ekl = x[0];
  } else {
    *alng = x[0];
    *arad = x[2];
    *alat = x[1];
    *alngspeed = x[3];
  }
  return (OK);
} /* end calc */
Ejemplo n.º 8
0
int swe_sx_nod_aps(double tjd_et, int ind, int iflag,
                   int  method,
                   double *xnasc, double *xndsc,
                   double *xperi, double *xaphe,
                   char *serr)
{
  int ij, i, j,ipl,fEquatorT,fUseJ2000T;
  int32 iplx;
  int32 ipli;
  int istart, iend;
  int32 iflJ2000;
  double plm;
  double t = (tjd_et - J2000) / 36525, dt;
  double x[6], xx[24], *xp, xobs[6], x2000[6];
  double xpos[3][6], xnorm[6];
  double xposm[6];
  double xn[3][6], xs[3][6];
  double xq[3][6], xa[3][6];
  double xobs2[6], x2[6];
  double *xna, *xnd, *xpe, *xap;
  double incl, sema, ecce, parg, ea, vincl, vsema, vecce, pargx, eax;
  struct plan_data *pedp = &swed.pldat[SEI_EARTH];
  struct plan_data *psbdp = &swed.pldat[SEI_SUNBARY];
  struct plan_data pldat;
  double *xsun = psbdp->x;
  double *xear = pedp->x;
  double *ep;
  double Gmsm, dzmin;
  double rxy, rxyz, fac, sgn;
  double sinnode, cosnode, sinincl, cosincl, sinu, cosu, sinE, cosE, cosE2;
  double uu, ny, ny2, c2, v2, pp, ro, ro2, rn, rn2;
  struct epsilon *oe;
  AS_BOOL is_true_nodaps = FALSE;
  AS_BOOL do_aberr = !(iflag & (SEFLG_TRUEPOS | SEFLG_NOABERR));
  AS_BOOL do_defl = !(iflag & SEFLG_TRUEPOS) && !(iflag & SEFLG_NOGDEFL);
  AS_BOOL do_focal_point = method & SE_NODBIT_FOPOINT;
  AS_BOOL ellipse_is_bary = FALSE;
  int32 iflg0;
  /* function calls for Pluto with asteroid number 134340
   * are treated as calls for Pluto as main body SE_PLUTO */
  ipl = AlToSweObj(ind);
  if (ipl == SE_WHITE_MOON)
    ipl = SE_AST_OFFSET+MaxNumberedAsteroid;
  if (ipl == SE_AST_OFFSET + 134340)
    ipl = SE_PLUTO;
  xna = xx;
  xnd = xx+6;
  xpe = xx+12;
  xap = xx+18;
  xpos[0][0] = 0; /* to shut up mint */
  /* to get control over the save area: */
  swi_force_app_pos_etc();
  method %= SE_NODBIT_FOPOINT;
  ipli = ipl;
  if (ipl == SE_SUN)
    ipli = SE_EARTH;
  if (ipl == SE_MOON)
    {
      do_defl = FALSE;
      if (!(iflag & SEFLG_HELCTR))
        do_aberr = FALSE;
    }
  iflg0 = (iflag & (SEFLG_EPHMASK|SEFLG_NONUT)) | SEFLG_SPEED | SEFLG_TRUEPOS;
  if (ipli != SE_MOON)
    iflg0 |= SEFLG_HELCTR;
  if (ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE ||
      ipl == SE_MEAN_APOG || ipl == SE_OSCU_APOG ||
      ipl < 0 ||
      (ipl >= SE_NPLANETS && ipl <= SE_AST_OFFSET))
    {
      /*(ipl >= SE_FICT_OFFSET && ipl - SE_FICT_OFFSET < SE_NFICT_ELEM)) */
      if (serr != NULL)
        sprintf(serr, "nodes/apsides for planet %5.0f are not implemented", (double) ipl);
      if (xnasc != NULL)
        for (i = 0; i <= 5; i++)
          xnasc[i] = 0;
      if (xndsc != NULL)
        for (i = 0; i <= 5; i++)
          xndsc[i] = 0;
      if (xaphe != NULL)
        for (i = 0; i <= 5; i++)
          xaphe[i] = 0;
      if (xperi != NULL)
        for (i = 0; i <= 5; i++)
          xperi[i] = 0;
      return ERR;
    }
  for (i = 0; i < 24; i++)
    xx[i] = 0;
  /***************************************
   * mean nodes and apsides
   ***************************************/
  /* mean points only for Sun - Neptune */
  if ((method == 0 || (method & SE_NODBIT_MEAN)) &&
      ((ipl >= SE_SUN && ipl <= SE_NEPTUNE) || ipl == SE_EARTH))
    {
      if (ipl == SE_MOON)
        {
          swi_mean_lunar_elements(tjd_et, &xna[0], &xna[3], &xpe[0], &xpe[3]);
          incl = MOON_MEAN_INCL;
          vincl = 0;
          ecce = MOON_MEAN_ECC;
          vecce = 0;
          sema = MOON_MEAN_DIST / AUNIT;
          vsema = 0;
        }
      else
        {
          iplx = ipl_to_elem[ipl];
          ep = el_incl[iplx];
          incl = ep[0] + ep[1] * t + ep[2] * t * t + ep[3] * t * t * t;
          vincl = ep[1] / 36525;
          ep = el_sema[iplx];
          sema = ep[0] + ep[1] * t + ep[2] * t * t + ep[3] * t * t * t;
          vsema = ep[1] / 36525;
          ep = el_ecce[iplx];
          ecce = ep[0] + ep[1] * t + ep[2] * t * t + ep[3] * t * t * t;
          vecce = ep[1] / 36525;
          ep = el_node[iplx];
          /* ascending node */
          xna[0] = ep[0] + ep[1] * t + ep[2] * t * t + ep[3] * t * t * t;
          xna[3] = ep[1] / 36525;
          /* perihelion */
          ep = el_peri[iplx];
          xpe[0] = ep[0] + ep[1] * t + ep[2] * t * t + ep[3] * t * t * t;
          xpe[3] = ep[1] / 36525;
        }
      /* descending node */
      xnd[0] = swe_degnorm(xna[0] + 180);
      xnd[3] = xna[3];
      /* angular distance of perihelion from node */
      parg = xpe[0] = swe_degnorm(xpe[0] - xna[0]);
      pargx = xpe[3] = swe_degnorm(xpe[0] + xpe[3]  - xna[3]);
      /* transform from orbital plane to mean ecliptic of date */
      swe_cotrans(xpe, xpe, -incl);
      /* xpe+3 is aux. position, not speed!!! */
      swe_cotrans(xpe+3, xpe+3, -incl-vincl);
      /* add node again */
      xpe[0] = swe_degnorm(xpe[0] + xna[0]);
      /* xpe+3 is aux. position, not speed!!! */
      xpe[3] = swe_degnorm(xpe[3] + xna[0] + xna[3]);
      /* speed */
      xpe[3] = swe_degnorm(xpe[3] - xpe[0]);
      /* heliocentric distance of perihelion and aphelion */
      xpe[2] = sema * (1 - ecce);
      xpe[5] = (sema + vsema) * (1 - ecce - vecce) - xpe[2];
      /* aphelion */
      xap[0] = swe_degnorm(xpe[0] + 180);
      xap[1] = -xpe[1];
      xap[3] = xpe[3];
      xap[4] = -xpe[4];
      if (do_focal_point)
        {
          xap[2] = sema * ecce * 2;
          xap[5] = (sema + vsema) * (ecce + vecce) * 2 - xap[2];
        }
      else
        {
          xap[2] = sema * (1 + ecce);
          xap[5] = (sema + vsema) * (1 + ecce + vecce) - xap[2];
        }
      /* heliocentric distance of nodes */
      ea = atan(tan(-parg * DEGTORAD / 2) * sqrt((1-ecce)/(1+ecce))) * 2;
      eax = atan(tan(-pargx * DEGTORAD / 2) * sqrt((1-ecce-vecce)/(1+ecce+vecce))) * 2;
      xna[2] = sema * (cos(ea) - ecce) / cos(parg * DEGTORAD);
      xna[5] = (sema+vsema) * (cos(eax) - ecce - vecce) / cos(pargx * DEGTORAD);
      xna[5] -= xna[2];
      ea = atan(tan((180 - parg) * DEGTORAD / 2) * sqrt((1-ecce)/(1+ecce))) * 2;
      eax = atan(tan((180 - pargx) * DEGTORAD / 2) * sqrt((1-ecce-vecce)/(1+ecce+vecce))) * 2;
      xnd[2] = sema * (cos(ea) - ecce) / cos((180 - parg) * DEGTORAD);
      xnd[5] = (sema+vsema) * (cos(eax) - ecce - vecce) / cos((180 - pargx) * DEGTORAD);
      xnd[5] -= xnd[2];
      /* no light-time correction because speed is extremely small */
      for (i = 0, xp = xx; i < 4; i++, xp += 6)
        {
          /* to cartesian coordinates */
          xp[0] *= DEGTORAD;
          xp[1] *= DEGTORAD;
          xp[3] *= DEGTORAD;
          xp[4] *= DEGTORAD;
          swi_polcart_sp(xp, xp);
        }
      /***************************************
       * "true" or osculating nodes and apsides
       ***************************************/
    } else {
      /* first, we need a heliocentric distance of the planet */
      if (swe_calc(tjd_et, ipli, iflg0, x, serr) == ERR)
        {
          if (FRiyalNumbered(tjd_et,ind,fTrue))
            {
              x[0]=planet[ind];
              x[1]=planetalt[ind];
              x[2]=planetdis[ind];
              x[3]=ret[ind];
              x[4]=altret[ind];
              x[5]=disret[ind];
            }
          else return ERR;
        }
      iflJ2000 = (iflag & SEFLG_EPHMASK)|SEFLG_J2000|SEFLG_EQUATORIAL|SEFLG_XYZ|SEFLG_TRUEPOS|SEFLG_NONUT|SEFLG_SPEED;
      ellipse_is_bary = FALSE;
      if (ipli != SE_MOON)
        {
          if ((method & SE_NODBIT_OSCU_BAR) && x[2] > 6)
            {
              iflJ2000 |= SEFLG_BARYCTR; /* only planets beyond Jupiter */
              ellipse_is_bary = TRUE;
            }
          else
            {
              iflJ2000 |= SEFLG_HELCTR;
            }
        }
      /* we need three positions and three speeds
       * for three nodes/apsides. from the three node positions,
       * the speed of the node will be computed. */
      if (ipli == SE_MOON)
        {
          dt = NODE_CALC_INTV;
          dzmin = 1e-15;
          Gmsm = GEOGCONST * (1 + 1 / EARTH_MOON_MRAT) /AUNIT/AUNIT/AUNIT*86400.0*86400.0;
        }
      else
        {
          if ((ipli >= SE_MERCURY && ipli <= SE_PLUTO) || ipli == SE_EARTH)
            plm = 1 / plmass[ipl_to_elem[ipl]];
          else
            plm = 0;
          dt = NODE_CALC_INTV * 10 * x[2];
          dzmin = 1e-15 * dt / NODE_CALC_INTV;
          Gmsm = HELGRAVCONST * (1 + plm) /AUNIT/AUNIT/AUNIT*86400.0*86400.0;
        }
      if (iflag & SEFLG_SPEED)
        {
          istart = 0;
          iend = 2;
        }
      else
        {
          istart = iend = 0;
          dt = 0;
        }
      for (i = istart, t = tjd_et - dt; i <= iend; i++, t += dt)
        {
          if (istart == iend)
            t = tjd_et;
          if (swe_calc(t, ipli, iflJ2000, xpos[i], serr) == ERR)
            {
              fUseJ2000T=fUseJ2000;
              fEquatorT=us.fEquator;
              fUseJ2000=fTrue;
              us.fEquator=fTrue;
              if (FRiyalNumbered(t,ind,fTrue))
                {
                  xpos[i][0]=spacex[ind];
                  xpos[i][1]=spacey[ind];
                  xpos[i][2]=spacez[ind];
                  xpos[i][3]=spacedx[ind];
                  xpos[i][4]=spacedy[ind];
                  xpos[i][5]=spacedz[ind];
              fUseJ2000=fUseJ2000T;
              us.fEquator=fEquatorT;
                }
              else return ERR;
            }
          /* the EMB is used instead of the earth */
          if (ipli == SE_EARTH)
            {
              if (swe_calc(t, SE_MOON, iflJ2000 & ~(SEFLG_BARYCTR|SEFLG_HELCTR), xposm, serr) == ERR)
                return ERR;
              for (j = 0; j <= 2; j++)
                xpos[i][j] += xposm[j] / (EARTH_MOON_MRAT + 1.0);
            }
          swi_plan_for_osc_elem(iflg0, t, xpos[i]);
        }
      for (i = istart; i <= iend; i++)
        {
          if (fabs(xpos[i][5]) < dzmin)
            xpos[i][5] = dzmin;
          fac = xpos[i][2] / xpos[i][5];
          sgn = xpos[i][5] / fabs(xpos[i][5]);
          for (j = 0; j <= 2; j++)
            {
              xn[i][j] = (xpos[i][j] - fac * xpos[i][j+3]) * sgn;
              xs[i][j] = -xn[i][j];
            }
        }
      for (i = istart; i <= iend; i++)
        {
          /* node */
          rxy =  sqrt(xn[i][0] * xn[i][0] + xn[i][1] * xn[i][1]);
          cosnode = xn[i][0] / rxy;
          sinnode = xn[i][1] / rxy;
          /* inclination */
          swi_cross_prod(xpos[i], xpos[i]+3, xnorm);
          rxy =  xnorm[0] * xnorm[0] + xnorm[1] * xnorm[1];
          c2 = (rxy + xnorm[2] * xnorm[2]);
          rxyz = sqrt(c2);
          rxy = sqrt(rxy);
          sinincl = rxy / rxyz;
          cosincl = sqrt(1 - sinincl * sinincl);
          if (xnorm[2] < 0) cosincl = -cosincl; /* retrograde asteroid, e.g. 20461 Dioretsa */
          /* argument of latitude */
          cosu = xpos[i][0] * cosnode + xpos[i][1] * sinnode;
          sinu = xpos[i][2] / sinincl;
          uu = atan2(sinu, cosu);
          /* semi-axis */
          rxyz = sqrt(square_sum(xpos[i]));
          v2 = square_sum((xpos[i]+3));
          sema = 1 / (2 / rxyz - v2 / Gmsm);
          /* eccentricity */
          pp = c2 / Gmsm;
          ecce = sqrt(1 - pp / sema);
          /* eccentric anomaly */
          cosE = 1 / ecce * (1 - rxyz / sema);
          sinE = 1 / ecce / sqrt(sema * Gmsm) * dot_prod(xpos[i], (xpos[i]+3));
          /* true anomaly */
          ny = 2 * atan(sqrt((1+ecce)/(1-ecce)) * sinE / (1 + cosE));
          /* distance of perihelion from ascending node */
          xq[i][0] = swi_mod2PI(uu - ny);
          xq[i][1] = 0;			/* latitude */
          xq[i][2] = sema * (1 - ecce);	/* distance of perihelion */
          /* transformation to ecliptic coordinates */
          swi_polcart(xq[i], xq[i]);
          swi_coortrf2(xq[i], xq[i], -sinincl, cosincl);
          swi_cartpol(xq[i], xq[i]);
          /* adding node, we get perihelion in ecl. coord. */
          xq[i][0] += atan2(sinnode, cosnode);
          xa[i][0] = swi_mod2PI(xq[i][0] + PI);
          xa[i][1] = -xq[i][1];
          if (do_focal_point)
            {
              xa[i][2] = sema * ecce * 2;	/* distance of aphelion */
            }
          else
            {
              xa[i][2] = sema * (1 + ecce);	/* distance of aphelion */
            }
          swi_polcart(xq[i], xq[i]);
          swi_polcart(xa[i], xa[i]);
          /* new distance of node from orbital ellipse:
           * true anomaly of node: */
          ny = swi_mod2PI(ny - uu);
          ny2 = swi_mod2PI(ny + PI);
          /* eccentric anomaly */
          cosE = cos(2 * atan(tan(ny / 2) / sqrt((1+ecce) / (1-ecce))));
          cosE2 = cos(2 * atan(tan(ny2 / 2) / sqrt((1+ecce) / (1-ecce))));
          /* new distance */
          rn = sema * (1 - ecce * cosE);
          rn2 = sema * (1 - ecce * cosE2);
          /* old node distance */
          ro = sqrt(square_sum(xn[i]));
          ro2 = sqrt(square_sum(xs[i]));
          /* correct length of position vector */
          for (j = 0; j <= 2; j++)
            {
              xn[i][j] *= rn / ro;
              xs[i][j] *= rn2 / ro2;
            }
        }
      for (i = 0; i <= 2; i++)
        {
          if (iflag & SEFLG_SPEED)
            {
              xpe[i] = xq[1][i];
              xpe[i+3] = (xq[2][i] - xq[0][i]) / dt / 2;
              xap[i] = xa[1][i];
              xap[i+3] = (xa[2][i] - xa[0][i]) / dt / 2;
              xna[i] = xn[1][i];
              xna[i+3] = (xn[2][i] - xn[0][i]) / dt / 2;
              xnd[i] = xs[1][i];
              xnd[i+3] = (xs[2][i] - xs[0][i]) / dt / 2;
            }
          else
            {
              xpe[i] = xq[0][i];
              xpe[i+3] = 0;
              xap[i] = xa[0][i];
              xap[i+3] = 0;
              xna[i] = xn[0][i];
              xna[i+3] = 0;
              xnd[i] = xs[0][i];
              xnd[i+3] = 0;
            }
        }
      is_true_nodaps = TRUE;
    }
  /* to set the variables required in the save area,
   * i.e. ecliptic, nutation, barycentric sun, earth
   * we compute the planet */
  if (ipli == SE_MOON && (iflag & (SEFLG_HELCTR | SEFLG_BARYCTR)))
    {
      swi_force_app_pos_etc();
      if (swe_calc(tjd_et, SE_SUN, iflg0, x, serr) == ERR)
        return ERR;
      } else {
          if (swe_calc(tjd_et, ipli, iflg0 | (iflag & SEFLG_TOPOCTR), x, serr) == ERR)
            {
              if (FRiyalNumbered(tjd_et,ind,iflg0 && SEFLG_HELCTR))
                {
                  x[0]=planet[ind];
                  x[1]=planetalt[ind];
                  x[2]=planetdis[ind];
                  x[3]=ret[ind];
                  x[4]=altret[ind];
                  x[5]=disret[ind];
                }
              else return ERR;
            }
            }
          /***********************
           * position of observer
           ***********************/
          if (iflag & SEFLG_TOPOCTR)
            {
              /* geocentric position of observer */
              if (swi_get_observer(tjd_et, iflag, FALSE, xobs, serr) != OK)
                return ERR;
              /*for (i = 0; i <= 5; i++)
                xobs[i] = swed.topd.xobs[i];*/
            }
          else
            {
              for (i = 0; i <= 5; i++)
                xobs[i] = 0;
            }
          if (iflag & (SEFLG_HELCTR | SEFLG_BARYCTR))
            {
              if ((iflag & SEFLG_HELCTR) && !(iflag & SEFLG_MOSEPH))
                for (i = 0; i <= 5; i++)
                  xobs[i] = xsun[i];
            }
          else if (ipl == SE_SUN && !(iflag & SEFLG_MOSEPH))
            {
              for (i = 0; i <= 5; i++)
                xobs[i] = xsun[i];
            }
          else
            {
              /* barycentric position of observer */
              for (i = 0; i <= 5; i++)
                xobs[i] += xear[i];
            }
          /* ecliptic obliqity */
          if (iflag & SEFLG_J2000)
            oe = &swed.oec2000;
          else
            oe = &swed.oec;
          /*************************************************
           * conversions shared by mean and osculating points
           *************************************************/
          for (ij = 0, xp = xx; ij < 4; ij++, xp += 6)
            {
              /* no nodes for earth */
              if (ipli == SE_EARTH && ij <= 1)
                {
                  for (i = 0; i <= 5; i++)
                    xp[i] = 0;
                  continue;
                }
              /*********************
               * to equator
               *********************/
              if (is_true_nodaps && !(iflag & SEFLG_NONUT))
                {
                  swi_coortrf2(xp, xp, -swed.nut.snut, swed.nut.cnut);
                  if (iflag & SEFLG_SPEED)
                    swi_coortrf2(xp+3, xp+3, -swed.nut.snut, swed.nut.cnut);
                }
              swi_coortrf2(xp, xp, -oe->seps, oe->ceps);
              swi_coortrf2(xp+3, xp+3, -oe->seps, oe->ceps);
              if (is_true_nodaps)
                {
                  /****************************
                   * to mean ecliptic of date
                   ****************************/
                  if (!(iflag & SEFLG_NONUT))
                    swi_nutate(xp, iflag, TRUE);
                }
              /*********************
               * to J2000
               *********************/
              swi_precess(xp, tjd_et, J_TO_J2000);
              if (iflag & SEFLG_SPEED)
                swi_precess_speed(xp, tjd_et, J_TO_J2000);
              /*********************
               * to barycenter
               *********************/
              if (ipli == SE_MOON)
                {
                  for (i = 0; i <= 5; i++)
                    xp[i] += xear[i];
                }
              else
                {
                  if (!(iflag & SEFLG_MOSEPH) && !ellipse_is_bary)
                    for (j = 0; j <= 5; j++)
                      xp[j] += xsun[j];
                }
              /*********************
               * to correct center
               *********************/
              for (j = 0; j <= 5; j++)
                xp[j] -= xobs[j];
              /* geocentric perigee/apogee of sun */
              if (ipl == SE_SUN && !(iflag & (SEFLG_HELCTR | SEFLG_BARYCTR)))
                for (j = 0; j <= 5; j++)
                  xp[j] = -xp[j];
              /*********************
               * light deflection
               *********************/
              dt = sqrt(square_sum(xp)) * AUNIT / CLIGHT / 86400.0;
              if (do_defl)
                swi_deflect_light(xp, dt, iflag);
              /*********************
               * aberration
               *********************/
              if (do_aberr)
                {
                  swi_aberr_light(xp, xobs, iflag);
                  /*
                   * Apparent speed is also influenced by
                   * the difference of speed of the earth between t and t-dt.
                   * Neglecting this would result in an error of several 0.1"
                   */
                  if (iflag & SEFLG_SPEED)
                    {
                      /* get barycentric sun and earth for t-dt into save area */
                      if (swe_calc(tjd_et - dt, ipli, iflg0 | (iflag & SEFLG_TOPOCTR), x2, serr) == ERR)
        {
          if (FRiyalNumbered(tjd_et-dt,ind,iflg0 && SEFLG_HELCTR))
            {
              x2[0]=planet[ind];
              x2[1]=planetalt[ind];
              x2[2]=planetdis[ind];
              x2[3]=ret[ind];
              x2[4]=altret[ind];
              x2[5]=disret[ind];
            }
          else return ERR;
        }
                      if (iflag & SEFLG_TOPOCTR)
                        {
                          /* geocentric position of observer */
                          /* if (swi_get_observer(tjd_et - dt, iflag, FALSE, xobs, serr) != OK)
                            return ERR;*/
                          for (i = 0; i <= 5; i++)
                            xobs2[i] = swed.topd.xobs[i];
                        }
                      else
                        {
                          for (i = 0; i <= 5; i++)
                            xobs2[i] = 0;
                        }
                      if (iflag & (SEFLG_HELCTR | SEFLG_BARYCTR))
                        {
                          if ((iflag & SEFLG_HELCTR) && !(iflag & SEFLG_MOSEPH))
                            for (i = 0; i <= 5; i++)
                              xobs2[i] = xsun[i];
                        }
                      else if (ipl == SE_SUN && !(iflag & SEFLG_MOSEPH))
                        {
                          for (i = 0; i <= 5; i++)
                            xobs2[i] = xsun[i];
                        }
                      else
                        {
                          /* barycentric position of observer */
                          for (i = 0; i <= 5; i++)
                            xobs2[i] += xear[i];
                        }
                      for (i = 3; i <= 5; i++)
                        xp[i] += xobs[i] - xobs2[i];
                      /* The above call of swe_calc() has destroyed the
                       * parts of the save area
                       * (i.e. bary sun, earth nutation matrix!).
                       * to restore it:
                       */
                      if (swe_calc(tjd_et, SE_SUN, iflg0 | (iflag & SEFLG_TOPOCTR), x2, serr) == ERR)
                        return ERR;
                    }
                }
              /*********************
               * precession
               *********************/
              /* save J2000 coordinates; required for sidereal positions */
              for (j = 0; j <= 5; j++)
                x2000[j] = xp[j];
              if (!(iflag & SEFLG_J2000))
                {
                  swi_precess(xp, tjd_et, J2000_TO_J);
                  if (iflag & SEFLG_SPEED)
                    swi_precess_speed(xp, tjd_et, J2000_TO_J);
                }
              /*********************
               * nutation
               *********************/
              if (!(iflag & SEFLG_NONUT))
                swi_nutate(xp, iflag, FALSE);
              /* now we have equatorial cartesian coordinates; keep them */
              for (j = 0; j <= 5; j++)
                pldat.xreturn[18+j] = xp[j];
              /************************************************
               * transformation to ecliptic.                  *
               * with sidereal calc. this will be overwritten *
               * afterwards.                                  *
               ************************************************/
              swi_coortrf2(xp, xp, oe->seps, oe->ceps);
              if (iflag & SEFLG_SPEED)
                swi_coortrf2(xp+3, xp+3, oe->seps, oe->ceps);
              if (!(iflag & SEFLG_NONUT))
                {
                  swi_coortrf2(xp, xp, swed.nut.snut, swed.nut.cnut);
                  if (iflag & SEFLG_SPEED)
                    swi_coortrf2(xp+3, xp+3, swed.nut.snut, swed.nut.cnut);
                }
              /* now we have ecliptic cartesian coordinates */
              for (j = 0; j <= 5; j++)
                pldat.xreturn[6+j] = xp[j];
              /************************************
               * sidereal positions               *
               ************************************/
              if (iflag & SEFLG_SIDEREAL)
                {
                  /* project onto ecliptic t0 */
                  if (swed.sidd.sid_mode & SE_SIDBIT_ECL_T0)
                    {
                      if (swi_trop_ra2sid_lon(x2000, pldat.xreturn+6, pldat.xreturn+18, iflag, serr) != OK)
                        return ERR;
                      /* project onto solar system equator */
                    }
                  else if (swed.sidd.sid_mode & SE_SIDBIT_SSY_PLANE)
                    {
                      if (swi_trop_ra2sid_lon_sosy(x2000, pldat.xreturn+6, pldat.xreturn+18, iflag, serr) != OK)
                        return ERR;
                    }
                  else
                    {
                      /* traditional algorithm */
                      swi_cartpol_sp(pldat.xreturn+6, pldat.xreturn);
                      pldat.xreturn[0] -= swe_get_ayanamsa(tjd_et) * DEGTORAD;
                      swi_polcart_sp(pldat.xreturn, pldat.xreturn+6);
                    }
                }
              if ((iflag & SEFLG_XYZ) && (iflag & SEFLG_EQUATORIAL))
                {
                  for (j = 0; j <= 5; j++)
                    xp[j] = pldat.xreturn[18+j];
                  continue;
                }
              if (iflag & SEFLG_XYZ)
                {
                  for (j = 0; j <= 5; j++)
                    xp[j] = pldat.xreturn[6+j];
                  continue;
                }
              /************************************************
               * transformation to polar coordinates          *
               ************************************************/
              swi_cartpol_sp(pldat.xreturn+18, pldat.xreturn+12);
              swi_cartpol_sp(pldat.xreturn+6, pldat.xreturn);
              /**********************
               * radians to degrees *
               **********************/
              for (j = 0; j < 2; j++)
                {
                  pldat.xreturn[j] *= RADTODEG;		/* ecliptic */
                  pldat.xreturn[j+3] *= RADTODEG;
                  pldat.xreturn[j+12] *= RADTODEG;	/* equator */
                  pldat.xreturn[j+15] *= RADTODEG;
                }
              if (iflag & SEFLG_EQUATORIAL)
                {
                  for (j = 0; j <= 5; j++)
                    xp[j] = pldat.xreturn[12+j];
                  continue;
                }
              else
                {
                  for (j = 0; j <= 5; j++)
                    xp[j] = pldat.xreturn[j];
                  continue;
                }
            }
          for (i = 0; i <= 5; i++)
            {
              if (i > 2 && !(iflag & SEFLG_SPEED))
                xna[i] = xnd[i] = xpe[i] = xap[i] = 0;
              if (xnasc != NULL)
                xnasc[i] = xna[i];
              if (xndsc != NULL)
                xndsc[i] = xnd[i];
              if (xperi != NULL)
                xperi[i] = xpe[i];
              if (xaphe != NULL)
                xaphe[i] = xap[i];
            }
          return OK;
        }
Ejemplo n.º 9
0
Archivo: sb.c Proyecto: 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;
}