commit da8128d284f53e9547f217256e7ed81d0ccae876
parent 3ead605c6ab1fccca6592497cc52e7592010363a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 9 Jan 2026 16:01:52 +0100
Allow the shtr utility to load lines from serialized data
The -s option is added to indicate to the tool that the lines provided
are formatted in the internal format of the Star-HITRAN library.
Diffstat:
2 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/doc/shtr.1 b/doc/shtr.1
@@ -25,7 +25,7 @@
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh SYNOPSIS
.Nm
-.Op Fl hv
+.Op Fl hsv
.Op Fl l Ar lines
.Op Fl m Ar molparam
.Op Fl o Ar output
@@ -88,6 +88,15 @@ Files storing line-by-line parameters to be loaded.
Files storing isotopologue metadata to be loaded.
.It Fl o Ar output
Files in which to serialize the list of loaded lines.
+.It Fl s
+Input lines are formatted according to
+.Nm Ns 's
+internal format, not according to the HITRAN format
+.Po
+see the
+.Fl o
+option
+.Pc .
.It Fl v
Make
.Nm
diff --git a/src/shtr_main.c b/src/shtr_main.c
@@ -35,12 +35,13 @@ struct args {
char* lines;
char* output;
+ int internal_format;
int verbose; /* Verbosity level */
int compression; /* Compression level */
int human_readable;
};
static const struct args ARGS_DEFAULT = {
- NULL, NULL, NULL, 0, SHTR_DEFAULT_COMPRESSION, 0
+ NULL, NULL, NULL, 0, 0, SHTR_DEFAULT_COMPRESSION, 0
};
struct cmd {
@@ -58,7 +59,7 @@ static INLINE void
usage(FILE* stream)
{
fprintf(stream,
-"usage: shtr [-hv] [-l lines] [-m molparam] [-o output] [-z compression_level]\n");
+"usage: shtr [-hsv] [-l lines] [-m molparam] [-o output] [-z compression_level]\n");
}
static res_T
@@ -71,12 +72,13 @@ args_init(struct args* args, int argc, char** argv)
*args = ARGS_DEFAULT;
- while((opt = getopt(argc, argv, "hl:m:o:vz:")) != -1) {
+ while((opt = getopt(argc, argv, "hl:m:o:svz:")) != -1) {
switch(opt) {
case 'h': args->human_readable = 1; break;
case 'l': args->lines = optarg; break;
case 'm': args->molparam = optarg; break;
case 'o': args->output = optarg; break;
+ case 's': args->internal_format = 1; break;
case 'v': args->verbose += (args->verbose < 3); break;
case 'z': res = cstr_to_int(optarg, &args->compression); break;
default: res = RES_BAD_ARG; break;
@@ -140,10 +142,43 @@ load_molparam(const struct cmd* cmd, struct shtr_isotope_metadata** molparam)
}
static res_T
-load_lines(const struct cmd* cmd, struct shtr_line_list** lines)
+load_lines_binary(const struct cmd* cmd, struct shtr_line_list** lines)
+{
+ FILE* fp = NULL;
+ res_T res = RES_OK;
+
+ ASSERT(cmd && lines && cmd->args.lines);
+
+ if(!strcmp(cmd->args.lines, STDIN_NAME)) {
+ fp = stdin;
+ } else {
+ fp = fopen(cmd->args.lines, "r");
+ if(!fp) {
+ fprintf(stderr, "%s: error opening file -- %s\n",
+ cmd->args.lines, strerror(errno));
+ res = RES_IO_ERR;
+ goto error;
+ }
+ }
+
+ res = shtr_line_list_create_from_stream(cmd->shtr, fp, lines);
+ if(res != RES_OK) goto error;
+
+exit:
+ if(fp && fp != stdin) CHK(fclose(fp) == 0);
+ return res;
+error:
+ goto exit;
+}
+
+static res_T
+load_lines_hitran(const struct cmd* cmd, struct shtr_line_list** lines)
{
struct shtr_line_list_load_args args = SHTR_LINE_LIST_LOAD_ARGS_NULL__;
+ res_T res = RES_OK;
+
ASSERT(cmd && lines && cmd->args.lines);
+
if(strcmp(cmd->args.lines, STDIN_NAME)) {
args.filename = cmd->args.lines;
} else {
@@ -151,7 +186,25 @@ load_lines(const struct cmd* cmd, struct shtr_line_list** lines)
args.filename = "stdin";
}
args.compression_level = cmd->args.compression;
- return shtr_line_list_load(cmd->shtr, &args, lines);
+
+ res = shtr_line_list_load(cmd->shtr, &args, lines);
+ if(res != RES_OK) goto error;
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+static res_T
+load_lines(const struct cmd* cmd, struct shtr_line_list** lines)
+{
+ ASSERT(cmd && lines && cmd->args.lines);
+ if(cmd->args.internal_format) {
+ return load_lines_binary(cmd, lines);
+ } else {
+ return load_lines_hitran(cmd, lines);
+ }
}
static res_T