66#include <assert.h>
77#include <math.h>
88#include <time.h>
9+ #include <zlib.h>
910#include "watdefs.h"
1011#include "afuncs.h"
1112#include "comets.h"
1213#include "date.h"
1314#include "norad.h"
1415#include "mpc_func.h"
16+ #include "stringex.h"
1517#include "observe.h"
1618
1719/* Code to generate topocentric ephemerides from TLE data, mostly focussed
@@ -31,9 +33,9 @@ typedef struct
3133
3234static int verbose = 0 ;
3335
34- static char * fgets_trimmed ( char * buff , const int buffsize , FILE * ifile )
36+ static char * gzgets_trimmed ( char * buff , const int buffsize , gzFile ifile )
3537{
36- char * rval = fgets ( buff , buffsize , ifile );
38+ char * rval = gzgets ( ifile , buff , buffsize );
3739
3840 if ( rval )
3941 {
@@ -162,7 +164,7 @@ static bool output_mjd = false;
162164static int show_ephems_from ( const char * path_to_tles , const ephem_t * e ,
163165 const char * filename , int start_line )
164166{
165- FILE * ifile ;
167+ gzFile ifile ;
166168 char line0 [100 ], line1 [100 ], line2 [100 ];
167169 int show_it = 1 , header_shown = 0 ;
168170 double jd_tle = 0. , tle_range = 1e+10 , abs_mag = 0. ;
@@ -176,14 +178,19 @@ static int show_ephems_from( const char *path_to_tles, const ephem_t *e,
176178 if ( verbose )
177179 printf ( "Should examine '%s'; start line %d\n" , filename , start_line );
178180 snprintf ( line0 , sizeof ( line0 ), "%s/%s" , path_to_tles , filename );
179- ifile = fopen ( line0 , "rb" );
181+ ifile = gzopen ( line0 , "rb" );
182+ if ( !ifile ) /* maybe it's compressed */
183+ {
184+ strlcat_error ( line0 , ".gz" );
185+ ifile = gzopen ( line0 , "rb" );
186+ }
180187 if ( !ifile )
181188 {
182189 fprintf ( stderr , "'%s' not opened\n" , line0 );
183190 exit ( 0 );
184191 }
185192 * line0 = * line1 = '\0' ;
186- while ( fgets_trimmed ( line2 , sizeof ( line2 ), ifile ))
193+ while ( gzgets_trimmed ( line2 , sizeof ( line2 ), ifile ))
187194 {
188195 tle_t tle ;
189196
@@ -348,29 +355,34 @@ static int show_ephems_from( const char *path_to_tles, const ephem_t *e,
348355 strcpy ( line0 , line1 );
349356 strcpy ( line1 , line2 );
350357 }
351- fclose ( ifile );
358+ gzclose ( ifile );
352359 return ( start_line );
353360}
354361
355362static const char * tle_list_filename = "tle_list.txt" ;
356363
357364int generate_artsat_ephems ( const char * path_to_tles , const ephem_t * e )
358365{
359- FILE * ifile ;
366+ gzFile ifile ;
360367 char buff [100 ];
361368 int is_in_range = 0 , id_matches = 1 , start_line = 0 ;
362369
363370 snprintf ( buff , sizeof ( buff ), "%s/%s" , path_to_tles , tle_list_filename );
364371 if ( verbose > 1 )
365372 printf ( "Opening '%s', looking for '%s'\n" , buff , e -> desig );
366- ifile = fopen ( buff , "rb" );
373+ ifile = gzopen ( buff , "rb" );
374+ if ( !ifile )
375+ {
376+ strlcat_error ( buff , ".gz" );
377+ ifile = gzopen ( buff , "rb" );
378+ }
367379 if ( !ifile )
368380 {
369381 fprintf ( stderr , "'%s' not opened\n" , buff );
370382 exit ( 0 );
371383 }
372384 while ( start_line != e -> n_steps &&
373- fgets_trimmed ( buff , sizeof ( buff ), ifile ))
385+ gzgets_trimmed ( buff , sizeof ( buff ), ifile ))
374386 {
375387 if ( !memcmp ( buff , "# Range:" , 8 ))
376388 {
@@ -405,7 +417,7 @@ int generate_artsat_ephems( const char *path_to_tles, const ephem_t *e)
405417 id_matches = 1 ;
406418 }
407419 }
408- fclose ( ifile );
420+ gzclose ( ifile );
409421 if ( start_line )
410422 printf ( "%s" , _header );
411423 return ( start_line );
@@ -418,15 +430,15 @@ static int set_location( ephem_t *e, const char *mpc_code, const char *obscode_f
418430
419431 if ( rval )
420432 {
421- FILE * ifile = fopen ( obscode_file_name , "rb" );
433+ gzFile ifile = gzopen ( obscode_file_name , "rb" );
422434 char buff [200 ];
423435
424436 if ( !ifile )
425437 {
426438 fprintf ( stderr , "'%s' not found\n" , obscode_file_name );
427439 exit ( 0 );
428440 }
429- while ( rval && fgets_trimmed ( buff , sizeof ( buff ), ifile ))
441+ while ( rval && gzgets_trimmed ( buff , sizeof ( buff ), ifile ))
430442 if ( !memcmp ( mpc_code , buff , 3 ))
431443 {
432444 const int planet = get_mpc_code_info ( & c , buff );
@@ -440,7 +452,7 @@ static int set_location( ephem_t *e, const char *mpc_code, const char *obscode_f
440452 rval = 0 ;
441453 printf ( "%s\n" , c .name );
442454 }
443- fclose ( ifile );
455+ gzclose ( ifile );
444456 }
445457 if ( !rval )
446458 {
0 commit comments