From 45d02e3e689fa2374eb54db9524bbc01de7d7260 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 13 Sep 1997 01:59:45 +0000 Subject: [PATCH] Mostly working on stars and generating sidereal time for accurate star placement. --- Aircraft/aircraft.c | 14 ++-- Aircraft/aircraft.h | 10 ++- Main/GLUTmain.c | 19 ++++-- Simulator/constants.h | 15 ++++- Time/depend | 2 + Time/fg_time.c | 144 +++++++++++++++++++++++++++++++++++++++++- Time/fg_time.h | 26 ++++++-- Time/sunpos.c | 10 ++- 8 files changed, 217 insertions(+), 23 deletions(-) diff --git a/Aircraft/aircraft.c b/Aircraft/aircraft.c index 4aa51e0b4..cb8f27e78 100644 --- a/Aircraft/aircraft.c +++ b/Aircraft/aircraft.c @@ -31,12 +31,12 @@ /* Display various parameters to stdout */ -void aircraft_debug(int type) { +void fgAircraftOutputCurrent(struct AIRCRAFT *a) { struct FLIGHT *f; struct CONTROLS *c; - f = ¤t_aircraft.flight; - c = ¤t_aircraft.controls; + f = &a->flight; + c = &a->controls; printf("Pos = (%.2f,%.2f,%.2f) (Phi,Theta,Psi)=(%.2f,%.2f,%.2f)\n", FG_Longitude * 3600.0 * RAD_TO_DEG, @@ -48,9 +48,13 @@ void aircraft_debug(int type) { /* $Log$ -/* Revision 1.10 1997/08/27 03:29:56 curt -/* Changed naming scheme of basic shared structures. +/* Revision 1.11 1997/09/13 02:00:05 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.10 1997/08/27 03:29:56 curt + * Changed naming scheme of basic shared structures. + * * Revision 1.9 1997/07/19 22:39:08 curt * Moved PI to ../constants.h * diff --git a/Aircraft/aircraft.h b/Aircraft/aircraft.h index 1f1f78819..459483d5c 100644 --- a/Aircraft/aircraft.h +++ b/Aircraft/aircraft.h @@ -44,16 +44,20 @@ extern struct AIRCRAFT current_aircraft; /* Display various parameters to stdout */ -void aircraft_debug(int type); +void fgAircraftOutputCurrent(struct AIRCRAFT *a); #endif /* AIRCRAFT_H */ /* $Log$ -/* Revision 1.5 1997/08/27 03:29:58 curt -/* Changed naming scheme of basic shared structures. +/* Revision 1.6 1997/09/13 02:00:06 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.5 1997/08/27 03:29:58 curt + * Changed naming scheme of basic shared structures. + * * Revision 1.4 1997/07/23 21:52:17 curt * Put comments around the text after an #endif for increased portability. * diff --git a/Main/GLUTmain.c b/Main/GLUTmain.c index 45c2671e0..01271d9f1 100644 --- a/Main/GLUTmain.c +++ b/Main/GLUTmain.c @@ -396,9 +396,16 @@ static void fgMainLoop( void ) { double cur_elev; double joy_x, joy_y; int joy_b1, joy_b2; + struct AIRCRAFT *a; struct FLIGHT *f; + struct fgTIME *t; - f = ¤t_aircraft.flight; + a = ¤t_aircraft; + f = &a->flight; + t = &cur_time_params; + + /* update "time" */ + fgTimeUpdate(f, t); /* Read joystick */ /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 ); @@ -447,7 +454,7 @@ static void fgMainLoop( void ) { FG_Altitude * FEET_TO_METER); } - aircraft_debug(1); + fgAircraftOutputCurrent(a); /* redraw display */ fgUpdateVisuals(); @@ -555,9 +562,13 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.15 1997/09/05 14:17:27 curt -/* More tweaking with stars. +/* Revision 1.16 1997/09/13 02:00:06 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.15 1997/09/05 14:17:27 curt + * More tweaking with stars. + * * Revision 1.14 1997/09/05 01:35:53 curt * Working on getting stars right. * diff --git a/Simulator/constants.h b/Simulator/constants.h index 625217378..9604c07e2 100644 --- a/Simulator/constants.h +++ b/Simulator/constants.h @@ -80,6 +80,13 @@ #define INVG 0.031080997 +/* Time Related Parameters */ + +#define MJD0 2415020.0 +#define J2000 (2451545.0 - MJD0) +#define SIDRATE .9972695677 + + /* Conversions */ /* Degrees to Radians */ @@ -115,9 +122,13 @@ /* $Log$ -/* Revision 1.9 1997/08/22 21:34:32 curt -/* Doing a bit of reorganizing and house cleaning. +/* Revision 1.10 1997/09/13 01:59:45 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.9 1997/08/22 21:34:32 curt + * Doing a bit of reorganizing and house cleaning. + * * Revision 1.8 1997/07/31 22:52:22 curt * Working on redoing internal coordinate systems & scenery transformations. * diff --git a/Time/depend b/Time/depend index 66b8d5dd7..2ba06afdd 100644 --- a/Time/depend +++ b/Time/depend @@ -1,5 +1,6 @@ fg_time.o: fg_time.c fg_time.h ../types.h fg_timer.o: fg_timer.c fg_timer.h +sidereal.o: sidereal.c sunpos.o: sunpos.c sunpos.h ../types.h fg_time.h ../constants.h \ ../GLUT/views.h ../GLUT/../types.h ../GLUT/../Flight/flight.h \ ../GLUT/../Flight/Slew/slew.h \ @@ -7,3 +8,4 @@ sunpos.o: sunpos.c sunpos.h ../types.h fg_time.h ../constants.h \ ../GLUT/../Flight/LaRCsim/../flight.h ../GLUT/../Math/mat3.h \ ../Math/fg_geodesy.h ../Math/mat3.h ../Math/polar.h \ ../Math/../types.h +ttest.o: ttest.c diff --git a/Time/fg_time.c b/Time/fg_time.c index 064a75c2c..ea0b5a51f 100644 --- a/Time/fg_time.c +++ b/Time/fg_time.c @@ -24,16 +24,156 @@ **************************************************************************/ +#include +#include +#include +#include + #include "fg_time.h" +#include "../constants.h" +#include "../Flight/flight.h" + + +#define DEGHR(x) ((x)/15.) +#define RADHR(x) DEGHR(x*RAD_TO_DEG) struct fgTIME cur_time_params; +/* given a date in months, mn, days, dy, years, yr, return the + * modified Julian date (number of days elapsed since 1900 jan 0.5), + * mjd. Adapted from Xephem. */ + +double cal_mjd (int mn, double dy, int yr) { + static double last_mjd, last_dy; + double mjd; + static int last_mn, last_yr; + int b, d, m, y; + long c; + + if (mn == last_mn && yr == last_yr && dy == last_dy) { + mjd = last_mjd; + return(mjd); + } + + m = mn; + y = (yr < 0) ? yr + 1 : yr; + if (mn < 3) { + m += 12; + y -= 1; + } + + if (yr < 1582 || (yr == 1582 && (mn < 10 || (mn == 10 && dy < 15)))) { + b = 0; + } else { + int a; + a = y/100; + b = 2 - a + a/4; + } + + if (y < 0) { + c = (long)((365.25*y) - 0.75) - 694025L; + } else { + c = (long)(365.25*y) - 694025L; + } + + d = 30.6001*(m+1); + + mjd = b + c + d + dy - 0.5; + + last_mn = mn; + last_dy = dy; + last_yr = yr; + last_mjd = mjd; + + return(mjd); +} + + +/* given an mjd, return greenwich mean siderial time, gst */ + +double utc_gst (double mjd) { + double gst; + double day = floor(mjd-0.5)+0.5; + double hr = (mjd-day)*24.0; + double T, x; + + T = ((int)(mjd - 0.5) + 0.5 - J2000)/36525.0; + x = 24110.54841 + (8640184.812866 + (0.093104 - 6.2e-6 * T) * T) * T; + x /= 3600.0; + gst = (1.0/SIDRATE)*hr + x; + + return(gst); +} + + +/* given Julian Date and Longitude (decimal degrees West) compute and + * return Local Sidereal Time, in decimal hours. + * + * Provided courtesy of ecdowney@noao.edu (Elwood Downey) + */ + +double sidereal (double mjd, double lng) { + double gst; + double lst; + + printf ("Current Lst on JD %13.5f at %8.4f degrees West: ", + mjd + MJD0, lng); + + /* convert to required internal units */ + lng *= DEG_TO_RAD; + + /* compute LST and print */ + gst = utc_gst (mjd); + lst = gst - RADHR (lng); + lst -= 24.0*floor(lst/24.0); + printf ("%7.4f\n", lst); + + /* that's all */ + return (lst); +} + + +/* Update the time dependent variables */ + +void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) { + /* get current Unix calendar time (in seconds) */ + t->cur_time = time(NULL); + printf("Current Unix calendar time = %ld\n", t->cur_time); + + /* get GMT break down for current time */ + t->gmt = gmtime(&t->cur_time); + printf("Current GMT = %d/%d/%2d %d:%02d:%02d\n", + t->gmt->tm_mon+1, t->gmt->tm_mday, t->gmt->tm_year, + t->gmt->tm_hour, t->gmt->tm_min, t->gmt->tm_sec); + + /* calculate modified Julian date */ + t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday, + (int)(t->gmt->tm_year + 1900)); + + /* add in partial day */ + t->mjd += (t->gmt->tm_hour / 24.0) + (t->gmt->tm_min / (24.0 * 60.0)) + + (t->gmt->tm_sec / (24.0 * 60.0 * 60.0)); + + /* convert "back" to Julian date + partial day (as a fraction of one) */ + t->jd = t->mjd + MJD0; + printf("Current Julian Date = %.5f\n", t->jd); + + /* Calculate local side real time */ + t->lst = sidereal(t->mjd, -(FG_Longitude * RAD_TO_DEG)); + printf("Current Sidereal Time = %.3f\n", t->lst); +} + + /* $Log$ -/* Revision 1.2 1997/08/27 03:30:35 curt -/* Changed naming scheme of basic shared structures. +/* Revision 1.3 1997/09/13 02:00:08 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.2 1997/08/27 03:30:35 curt + * Changed naming scheme of basic shared structures. + * * Revision 1.1 1997/08/13 21:55:59 curt * Initial revision. * diff --git a/Time/fg_time.h b/Time/fg_time.h index 6f028b2eb..df1f10fc4 100644 --- a/Time/fg_time.h +++ b/Time/fg_time.h @@ -33,14 +33,24 @@ #endif #include +#include #include "../types.h" +#include "../Flight/flight.h" /* Define a structure containing global time parameters */ struct fgTIME { - /* the point on the earth's surface above which the sun is directly - * overhead */ + /* the date/time in various forms */ + time_t cur_time; /* Unix "calendar" time in seconds */ + struct tm *gmt; /* Break down of GMT time */ + + double jd; /* Julian date */ + double mjd; /* modified Julian date */ + + double lst; /* local side real time */ + + /* position of the sun in various forms */ double sun_lon, sun_gc_lat; /* in geocentric coordinates */ struct fgCartesianPoint fg_sunpos; /* in cartesian coordiantes */ GLfloat sun_vec[4]; /* in view coordinates */ @@ -51,13 +61,21 @@ struct fgTIME { extern struct fgTIME cur_time_params; +/* Update the time dependent variables */ +void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t); + + #endif /* FG_TIME_H */ /* $Log$ -/* Revision 1.3 1997/09/04 02:17:39 curt -/* Shufflin' stuff. +/* Revision 1.4 1997/09/13 02:00:08 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.3 1997/09/04 02:17:39 curt + * Shufflin' stuff. + * * Revision 1.2 1997/08/27 03:30:36 curt * Changed naming scheme of basic shared structures. * diff --git a/Time/sunpos.c b/Time/sunpos.c index ab0ab1498..1e593bc02 100644 --- a/Time/sunpos.c +++ b/Time/sunpos.c @@ -272,7 +272,7 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) { time_warp += 0; /* increase this to make the world spin real fast */ - fgSunPosition(time(NULL) + time_warp, &t->sun_lon, &sun_gd_lat); + fgSunPosition(t->cur_time + time_warp, &t->sun_lon, &sun_gd_lat); fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &t->sun_gc_lat); @@ -303,9 +303,13 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) { /* $Log$ -/* Revision 1.9 1997/09/05 14:17:31 curt -/* More tweaking with stars. +/* Revision 1.10 1997/09/13 02:00:09 curt +/* Mostly working on stars and generating sidereal time for accurate star +/* placement. /* + * Revision 1.9 1997/09/05 14:17:31 curt + * More tweaking with stars. + * * Revision 1.8 1997/09/05 01:36:04 curt * Working on getting stars right. * -- 2.39.2