htcp

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

dump_netcdf_data.sh (1289B)


      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 
     20 set -e
     21 
     22 if [ $# -lt 2 ]; then
     23   printf "usage: %s variable netcdf\n" "${0##*/}" >&2
     24   exit 1
     25 fi
     26 
     27 if [ ! -f "$2" ]; then
     28   printf "\"%s\" is not a valid file\n" "$2" >&2
     29   exit 1
     30 fi
     31 
     32 name=$(basename "$2")
     33 name=${name%.*}
     34 
     35 blanks="[[:blank:]]\{0,\}"
     36 ncdump -v "$1" "$2" \
     37   | sed -n "/^${blanks}$1${blanks}=/,\$p" \
     38   | sed "s/^${blanks}$1${blanks}=${blanks}//g" \
     39   | sed "s/[;} ]//g" \
     40   | sed "s/,/\n/g" \
     41   | sed "/^${blanks}$/d" > "${name}_${1}"