Ejemplo n.º 1
0
/* Read an orbit in alpha, beta, gamma format & covar matrix from file.
   Also reads the coordinate frame specifications.
*/
int
read_abg(char *fname, 
	 PBASIS *p, 
	 double **covar)
{
  FILE *fptr;
  int  i;
  char	inbuff[256];

  if (fname==NULL)
    fptr = stdin;
  else if ( (fptr=fopen(fname,"r"))==NULL) {
    fprintf(stderr,"Error opening a/b/g orbit file %s\n",fname);
    return(1);
  }

  /* Skipping comments, read the a/b/g specs*/
  if (fgets_nocomment(inbuff,255,fptr,NULL)==NULL) {
    fprintf(stderr,"Data missing from a/b/g/ data file.\n");
    return(1);
  }

  if (sscanf(inbuff, "%lf %lf %lf %lf %lf %lf",
	     &(p->a),&(p->adot),&(p->b),&(p->bdot),
	     &(p->g),&(p->gdot)) != 6) {
    fprintf(stderr,"Error reading a/b/g data\n");
    return(1);
  }

  for (i=1; i<=6; i++) {
    if (fgets_nocomment(inbuff,255,fptr,NULL)==NULL) {
      fprintf(stderr,"Data missing from a/b/g/ covariance.\n");
      return(1);
    }

    if (sscanf(inbuff, "%lf %lf %lf %lf %lf %lf",
	       &covar[i][1],&covar[i][2],&covar[i][3],
	       &covar[i][4],&covar[i][5],&covar[i][6]) != 6) {
      fprintf(stderr,"Error reading a/b/g covariance\n");
      return(1);
    }
  }

  /* Now read the coordinate system info */
  if (fgets_nocomment(inbuff,255,fptr,NULL)==NULL) {
    fprintf(stderr,"Data missing from a/b/g/ data file.\n");
    return(1);
  }

  if (sscanf(inbuff, "%lf %lf %lf %lf %lf %lf",
	     &lat0, &lon0, &xBary, &yBary, &zBary, &jd0) != 6) {
    fprintf(stderr,"Error reading coord system info\n");
    return(1);
  }
  lat0 *= DTOR;
  lon0 *= DTOR;

  if (fname!=NULL) fclose(fptr);
  return(0);
}
Ejemplo n.º 2
0
/* Input file is stdin if fname==NULL */
int
read_radec(OBSERVATION obsarray[], char *fname, int *nobs)
{
  FILE *fptr;
  OBSERVATION  *obs;
  int  i;
  char	inbuff[256];
  double jd,ra,dec,elat,elon;

  if (fname==NULL)
    fptr = stdin;
  else if ( (fptr=fopen(fname,"r"))==NULL) {
    fprintf(stderr,"Error opening observations file %s\n",fname);
    exit(1);
  }

  *nobs=0;
  while ( fgets_nocomment(inbuff,255,fptr,NULL)!=NULL) {
    if ( scan_observation(inbuff, &(obsarray[*nobs]))) {
      fprintf(stderr,"Quitting on format error\n");
      exit(1);
    }

    obs = &(obsarray[*nobs]);
    (*nobs)++;

    eq_to_ec(obs->thetax,obs->thetay,&elat,&elon,NULL);

    if (*nobs==1) {
      double xec, yec, zec;
      /* Use first observation to set the reference frame */
      jd0 = obs->obstime;
      lat0 = elat;
      lon0 = elon;
      
      /* Find location of SSBARY wrt observatory at zero time */
      earth_ssbary(jd0, obs->obscode, &xBary, &yBary, &zBary);

      /* Negate the vector to make it earth->SSBARY*/
      /* And rotate equatorial into the tangent-point coords */
      xBary *= -1.;  yBary *= -1.;  zBary *= -1.;
      xyz_eq_to_ec(xBary, yBary, zBary, &xec, &yec, &zec,NULL);
      xyz_ec_to_proj(xec, yec, zec, &xBary, &yBary, &zBary, lat0, lon0, NULL);
    }

    /* Set time to years after jd0, rotate to tangent plane coords */
    obs->obstime = (obs->obstime-jd0)*DAY;
    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));
		
  }
  if (fname!=NULL) fclose(fptr);
  return(0);
}
Ejemplo n.º 3
0
/* Read the look-up table for observatories.  
 * Note that ground-based longitudes are stored in hours, 
 * altitude in meters, lat in radians */
void
read_observatories(char *fname)
{

  FILE *sitefile;
  char  inbuff[BUFFSIZE], latstring[40], lonstring[40];
  int nchar;
  int obscode;
  char fileName[FNAMESIZE];

  extern double dmsdeg(char *string);
  extern double hmsdeg(char *string);

  nsites = nspacecraft = 0;

  /** use passed filename, or a previously specified filename,
   ** or environment-specified file, or the default filename, in that order
   */
  if (fname != NULL)
    strncpy(fileName, fname, FNAMESIZE-1);
  else if (strlen(observatory_file)>0)
    strncpy(fileName, observatory_file, FNAMESIZE-1);
  else if (getenv(OBS_ENVIRON)!=NULL)
    strncpy(fileName, getenv(OBS_ENVIRON), FNAMESIZE-1);
  else
    strncpy(fileName, DEFAULT_OBSERVATORY_FILE, FNAMESIZE-1);
  
  fileName[FNAMESIZE-1]=0;
  /* fprintf(stderr,"Loading from %s\n", fileName); */

  if ((sitefile = fopen(fileName,"r"))==NULL) {
    fprintf(stderr,"Error opening observatories file %s\n",fileName);
    exit(1);
  }

  while (fgets_nocomment(inbuff, BUFFSIZE-1, sitefile, NULL)!=NULL) {
    /* fprintf(stderr,"%s\n", inbuff); */
    if (sscanf(inbuff, "%i", &obscode)!=1) {
      fprintf(stderr,"Bad line in obseratories file %s:\n->%s\n",
	      fileName, inbuff);
      exit(1);
    }
    if (obscode < OBSCODE_ORBITAL) {
      /* This line specifies a ground-based location */
      SITE *sss;
      sss = &(sitelist[nsites]);
      if (sscanf(inbuff,"%d %s %s %lf %n", &(sss->code), lonstring, latstring,
		 &(sss->altitude), &nchar)!=4) {
	fprintf(stderr,"Bad line in obseratories file %s:\n->%s\n",
		fileName, inbuff);
	exit(1);
      }
      /* fprintf(stderr, "nchar: %i, strlen: %i\n",nchar, (int) strlen(inbuff)); */
      if (nchar<(int) strlen(inbuff)) {
	int nn;
	nn = strcspn(inbuff+nchar,"\n");
	if (nn>=80) nn=79;
	strncpy(sss->name, inbuff+nchar, nn);
	sss->name[nn]=0;
      } else {
	sss->name[0] = 0;
      }
      sss->lon = dmsdeg(lonstring)/15.;	/*convert longitude to hours*/
      sss->lat = dmsdeg(latstring)*DTOR;
      nsites++;

    } else {
      /* This is an orbiting observatory */
      SPACECRAFT *sss;
      sss = &(spacecraftlist[nspacecraft]);
      if (sscanf(inbuff,"%d %s %lf %lf %lf %s %d", 
		 &(sss->code), lonstring, &(sss->P),
		 &(sss->precess), &(sss->jd0), latstring, 
		 &nchar)!=6) {
	fprintf(stderr,"Bad line in obseratories file %s:\n->%s\n",
		fileName, inbuff);
	exit(1);
      }
      if (nchar<(int)strlen(inbuff)) {
	int nn;
	nn = strcspn(inbuff+nchar,"\n");
	if (nn>=80) nn=79;
	strncpy(sss->name, inbuff+nchar, nn);
	sss->name[nn]=0;
      } else {
	sss->name[0] = 0;
      }
      sss->i = dmsdeg(lonstring)*DTOR;	/*convert to radians*/
      sss->ra0 = dmsdeg(latstring)*DTOR;

      /* calculate the semi-major axis, in AU */
      sss->a = pow( pow(sss->P*DAY,2.) * GM * EARTHMASS / (TPI*TPI),
		    1./3.);
      nspacecraft++;
    }
  }
  fclose(sitefile);
  
  if (nsites<1 && nspacecraft<1) {
    fprintf(stderr,"Error: no observatory sites found\n");
    exit(1);
  }
}
Ejemplo n.º 4
0
/* Input file is stdin if fname==NULL */
int
read_radec(OBSERVATION obsarray[], char *fname, int *nobs)
{
  FILE *fptr;
  OBSERVATION  *obs;
  int  scan_status_flag;
  int  i;
  char	inbuff[256];
  double jd,ra,dec,elat,elon;

  if (fname==NULL)
    fptr = stdin;
  else if ( (fptr=fopen(fname,"r"))==NULL) {
    fprintf(stderr,"Error opening observations file %s\n",fname);
    exit(1);
  }

  *nobs=0;
  while ( fgets_nocomment(inbuff,255,fptr,NULL)!=NULL) {

    // obs refers to the previous observation, after the first loop.
    scan_status_flag = scan_observation(inbuff, &(obsarray[*nobs]), obs);

    // scanned line was 2nd line of two line format so don't advance nobs as all we did was reset the observer x/y
    if (scan_status_flag == -1) {
      mpc3d(obs->obstime, &(obs->xe), &(obs->ye), &(obs->ze));
      continue;
    }

    // all other non-zero status values indicate an error.
    if ( scan_status_flag == 1) {
      fprintf(stderr,"Quitting on format error\n");
      exit(1);
    }

    obs = &(obsarray[*nobs]);
    (*nobs)++;

    eq_to_ec(obs->thetax,obs->thetay,&elat,&elon,NULL);


    if (*nobs==1) {
      double xec, yec, zec;
      /* Use first observation to set the reference frame */
      jd0 = obs->obstime;
      lat0 = elat;
      lon0 = elon;


      /* fprintf(stderr, "%f %f %f %d\n", elat, elon, obs->obstime, obs->obscode); */

      /* Find location of SSBARY wrt observatory at zero time */
      earth_ssbary(jd0, obs->obscode, &xBary, &yBary, &zBary);

      /* fprintf(stderr, "%f %f %f %d\n", elat, elon, obs->obstime, obs->obscode); */

      /* Negate the vector to make it earth->SSBARY*/
      /* And rotate equatorial into the tangent-point coords */
      xBary *= -1.;  yBary *= -1.;  zBary *= -1.;
      xyz_eq_to_ec(xBary, yBary, zBary, &xec, &yec, &zec,NULL);
      xyz_ec_to_proj(xec, yec, zec, &xBary, &yBary, &zBary, lat0, lon0, NULL);
    }
    /* fprintf(stderr,"%f %f", lat0, lon0); */
    /* Set time to years after jd0, rotate to tangent plane coords */
    obs->obstime = (obs->obstime-jd0)*DAY;
    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: */
    if (scan_status_flag == -2) {
      mpc3d(obs->obstime, &(obs->xe), &(obs->ye), &(obs->ze));
    } else {
      earth3d(obs->obstime, obs->obscode,
              &(obs->xe), &(obs->ye), &(obs->ze));
    }
  }
  if (fname!=NULL) fclose(fptr);
  return(0);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
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);
}