/* comet_elements.c enters comet elements */ /* Based upon Earl Spillar's comets.c */ /* 96/01/15 R. Howell -- Modified to correct prompts */ /* Also allows years > 1999 */ /* Outputs info in new orbit catalog format */ #include #include #include double cal_jd(); /* Convert date to JD */ int gtline(); /* Get line from input */ void trimstr(); /* Trim trailing spaces */ main() /* Comets program */ { FILE *output_file; double perihel_jul_date,q,Omega,i; double equinox_jul_date,a,e,n,w,M=0.0,semdia=0.0,mag=0.0; 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'; 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; }perihel,equinox; printf("Enter the equinox for the elements (yyyy mm dd)"); printf("\nThis will probably by 1950 1 1 or 2000 1 1 : "); scanf("%d %d %lf",&equinox.year,&equinox.month,&equinox.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 comet: "); gtline(name, 40); name[39] = 0; /* Make sure it is null terminated */ printf("Enter the alternate name (such as 58p): "); gtline(number, 16); number[15] = 0; /* Make sure it is null terminated */ printf("Enter the date of perihelion passage (yyyy mm dd hh.hh):"); scanf("%d %d %d %lf", &perihel.year, &perihel.month, &temp_day, &temp_hr); perihel.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); perihel_jul_date = (double) cal_jd(perihel.year, perihel.month, perihel.day); equinox_jul_date = (double) cal_jd(equinox.year, equinox.month, equinox.day); a = q/(1-e); /* convert perihelion to mean dist */ printf("Orbit catalog file where elements will be appended: "); scanf("%s",outfile); output_file=fopen(outfile,"a"); /* 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, perihel_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); output_file=fopen(outfile,"a"); } 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); } 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'; }