Example #1
0
/* routine to advance jd until oppangle is reached */
void
seek_oppangle(double oppangle,
	      double *jd,
	      PBASIS *p,
	      int    obscode)
{
  OBSERVATION futobs;
  double nextopp, difflast, diffnext, lastopp;
  
  futobs.obscode = obscode;
  futobs.obstime = (*jd-jd0)*DAY;
  futobs.xe = -999.;		/* Force evaluation of earth3d */
  predict_posn(p,NULL,&futobs,NULL);
  lastopp = opposition_angle(&futobs)/DTOR;

  do {
    *jd += TIME_STEP;
    futobs.obstime = (*jd-jd0)*DAY;
    futobs.xe = -999.;		/* Force evaluation of earth3d */
    predict_posn(p,NULL,&futobs,NULL);
    nextopp = opposition_angle(&futobs)/DTOR;
    
    difflast = oppangle - lastopp;
    while (difflast < -180.) difflast+=360.;
    while (difflast > 180.) difflast-=360.;
    diffnext = oppangle - nextopp;
    while (diffnext < -180.) diffnext+=360.;
    while (diffnext > 180.) diffnext-=360.;

    lastopp = nextopp;
  } while ( diffnext != 0. && 
	    (diffnext*difflast>0. || fabs(diffnext)>120.));

  return;
}
Example #2
0
int
main(int argc, char *argv[])
{
  PBASIS ptrue, pfit, ptry;
  OBSERVATION	futobs, obsarray[MAXOBS], *obs;
  int nobs;
  double tt;

  ORBIT  orbit;
  XVBASIS xv;

  double **covar, **covar_aei, **covar_xyz;
  double chisq;
  int dof;

  char	inbuff[256];
  double **sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double xx,yy,xy,bovasqrd,det;
  double now, threshold, timestart, timespan, timeend;
  double besttime, bestvara, elong;
  int i, refit;

  if (argc!=4 || *argv[1]=='^') print_help();


  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,6,1,6);
  covar = dmatrix(1,6,1,6);
  covar_xyz = dmatrix(1,6,1,6);
  covar_aei = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  if (read_abg(argv[1],&ptrue,covar)) {
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",argv[1]);
    exit(1);
  }

  if ((threshold = atof(argv[2]))<=0.) {
    fprintf(stderr,"Bad observation threshold %s\n",argv[2]);
    print_help();
  }

  if ((timespan = atof(argv[3]))<=0.) {
    fprintf(stderr,"Bad time span %s\n",argv[3]);
    print_help();
  }

  /* Read in the initial observation times */
  nobs = 0;
  while (fgets_nocomment(inbuff, 255, stdin, stdout)!=NULL) {
    obs = &(obsarray[nobs]);
    if (scan_observation(inbuff, obs)) exit(1);
    /* Set time to years after jd0, don't care about coordinates here*/
    obs->obstime = (obs->obstime-jd0)*DAY;
    if (nobs==0) timestart = obs->obstime;
    /* Calculate the position of Earth at this time to avoid doing
     * it many times later: */
    earth3d(obs->obstime, obs->obscode,
	    &(obs->xe),&(obs->ye),&(obs->ze));
    /* replace with faked position */
    fake_observation(&ptrue, obs);
    print_radec(obs,stdout);
    printf("Reobserve time %.4f opp. angle %.2f\n", obs->obstime-timestart,
	   opposition_angle(obs)/DTOR);
    nobs++;
  }

  /* Get an orbit fit*/
  fit_observations(obsarray, nobs, &pfit, covar, &chisq, &dof, NULL);

  /*Save site and error limits to use in future */
  obsarray[nobs].obscode = obsarray[nobs-1].obscode;
  obsarray[nobs].dthetax = obsarray[nobs-1].dthetax;
  obsarray[nobs].dthetay = obsarray[nobs-1].dthetay;

  timeend = timestart + timespan;
  bestvara = 1e10;
  besttime = 0.;

  for (now = obsarray[nobs-1].obstime; now <= timeend;  ) {

    /*Advance observing time */
    if ( now-timestart < 2*MONTH) now+= DAY;
    else now+=MONTH;

    /*Get position and x uncertainty*/
    /* Predict position & examine uncertainty */
    obsarray[nobs].obstime = now;
    obsarray[nobs].xe = -999.;		/* Force evaluation of earth3d */

    predict_posn(&pfit,covar,&obsarray[nobs],sigxy);


    /* Compute a, b, theta of error ellipse for output */
    xx = sigxy[1][1];
    yy = sigxy[2][2];
    xy = sigxy[1][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Adjust for PA to be N through E, */
    PA = PA-90;
    if (PA<-90.) PA += 180.;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    /* See what uncertainty in a results from this obs.*/
    fit_observations(obsarray, nobs+1, &ptry, covar_aei, &chisq, &dof, NULL);

    pbasis_to_bary(&ptry, &xv, derivs);
    covar_map(covar_aei, derivs, covar_xyz,6,6);
    orbitElements(&xv, &orbit);
    aei_derivs(&xv, derivs);
    covar_map(covar_xyz, derivs, covar_aei,6,6);
    
    /* Report results of this test to output */
    printf("%7.4f %.2f %.2f %.2f %9.6f %.3g %5.1f  %5.1f %d\n", now-timestart,
	   obsarray[nobs].thetax/ARCSEC, obsarray[nobs].thetay/ARCSEC,
	   a/ARCSEC, sqrt(covar_aei[1][1]), sqrt(covar_aei[2][2]),
	   elong/DTOR, opposition_angle(&obsarray[nobs])/DTOR, nobs);
    
    /* Go to next date if Sun is too close */
    elong = elongation(&obsarray[nobs]);
    if (elong < MIN_ELONG) continue;

    if (a > threshold*ARCSEC) {
      /* object is lost.  See what prior observation was best
       * for constraining a, then add it and refit orbit, continue
       */
      if (besttime<=0) {
	fprintf(stderr,"Object is lost before observation\n");
	exit(1);
      }
      obsarray[nobs].obstime = besttime;
      obsarray[nobs].xe = -999.;
      fake_observation(&ptrue, &obsarray[nobs]);
      printf("Reobserve time %.4f opp. angle %.2f\n", besttime-timestart,
	    opposition_angle(&obsarray[nobs])/DTOR);
      print_radec(&obsarray[nobs],stdout);
      nobs++;
      fit_observations(obsarray, nobs, &pfit, covar, &chisq, &dof, NULL);
      now = besttime;
      besttime = 0.;
      bestvara = 1e10;
      obsarray[nobs].obscode = obsarray[nobs-1].obscode;
      obsarray[nobs].dthetax = obsarray[nobs-1].dthetax;
      obsarray[nobs].dthetay = obsarray[nobs-1].dthetay;
    } else {

      /* Is this the best observation so far? */
      if (covar_aei[1][1] < bestvara) {
	bestvara = covar_aei[1][1];
	besttime = now;
      }
    }
  }

  /*Do a final observation*/
  obsarray[nobs].obstime = besttime;
  obsarray[nobs].xe = -999.;
  fake_observation(&ptrue, &obsarray[nobs]);
  printf("Reobserve time %.4f opp. angle %.2f\n", besttime-timestart,
	 opposition_angle(&obsarray[nobs])/DTOR);
  print_radec(&obsarray[nobs],stdout);
  nobs++;
  fit_observations(obsarray, nobs, &pfit, covar_aei, &chisq, &dof, NULL);

  pbasis_to_bary(&pfit, &xv, derivs);
  covar_map(covar_aei, derivs, covar_xyz,6,6);
  orbitElements(&xv, &orbit);
  aei_derivs(&xv, derivs);
  covar_map(covar_xyz, derivs, covar_aei,6,6);
  printf("Final uncertainty in a: %.3g\n",
	 sqrt(covar_aei[1][1]));

   
  free_dmatrix(covar,1,6,1,6);
  free_dmatrix(covar_xyz,1,6,1,6);
  free_dmatrix(covar_aei,1,6,1,6);
  free_dmatrix(derivs,1,6,1,6);
  exit(0);
}
Example #3
0
int
main(int argc, char *argv[])
{
  PBASIS p, pfit;
  ORBIT o, ofit;
  XVBASIS xv;

  OBSERVATION	futobs;
  OBSERVATION *oo;
  FILE *abgfile;
  char	inbuff[256],objname[256],fname[256];

  double **covar,**sigxy;
  double lat,lon;
  int i,nfields;
  double x[3], v[3], range;

  double oppangle, epochs[MAX_EPOCHS], observe_day, period;
  double x0, y0;
  int nepochs, iphase, iexpose, iorbit;

  int dof,ii;
  double chisq, dbary, ddbary, vis_start, vis_end, jd;
  double  **covar_abg, **covar_xyz, **derivs, **covar_aei;
  double launch;	/*Date to start hunting for oppangle*/

  if (argc<2) print_help();
  oppangle = atof(argv[1]);
  epochs[0]=0.;
  for (i=2; i<argc; i++) epochs[i-1] = atof(argv[i]);
  nepochs = argc-1;

  futobs.obscode = OBSCODE_HST;

  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  printf(
"#   ID  phi  distance            a                   e                     i   "
"    posn        d             a              e              i \n"
"#                        real   fit     err    real   fit     err     fit  err  NEW OBSERVATION:\n");
 
  covar_abg = dmatrix(1,6,1,6);
  covar_xyz = dmatrix(1,6,1,6);
  covar_aei = dmatrix(1,6,1,6);
  derivs = dmatrix(1,6,1,6);
  sigxy = dmatrix(1,2,1,2);
  covar = dmatrix(1,6,1,6);

  /* Loop through input containing names of objects */
  while ( fgets_nocomment(inbuff,255,stdin,NULL)!=NULL) {
    sscanf(inbuff," %s ",objname);
    strcpy(fname,objname);
    strcat(fname,SUFFIX);

    if (read_abg(fname,&p,covar)) {
      fprintf(stderr, "Error reading alpha/beta/gamma file %s\n",fname);
      exit(1);
    }

    /* look at several points around the orbital phase */
    /* get orbital elements for this one */
    pbasis_to_bary(&p, &xv, NULL);
    orbitElements(&xv, &o);

    period = pow(o.a, 1.5);
    launch = jd0;

    for (iphase=0; iphase<PHASE_STEPS; iphase++) {
      /* Advance the object through its orbit by moving back time
       * of perihelion (which is in days) */
      o.T -= period/ (PHASE_STEPS*DAY);
      /* Set up new orbit system based on this */
      elements_to_pbasis(&o, launch, futobs.obscode, &p);
      
      /* Now look for the day at which opp. angle meets spec */
      observe_day = launch;
      seek_oppangle(oppangle, &observe_day, &p, futobs.obscode);

      futobs.obstime = (observe_day-jd0)*DAY;
      futobs.xe = -999.;		/* Force evaluation of earth3d */
      predict_posn(&p,NULL,&futobs,NULL);

      /* Now transform ecliptic*/
      proj_to_ec(futobs.thetax,futobs.thetay,
		 &lat, &lon,
		 lat0, lon0, NULL);

      /* Only keep objects close to ecliptic */
      if (fabs(lat) > LAT_MAX*DTOR) continue;

      /* Now reset the orbit and coordinate system to start here */
      elements_to_pbasis(&o, observe_day, futobs.obscode, &p);
      nobs = 0;

      /* accumulate observations at all epochs */
      for (i=0; i<nepochs; i++) {
	/* Advance time until object is NOT visible */
	vis_end = observe_day+epochs[i];
	do {
	  vis_end+= VIS_TIME_STEP;
	  futobs.obstime = (vis_end-jd0)*DAY;
	  futobs.xe = -999.;		/* Force evaluation of earth3d */
	  predict_posn(&p,NULL,&futobs,NULL);
	} while (zenith_angle(&futobs) <= ZA_LIMIT) ;

	for (iorbit=0; iorbit<NORBITS*NFIELDS; iorbit++) {
	  /* Then advance to first time it IS visible. */
	  vis_start = vis_end;
	  do {
	    vis_start+= VIS_TIME_STEP;
	    futobs.obstime = (vis_start-jd0)*DAY;
	    futobs.xe = -999.;		/* Force evaluation of earth3d */
	    predict_posn(&p,NULL,&futobs,NULL);
	  } while (zenith_angle(&futobs) > ZA_LIMIT) ;
	  
	  /* Now find end of visibility period */
	  vis_end = vis_start;
	  do {
	    vis_end+= VIS_TIME_STEP;
	    futobs.obstime = (vis_end-jd0)*DAY;
	    futobs.xe = -999.;		/* Force evaluation of earth3d */
	    predict_posn(&p,NULL,&futobs,NULL);
	  } while (zenith_angle(&futobs) <= ZA_LIMIT) ;
	  vis_end -= VIS_TIME_STEP;
	  
	  /* Only proceed if we are observing this field on this orbit*/
	  if (iorbit%NFIELDS !=0) continue;
	  
	  /* Find middle of each exposure time */
	  jd = vis_start + (vis_end - vis_start)/(2.*EXP_PER_ORBIT);
	  for (iexpose=0; iexpose<EXP_PER_ORBIT; iexpose++, 
		 jd+=(vis_end - vis_start)/EXP_PER_ORBIT) {
	    oo = &obsarray[nobs];
	    oo->obstime = (jd-jd0)*DAY;
	    oo->xe = -999.;		/* Force evaluation of earth3d */
	    oo->obscode = OBSCODE_HST;
	    predict_posn(&p,NULL,oo,NULL);
	    oo->dthetax = oo->dthetay =  
	      ASTROM_ERROR*sqrt(NORBITS*EXP_PER_ORBIT)*ARCSEC;
	    nobs++;

	    /*if (iphase==0) {
	      double ra, dec;
	      char rastring[40], decstring[40];
	      proj_to_ec(oo->thetax,oo->thetay,
			 &lat, &lon,
			 lat0, lon0, NULL);
	      ec_to_eq(lat, lon, &ra, &dec, NULL);
	      deghms(ra/DTOR,rastring);
	      degdms(dec/DTOR,decstring);
	      fprintf(stderr,"%f %s %s %.3f %d\n",jd, rastring, decstring,
		      oo->dthetax/ARCSEC,
		      OBSCODE_HST);
	    }*/

	  } /*exposure loop*/
	} /*orbit loop*/
      } /*observation-epoch loop */

      /* Now fit the observations and report results */
      ii=fit_observations(obsarray, nobs, &pfit, covar, &chisq, &dof, NULL);
      /*fprintf(stderr,"#     lat0       lon0       xBary     yBary      zBary   JD0\n");
	fprintf(stderr,"%12.7f %12.7f %10.7f %10.7f %10.7f  %.6f\n",
	lat0/DTOR,lon0/DTOR,xBary,yBary,zBary,jd0);
	fprintf(stderr,"# Chi-squared of fit: %.2f DOF: %d\n",chisq,dof);
	fprintf(stderr,"%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f\n",
	pfit.a,pfit.adot,pfit.b,pfit.bdot, pfit.g, pfit.gdot);
	print_matrix(stderr,covar,6,6);
      */
      pbasis_to_bary(&pfit, &xv, derivs);
      orbitElements(&xv, &ofit);
      /* Note that below is distance at jd0=abg file zpoint, NOT at
       * first observation, which is some part of a year later.
       */
      dbary = sqrt(xBary*xBary + yBary*yBary + pow(zBary-1/pfit.g,2.));
      ddbary = dbary*dbary*sqrt(covar[5][5]);

      /* Get elements and covariance matrix thereof */
      covar_map(covar, derivs, covar_xyz,6,6);
      aei_derivs(&xv, derivs);
      covar_map(covar_xyz, derivs, covar_aei,6,6);
    
      /*Print out some info & uncertainties */
      printf("%8s %2d %5.2f +- %4.2f %1d %5.2f %5.2f +- %4.2f %5.3f %5.3f +- %5.3f"
	     " %7.1f +- %4.1f",
	     objname, iphase, 
	     dbary, ddbary, ii,
	     o.a, ofit.a, sqrt(covar_aei[1][1]),
	     o.e, ofit.e, sqrt(covar_aei[2][2]),
	     ofit.i, sqrt(covar_aei[3][3])/DTOR);

      /* Now get the positional uncertainty at a future date, and
       * refit after two extra measurements from ground
       */
      oo = &obsarray[nobs];
      nobs++;
      jd = observe_day + OPP_GRND - oppangle;
      oo->obstime = (jd-jd0)*DAY;
      oo->obscode = OBSCODE_GRND;
      oo->xe = -999.;
      predict_posn(&pfit,covar,oo,sigxy);
      /*if (iphase==0) {
	fprintf(stderr,"Prediction on %.2f, posn %.2f %.2f unc %.2f %.2f\n",
		    jd, oo->thetax/ARCSEC, oo->thetay/ARCSEC,
		    sqrt(sigxy[1][1])/ARCSEC, sqrt(sigxy[2][2])/ARCSEC);
	print_matrix(stderr,covar,6,6);
      }*/

      { 
	/* Compute a, of error ellipse for output */
	double xx, yy, xy, bovasqrd, det, a;
	xx = sigxy[1][1];
	yy = sigxy[2][2];
	xy = sigxy[1][2];
	bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
	  / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
	det = xx*yy-xy*xy;
	a = pow(det/bovasqrd,0.25);
	printf(" %5.1f", a/ARCSEC);
      }


      /* Now re-fit with two additional observations */
      predict_posn(&p,NULL,oo,NULL);
      oo->dthetax = oo->dthetay = ERROR_GRND * ARCSEC;
      oo = &obsarray[nobs];
      nobs++;
      oo->obstime = obsarray[nobs-2].obstime + DAY;
      oo->obscode = OBSCODE_GRND;
      oo->xe = -999.;
      predict_posn(&p,NULL,oo,NULL);
      oo->dthetax = oo->dthetay = ERROR_GRND * ARCSEC;

      ii = fit_observations(obsarray, nobs, &pfit, covar, &chisq, &dof, NULL);
      pbasis_to_bary(&pfit, &xv, derivs);
      orbitElements(&xv, &ofit);

      dbary = sqrt(xBary*xBary + yBary*yBary + pow(zBary-1/pfit.g,2.));
      ddbary = dbary*dbary*sqrt(covar[5][5]);

      /* Get elements and covariance matrix thereof */
      covar_map(covar, derivs, covar_xyz,6,6);
      aei_derivs(&xv, derivs);
      covar_map(covar_xyz, derivs, covar_aei,6,6);
    
      /*Print out some info & uncertainties */
      printf(" %5.2f +- %4.2f %1d %5.2f +- %4.2f %5.3f +- %5.3f"
	     " %7.1f +- %4.1f \n",
	     dbary, ddbary, ii,
	     ofit.a, sqrt(covar_aei[1][1]),
	     ofit.e, sqrt(covar_aei[2][2]),
	     ofit.i, sqrt(covar_aei[3][3])/DTOR);

    } /*phase loop */
  } /*object loop*/
  exit(0);
}
Example #4
0
int
main(int argc, char *argv[])
{
  PBASIS p;
  OBSERVATION	futobs, obs;
  struct date_time dt;
  char	inbuff[256],rastring[20],decstring[20];
  double **covar,**sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double dx, dy, chisq, elat, elon;
  double xx,yy,xy,bovasqrd,det;
  int i,nfields;

  int iarg=1;
  if (argc>1 && *argv[1]=='^') print_help();
  if (read_options(&iarg, argc, argv)) print_help();
  if (argc-iarg!=1) print_help();
  

  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,2,1,2);
  covar = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  if (read_abg(argv[iarg],&p,covar)) {
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",argv[iarg]);
    exit(1);
  }

  while (fgets_nocomment(inbuff, 255, stdin, stdout)!=NULL) {
    if (scan_observation(inbuff, &obs)) exit(1);
    /* Set time to years after jd0, rotate to tangent plane coords */
    obs.obstime = (obs.obstime-jd0)*DAY;
    eq_to_ec(obs.thetax,obs.thetay,&elat,&elon,NULL);
    ec_to_proj(elat,elon,&(obs.thetax),&(obs.thetay),
	       lat0,lon0,NULL);
    /* Calculate the position of Earth at this time to avoid doing
     * it many times later: */
    earth3d(obs.obstime, obs.obscode,
	    &(obs.xe),&(obs.ye),&(obs.ze));

    futobs.obstime = obs.obstime;
    futobs.obscode = obs.obscode;
    futobs.xe = -999.;

    predict_posn(&p,covar,&futobs,sigxy);

    /* Errors: */
    dx = obs.thetax - futobs.thetax;
    dy = obs.thetay - futobs.thetay;
    /* Add observational errors into the uncertainty */
    sigxy[1][1] += pow(obs.dthetax,2.);
    sigxy[2][2] += pow(obs.dthetay,2.);
   
    chisq = dx*dx*sigxy[2][2] -2.*dx*dy*sigxy[1][2] + dy*dy*sigxy[1][1];
    chisq /= sigxy[1][1]*sigxy[2][2] - sigxy[1][2]*sigxy[2][1];

    /* Compute a, b, theta of error ellipse for output */
    xx = sigxy[1][1];
    yy = sigxy[2][2];
    xy = sigxy[1][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Adjust for PA to be N through E, */
    PA = PA-90;
    if (PA<-90.) PA += 180.;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    printf("%7.4f %9.2f %9.2f %8.3f %8.3f %8.2f %8.2f %7.2f %.2f\n",
	   futobs.obstime, futobs.thetax/ARCSEC, futobs.thetay/ARCSEC,
	   dx/ARCSEC, dy/ARCSEC,
	   a/ARCSEC,b/ARCSEC,PA, chisq
); 

  }
  exit(0);
}
Example #5
0
double *predict(char *abg_file, double jdate, int obscode)
{

  PBASIS p;
  OBSERVATION	futobs;
  struct date_time dt;
  char	inbuff[256], rastring[20], decstring[20];
  char  outbuff[256];
  char  *f_string;
  double **covar,**sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double yr,mo,day,hr,mn,ss;
  double xx,yy,xy,bovasqrd,det;
  double distance;
  static double result[6];
  int i,nfields;
  int iarg=1;

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,2,1,2);
  covar = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  result[0] = -1.0;
  result[1] = -1.0;
  result[2] = -1.0;
  result[3] = -1.0;
  result[4] = -1.0;
  result[5] = -1.0;
 
  if (read_abg(abg_file,&p,covar) ) { 
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",abg_file);
    return result;
  }


  /* get observatory code */
  futobs.obscode=obscode;

  futobs.obstime=(jdate-jd0)*DAY;
  futobs.xe = -999.;		/* Force evaluation of earth3d */

  distance = predict_posn(&p,covar,&futobs,sigxy);


  
  /* Now transform to RA/DEC, via ecliptic*/
  proj_to_ec(futobs.thetax,futobs.thetay,
	     &lat, &lon,
	     lat0, lon0, derivs);
  /* map the covariance */
  covar_map(sigxy, derivs, covecl, 2, 2);
  
  /* Now to ICRS: */
  ec_to_eq(lat, lon, &ra, &dec, derivs);
  /* map the covariance */
  covar_map(covecl, derivs, coveq, 2, 2);
  
  /* Compute a, b, theta of error ellipse for output */
  xx = coveq[1][1]*cos(dec)*cos(dec);
  xy = coveq[1][2]*cos(dec);
  yy = coveq[2][2];
  PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
  /* Put PA N through E */
  PA = 90.-PA;
  bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
    / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
  det = xx*yy-xy*xy;
  b = pow(det*bovasqrd,0.25);
  a = pow(det/bovasqrd,0.25);
  
  ra /= DTOR;
  if (ra<0.) ra+= 360.;
  dec /= DTOR;


   result[0] = ra;
   result[1] = dec;
   result[2] = a/ARCSEC;
   result[3] = b/ARCSEC;
   result[4] = PA;
   result[5] = distance;

  return result;

}
Example #6
0
int
main(int argc, char *argv[])
{
  PBASIS p;
  OBSERVATION	futobs;
  struct date_time dt;
  char	inbuff[256],rastring[20],decstring[20];
  double **covar,**sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double yr,mo,day,hr,mn,ss;
  double xx,yy,xy,bovasqrd,det;
  int i,nfields;

  int iarg=1;
  if (argc>1 && *argv[1]=='^') print_help();
  if (read_options(&iarg, argc, argv)) print_help();
  if (iarg>=argc) print_help();

  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,2,1,2);
  covar = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  if (read_abg(argv[iarg],&p,covar)) {
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",argv[iarg]);
    exit(1);
  }

  /* get observatory code */
  fprintf (stderr,"Enter observatory code:\n");
  if (fgets_nocomment(inbuff,255,stdin,NULL)==NULL
      || sscanf(inbuff,"%d",&futobs.obscode)!=1) {
    fprintf(stderr,"Error reading observatory code\n");
    exit(1);
  }
  printf("# For observations at site %d\n"
	 "#                 x/RA           y/DEC          "
	 "err_a    err_b  err_pa\n",futobs.obscode);

  fprintf (stderr,"Enter JD's or Y M D ... of observations, -1 to quit:\n");
  while ( fgets_nocomment(inbuff,255,stdin,NULL)!=NULL) {
    nfields=sscanf(inbuff,"%lf %lf %lf %lf %lf %lf",
		   &yr,&mo,&day,&hr,&mn,&ss);
    if (nfields==0 ) {
      fprintf(stderr,"Error on time spec:\n->%s\n",inbuff);
      exit(1);
    } else if (yr<0.) {
      /*done*/
      exit(0);
    } else if (nfields==1 || nfields==2) {
      /* Got a JD. (probably...)*/
      futobs.obstime = (yr-jd0)*DAY;
    } else {
      dt.y = yr;
      dt.mo = mo;
      dt.d = day;
      if (nfields>=4) dt.h = hr;  else dt.h=0.;
      if (nfields>=5) dt.mn = mn; else dt.mn=0.;
      if (nfields>=6) dt.s = ss;  else dt.s=0.;
      futobs.obstime = (date_to_jd(dt)-jd0)*DAY;
    }

    futobs.xe = -999.;		/* Force evaluation of earth3d */

    printf("At time= %s",inbuff);

    predict_posn(&p,covar,&futobs,sigxy);

    printf("# Solar Elongation = %.2f Opp angle = %.2f\n",
	   elongation(&futobs)/DTOR,opposition_angle(&futobs)/DTOR);

    /* Compute a, b, theta of error ellipse for output */
    xx = sigxy[1][1];
    yy = sigxy[2][2];
    xy = sigxy[1][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Adjust for PA to be N through E, */
    PA = PA-90;
    if (PA<-90.) PA += 180.;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    printf("Cum. ecliptic posn: %10.4f %10.4f   %8.2f %8.2f %7.2f\n",
	   futobs.thetax/ARCSEC, futobs.thetay/ARCSEC,
	   a/ARCSEC,b/ARCSEC,PA); 

    /* Now transform to RA/DEC, via ecliptic*/
    proj_to_ec(futobs.thetax,futobs.thetay,
	       &lat, &lon,
	       lat0, lon0, derivs);
    /* map the covariance */
    covar_map(sigxy, derivs, covecl, 2, 2);

    /* Now to ICRS: */
    ec_to_eq(lat, lon, &ra, &dec, derivs);
    /* map the covariance */
    covar_map(covecl, derivs, coveq, 2, 2);

    /* Compute a, b, theta of error ellipse for output */
    xx = coveq[1][1]*cos(dec)*cos(dec);
    xy = coveq[1][2]*cos(dec);
    yy = coveq[2][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Put PA N through E */
    PA = 90.-PA;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    ra /= DTOR;
    if (ra<0.) ra+= 360.;
    dec /= DTOR;
    deghms(ra,rastring);
    degdms(dec,decstring);
    printf("ICRS position: %s %s %10.4f %10.4f %7.2f\n",
	   rastring,decstring,a/ARCSEC,b/ARCSEC,PA); 
  }
  exit(0);
}