Merge branch 'fixf'
[wrf-fire-matlab.git] / plot_tracer / ncdump_wrapper.sh
blob80fcf2b247d847657a74080a2353f2a687ac4cc7
1 #!/bin/bash
3 # used to export variables from netcdf output file
5 # /path/to/ncdump
6 NCDUMP_BIN="$1"
8 # the netcdf output file to use
9 NC_FILE="$2"
11 # directory to put files into
12 OUT_DIR="$3"
14 NUM_ARGS=3
16 # variables to export
17 VARS="XFG
18 YFG
19 XCD
20 YCD"
22 # usage statement
23 function usage() {
24 echo "usage:"
25 echo `basename $0` /path/to/ncdump /path/to/netcdf_file /path/to/output_dir
28 if [ $# -ne 3 ] ; then
29 usage
30 exit 1
33 # check ncdump binary
35 if ! $NCDUMP_BIN 2>&1 | grep write_matrix &> /dev/null ; then
36 echo "ncdump does not support -w flag"
37 exit 1
40 # check netcdf file
42 if [ ! -f $NC_FILE ] ; then
43 echo "$NC_FILE is not a file"
44 usage
45 exit 1
48 # test netcdf file
49 for var in $VARS ; do
50 if ! $NCDUMP_BIN -h $NC_FILE 2>&1 | grep $var &> /dev/null ; then
51 echo "either $NC_FILE is not a netcdf file or"
52 echo "$var does not exist in the file"
53 exit 1
55 done
57 if [ -z "$OUT_DIR" ] ; then
58 echo "no output directory given"
59 usage
60 exit 1
63 if [ -f "$OUT_DIR" ] ; then
64 echo "$OUT_DIR is a file, not a directory"
65 usage
66 exit 1
69 if [ -d "$OUT_DIR" ] && ls "${OUT_DIR}/*" &> /dev/null ; then
70 echo "$OUT_DIR is not empty"
71 usage
72 exit 1
75 # done with tests
77 # save full pathname of ncdump binary and netcdf file
78 NCDUMP_FULL=$(which $NCDUMP_BIN)
79 NETCDF_FULL=$(cd $(dirname "$NC_FILE") && echo $PWD)/$(basename "$NC_FILE")
81 if [ ! -e "$OUT_DIR" ] ; then
82 mkdir -p "$OUT_DIR"
85 cd "$OUT_DIR"
86 VC=""
88 for var in $VARS ; do
89 VC="${VC},$var"
90 done
92 $NCDUMP_FULL -w -v $VC $NETCDF_FULL &> ncdump.log
93 exit 0