Added zlib support for reading in compressed data files.
This commit is contained in:
parent
001d39314f
commit
371806f033
2 changed files with 62 additions and 51 deletions
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include <Debug/fg_debug.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Include/fg_zlib.h>
|
||||
#include <Main/options.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
|
@ -40,6 +41,8 @@
|
|||
|
||||
struct OrbElements pltOrbElements[9];
|
||||
|
||||
static fgFile data;
|
||||
|
||||
|
||||
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
|
||||
think of (Durk) */
|
||||
|
||||
int fgReadOrbElements(struct OrbElements *dest, FILE *src)
|
||||
{
|
||||
char line[256];
|
||||
int fgReadOrbElements(struct OrbElements *dest, gzFile src) {
|
||||
char line[256];
|
||||
int i,j;
|
||||
j = 0;
|
||||
do
|
||||
{
|
||||
if (feof (src)) {
|
||||
do {
|
||||
if ( fggets(src, line, 256) == NULL ) {
|
||||
fgPrintf (FG_ASTRO, FG_ALERT,
|
||||
"End of file found while reading planetary positions:\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fgets(line, 256,src);
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if (line[i] == '#')
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (line[i] == '#')
|
||||
line[i] = 0;
|
||||
}
|
||||
/*printf("Reading line %d\n", j++); */
|
||||
}
|
||||
while (!(strlen(line)));
|
||||
// printf("Reading line %d = %s\n", j++, line);
|
||||
} while (!(strlen(line)));
|
||||
|
||||
sscanf(line, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",
|
||||
&dest->NFirst, &dest->NSec,
|
||||
&dest->iFirst, &dest->iSec,
|
||||
|
@ -114,10 +112,8 @@ int fgReadOrbElements(struct OrbElements *dest, FILE *src)
|
|||
int fgSolarSystemInit(fgTIME t)
|
||||
{
|
||||
fgOPTIONS *o;
|
||||
char path[80];
|
||||
int i;
|
||||
FILE *data;
|
||||
int ret_val = 0;
|
||||
char path[256], gzpath[256];
|
||||
int i, ret_val;
|
||||
|
||||
fgPrintf( FG_ASTRO, FG_INFO, "Initializing solar system\n");
|
||||
|
||||
|
@ -126,29 +122,33 @@ int fgSolarSystemInit(fgTIME t)
|
|||
path[0] = '\0';
|
||||
strcat(path, o->fg_root);
|
||||
strcat(path, "/Scenery/");
|
||||
strcat(path, "Planets.dat");
|
||||
strcat(path, "Planets");
|
||||
|
||||
if ( (data = fopen(path, "r")) == NULL )
|
||||
{
|
||||
fgPrintf( FG_ASTRO, FG_ALERT,
|
||||
if ( (data = fgopen(path, "rb")) == NULL ) {
|
||||
strcpy(gzpath, path);
|
||||
strcat(gzpath, ".gz");
|
||||
if ( (data = fgopen(gzpath, "rb")) == NULL ) {
|
||||
fgPrintf( FG_ASTRO, FG_EXIT,
|
||||
"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$
|
||||
/* Revision 1.5 1998/05/13 18:25:34 curt
|
||||
/* Root path info moved to fgOPTIONS.
|
||||
/* Revision 1.6 1998/05/29 20:35:41 curt
|
||||
/* 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
|
||||
* Type-ified fgTIME and fgVIEW
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <Aircraft/aircraft.h>
|
||||
#include <Debug/fg_debug.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Include/fg_zlib.h>
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/views.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
@ -62,10 +63,10 @@
|
|||
|
||||
/* Initialize the Star Management Subsystem */
|
||||
int fgStarsInit( void ) {
|
||||
FILE *fd;
|
||||
fgFile fd;
|
||||
fgOPTIONS *o;
|
||||
/* struct CelestialCoord pltPos; */
|
||||
char path[1024];
|
||||
char path[256], gzpath[256];
|
||||
char line[256], name[256];
|
||||
char *front, *end;
|
||||
double right_ascension, declination, magnitude;
|
||||
|
@ -81,7 +82,7 @@ int fgStarsInit( void ) {
|
|||
path[0] = '\0';
|
||||
strcat(path, o->fg_root);
|
||||
strcat(path, "/Scenery/");
|
||||
strcat(path, "Stars.dat");
|
||||
strcat(path, "Stars");
|
||||
|
||||
max_stars = FG_MAX_STARS;
|
||||
|
||||
|
@ -89,10 +90,14 @@ int fgStarsInit( void ) {
|
|||
fgPrintf( FG_ASTRO, FG_INFO,
|
||||
" Loading %d Stars: %s\n", max_stars, path);
|
||||
|
||||
if ( (fd = fopen(path, "r")) == NULL ) {
|
||||
fgPrintf( FG_ASTRO, FG_ALERT,
|
||||
"Cannot open star file: '%s'\n", path);
|
||||
return 0; // Oops, lets not even try to continue. This is critical.
|
||||
if ( (fd = fgopen(path, "rb")) == NULL ) {
|
||||
strcpy(gzpath, path);
|
||||
strcat(gzpath, ".gz");
|
||||
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);
|
||||
|
@ -101,7 +106,7 @@ int fgStarsInit( void ) {
|
|||
|
||||
/* read in each line of the file */
|
||||
count = 0;
|
||||
while ( (fgets(line, 256, fd) != NULL) && (count < max_stars) ) {
|
||||
while ( (fggets(fd, line, 256) != NULL) && (count < max_stars) ) {
|
||||
front = line;
|
||||
|
||||
/* printf(" Read line = %s", front); */
|
||||
|
@ -171,7 +176,7 @@ int fgStarsInit( void ) {
|
|||
|
||||
} /* while */
|
||||
|
||||
fclose(fd);
|
||||
fgclose(fd);
|
||||
|
||||
xglEnd();
|
||||
|
||||
|
@ -260,9 +265,12 @@ void fgStarsRender( void ) {
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.6 1998/05/13 18:25:35 curt
|
||||
/* Root path info moved to fgOPTIONS.
|
||||
/* Revision 1.7 1998/05/29 20:35:42 curt
|
||||
/* 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
|
||||
* Type-ified fgTIME and fgVIEW
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue