commit e131f6e67e45fee616d525b19a7b3d66d2a896a5
parent c36eaaccbf54c0becdb8928429284154dae25254
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 17 Jul 2018 11:20:13 +0200
Push further the htcp_load_from_file test
Test the data dimensions
Diffstat:
4 files changed, 95 insertions(+), 9 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -75,7 +75,8 @@ if(NOT NO_TEST)
set(VAR_LISTS RVT RCT PABST THT)
- set(_script ${HTCP_SOURCE_DIR}/dump_netcdf_data.sh)
+ 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)
@@ -90,20 +91,28 @@ if(NOT NO_TEST)
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} ${_var} ${_netcdf})
+ 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} les2htcp-${_file}.nc
+ DEPENDS ${_script_data}
COMMENT "${_file}.nc: dump raw data"
VERBATIM)
- add_custom_target(dump-${_file}.nc ALL DEPENDS ${_ref_files})
+ 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})
diff --git a/src/dump_netcdf_data.sh b/src/dump_netcdf_data.sh
@@ -18,13 +18,13 @@ set -e
set -o pipefail
if [ $# -lt 2 ]; then
- echo "Usage: $0 VAR-NAME LES-NETCDF "
- exit 0
+ >&2 echo "Usage: $0 VAR-NAME LES-NETCDF "
+ exit -1
fi
if [ ! -f $2 ]; then
- echo "\"$2\" is not a valid file."
- exit 0
+ >&2 echo "\"$2\" is not a valid file."
+ exit -1
fi
name=$(basename $2)
diff --git a/src/dump_netcdf_desc.sh b/src/dump_netcdf_desc.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>. */
+set -e
+set -o pipefail
+
+if [ $# -lt 1 ]; then
+ >&2 echo "Usage: $0 -NAME LES-NETCDF "
+ 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/p')
+ny=$(echo $dimensions | sed -n 's/^.*S_N_direction *= *\([0-9]\+\) *;.*$/\1/p')
+nz=$(echo $dimensions | sed -n 's/^.*vertical_levels *= *\([0-9]\+\) *;.*$/\1/p')
+ntimes=$(echo $dimensions | sed -n 's/^.*time *= *\([0-9]\+\) *;.*$/\1/p')
+
+if [ -z "$ntimes" ]; then
+ ntimes=$(echo $dimensions | sed -n 's/^.*time *=.*\/\/ *(\([0-9]\+\) currently).*$/\1/p')
+fi
+
+if [ -z "$nx" -o -z "$ny" -o -z "$nz" -o -z "$ntimes" ]; then
+ >&2 echo $0: Error retrieving the dimensions of \"$1\"
+ exit -1
+fi
+
+name=$(basename $1)
+name=${name%.*}
+{
+ echo $nx
+ echo $ny
+ echo $nz
+ echo $ntimes
+} > ${name}_desc
diff --git a/src/test_htcp_load_from_file.c b/src/test_htcp_load_from_file.c
@@ -38,6 +38,34 @@ THT_to_T(const double THT, const size_t i /*Id of THT*/, const void* ctx)
}
static void
+check_descriptor
+ (const struct htcp_desc* desc,
+ const char* path, /* Path where the reference values are */
+ const char* basename) /* Basename of the reference files */
+{
+ char buf[128];
+ double nx, ny, nz, ntimes;
+ FILE* fp = NULL;
+ size_t i;
+
+ printf("Check the descriptor\n");
+
+ CHK(desc && path && basename);
+
+ i = (size_t)snprintf(buf, sizeof(buf), "%s/%s_desc", path, basename);
+ CHK(i < sizeof(buf));
+ CHK(fp = fopen(buf, "r"));
+ CHK(fscanf(fp, "%lg %lg %lg %lg", &nx, &ny, &nz, &ntimes) == 4);
+ CHK(fscanf(fp, "%*g") == EOF);
+ CHK(fclose(fp) == 0);
+
+ CHK(desc->spatial_definition[0] == nx);
+ CHK(desc->spatial_definition[1] == ny);
+ CHK(desc->spatial_definition[2] == nz);
+ CHK(desc->time_definition == ntimes);
+}
+
+static void
check_variable
(const double* loaded_data,
const size_t ndata,
@@ -93,9 +121,10 @@ main(int argc, char** argv)
CHK(htcp_get_desc(htcp, &desc) == RES_OK);
/* Compute the basename of the ref file from the submitted htcp file */
+ base = filename;
p = strrchr(filename, '/');
if(p) base = p+1;
- p = strrchr(base, '.');
+ p = strrchr(filename, '.');
if(p) *p = '\0';
n = desc.spatial_definition[0]
@@ -103,6 +132,7 @@ main(int argc, char** argv)
* desc.spatial_definition[2]
* desc.time_definition;
+ check_descriptor(&desc, path, base);
check_variable(desc.RVT, n, "RVT", path, base, NULL, NULL);
check_variable(desc.RCT, n, "RCT", path, base, NULL, NULL);
check_variable(desc.PABST, n, "PABST", path, base, NULL, NULL);