rnatm

Load and structure data describing an atmosphere
git clone git://git.meso-star.fr/rnatm.git
Log | Files | Refs | README | LICENSE

commit 01d9b2bc03acc75ff351ed791d925456fc5f30ff
parent 00a6a570df5a6e9bd235c17ae4bda0dd17f30051
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 31 Oct 2023 12:56:05 +0100

Merge branch 'release_0.1'

Diffstat:
M.gitignore | 14+++++++-------
AMakefile | 193+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 106+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Dcmake/CMakeLists.txt | 161-------------------------------------------------------------------------------
Aconfig.mk | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ddoc/rngt.5.scd | 71-----------------------------------------------------------------------
Ddoc/rnpfi.5.scd | 71-----------------------------------------------------------------------
Amake.sh | 46++++++++++++++++++++++++++++++++++++++++++++++
Arnatm.pc.in | 19+++++++++++++++++++
Arngt.5 | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arnpfi.5 | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/rnatm.h | 1-
Msrc/rnatm_c.h | 2+-
Msrc/rnatm_mesh.c | 5++++-
Msrc/rnatm_octree.c | 7++++---
Msrc/rnatm_properties.c | 10++++++++--
Msrc/rnatm_radcoef.c | 4----
Msrc/rnatm_voxel_partition.c | 9++++++++-
Msrc/test_rnatm.c | 2+-
19 files changed, 674 insertions(+), 375 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,12 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] -*.orig +*.[aod] +*.so *~ +test* +!test*.[ch] +.config +.test tags - +*.pc diff --git a/Makefile b/Makefile @@ -0,0 +1,193 @@ +# Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique +# Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace +# Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris +# Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2022, 2023 Observatoire de Paris +# Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne +# Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin +# Copyright (C) 2022, 2023 Université Paul Sabatier +# +# 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/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = librnatm.a +LIBNAME_SHARED = librnatm.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Library building +################################################################################ +SRC =\ + src/rnatm.c\ + src/rnatm_log.c\ + src/rnatm_mesh.c\ + src/rnatm_octree.c\ + src/rnatm_octrees_storage.c\ + src/rnatm_properties.c\ + src/rnatm_radcoef.c\ + src/rnatm_voxel_partition.c\ + src/rnatm_write_vtk.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then \ + echo "$(LIBNAME)"; \ + else \ + echo "$(LIBNAME_SHARED)"; \ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) + +$(LIBNAME_STATIC): librnatm.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +librnatm.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(RNSF_VERSION) rnsf; then \ + echo "rnsf $(RNSF_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(RNSL_VERSION) rnsl; then \ + echo "rnsl $(RNSL_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SARS_VERSION) sars; then \ + echo "sars $(SARS_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SBUF_VERSION) sbuf; then \ + echo "sbuf $(SBUF_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SCK_VERSION) sck; then \ + echo "sck $(SCK_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh; then \ + echo "smsh $(SMSH_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SSF_VERSION) ssf; then \ + echo "ssf $(SSF_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SUVM_VERSION) suvm; then \ + echo "suvm $(SUVM_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SVX_VERSION) svx; then \ + echo "svx $(SVX_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DRNATM_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RNSF_VERSION@#$(RNSF_VERSION)#g'\ + -e 's#@RNSL_VERSION@#$(RNSL_VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + -e 's#@SARS_VERSION@#$(SARS_VERSION)#g'\ + -e 's#@SBUF_VERSION@#$(SBUF_VERSION)#g'\ + -e 's#@SCK_VERSION@#$(SCK_VERSION)#g'\ + -e 's#@SMSH_VERSION@#$(SMSH_VERSION)#g'\ + -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\ + -e 's#@SUVM_VERSION@#$(SUVM_VERSION)#g'\ + -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\ + rnatm.pc.in > rnatm.pc + +rnatm-local.pc: rnatm.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RNSF_VERSION@#$(RNSF_VERSION)#g'\ + -e 's#@RNSL_VERSION@#$(RNSL_VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + -e 's#@SARS_VERSION@#$(SARS_VERSION)#g'\ + -e 's#@SBUF_VERSION@#$(SBUF_VERSION)#g'\ + -e 's#@SCK_VERSION@#$(SCK_VERSION)#g'\ + -e 's#@SMSH_VERSION@#$(SMSH_VERSION)#g'\ + -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\ + -e 's#@SUVM_VERSION@#$(SUVM_VERSION)#g'\ + -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\ + rnatm.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rnatm.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rad-net" src/rnatm.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rnatm" COPYING README.md + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" rngt.5 rnpfi.5 + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rnatm.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnatm/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnatm/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/rad-net/rnatm.h" + rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rngt.5" + rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rnpfi.5" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(LIBNAME) + rm -f .config librnatm.o rnatm.pc rnatm-local.pc + +distclean: clean + rm -f $(DEP) src/test_rnatm.d + +lint: + shellcheck -o all make.sh + mandoc -Tlint -Wall rngt.5 || [ $$? -le 1 ] + mandoc -Tlint -Wall rnpfi.5 || [ $$? -le 1 ] + +################################################################################ +# Tests +################################################################################ +TEST_SRC = src/test_rnatm.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +RNATM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rnatm-local.pc) +RNATM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rnatm-local.pc) + +build_tests: build_library src/test_rnatm.d + @$(MAKE) -fMakefile -f src/test_rnatm.d test_rnatm + +clean_test: + rm -f test_rnatm src/test_rnatm.o + +$(TEST_DEP): config.mk rnatm-local.pc + @$(CC) $(CFLAGS_EXE) $(RNATM_CFLAGS) $(RSYS_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_rnatm.o: config.mk rnatm-local.pc + $(CC) $(CFLAGS_EXE) $(RNATM_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + +test_rnatm: src/test_rnatm.o config.mk rnatm-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) $(RNATM_CFLAGS) $(RSYS_CFLAGS) -o $@ src/$@.o \ + $(LDFLAGS_EXE) $(RNATM_LIBS) $(RSYS_LIBS) diff --git a/README.md b/README.md @@ -1,65 +1,69 @@ # Rad-Net ATMosphere -This C library loads and manages data from atmosphere. The gas volumetric mesh -is described by a [Star-Mesh](https://gitlab.com/meso-star/star-mesh) file -while its radiative properties are stored in a -[Star-CorrelatedK](https://gitlab.com/meso-star/star-ck) file. Its temperature -is recorded per node in a -[Star-Buffer](https://gitla.com/meso-star/star-buffer) file. Aerosol volumetric -meshes are also Star-Mesh geometries and their radiative properties are stored -in [Star-Aerosol](https://gitlab.com/meso-star/star-aerosol) files. The -properties of the phase functions are finally listed in files following the -[Rad-Net Scattering Function](https://gitlab.com/meso-star/rnsf) file format. - -## How to build - -This library is compatible with 64-bits POSIX systems. It relies the -[CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) packages to build. It also depends -on the [Rad-Net Scattering Function](https://gitlab.com/meso-star/rnsf), -[RNSL](https://gitlab.com/meso-star/rnsl), -[RSys](https://gitlab.com/vaplv/rsys/), -[Star-Aerosol](https://gitlab.com/meso-star/star-aerosol), -[Star-Buffer](https://gitlab.com/meso-star/star-buffer), -[Star-CorrelatedK](https://gitlab.com/meso-star/star-ck), -[Star-Mesh](https://gitlab.com/meso-star/star-mesh), -[Star-ScatteringFunctions](https://gitlab.com/meso-star/star-sf), -[Star-UnstructuredVolumetricMesh](https://gitlab.com/meso-star/star-uvm), -[Star-VoXel](https://gitlab.com/meso-star/star-vx) -libraries, and on [OpenMP](https://www.openmp.org) 1.2 to parallelize its -computations. It optionally depends on [scdoc](https://sr.ht/~sircmpwn/scdoc/) -which, if available, is used to generate the man pages. - -First ensure that CMake is installed on your system. Then install the RCMake -package as well as the aforementioned prerequisites. Finally generate the -project from the `cmake/CMakeLists.txt` file by appending to the -`CMAKE_PREFIX_PATH` variable the install directories of its dependencies. The -resulting project can be edited, built, tested and installed as any CMake -project. Refer to the [CMake documentation](https://cmake.org/documentation) -for further informations on CMake. +This C library loads and manages data describing an atmosphere. + +## Requirements + +- C compiler with OpenMP support +- POSIX make +- pkg-config +- [Rad-Net Scattering Functions](https://gitlab.com/meso-star/rnsf) +- [Rad-Net String List](https://gitlab.com/meso-star/rnsl) +- [RSys](https://gitlab.com/vaplv/rsys) +- [Star AeRoSol](https://gitlab.com/meso-star/star-aerosol) +- [Star Buffer](https://gitlab.com/meso-star/star-buffer) +- [Star CorrelatedK](https://gitlab.com/meso-star/star-ck) +- [Star Mesh](https://gitlab.com/meso-star/star-mesh) +- [Star Scattering Functions](https://gitlab.com/meso-star/star-sf) +- [Star Unstructured Volumetric Mesh](https://gitlab.com/meso-star/star-uvm) +- [Star VoXel](https://gitlab.com/meso-star/star-vx) + +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes +### Version 0.1 + +- Fix voxelization deadlock. +- Fix of a bug when calculating the octree definition: the definition + should be equal to 0, which would result in an error. +- Fix the calculation of radiative coefficients. They were erroneous + when the gas band overlapped several aerosol bands: the aerosol + average was wrongly reduced to the integration domain. +- Write the man pages directly in mdoc's roff macros, instead of using + the scdoc markup language as a source for man pages. +- Replace CMake by Makefile as build system. +- Update compiler and linker flags to increase the security and + robustness of generated binaries. +- Provide a pkg-config file to link the library as an external + dependency. + ### Version 0.0.1 -Fix several bugs when volumetric meshes of the components are not identical: +Fix several bugs when volumetric meshes of the components are not +identical: - Fix the `rnatm_sample_component` function. The cumulative was - calculated assuming that all components are either present or absent at the - queried position. Thus, the accumulation was only correct when the volumetric - meshes were the same for all components. -- Fix the calculation of the minimum radiative coefficient of a voxel in the - octree. It was simply miscalculated and its value might not be the minimum. -- Fix the accumulation of radiative coefficients in the voxels of the octree. - When the volumetric meshes were not the same for all components, some voxels - could be "emptied" during the accumulation. + calculated assuming that all components are either present or absent + at the queried position. Thus, the accumulation was only correct when + the volumetric meshes were the same for all components. +- Fix the calculation of the minimum radiative coefficient of a voxel in + the octree. It was simply miscalculated and its value might not be the + minimum. +- Fix the accumulation of radiative coefficients in the voxels of the + octree. When the volumetric meshes were not the same for all + components, some voxels could be "emptied" during the accumulation. -## Copyright notice +## Copyrights Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris -Copyright (C) 2022, 2023 [|Méso|Star>](https://www.meso-star.com) (<contact@meso-star.com>) +Copyright (C) 2022, 2023 [|Méso|Star>](https://www.meso-star.com) (contact@meso-star.com) Copyright (C) 2022, 2023 Observatoire de Paris Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin @@ -67,6 +71,6 @@ Copyright (C) 2022, 2023 Université Paul Sabatier ## License -Rad-Net Atmosphere is free software released under the GPL v3+ license: GNU GPL -version 3 or later. You are welcome to redistribute it under certain -conditions; refer to the COPYING file for details. +Rad-Net Atmosphere is free software released under the GPL v3+ license: +GNU GPL version 3 or later. You are welcome to redistribute it under +certain conditions; refer to the COPYING file for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,161 +0,0 @@ -# Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique -# Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace -# Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris -# Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2022, 2023 Observatoire de Paris -# Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne -# Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin -# Copyright (C) 2022, 2023 Université Paul Sabatier -# -# 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/>. - -cmake_minimum_required(VERSION 3.1) -project(rnatm C) -enable_testing() - -set(RNATM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Do not build tests" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(OpenMP 1.2 REQUIRED) -find_package(RCMake 0.4 REQUIRED) -find_package(RNSL REQUIRED) -find_package(RNSF REQUIRED) -find_package(RSys 0.12.1 REQUIRED) -find_package(StarAerosol REQUIRED) -find_package(StarBuffer REQUIRED) -find_package(StarCK REQUIRED) -find_package(StarMesh REQUIRED) -find_package(StarSF 0.8 REQUIRED) -find_package(StarUVM 0.0 REQUIRED) -find_package(StarVX 0.2 REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories( - ${RNSL_INCLUDE_DIR} - ${RNSF_INCLUDE_DIR} - ${RSys_INCLUDE_DIR} - ${StarAerosol_INCLUDE_DIR} - ${StarBuffer_INCLUDE_DIR} - ${StarCK_INCLUDE_DIR} - ${StarMesh_INCLUDE_DIR} - ${StarSF_INCLUDE_DIR} - ${StarUVM_INCLUDE_DIR} - ${StarVX_INCLUDE_DIR}) - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 0) -set(VERSION_PATCH 1) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(RNATM_FILES_SRC - rnatm.c - rnatm_log.c - rnatm_mesh.c - rnatm_octree.c - rnatm_octrees_storage.c - rnatm_properties.c - rnatm_radcoef.c - rnatm_voxel_partition.c - rnatm_write_vtk.c) -set(RNATM_FILES_INC - rnatm_c.h - rnatm_log.h - rnatm_octrees_storage.h - rnatm_voxel.h - rnatm_voxel_partition.h) -set(RNATM_FILES_INC_API rnatm.h) -set(RNATM_FILES_DOC COPYING README.md) - -# Prepend each file in the `RNATM_FILES_<SRC|INC>' list by `RNATM_SOURCE_DIR' -rcmake_prepend_path(RNATM_FILES_SRC ${RNATM_SOURCE_DIR}) -rcmake_prepend_path(RNATM_FILES_INC ${RNATM_SOURCE_DIR}) -rcmake_prepend_path(RNATM_FILES_INC_API ${RNATM_SOURCE_DIR}) -rcmake_prepend_path(RNATM_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_library(rnatm SHARED ${RNATM_FILES_SRC} ${RNATM_FILES_INC} ${RNATM_FILES_INC_API}) -target_link_libraries(rnatm RNSL RNSF RSys StarAerosol StarBuffer StarCK StarMesh - StarSF StarUVM StarVX m) - -set_target_properties(rnatm PROPERTIES - COMPILE_FLAGS "${OpenMP_C_FLAGS}" - LINK_FLAGS "${OpenMP_C_FLAGS}" - DEFINE_SYMBOL RNATM_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -rcmake_setup_devel(rnatm RNATM ${VERSION} rad-net/rnatm_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - function(build_test _name) - add_executable(${_name} - ${RNATM_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} rnatm RSys) - endfunction() - - function(new_test _name) - build_test(${_name}) - add_test(${_name} ${_name}) - endfunction() - - build_test(test_rnatm) - -endif() - -################################################################################ -# Man page -############################################################################### -find_program(SCDOC NAMES scdoc) -if(NOT SCDOC) - message(WARNING - "The `scdoc' program is missing. " - "The Rad Net ATMopshere man page cannot be generated.") -else() - set(_man_names rngt.5 rnpfi.5) - - foreach(_man IN LISTS _man_names) - set(_src ${PROJECT_SOURCE_DIR}/../doc/${_man}.scd) - add_custom_command( - OUTPUT ${_man} - COMMAND ${SCDOC} < ${_src} > ${_man} - DEPENDS ${_src} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Buid ROFF man page ${_man}" - VERBATIM) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_man} DESTINATION share/man/man5) - endforeach() - add_custom_target(man-roff ALL DEPENDS ${_man_names}) -endif() - - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS rnatm - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${RNATM_FILES_INC_API} DESTINATION include/rad-net) -install(FILES ${RNATM_FILES_DOC} DESTINATION share/doc/rnatm) diff --git a/config.mk b/config.mk @@ -0,0 +1,141 @@ +VERSION = 0.1.0 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +RNSF_VERSION = 0.1 +RNSF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rnsf) +RNSF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rnsf) + +RNSL_VERSION = 0.1 +RNSL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rnsl) +RNSL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rnsl) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +SARS_VERSION = 0.1 +SARS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sars) +SARS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sars) + +SBUF_VERSION = 0.1 +SBUF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sbuf) +SBUF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sbuf) + +SCK_VERSION = 0.1 +SCK_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sck) +SCK_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sck) + +SMSH_VERSION = 0.1 +SMSH_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags smsh) +SMSH_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs smsh) + +SSF_VERSION = 0.9 +SSF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags ssf) +SSF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs ssf) + +SUVM_VERSION = 0.3 +SUVM_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags suvm) +SUVM_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs suvm) + +SVX_VERSION = 0.3 +SVX_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags svx) +SVX_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs svx) + +DPDC_CFLAGS =\ + $(RNSF_CFLAGS)\ + $(RNSL_CFLAGS)\ + $(RSYS_CFLAGS)\ + $(SARS_CFLAGS)\ + $(SBUF_CFLAGS)\ + $(SCK_CFLAGS)\ + $(SMSH_CFLAGS)\ + $(SSF_CFLAGS)\ + $(SUVM_CFLAGS)\ + $(SVX_CFLAGS)\ + -fopenmp + +DPDC_LIBS =\ + $(RNSF_LIBS)\ + $(RNSL_LIBS)\ + $(RSYS_LIBS)\ + $(SARS_LIBS)\ + $(SBUF_LIBS)\ + $(SCK_LIBS)\ + $(SMSH_LIBS)\ + $(SSF_LIBS)\ + $(SUVM_LIBS)\ + $(SVX_LIBS)\ + -fopenmp\ + -lm + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +# Increase the security and robustness of generated binaries +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/doc/rngt.5.scd b/doc/rngt.5.scd @@ -1,71 +0,0 @@ -rngt(5) - -; Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique -; Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace -; Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris -; Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) -; Copyright (C) 2022, 2023 Observatoire de Paris -; Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne -; Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin -; Copyright (C) 2022, 2023 Université Paul Sabatier -; -; 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/>. - -# NAME - -rngt - Rad-Net Gas Temperatures - -# DESCRIPTION - -*rngt* is a binary file format for storing gas temperatures. The temperatures -are discretized according to the mesh of the gas. The mesh to which the -temperatures are attached is _not_ described there but must be defined in a -separate file, for example in an *smsh*(5) file. The number of temperatures and -their order must therefore correspond to the data of the mesh to which they are -attached, i.e. to the nodes|cells listed in the corresponding mesh. - -*rngt* file is actually a Star-Buffer file (see *sbuf*(5)). It starts with a -header of 4 64-bit integers describing the layout of the data. The first integer -is a power of two (usually 4096) that defines the size of the memory page in -bytes to which the list of temperatures aligns (_pagesize_). The second integer -is the _size_ of the array, i.e. the number of temperatures defined in the list. -Finally, the 2 remaining integers store the memory size (4 bytes) and the memory -alignment (4 bytes) of a temperature. - -Padding bytes follow the file header to align the listed temperatures to -_pagesize_. - -The end of the file is eventually padded with dummy bytes to ensure that the -overall file size is a multiple of _pagesize_. - -# BINARY FILE FORMAT - -Data are encoded with respect to the little endian bytes ordering, i.e. least -significant bytes are stored first. - -``` -<rngt> ::= <pagesize> <size> 4 4 - <padding> - <temperatures> - <padding> - -<pagesize> ::= UINT64 -<size> ::= UINT64 # Number of temperatures stored -<temperatures> ::= FLOAT ... # In K -<padding> ::= [ BYTE ... ] # Ensure alignement -``` - -# SEE ALSO - -*sbuf*(5), *smsh*(5) diff --git a/doc/rnpfi.5.scd b/doc/rnpfi.5.scd @@ -1,71 +0,0 @@ -rnpfi(5) - -; Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique -; Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace -; Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris -; Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) -; Copyright (C) 2022, 2023 Observatoire de Paris -; Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne -; Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin -; Copyright (C) 2022, 2023 Université Paul Sabatier -; -; 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/>. - -# NAME - -rnpfi - Rad-Net Phase Function Indices - -# DESCRIPTION - -*rnpfi* is a binary file format for storing a list of indices referring to phase -functions. The indices are attached to a volumetric mesh which is _not_ -described there but must be defined in a separate file, for example in an -*smsh*(5) file. The number of indices and their order must therefore correspond -to the data of the mesh to which they are attached, i.e. to the nodes|cells -listed in the corresponding mesh. - -*rnpfi* file is actually a Star-Buffer file (see *sbuf*(5)). It starts with a -header of 4 64-bit integers describing the layout of the data. The first integer -is a power of two (usually 4096) that defines the size of the memory page in -bytes to which the list of indices aligns (_pagesize_). The second integer is -the _size_ of the array, i.e. the number of indices defined in the list. -Finally, the 2 remaining integers store the memory size (4 bytes) and the memory -alignment (4 bytes) of an index. - -Padding bytes follow the file header to align the listed indices to -_pagesize_. - -The end of the file is eventually padded with dummy bytes to ensure that the -overall file size is a multiple of _pagesize_. - -# BINARY FILE FORMAT - -Data are encoded with respect to the little endian bytes ordering, i.e. least -significant bytes are stored first. - -``` -<rngt> ::= <pagesize> <size> 4 4 - <padding> - <indices> - <padding> - -<pagesize> ::= UINT64 -<size> ::= UINT64 # Number of indices stored -<indices> ::= UINT32 ... -<padding> ::= [ BYTE ... ] # Ensure alignement -``` - -# SEE ALSO - -*sbuf*(5), *smsh*(5) diff --git a/make.sh b/make.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique +# Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace +# Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris +# Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2022, 2023 Observatoire de Paris +# Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne +# Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin +# Copyright (C) 2022, 2023 Université Paul Sabatier +# +# 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/>. + +set -e + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/rnatm.pc.in b/rnatm.pc.in @@ -0,0 +1,19 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@, suvm >= @SUVM_VERSION@, svx >= @SVX_VERSION@ +Requires.private:\ + rnsl >= @RNSL_VERSION@,\ + rnsf >= @RNSF_VERSION@,\ + sars >= @SARS_VERSION@,\ + sbuf >= @SBUF_VERSION@,\ + sck >= @SCK_VERSION@,\ + smsh >= @SMSH_VERSION@,\ + ssf >= @SSF_VERSION@ +Name: rnatm +Description: Rad-Net ATMopshere +Version: @VERSION@ +Libs: -L${libdir} -lrnatm +Libs.private: -fopenmp -lm +CFlags: -I${includedir} diff --git a/rngt.5 b/rngt.5 @@ -0,0 +1,94 @@ +.\" Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique +.\" Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace +.\" Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris +.\" Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) +.\" Copyright (C) 2022, 2023 Observatoire de Paris +.\" Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne +.\" Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin +.\" Copyright (C) 2022, 2023 Université Paul Sabatier +.\" +.\" 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/>. +.Dd September 26, 2023 +.Dt RNGT 5 +.Os +.Sh NAME +.Nm rngt +.Nd Rad-Net Gas Temperatures +.Sh DESCRIPTION +.Nm +is a binary file format for storing gas temperatures. +The temperatures are discretized according to the mesh of the gas. +The mesh to which the temperatures are attached is +.Em not +described there but must be defined in a separate file, for example in an +.Xr smsh 5 +file. +The number of temperatures and their order must therefore correspond to +the data of the mesh to which they are attached, i.e. to the nodes or +cells listed in the corresponding mesh. +.Pp +A +.Nm +file is actually a Star-Buffer file +.Pq see Xr sbuf 5 . +It starts with a header of 4 integers. +The first integer is a power of two +.Pq usually 4096 +that defines the size of the memory page in bytes +.Pq Va pagesize +on which the list of temperatures are aligned. +By aligning data to pagesize, and depending on system requirements, +memory mapping can be used to automatically load/unload pages on demand +.Pq see Xr mmap 2 . +The second integer is the +.Va size +of the array, i.e. the number of temperatures stored in the list. +The two remaining integers store the memory size +.Pq 4 bytes +and the memory alignment +.Pq 4 bytes +of a temperature. +.Pp +Padding bytes follow the file header to align the listed temperatures to +.Va pagesize . +.Pp +Padding bytes are finally added at the end of the file to align its +overall size with the size of a page. +.Pp +Data are encoded with respect to the little endian bytes ordering, +i.e. least significant bytes are stored first. +.Pp +The file format is as follows: +.Bl -column (temperature) (::=) () +.It Ao Va rngt Ac Ta ::= Ta Ao Va pagesize Ac Ao Va size Ac Li 4 4 +.It Ta Ta Aq Va padding +.It Ta Ta Aq Va temperatures +.It Ta Ta Aq Va padding +.It Ao Va pagesize Ac Ta ::= Ta Vt uint64_t +.It Ao Va size Ac Ta ::= Ta Vt uint64_t +# Number of temperatures stored +.It Ao Va temperatures Ac Ta ::= Ta Vt float ... +# In K +.It Ao Va padding Ac Ta ::= Ta Op Vt int8_t ... +.El +.Sh SEE ALSO +.Xr mmap 2 , +.Xr sbuf 5 , +.Xr smsh 5 +.Sh HISTORY +The +.Nm +format was first developed for the +.Xr htrdr-planeto 1 +program. diff --git a/rnpfi.5 b/rnpfi.5 @@ -0,0 +1,93 @@ +.\" Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique +.\" Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace +.\" Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris +.\" Copyright (C) 2022, 2023 |Méso|Star>(contact@meso-star.com) +.\" Copyright (C) 2022, 2023 Observatoire de Paris +.\" Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne +.\" Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin +.\" Copyright (C) 2022, 2023 Université Paul Sabatier +.\" +.\" 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/>. +.Dd September 26, 2023 +.Dt RNPFI 5 +.Os +.Sh NAME +.Nm rnpfi +.Nd Rad-Net Phase Function Indices +.Sh DESCRIPTION +.Nm +is a binary file format for storing a list of indices referring to +phase functions. +The indices are attached to a volumetric mesh which is +.Em not +described there but must be defined in a separate file, for example in an +.Xr smsh 5 +file. +The number of indices and their order must therefore correspond to the +data of the mesh to which they are attached, i.e. to the nodes or cells +listed in the corresponding mesh. +.Pp +A +.Nm +file is actually a Star-Buffer file +.Pq see Xr sbuf 5 . +It starts with a header of 4 integers. +The first integer is a power of two +.Pq usually 4096 +that defines the size of the memory page in bytes +.Pq Va pagesize +on which the list of indices are aligned. +By aligning data to pagesize, and depending on system requirements, +memory mapping can be used to automatically load/unload pages on demand +.Pq see Xr mmap 2 . +The second integer is the +.Va size +of the array, i.e. the number of indices stored in the list. +The two remaining integers store the memory size +.Pq 4 bytes +and the memory alignment +.Pq 4 bytes +of an index. +.Pp +Padding bytes follow the file header to align the listed indices to +.Va pagesize . +.Pp +Padding bytes are finally added at the end of the file to align its +overall size with the size of a page. +.Pp +Data are encoded with respect to the little endian bytes ordering, +i.e. least significant bytes are stored first. +.Pp +The file format is as follows: +.Bl -column (pagesize) (::=) () +.It Ao Va rnpfi Ac Ta ::= Ta Ao Va pagesize Ac Ao Va size Ac Li 4 4 +.It Ta Ta Aq Va padding +.It Ta Ta Aq Va indices +.It Ta Ta Aq Va padding +.It Ao Va pagesize Ac Ta ::= Ta Vt uint64_t +.It Ao Va size Ac Ta ::= Ta Vt uint64_t +# Number of indices stored +.It Ao Va indices Ac Ta ::= Ta Vt uint32_t ... +.It Ao Va padding Ac Ta ::= Ta Op Vt int8_t ... +.El +.Sh SEE ALSO +.Xr mmap 2 , +.Xr sbuf 5 , +.Xr smsh 5 +.Sh HISTORY +The +.Nm +format was first developed for the +.Xr htrdr-planeto 1 +program. diff --git a/src/rnatm.h b/src/rnatm.h @@ -23,7 +23,6 @@ #ifndef RNATM_H #define RNATM_H -#include <star/s3d.h> #include <star/suvm.h> #include <star/svx.h> diff --git a/src/rnatm_c.h b/src/rnatm_c.h @@ -215,7 +215,7 @@ accel_struct_copy_and_release #define DARRAY_DATA struct accel_struct #define DARRAY_FUNCTOR_INIT accel_struct_init #define DARRAY_FUNCTOR_RELEASE accel_struct_release -#define DARRAY_FUNCTOR_COPY accel_struct_copy_and_release +#define DARRAY_FUNCTOR_COPY accel_struct_copy #define DARRAY_FUNCTOR_COPY_AND_RELEASE accel_struct_copy_and_release #include <rsys/dynamic_array.h> diff --git a/src/rnatm_mesh.c b/src/rnatm_mesh.c @@ -90,13 +90,16 @@ setup_uvm size_t* nvertices) { struct suvm_tetrahedral_mesh_args mesh_args = SUVM_TETRAHEDRAL_MESH_ARGS_NULL; + struct smsh_load_args smsh_load_args = SMSH_LOAD_ARGS_NULL; struct smsh_desc smsh_desc = SMSH_DESC_NULL; struct suvm_volume* volume = NULL; res_T res = RES_OK; ASSERT(atm && args && filename && suvm && smsh && out_volume); /* Load and retrieve the Star-Mesh data */ - res = smsh_load(smsh, filename); + smsh_load_args.path = filename; + smsh_load_args.memory_mapping = 0; + res = smsh_load(smsh, &smsh_load_args); if(res != RES_OK) goto error; res = smsh_get_desc(smsh, &smsh_desc); if(res != RES_OK) goto error; diff --git a/src/rnatm_octree.c b/src/rnatm_octree.c @@ -280,7 +280,7 @@ static FINLINE unsigned round_pow2(const unsigned val) { const unsigned next_pow2 = (unsigned)round_up_pow2(val); - if(next_pow2 - val <= next_pow2/4) { + if(val == 0 || next_pow2 - val <= next_pow2/4) { return next_pow2; } else { return next_pow2/2; @@ -1365,7 +1365,7 @@ create_octrees(struct rnatm* atm, const struct rnatm_create_args* args) const res_T res_local = voxelize_atmosphere(atm, pool, &sync); if(res_local != RES_OK) { log_err(atm, "error when voxelizing the atmosphere -- %s\n", - res_to_cstr((res_T)res)); + res_to_cstr((res_T)res_local)); pool_invalidate(pool); ATOMIC_SET(&res, res_local); } @@ -1375,7 +1375,8 @@ create_octrees(struct rnatm* atm, const struct rnatm_create_args* args) { const res_T res_local = build_octrees(atm, args, pool, &sync); if(res_local != RES_OK) { - log_err(atm, "error building octrees -- %s\n", res_to_cstr((res_T)res)); + log_err(atm, "error building octrees -- %s\n", + res_to_cstr((res_T)res_local)); pool_invalidate(pool); ATOMIC_SET(&res, res_local); } diff --git a/src/rnatm_properties.c b/src/rnatm_properties.c @@ -610,6 +610,7 @@ setup_gas_properties(struct rnatm* atm, const struct rnatm_gas_args* gas_args) { char buf[128]; struct time t0, t1; + struct sck_load_args sck_load_args = SCK_LOAD_ARGS_NULL; struct sck_band band_low = SCK_BAND_NULL; struct sck_band band_upp = SCK_BAND_NULL; struct sck_create_args sck_args = SCK_CREATE_ARGS_DEFAULT; @@ -651,7 +652,9 @@ setup_gas_properties(struct rnatm* atm, const struct rnatm_gas_args* gas_args) if(res != RES_OK) goto error; /* Load correlated-K */ - res = sck_load(atm->gas.ck, gas_args->sck_filename); + sck_load_args.path = gas_args->sck_filename; + sck_load_args.memory_mapping = 1; + res = sck_load(atm->gas.ck, &sck_load_args); if(res != RES_OK) goto error; res = check_gas_ck_desc(atm, gas_args); if(res != RES_OK) goto error; @@ -689,6 +692,7 @@ setup_aerosol_properties size_t ibands[2]; struct time t0, t1; struct sars_create_args sars_args = SARS_CREATE_ARGS_DEFAULT; + struct sars_load_args sars_load_args = SARS_LOAD_ARGS_NULL; struct sbuf_create_args sbuf_args = SBUF_CREATE_ARGS_DEFAULT; struct sbuf_desc sbuf_desc = SBUF_DESC_NULL; @@ -707,7 +711,9 @@ setup_aerosol_properties if(res != RES_OK) goto error; /* Load the aerosol radiative properties */ - res = sars_load(aerosol->sars, aerosol_args->sars_filename); + sars_load_args.path = aerosol_args->sars_filename; + sars_load_args.memory_mapping = 1; + res = sars_load(aerosol->sars, &sars_load_args); if(res != RES_OK) goto error; res = check_aerosol_sars_desc(atm, aerosol, aerosol_args); if(res != RES_OK) goto error; diff --git a/src/rnatm_radcoef.c b/src/rnatm_radcoef.c @@ -164,10 +164,6 @@ tetra_get_radcoef_aerosol lambda_min = MMAX(gas_band.lower, ars_band.lower); lambda_max = MMIN(gas_band.upper, ars_band.upper); /* exclusive */ lambda_max = nextafter(lambda_max, 0); /* inclusive */ - - /* Shrink lambda_<min|max> to the spectral range */ - lambda_min = MMAX(lambda_min, atm->spectral_range[0]); - lambda_max = MMIN(lambda_max, atm->spectral_range[1]); lambda_len = (float)(lambda_max - lambda_min); ASSERT(lambda_len > 0); diff --git a/src/rnatm_voxel_partition.c b/src/rnatm_voxel_partition.c @@ -122,6 +122,7 @@ partition_init partition->id = SIZE_MAX; partition->tile = NULL; partition->pool = pool; + partition->ref = 0; } static void @@ -251,11 +252,17 @@ partition_free(struct partition* partition) pool = partition->pool; - if(ATOMIC_DECR(&partition->ref) != 0) + /* The partition reference counter can be zero before being decremented: it is + * initialized to the voxel width once the partition has been commited. So, if + * the partition is released before any commit (for example, when it doesn't + * overlap the atmosphere grid), it can be negative after it has been + * decremented */ + if(ATOMIC_DECR(&partition->ref) > 0) return; /* The partition is still referenced */ mutex_lock(pool->mutex); list_move_tail(&partition->node, &pool->parts_free); /* Free the partition */ + partition->ref = 0; /* Reset to 0 rather than letting a negative value */ if(partition->tile) { /* Free the reserved tile */ list_move_tail(&partition->tile->node, &pool->tiles_free); partition->tile = NULL; diff --git a/src/test_rnatm.c b/src/test_rnatm.c @@ -318,7 +318,7 @@ args_init(struct args* args, int argc, char** argv) while((opt = getopt(argc, argv, "a:cd:g:hi:Nn:o:s:T:t:V:v")) != -1) { switch(opt) { case 'a': - sa_add(args->rnatm.aerosols, 1); + (void)sa_add(args->rnatm.aerosols, 1); args->rnatm.aerosols[args->rnatm.naerosols] = RNATM_AEROSOL_ARGS_NULL; args->rnatm.naerosols += 1; res = cstr_parse_list(optarg, ':', parse_aerosol_parameters, args);