Skip to content

Commit cc0c127

Browse files
committed
Finish plevel mods and tests
1 parent 9756d4b commit cc0c127

File tree

11 files changed

+405
-107
lines changed

11 files changed

+405
-107
lines changed

src/Makefile.am

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ combine_programs = \
99
bin_PROGRAMS = \
1010
decompress-ncc \
1111
list_ncvars \
12-
PLEV.exe \
1312
$(combine_programs)
1413

1514
bin_SCRIPTS = \
1615
combine_restarts \
1716
iceberg_comb.sh \
18-
list_ncvars.csh
17+
list_ncvars.csh \
18+
plevel.sh
1919

20-
pkglibexec_PROGRAMS = print_version
20+
pkglibexec_PROGRAMS = \
21+
print_version \
22+
PLEV.exe
2123

2224
noinst_LIBRARIES = libver.a
2325

@@ -134,7 +136,10 @@ iceberg_comb.sh: iceberg-comb/iceberg_comb.sh.in Makefile
134136
# ********************************************************* #
135137
# plevel #
136138
# ********************************************************* #
137-
dist_bin_SCRIPTS = plevel/plevel.sh
139+
plevel.sh: plevel/plevel.sh.in Makefile
140+
$(do_subst) < $(srcdir)/plevel/plevel.sh.in > plevel.sh
141+
chmod +x plevel.sh
142+
138143
PLEV_exe_SOURCES = plevel/plev_constants.F90 \
139144
plevel/moisture_convert.F90 \
140145
plevel/pressure_interp.F90 \

src/plevel/plevel.sh renamed to src/plevel/plevel.sh.in

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
# afy Ver 1.01 Use 'which' to locate executables June 10
3333
# ------------------------------------------------------------------------------
3434

35+
script_name=`basename $0`
36+
pkg_libexec_dir=${PKGLIBEXECDIR:-@pkglibexecdir@}
37+
38+
plevel_interp=$pkg_libexec_dir/PLEV.exe
39+
3540
fields=
3641
more_output=1
3742
ofile=plevel.nc
@@ -47,6 +52,57 @@ tlist=
4752
plevs="100000 92500 85000 70000 60000 50000 40000 30000 25000 \
4853
20000 15000 10000 7000 5000 3000 2000 1000"
4954

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+
}
50106
#-----------------------------------------------------------------------
51107

52108
while getopts 03amxi:o:d:p:t:z:s: arg
@@ -73,93 +129,48 @@ fields=$@
73129
#-----------------------------------------------------------------------
74130

75131
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
117134
fi
118135

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\""
125139
exit 1
126140
fi
127141

128142
# make sure input files are present
129-
130-
list=
143+
missing_ifiles=
131144
for file in $ifiles;
132145
do
133146
if [ ! -e $file ]; then
134-
list="$list $file"
147+
missing_ifiles="$missing_ifiles $file"
135148
fi
136149
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;
140153
do
141-
echo $file
154+
echoerr " $file"
142155
done
143156
exit 1
144157
fi
145158

146159
# process time loop limits (create array of length 3)
147-
148160
tlist=`echo ${tlist} | sed -e "s/,,,/,,0,/"`
149161
tlist=`echo ${tlist} | sed -e "s/^,/0,/"`
150162
tlist=`echo ${tlist} | sed -e "s/,,/,0,/"`
151163
tloop=`echo ${tlist} | sed -e "s/,/ /g"`
152164

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"
157168

158-
echo " &input" > $namelist
169+
echo " &input" >> $namelist
159170

160171
# 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
163174

164175
# input field names
165176
i=0
@@ -201,18 +212,21 @@ i=0
201212
for index in $tloop;
202213
do
203214
let "i=$i+1"
204-
if [ $index -gt 0 ]; then
215+
if [ $index -gt 0 ]; then
205216
case $i in
206217
1) echo " time_beg = $index" >> $namelist;;
207218
2) echo " time_end = $index" >> $namelist;;
208219
3) echo " time_inc = $index" >> $namelist;;
209-
esac
220+
esac
210221
fi
211222
done
212223

213-
echo " /" >> $namelist
214-
215-
$executable
216-
217-
#rm -f $namelist
224+
echo " /" >> $namelist
218225

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

tests/Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ TESTS = combine-ncc/combine \
7272
mppnccombine/xyt-decomp \
7373
mppnccombine/yt-decomp \
7474
plevel/plevel \
75+
plevel/plevel-0 \
76+
plevel/plevel-3 \
77+
plevel/plevel-a \
78+
plevel/plevel-o \
79+
plevel/plevel-nctypes \
80+
plevel/plevel-t \
7581
scatter-ncc/scatter_1x1 \
7682
scatter-ncc/scatter_1x2 \
7783
scatter-ncc/scatter_2x1

tests/plevel/create_plevel_test_ncfile.c

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <netcdf.h>
22
#include <stdio.h>
33
#include <stdlib.h>
4+
#include <unistd.h>
45

56
#define FILE_NAME "test_input.nc"
67
#define NX 10
78
#define NY 10
89
#define PFULL 33
910
#define PHALF 34
10-
#define TIME 1
11+
#define TIME 10
1112
#define PS_MIN 75223
1213
#define PS_MAX 101325
1314
#define TEMP_MIN 250
@@ -20,12 +21,28 @@ void check_err(int stat, int line) {
2021
}
2122
}
2223

23-
int main() {
24+
int main(int argc, char **argv) {
2425
int ncid, time_dim, xt_dim, yt_dim, pfull_dim, phalf_dim;
2526
int times_id, xt_id, yt_id, phalf_id, pfull_id, pk_id, bk_id;
2627
int ps_id, temp_id, dummy_id;
2728

29+
int nc_format = NC_CLOBBER;
30+
2831
int stat;
32+
int c;
33+
34+
while (( c = getopt (argc, argv, "abc:")) != -1)
35+
{
36+
switch (c)
37+
{
38+
case '4':
39+
nc_format = NC_CLOBBER | NC_NETCDF4;
40+
break;
41+
case '6':
42+
nc_format = NC_CLOBBER | NC_64BIT_OFFSET;
43+
break;
44+
}
45+
}
2946

3047
size_t start_ps[3] = {0, 0, 0};
3148
size_t start_temp[4] = {0, 0, 0, 0};
@@ -85,7 +102,7 @@ int main() {
85102
check_err(stat, __LINE__);
86103

87104
// Allocate memory for sample data and write to file
88-
double times_data[TIME] = {0};
105+
double times_data = 0;
89106
float xt_data[NX], yt_data[NY], temp_data[PFULL][NX][NY];
90107
float ps_data[NX][NY];
91108
float dummy_data[NX][NY];
@@ -128,23 +145,7 @@ int main() {
128145
1497.781, 1156.253, 867.792, 625.5933, 426.2132, 264.7661,
129146
145.0665, 60.0, 15.0, 0.0};
130147

131-
// Generate random data as in the Python example
132-
for (int i = 0; i < PFULL; i++)
133-
for (int j = 0; j < NX; j++)
134-
for (int k = 0; k < NY; k++)
135-
temp_data[i][j][k] = (rand() % (TEMP_MAX - TEMP_MIN)) + TEMP_MIN;
136-
137-
for (int i = 0; i < NX; i++)
138-
for (int j = 0; j < NY; j++)
139-
ps_data[i][j] = (rand() % (PS_MAX-PS_MIN)) + PS_MIN;
140-
141-
for (int i = 0; i < NX; i++)
142-
for (int j = 0; j < NY; j++)
143-
dummy_data[i][j] = i * NX + j;
144-
145-
// Writing data
146-
stat = nc_put_var_double(ncid, times_id, &times_data[0]);
147-
check_err(stat, __LINE__);
148+
// Writing static data
148149
stat = nc_put_var_float(ncid, xt_id, &xt_data[0]);
149150
check_err(stat, __LINE__);
150151
stat = nc_put_var_float(ncid, yt_id, &yt_data[0]);
@@ -157,21 +158,47 @@ int main() {
157158
check_err(stat, __LINE__);
158159
stat = nc_put_var_float(ncid, bk_id, &bk_data[0]);
159160
check_err(stat, __LINE__);
160-
stat = nc_put_vara_float(ncid, temp_id,
161-
(size_t[4]){0, 0, 0, 0},
162-
(size_t[4]){1, PFULL, NX, NY},
163-
&temp_data[0][0][0]);
164-
check_err(stat, __LINE__);
165-
stat = nc_put_vara_float(ncid, ps_id,
166-
(size_t[3]){0, 0, 0},
161+
162+
// Write time-variable data
163+
for (int rec=0; rec < TIME; rec++)
164+
{
165+
// Generate random data as in the Python example
166+
for (int i = 0; i < PFULL; i++)
167+
for (int j = 0; j < NX; j++)
168+
for (int k = 0; k < NY; k++)
169+
temp_data[i][j][k] = (rand() % (TEMP_MAX - TEMP_MIN)) + TEMP_MIN;
170+
171+
for (int i = 0; i < NX; i++)
172+
for (int j = 0; j < NY; j++)
173+
ps_data[i][j] = (rand() % (PS_MAX-PS_MIN)) + PS_MIN;
174+
175+
for (int i = 0; i < NX; i++)
176+
for (int j = 0; j < NY; j++)
177+
dummy_data[i][j] = i * NX + j;
178+
179+
times_data = (double)rec;
180+
181+
stat = nc_put_vara_double(ncid, times_id,
182+
(size_t[1]){rec},
183+
(size_t[1]){1},
184+
&times_data);
185+
check_err(stat, __LINE__);
186+
stat = nc_put_vara_float(ncid, temp_id,
187+
(size_t[4]){rec, 0, 0, 0},
188+
(size_t[4]){1, PFULL, NX, NY},
189+
&temp_data[0][0][0]);
190+
check_err(stat, __LINE__);
191+
stat = nc_put_vara_float(ncid, ps_id,
192+
(size_t[3]){rec, 0, 0},
167193
(size_t[3]){1, NX, NY},
168194
&ps_data[0][0]);
169-
check_err(stat, __LINE__);
170-
stat = nc_put_vara_float(ncid, dummy_id,
171-
(size_t[3]){0, 0, 0},
172-
(size_t[3]){1, NX, NY},
173-
&dummy_data[0][0]);
174-
check_err(stat, __LINE__);
195+
check_err(stat, __LINE__);
196+
stat = nc_put_vara_float(ncid, dummy_id,
197+
(size_t[3]){rec, 0, 0},
198+
(size_t[3]){1, NX, NY},
199+
&dummy_data[0][0]);
200+
check_err(stat, __LINE__);
201+
}
175202

176203
// Close the file
177204
stat = nc_close(ncid);

0 commit comments

Comments
 (0)