Skip to content

Commit 9756d4b

Browse files
committed
plevel.sh first test
1 parent bc98cf7 commit 9756d4b

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

tests/Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ else
2929
skipflag=""
3030
endif
3131

32+
AM_CFLAGS = $(NETCDF_CFLAGS)
33+
LDADD = $(NETCDF_LDFLAGS) $(NETCDF_LIBS)
34+
35+
check_PROGRAMS = create_plevel_test_ncfile
36+
create_plevel_test_ncfile_SOURCES=plevel/create_plevel_test_ncfile.c
37+
38+
3239
TESTS_ENVIRONMENT = top_srcdir=$(abs_top_srcdir); export top_srcdir; \
40+
builddir=$(abs_builddir); export builddir; \
3341
export skip_mpi=$(skip_MPI); \
3442
export skipflag=$(skipflag); \
3543
export PKGLIBEXECDIR="$(abs_top_builddir)/src" \
@@ -63,6 +71,7 @@ TESTS = combine-ncc/combine \
6371
mppnccombine/xt-decomp \
6472
mppnccombine/xyt-decomp \
6573
mppnccombine/yt-decomp \
74+
plevel/plevel \
6675
scatter-ncc/scatter_1x1 \
6776
scatter-ncc/scatter_1x2 \
6877
scatter-ncc/scatter_2x1

tests/plevel/create_ncfile.c renamed to tests/plevel/create_plevel_test_ncfile.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ void check_err(int stat, int line) {
2222

2323
int main() {
2424
int ncid, time_dim, xt_dim, yt_dim, pfull_dim, phalf_dim;
25-
int times_id, xt_id, yt_id, phalf_id, pfull_id, pk_id, bk_id, ps_id, temp_id;
25+
int times_id, xt_id, yt_id, phalf_id, pfull_id, pk_id, bk_id;
26+
int ps_id, temp_id, dummy_id;
27+
2628
int stat;
2729

2830
size_t start_ps[3] = {0, 0, 0};
@@ -61,10 +63,11 @@ int main() {
6163
check_err(stat, __LINE__);
6264
stat = nc_def_var(ncid, "bk", NC_FLOAT, 1, &phalf_dim, &bk_id);
6365
check_err(stat, __LINE__);
64-
stat = nc_def_var(ncid, "ps", NC_FLOAT, 3, (int[]){time_dim, yt_dim, xt_dim}, &ps_id);
66+
stat = nc_def_var(ncid, "ps", NC_FLOAT, 3, (int[]){time_dim, xt_dim, yt_dim}, &ps_id);
6567
check_err(stat, __LINE__);
6668
stat = nc_def_var(ncid, "temp", NC_FLOAT, 4, (int[]){time_dim, pfull_dim, xt_dim, yt_dim}, &temp_id);
6769
check_err(stat, __LINE__);
70+
stat = nc_def_var(ncid, "dummy", NC_FLOAT, 3, (int[]){time_dim, yt_dim, xt_dim}, &dummy_id);
6871

6972
// Assign global attributes
7073
stat = nc_put_att_text(ncid, NC_GLOBAL, "description", 40, "Sample netCDF file for testing run_timepressure_interp");
@@ -84,7 +87,8 @@ int main() {
8487
// Allocate memory for sample data and write to file
8588
double times_data[TIME] = {0};
8689
float xt_data[NX], yt_data[NY], temp_data[PFULL][NX][NY];
87-
float ps_data[NY][NX];
90+
float ps_data[NX][NY];
91+
float dummy_data[NX][NY];
8892

8993
for (int i = 0; i < NX; i++) xt_data[i] = i;
9094
for (int i = 0; i < NY; i++) yt_data[i] = i;
@@ -130,10 +134,14 @@ int main() {
130134
for (int k = 0; k < NY; k++)
131135
temp_data[i][j][k] = (rand() % (TEMP_MAX - TEMP_MIN)) + TEMP_MIN;
132136

133-
for (int i = 0; i < NY; i++)
134-
for (int j = 0; j < NX; j++)
137+
for (int i = 0; i < NX; i++)
138+
for (int j = 0; j < NY; j++)
135139
ps_data[i][j] = (rand() % (PS_MAX-PS_MIN)) + PS_MIN;
136140

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+
137145
// Writing data
138146
stat = nc_put_var_double(ncid, times_id, &times_data[0]);
139147
check_err(stat, __LINE__);
@@ -156,9 +164,14 @@ int main() {
156164
check_err(stat, __LINE__);
157165
stat = nc_put_vara_float(ncid, ps_id,
158166
(size_t[3]){0, 0, 0},
159-
(size_t[4]){1, NY, NX},
167+
(size_t[3]){1, NX, NY},
160168
&ps_data[0][0]);
161169
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__);
162175

163176
// Close the file
164177
stat = nc_close(ncid);

tests/plevel/plevel

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
# ensure the help option prints something and exits successfully
4+
5+
# Copyright (C) 2024 Geophysical Fluid Dynamics Laboratory
6+
7+
# This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools).
8+
9+
# FRE-NCtools is free software: you can redistribute it and/or modify it under
10+
# the terms of the GNU Lesser General Public License as published by
11+
# the Free Software Foundation, either version 3 of the License, or (at
12+
# your option) any later version.
13+
14+
# FRE-NCtools is distributed in the hope that it will be useful, but WITHOUT
15+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17+
# for more details.
18+
19+
# You should have received a copy of the GNU Lesser General Public
20+
# License along with FRE-NCTools. If not, see
21+
# <http://www.gnu.org/licenses/>.
22+
23+
if test "$VERBOSE" = yes
24+
then
25+
set -x
26+
command -v plevel.sh
27+
plevel.sh -V
28+
fi
29+
30+
. "$srcdir/init.sh"
31+
32+
# Generate the test_input.nc file
33+
$builddir/create_plevel_test_ncfile || framework_failure_
34+
35+
# Run plevel.sh with default options
36+
$top_srcdir/src/plevel/plevel.sh -i test_input.nc temp || fail_ plevel.sh failed
37+
test -e plevel.nc || fail_ plevel.nc file does not exist after running plevel.sh
38+
ncdump -v temp plevel.nc || fail_ temp variable not found in plevel.sh

0 commit comments

Comments
 (0)