1
0
Fork 0

Added zlib support for reading in compressed data files.

This commit is contained in:
curt 1998-05-29 20:35:41 +00:00
parent 001d39314f
commit 371806f033
2 changed files with 62 additions and 51 deletions

View file

@ -32,6 +32,7 @@
#include <Debug/fg_debug.h> #include <Debug/fg_debug.h>
#include <Include/fg_constants.h> #include <Include/fg_constants.h>
#include <Include/fg_zlib.h>
#include <Main/options.hxx> #include <Main/options.hxx>
#include <Time/fg_time.hxx> #include <Time/fg_time.hxx>
@ -40,6 +41,8 @@
struct OrbElements pltOrbElements[9]; struct OrbElements pltOrbElements[9];
static fgFile data;
double fgCalcActTime(fgTIME t) double fgCalcActTime(fgTIME t)
{ {
@ -77,28 +80,23 @@ double fgCalcEccAnom(double M, double e)
of, other than feof(FILE*)? That's currently the only check I can of, other than feof(FILE*)? That's currently the only check I can
think of (Durk) */ think of (Durk) */
int fgReadOrbElements(struct OrbElements *dest, FILE *src) int fgReadOrbElements(struct OrbElements *dest, gzFile src) {
{ char line[256];
char line[256];
int i,j; int i,j;
j = 0; j = 0;
do do {
{ if ( fggets(src, line, 256) == NULL ) {
if (feof (src)) {
fgPrintf (FG_ASTRO, FG_ALERT, fgPrintf (FG_ASTRO, FG_ALERT,
"End of file found while reading planetary positions:\n"); "End of file found while reading planetary positions:\n");
return 0; return 0;
} }
for (i = 0; i < 256; i++) {
fgets(line, 256,src); if (line[i] == '#')
for (i = 0; i < 256; i++)
{
if (line[i] == '#')
line[i] = 0; line[i] = 0;
} }
/*printf("Reading line %d\n", j++); */ // printf("Reading line %d = %s\n", j++, line);
} } while (!(strlen(line)));
while (!(strlen(line)));
sscanf(line, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", sscanf(line, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",
&dest->NFirst, &dest->NSec, &dest->NFirst, &dest->NSec,
&dest->iFirst, &dest->iSec, &dest->iFirst, &dest->iSec,
@ -114,10 +112,8 @@ int fgReadOrbElements(struct OrbElements *dest, FILE *src)
int fgSolarSystemInit(fgTIME t) int fgSolarSystemInit(fgTIME t)
{ {
fgOPTIONS *o; fgOPTIONS *o;
char path[80]; char path[256], gzpath[256];
int i; int i, ret_val;
FILE *data;
int ret_val = 0;
fgPrintf( FG_ASTRO, FG_INFO, "Initializing solar system\n"); fgPrintf( FG_ASTRO, FG_INFO, "Initializing solar system\n");
@ -126,29 +122,33 @@ int fgSolarSystemInit(fgTIME t)
path[0] = '\0'; path[0] = '\0';
strcat(path, o->fg_root); strcat(path, o->fg_root);
strcat(path, "/Scenery/"); strcat(path, "/Scenery/");
strcat(path, "Planets.dat"); strcat(path, "Planets");
if ( (data = fopen(path, "r")) == NULL ) if ( (data = fgopen(path, "rb")) == NULL ) {
{ strcpy(gzpath, path);
fgPrintf( FG_ASTRO, FG_ALERT, strcat(gzpath, ".gz");
if ( (data = fgopen(gzpath, "rb")) == NULL ) {
fgPrintf( FG_ASTRO, FG_EXIT,
"Cannot open data file: '%s'\n", path); "Cannot open data file: '%s'\n", path);
} else { }
/* printf(" reading datafile %s\n", path); */
fgPrintf( FG_ASTRO, FG_INFO, " reading datafile %s\n", path);
/* for all the objects... */
for (i = 0; i < 9; i ++)
{
/* ...read from the data file ... */
if (!(fgReadOrbElements (&pltOrbElements[i], data))) {
ret_val = 0;
}
/* ...and calculate the actual values */
fgSolarSystemUpdate(&pltOrbElements[i], t);
}
ret_val = 1;
} }
return ret_val;
/* printf(" reading datafile %s\n", path); */
fgPrintf( FG_ASTRO, FG_INFO, " reading datafile %s\n", path);
/* for all the objects... */
for (i = 0; i < 9; i ++) {
/* ...read from the data file ... */
if (!(fgReadOrbElements (&pltOrbElements[i], data))) {
ret_val = 0;
}
/* ...and calculate the actual values */
fgSolarSystemUpdate(&pltOrbElements[i], t);
}
fgclose(data);
return ( 1 );
} }
@ -170,9 +170,12 @@ void fgSolarSystemUpdate(struct OrbElements *planet, fgTIME t)
/* $Log$ /* $Log$
/* Revision 1.5 1998/05/13 18:25:34 curt /* Revision 1.6 1998/05/29 20:35:41 curt
/* Root path info moved to fgOPTIONS. /* Added zlib support for reading in compressed data files.
/* /*
* Revision 1.5 1998/05/13 18:25:34 curt
* Root path info moved to fgOPTIONS.
*
* Revision 1.4 1998/04/28 01:19:00 curt * Revision 1.4 1998/04/28 01:19:00 curt
* Type-ified fgTIME and fgVIEW * Type-ified fgTIME and fgVIEW
* *

View file

@ -43,6 +43,7 @@
#include <Aircraft/aircraft.h> #include <Aircraft/aircraft.h>
#include <Debug/fg_debug.h> #include <Debug/fg_debug.h>
#include <Include/fg_constants.h> #include <Include/fg_constants.h>
#include <Include/fg_zlib.h>
#include <Main/options.hxx> #include <Main/options.hxx>
#include <Main/views.hxx> #include <Main/views.hxx>
#include <Time/fg_time.hxx> #include <Time/fg_time.hxx>
@ -62,10 +63,10 @@
/* Initialize the Star Management Subsystem */ /* Initialize the Star Management Subsystem */
int fgStarsInit( void ) { int fgStarsInit( void ) {
FILE *fd; fgFile fd;
fgOPTIONS *o; fgOPTIONS *o;
/* struct CelestialCoord pltPos; */ /* struct CelestialCoord pltPos; */
char path[1024]; char path[256], gzpath[256];
char line[256], name[256]; char line[256], name[256];
char *front, *end; char *front, *end;
double right_ascension, declination, magnitude; double right_ascension, declination, magnitude;
@ -81,7 +82,7 @@ int fgStarsInit( void ) {
path[0] = '\0'; path[0] = '\0';
strcat(path, o->fg_root); strcat(path, o->fg_root);
strcat(path, "/Scenery/"); strcat(path, "/Scenery/");
strcat(path, "Stars.dat"); strcat(path, "Stars");
max_stars = FG_MAX_STARS; max_stars = FG_MAX_STARS;
@ -89,10 +90,14 @@ int fgStarsInit( void ) {
fgPrintf( FG_ASTRO, FG_INFO, fgPrintf( FG_ASTRO, FG_INFO,
" Loading %d Stars: %s\n", max_stars, path); " Loading %d Stars: %s\n", max_stars, path);
if ( (fd = fopen(path, "r")) == NULL ) { if ( (fd = fgopen(path, "rb")) == NULL ) {
fgPrintf( FG_ASTRO, FG_ALERT, strcpy(gzpath, path);
"Cannot open star file: '%s'\n", path); strcat(gzpath, ".gz");
return 0; // Oops, lets not even try to continue. This is critical. if ( (fd = fgopen(gzpath, "rb")) == NULL ) {
// Oops, lets not even try to continue. This is critical.
fgPrintf( FG_ASTRO, FG_EXIT,
"Cannot open star file: '%s'\n", path);
}
} }
stars[i] = xglGenLists(1); stars[i] = xglGenLists(1);
@ -101,7 +106,7 @@ int fgStarsInit( void ) {
/* read in each line of the file */ /* read in each line of the file */
count = 0; count = 0;
while ( (fgets(line, 256, fd) != NULL) && (count < max_stars) ) { while ( (fggets(fd, line, 256) != NULL) && (count < max_stars) ) {
front = line; front = line;
/* printf(" Read line = %s", front); */ /* printf(" Read line = %s", front); */
@ -171,7 +176,7 @@ int fgStarsInit( void ) {
} /* while */ } /* while */
fclose(fd); fgclose(fd);
xglEnd(); xglEnd();
@ -260,9 +265,12 @@ void fgStarsRender( void ) {
/* $Log$ /* $Log$
/* Revision 1.6 1998/05/13 18:25:35 curt /* Revision 1.7 1998/05/29 20:35:42 curt
/* Root path info moved to fgOPTIONS. /* Added zlib support for reading in compressed data files.
/* /*
* Revision 1.6 1998/05/13 18:25:35 curt
* Root path info moved to fgOPTIONS.
*
* Revision 1.5 1998/04/28 01:19:03 curt * Revision 1.5 1998/04/28 01:19:03 curt
* Type-ified fgTIME and fgVIEW * Type-ified fgTIME and fgVIEW
* *