#include <Debug/fg_debug.h>
#include <Include/fg_constants.h>
+#include <Include/fg_zlib.h>
#include <Main/options.hxx>
#include <Time/fg_time.hxx>
struct OrbElements pltOrbElements[9];
+static fgFile data;
+
double fgCalcActTime(fgTIME t)
{
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,
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");
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;
+ }
+ }
+
+ /* 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);
}
- return ret_val;
+
+ fgclose(data);
+
+ return ( 1 );
}
/* $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
*
#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>
/* 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;
path[0] = '\0';
strcat(path, o->fg_root);
strcat(path, "/Scenery/");
- strcat(path, "Stars.dat");
+ strcat(path, "Stars");
max_stars = FG_MAX_STARS;
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);
/* 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); */
} /* while */
- fclose(fd);
+ fgclose(fd);
xglEnd();
/* $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
*