star-gas

Load and structure gas data
git clone git://git.meso-star.fr/star-gas.git
Log | Files | Refs | README | LICENSE

commit bf62e61449ddc040f79bd4c7ffe570e118b030f8
parent 777838bfc506fadd7e1d3c8631710e81a3f8493b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  3 Mar 2026 11:33:00 +0100

Time-variable therm props can be read from stdin

So we can pipe this list to the standard input and define it on the fly.

It could have been expected that the mesh could be read from the
standard input. But it is formatted in binary and therefore is less
suitable for pipes. Indeed, pipes are more powerful when they chain data
in plain text format, which can then be processed by a whole set of
shell tools that enrich the workflow. Hence the choice to instead
process the list of properties on the standard input.

The sgas-lint utility is updated to make this list of properties
optional. If not defined, it is read from the standard input.

Diffstat:
Mdoc/sgas-lint.1 | 44+++++++++++++++++++++++---------------------
Msrc/sgas.c | 17++++++++++++-----
Msrc/sgas.h | 5++++-
Msrc/sgas_lint.c | 15++++++++++-----
4 files changed, 49 insertions(+), 32 deletions(-)

diff --git a/doc/sgas-lint.1 b/doc/sgas-lint.1 @@ -25,7 +25,7 @@ .Nm .Op Fl hv .Fl m Ar mesh -.Fl p Ar therm_props_list +.Op Ar therm_props_list .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh DESCRIPTION .Nm @@ -35,27 +35,18 @@ In fact, it checks the behaviour of the Star-Gas library on which it relies, and in doing so checks that the loading and structuring of input data works as expected. .Pp -Input data are the volumetric gas mesh and a set of time-variable -thermodynamic properties. -The geometry of the gas is therefore constant but its properties may -vary over time. +Input data are the volumetric gas +.Ar mesh +and a set of time variable thermodynamic properties listed in the +.Ar therm_props_list +file. +If +.Ar therm_props_list +is not set, the list of thermodynamic properties is read from the +standard input. .Pp -The options are as follow: -.Bl -tag -width Ds -.\"""""""""""""""""""""""""""""""""" -.It Fl h -Display short help and exit. -.\"""""""""""""""""""""""""""""""""" -.It Fl m Ar mesh -Tetrahedral gas mesh in -.Xr smsh 5 -format. -.\"""""""""""""""""""""""""""""""""" -.It Fl p Ar therm_props_list -File listing the evolution of thermodynamic properties over time. -.Pp -This is a simple text file where each line consists of two fields -separated b at least on space. +These properties are listed in a simple text format, where each line +consists of at least two fields separated by at least one space. The first field is a real number representing the time at which the thermodynamic properties are defined, followed by the path to an .Xr atrtp 5 @@ -78,6 +69,17 @@ Here is an example file: 37.24 "${DATA_PATH}/37.24/therm_props.atrtp" 37.36 "${DATA_PATH}/37.36/therm_props.atrtp" .Ed +.Pp +The options are as follow: +.Bl -tag -width Ds +.\"""""""""""""""""""""""""""""""""" +.It Fl h +Display short help and exit. +.\"""""""""""""""""""""""""""""""""" +.It Fl m Ar mesh +Tetrahedral gas mesh in +.Xr smsh 5 +format. .\"""""""""""""""""""""""""""""""""" .It Fl v Make diff --git a/src/sgas.c b/src/sgas.c @@ -125,7 +125,7 @@ struct sgas { static INLINE res_T check_sgas_create_args(const struct sgas_create_args* args) { - if(!args || !args->mesh || !args->therm_props_list) return RES_BAD_ARG; + if(!args || !args->mesh) return RES_BAD_ARG; return RES_OK; } @@ -497,15 +497,22 @@ setup_therm_props const struct sgas_create_args* args) { struct txtrdr* txtrdr; + char* name = NULL; res_T res = RES_OK; ASSERT(gas && args); /* Pre-conditions */ - res = txtrdr_file - (gas->allocator, args->therm_props_list, '#', &txtrdr); + if(args->therm_props_list) { + /* Read the list of thermodynamic properties from an input file */ + name = args->therm_props_list; + res = txtrdr_file(gas->allocator, name, '#', &txtrdr); + } else { + /* Read the list of thermodynamic properties from the standard input */ + name = "stdin"; + res = txtrdr_stream(gas->allocator, stdin, name, '#', &txtrdr); + } if(res != RES_OK) { - ERROR(gas, "Error opening file \"%s\" -- %s\n", - args->therm_props_list, res_to_cstr(res)); + ERROR(gas, "Cannot create \"%s\" reader -- %s\n", name, res_to_cstr(res)); goto error; } diff --git a/src/sgas.h b/src/sgas.h @@ -41,7 +41,10 @@ struct mem_allocator; struct sgas_create_args { char* mesh; /* Path to a tetrahedral mesh in smsh(5) format */ - char* therm_props_list; /* Path to the list of time vayring atrtp(5) files */ + + /* Path to the list of time vayring atrtp(5) files. + * NULL <=> read from stdin */ + char* therm_props_list; struct logger* logger; /* NULL <=> default logger */ struct mem_allocator* allocator; /* NULL <=> default allocator */ diff --git a/src/sgas_lint.c b/src/sgas_lint.c @@ -25,7 +25,11 @@ struct args { char* mesh; /* Path to a tetrahedral mesh in smsh(5) format */ - char* therm_props_list; /* Path to the list of time varying atrtp(5) files */ + + /* Path to the list of time varying atrtp(5) files. + * NULL <=> read from standard input */ + char* therm_props_list; + int verbose; /* Verbosity level */ int quit; }; @@ -45,7 +49,7 @@ static const struct cmd CMD_NULL = CMD_NULL__; static void usage(const char* name, FILE* stream) { - fprintf(stream, "usage: %s [-hv] -m mesh -p therm_props_list\n", name); + fprintf(stream, "usage: %s [-hv] -m mesh [therm_props_list]\n", name); } static res_T @@ -57,14 +61,13 @@ args_init(struct args* args, int argc, char** argv) *args = ARGS_DEFAULT; - while((opt = getopt(argc, argv, "hm:p:v")) != -1) { + while((opt = getopt(argc, argv, "hm:v")) != -1) { switch(opt) { case 'h': usage(argv[0], stdout); args->quit = 1; goto exit; case 'm': args->mesh = optarg; break; - case 'p': args->therm_props_list = optarg; break; case 'v': args->verbose += (args->verbose < 3); break; default: res = RES_BAD_ARG; break; } @@ -77,7 +80,9 @@ args_init(struct args* args, int argc, char** argv) } } - if(!args->mesh || !args->therm_props_list) { + if(optind < argc) args->therm_props_list = argv[optind]; + + if(!args->mesh) { res = RES_BAD_ARG; goto error; }