Skip to content

Commit

Permalink
Baseline initial driver script for new test format.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGayno-NOAA committed Jan 22, 2025
1 parent c24632c commit 0f9f921
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 6 deletions.
87 changes: 87 additions & 0 deletions reg_tests/cpld_gridgen/rt2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

set -x

readonly program=$(basename $0)
# PATHRT - Path to regression tests directory
readonly PATHRT="$(cd $(dirname $0) && pwd -P)"
export PATHRT
# PATHTR - Path to the UFS UTILS directory
readonly PATHTR="$(cd $PATHRT/../.. && pwd)"
export PATHTR

export compiler=${compiler:-intelllvm}
source $PATHTR/sorc/machine-setup.sh >/dev/null 2>&1
if [[ "$compiler" == "intelllvm" ]]; then
if [[ ! -f ${PATHTR}/modulefiles/build.$target.$compiler.lua ]];then
echo "IntelLLVM not available. Will use Intel Classic."
compiler=intel
fi
fi
echo "Machine: $target"
echo "Compiler: $compiler"

module use $PATHTR/modulefiles
module load build.$target.$compiler
if [[ $target = wcoss2 ]]; then
module load netcdf
module load nccmp
fi
set +x
module list
set -x

export CREATE_BASELINE=false
if [[ $target = hera ]]; then
export MOM6_FIXDIR=/scratch1/NCEPDEV/global/glopara/fix/mom6/20220805
STMP=${STMP:-/scratch2/NCEPDEV/stmp1/$USER}
export NCCMP=nccmp
BASELINE_ROOT=/scratch1/NCEPDEV/nems/role.ufsutils/ufs_utils/reg_tests/cpld_gridgen/baseline_data
fi


RUNDIR_ROOT=$STMP/CPLD_GRIDGEN/



declare -A tests
all_tests=""

i=0
while read -r line || [ "$line" ]; do

line="${line#"${line%%[![:space:]]*}"}"
[[ ${#line} == 0 ]] && continue
[[ $line =~ \# ]] && continue

TEST_NAME=$(echo $line | cut -d'|' -f1 | sed -e 's/^ *//' -e 's/ *$//')
TEST_NAME=${TEST_NAME##mx}

RUNDIR=$RUNDIR_ROOT/$TEST_NAME
rm -fr $RUNDIR
mkdir -p $RUNDIR
export RUNDIR
export OUTDIR_PATH=$RUNDIR
export BASELINE=$BASELINE_ROOT/$TEST_NAME
export REGRESSIONTEST_LOG=RegressionTests_$target.$compiler.${TEST_NAME}.log

cp $PATHRT/parm/grid.nml.IN $RUNDIR
cp $PATHTR/exec/cpld_gridgen $RUNDIR

tests[$i]=$(sbatch --parsable --ntasks-per-node=1 --nodes=1 -t 0:10:00 -A fv3-cpu -q batch -J "test${i}" \
-o log${i} -e log${i} $PATHTR/ush/cpld_gridgen.sh "$TEST_NAME")

exit

all_tests=${all_tests}":"${tests[$i]}

((i=i+1))
done < ./rt.conf

sbatch --nodes=1 -t 0:01:00 -A fv3-cpu -J summary -o logx -e logx \
--open-mode=append -q batch -d afterok${all_tests} << EOF
#!/bin/bash
grep -a 'finished test' log* > summary.log
EOF

exit
75 changes: 69 additions & 6 deletions ush/cpld_gridgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,74 @@ function edit_namelist {
-e "s/DO_POSTWGTS/$DO_POSTWGTS/g"
}

check_results() {

[ -o xtrace ] && set_x='set -x' || set_x='set +x'
set +x

local test_status=PASS
# verification run
if [[ $CREATE_BASELINE = false ]]; then

echo | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo "Working dir = $RUNDIR" | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo "Baseline dir = $BASELINE" | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo "Checking test $TEST_NAME results ...." | tee -a $PATHRT/$REGRESSIONTEST_LOG

for file in $BASELINE/*.nc; do
printf %s "Comparing " $(basename ${file}) "...." | tee -a $PATHRT/$REGRESSIONTEST_LOG

if [[ ! -f $RUNDIR/$(basename ${file}) ]]; then
echo "....MISSING file" | tee -a $PATHRT/$REGRESSIONTEST_LOG
test_status=FAIL
else
$NCCMP -dmfqS -w format $(basename ${file}) $file >>${PATHRT}/nccmp_${TEST_NAME}.log 2>&1 && d=$? || d=$?
if [[ $d -ne 0 ]]; then
echo "....NOT OK" | tee -a $PATHRT/$REGRESSIONTEST_LOG
test_status=FAIL
else
echo "....OK" | tee -a $PATHRT/$REGRESSIONTEST_LOG
fi
fi
done
echo | tee -a $PATHRT/$REGRESSIONTEST_LOG
# baseline creation run
else

echo | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo "Working dir = $RUNDIR" | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo "Moving baseline files to $NEW_BASELINE ...." | tee -a $PATHRT/$REGRESSIONTEST_LOG
echo | tee -a $PATHRT/$REGRESSIONTEST_LOG

mkdir -p $NEW_BASELINE

for file in *.nc; do
printf %s "Moving " $file "...." | tee -a $PATHRT/$REGRESSIONTEST_LOG

cp $file $NEW_BASELINE/$file && d=$? || d=$?
if [[ $d -ne 0 ]]; then
echo "....NOT OK" | tee -a $PATHRT/$REGRESSIONTEST_LOG
test_status=FAIL
else
echo "....OK" | tee -a $PATHRT/$REGRESSIONTEST_LOG
fi
done
echo | tee -a $PATHRT/$REGRESSIONTEST_LOG

fi

if [[ $test_status == FAIL ]]; then
echo "$TEST_NAME failed" >> $PATHRT/fail_test_$TEST_NAME
fi
}

echo top of cpld_gridgen.sh

cd $RUNDIR

export RESNAME=${RESNAME:-$1}
TEST_NAME=$RESNAME
export DEBUG=.false.
export MASKEDIT=.false.
export DO_POSTWGTS=.true.
Expand Down Expand Up @@ -76,12 +143,6 @@ if [ $RESNAME = 025 ]; then
fi
fi

if [ ! -d ${OUTDIR_PATH} ]; then
mkdir -p ${OUTDIR_PATH}
fi

cd ${OUTDIR_PATH}

edit_namelist < grid.nml.IN > grid.nml
$APRUN ./cpld_gridgen

Expand All @@ -94,3 +155,5 @@ $APRUN -n 1 ESMF_Scrip2Unstruct ${FSRC} ${FDST} 0
export FSRC=${OUTDIR_PATH}/grid_cice_NEMS_mx${RESNAME}.nc
export FDST=${OUTDIR_PATH}/kmtu_cice_NEMS_mx${RESNAME}.nc
ncks -O -v kmt ${FSRC} ${FDST}

check_results

0 comments on commit 0f9f921

Please sign in to comment.