commit 38c4d139a517e0160bea78166d4a397fc8ac449a
parent c50e00a8fc570651dcc4b6c77332d1e29e5ffa1d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 29 Oct 2025 17:34:05 +0100
stardis: fix the computation of the sun's position
The position of the sun is calculated based on a location on Earth and a
date in UTC +00:00. The conversion of the path time, given in seconds
elapsed since January 1, 1850 UTC +00:00, to a UTC date was incorrect.
As a result, the computed position of the sun was incorrect.
Diffstat:
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/stardis_smeteo.c b/src/stardis_smeteo.c
@@ -214,8 +214,11 @@ compute_sun_position
ASSERT(bcond && sun);
/* The limit condition stores the number of seconds elapsed since the epoch
- * until January 1, 1850, UTC +00:00 */
- time_since_jan_1_1850_utc0 = (time_t)time; /* [s] */
+ * until January 1, 1850, UTC +00:00 time. Thus, add this offset to the number
+ * of seconds elapsed since January 1, 1850, UTC +00:00 to convert this number
+ * of seconds to UTC+00:00 */
+ time_since_jan_1_1850_utc0 = /* [s] */
+ (time_t)((double)bcond->lib_desc.jan_1_1850 + time);
/* Convert time in number of seconds into a broken-down time as expected by
* the Star-CElestial-Mechanics library */
diff --git a/src/stardis_smeteo_library.c b/src/stardis_smeteo_library.c
@@ -37,6 +37,12 @@ struct stardis_smeteo_lib {
/* Algorithm for computing the solar position */
enum scem_sun_algo algo;
+ /* Number of seconds elapsed since the epoch until January 1, 1850, UTC+00:00
+ * The day_1850 field in the smeteo file can therefore be used to calculate
+ * the number of seconds to add to this member variable in order to convert
+ * the smeteo time to UTC+00:00 */
+ time_t jan_1_1850;
+
ref_T ref;
};
@@ -107,6 +113,32 @@ error:
goto exit;
}
+/* Retrieve the number of seconds elapsed since the epoch until January 1, 1850,
+ * local time */
+static res_T
+setup_utc_reference(struct stardis_smeteo_lib* lib)
+{
+ struct tm date = {0};
+ struct smeteo_desc desc = SMETEO_DESC_NULL;
+ res_T res = RES_OK;
+ ASSERT(lib);
+
+ if((res = smeteo_get_desc(lib->smeteo, &desc)) != RES_OK) return res;
+
+ date.tm_mday = 1;
+ date.tm_mon = 0; /* January */
+ date.tm_year = 1850 - 1900;
+ date.tm_min = 0;
+ date.tm_hour = 0;
+ date.tm_sec = 0;
+ date.tm_isdst = -1; /* Daylight saving time is unknown */
+
+ lib->jan_1_1850 = mktime(&date);
+ if(lib->jan_1_1850 == (time_t)-1) return RES_UNKNOWN_ERR;
+
+ return RES_OK;
+}
+
static res_T
setup_smeteo
(struct stardis_smeteo_lib* lib,
@@ -132,6 +164,8 @@ setup_smeteo
/* Load meteorological data */
if((res = smeteo_load(lib->smeteo, args->filename)) != RES_OK) goto error;
if((res = smeteo_get_desc(lib->smeteo, &desc)) != RES_OK) goto error;
+
+ if((res = setup_utc_reference(lib)) != RES_OK) goto error;
lib->algo = args->algo;
/* Retrieve the maximum convection coefficient from meteorological data */
@@ -245,5 +279,6 @@ stardis_smeteo_lib_get_desc
desc->Tsrf_range[1] = lib->Tsrf_range[1];
desc->Trad_range[0] = lib->Trad_range[0];
desc->Trad_range[1] = lib->Trad_range[1];
+ desc->jan_1_1850 = lib->jan_1_1850;
desc->algo = lib->algo;
}