/* comet_elements.c enters comet elements */ /* Based upon Earl Spillar's comets.c */ /* 95/11/24 R. Howell -- Modified to correct prompts */ /* Also allows years > 1999 */ #include #include /* double cal_jd(int y,int m,double d); */ double cal_jd(); main() /* Comets program */ { FILE *output_file; double transjul_date,q,omega,i; double epochjul_date,a,e,n,w,M=0.0,semdia=0.0,mag=0.0; char number[16], name[40],outfile[80],c='N'; int temp_day; /* Temporarily holds day of perihelion */ double temp_hr; /* Temporarily holds hh.hh of perihelion */ struct date{ int year; int month; double day; }trans,epoch; printf("**** Enters Comet Orbit Elements ****\n"); printf("Enter a number or ALTERNATE name for the comet: "); scanf("%15s",number); number[15] = 0; printf("Enter the name of the comet: "); scanf("%39s",name); name[39] = 0; /* Make sure it is null terminated */ printf("Enter the date of perihelion transit (yyyy mm dd hh.hh):"); scanf("%d %d %d %lf", &trans.year, &trans.month, &temp_day, &temp_hr); trans.day = (double)temp_day + (temp_hr/24.); printf("Enter the distance at perihelion q: "); scanf("%lf",&q); printf("Enter the eccentricity e: "); scanf("%lf",&e); printf("Enter the argument of perihelion omega: "); scanf("%lf",&w); printf("Enter the longitude of ascending node Omega: "); scanf("%lf",&omega); printf("Enter the inclination i: "); scanf("%lf",&i); printf("Enter the daily motion n or 0.0 if unknown: "); scanf("%lf",&n); printf("Enter the equinox for the elements (yyyy mm dd): "); scanf("%d %d %lf",&epoch.year,&epoch.month,&epoch.day); transjul_date = (double) cal_jd(trans.year, trans.month,trans.day); epochjul_date = (double) cal_jd(epoch.year, epoch.month,epoch.day); a = q/(1-e); /* convert perihelion to mean dist */ printf("\nNumber: %6s",number); printf("\nComet Name: %20s\n",name); printf("Date of Perihelion Transit (JD): %f\n",transjul_date); printf("Mean Distance: %f\n",a); /* mean distance */ printf("Eccentricity: %f\n",e); printf("Argument of Latitude: %f\n",w); printf("Longitude of Ascending Node: %f\n",omega); printf("Inclindation: %f\n",i); printf("Equinox (JD): %f\n",epochjul_date); printf("Enter name of output file: "); scanf("%s",outfile); output_file=fopen(outfile,"a"); fprintf(output_file,"%6s %-20s %9.4f %10.5f %10.5f %10.5f %11.7f\n", number, name, transjul_date,i,omega,w,a); fprintf(output_file,"%10.5f %10.7f %10.7f %9.4f %7.3f %7.3f\n", n,e, M, epochjul_date,mag,semdia); } double cal_jd(yyyy, m, d) /* Conversion routine */ int yyyy; int m; double d; { double B,jul_date; if (m <= 2){ m = m + 12; yyyy = yyyy - 1; } /* yyyy = yyyy + 1900.0; New version uses full year. */ B = -15.0; /* approximation only good between 1 March 1900 and */ /* 28 February 2100 */ jul_date = ((floor(365.25 * yyyy))+(floor(30.6001*(m+1)))+(B)+ (1720996.5)+(d)); return((double)jul_date); }