star-gas

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

commit bcf9f3c7ade0e2e3ee4c9198bde831a36b64dc11
parent 06c180ee0a68a3b11384d78aabee72fb9b9ac256
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  2 Mar 2026 16:39:15 +0100

Start writing the sgas-lint utility

It is designed to check the sgas library, but also as a stand-alone tool
that users can run to check that their input data is consistent with the
library's expectations.

Currently, only the analysis of very basic arguments is implemented.

Diffstat:
MMakefile | 37++++++++++++++++++++++++++++++++++---
Asrc/sgas_lint.c | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 137 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile @@ -23,7 +23,7 @@ LIBNAME_SHARED = libsgas.so LIBNAME = $(LIBNAME_$(LIB_TYPE)) default: library -all: default tests +all: default util ################################################################################ # Library @@ -71,6 +71,35 @@ libsgas.o: $(OBJ) $(CC) $(CFLAGS_LIB) -c $< -o $@ ################################################################################ +# Utility +################################################################################ +UTIL_SRC = src/sgas_lint.c +UTIL_OBJ = $(UTIL_SRC:.c=.o) +UTIL_DEP = $(UTIL_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +INCS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sgas-local.pc) +LIBS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sgas-local.pc) + +CFLAGS_UTIL = -std=c89 $(CFLAGS_EXE) $(INCS_UTIL) +LDFLAGS_UTIL = $(LDFLAGS_EXE) $(LIBS_UTIL) + +util: library $(UTIL_DEP) + $(MAKE) -fMakefile -f$(UTIL_DEP) sgas-lint + +$(UTIL_DEP): config.mk sgas-local.pc + $(CC) $(CFLAGS_UTIL) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(UTIL_OBJ): config.mk sgas-local.pc + $(CC) $(CFLAGS_UTIL) -c $(@:.o=.c) -o $@ + +sgas-lint: config.mk sgas-local.pc $(LIBNAME) $(UTIL_OBJ) + $(CC) $(CFLAGS_UTIL) -o $@ $(UTIL_OBJ) $(LDFLAGS_UTIL) + +clean_util: + rm -f $(UTIL_DEP) $(UTIL_OBJ) sgas-lint + +################################################################################ # Miscellaneous ################################################################################ pkg: @@ -93,7 +122,7 @@ sgas-local.pc: sgas.pc.in -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ sgas.pc.in > $@ -install: library pkg +install: library util pkg install() { mode="$$1"; prefix="$$2"; shift 2; \ mkdir -p "$${prefix}"; \ cp "$$@" "$${prefix}"; \ @@ -103,17 +132,19 @@ install: library pkg }; \ if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \ install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ + install 755 "$(DESTDIR)$(BINPREFIX)" sgas-lint; \ install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" sgas.pc; \ install 644 "$(DESTDIR)$(INCPREFIX)/star" src/sgas.h; \ install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-gas" COPYING README.md uninstall: rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(BINPREFIX)/sgas-lint" rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/sgas.pc" rm -f "$(DESTDIR)$(INCPREFIX)/star/sgas.h" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-gas/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-gas/README.md" -clean: #clean_test +clean: clean_util rm -f $(DEP) $(OBJ) $(LIBNAME) rm -f .config libsgas.o sgas.pc sgas-local.pc diff --git a/src/sgas_lint.c b/src/sgas_lint.c @@ -0,0 +1,103 @@ +/* Copyright (C) 2025, 2026 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2025, 2026 Université de Lorraine + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#define _POSIX_C_SOURCE 200112L /* getopt support */ + +#include "sgas.h" + +#include <rsys/mem_allocator.h> + +#include <stdio.h> +#include <unistd.h> /* getopt */ + +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 */ + int verbose; /* Verbosity level */ + int quit; +}; +#define ARGS_DEFAULT__ {0} +static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +usage(const char* name, FILE* stream) +{ + fprintf(stream, "usage: %s [-hv] -m mesh -p therm_props_list\n", name); +} + +static res_T +args_init(struct args* args, int argc, char** argv) +{ + int opt = 0; + res_T res = RES_OK; + ASSERT(args && argv); + + *args = ARGS_DEFAULT; + + while((opt = getopt(argc, argv, "hm:p: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; + } + if(res != RES_OK) { + if(optarg) { + fprintf(stderr, "%s: invalid option argument '%s' -- '%c'\n", + argv[0], optarg, opt); + } + goto error; + } + } + + if(!args->mesh || !args->therm_props_list) { + res = RES_BAD_ARG; + goto error; + } + +exit: + return res; +error: + usage(argv[0], stderr); + goto exit; +} + +/******************************************************************************* + * The program + ******************************************************************************/ +int +main(int argc, char** argv) +{ + struct args args = ARGS_DEFAULT; + int err = 0; + res_T res = RES_OK; + + if((res = args_init(&args, argc, argv)) != RES_OK) goto error; + +exit: + CHK(mem_allocated_size() == 0); + return err; +error: + err = 1; + goto exit; +}