kopia lustrzana https://gitlab.com/Zwarf/picplanner
Added calculation for position of sun, Added timezone support, updated multiple calculations
rodzic
99c6fe8759
commit
e432135285
|
@ -33,14 +33,22 @@ int times_to_zone (int day_utc, int hour_utc, int day_local, int hour_local){
|
|||
}
|
||||
|
||||
void utc_zone_to_time (int *time_utc, int *time_local){
|
||||
int sign = *(time_utc+6)/abs(*(time_utc+6));
|
||||
*(time_local+3) = *(time_utc+3)+*(time_utc+6);
|
||||
int sign = *(time_utc+5)/abs(*(time_utc+5));
|
||||
|
||||
*time_local=*time_utc;
|
||||
*(time_local+1)=*(time_utc+1);
|
||||
*(time_local+2)=*(time_utc+2);
|
||||
*(time_local+3)=*(time_utc+3);
|
||||
*(time_local+4)=*(time_utc+4);
|
||||
*(time_local+5)=*(time_utc+5);
|
||||
|
||||
*(time_local+3) = *(time_utc+3)+*(time_utc+5);
|
||||
if (*(time_local+3)>24 || *(time_local+3) < 0){ /* Test if hours are still inside the same day */
|
||||
*(time_local+3) = *(time_local+3)%24;
|
||||
*(time_local+2) = *(time_utc+2)+sign;
|
||||
|
||||
if (*(time_local+2) > max_day_in_month (*(time_utc+1), *(time_utc)) || *(time_local+2) < 1){ /* Test if days are still inside the same month */
|
||||
*(time_local+2) = (*(time_local+2)-1)%max_day_in_month (*(time_utc+1)+sign, *(time_utc))+1;
|
||||
*(time_local+2) = (*(time_local+2)-1)%max_day_in_month (*(time_utc+1)+sign, *(time_utc))+1; /* -1 and +1 necessary due to mod calculations */
|
||||
*(time_local+1) = *(time_utc+1)+sign;
|
||||
|
||||
if (*(time_local+1) > 12 || *(time_local+1) < 1){ /* Test if months are still inside the same year */
|
||||
|
@ -51,6 +59,34 @@ void utc_zone_to_time (int *time_utc, int *time_local){
|
|||
}
|
||||
}
|
||||
|
||||
void time_to_utc (int *time_local, int *time_utc){
|
||||
calc_time_utc (time_utc);
|
||||
int sign = *(time_utc+5)/abs(*(time_utc+5));
|
||||
|
||||
*time_utc=*time_local;
|
||||
*(time_utc+1)=*(time_local+1);
|
||||
*(time_utc+2)=*(time_local+2);
|
||||
*(time_utc+3)=*(time_local+3);
|
||||
*(time_utc+4)=*(time_local+4);
|
||||
*(time_local+5)=*(time_utc+5);
|
||||
|
||||
*(time_utc+3) = *(time_local+3)-*(time_utc+5);
|
||||
if (*(time_utc+3) > 24 || *(time_utc+3) < 0){
|
||||
*(time_utc+3) = *(time_utc+3)%24;
|
||||
*(time_utc+2) = *(time_utc+2)+sign;
|
||||
|
||||
if (*(time_utc+2) > max_day_in_month (*(time_local+1), *(time_local)) || *(time_utc+2) < 1){
|
||||
*(time_utc+2) = (*(time_utc+2)-1)%max_day_in_month (*(time_local+1)+sign, *(time_local))+1;
|
||||
*(time_utc+1) = *(time_local+1)+sign;
|
||||
|
||||
if (*(time_utc+1) > 12 || *(time_utc+1) < 1){
|
||||
*(time_utc+1) = (*(time_local+1)-1)%12+1;
|
||||
*(time_utc) = *(time_local)+sign;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max_day_in_month (int month, int year){
|
||||
int max_days = 30;
|
||||
/* check which month is set */
|
||||
|
@ -88,16 +124,14 @@ void calc_time_utc (int *time_utc)
|
|||
|
||||
int time_zone = times_to_zone (tmp->tm_mday, tmp->tm_hour, tmp_local.tm_mday, tmp_local.tm_hour);
|
||||
|
||||
g_print ("UTC: %02d:%02d:%02d - %d.%d.%d, Time zone: %d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_mday, tmp->tm_mon+1, tmp->tm_year+1900, time_zone);
|
||||
g_print ("UTC: %02d:%02d - %d.%d.%d, Time zone: %d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_mday, tmp->tm_mon+1, tmp->tm_year+1900, time_zone);
|
||||
|
||||
*(time_utc) = tmp->tm_year+1900;
|
||||
*(time_utc+1) = tmp->tm_mon+1;
|
||||
*(time_utc+2) = tmp->tm_mday;
|
||||
*(time_utc+3) = tmp->tm_hour;
|
||||
*(time_utc+4) = tmp->tm_min;
|
||||
*(time_utc+5) = tmp->tm_sec;
|
||||
*(time_utc+6) = time_zone;
|
||||
g_print ("Time calculated");
|
||||
*(time_utc+5) = time_zone;
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,13 +143,10 @@ void calc_jd (int *time_utc, double *time_jd)
|
|||
double day = *(time_utc+2);
|
||||
float hour = *(time_utc+3);
|
||||
float min = *(time_utc+4);
|
||||
float sec = *(time_utc+5);
|
||||
|
||||
g_print ("Seconds: %f, Minute: %f, Hour: %f, Day: %f, Month: %f, Year: %f\n",sec,min,hour,day,month,year);
|
||||
g_print ("Minute: %f, Hour: %f, Day: %f, Month: %f, Year: %f\n",min,hour,day,month,year);
|
||||
/* calculate a float type day number which is direct proportional to the time went by */
|
||||
day += (hour + (min + sec/60.)/60.)/24.;
|
||||
|
||||
g_print ("Day: %f, Month: %f, Year:%f\n",day,month,year);
|
||||
day += (hour + min/60.)/24.;
|
||||
|
||||
if (month<=2){
|
||||
year --;
|
||||
|
@ -164,6 +195,7 @@ void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time)
|
|||
float hours_passed;
|
||||
double jd_sidereal;
|
||||
|
||||
/* Julian date at 0 UT at the current date */
|
||||
if (*time_jd - (int)*time_jd >= 0.5){
|
||||
jd_sidereal = (int)(*time_jd) + 0.5;
|
||||
}
|
||||
|
@ -172,13 +204,20 @@ void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time)
|
|||
}
|
||||
|
||||
hours_passed = 24*(*time_jd-jd_sidereal);
|
||||
g_print("hours_passed %f\n", hours_passed);
|
||||
double T = (*time_jd - 2451545)/36525;
|
||||
|
||||
/* This formular calculatest the amount of 100 years since the fundamental epoche J2000 (1.1.2000)
|
||||
* This formular is NOT allowed to get julian days which end on .5 (00:00), because the formular below only considers the rotation around the sun NOT its' own prcession.
|
||||
* So we only want to know in which "direktion" we look every day at 00:00 in Greenwich in comparison to the "fixed" stars. */
|
||||
|
||||
*sidereal_time = 100.46061837 + T*(36000.770053608 + T*(0.000387933 - T/38710000)) + longitude + hours_passed*1.00273790935*15;
|
||||
*sidereal_time = 100.46061837 + T*(36000.770053608 + T*(0.000387933 - T/38710000.0)) + longitude + hours_passed*1.00273790935*15;
|
||||
while (*sidereal_time>360){
|
||||
*sidereal_time -= 360;
|
||||
}
|
||||
|
||||
g_print("sidereal_time %f\n", *sidereal_time);
|
||||
|
||||
|
||||
/* This formula for the sidereal time is not that easy to explain and strongly based on numerical calculations which do not allow analytical arguments.
|
||||
* For further details I recommend reading the reports of the International Atronomical Union (IAU) and the publications from P. K. Seidelmann from 1981.
|
||||
|
@ -201,22 +240,66 @@ void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time)
|
|||
* It has to be multiplied by 15 to receive an angle (360/24=15).*/
|
||||
}
|
||||
|
||||
void calc_coordinates_sun(double *time_jd, float *coordinates_sun){
|
||||
double jd;
|
||||
int day_in_year;
|
||||
float right_ascension;
|
||||
float declination;
|
||||
|
||||
jd = *time_jd - 2451545;
|
||||
while (jd > 365){
|
||||
jd -= 365.25; /* TODO: TO SIMPLIFIED! */
|
||||
}
|
||||
day_in_year = jd+1;
|
||||
g_print("Day in Year: %d\n", day_in_year);
|
||||
|
||||
right_ascension = 360.0/365.24*(day_in_year-81);
|
||||
/* declination = 23.44*sin(calc_deg_rad (right_ascension)); */
|
||||
declination = calc_rad_deg (asin(sin(calc_deg_rad(-23.44))*cos(calc_deg_rad(360.0/365.24*(day_in_year+10)+360/M_PI*0.0167*sin(calc_deg_rad (360.0/365.24*(day_in_year-2)))))));
|
||||
g_print("Sun; Right Ascension: %f, Declination: %f\n", right_ascension, declination);
|
||||
|
||||
*coordinates_sun = right_ascension;
|
||||
*(coordinates_sun+1) = declination;
|
||||
}
|
||||
|
||||
/* Convert between the rotation coordinate system and the horizontal coordinate system */
|
||||
void calc_convert_rotation_horizontal(float right_ascension, float declination, float latitude, float longitude, double time_sidereal, float *coordinates)
|
||||
void calc_convert_rotation_horizontal(float right_ascension, float declination, float latitude, double time_sidereal, float *coordinates)
|
||||
{
|
||||
|
||||
latitude = calc_deg_rad (latitude);
|
||||
right_ascension = calc_deg_rad (right_ascension);
|
||||
declination = calc_deg_rad(declination);
|
||||
time_sidereal = calc_deg_rad (time_sidereal);
|
||||
|
||||
float azimuth = atan( sin(time_sidereal-right_ascension) / ( sin(latitude)*cos(time_sidereal-right_ascension) - cos(latitude)*tan(declination) ) );
|
||||
float elevation = asin( sin(latitude)*sin(declination) + cos(latitude)*cos(declination)*cos(time_sidereal-right_ascension) );
|
||||
float azimuth, elevation;
|
||||
float x = -cos(latitude)*sin(declination)+sin(latitude)*cos(declination)*cos(time_sidereal-right_ascension);
|
||||
float y = cos(declination)*sin(time_sidereal-right_ascension);
|
||||
|
||||
if (x < 0 && y <= 0){
|
||||
azimuth = atan(y/x);
|
||||
}
|
||||
else if (x < 0 && y > 0){
|
||||
azimuth = atan(y/x)+2*M_PI;
|
||||
}
|
||||
else if (x > 0){
|
||||
azimuth = atan(y/x)+M_PI;
|
||||
}
|
||||
else if (x == 0 && y < 0){
|
||||
azimuth = M_PI/2;
|
||||
}
|
||||
else if (x == 0 && y > 0){
|
||||
azimuth = -3*M_PI/2;
|
||||
}
|
||||
else{
|
||||
azimuth = 0;
|
||||
g_print("Error calculating azimuth!");
|
||||
}
|
||||
|
||||
elevation = asin( sin(latitude)*sin(declination) + cos(latitude)*cos(declination)*cos(time_sidereal-right_ascension) );
|
||||
|
||||
/* TODO
|
||||
* explanation missing!! */
|
||||
|
||||
* explanation missing!!
|
||||
* */
|
||||
g_print("Latitude %f, RA %f, dec %f, time_sidereal %f, azimuth %f, elevation %f\n", latitude, right_ascension, declination, time_sidereal, azimuth, elevation);
|
||||
|
||||
azimuth = calc_rad_deg (azimuth);
|
||||
elevation = calc_rad_deg (elevation);
|
||||
|
|
|
@ -8,6 +8,8 @@ float calc_rad_deg (float rad);
|
|||
|
||||
int times_to_zone (int day_utc, int hour_utc, int day_local, int hour_local);
|
||||
|
||||
void time_to_utc (int *time_local, int *time_utc);
|
||||
|
||||
void utc_zone_to_time (int *time_utc, int *time_local);
|
||||
|
||||
int max_day_in_month (int month, int year);
|
||||
|
@ -18,6 +20,8 @@ void calc_jd (int *time_utc, double *time_jd);
|
|||
|
||||
void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time);
|
||||
|
||||
void calc_convert_rotation_horizontal(float right_ascension, float declination, float latitude, float longitude, double time_sidereal, float *coordinates);
|
||||
void calc_coordinates_sun(double *time_jd, float *coordinates_sun);
|
||||
|
||||
void calc_convert_rotation_horizontal(float right_ascension, float declination, float latitude, double time_sidereal, float *coordinates);
|
||||
|
||||
|
||||
|
|
|
@ -6,19 +6,32 @@ float hand_milky_way(float latitude, float longitude, int *time_utc){
|
|||
double sidereal_time;
|
||||
float coordinates;
|
||||
|
||||
static float ra_milky_way = 266.5;
|
||||
float d_milky_way = -29.00;
|
||||
float ra_milky_way = 266.417;
|
||||
float d_milky_way = -29.008;
|
||||
g_print("Handler Milky Way\n");
|
||||
|
||||
ra_milky_way = 7;
|
||||
|
||||
/* translate time to JD */
|
||||
calc_jd(time_utc, &time_jd);
|
||||
/* calculate siderial time */
|
||||
calc_sidereal_time(longitude, &time_jd, &sidereal_time);
|
||||
|
||||
g_print("Longitude %f, time_jd %f, sidereal_time %f\n", longitude, time_jd, sidereal_time);
|
||||
/* transfer rotating coordniate system to fixed coordniate system */
|
||||
calc_convert_rotation_horizontal(ra_milky_way, d_milky_way, latitude, longitude, sidereal_time, &coordinates);
|
||||
calc_convert_rotation_horizontal(ra_milky_way, d_milky_way, latitude, sidereal_time, &coordinates);
|
||||
|
||||
/* hand back both coordinates */
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
float hand_sun(float latitude, float longitude, int *time_utc){
|
||||
|
||||
double time_jd;
|
||||
double sidereal_time;
|
||||
float coordinates_sun;
|
||||
float coordinates_sun_horizontal;
|
||||
calc_jd (time_utc, &time_jd);
|
||||
calc_coordinates_sun (&time_jd, &coordinates_sun);
|
||||
calc_sidereal_time(longitude, &time_jd, &sidereal_time);
|
||||
calc_convert_rotation_horizontal (*(&coordinates_sun), *(&coordinates_sun+1), latitude, sidereal_time, &coordinates_sun_horizontal);
|
||||
return coordinates_sun_horizontal;
|
||||
}
|
||||
|
|
|
@ -2,3 +2,5 @@
|
|||
#include <calculations.h>
|
||||
|
||||
float hand_milky_way(float latitude, float longitude, int *time_utc);
|
||||
|
||||
float hand_sun(float latitude, float longitude, int *time_utc);
|
||||
|
|
41
src/main.c
41
src/main.c
|
@ -125,19 +125,27 @@ static int correct_time (GtkWidget *widget, gpointer data){
|
|||
|
||||
static int set_time_now (GtkWidget *widget, gpointer data){
|
||||
g_print("Now\n");
|
||||
int time_utc_now[7];
|
||||
int time_utc_now[6];
|
||||
int time_local[6];
|
||||
calc_time_utc (time_utc_now);
|
||||
gtk_spin_button_set_value (entry_year, time_utc_now[0]);
|
||||
gtk_combo_box_set_active (entry_month, time_utc_now[1]-1);
|
||||
gtk_spin_button_set_value (entry_day, time_utc_now[2]);
|
||||
gtk_spin_button_set_value (entry_hour, time_utc_now[3]);
|
||||
gtk_spin_button_set_value (entry_min, time_utc_now[4]);
|
||||
utc_zone_to_time (time_utc_now, time_local);
|
||||
gtk_spin_button_set_value (entry_year, *(time_local));
|
||||
gtk_combo_box_set_active (entry_month, *(time_local+1)-1);
|
||||
gtk_spin_button_set_value (entry_day, *(time_local+2));
|
||||
gtk_spin_button_set_value (entry_hour, *(time_local+3));
|
||||
gtk_spin_button_set_value (entry_min, *(time_local+4));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Button calculate */
|
||||
static int calculate (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
int hour;
|
||||
int min;
|
||||
|
||||
const char *north_entry_string;
|
||||
const char *east_entry_string;
|
||||
|
||||
|
@ -154,9 +162,24 @@ static int calculate (GtkWidget *widget, gpointer data)
|
|||
float longitude = atof(east_entry_string);
|
||||
g_print("Calculation ongoing\n");
|
||||
|
||||
int time_utc_now[7];
|
||||
calc_time_utc (time_utc_now);
|
||||
hand_milky_way (latitude, longitude, time_utc_now);
|
||||
year = gtk_spin_button_get_value_as_int (entry_year);
|
||||
month = gtk_combo_box_get_active (entry_month)+1;
|
||||
day = gtk_spin_button_get_value_as_int (entry_day);
|
||||
hour = gtk_spin_button_get_value_as_int (entry_hour);
|
||||
min = gtk_spin_button_get_value_as_int (entry_min);
|
||||
|
||||
int time_local[6];
|
||||
int time_utc[6];
|
||||
|
||||
*(time_local) = year;
|
||||
*(time_local+1) = month;
|
||||
*(time_local+2) = day;
|
||||
*(time_local+3) = hour;
|
||||
*(time_local+4) = min;
|
||||
|
||||
time_to_utc (time_local, time_utc);
|
||||
hand_milky_way (latitude, longitude, time_utc);
|
||||
hand_sun (latitude, longitude, time_utc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,9 @@ struct Output *search_nominatim (const gchar *searchtext){
|
|||
json_object_object_get_ex(jsonProperties, "display_name", &jsonDisplayName);
|
||||
(*output).displayText = json_object_get_string(jsonDisplayName);
|
||||
|
||||
g_print("Display Text: %s, North: %f, East: %f\n",(*output).displayText, (*output).east, (*output).north);
|
||||
/*
|
||||
* g_print("Display Text: %s, North: %f, East: %f\n",(*output).displayText, (*output).east, (*output).north);
|
||||
*/
|
||||
return output;
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
|
|
Ładowanie…
Reference in New Issue