rnsf

Define and load a phase function data format
git clone git://git.meso-star.fr/rnsf.git
Log | Files | Refs | README | LICENSE

commit 545fe60a698243e8cfb31f26b2d7ae8d3761c160
parent 577e49b95738db8fba014b1d4c5c6002efa4bc98
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 31 Oct 2023 12:05:50 +0100

Merge branch 'feature_posix_make' into develop

Diffstat:
M.gitignore | 14+++++++-------
AMakefile | 161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 33+++++++++++++++------------------
Dcmake/CMakeLists.txt | 129-------------------------------------------------------------------------------
Aconfig.mk | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ddoc/rnsf.5.scd | 138-------------------------------------------------------------------------------
Amake.sh | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arnsf.5 | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arnsf.pc.in | 11+++++++++++
9 files changed, 495 insertions(+), 292 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,161 @@ +# 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 = librnsf.a +LIBNAME_SHARED = librnsf.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Library building +################################################################################ +SRC = src/rnsf.c src/rnsf_fetch_phase_fn.c src/rnsf_log.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) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS) -lm + +$(LIBNAME_STATIC): librnsf.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +librnsf.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_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) -DRNSF_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + rnsf.pc.in > rnsf.pc + +rnsf-local.pc: rnsf.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'\ + rnsf.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rnsf.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rad-net" src/rnsf.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rnsf" COPYING README.md + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" rnsf.5 + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rnsf.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnsf/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnsf/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/rad-net/rnsf.h" + rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rnsf.5" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) + rm -f .config .test librnsf.o rnsf.pc rnsf-local.pc + +distclean: clean + rm -f $(DEP) $(TEST_DEP) + +lint: + shellcheck -o all make.sh + mandoc -Tlint -Wall rnsf.5 || [ $$? -le 1 ] + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_rnsf.c\ + src/test_rnsf_bands.c\ + src/test_rnsf_wlens.c\ + src/test_rnsf_load.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +RNSF_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rnsf-local.pc) +RNSF_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rnsf-local.pc) + +test: build_tests + @$(SHELL) make.sh check test_rnsf + @$(SHELL) make.sh check test_rnsf_bands + @$(SHELL) make.sh check test_rnsf_wlens + +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_file_bands.rnsf + +$(TEST_DEP): config.mk rnsf-local.pc + @$(CC) $(CFLAGS_EXE) $(RNSF_CFLAGS) $(RSYS_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ): config.mk rnsf-local.pc + $(CC) $(CFLAGS_EXE) $(RNSF_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + +test_rnsf \ +test_rnsf_bands \ +test_rnsf_wlens \ +test_rnsf_load \ +: config.mk rnsf-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RNSF_LIBS) $(RSYS_LIBS) diff --git a/README.md b/README.md @@ -1,31 +1,28 @@ # Rad-Net Scattering Functions -This project defines a file format used to describe spectrally varying phase -functions and provides a C library for this file format. +This C library loads a set of phase functions stored in rnsf format. +See `rnsf.5` for format specification. -## How to build +## Requirements -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 [RSys](https://gitlab.com/vaplv/rsys/) library. It optionally depends on -[scdoc](https://sr.ht/~sircmpwn/scdoc/) which, if available, is used to -generate the man page of the file format. +- C compiler +- POSIX make +- pkg-config +- [RSys](https://gitlab.com/vaplv/rsys) +- [mandoc](https://mandoc.bsd.lv) -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. +## Installation -## Copyright notice +Edit config.mk as needed, then run: + + make clean install + +## 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 diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,129 +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(rnsf C) -enable_testing() - -set(RNSF_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Do not build tests" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.9 REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories(${RSys_INCLUDE_DIR}) - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 0) -set(VERSION_PATCH 0) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(RNSF_FILES_SRC - rnsf.c - rnsf_fetch_phase_fn.c - rnsf_log.c) -set(RNSF_FILES_INC - rnsf_c.h - rnsf_log.h - rnsf_phase_fn.h) -set(RNSF_FILES_INC_API rnsf.h) -set(RNSF_FILES_DOC COPYING README.md) - -# Prepend each file in the `RNSF_FILES_<SRC|INC>' list by `RNSF_SOURCE_DIR' -rcmake_prepend_path(RNSF_FILES_SRC ${RNSF_SOURCE_DIR}) -rcmake_prepend_path(RNSF_FILES_INC ${RNSF_SOURCE_DIR}) -rcmake_prepend_path(RNSF_FILES_INC_API ${RNSF_SOURCE_DIR}) -rcmake_prepend_path(RNSF_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_library(rnsf SHARED ${RNSF_FILES_SRC} ${RNSF_FILES_INC} ${RNSF_FILES_INC_API}) -target_link_libraries(rnsf RSys m) - -set_target_properties(rnsf PROPERTIES - DEFINE_SYMBOL RNSF_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -rcmake_setup_devel(rnsf RNSF ${VERSION} rad-net/rnsf_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - function(build_test _name) - add_executable(${_name} - ${RNSF_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} rnsf RSys) - endfunction() - - function(new_test _name) - build_test(${_name}) - add_test(${_name} ${_name}) - endfunction() - - new_test(test_rnsf) - new_test(test_rnsf_bands) - new_test(test_rnsf_wlens) - - build_test(test_rnsf_load) -endif() - -################################################################################ -# Man pages -############################################################################### -find_program(SCDOC NAMES scdoc) -if(NOT SCDOC) - message(WARNING - "The `scdoc' program is missing. " - "The rnsf man page cannot be generated.") -else() - set(_src ${PROJECT_SOURCE_DIR}/../doc/rnsf.5.scd) - add_custom_command( - OUTPUT rnsf.5 - COMMAND ${SCDOC} < ${_src} > rnsf.5 - DEPENDS ${_src} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Buid ROFF man page rnsf.5" - VERBATIM) - add_custom_target(man-roff ALL DEPENDS rnsf.5) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rnsf.5 DESTINATION share/man/man5) -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS rnsf - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${RNSF_FILES_INC_API} DESTINATION include/rad-net) -install(FILES ${RNSF_FILES_DOC} DESTINATION share/doc/rnsf) - diff --git a/config.mk b/config.mk @@ -0,0 +1,77 @@ +VERSION = 0.0.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)) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +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/rnsf.5.scd b/doc/rnsf.5.scd @@ -1,138 +0,0 @@ -rnsf(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 - -rnsf - Rad-Net Scattering Functions file format - -# DESCRIPTION - -*rnsf* is a text file format that describes a phase function whose type and -parameters can vary spectrally. Its data are described for a set of wavelengths -or spectral bands that must be listed in ascending order. - -Characters behind the hash mark (#) are considered comments and are therefore -ignored, as well as empty lines, i.e. lines without any characters or composed -only of spaces and tabs. - -# GRAMMAR - -``` -<rnsf> ::= <per-wlen-phase-func> - | <per-band-pĥase-func> - ---- - -<per-wlen-phase-func> ::= wavelengths <wavelengths-count> - <wlen-phase-func> - [ <wlen-phase-func> ... ] - -<wlen-phase-func> ::= <wavelength> <phase-func> -<wavelengths-count> ::= INTEGER -<wavelength> ::= REAL # In nanometers - ---- - -<per-band-phase-func> ::= bands <bands-count> - <band-phase-func> - [ <band-phase-func ... ] - -<wlen-band-func> ::= <wavelength-min> <wavelength-max> <phase-func> - -<bands-count> ::= INTEGER -<wavelength-min> ::= REAL # Inclusive bound in nanometers -<wavelength-max> ::= REAL # Inlcusive bound in nanometers - ---- - -<phase-func> ::= <phase-func-HG> - | <phase-func-discrete> - -<phase-func-HG> ::= HG <asymmetric-param> -<asymmetric-param> ::= REAL # in [-1, 1] - -<phase-func-discrete> ::= discrete <angles-count> - 0 <value> - [ <per-angle-value> ... ] # In ascending order wrt the angle - 3.14159 <value> -<per-angle-value> ::= <theta> <value> -<theta> ::= REAL # In radian -<value> ::= REAL # Not necessarily normalized - -``` - -# EXAMPLES - -Spectrally varying phase function on two spectral bands: a band for the visible -part of the spectrum for which a Henyey & Greenstein phase function is used, and -a band for long waves with a discretized phase function on 4 angles: - -``` -bands 2 - -# Visible part -380 780 HG 0 - -# Inrared -1000 100000 discrete 4 - 0 0.079577 - 0.78 0.079577 - 2.35 0.079577 - 3.14159 0.079577 -``` - -Setup a phase function for a set of 10 wavelengths. Use a discrete phase -function for short waves and Henyey & Greenstein for long waves: - -``` -wavelengths 10 - -# Short waves -430 discrete 8 - 0 0.02 - 0.23 0.04 - 0.5 0.07 - 0.7 0.15 - 1.54 1.23 - 1.8 0.02 - 2 1.23 - 3.14159 0.79 -450 discrete 2 - 0 0.5 - 3.14159 0.796 -750 discrete 4 - 0 0.079577 - 0.78 0.079577 - 2.35 0.079577 - 3.14159 0.079577 - -# Long waves -1100 HG -0.1 -1300 HG 0.57 -1400 HG 0.4 -2100 HG 0.3 -2500 HG -0.9 -2900 HG -0.4 -100000 HG 0.0 -``` diff --git a/make.sh b/make.sh @@ -0,0 +1,76 @@ +#!/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 + +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}" +} + +check() +{ + prog="$1" + shift 1 + + printf "%s " "${prog}" + if ./"${prog}" "$@" > /dev/null 2>&1; then + printf "\033[1;32mOK\033[m\n" + else + printf "\033[1;31mError\033[m\n" + fi +} + +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/rnsf.5 b/rnsf.5 @@ -0,0 +1,148 @@ +.\" 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 15, 2023 +.Dt RNSF 5 +.Os +.Sh NAME +.Nm rnsf +.Nd Rad-Net Scattering Functions file format +.Sh DESCRIPTION +.Nm +is a text file format that describes a phase function whose type and parameters +can vary spectrally. +Its data are described for a set of wavelengths or spectral bands that must be +listed in ascending order. +.Pp +Characters behind the hash mark +.Pq Li # +are considered comments and are therefore ignored, as well as empty lines, +i.e. lines without any characters or composed only of spaces and tabs. +.Pp +The file format is as follows: +.Bl -column (per-band-phase-func) (::=) () +.It Ao Va rnsf Ac Ta ::= Ta Ao Va per-wlen-phase-func Ac | +.Ao Va per-band-phase-func Ac +.It \ Ta Ta +.It Ao Va per-wlen-phase-func Ac Ta ::= Ta +.Li wavelengths +.Aq Va wavelengths-count +.It Ta Ta Aq Va wlen-phase-func +.It Ta Ta Va ... +.It Ao Va wlen-phase-func Ac Ta ::= Ta Ao Va wavelength Ac Ao Va phase-func Ac +.It Ao Va wavelengths-count Ac Ta ::= Ta Va integer +.It Ao Va wavelength Ac Ta ::= Ta Va real +# In nanometers +.It \ Ta Ta +.It Ao Va per-band-phase-func Ac Ta ::= Ta +.Li bands +.Aq Va bands-count +.It Ta Ta Aq Va band-phase-func +.It Ta Ta Va ... +.It Ao Va band-phase-func Ac Ta ::= Ta +.Aq Va length-min +.Aq Va length-max +.Aq Va phase-func +.It Ao Va bands-count Ac Ta ::= Ta Va integer +.It Ao Va length-min Ac Ta ::= Ta Va real +# Inclusive bound in nanometers +.It Ao Va length-max Ac Ta ::= Ta Va real +# Inclusive bound in nanometers +.It \ Ta Ta +.It Ao Va phase-func Ac Ta ::= Ta Ao Va phase-func-HG Ac | +.Ao Va phase-func-discrete Ac +.It \ Ta Ta +.It Ao Va phase-func-HG Ac Ta ::= Ta Li HG Aq Va asymmetric-param +.It Ao Va asymmetric-param Ac Ta ::= Ta Va real +# In +.Bq -1, 1 +.It \ Ta Ta +.It Ao Va phase-func-discrete Ac Ta ::= Ta Li discrete Aq Va angles-count +.It Ta Ta Li 0 Aq Va value +.It Ta Ta Op Ao Va pair Ac Va ... +# Ascending angles +.It Ta Ta Li 3.14159 Aq Va value +.It Ao Va angles-count Ac Ta ::= Ta Va integer +# Must be >= 2 +.It Ao Va pair Ac Ta ::= Ta Ao Va theta Ac Ao Va value Ac +.It Ao Va theta Ac Ta ::= Ta Va real +# In radians +.It Ao Va value Ac Ta ::= Ta Va real +# Not necessarily normalized +.El +.Sh EXAMPLES +Spectrally varying phase function on two spectral bands: a band for the visible +part of the spectrum for which a Henyey & Greenstein phase function is used, +and a band for long waves with a discretized phase function on 4 angles: +.Bd -literal -offset Ds +bands 2 + +# Visible part +380 780 HG 0 + +# Inrared +1000 100000 discrete 4 + 0 0.079577 + 0.78 0.079577 + 2.35 0.079577 + 3.14159 0.079577 +.Ed +.Pp +Phase function for a set of 10 wavelengths. +Use a discrete phase function for short waves and Henyey & Greenstein for long +waves: +.Bd -literal -offset Ds +wavelengths 10 + +# Short waves +430 discrete 8 + 0 0.02 + 0.23 0.04 + 0.5 0.07 + 0.7 0.15 + 1.54 1.23 + 1.8 0.02 + 2 1.23 + 3.14159 0.79 +450 discrete 2 + 0 0.5 + 3.14159 0.796 +750 discrete 4 + 0 0.079577 + 0.78 0.079577 + 2.35 0.079577 + 3.14159 0.079577 + +# Long waves +1100 HG -0.1 +1300 HG 0.57 +1400 HG 0.4 +2100 HG 0.3 +2500 HG -0.9 +2900 HG -0.4 +100000 HG 0.0 +.Ed +.Sh HISTORY +The +.Nm +format was first developed for the +.Xr htrdr-planeto 1 +program. diff --git a/rnsf.pc.in b/rnsf.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Name: rnsf +Description: Rad-Net Scattering Functions +Version: @VERSION@ +Libs: -L${libdir} -lrnsf +Libs.private: -lm +CFlags: -I${includedir}