32
32
# afy Ver 1.01 Use 'which' to locate executables June 10
33
33
# ------------------------------------------------------------------------------
34
34
35
+ script_name=` basename $0 `
36
+ pkg_libexec_dir=${PKGLIBEXECDIR:-@ pkglibexecdir@ }
37
+
38
+ plevel_interp=$pkg_libexec_dir /PLEV.exe
39
+
35
40
fields=
36
41
more_output=1
37
42
ofile=plevel.nc
@@ -47,6 +52,57 @@ tlist=
47
52
plevs=" 100000 92500 85000 70000 60000 50000 40000 30000 25000 \
48
53
20000 15000 10000 7000 5000 3000 2000 1000"
49
54
55
+ echoerr ()
56
+ {
57
+ echo " $@ " 1>&2
58
+ }
59
+
60
+ usage ()
61
+ {
62
+ cat << EOF
63
+ Usage: $script_name [-a] [-3] [-0] [-f] [-d #] -i file [-o ofile] [-m] [-z #] [-s] [fields.....]
64
+ Interpolates data from model levels to pressure levels. The input
65
+ model grid is a hybrid sigma-pressure coordinate and the output
66
+ pressure levels may be specified. The minimum required input fields
67
+ are "bk", "pk", and "ps".
68
+
69
+ -a Output all fields converting 3d fields to pressure
70
+ levels.
71
+ -3 Output and convert all 3d fields to pressure levels.
72
+ -0 When fields sphum or zsurf do not exist use zero,
73
+ otherwise fail.
74
+ -m Default missing value is used for all fields (the
75
+ _FillValue).
76
+ -x Do not set data extrapolated beneath the surface to
77
+ missing values.
78
+ -i file Input netcdf file, the file must contain the required
79
+ variables (pk, bk, ps, ...).
80
+ -o ofile The output file name. (Default: plevel.nc)
81
+ -p plevs A list of output pressure levels in pascals (with no
82
+ decimal point). The default is the 17 NCEP
83
+ reananalysis levels (bottom to top). The list must be
84
+ in quotes and values must be separated by a space.
85
+ -d value The verbosity level, use an integer number where
86
+ value >= 0. (Default: value=1)
87
+ -t #,#,# The starting, ending, and increment index for time axis
88
+ processing where # is a positive number. (The default
89
+ is to process all time indices.)
90
+ -z # If using NetCDF4, use deflation of level #. Defaults
91
+ to input file settings.
92
+ -s 1|0 If using NetCDF4, use shuffle if 1 and don't use if 0.
93
+ Defaults to input file settings.
94
+
95
+ fields A list of (additional) output fields. If this list is
96
+ not supplied, then the "-a" or "-3" option must be
97
+ specified. Possible list entries included any fields
98
+ in the input files, and additional fields: slp, hght.
99
+ Additional input fields may be required for these
100
+ output fields.
101
+
102
+ Example: $script_name -a -i atmos.nc slp hght
103
+
104
+ EOF
105
+ }
50
106
# -----------------------------------------------------------------------
51
107
52
108
while getopts 03amxi:o:d:p:t:z:s: arg
@@ -73,93 +129,48 @@ fields=$@
73
129
# -----------------------------------------------------------------------
74
130
75
131
if [ " ${ifiles:- NULL} " = " NULL" ]; then
76
- name=` basename $0 `
77
- cat << EOF
78
-
79
- Interpolates data from model levels to pressure levels.
80
- The input model grid is a hybrid sigma-pressure coordinate
81
- and the output pressure levels may be specified.
82
- The minimum required input fields are "bk", "pk", and "ps".
83
-
84
- Usage: $name [-a] [-3] [-0] [-f] [-d #] -i file [-o ofile] [-m] [-z #] [-s] [fields.....]
85
-
86
- -a = Output all fields converting 3d fields to pressure levels.
87
- -3 = Output and convert all 3d fields to pressure levels.
88
- -0 = When fields sphum or zsurf do not exist use zero, otherwise fail.
89
- -m = Default missing value is used for all fields (the _FillValue).
90
- -x = DO NOT set data extrapolated beneath the surface to missing values.
91
- -i file = Input netcdf file, the file must contain the required variables
92
- (pk,bk,ps,...).
93
- If the -i files option is omitted a usage message is printed.
94
- -o ofile = The output file name. (Default: plevel.nc)
95
- -p plevs = A list of output pressure levels in pascals (with no decimal point).
96
- The default is the 17 NCEP reananalysis levels (bottom to top).
97
- The list must be in quotes and values must be separated by a space.
98
- -d value The verbosity level, use an integer number where value >= 0.
99
- (Default: value=1)
100
- -t #,#,# The starting, ending, and increment index for time axis processing
101
- where # is a positive number.
102
- (The default is to process all time indices.)
103
- -z # If using NetCDF4, use deflation of level #.
104
- Defaults to input file settings.
105
- -s 1|0 If using NetCDF4, use shuffle if 1 and don't use if 0.
106
- Defaults to input file settings.
107
-
108
- fields = A list of (additional) output fields. If this list is not supplied,
109
- then the "-a" or "-3" option must be specified. Possible list entries
110
- included any fields in the input files, and additional fields: slp, hght.
111
- Additional input fields may be required for these output fields.
112
-
113
- Example: $name -a -i atmos.nc slp hght
114
-
115
- EOF
116
- exit 1
132
+ echoerr " $script_name : no input files specified. Must specify \" -i <infiles>\" "
133
+ exit 1
117
134
fi
118
135
119
- # location of executable
120
- executable=` which PLEV.exe`
121
-
122
- if [ ! -x " $executable " ]; then
123
- echo " ERROR: executable does not exist"
124
- echo " executable=$executable "
136
+ # Verify PLEV.exe is available
137
+ if [ ! -x " $plevel_interp " ]; then
138
+ echoerr " $script_name : unable to find required libexec program \" $plevel_interp \" "
125
139
exit 1
126
140
fi
127
141
128
142
# make sure input files are present
129
-
130
- list=
143
+ missing_ifiles=
131
144
for file in $ifiles ;
132
145
do
133
146
if [ ! -e $file ]; then
134
- list =" $list $file "
147
+ missing_ifiles =" $missing_ifiles $file "
135
148
fi
136
149
done
137
- if [ ${# list } -gt 0 ]; then
138
- echo ERROR: the following input files do not exist
139
- for file in $list ;
150
+ if [ ${# missing_ifiles } -gt 0 ]; then
151
+ echoerr " $script_name : missing input files: "
152
+ for file in $missing_ifiles ;
140
153
do
141
- echo $file
154
+ echoerr " $file "
142
155
done
143
156
exit 1
144
157
fi
145
158
146
159
# process time loop limits (create array of length 3)
147
-
148
160
tlist=` echo ${tlist} | sed -e " s/,,,/,,0,/" `
149
161
tlist=` echo ${tlist} | sed -e " s/^,/0,/" `
150
162
tlist=` echo ${tlist} | sed -e " s/,,/,0,/" `
151
163
tloop=` echo ${tlist} | sed -e " s/,/ /g" `
152
164
153
- # -----------------------------------------------------------------------
154
- # ---- namelist for pressure interp program ----
155
-
156
- namelist=" plev.input.nml"
165
+ #
166
+ # Generate namelist for pressure interp program
167
+ namelist=" plev.input.nml"
157
168
158
- echo " &input" > $namelist
169
+ echo " &input" > > $namelist
159
170
160
171
# input file names
161
- echo " in_file_name = '$file ' ," >> $namelist
162
- echo " out_file_name = '$ofile ' ," >> $namelist
172
+ echo " in_file_name = '$file ' ," >> $namelist
173
+ echo " out_file_name = '$ofile ' ," >> $namelist
163
174
164
175
# input field names
165
176
i=0
@@ -201,18 +212,21 @@ i=0
201
212
for index in $tloop ;
202
213
do
203
214
let " i=$i +1"
204
- if [ $index -gt 0 ]; then
215
+ if [ $index -gt 0 ]; then
205
216
case $i in
206
217
1) echo " time_beg = $index " >> $namelist ;;
207
218
2) echo " time_end = $index " >> $namelist ;;
208
219
3) echo " time_inc = $index " >> $namelist ;;
209
- esac
220
+ esac
210
221
fi
211
222
done
212
223
213
- echo " /" >> $namelist
214
-
215
- $executable
216
-
217
- # rm -f $namelist
224
+ echo " /" >> $namelist
218
225
226
+ eval $plevel_interp
227
+ if [ $? -eq 0 ]
228
+ then
229
+ rm -f $namelist
230
+ else
231
+ echoerr " $script_name : error running \" $plevel_interp \" "
232
+ fi
0 commit comments