htcp

Properties of water suspended in clouds
git clone git://git.meso-star.fr/htcp.git
Log | Files | Refs | README | LICENSE

commit dc4d18a225627f81b9f0b36687964e51f9d23449
parent 408588259eaa2c257937a04dbb3c4f8f0108f07d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 30 Oct 2023 15:09:53 +0100

Merge branch 'feature_posix_make' into develop

Diffstat:
M.gitignore | 19+++++++++++--------
AMakefile | 187+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 64++++++++++++++++++++++++++++++++--------------------------------
Dcmake/CMakeLists.txt | 131-------------------------------------------------------------------------------
Dcmake/doc/CMakeLists.txt | 60------------------------------------------------------------
Dcmake/htcp/CMakeLists.txt | 62--------------------------------------------------------------
Dcmake/les2htcp/CMakeLists.txt | 66------------------------------------------------------------------
Dcmake/les2htcp/FindNetCDF.cmake | 119-------------------------------------------------------------------------------
Aconfig.mk | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ddoc/htcp.5.scd | 98-------------------------------------------------------------------------------
Ddoc/les2htcp.1.scd | 131-------------------------------------------------------------------------------
Ahtcp.5 | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ahtcp.pc.in | 10++++++++++
Ales2htcp.1 | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/dump_netcdf_data.sh | 22++++++++++++----------
Msrc/dump_netcdf_desc.sh | 38++++++++++++++++++++++++++------------
Msrc/les2htcp.c | 68+++++++++++++++++++++++++++-----------------------------------------
Msrc/les2htcp.h.in | 18+++++++++---------
Asrc/test_htcp_load_from_file.sh | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
20 files changed, 816 insertions(+), 779 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,13 +1,16 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp +*.nc +*.htcp [Bb]uild* *.sw[po] -*.[ao] -*.orig +*.[aod] +*.so *~ +test* +!test*.[ch] +.config +.test tags -*.nc -*.htcp +*.pc +src/les2htcp.h +les2htcp diff --git a/Makefile b/Makefile @@ -0,0 +1,187 @@ +# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018 Centre National de la Recherche Scientifique +# Copyright (C) 2018 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 = libhtcp.a +LIBNAME_SHARED = libhtcp.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Library/program building +################################################################################ +SRC = src/htcp.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +default: build_library build_program + +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) + +build_program: .config src/les2htcp.d build_library + @$(MAKE) -fMakefile -fsrc/les2htcp.d les2htcp + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS) + +$(LIBNAME_STATIC): libhtcp.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libhtcp.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +src/les2htcp.d src/les2htcp.o: config.mk + +src/les2htcp.c: src/les2htcp.h +src/les2htcp.h: src/les2htcp.h.in + sed -e 's#@VERSION_MAJOR@#$(VERSION_MAJOR)#g' \ + -e 's#@VERSION_MINOR@#$(VERSION_MINOR)#g' \ + -e 's#@VERSION_PATCH@#$(VERSION_PATCH)#g' \ + src/les2htcp.h.in > $@ + +les2htcp: src/les2htcp.o + $(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(NETCDF_CFLAGS) \ + -o $@ src/les2htcp.o $(LDFLAGS_EXE) $(RSYS_LIBS) $(NETCDF_LIBS) -lm + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(NETCDF_VERSION) netcdf; then \ + echo "netcdf $(NETCDF_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -DHTCP_SHARED_BUILD -c $< -o $@ + +src/les2htcp.d: src/les2htcp.c + @$(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(NETCDF_CFLAGS) -MM -MT "$(@:.d=.o) $@" \ + src/les2htcp.c -MF $@ + +src/les2htcp.o: src/les2htcp.c + $(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(NETCDF_CFLAGS) -c src/les2htcp.c -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + htcp.pc.in > htcp.pc + +htcp-local.pc: htcp.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + htcp.pc.in > $@ + +install: build_library build_program pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" les2htcp + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" htcp.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/high_tune" src/htcp.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/htcp" COPYING README.md + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man1" les2htcp.1 + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" htcp.5 + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/bin/les2htcp" + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/htcp.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/htcp/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/htcp/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/high_tune/htcp.h" + rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/les2htcp.1" + rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/htcp.5" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_program build_tests + +clean: clean_test + rm -f $(OBJ) src/les2htcp.o $(TEST_OBJ) $(LIBNAME) les2htcp + rm -f .config .test libhtcp.o htcp.pc htcp-local.pc + +distclean: clean + rm -f $(DEP) src/les2htcp.d src/les2htcp.h $(TEST_DEP) + +lint: + shellcheck -o all make.sh + shellcheck -o all src/dump_netcdf_data.sh + shellcheck -o all src/dump_netcdf_desc.sh + shellcheck -o all src/test_htcp_load_from_file.sh + mandoc -Tlint -Wall les2htcp.1 || [ $$? -le 1 ] + mandoc -Tlint -Wall htcp.5 || [ $$? -le 1 ] + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_htcp.c\ + src/test_htcp_load.c\ + src/test_htcp_load_from_file.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +HTCP_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags htcp-local.pc) +HTCP_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs htcp-local.pc) + +test: build_tests build_program + @$(SHELL) make.sh run_test src/test_htcp.c src/test_htcp_load.c + +build_tests: build_library $(TEST_DEP) .test + @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin + +.test: Makefile make.sh + @$(SHELL) make.sh config_test $(TEST_SRC) > $@ + +clean_test: + $(SHELL) make.sh clean_test $(TEST_SRC) + +$(TEST_DEP): config.mk htcp-local.pc + @$(CC) $(CFLAGS_EXE) $(HTCP_CFLAGS) $(RSYS_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ): config.mk htcp-local.pc + $(CC) $(CFLAGS_EXE) $(HTCP_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + +test_htcp \ +test_htcp_load \ +test_htcp_load_from_file \ +: config.mk htcp-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(HTCP_LIBS) $(RSYS_LIBS) -lm diff --git a/README.md b/README.md @@ -1,32 +1,32 @@ # High-Tune: Cloud Properties -This project describes the htcp binary fileformat that is used to store the -some properties of a cloud. The provided `les2htcp` command line tool extracts -these properties from a LES output stored in a -[NetCDF](https://www.unidata.ucar.edu/software/netcdf/) file, and converts them -in the `htcp` fileformat. Finally, a library is provided to load the `htcp` -fileformat. Since the data to load can be huge, this library silently -loads/unloads them dynamically allowing to process data that are too large to -fit in the main memory. - -## How to build - -The `les2htcp` program and `htcp` library are compatible GNU/Linux 64-bits. -They rely on the [CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) packages to build. They also depend -on the [RSys](https://gitlab.com/vaplv/rsys/) library. Furthermore, the -`les2htcp` tool depends on the -[NetCDF](https://www.unidata.ucar.edu/software/netcdf/) C library. -Both eventually depend on [scdoc](https://sr.ht/~sircmpwn/scdoc/) -which, if available, is used to generate the man pages. - -To build them, 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](https://cmake.org/documentation) for further -informations on CMake. +This project defines a file format for storing the properties of liquid water +suspended in clouds. See `htcp.5` for the format specification. A C library is +provided for loading files in this format. + +To facilitate interoperability, the `les2htcp` tool converts data to htcp +format from a [netCDF](https://www.unidata.ucar.edu/software/netcdf/) file. +While the netCDF format is widely adopted there is no standard or common +practice for describing cloud properties, whether in terms of data layout, +variable names or units. The htcp format was developed to circumvent this +problem: it is a simple file format, independent of netCDF-based data +formatting, leaving data conversion to third-party translation tools. +`les2htcp` is one such tool. See `les2htcp.1` for a complete descritpion. + +## Requirements + +- C compiler +- POSIX make +- pkg-config +- netCDF4 +- [RSys](https://gitlab.com/vaplv/rsys) +- [mandoc](https://mandoc.bsd.lv) + +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes @@ -52,18 +52,18 @@ mixing ratio and the liquid water mixing ratio. ### Version 0.0.1 -- Fix warnings and compilation errors when using the NetCDF library in version +- Fix warnings and compilation errors when using the netCDF library in version 4.4.0. - Fix compilation errors on systems with GNU C library version less than 2.19. -## Copyright notice +## Copyright -Copyright (C) 2018, 2020-2023 |Méso|Star> (<contact@meso-star.com>) -Copyright (C) 2018 Centre National de la Recherche Scientifique +Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +Copyright (C) 2018 Centre National de la Recherche Scientifique Copyright (C) 2018 Université Paul Sabatier ## License `htcp` and `les2htcp` are free software released under the GPL v3+ license: GNU -GPL version 3 or later. You are welcome to redistribute it under certain +GPL version 3 or later. You are welcome to redistribute them under certain conditions; refer to the COPYING file for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,131 +0,0 @@ -# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2018 Centre National de la Recherche Scientifique -# Copyright (C) 2018 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(htcp) -enable_testing() - -option(NO_TEST "Do not build tests" OFF) - -set(HTCP_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -set(NETCDF_PATH ${PROJECT_SOURCE_DIR}/../ CACHE PATH - "Path where the NetCDF test files are stored.") - -################################################################################ -# Prerequisites -################################################################################ -find_package(RCMake 0.3 REQUIRED) -find_package(RSys 0.6 REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories(${RSys_INCLUDE_DIR}) - -if(CMAKE_COMPILER_IS_GNUCC) - set(MATH_LIB m) -endif() - -################################################################################ -# Test utilities -################################################################################ -if(NOT NO_TEST) - function(build_test _name) - add_executable(${_name} - ${HTCP_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} htcp ${ARGN}) - endfunction() - - function(new_test _name) - build_test(${_name}) - add_test(${_name} ${_name}) - endfunction() -endif() - -################################################################################ -# Sub projects -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 0) -set(VERSION_PATCH 5) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -add_subdirectory(doc) -add_subdirectory(htcp) -add_subdirectory(les2htcp) - -################################################################################ -# Test both the les2htcp utility and the htcp library. -################################################################################ -if(NOT NO_TEST) - build_test(test_htcp_load_from_file ${MATH_LIB}) - - set(TEST_FILES - CEN2D.1.ARMCU.008.diaKCL - CERK4.1.ARMCu.008 - DZVAR.1.ARMCU.008.diaKCL - L25km.1.ARMCU.008.diaKCL - L51km.1.ARMCu.008) - - set(VAR_LISTS RVT RCT PABST THT) - - set(_script_data ${HTCP_SOURCE_DIR}/dump_netcdf_data.sh) - set(_script_desc ${HTCP_SOURCE_DIR}/dump_netcdf_desc.sh) - foreach(_file IN LISTS TEST_FILES) - set(_netcdf ${NETCDF_PATH}/${_file}.nc) - - if(EXISTS ${_netcdf}) - set(_output_base ${CMAKE_CURRENT_BINARY_DIR}/${_file}) - - add_custom_command( - OUTPUT ${_output_base}.htcp - COMMAND les2htcp -m 1000 -i ${_netcdf} -fo ${_output_base}.htcp - DEPENDS les2htcp - COMMENT "${_file}.nc: convert to HTCP fileformat" - VERBATIM) - add_custom_target(les2htcp-${_file}.nc ALL DEPENDS ${_output_base}.htcp) - - add_custom_command( - OUTPUT ${_output_base}_desc - COMMAND sh ${_script_desc} ${_netcdf} - DEPENDS ${_script_desc} - COMMENT "${_file}.nc: dump descriptor" - VERBATIM) - add_custom_target(dump-desc-${_file}.nc ALL DEPENDS ${_output_base}_desc) - - set(_ref_files) - set(_cmds) - foreach(_var IN LISTS VAR_LISTS) - set(_cmds ${_cmds} COMMAND sh ${_script_data} ${_var} ${_netcdf}) - set(_ref_files ${_ref_files} ${_output_base}_${_var}) - endforeach() - - add_custom_command( - OUTPUT ${_ref_files} - ${_cmds} - DEPENDS ${_script_data} - COMMENT "${_file}.nc: dump raw data" - VERBATIM) - add_custom_target(dump-data-${_file}.nc ALL DEPENDS ${_ref_files}) - - add_test(test_htcp_load_from_file_${_file} - test_htcp_load_from_file ${_output_base}.htcp ${CMAKE_CURRENT_BINARY_DIR}) - endif() - endforeach() -endif() - diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt @@ -1,60 +0,0 @@ -# Copyright (C) 2018, 2020-2022 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2018 Centre National de la Recherche Scientifique -# Copyright (C) 2018 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(HTCP_DOC_DIR ${PROJECT_SOURCE_DIR}/../doc) - -################################################################################ -# Look for the a2x program -################################################################################ -find_program(SCDOC NAMES scdoc) -if(NOT SCDOC) - message(WARNING - "The `scdoc' program is missing. " - "The High-Tune Cloud Properties man pages cannot be generated.") - return() -endif() - -################################################################################ -# ROFF man pages -################################################################################ -set(MAN_NAMES htcp.5 les2htcp.1) -set(MAN5_FILES) -set(MAN1_FILES) - -foreach(_man IN LISTS MAN_NAMES) - set(_src ${HTCP_DOC_DIR}/${_man}.scd) - add_custom_command( - OUTPUT ${_man} - COMMAND ${SCDOC} < ${_src} > ${_man} - DEPENDS ${_src} - COMMENT "Build ROFF man page ${_man}" - VERBATIM) - list(APPEND MAN_FILES ${_man}) - - string(REGEX MATCH "^.*.5$" _man5 ${_man}) - string(REGEX MATCH "^.*.1$" _man1 ${_man}) - if(_man1) - list(APPEND MAN1_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_man1}) - elseif(_man5) - list(APPEND MAN5_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_man5}) - else() - message(FATAL_ERROR "Unexpected man type") - endif() -endforeach() -add_custom_target(man-roff ALL DEPENDS ${MAN_NAMES}) -install(FILES ${MAN1_FILES} DESTINATION share/man/man1) -install(FILES ${MAN5_FILES} DESTINATION share/man/man5) diff --git a/cmake/htcp/CMakeLists.txt b/cmake/htcp/CMakeLists.txt @@ -1,62 +0,0 @@ -# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2018 Centre National de la Recherche Scientifique -# Copyright (C) 2018 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(htcp-library C) - -################################################################################ -# Configure and define targets -################################################################################ -set(HTCP_FILES_SRC htcp.c) -set(HTCP_FILES_INC ) -set(HTCP_FILES_INC_API htcp.h) -set(HTCP_FILES_DOC COPYING) - -# Prepend each file in the `HTCP_FILES_<SRC|INC>' list by `HTCP_SOURCE_DIR' -rcmake_prepend_path(HTCP_FILES_SRC ${HTCP_SOURCE_DIR}) -rcmake_prepend_path(HTCP_FILES_INC ${HTCP_SOURCE_DIR}) -rcmake_prepend_path(HTCP_FILES_INC_API ${HTCP_SOURCE_DIR}) -rcmake_prepend_path(HTCP_FILES_DOC ${PROJECT_SOURCE_DIR}/../../) - -add_library(htcp SHARED ${HTCP_FILES_SRC} ${HTCP_FILES_INC} ${HTCP_FILES_INC_API}) -target_link_libraries(htcp RSys) - -set_target_properties(htcp PROPERTIES - DEFINE_SYMBOL HTCP_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -rcmake_setup_devel(htcp HTCP ${VERSION} high_tune/htcp_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - new_test(test_htcp) - new_test(test_htcp_load) -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS htcp - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${HTCP_FILES_INC_API} DESTINATION include/high_tune) -install(FILES ${HTCP_FILES_DOC} DESTINATION share/doc/htcp) - diff --git a/cmake/les2htcp/CMakeLists.txt b/cmake/les2htcp/CMakeLists.txt @@ -1,66 +0,0 @@ -# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2018 Centre National de la Recherche Scientifique -# Copyright (C) 208 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(les2htcp C) - -# Required by netcdf.h header that some versions contains C99 comments -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89") - -################################################################################ -# Check dependencies -################################################################################ -get_filename_component(_current_source_dir ${CMAKE_CURRENT_LIST_FILE} PATH) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${_current_source_dir}) - -find_package(NetCDF REQUIRED) - -include_directories( - ${NETCDF_C_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR}) - -################################################################################ -# Generate files -################################################################################ -configure_file(${HTCP_SOURCE_DIR}/les2htcp.h.in - ${CMAKE_CURRENT_BINARY_DIR}/les2htcp.h @ONLY) - -################################################################################ -# Configure and define targets -################################################################################ -set(LES2HTCP_FILES_SRC les2htcp.c) -set(LES2HTCP_FILES_INC les2htcp.h.in) -set(LES2HTCP_FILES_DOC COPYING) - -# Prepend each file in the `HTNC_FILES_<SRC|INC>' list by `HTCP_SOURCE_DIR' -rcmake_prepend_path(LES2HTCP_FILES_SRC ${HTCP_SOURCE_DIR}) -rcmake_prepend_path(LES2HTCP_FILES_INC ${HTCP_SOURCE_DIR}) -rcmake_prepend_path(LES2HTCP_FILES_DOC ${PROJECT_SOURCE_DIR}/../../) - -add_executable(les2htcp ${LES2HTCP_FILES_SRC}) -target_link_libraries(les2htcp RSys ${NETCDF_C_LIBRARIES} m) - -set_target_properties(les2htcp PROPERTIES - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS les2htcp RUNTIME DESTINATION bin) -install(FILES ${LES2HTCP_FILES_DOC} DESTINATION share/doc/les2htcp) - diff --git a/cmake/les2htcp/FindNetCDF.cmake b/cmake/les2htcp/FindNetCDF.cmake @@ -1,119 +0,0 @@ -# - Find NetCDF -# Find the native NetCDF includes and library -# -# NETCDF_INCLUDE_DIR - user modifiable choice of where netcdf headers are -# NETCDF_LIBRARY - user modifiable choice of where netcdf libraries are -# -# Your package can require certain interfaces to be FOUND by setting these -# -# NETCDF_CXX - require the C++ interface and link the C++ library -# NETCDF_F77 - require the F77 interface and link the fortran library -# NETCDF_F90 - require the F90 interface and link the fortran library -# -# Or equivalently by calling FindNetCDF with a COMPONENTS argument containing one or -# more of "CXX;F77;F90". -# -# When interfaces are requested the user has access to interface specific hints: -# -# NETCDF_${LANG}_INCLUDE_DIR - where to search for interface header files -# NETCDF_${LANG}_LIBRARY - where to search for interface libraries -# -# This module returns these variables for the rest of the project to use. -# -# NETCDF_FOUND - True if NetCDF found including required interfaces (see below) -# NETCDF_LIBRARIES - All netcdf related libraries. -# NETCDF_INCLUDE_DIRS - All directories to include. -# NETCDF_HAS_INTERFACES - Whether requested interfaces were found or not. -# NETCDF_${LANG}_INCLUDE_DIRS/NETCDF_${LANG}_LIBRARIES - C/C++/F70/F90 only interface -# -# Normal usage would be: -# set (NETCDF_F90 "YES") -# find_package (NetCDF REQUIRED) -# target_link_libraries (uses_everthing ${NETCDF_LIBRARIES}) -# target_link_libraries (only_uses_f90 ${NETCDF_F90_LIBRARIES}) - -#search starting from user editable cache var -if (NETCDF_INCLUDE_DIR AND NETCDF_LIBRARY) - # Already in cache, be silent - set (NETCDF_FIND_QUIETLY TRUE) -endif () - -set(USE_DEFAULT_PATHS "NO_DEFAULT_PATH") -if(NETCDF_USE_DEFAULT_PATHS) - set(USE_DEFAULT_PATHS "") -endif() - -find_path (NETCDF_INCLUDE_DIR netcdf.h - PATHS "${NETCDF_DIR}/include") -mark_as_advanced (NETCDF_INCLUDE_DIR) -set (NETCDF_C_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR}) - -find_library (NETCDF_LIBRARY NAMES netcdf - PATHS "${NETCDF_DIR}/lib" - HINTS "${NETCDF_INCLUDE_DIR}/../lib") -mark_as_advanced (NETCDF_LIBRARY) - -set (NETCDF_C_LIBRARIES ${NETCDF_LIBRARY}) - -#start finding requested language components -set (NetCDF_libs "") -set (NetCDF_includes "${NETCDF_INCLUDE_DIR}") - -get_filename_component (NetCDF_lib_dirs "${NETCDF_LIBRARY}" PATH) -set (NETCDF_HAS_INTERFACES "YES") # will be set to NO if we're missing any interfaces - -macro (NetCDF_check_interface lang header libs) - if (NETCDF_${lang}) - #search starting from user modifiable cache var - find_path (NETCDF_${lang}_INCLUDE_DIR NAMES ${header} - HINTS "${NETCDF_INCLUDE_DIR}" - HINTS "${NETCDF_${lang}_ROOT}/include" - ${USE_DEFAULT_PATHS}) - - find_library (NETCDF_${lang}_LIBRARY NAMES ${libs} - HINTS "${NetCDF_lib_dirs}" - HINTS "${NETCDF_${lang}_ROOT}/lib" - ${USE_DEFAULT_PATHS}) - - mark_as_advanced (NETCDF_${lang}_INCLUDE_DIR NETCDF_${lang}_LIBRARY) - - #export to internal varS that rest of project can use directly - set (NETCDF_${lang}_LIBRARIES ${NETCDF_${lang}_LIBRARY}) - set (NETCDF_${lang}_INCLUDE_DIRS ${NETCDF_${lang}_INCLUDE_DIR}) - - if (NETCDF_${lang}_INCLUDE_DIR AND NETCDF_${lang}_LIBRARY) - list (APPEND NetCDF_libs ${NETCDF_${lang}_LIBRARY}) - list (APPEND NetCDF_includes ${NETCDF_${lang}_INCLUDE_DIR}) - else () - set (NETCDF_HAS_INTERFACES "NO") - message (STATUS "Failed to find NetCDF interface for ${lang}") - endif () - endif () -endmacro () - -list (FIND NetCDF_FIND_COMPONENTS "CXX" _nextcomp) -if (_nextcomp GREATER -1) - set (NETCDF_CXX 1) -endif () -list (FIND NetCDF_FIND_COMPONENTS "F77" _nextcomp) -if (_nextcomp GREATER -1) - set (NETCDF_F77 1) -endif () -list (FIND NetCDF_FIND_COMPONENTS "F90" _nextcomp) -if (_nextcomp GREATER -1) - set (NETCDF_F90 1) -endif () -NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++) -NetCDF_check_interface (F77 netcdf.inc netcdff) -NetCDF_check_interface (F90 netcdf.mod netcdff) - -#export accumulated results to internal varS that rest of project can depend on -list (APPEND NetCDF_libs "${NETCDF_C_LIBRARIES}") -set (NETCDF_LIBRARIES ${NetCDF_libs}) -set (NETCDF_INCLUDE_DIRS ${NetCDF_includes}) - -# handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if -# all listed variables are TRUE -include (FindPackageHandleStandardArgs) -find_package_handle_standard_args (NetCDF - DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDE_DIRS NETCDF_HAS_INTERFACES) diff --git a/config.mk b/config.mk @@ -0,0 +1,85 @@ +VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_PATCH = 5 +VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) +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)) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +NETCDF_VERSION = 4 +NETCDF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags netcdf) +NETCDF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs netcdf) + +################################################################################ +# 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/htcp.5.scd b/doc/htcp.5.scd @@ -1,98 +0,0 @@ -htcp(5) - -; Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) -; Copyright (C) 2018 Centre National de la Recherche Scientifique -; Copyright (C) 2018 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 - -htcp - High-Tune: Cloud Properties file format - -# DESCRIPTION - -*htcp* is a binary file format that describes properties on liquid water -content in suspension within clouds. The *les2htcp*(1) command can be used to -generate a *htcp* file from cloud properties saved in a NetCDF file format. - -The cloud properties are actually spatio temporal double precision floating -point data, structured in a 4D grid whose definition and spatial origin is -given by the _<definition>_ and the _<lower-pos>_ fields. The size of a grid -cell along the X and Y dimension is constant while the size along the Z axis -can be irregular. Is such case, the _<is-Z-irregular>_ header flag is set to 1 -and the sizes of the cells in Z are explicitly listed in _<voxel-size>_. Note -that in *htcp*, the spatial dimensions are defined in meters, i.e. values -listed in _<lower-pos>_ and _<voxel-size>_ are meters. - -For a given property, the list of its spatio temporal data are linearly listed -along the X, Y, Z and time dimension, in that order. The address where its -first data is stored is aligned on the value defined by the file header field -_<pagesize>_; several bytes of padding can be thus added priorly to a property -in order to ensure that its first data is correctly aligned. - -Available cloud properties are: - -- _<RVT>_: water vapor mixing ratio in kg of water per m^3 of dry air. -- _<RCT>_: liquid water in suspension mixing ratio in kg of water per m^3 of dry - air. -- _<PABST>_: pressure in Pascal. -- _<T>_: temperature in Kelvin. - -# BINARY FILE FORMAT - -Data are encoded with respect to the little endian bytes ordering, i.e. least -significant bytes are stored first. - -``` -<htcp> ::= <header> - <definition> - <lower-pos> - <voxel-size> - <padding> - <RVT> - <padding> - <RCT> - <padding> - <PABST> - <padding> - <T> - <padding> - -<header> ::= <pagesize> <is-Z-irregular> -<definition> ::= <X> <Y> <Z> <time> # Spatial and temporal definition -<lower-pos> ::= DOUBLE DOUBLE DOUBLE # Spatial origin of the grid -<voxel-size> ::= DOUBLE DOUBLE # Size of a cell in X and Y - DOUBLE [ DOUBLE ... ] # Size of the cells in Z - -<pagesize> ::= INT64 -<is-Z-irregular> - ::= INT8 - -<X> ::= INT32 -<Y> ::= INT32 -<Z> ::= INT32 -<time> ::= INT32 - -<RVT> ::= DOUBLE [ DOUBLE ... ] # Water vapor mixing ratio -<RCT> ::= DOUBLE [ DOUBLE ... ] # Liquid water in suspension mixing ratio -<PABST> ::= DOUBLE [ DOUBLE ... ] # Pressure -<T> ::= DOUBLE [ DOUBLE ... ] # Temperature - -<padding> ::= [ BYTE ... ] -``` - -# SEE ALSO - -*les2htcp*(1) diff --git a/doc/les2htcp.1.scd b/doc/les2htcp.1.scd @@ -1,131 +0,0 @@ -les2htcp(1) - -; Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) -; Copyright (C) 2018 Centre National de la Recherche Scientifique -; Copyright (C) 2018 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 - -les2htcp - convert cloud properties from NetCDF to htcp(5) file format - -# SYNOPSIS - -les2htcp [_option_] ... -i _NetCDF_ - -# DESCRIPTION -*les2htcp* generates a *htcp*(5) file from cloud properties stores in a NetCDF -file [1]. Expected variables in the submitted NetCDF file are: - -- _W_E_direction_ *and* _S_N_direction_: one dimensional list of position of the - center of each cell along the West-East and South-North horizontal axis, - respectively. This should be a homogeneous mesh: each cell should have the - same width along each axis. The unit is assumed to be the meter but it can - be adjusted by the *-m* option. -- _VLEV_ *or* _vertical_levels_: position of the center of each cell along the - vertical axis. The vertical mesh can possibly be inhomogeneous: each cell - can have different vertical extent. At least one of this variable must be - defined. Note that _VLEV_ is a four dimensional variable while - _vertical_levels_ is assumed to be one dimensional. In all cases, *les2htcp* - assumes that the vertical columns are the same for each cell along the - West-East and South-North axis. The unit is assumed to be the meter but it - can be adjusted by the *-m* option. -- _RVT_: water vapor mixing ratio in each grid cell; in kg of water per kg of - air. -- _RCT_: liquid water (in suspension) mixing ratio in each grid cell; in kg of - water per kg of dry air. -- _PABST_: pressure in each grid cell in Pascal. -- _THT_: potential temperature in each grid cell in Kelvin. - -# OPTIONS - -*-c* - Advanced checks on the validity of the submitted _NetCDF_ file with respect - to the *les2htcp* prerequisites on the NetCDF data. Note that this option - can increase significantly the conversion time. - -*-f* - Force overwrite of the _output_ file. - -*-h* - List short help and exit. - -*-i* _NetCDF_ - NetCDF file to convert. - -*-m* _float-to-meter_ - Scale factor from floating point unit to meters. By default it is set to 1. - -*-o* _output_ - Destination file where the *htcp*(5) file is written. If not defined, the - results are written to standard output. - -*-p* _page-size_ - Targeted page size in bytes; must be a power of 2. The size of the converted - NetCDF data and their starting address into the *htcp*(5) file are aligned - according to _page-size_. By default, _page-size_ is 4096 bytes. - -*-q* - Write nothing to _output_. Might be used in conjunction of the *-c* option - to only check the submitted _NetCDF_. - -*-v* - Display version information and exit. - -# EXAMPLES - -Convert the _clouds.nc_ NetCDF file. Write the resulting *htcp*(5) file in -_cloud.htcp_ excepted if the file already exists; in this case an error is -notified, the program stops and the _cloud.htcp_ file remains unchanged: - -``` -les2htcp -i clouds.nc -o clouds.htcp -``` - -Convert the _clouds_km.nc_ file to *htcp*(5) file format. Use the *-f* option -to write the output file _clouds.htcp_ even though it already exists. The -_clouds_km.nc_ file to convert has its spatial unit in kilo-meters while the -*htcp*(5) file format assumes meters: use the *-m* _1000_ option to map -kilo-meters to meters: - -``` -les2htcp -i clouds_km.nc -m 1000 -o clouds.htcp -``` - -Check that the submitted _clouds.nc_ file is valid regarding the -*les2htcp* constraints. Use the *-q* option to disable the generation of -output data: - -``` -les2htcp -c -i clouds.nc -q -``` - -# COPYRIGHT - -Copyright © 2018, 2020 |Méso|Star> <contact@meso-star.com>++ -Copyright © 2018 Centre National de la Recherche Scientifique++ -Copyright © 2018 Université Paul Sabatier <contact-edstar@laplace.univ-tlse.fr> - -# LICENSE - -*les2htcp* is free software released under the GPLv3+ license: GNU GPL version -3 or later <https://gnu.org/licenses/gpl.html>. You are free to change and -redistribute it. There is NO WARRANTY, to the extent permitted by law. - -# SEE ALSO - -. Network Common Data Form - <https://www.unidata.ucar.edu/software/netcdf/> - -*htcp*(5) diff --git a/htcp.5 b/htcp.5 @@ -0,0 +1,112 @@ +.\" Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +.\" Copyright (C) 2018 Centre National de la Recherche Scientifique +.\" Copyright (C) 2018 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 4, 2023 +.Dt HTCP 5 +.Os +.Sh NAME +.Nm htcp +.Nd High-Tune: Cloud Properties +.Sh DESCRIPTION +.Nm +is a binary file format for storing the properties of liquid water content +suspended in clouds. +Cloud properties are double-precision spatio-temporal floating-point values, +structured in a 4D grid whose definition and origin are stored in the +.Va definition +and +.Va lower-pos +fields. +The size of a grid cell can be irregular. +In such case, the +.Va is-Z-irregular +flag is set to 1 and the sizes of the cells in Z are explicitly listed in +.Va voxel-size +.Pq in meters . +The size of a grid cell along the X and Y axes is constant, whereas the size +along the Z axis may be irregular. +In this case, the +.Va is-Z-irregular +flag is set to 1 and the Z cell size is explicitly indicated in +.Va voxel-size +.Pq in meters . +.Pp +For each property, the list of its data is enumerated linearly along the X, Y, +Z and time dimensions, in that order. +The address where its first data is stored is aligned with the value defined by +the +.Va pagesize +field; several padding bytes can therefore be added before a property to ensure +data alignment. +Padding bytes are also added at the end of the file to align its overall size +with the size of a page. +.Pp +The stored cloud properties are as follows: +.Bl -dash -offset indent -compact +.It +.Va RVT : +water vapor mixing ratio in kg of water per m^3 of dry air. +.It +.Va RCT : +liquid water in suspension mixing ratio in kg of water per m^3 of dry air. +.It +.Va PABST : +pressure in Pascal. +.It +.Va T : +temperature in Kelvin. +.El +.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 (is-Z-irregular) (::=) () +.It Ao Va htcp Ac Ta ::= Ta Ao Va pagesize Ac Ao Va is-Z-irregular Ac +.It Ta Ta Aq Va definition +.It Ta Ta Aq Va lower-pos +.It Ta Ta Aq Va voxel-size +.It Ta Ta Aq Va padding +.It Ta Ta Aq Va RVT +.It Ta Ta Aq Va padding +.It Ta Ta Aq Va RCT +.It Ta Ta Aq Va padding +.It Ta Ta Aq Va PABST +.It Ta Ta Aq Va padding +.It Ta Ta Aq Va T +.It Ta Ta Aq Va padding +.It \ Ta Ta +.It Ao Va pagesize Ac Ta ::= Ta Vt uint64_t +.It Ao Va is-Z-irregular Ac Ta ::= Ta Vt int8_t +.It \ Ta Ta +.It Ao Va definition Ac Ta ::= Ta Ao Va X Ac Ao Va Y Ac Ao Va Z Ac Ao Va time Ac +.It Ao Va lower-pos Ac Ta ::= Ta Vt double double double +# In m +.It Ao Va voxel-size Ac Ta ::= Ta Vt double double double ... +# In m +.It Ao Va X Ac Ta ::= Ta Vt uint32_t +.It Ao Va Y Ac Ta ::= Ta Vt uint32_t +.It Ao Va Z Ac Ta ::= Ta Vt uint32_t +.It Ao Va time Ac Ta ::= Ta Vt uint32_t +.It \ Ta Ta +.It Ao Va RVT Ac Ta ::= Ta Vt double ... +.It Ao Va RCT Ac Ta ::= Ta Vt double ... +.It Ao Va PABST Ac Ta ::= Ta Vt double ... +.It Ao Va T Ac Ta ::= Ta Vt double ... +.It Ao Va padding Ac Ta ::= Ta Op Vt int8_t ... +.El +.Sh SEE ALSO +.Xr les2htcp 1 diff --git a/htcp.pc.in b/htcp.pc.in @@ -0,0 +1,10 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Name: htcp +Description: High-Tune Cloud Properties +Version: @VERSION@ +Libs: -L${libdir} -lhtcp +CFlags: -I${includedir} diff --git a/les2htcp.1 b/les2htcp.1 @@ -0,0 +1,177 @@ +.\" Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +.\" Copyright (C) 2018 Centre National de la Recherche Scientifique +.\" Copyright (C) 2018 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 5, 2023 +.Dt LES2HTCP 1 +.Os +.Sh NAME +.Nm les2htcp +.Nd convert cloud properties from netCDF to +.Xr htcp 5 +.Sh SYNOPSIS +.Nm +.Op Fl cfhqv +.Op Fl m Ar float_to_meter +.Op Fl o Ar output +.Op Fl p Ar pagesize +.Fl i Ar netcdf +.Sh DESCRIPTION +.Nm +generates a +.Xr htcp 5 +file from cloud properties stored in a netCDF file. +The variables expected in the submitted netCDF file are: +.Bl -dash -offset indent +.It +.Va W_E_direction +and +.Va S_N_direction : +one-dimensional list of the position at the center of each cell along the +west-east and south-north horizontal axis, respectively. +The mesh must be homogeneous: each cell must have the same width along each +axis. +The unit is assumed to be meters, but this can be adjusted via +the +.Fl m +option. +.It +.Va VLEV +or +.Va vertical_levels : +position at the center of each cell along the vertical axis. +The vertical mesh can be inhomogeneous, i.e. each cell can have a different +vertical extent. +At least one of these variables must be defined. +Note that +.Va VLEV +is a four-dimensional variable, whereas +.Va vertical_levels +is assumed to be one-dimensional. +In all cases +.Nm +assumes that the vertical columns are +the same for each cell along the west-east and south-north axes. +The unit is assumed to be meters, but this can be adjusted via the +.Fl m +option. +.It +.Va RCT : +mixing ratio of liquid suspended water in each grid cell; in kg of water per kg +of dry air. +.It +.Va PABST : +pressure in each grid cell in Pascal. +.It +.Va THT : +potential temperature in each grid cell in Kelvin. +.El +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl c +Advanced checks of the validity of the input +.Ar netcdf +file against +.Nm +prerequisites on netCDF data. +Note that this option can significantly increase conversion time. +.It Fl f +Forces overwriting of +.Ar output +file. +.It Fl h +Display short help. +.It Fl i Ar netcdf +netCDF file to convert. +.It Fl m Ar float_to_meter +Scale factor to be applied to floating-point number +.Li 1.0 to convert it to meters. By default, it is set to +.Li 1 . +.It Fl o Ar output +Output file. +If not defined, data is written to standard output. +.It Fl p Ar pagesize +Page size in bytes on which htcp data will be aligned. +It must be a power of 2 and greater than or equal to the size of a system page, +which is the default value +.Pq see Xr sysconf 3 . +.It Fl q +Writes nothing to the output. +Can be used in conjunction with the +.Fl c +option to check only the validity of the input netCDF. +.It Fl v +Display the version number and exit. +.El +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +Convert the netCDF +.Pa clouds.nc +file. +The resulting +.Xr htcp 5 +file is stored in the +.Pa cloud.htcp +file unless it already exists; in this case, an error is notified, the program +stops and the +.Pa cloud.htcp +file remains unchanged: +.Pp +.Dl les2htcp -i clouds.nc -o clouds.htcp +.Pp +Converts netCDF file +.Pa clouds_km.nc +to +.Xr htcp 5 +format. +Use the +.Fl f +option to write the output file +.Pa clouds.htcp +even if it already exists. +The input file to be converted has its spatial unit in kilo-meters, whereas the +htcp file format assumes meters; use the +.Fl m Ar 1000 +option to perform the conversion: +.Pp +.Dl les2htcp -i clouds_km.nc -m 1000 -o clouds.htcp +.Pp +Check that the netCDF file +.Pa clouds.nc +is a valid input file for +.Nm . +Use the +.Fl q +option to disable file conversion: +.Pp +.Dl les2htcp -c -i clouds.nc -q +.Sh SEE ALSO +.Xr htrdr 1 , +.Xr sysconf 3 , +.Xr htcp 5 +.Sh STANDARDS +.Rs +.%A Edward Hartnett +.%D March 2011 +.%R ESDS-RFC-022v1 +.%T netCDF4/HDF5 File Format +.Re +.Sh HISTORY +.Nm +has been developed to generate cloud properties as input to the +.Xr htrdr 1 +program. diff --git a/make.sh b/make.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018 Centre National de la Recherche Scientifique +# Copyright (C) 2018 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 + +config_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + test_list="${test_list} ${test}" + printf "%s: %s\n" "${test}" "src/${test}.o" + done + printf "test_bin: %s\n" "${test_list}" +} + +run_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + + printf "%s " "${test}" + if "./${test}" > /dev/null 2>&1; then + printf "\033[1;32mOK\033[m\n" + else + printf "\033[1;31mError\033[m\n" + fi + done 2> /dev/null +} + + +clean_test() +{ + for i in "$@"; do + rm -f "$(basename "${i}" ".c")" + done +} + +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/src/dump_netcdf_data.sh b/src/dump_netcdf_data.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/bin/sh -e -# Copyright (C) 2018, 2020-2022 |Méso|Star> (contact@meso-star.com) -# Copyright (C) CNRS, Université Paul Sabatier +# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018 Centre National de la Recherche Scientifique +# Copyright (C) 2018 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 @@ -19,21 +20,22 @@ set -e if [ $# -lt 2 ]; then - >&2 echo "Usage: $0 VAR-NAME LES-NETCDF " + printf "usage: %s variable netcdf\n" "${0##*/}" >&2 exit 1 fi if [ ! -f "$2" ]; then - >&2 echo "\"$2\" is not a valid file." + printf "\"%s\" is not a valid file\n" "$2" >&2 exit 1 fi name=$(basename "$2") name=${name%.*} +blanks="[[:blank:]]\{0,\}" ncdump -v "$1" "$2" \ - | sed -n "/^ *$1 *=/,\$p" \ - | sed "s/^ *$1 *= *//g" \ - | sed 's/[;} ]//g' \ - | sed 's/,/\n/g' \ - | sed '/^ *$/d' > "${name}_${1}" + | sed -n "/^${blanks}$1${blanks}=/,\$p" \ + | sed "s/^${blanks}$1${blanks}=${blanks}//g" \ + | sed "s/[;} ]//g" \ + | sed "s/,/\n/g" \ + | sed "/^${blanks}$/d" > "${name}_${1}" diff --git a/src/dump_netcdf_desc.sh b/src/dump_netcdf_desc.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/bin/sh -e -# Copyright (C) 2018, 2020-2022 |Méso|Star> (contact@meso-star.com) -# Copyright (C) CNRS, Université Paul Sabatier +# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018 Centre National de la Recherche Scientifique +# Copyright (C) 2018 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 @@ -18,22 +19,35 @@ set -e if [ $# -lt 1 ]; then - >&2 printf "Usage: %s -NAME LES-NETCDF\n" "$0" + printf "usage: %s variable netcdf\n" "${0##*/}" >&2 exit 1 fi -dimensions=$(ncdump -h "$1" | sed '/^ *variables/,$d' | sed '1,2d') -nx=$(echo "${dimensions}" | sed -n 's/^.*W_E_direction *= *\([0-9]\{1,\}\) *;.*$/\1/p') -ny=$(echo "${dimensions}" | sed -n 's/^.*S_N_direction *= *\([0-9]\{1,\}\) *;.*$/\1/p') -nz=$(echo "${dimensions}" | sed -n 's/^.*vertical_levels *= *\([0-9]\{1,\}\) *;.*$/\1/p') -ntimes=$(echo "${dimensions}" | sed -n 's/^.*time *= *\([0-9]\{1,\}\) *;.*$/\1/p') + +b="[[:blank:]]\{0,\}" # Blanks +c=".\{0,\}" # Any chars + +dimensions=$(ncdump -h "$1" | sed "/^${b}variables/,\$d" | sed '1,2d') +nx=$(echo "${dimensions}" | \ + sed -n "s/^${c}W_E_direction${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p") +ny=$(echo "${dimensions}" | \ + sed -n "s/^${c}S_N_direction${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p") +nz=$(echo "${dimensions}" | \ + sed -n "s/^${c}vertical_levels${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p") +ntimes=$(echo "${dimensions}" | \ + sed -n "s/^${c}time${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p") if [ -z "${ntimes}" ]; then - ntimes=$(echo "${dimensions}" | sed -n 's/^.*time *=.*\/\/ *(\([0-9]\{1,\}\) currently).*$/\1/p') + ntimes=$(echo "${dimensions}" | \ + sed -n "s/^${c}time${b}=${c}\/\/${b}(\([0-9]\{1,\}\) currently)${c}$/\1/p") fi -if [ -z "${nx}" ] || [ -z "${ny}" ] || [ -z "${nz}" ] || [ -z "${ntimes}" ]; then - >&2 printf "%s: Error retrieving the dimensions of \"%s\"\n" "$0" "$1" +if [ -z "${nx}" ] \ +|| [ -z "${ny}" ] \ +|| [ -z "${nz}" ] \ +|| [ -z "${ntimes}" ] +then + >&2 printf "%s: error retrieving the dimensions of \"%s\"\n" "$0" "$1" exit 1 fi diff --git a/src/les2htcp.c b/src/les2htcp.c @@ -28,7 +28,7 @@ #include <errno.h> #include <netcdf.h> #include <string.h> -#include <unistd.h> /* getopt */ +#include <unistd.h> /* getopt, sysconf */ #include <fcntl.h> /* open */ #include <sys/stat.h> /* S_IRUSR & S_IWUSR */ @@ -45,46 +45,15 @@ struct args { int no_output; int quit; /* Quit the application */ }; -#define ARGS_DEFAULT__ {NULL,NULL,1.0,4096,0,0,0,0} +#define ARGS_DEFAULT__ {NULL,NULL,1.0,-1,0,0,0,0} static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; -static void -print_help(const char* cmd) +static INLINE void +usage(const char* cmd) { ASSERT(cmd); - (void)cmd; - - printf( -"Usage: les2htcp -i INPUT [OPTIONS]\n" -"Convert the LES data stored into INPUT from NetCDF to the htcp fileformat.\n\n"); - printf( -" -c advanced check of the validity of the submitted LES file.\n"); - printf( -" -f overwrite the OUTPUT file if it already exists.\n"); - printf( -" -h display this help and exit.\n"); - printf( -" -i INPUT path of the LES file to convert.\n"); - printf( -" -m FLT_TO_METER scale factor to convert from floating point units to\n" -" meters. By default, it is set to %g.\n", - ARGS_DEFAULT.fp_to_meter); - printf( -" -o OUTPUT write results to OUTPUT. If not defined, write results to\n" -" standard output.\n"); - printf( -" -p targeted page size in bytes. Must be a power of 2. By\n" -" default, the page size is %li Bytes.\n", - ARGS_DEFAULT.pagesize); - printf( -" -q do not write results to OUTPUT.\n"); - printf( -" -v display version information and exit.\n"); - printf("\n"); - printf( -"les2htcp is free software released under the GNU GPL license, version 3 or\n" -"later. You are free to change or redistribute it under certain conditions\n" -"<http://gnu.org/licenses/gpl.html>\n"); + printf("usage: %s [-cfhqv] [-m float_to_meter] [-o output] [-p pagesize] " + "-i netcdf\n", cmd); } static void @@ -97,16 +66,26 @@ args_release(struct args* args) static res_T args_init(struct args* args, const int argc, char** argv) { + long system_pagesize; int opt; res_T res = RES_OK; ASSERT(args && argc && argv); + system_pagesize = sysconf(_SC_PAGESIZE); + if(system_pagesize == -1) { + fprintf(stderr, + "Error when querying the size of a system page -- %s\n", + strerror(errno)); + res = RES_BAD_OP; + goto error; + } + while((opt = getopt(argc, argv, "cfhi:m:o:p:qv")) != -1) { switch(opt) { case 'c': args->check = 1; break; case 'f': args->force_overwrite = 1; break; case 'h': - print_help(argv[0]); + usage(argv[0]); args_release(args); args->quit = 1; goto exit; @@ -119,14 +98,15 @@ args_init(struct args* args, const int argc, char** argv) case 'p': res = cstr_to_long(optarg, &args->pagesize); if(res == RES_OK && !IS_POW2(args->pagesize)) res = RES_BAD_ARG; + if(res == RES_OK && args->pagesize < system_pagesize) res = RES_BAD_ARG; break; case 'q': args->no_output = 1; break; case 'v': printf("%s %d.%d.%d\n", argv[0], - LES2HTLES_VERSION_MAJOR, - LES2HTLES_VERSION_MINOR, - LES2HTLES_VERSION_PATCH); + LES2HTCP_VERSION_MAJOR, + LES2HTCP_VERSION_MINOR, + LES2HTCP_VERSION_PATCH); args->quit = 1; goto exit; default: res = RES_BAD_ARG; break; @@ -148,9 +128,15 @@ args_init(struct args* args, const int argc, char** argv) if(args->no_output) args->output = NULL; + /* Use the default page size if not explicitly defined by the caller. */ + if(args->pagesize < system_pagesize) { + args->pagesize = system_pagesize; + } + exit: return res; error: + usage(argv[0]); args_release(args); goto exit; } diff --git a/src/les2htcp.h.in b/src/les2htcp.h.in @@ -1,6 +1,6 @@ -/* Copyright (C) 2018, 2020-2022 |Méso|Star> (contact@meso-star.com) - * Copyright (C) 2018 CNRS - * Copyright (C) 2018 Université Paul Sabatier (contact-edstar@laplace.univ-tlse.fr) +/* Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2018 Centre National de la Recherche Scientifique + * Copyright (C) 2018 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 @@ -15,12 +15,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef LES2HTLES_H -#define LES2HTLES_H +#ifndef LES2HTCP_H +#define LES2HTCP_H -#define LES2HTLES_VERSION_MAJOR @VERSION_MAJOR@ -#define LES2HTLES_VERSION_MINOR @VERSION_MINOR@ -#define LES2HTLES_VERSION_PATCH @VERSION_PATCH@ +#define LES2HTCP_VERSION_MAJOR @VERSION_MAJOR@ +#define LES2HTCP_VERSION_MINOR @VERSION_MINOR@ +#define LES2HTCP_VERSION_PATCH @VERSION_PATCH@ -#endif /* LES2HTLES_H */ +#endif /* LES2HTCP_H */ diff --git a/src/test_htcp_load_from_file.sh b/src/test_htcp_load_from_file.sh @@ -0,0 +1,55 @@ +#!/bin/sh -e + +# Copyright (C) 2018, 2020-2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018 Centre National de la Recherche Scientifique +# Copyright (C) 2018 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/>. */ + +dump_data() { + variable="$1" + netcdf="$2" + printf "Dump the variable \"%s\" from \"%s\"\n" "${variable}" "${netcdf}" + dump_netcdf_data.sh "${variable}" "${netcdf}" +} + +if [ $# -ne 1 ]; then + printf "usage: %s netcdf\n" "${0##*/}" >&2 + exit 1 +fi + +nc="$1" + +if [ ! -f "${nc}" ]; then + printf "Invalid netcdf: %s\n" "${nc}" >&2 + exit 1 +fi + +prefix=$(basename "${nc}") +prefix=${prefix%.*} +htcp="${prefix}.htcp" +path=$(pwd) + +printf "Convert \"%s\" to \"%s\"\n" "${nc}" "${htcp}" +les2htcp -m 1000 -i "${nc}" -fo "${htcp}" + +printf "Dump the descriptor of \"%s\"\n" "${nc}" +dump_netcdf_desc.sh "${nc}" + +dump_data "PABST" "${nc}" +dump_data "RCT" "${nc}" +dump_data "RVT" "${nc}" +dump_data "THT" "${nc}" + +test_htcp_load_from_file "${prefix}.htcp" "${path}"