htcp

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

commit 2cfc673dde0c06e7e2d818486b461ba5ac4487ed
parent 91d6974d3048b67014585c31f041bb9a4a4a6da9
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  4 Sep 2023 12:00:42 +0200

Update the dump_netcdf shell scripts

Make them executable and reinforce POSIX compliance: in the sed
directive, replace "*" with "\{0,\}" to notify a cardinality [0..n].

Diffstat:
Msrc/dump_netcdf_data.sh | 22++++++++++++----------
Msrc/dump_netcdf_desc.sh | 38++++++++++++++++++++++++++------------
2 files changed, 38 insertions(+), 22 deletions(-)

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