commit 92d22e1a5d58fc53c17bf61e74c84085c5758964
parent 860c57a4725a2f701f567ef59b1f552558776125
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Fri, 13 Dec 2024 19:46:47 +0100
Started implementing sphin_config
The module responsible for reading the radiative transfer problem data
from the input file and to load it into memory.
Diffstat:
2 files changed, 134 insertions(+), 2 deletions(-)
diff --git a/src/sphin.h b/src/sphin.h
@@ -54,6 +54,7 @@ static const struct sphin_create_args SPHIN_CREATE_ARGS_DEFAULT = {
/* Forward declaration */
struct sphin;
+struct sphin_config; /* Physical configuration */
BEGIN_DECLS
@@ -76,13 +77,15 @@ sphin_ref_put
SPHIN_API res_T
sphin_load
(struct sphin* sphin,
- const char* filename);
+ const char* filename,
+ struct sphin_config** config);
SPHIN_API res_T
sphin_load_stream
(struct sphin* sphin,
FILE* stream,
- const char* stream_name);
+ const char* stream_name,
+ struct sphin_config** config);
END_DECLS
diff --git a/src/sphin_config.c b/src/sphin_config.c
@@ -0,0 +1,129 @@
+/* Copyright (C) 2024 Centre National de la Recherche Scientifique
+ * Copyright (C) 2024 Clermont Auvergne INP
+ * Copyright (C) 2024 INSA Lyon
+ * Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux
+ * Copyright (C) 2024 Institut National Polytechnique de Toulouse
+ * Copyright (C) 2024 |Méso|Star> (contact@meso-star.com)
+ * Copyright (C) 2024 PhotonLyX (info@photonlyx.com)
+ * Copyright (C) 2024 Université de Lorraine
+ * Copyright (C) 2024 Université Paul Sabatier
+ * Copyright (C) 2024 Université Toulouse - Jean Jaurès
+ *
+ * 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/>. */
+
+#include "sphin.h"
+
+struct sphin_config {
+ /* Put the fun things here */
+
+ struct sphin* sphin;
+ ref_T ref;
+};
+
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static res_T
+config_create
+ (struct sphin* sphin,
+ struct sphin_config** out_config)
+{
+ res_T res = RES_OK;
+
+ ASSERT(NULL != sphin);
+ ASSERT(NULL != out_config);
+}
+
+static res_T
+load_stream
+ (struct sphin* sphin,
+ FILE* stream,
+ const char* streamname,
+ struct sphin_config** config)
+{
+ res_T res = RES_OK;
+
+ ASSERT(NULL != sphin);
+ ASSERT(NULL != stream);
+ ASSERT(NULL != streamname);
+ ASSERT(NULL != config);
+
+ res = config_create(sphin, config);
+ if (res != RES_OK) {
+ goto error;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+/*******************************************************************************
+ * Exported functions
+ ******************************************************************************/
+res_T
+sphin_load
+ (struct sphin* sphin,
+ const char* filename,
+ struct sphin_config** config)
+{
+ FILE* stream = NULL;
+ res_T res = RES_OK;
+
+ if (sphin == NULL || filename == NULL || config == NULL) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ stream = fopen(filename, "r");
+ if (stream == NULL) {
+ ERROR(sphin, "Not possible to open file %s -- %s\n",
+ filename, strerror(errno));
+ res = RES_IO_ERR;
+ goto error;
+ }
+
+ res = load_stream(sphin, stream, filename, config);
+ if (res != RES_OK) {
+ goto error;
+ }
+
+exit:
+ if (stream != NULL) {
+ fclose(stream);
+ }
+ return res;
+
+error:
+ goto exit;
+}
+
+res_T
+sphin_load_stream
+ (struct sphin* sphin,
+ FILE* stream,
+ const char* streamname,
+ struct sphin_config** config)
+{
+ if(NULL == sphin
+ || NULL == stream
+ || NULL == streamname
+ || NULL == config) {
+ return RES_BAD_ARG;
+ }
+ return load_stream(sphin, stream, streamname, config);
+}
+