/* Asteroid element program */ /* Based upon Earl Spillar's planet.c */ /* 95/11/24 Robert R. Howell */ #include #include #include double cal_jd(); /* Convert date to JD */ int gtline(); /* Get line from input */ void trimstr(); /* Trim trailing spaces */ main() /* Asteroid entry program */ { FILE *output_file; double epoch_jul_date, Omega, i, w, n; double a,e,equinox_jul_date,mag,semdia,M; char number[16], pnumber[18]; /* Short name or number, then same with quotes */ char name[40], pname[42]; /* Full name, then same with quotes. */ char outfile[80],c='N'; void convert(); struct date{ int year; int month; double day; }epoch,equinox; printf("Enter all angles in degrees\n"); printf("\nEnter the equinox for the elements (yyyy mm dd.dd)"); printf("\nThis will probably by 1950 1 1 or 2000 1 1 : "); scanf("%d %d %lf",&equinox.year,&equinox.month,&equinox.day); printf("Enter the epoch of the elements yyyy mm dd.dd: "); scanf("%d %d %lf",&epoch.year,&epoch.month,&epoch.day); /* Discard rest of line, in case limit caused end of input */ while (c != EOF && c != '\n') c=getchar(); printf("Enter the name of the asteroid: "); gtline(name, 40); name[39] = 0; /* Make sure it is null terminated */ printf("Enter the alternate name (such as 5a): "); gtline(number, 16); number[15] = 0; /* Make sure it is null terminated */ printf("Enter the magnitude (m) or 0.0: "); scanf("%lf",&mag); printf("Enter the diameter (km) or 0.0: "); scanf("%lf",&semdia); semdia = semdia / 2.; /* Center diameter -- use semidiam. */ printf("Enter the inclination (i): "); scanf("%lf",&i); printf("Enter the ascending node (Omega): "); scanf("%lf",&Omega); printf("Enter the argument of the perihelion (omega): "); scanf("%lf",&w); printf("Enter the mean distance (a): "); scanf("%lf",&a); printf("Enter the daily motion (n) or 0.0 to calculate: "); scanf("%lf",&n); printf("Enter the eccentricity (e): "); scanf("%lf",&e); printf("Enter the mean anomaly (M): "); scanf("%lf", &M); printf("Orbit catalog file where elements will be appended: "); scanf("%s",outfile); output_file=fopen(outfile,"a"); equinox_jul_date = (double) cal_jd(equinox.year, equinox.month, equinox.day); epoch_jul_date = (double) cal_jd(epoch.year, epoch.month, epoch.day ); /* Add quotes around short and full name */ trimstr(number); strcpy(pnumber, "\'"); strcat(pnumber, number); strcat(pnumber, "\'"); trimstr(name); strcpy(pname, "\'"); strcat(pname, name); strcat(pname, "\'"); fprintf(output_file,"%-6s %-20s %9.4f %10.5f %9.5f %9.5f %11.7f\n", pnumber, pname, epoch_jul_date,i,Omega,w,a); fprintf(output_file,"%10.5f %10.7f %10.7f %9.4f %7.3f %7.3f\n", n,e, M, equinox_jul_date,mag,semdia); fclose(output_file); } 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; } 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); } int gtline(s, lim) char s[]; int lim; { /* Get line & return length, or EOF if FIRST character IS EOF */ /* The limit is the FULL LENGTH, including the final '\n'. */ /* This is very similar to K&R 1st ed. getline, except I also return */ /* EOF, and I don't return the final '\n'. */ /* Because I return EOF, I'm implicitly assuming that EOF is not the */ /* same as any valid integer. Usually it is -1. */ int c, i; int found_eol = 0; /* Input characters till limit or EOL */ for (i=0; i=0; i--) if (str[i] == ' ') str[i] = '\0'; }