Skip to content

Commit 5aae555

Browse files
authored
Merge pull request #375 from NOAA-GFDL/374.combine-restarts-glob-bug
Fix combine-restarts file glob bug
2 parents d9a874c + addaf6a commit 5aae555

File tree

2 files changed

+120
-2
lines changed

2 files changed

+120
-2
lines changed

src/combine-restarts/combine_restarts.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ verbose=0
5454
remove_files=0
5555
dryrun=0
5656
combineNccOpts=""
57-
mppCombOpts_default='-64 -h 16384 -m'
57+
mppCombOpts_default='-h 16384 -m'
5858
mppCombOpts="$mppCombOpts_default"
5959

6060
while getopts :hC:M:nrvV OPT; do
@@ -119,7 +119,7 @@ do
119119
then
120120
echoerr "debug1: processing for combined file '${f}'"
121121
fi
122-
inputFiles=$( ls -1 | @EGREP@ "${f}${patternGrepTail}" | xargs )
122+
inputFiles=$( ls -1 | @EGREP@ "^${f}${patternGrepTail}" | xargs )
123123
if [ $( echo ${inputFiles} | wc -w ) -gt 0 ]
124124
then
125125
# Check if file is a compressed file

tests/combine_restarts/glob_bugfix

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) 2024 Geophysical Fluid Dynamics Laboratory
4+
5+
# This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools).
6+
7+
# FRE-NCtools is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU Lesser General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or (at
10+
# your option) any later version.
11+
12+
# FRE-NCtools is distributed in the hope that it will be useful, but WITHOUT
13+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
# for more details.
16+
17+
# You should have received a copy of the GNU Lesser General Public
18+
# License along with FRE-NCTools. If not, see
19+
# <http://www.gnu.org/licenses/>.
20+
21+
# Create two similar input files that will expose a previous bug.
22+
# e.g. land and testland
23+
# Verify that the combine line for land does not include testland.
24+
if test "$VERBOSE" = yes
25+
then
26+
set -x
27+
command -v combine_restarts
28+
combine_restarts -V
29+
fi
30+
31+
. "$srcdir/init.sh"
32+
33+
ncgen -o land.nc.0000 << EOF || framework_failure_
34+
netcdf land.nc {
35+
dimensions:
36+
lat = 10 ;
37+
lon = 10 ;
38+
lpt = 5 ;
39+
variables:
40+
int lpt(lpt) ;
41+
lpt:compress = "lat lon" ;
42+
float lst(lpt);
43+
float lat(lat) ;
44+
float lon(lon) ;
45+
data:
46+
lon = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
47+
lat = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
48+
lpt = 1, 5, 22, 35, 47 ;
49+
lst = 100.0, 101.0, 102.0, 103.0, 104.0 ;
50+
}
51+
EOF
52+
53+
ncgen -o land.nc.0001 << EOF || framework_failure_
54+
netcdf land.nc {
55+
dimensions:
56+
lat = 10 ;
57+
lon = 10 ;
58+
lpt = 5 ;
59+
variables:
60+
int lpt(lpt) ;
61+
lpt:compress = "lat lon" ;
62+
float lst(lpt);
63+
float lat(lat) ;
64+
float lon(lon) ;
65+
data:
66+
lon = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
67+
lat = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
68+
lpt = 51, 63, 64, 77, 94 ;
69+
lst = 105.0, 106.0, 107.0, 108.0, 109.0 ;
70+
}
71+
EOF
72+
73+
ncgen -o testland.nc.0000 << EOF || framework_failure_
74+
netcdf testland.nc {
75+
dimensions:
76+
lat = 10 ;
77+
lon = 10 ;
78+
lpt = 5 ;
79+
variables:
80+
int lpt(lpt) ;
81+
lpt:compress = "lat lon" ;
82+
float lst(lpt);
83+
float lat(lat) ;
84+
float lon(lon) ;
85+
data:
86+
lon = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
87+
lat = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
88+
lpt = 1, 5, 22, 35, 47 ;
89+
lst = 100.0, 101.0, 102.0, 103.0, 104.0 ;
90+
}
91+
EOF
92+
93+
ncgen -o testland.nc.0001 << EOF || framework_failure_
94+
netcdf testland.nc {
95+
dimensions:
96+
lat = 10 ;
97+
lon = 10 ;
98+
lpt = 5 ;
99+
variables:
100+
int lpt(lpt) ;
101+
lpt:compress = "lat lon" ;
102+
float lst(lpt);
103+
float lat(lat) ;
104+
float lon(lon) ;
105+
data:
106+
lon = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
107+
lat = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ;
108+
lpt = 51, 63, 64, 77, 94 ;
109+
lst = 105.0, 106.0, 107.0, 108.0, 109.0 ;
110+
}
111+
EOF
112+
113+
output=$(combine_restarts -n 2>&1) || fail_ Dry run failed
114+
115+
# Verify that the combined "land" file does not contain "testland"
116+
echo "$output" | grep "combine-ncc land.nc.0000 land.nc.0001 land.nc" || fail_ land combining line incorrect in output "\n******\n$output\n******"
117+
118+
Exit $fail

0 commit comments

Comments
 (0)