commit 0cb3177c9e90ab4cbe0d1deaafa33b48d2980cbf
parent 6803f121ceed7f9c3cfd342b8c4c09d81f202ddf
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 20 Feb 2025 19:12:57 +0100
Start implementing the suvm-map-data program
Only argument analysis implemented
Diffstat:
3 files changed, 124 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -5,6 +5,7 @@
.gitignore
*.pc
*.so
+suvm-map-data
suvm-voxelize
*.sw[po]
tags
diff --git a/Makefile b/Makefile
@@ -120,7 +120,7 @@ lint: lint_utils
#################################################################################
# Utils
#################################################################################
-UTIL_SRC = src/suvm_voxelize.c
+UTIL_SRC = src/suvm_voxelize.c src/suvm_map_data.c
UTIL_OBJ = $(UTIL_SRC:.c=.o)
UTIL_DEP = $(UTIL_SRC:.c=.d)
@@ -133,35 +133,42 @@ CFLAGS_UTIL = -std=c89 $(CFLAGS_EXE) $(INCS_UTIL)
LDFLAGS_UTIL = $(LDFLAGS_EXE) $(LIBS_UTIL)
utils: library .config_utils
- @$(MAKE) $(UTIL_DEP); \
- $(MAKE) -f Makefile -f src/suvm_voxelize.d suvm-voxelize
+ @$(MAKE) $(UTIL_DEP)
+ @$(MAKE) -f Makefile -f src/suvm_map_data.d suvm-map-data
+ @$(MAKE) -f Makefile -f src/suvm_voxelize.d suvm-voxelize
.config_utils: config.mk
$(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh
@echo "config done" > $@
-src/suvm_voxelize.d: config.mk suvm-local.pc
+$(UTIL_DEP): config.mk suvm-local.pc
@$(CC) -std=c89 $(CFLAGS_UTIL) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
-src/suvm_voxelize.o: config.mk suvm-local.pc
+$(UTIL_OBJ): config.mk suvm-local.pc
$(CC) -std=c89 $(CFLAGS_UTIL) -c $(@:.o=.c) -o $@
suvm-voxelize: config.mk suvm-local.pc $(LIBNAME) src/suvm_voxelize.o
$(CC) -std=c89 $(CFLAGS_UTIL) -o $@ src/suvm_voxelize.o $(LDFLAGS_UTIL)
+suvm-map-data: config.mk suvm-local.pc $(LIBNAME) src/suvm_map_data.o
+ $(CC) -std=c89 $(CFLAGS_UTIL) -o $@ src/suvm_map_data.o $(LDFLAGS_UTIL)
+
clean_utils:
- rm -f $(UTIL_DEP) $(UTIL_OBJ) suvm-voxelize
+ rm -f $(UTIL_DEP) $(UTIL_OBJ) suvm-voxelize suvm-map-data
rm -f .config_utils
install_utils: utils
mkdir -p "$(DESTDIR)$(BINPREFIX)"
mkdir -p "$(DESTDIR)$(MANPREFIX)/man1"
+ cp suvm-map-data "$(DESTDIR)$(BINPREFIX)"
cp suvm-voxelize "$(DESTDIR)$(BINPREFIX)"
cp suvm-voxelize.1 "$(DESTDIR)$(MANPREFIX)/man1/"
+ chmod 755 "$(DESTDIR)$(BINPREFIX)/suvm-map-data"
chmod 755 "$(DESTDIR)$(BINPREFIX)/suvm-voxelize"
chmod 644 "$(DESTDIR)$(MANPREFIX)/man1/suvm-voxelize.1"
uninstall_utils:
+ rm -f "$(DESTDIR)$(BINPREFIX)/suvm-map-data"
rm -f "$(DESTDIR)$(BINPREFIX)/suvm-voxelize"
rm -f "$(DESTDIR)$(MANPREFIX)/man1/suvm-voxelize.1"
diff --git a/src/suvm_map_data.c b/src/suvm_map_data.c
@@ -0,0 +1,110 @@
+/* Copyright (C) 2020-2023, 2025 |Méso|Star> (contact@meso-star.com)
+ *
+ * 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 <rsys/rsys.h>
+
+#include <unistd.h> /* getopt */
+
+/* Maximum number of data items that can be mapped to each cell */
+#define MAX_DATA 8
+
+struct args {
+ const char* mesh; /* Tetrahedral mesh */
+ const char* output; /* Output file */
+ const char* data; /* Data to map */
+
+ /* List of data names.
+ * If a name is missing for a data item, a default name is used */
+ const char* names[8];
+ int nnames; /* Number of names */
+};
+static const struct args ARGS_DEFAULT = {0};
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static INLINE void
+usage(FILE* stream)
+{
+ fprintf(stream,
+ "usage: suvm-map-data [-d data] [-o output] [-n name ...] -m mesh\n");
+}
+
+static void
+args_release(struct args* args)
+{
+ ASSERT(args);
+ *args = ARGS_DEFAULT;
+}
+
+static res_T
+args_init(struct args* args, const int argc, char** argv)
+{
+ int opt = 0;
+ res_T res = RES_OK;
+
+ *args = ARGS_DEFAULT;
+
+ while((opt = getopt(argc, argv, "d:m:o:")) != -1) {
+ switch(opt) {
+ case 'd': args->data = optarg; break;
+ case 'm': args->mesh = optarg; break;
+ case 'n':
+ if(args->nnames < MAX_DATA) {
+ args->names[args->nnames] = optarg;
+ ++args->nnames;
+ }
+ break;
+ case 'o': args->output = optarg; break;
+ default: res = RES_BAD_ARG;
+ }
+ if(res != RES_OK) goto error;
+ }
+
+ if(!args->mesh) {
+ fprintf(stderr, "Mesh is missing -- option '-m'\n");
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+exit:
+ return res;
+error:
+ usage(stderr);
+ args_release(args);
+ 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:
+ args_release(&args);
+ return err;
+error:
+ err = 1;
+ goto exit;
+}