**************************************************************************/
+#include <math.h>
#include <string.h>
-#include "orbits.h"
-
-#include "../Include/general.h"
-#include "../Time/fg_time.h"
+#include <Astro/orbits.h>
+#include <Include/fg_constants.h>
+#include <Include/general.h>
+#include <Time/fg_time.h>
+#include <Main/fg_debug.h>
struct OrbElements pltOrbElements[9];
double fgCalcActTime(struct fgTIME t)
{
- double
- actTime, UT;
- int year;
-
- /* a hack. This one introduces the 2000 problem into the program */
- year = t.gmt->tm_year + 1900;
-
- /* calculate the actual time, rember to add 1 to tm_mon! */
- actTime = 367 * year - 7 *
- (year + ((t.gmt->tm_mon+1) + 9) / 12) / 4 + 275 *
- (t.gmt->tm_mon+1) / 9 + t.gmt->tm_mday - 730530;
-
- UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60);
- /*printf("UT = %f\n", UT); */
- actTime += (UT / 24.0);
- #define DEBUG 1
- #ifdef DEBUG
- /* printf(" Actual Time:\n"); */
- /* printf(" current day = %f\t", actTime); */
- /* printf(" GMT = %d, %d, %d, %d, %d, %d\n",
- year, t.gmt->tm_mon, t.gmt->tm_mday,
- t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); */
- #endif
- return actTime;
+ return (t.mjd - 36523.5);
}
-/* convert degrees to radians */
-double fgDegToRad(double angle)
-{
- return (angle * PIOVER180);
-}
double fgCalcEccAnom(double M, double e)
{
do
{
E1 = E0 - (E0 - e * sin(E0) - M) / (1 - e * cos(E0));
- diff = abs(E0 - E1);
+ diff = fabs(E0 - E1);
E0 = E1;
}
- while (diff > fgDegToRad(0.001));
+ while (diff > (DEG_TO_RAD * 0.001));
return E0;
}
return eccAnom;
}
+/* This function assumes that if the FILE ptr is valid that the
+ contents will be valid. Should we check the file for validity? */
+
+/* Sounds like a good idea to me. What type of checks are you thinking
+ of, other than feof(FILE*)? That's currently the only check I can
+ think of (Durk) */
-void fgReadOrbElements(struct OrbElements *dest, FILE *src)
+int fgReadOrbElements(struct OrbElements *dest, FILE *src)
{
char line[256];
int i,j;
j = 0;
do
{
+ if (feof (src)) {
+ 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++)
{
}
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,
- &dest->wFirst, &dest->wSec,
- &dest->aFirst, &dest->aSec,
- &dest->eFirst, &dest->eSec,
- &dest->MFirst, &dest->MSec);
+ &dest->NFirst, &dest->NSec,
+ &dest->iFirst, &dest->iSec,
+ &dest->wFirst, &dest->wSec,
+ &dest->aFirst, &dest->aSec,
+ &dest->eFirst, &dest->eSec,
+ &dest->MFirst, &dest->MSec);
+
+ return(1);
}
-void fgSolarSystemInit(struct fgTIME t)
+int fgSolarSystemInit(struct fgTIME t)
{
- struct fgGENERAL *g;
- char path[80];
- int i;
- FILE *data;
+ fgGENERAL *g;
+ char path[80];
+ int i;
+ FILE *data;
+ int ret_val = 0;
- printf("Initializing solar system\n");
+ fgPrintf( FG_ASTRO, FG_INFO, "Initializing solar system\n");
/* build the full path name to the orbital elements database file */
- g = &general;
- path[0] = '\0';
- strcat(path, g->root_dir);
- strcat(path, "/Scenery/");
- strcat(path, "Planets.dat");
-
- if ( (data = fopen(path, "r")) == NULL )
- {
- printf("Cannot open data file: '%s'\n", path);
- return;
- }
- #ifdef DEBUG
- printf(" reading datafile %s\n", path);
- #endif
-
- /* for all the objects... */
- for (i = 0; i < 9; i ++)
- {
- /* ...read from the data file ... */
- fgReadOrbElements(&pltOrbElements[i], data);
- /* ...and calculate the actual values */
- fgSolarSystemUpdate(&pltOrbElements[i], t);
- }
+ g = &general;
+ path[0] = '\0';
+ strcat(path, g->root_dir);
+ strcat(path, "/Scenery/");
+ strcat(path, "Planets.dat");
+ if ( (data = fopen(path, "r")) == NULL )
+ {
+ fgPrintf( FG_ASTRO, FG_ALERT,
+ "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;
}
actTime = fgCalcActTime(t);
/* calculate the actual orbital elements */
- planet->M = fgDegToRad(planet->MFirst + (planet->MSec * actTime)); // angle in radians
- planet->w = fgDegToRad(planet->wFirst + (planet->wSec * actTime)); // angle in radians
- planet->N = fgDegToRad(planet->NFirst + (planet->NSec * actTime)); // angle in radians
- planet->i = fgDegToRad(planet->iFirst + (planet->iSec * actTime)); // angle in radians
- planet->e = planet->eFirst + (planet->eSec * actTime);
- planet->a = planet->aFirst + (planet->aSec * actTime);
+ planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime));
+ planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime));
+ planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime));
+ planet->i = DEG_TO_RAD * (planet->iFirst + (planet->iSec * actTime));
+ planet->e = planet->eFirst + (planet->eSec * actTime);
+ planet->a = planet->aFirst + (planet->aSec * actTime);
}
/* $Log$
-/* Revision 1.1 1998/01/07 03:16:17 curt
-/* Moved from .../Src/Scenery/ to .../Src/Astro/
+/* Revision 1.9 1998/03/14 00:27:12 curt
+/* Updated fgGENERAL to a "type" of struct.
/*
+ * Revision 1.8 1998/02/23 19:07:55 curt
+ * Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.7 1998/02/12 21:59:33 curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.6 1998/02/03 23:20:11 curt
+ * Lots of little tweaks to fix various consistency problems discovered by
+ * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
+ * passed arguments along to the real printf(). Also incorporated HUD changes
+ * by Michele America.
+ *
+ * Revision 1.5 1998/02/02 20:53:22 curt
+ * To version 0.29
+ *
+ * Revision 1.4 1998/01/27 00:47:47 curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
+ * Revision 1.3 1998/01/22 02:59:27 curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
+ * Revision 1.2 1998/01/19 19:26:58 curt
+ * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
+ * This should simplify things tremendously.
+ *
+ * Revision 1.1 1998/01/07 03:16:17 curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
* Revision 1.6 1997/12/30 20:47:52 curt
* Integrated new event manager with subsystem initializations.
*