/* Earl's file reading routines -- modified by R. Howell */ /* I've left out the other initialization routines, and only have a modified */ /* version of GETORBIT here. */ #include "../track/wirotypes.h" #include "../track/wiro.h" #include #include #include #include "kep.h" read_orbit_elements(aname, el, display_name) char *aname; struct orbit *el; char *display_name; { int found_object = 0; /* Flag set to 1 when object found */ FILE *catalog; char lstr1[ 100 ], lstr2[ 100 ], filename[200]; char *ignore, /* Used to mark start of comment file in line */ temp[ 80 ], cat_name[ 80 ], o_name[80], /* Object on current line of file */ o_number[80]; /* Object "number" on current line of file */ int s1, /* number of fields converted in line 1 */ s2; /* number of fields converted in line 2 */ /* First find which catalog to use */ strcpy(filename, CATALOGS); strcat(filename, "current_orbit.cat"); catalog = fopen( filename, "r" ); if ( catalog == NULL ) { printf("No orbit elements catalog has been selected.\n"); printf("Use \"orbit_catalog\" to do this.\n"); exit( -2 ); } fscanf( catalog, "%s", cat_name ); fclose( catalog ); strcpy( temp, CATALOGS ); strcat( temp, cat_name ); catalog = fopen( temp, "r" ); if ( catalog == NULL ) { printf( "Unable to open catalog: %s\n", temp ); exit( -1 ); } /* Now loop through the catalog, looking for a name or number which matches */ do { fgets( lstr1, 99, catalog ); if ( lstr1[ 0 ] == '*' ) continue; /* Is it a comment line? */ if ( lstr1[ 0 ] == '%' ) continue; fgets( lstr2, 99, catalog ); if ( lstr2[ 0 ] == '*' ) continue; /* Is it a comment line? */ if ( lstr2[ 0 ] == '%' ) continue; /* Note -- comment lines are not allowed between parts of a two line set */ /* The system may get confused if there are unpaired lines. */ /* Now chop off any part of the line after the | symbol */ /* It is for comments */ ignore = strchr( lstr1, '|' ); if ( ignore != NULL ) *ignore = '\0'; /* Repeat for second line */ ignore = strchr( lstr2, '|' ); if ( ignore != NULL ) *ignore = '\0'; /* Now try to read the pair of lines for the elements */ s1 = sscanf( lstr1, "'%[^']' '%[^']' %lf %lf %lf %lf %lf", o_number, o_name, &el->epoch, &el->i, &el->W, &el->w, &el->a ); s2 = sscanf( lstr2, "%lf %lf %lf %lf %lf %lf", &el->dm, &el->ecc, &el->M, &el->equinox, &el->mag, &el->sdiam); if (s1 != 7 || s2 != 6) continue; /* If any conversion failed, skip */ /* If name or number matches, we have found the entry */ /* Note the "number" is treated like a second name. */ /* It must match exactly, character by character. */ if ( strcmp( o_number, aname ) == 0 || strcmp( o_name, aname ) == 0 ) { found_object = 1; break; } strcpy( o_number, "" ); /* Clear out the number for next search */ strcpy( o_name, "" ); /* Clear out the name for next search */ } while ( !feof( catalog ) ); fclose( catalog ); if (!found_object) { printf("Could not find object \"%s\" in the catalog!\n", aname); exit(1); } strncpy(el->obname, o_name, 15); el->obname[15] = '\0'; /* Should really check name lengths. A project for later. */ strcpy(display_name, o_number); strcat(display_name, " "); strcat(display_name, o_name); }