htcp

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

dump_netcdf_desc.sh (1912B)


      1 #!/bin/sh -e
      2 
      3 # Copyright (C) 2018, 2020-2023, 2025 |Méso|Star> (contact@meso-star.com)
      4 # Copyright (C) 2018 Centre National de la Recherche Scientifique
      5 # Copyright (C) 2018 Université Paul Sabatier
      6 #
      7 # This program is free software: you can redistribute it and/or modify
      8 # it under the terms of the GNU General Public License as published by
      9 # the Free Software Foundation, either version 3 of the License, or
     10 # (at your option) any later version.
     11 #
     12 # This program is distributed in the hope that it will be useful,
     13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     15 # GNU General Public License for more details.
     16 #
     17 # You should have received a copy of the GNU General Public License
     18 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
     19 set -e
     20 
     21 if [ $# -lt 1 ]; then
     22   printf "usage: %s variable netcdf\n" "${0##*/}" >&2
     23   exit 1
     24 fi
     25 
     26 
     27 b="[[:blank:]]\{0,\}" # Blanks
     28 c=".\{0,\}" # Any chars
     29 
     30 dimensions=$(ncdump -h "$1" | sed "/^${b}variables/,\$d" | sed '1,2d')
     31 nx=$(echo "${dimensions}" | \
     32   sed -n "s/^${c}W_E_direction${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p")
     33 ny=$(echo "${dimensions}" | \
     34   sed -n "s/^${c}S_N_direction${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p")
     35 nz=$(echo "${dimensions}" | \
     36   sed -n "s/^${c}vertical_levels${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p")
     37 ntimes=$(echo "${dimensions}" | \
     38   sed -n "s/^${c}time${b}=${b}\([0-9]\{1,\}\)${b};${c}$/\1/p")
     39 
     40 if [ -z "${ntimes}" ]; then
     41   ntimes=$(echo "${dimensions}" | \
     42   sed -n "s/^${c}time${b}=${c}\/\/${b}(\([0-9]\{1,\}\) currently)${c}$/\1/p")
     43 fi
     44 
     45 if [ -z "${nx}" ] \
     46 || [ -z "${ny}" ] \
     47 || [ -z "${nz}" ] \
     48 || [ -z "${ntimes}" ]
     49 then
     50   >&2 printf "%s: error retrieving the dimensions of \"%s\"\n" "$0" "$1"
     51   exit 1
     52 fi
     53 
     54 name=$(basename "$1")
     55 name=${name%.*}
     56 {
     57   echo "${nx}"
     58   echo "${ny}"
     59   echo "${nz}"
     60   echo "${ntimes}"
     61 } > "${name}_desc"