int abg_to_xyz(int argc, char *argv[]) { PBASIS p; XVBASIS xv; double **covar_abg, **covar_xyz, **derivs; int i,j; /* if (argc!=1) print_help(abg_to_xyz_help); */ covar_abg = dmatrix(1,6,1,6); covar_xyz = dmatrix(1,6,1,6); derivs = dmatrix(1,6,1,6); /* 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)); } if (read_abg(NULL,&p,covar_abg)) { fprintf(stderr, "Error in input alpha/beta/gamma file\n"); exit(1); } /* Transform the orbit basis and get the deriv. matrix */ pbasis_to_bary(&p, &xv, derivs); /* Map the covariance matrix to new basis */ covar_map(covar_abg, derivs, covar_xyz,6,6); /* Print out the results, with comments */ printf("# x y z " "vx vy vz\n"); printf("%12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n", xv.x, xv.y, xv.z, xv.xdot, xv.ydot, xv.zdot); printf("# covariance matrix:\n"); print_matrix(stdout,covar_xyz,6,6); printf("# Position is for JD:\n%.5f\n",jd0); free_dmatrix(covar_abg,1,6,1,6); free_dmatrix(covar_xyz,1,6,1,6); free_dmatrix(derivs,1,6,1,6); exit(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); }
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); }
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; }
double *abg_to_aei(char *abg_file) { PBASIS p; XVBASIS xv; ORBIT orbit; static double result[15]; double d, dd; double **covar_abg, **covar_xyz, **derivs, **covar_aei; int i,j; 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); if (read_abg(abg_file,&p,covar_abg)) { fprintf(stderr, "Error in input alpha/beta/gamma file\n"); exit(1); } /* Transform the orbit basis and get the deriv. matrix */ pbasis_to_bary(&p, &xv, derivs); /* Map the covariance matrix to new basis */ covar_map(covar_abg, derivs, covar_xyz,6,6); /* Get partial derivative matrix from xyz to aei */ aei_derivs(&xv, derivs); /* Map the covariance matrix to new basis */ covar_map(covar_xyz, derivs, covar_aei,6,6); /* Transform xyz basis to orbital parameters */ orbitElements(&xv, &orbit); d = sqrt(xBary*xBary + yBary*yBary + pow(zBary-1/p.g,2.)); dd = d*d*sqrt(covar_abg[5][5]); /* Print out the results, with comments */ /* printf(aei_file,"# Barycentric osculating elements in ICRS at epoch %.1f:\n",jd0); printf("# a e i Node Arg of Peri Time of Peri\n"); printf("%12.6f %9.6f %8.3f %8.3f %8.3f %11.3f\n", orbit.a, orbit.e, orbit.i, orbit.lan, orbit.aop, orbit.T); fprintf("+-%10.6f %9.6f %8.3f %8.3f %8.3f %11.3f\n", sqrt(covar_aei[1][1]), sqrt(covar_aei[2][2]), sqrt(covar_aei[3][3])/DTOR, sqrt(covar_aei[4][4])/DTOR, sqrt(covar_aei[5][5])/DTOR, sqrt(covar_aei[6][6])/DAY); fprintf("# covariance matrix:\n"); fprint_matrix(stdout,covar_aei,6,6); */ result[0] = orbit.a; result[1] = orbit.e; result[2] = orbit.i; result[3] = orbit.lan; result[4] = orbit.aop; result[5] = orbit.T; result[6] = sqrt(covar_aei[1][1]); result[7] = sqrt(covar_aei[2][2]); result[8] = sqrt(covar_aei[3][3])/DTOR; result[9] = sqrt(covar_aei[4][4])/DTOR; result[10] = sqrt(covar_aei[5][5])/DTOR; result[11] = sqrt(covar_aei[6][6])/DAY; result[12] = jd0; result[13] = d; result[14] = dd; free_dmatrix(covar_abg,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); return result; }
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); }