In Calendar_Date_to_JD and JD_to_Calendar_Date changed float params to double. Refs: #201

This commit is contained in:
John M. Penn 2016-03-14 13:15:04 -05:00
parent 26dfb3a000
commit 793530250e
6 changed files with 68 additions and 62 deletions

View File

@ -12,11 +12,11 @@ REALTIME = True
if REALTIME:
execfile("Modified_data/realtime.py")
JAPANESE = True
JAPANESE = False
if JAPANESE:
execfile("Modified_data/Japanese_labels_alt.py")
STRIPCHART = True
STRIPCHART = False
if STRIPCHART:
trickView = trick.TrickView()
trickView.set_auto_open_file("sun.tv")
@ -60,10 +60,10 @@ sun_predictor.sun.observer_offset_from_UTC = -6
""" Set local time here. """
""" ======================================== """
sun_predictor.sun.local_time.year = 2016
sun_predictor.sun.local_time.month = 2
sun_predictor.sun.local_time.day = 26
sun_predictor.sun.local_time.hour = 16
sun_predictor.sun.local_time.min = 0
sun_predictor.sun.local_time.month = 3
sun_predictor.sun.local_time.day = 11
sun_predictor.sun.local_time.hour = 17
sun_predictor.sun.local_time.min = 10
sun_predictor.sun.local_time.sec = 0.0
trick.stop(86400.0)

View File

@ -37,8 +37,8 @@ int is_julian_date (int Y, int M, double D);
* @param D (IN) Day
* @param JD (OUT) Julian date
*/
int Calendar_Date_to_JD (int Y, int M, float D, double * JD);
void JD_to_Calendar_Date (double JD, int *year, int *month, float *day) ;
int Calendar_Date_to_JD (int Y, int M, double D, double * JD);
void JD_to_Calendar_Date (double JD, int *year, int *month, double *day) ;
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*******************************************************************
* @\file JD.c
/*******************************************************************
* @\file JD.c
* @\brief This is the JD.c file
* Reference(s):
* (1) Meeus,Jean."Astronomical Algorithms",
@ -10,28 +10,38 @@
#include <stdio.h>
#include <math.h>
#include "JD.h"
#include "JD.h"
int is_gregorian_date (int Y, int M, double D) {
return ((Y>1582)||((Y==1582)&&(M>10))||((Y==1582)&&(M==10)&&(D>=15.0)));
return ((Y>1582)||((Y==1582)&&(M>10))||((Y==1582)&&(M==10)&&(D>=15.0)));
}
int is_julian_date (int Y, int M, double D) {
return ((Y<1582)||((Y==1582)&&(M<10))||((Y==1582)&&(M==10)&&(D<5.0)));
return ((Y<1582)||((Y==1582)&&(M<10))||((Y==1582)&&(M==10)&&(D<5.0)));
}
/* The algorithm for this function is described on page 60 of ref(1). */
int Calendar_Date_to_JD (int Y, int M, float D, double * JD) {
int Calendar_Date_to_JD (int Y, int M, double D, double * JD) {
int A, B;
/* Is the day valid? */
if ((D < 1.0) || (M >= 32.0)) return -1;
if ((D < 1.0) || (M >= 32.0)) {
printf("%s: Day Invalid.", __FUNCTION__);
return -1;
}
/* Is the month valid? */
if ((M < 1) || (M > 12)) return -1;
if ((M < 1) || (M > 12)) {
printf("%s: Month Invalid.", __FUNCTION__);
return -1;
}
/* Is the year valid? */
if ((Y < -4712) || ((Y == -4712) && (D < 1.5))) return -1;
if ((Y < -4712) || ((Y == -4712) && (D < 1.5))) {
printf("%s: Year Invalid.", __FUNCTION__);
return -1;
}
if (M <= 2) {
Y = Y - 1;
@ -45,21 +55,21 @@ int Calendar_Date_to_JD (int Y, int M, float D, double * JD) {
} else if (is_julian_date (Y,M,D)) {
B = 0;
} else {
return -1;
return -1;
}
*JD = (int)(365.25 * (Y + 4716)) + (int)(30.6001 * (M+1)) + D + B - 1524.5;
*JD = (int)(365.25 * (Y + 4716)) + (int)(30.6001 * (M+1)) + D + B - 1524.5;
return 0;
}
/* The algorithm for this function is described on page 63 of ref(1). */
void JD_to_Calendar_Date (double JD, int *Year, int *Month, float *Day) {
void JD_to_Calendar_Date (double JD, int *Year, int *Month, double *Day) {
int Z,A,B,C,D,E;
int alpha, year, month;
float day;
float F;
double day;
double F;
Z = (int)(JD + 0.5);
F = (JD + 0.5) - Z;

View File

@ -18,11 +18,10 @@ PROGRAMMERS:
#define MINUTES_PER_DAY 1440.0
#define SECONDS_PER_DAY 86400.0
int sun_pred_cyclic(
SUN_PRED* S,
double current_sim_time )
{
float dday;
int sun_pred_cyclic( SUN_PRED* S,
double current_sim_time ) {
double dday;
double JDL;
double tsec;

View File

@ -6,19 +6,16 @@ PROGRAMMERS:
*******************************************************************************/
#include "sun_pred.h"
int sun_pred_default_data(
SUN_PRED* S )
{
int sun_pred_default_data( SUN_PRED* S ) {
/* (helios/include/sun_pred.d) */
S->observer_latitude = 29.55298;
S->observer_longitude = 95.09379;
S->observer_offset_from_UTC = -6;
S->local_time.year = 2006;
S->local_time.month = 8;
S->local_time.day = 8;
S->local_time.hour = 12;
S->local_time.min = 0;
S->local_time.year = 2016;
S->local_time.month = 3;
S->local_time.day = 11;
S->local_time.hour = 13;
S->local_time.min = 25;
S->local_time.sec = 0.0;
/* Wide characters must use the prefix L when defined in quotes. */
S->label_UTC = L"UTC" ;

View File

@ -13,34 +13,34 @@ PROGRAMMERS:
#define MINUTES_PER_DAY 1440.0
#define SECONDS_PER_DAY 86400.0
int sun_pred_init(
SUN_PRED* S )
{
float dday;
double JDL;
double tsec;
int sun_pred_init( SUN_PRED* S ) {
/* Convert the local time to JD */
dday = S->local_time.day +
( S->local_time.hour / HOURS_PER_DAY ) +
( S->local_time.min / MINUTES_PER_DAY ) +
( S->local_time.sec / SECONDS_PER_DAY ) ;
double dday;
double JDL;
double tsec;
Calendar_Date_to_JD (S->local_time.year, S->local_time.month, dday, &JDL);
/* Subtract the local offset from UTC from the JD. */
S->JD_start = JDL - ( S->observer_offset_from_UTC / HOURS_PER_DAY ) ;
S->JD = S->JD_start;
/* Convert the local time to JD */
dday = S->local_time.day +
( S->local_time.hour / HOURS_PER_DAY ) +
( S->local_time.min / MINUTES_PER_DAY ) +
( S->local_time.sec / SECONDS_PER_DAY ) ;
/* Convert the new JD back to UTC Calendar date */
JD_to_Calendar_Date (S->JD, &S->utc.year, &S->utc.month, &dday );
Calendar_Date_to_JD (S->local_time.year, S->local_time.month, dday, &JDL);
S->utc.day = (int)dday;
tsec = (dday - S->utc.day ) * SECONDS_PER_DAY + 0.5;
S->utc.hour = (int)( tsec / 3600.0 ); tsec = tsec - ( S->utc.hour * 3600.0 );
S->utc.min = (int)( tsec / 60.0 ); tsec = tsec - ( S->utc.min * 60.0 );
S->utc.sec = (int)( tsec );
/* Subtract the local offset from UTC from the JD. */
return 0 ;
S->JD_start = JDL - ( S->observer_offset_from_UTC / HOURS_PER_DAY ) ;
S->JD = S->JD_start;
/* Convert the new JD back to UTC Calendar date */
JD_to_Calendar_Date (S->JD, &S->utc.year, &S->utc.month, &dday );
S->utc.day = (int)dday;
tsec = (dday - S->utc.day ) * SECONDS_PER_DAY + 0.5;
S->utc.hour = (int)( tsec / 3600.0 ); tsec = tsec - ( S->utc.hour * 3600.0 );
S->utc.min = (int)( tsec / 60.0 ); tsec = tsec - ( S->utc.min * 60.0 );
S->utc.sec = (int)( tsec );
return 0 ;
}