star-meteo

Time varying meteorological data
git clone git://git.meso-star.fr/star-meteo.git
Log | Files | Refs | README | LICENSE

commit 7599cf89ad8f43deaa41f17a3dfa6927118d6ccc
parent 9c8dcc3058076fa90fd01fc7fa57913f61a05a8b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 13 Aug 2025 09:56:16 +0200

Add support for multiple files to the smeteo utility

Diffstat:
Mdoc/smeteo.1 | 10+++++-----
Msrc/smeteo_main.c | 31+++++++++++++++++++++----------
2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/doc/smeteo.1 b/doc/smeteo.1 @@ -12,7 +12,7 @@ .\" .\" You should have received a copy of the GNU Lesser General Public License .\" along with this program. If not, see <http://www.gnu.org/licenses/>. -.Dd August 11, 2025 +.Dd August 13, 2025 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Dt SMETEO 1 .Os @@ -26,19 +26,19 @@ file .Sh SYNOPSIS .Nm .Op Fl hv -.Op Ar file +.Op Ar file No ... .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh DESCRIPTION -Loads a +Loads .Xr smeteo 5 -file and displays information about it. +files and displays information about them. If no file is provided, data is read from standard input. .Pp On output, it displays the ground albedo, the longitude and latitude in degrees of the corresponding geographical position, the number of its meteorological entries loaded and the name of the file from which they were loaded. -The message is formatted as follows: +For each input file, the message is formatted as follows: .Bd -literal -offset Ds "%f %f %f %lu %s\\n", albedo, longitude, latitude, entry_count, file .Ed diff --git a/src/smeteo_main.c b/src/smeteo_main.c @@ -23,11 +23,12 @@ #include <unistd.h> /* getopt */ struct args { - const char* filename; /* Path toward the file storing meteo data */ + char* const* filenames; /* Path toward the files storing meteo data */ + int nfiles; /* Number of input files */ int verbose; /* Verbosity level */ int quit; }; -static const struct args ARGS_DEFAULT = {NULL, 0, 0}; +static const struct args ARGS_DEFAULT = {NULL, 0, 0, 0}; struct cmd { struct args args; @@ -41,7 +42,7 @@ static const struct cmd CMD_NULL = {0}; static INLINE void usage(FILE* stream) { - fprintf(stream, "usage: smeteo [-hv] [file]\n"); + fprintf(stream, "usage: smeteo [-hv] [file ...]\n"); } static res_T @@ -64,7 +65,8 @@ args_init(struct args* args, int argc, char** argv) if(res != RES_OK) goto error; } - args->filename = optind < argc ? argv[optind] : NULL; + args->filenames = argv + optind; + args->nfiles = argc - optind; exit: return res; @@ -116,14 +118,23 @@ cmd_run(struct cmd* cmd) res_T res = RES_OK; ASSERT(cmd); - if(cmd->args.filename) { - res = smeteo_load(cmd->smeteo, cmd->args.filename); - } else { + if(!cmd->args.nfiles) { + /* Read input data from standard input */ res = smeteo_load_stream(cmd->smeteo, stdin, "stdin"); - } - if(res != RES_OK) goto error; + if(res != RES_OK) goto error; + + print_info(cmd); - print_info(cmd); + } else { + /* Load provided input files */ + int i = 0; + FOR_EACH(i, 0, cmd->args.nfiles) { + res = smeteo_load(cmd->smeteo, cmd->args.filenames[i]); + if(res != RES_OK) goto error; + + print_info(cmd); + } + } exit: return res;