#include #include #include #include"chby.h" #include"generate.h" #include"allocate.h" void main() /*----------------------------------------------------------------------------- PURPOSE: This program reads the ASCII ephemeris file for an asteroid and generates a Chebyshev polynomial ephemeris. REFERENCES: Hilton, J. L. 1998, "U.S. Naval Observatory Ephemerides of the Largest Asteroids," (submitted to Astron. J.) INPUT ARGUMENTS: None. INPUT PROMPTS: Asteroid number. The asteroids official numerical designation by the Minor Planet Center. Asteroid name. Tolerance. The maximum allowed deviation between the ephemeris position and the position generated by the Chebyshev polynomial in AU. Header A string of undesignated length giving information about the ephemeris appended to the beginning of the Chebyshev polynomial ephemeris. INPUT FILES: Asteroid ASCII ephemeris file, '.eph' extension. OUTPUT FILES: Asteroid Chebyshev polynomial ephemeris file, '.chby' extension. STANDARD OUTPUT None. VER./DATE/ PROGRAMMER: V1.0/12-95/JLH (USNO/AA) V1.1/04-97/JLH (USNO/AA) NOTES: Two temporary files are created while this program is running and then removed when no longer needed. The total size of the temporary files is approximately the same as the Chebyshev ephemeris file (about 1/20 the size of the input ephemeris. -----------------------------------------------------------------------------*/ { double tol; int mp, i = 0, len = 80, err = 0; char *name, *head, *buf, ch; buf = cmalloc( 81 * sizeof( char ), err ); /* Print out banner. */ printf( "\n\nU.S. Naval Observatory Chebyshev polynomial ephemeris generator " ); printf( "for asteroids.\n\nFor information on the prompts and the format of " ); printf( "ephemeris input file please\nsee the documentation.\n\n" ); /* Get asteroid number. */ printf( "Asteroid Number? " ); scanf ( "%i", &mp ); /* Throw away terminating line feed and get asteroid name. */ getchar(); printf( "Asteroid Name? " ); ch = (char) getchar(); while( ch != '\n' ) { buf[i] = ch; ++i; ch = (char) getchar(); } buf[i] = '\0'; name = cmalloc( (1 + strlen( buf )) * sizeof( char ), err ); strcpy( name, buf ); /* Get tolerance of Chebyshev polynomial. */ printf( "Tolerance (AU)? " ); scanf ( "%lf", &tol ); /* Throw away terminating line feed and get header line(s). */ getchar(); printf( "Header information string (delimited by \" \")?\n" ); /* Throw away initial delimiter after checking to make sure it is valid. */ i = 0; ch = (char) getchar(); if( ch != '"' ) { fprintf( stderr, "ERROR: Character string not delimited by \"!\n" ); exit( EXIT_FAILURE ); } ch = (char) getchar(); /* Until end delimiter is encountered, fill buffer with characters. */ while( ch != '"' ) { buf[i] = ch; /* If buffer is full allocate another chunk of space. */ if( i == len ) { len += 80; buf = crealloc( buf, (len + 1 ) * sizeof( char ), err ); } ++i; /* If ch is '\' get the delimited character as well. */ if( ch == '\\' ) { ch = (char) getchar(); buf[i] = ch; /* Again check for a full buffer. */ if( i == len ) { len += 80; buf = crealloc( buf, (len + 1 ) * sizeof( char ), err ); } ++i; } ch = (char) getchar(); } /* Put terminating \0 on buffer. The allocate memory for string and copy buffer into it. */ buf[i] = '\0'; head = cmalloc( (1 + strlen( buf )) * sizeof( char ), err ); strcpy( head, buf ); /* Generate Chebyshev polynomial ephemeris. */ generate( &mp, name, &tol, head, err ); if( err != 0 ) printf( "An error has occurred! Check stderr for more information." ); else printf( "%i %s\nTolerance = %e\n%s\n", mp, name, tol, head ); /* Free memory */ free( buf ); free( name ); free( head ); }