X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=Astro%2Forbits.c;h=fe5208c4a9c6e8dd2117cb10fc9414fe3feb009b;hb=20cf326fec07113e0702a7367a162febf0fade88;hp=6c82f79a42ca2919dfa55e13ebb6720229bb0a83;hpb=f1f01451cc3fa0d0b881939878baf0f14a8b486a;p=simgear.git diff --git a/Astro/orbits.c b/Astro/orbits.c index 6c82f79a..fe5208c4 100644 --- a/Astro/orbits.c +++ b/Astro/orbits.c @@ -36,48 +36,12 @@ 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, remember 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; -//} - - double fgCalcActTime(struct fgTIME t) { return (t.mjd - 36523.5); } -/* convert degrees to radians */ -/* -double fgDegToRad(double angle) -{ - return (angle * PIOVER180); -} -*/ double fgCalcEccAnom(double M, double e) { double @@ -101,14 +65,26 @@ double fgCalcEccAnom(double M, double e) } +/* 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++) { @@ -119,49 +95,55 @@ void fgReadOrbElements(struct OrbElements *dest, FILE *src) } 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; + struct fgGENERAL *g; + char path[80]; + int i; + FILE *data; + int ret_val = 0; - fgPrintf( FG_ASTRO, FG_INFO, "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 ) - { - fgPrintf( FG_ASTRO, FG_ALERT, - "Cannot open data file: '%s'\n", path); - return; - } - /* 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 ... */ - 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; } @@ -173,22 +155,31 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) actTime = fgCalcActTime(t); /* calculate the actual orbital elements */ - planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime)); // angle in radians - planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime)); // angle in radians - planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime)); // angle in radians - planet->i = DEG_TO_RAD * (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.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.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 + * + * + * 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 *