Skip to content

Commit

Permalink
Fix compare_ncfile ufs-community#296
Browse files Browse the repository at this point in the history
  • Loading branch information
MinsukJi-NOAA committed Feb 12, 2021
1 parent 6a6721c commit 09ab000
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
18 changes: 13 additions & 5 deletions tests/compare_ncfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
from netCDF4 import Dataset

with Dataset(sys.argv[1]) as nc1, Dataset(sys.argv[2]) as nc2:
# Check if the list of variables are the same
if nc1.variables.keys()!=nc2.variables.keys():
print("Variables are different")
sys.exit(1)
sys.exit(2)

for varname in nc1.variables.keys():
diff = nc2[varname][:]-nc1[varname][:]
if (np.abs(diff)).max() != 0:
print(varname,"is different")
sys.exit(1)
# First check if each variable has the same dimension
if np.shape(nc1[varname][:])!=np.shape(nc2[varname][:]):
print(varname,"dimension is different")
sys.exit(2)
# If dimension is the same, compare data
else:
diff = nc2[varname][:]-nc1[varname][:]

if (np.abs(diff)).max() != 0:
print(varname,"is different")
sys.exit(2)
12 changes: 10 additions & 2 deletions tests/rt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ rt_single() {
[[ ${#line} == 0 ]] && continue
[[ $line == \#* ]] && continue

if [[ $line =~ COMPILE && $line =~ ${MACHINE_ID} ]]; then
compile_line=$line
if [[ $line == COMPILE* ]] ; then
MACHINES=$(echo $line | cut -d'|' -f3 | sed -e 's/^ *//' -e 's/ *$//')
if [[ ${MACHINES} == '' ]]; then
compile_line=$line
elif [[ ${MACHINES} == -* ]]; then
[[ ${MACHINES} =~ ${MACHINE_ID} ]] || compile_line=$line
elif [[ ${MACHINES} == +* ]]; then
[[ ${MACHINES} =~ ${MACHINE_ID} ]] && compile_line=$line
fi
fi

if [[ $line =~ RUN ]]; then
Expand Down Expand Up @@ -771,6 +778,7 @@ else
[[ ${KEEP_RUNDIR} == false ]] && rm -rf ${RUNDIR_ROOT}
[[ ${ROCOTO} == true ]] && rm -f ${ROCOTO_XML} ${ROCOTO_DB} *_lock.db
[[ ${TEST_35D} == true ]] && rm -f tests/cpld_bmark*_20*
[[ ${SINGLE_NAME} != '' ]] && rm -f rt.conf.single
fi

date >> ${REGRESSIONTEST_LOG}
Expand Down
16 changes: 13 additions & 3 deletions tests/rt_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,23 @@ check_results() {

else

d=$( cmp ${RTPWD}/${CNTL_DIR}/$i ${RUNDIR}/$i | wc -l )
cmp ${RTPWD}/${CNTL_DIR}/$i ${RUNDIR}/$i >/dev/null 2>&1 && d=$? || d=$?
if [[ $d -eq 2 ]]; then
echo "....CMP ERROR" >> ${REGRESSIONTEST_LOG}
echo "....CMP ERROR"
exit 1
fi

if [[ $d -ne 0 ]] ; then
if [[ $d -eq 1 && ${i##*.} == 'nc' ]] ; then
if [[ ${MACHINE_ID} =~ orion || ${MACHINE_ID} =~ hera || ${MACHINE_ID} =~ wcoss_dell_p3 || ${MACHINE_ID} =~ wcoss_cray || ${MACHINE_ID} =~ cheyenne || ${MACHINE_ID} =~ gaea || ${MACHINE_ID} =~ jet ]]; then
printf ".......ALT CHECK.." >> ${REGRESSIONTEST_LOG}
printf ".......ALT CHECK.."
d=$( ${PATHRT}/compare_ncfile.py ${RTPWD}/${CNTL_DIR}/$i ${RUNDIR}/$i 2>/dev/null | wc -l )
${PATHRT}/compare_ncfile.py ${RTPWD}/${CNTL_DIR}/$i ${RUNDIR}/$i >/dev/null 2>&1 && d=$? || d=$?
if [[ $d -eq 1 ]]; then
echo "....ERROR" >> ${REGRESSIONTEST_LOG}
echo "....ERROR"
exit 1
fi
fi
fi

Expand Down

0 comments on commit 09ab000

Please sign in to comment.