Example #1
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);
}
Example #2
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);
}
Example #3
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);
}