commit e29f81164ae32c7674874470b0905d5e37972072
parent 9179878168be78ab80fa39bd16532345557ab760
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 10 Oct 2025 16:51:09 +0200
stardis: add a lib argument to define the solar algorithm
This let the choice between the PSA and Meeus algorithms provided by the
star-cem library. Note that using one or the other does not seem to have
any impact on the result. Their impact on performance has not been
measured.
Diffstat:
2 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/src/stardis_smeteo_library.c b/src/stardis_smeteo_library.c
@@ -25,6 +25,7 @@
#include <rsys/str.h>
#include <float.h> /* DBL_MAX */
+#include <unistd.h> /* getopt */
struct stardis_smeteo_lib {
struct smeteo* smeteo;
@@ -49,8 +50,9 @@ struct stardis_smeteo_lib {
struct args {
char* filename;
+ enum scem_sun_algo algo;
};
-#define ARGS_DEFAULT__ {0}
+#define ARGS_DEFAULT__ {NULL, SCEM_SUN_MEEUS}
static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
/*******************************************************************************
@@ -59,19 +61,52 @@ static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
static void
usage(FILE* stream, const char* name)
{
- fprintf(stream, "usage: %s file\n", name);
+ ASSERT(stream && name);
+ fprintf(stream, "usage: %s [-a sun_algo] file\n", name);
+}
+
+static res_T
+parse_algo(const char* str, enum scem_sun_algo* algo)
+{
+ ASSERT(str && algo);
+
+ if(!strcmp(str, "meeus")) {
+ *algo = SCEM_SUN_MEEUS;
+ } else if(!strcmp(str, "psa")) {
+ *algo = SCEM_SUN_PSA;
+ } else {
+ return RES_BAD_ARG;
+ }
+ return RES_OK;
}
static res_T
args_init(struct args* args, int argc, char* argv[])
{
+ int opt = 0;
res_T res = RES_OK;
ASSERT(args && argc >= 1 && argv);
*args = ARGS_DEFAULT;
- if(argc == 1) { res = RES_BAD_ARG; goto error; }
- args->filename = argv[1];
+ optind = 1;
+ while((opt=getopt(argc, argv, "a:")) != -1) {
+ switch(opt) {
+ case 'a':
+ res = parse_algo(optarg, &args->algo);
+ break;
+ default: res = RES_BAD_ARG; break;
+ }
+ if(res != RES_OK) {
+ if(optarg) {
+ fprintf(stderr, "%s: invalid option argument '%s' -- '%c'\n",
+ argv[0], optarg, opt);
+ }
+ goto error;
+ }
+ }
+ if(optind >= argc) { res = RES_BAD_ARG; goto error; }
+ args->filename = argv[optind];
exit:
return res;
@@ -134,10 +169,7 @@ setup_smeteo
if((res = smeteo_get_desc(lib->smeteo, &desc)) != RES_OK) goto error;
if((res = setup_utc_reference(lib)) != RES_OK) goto error;
-
- /* TODO Add an argument to the library creation function to allow the caller
- * to define the algorithm to be used */
- lib->algo = SCEM_SUN_MEEUS;
+ lib->algo = args->algo;
/* Retrieve the maximum convection coefficient from meteorological data */
FOR_EACH(i, 0, desc.nentries) max_H = MMAX(desc.entries[i].H, max_H);
diff --git a/src/test_stardis_smeteo_ground_temperature.sh b/src/test_stardis_smeteo_ground_temperature.sh
@@ -121,7 +121,7 @@ stardis_input_imposed_flux()
stardis_input_external_source()
{
# The plugin
- printf 'PROGRAM Meteo libstardis_smeteo.so %s\n' "${smeteo}"
+ printf 'PROGRAM Meteo libstardis_smeteo.so %s PROG_PARAMS -a meeus\n' "${smeteo}"
echo ''
# Media