From c27fdc80b5a6eff5794fe3a15a936a86a98f8325 Mon Sep 17 00:00:00 2001 From: Jason Sarich Date: Fri, 4 Nov 2022 09:59:53 -0500 Subject: [PATCH 1/4] Add new tests for grid tools --- .../tools/mkatmsrffile/test_mkatmsrffile.sh | 135 ++++++++++++ .../cube_to_target/test_cube_to_target.sh | 105 ++++++++++ .../tools/mksurfdata_map/test_mksurfdat.sh | 192 ++++++++++++++++++ 3 files changed, 432 insertions(+) create mode 100755 components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh create mode 100755 components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh create mode 100755 components/elm/tools/mksurfdata_map/test_mksurfdat.sh diff --git a/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh b/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh new file mode 100755 index 000000000000..eb9d270f8575 --- /dev/null +++ b/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +# get arguments +# Need --e3sm_root= +# --reference_files= +# --inputdata_root= + +# See step 9 in +# https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids + +e3sm_root="default" +test_root="default" +inputdata_root="default" +reference_files="default" + +for arg in "$@" +do +case $arg in + -e=*|--e3sm_root=*) + e3sm_root="${arg#*=}" + shift + ;; + + -i=*|--inputdata_root=*) + inputdata_root="${arg#*=}" + shift + ;; + + -r=*|--reference_files=*) + reference_files="${arg#*=}" + shift + ;; + +esac +done + +if [[ ${e3sm_root} == "default" ]]; then + echo "Error: e3sm_root not set" >&2 + exit 1; +fi + +if [[ ${inputdata_root} == "default" ]]; then + echo "Error: inputdata_root not set" >&2 + exit 1; +fi + +if [[ ${reference_files} == "default" ]]; then + echo "Error: reference_files not set" >&2 + exit 1; +fi + +output_root=$PWD +cime_root=${e3sm_root}/cime + +# Add testing bin to path +PATH=${test_root}/bin:${PATH} + +# We will redirect verbose test log output to a file; remove any existing +# versions of this file first +test_log=${PWD}/test.out +rm -f ${test_log} + + +srf_file=${reference_files}/1x1d.nc +atm_file=${reference_files}/ne30np4_pentagons.091226.nc +land_file=${inputdata_root}/atm/cam/chem/trop_mozart/dvel/regrid_vegetation.nc +soilw_file=${inputdata_root}/atm/cam/chem/trop_mozart/dvel/clim_soilw.nc +srf2atm_file=${reference_files}/map_1x1_to_ne30np4_aave.nc + +for i in ${srf_file} ${atm_file} ${land_file} ${soilw_file} ${srf2atm_file} +do + if [ ! -f $i ]; then + echo "Error: file ${i} not found" >&2 + exit 1 + fi +done + +output_file=${PWD}/atmsrf_ne30np4.nc + +echo "build mkatmsrrfile in ${PWD}/builds ..." >> ${test_log} +mkdir -p builds +cd builds +${cime_root}/CIME/scripts/configure --mpilib mpich --macros-format Makefile >> ${test_log} 2>&1 + +if [ ! -f .env_mach_specific.sh ]; then + if [ ! -f .env_mach_specific.sh ]; then + echo "ERROR running ${cime_root}/CIME/scripts/configure" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 + fi +fi +cp ${e3sm_root}/components/eam/tools/mkatmsrffile/* . +sed "s:^FFLAGS:#FFLAGS:g" Makefile | sed "s:^INC:#INC^:g" | sed "s:^LIB:#LIB:g" > Makefile.tmp +echo "include Macros.make" > Makefile +echo 'FC=${MPIFC}' >> Makefile +echo 'LIB=${SLIBS}' >> Makefile +echo 'FFLAGS+=-I${NETCDF_PATH}/include' >> Makefile +cat Makefile.tmp >> Makefile + +cat < nml_atmsrf +&input +srfFileName = '${srf_file}' +atmFileName = '${atm_file}' +landFileName = '${land_file}' +soilwFileName = '${soilw_file}' +srf2atmFmapname = '${srf2atm_file}' +outputFileName = '${output_file}' +/ + +EOF + + + +# + +(. .env_mach_specific.sh && export FC=gfortran && export LIB_NETCDF=${NETCDF_FORTRAN_PATH}/lib && export INC_NETCDF=${NETCDF_FORTRAN_PATH/include} && make) >> ${test_log} 2>&1 +if [ ! -f mkatmsrffile ]; then + echo "ERROR building mkatmsrffile" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +rm -f ${output_file} +echo "Running mkatmsrffile" >> ${test_log} 2>&1 +(. .env_mach_specific.sh && ./mkatmsrffile ) >> ${test_log} + +if [ ! -f ${output_file} ]; then + echo "Error: file ${i} not found" >&2 + exit 1 +else + echo "output file ${i} created" >> ${test_log} 2>&1 +fi + + +exit 0 diff --git a/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh b/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh new file mode 100755 index 000000000000..8410c24c2a15 --- /dev/null +++ b/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# get arguments +# Need --e3sm_root= + +# Also need tempest in PATH for now... + + +# test mkdurfdat.pl to generate land surface data +# See step 7 in +# https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids + +e3sm_root="default" +test_root="default" +inputdata_root="default" +reference_files="default" + +for arg in "$@" +do +case $arg in + -e=*|--e3sm_root=*) + e3sm_root="${arg#*=}" + shift + ;; + + -i=*|--inputdata_root=*) + inputdata_root="${arg#*=}" + shift + ;; + + -r=*|--reference_files=*) + reference_files="${arg#*=}" + shift + ;; + +esac +done + +if [[ ${e3sm_root} == "default" ]]; then + echo "Error: e3sm_root not set" >&2 + exit 1; +fi + +if [[ ${inputdata_root} == "default" ]]; then + echo "Error: inputdata_root not set" >&2 + exit 1; +fi + +if [[ ${reference_files} == "default" ]]; then + echo "Error: reference_files not set" >&2 + exit 1; +fi + +output_root=$PWD +cime_root=${e3sm_root}/cime + +# Add testing bin to path +PATH=${test_root}/bin:${PATH} + +# We will redirect verbose test log output to a file; remove any existing +# versions of this file first +test_log=${PWD}/test.out +rm -f ${test_log} + + +target_grid=${reference_files}/ne30pg4_scrip.nc +input_topo=${inputdata_root}/atm/cam/topo/USGS-topo-cube3000.nc +output_topo=${PWD}/output.nc + +echo "build cube_to_data in ${PWD}/builds ..." >> ${test_log} +mkdir -p builds +cd builds +${cime_root}/CIME/scripts/configure --mpilib mpich --macros-format Makefile >> ${test_log} 2>&1 + +if [ ! -f .env_mach_specific.sh ]; then + if [ ! -f .env_mach_specific.sh ]; then + echo "ERROR running ${cime_root}/CIME/scripts/configure" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 + fi +fi +cp ${e3sm_root}/components/eam/tools/topo_tool/cube_to_target/* . +sed "s:^FFLAGS:#FFLAGS:g" Makefile | sed "s:^LDFLAGS:#LDFLAGS:g" > Makefile.tmp +echo "include Macros.make" > Makefile +echo 'FC=${MPIFC}' >> Makefile +echo 'LDFLAGS=${SLIBS}' >> Makefile +echo 'FFLAGS+=-I${NETCDF_PATH}/include' >> Makefile +cat Makefile.tmp >> Makefile + + + +# + +(. .env_mach_specific.sh && export FC=gfortran && export LIB_NETCDF=${NETCDF_FORTRAN_PATH}/lib && export INC_NETCDF=${NETCDF_FORTRAN_PATH/include} && make) >> ${test_log} 2>&1 + +if [ ! -f cube_to_target ]; then + echo "ERROR building cube_to_target" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +echo "Running cube_to_target" >> ${test_log} 2>&1 +(. .env_mach_specific.sh && ./cube_to_target --target-grid ${target_grid} --input-topography ${input_topo} --output-topography ${output_topo} ) >> ${test_log} + +exit 0 diff --git a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh new file mode 100755 index 000000000000..5623b307a277 --- /dev/null +++ b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh @@ -0,0 +1,192 @@ +#!/bin/bash + +# get arguments +# Need --e3sm_root= +# --ESMFBIN= +# --inputdata_root= + +# Also need tempest in PATH for now... + + +# test mkdurfdat.pl to generate land surface data +# See step 7 in +# https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids + +e3sm_root="default" +test_root="default" +esmfbin="default" +inputdata_root="default" + +for arg in "$@" +do +case $arg in + -e=*|--e3sm_root=*) + e3sm_root="${arg#*=}" + shift + ;; + + -E=*|--ESMFBIN=*) + esmfbin="${arg#*=}" + shift + ;; + + -i=*|--inputdata_root=*) + inputdata_root="${arg#*=}" + shift + ;; + +esac +done + +if [[ ${inputdata_root} == "default" ]]; then + echo "Error: inputdata_root not set" >&2 + exit 1; +fi +if [[ ${e3sm_root} == "default" ]]; then + echo "Error: e3sm_root not set" >&2 + exit 1; +fi +if [[ ${esmfbin} == "default" ]]; then + echo "Error: ESMFBIN not set" >&2 + exit 1; +fi + +export ESMFBIN_PATH=${esmfbin} + +output_root=$PWD +cime_root=${e3sm_root}/cime + +# Add testing bin to path +PATH=${test_root}/bin:${PATH} + +# We will redirect verbose test log output to a file; remove any existing +# versions of this file first +test_log=${PWD}/test.out +rm -f ${test_log} + +########### +### 1 ### Create mapping files for each land surface type if needed +########### + +# a) +# Obtain or generate a target grid file in SCRIP format. For these example, we will use a ne1024pg2 grid file, +# which we will need to create (note that most np4 grid files can be found within the inputdata repository, for +# example, the ne1024np4 grid file is at +# https://web.lcrc.anl.gov/public/e3sm/mapping/grids/ne1024np4_scrip_c20191023.nc) + +generatecsmesh=`which GenerateCSMesh` +generatevolumetricmesh=`which GenerateVolumetricMesh` +convertexodustoscrip=`which ConvertMeshToSCRIP` +mksurfdata_map=`which mksurfdata_map` # TODO compile this + +#ne1024g=${cime_root}/tools/mapping/tests/reference_files/ne1024.g +# These files will be created +meshfile=ne4.g +gridfile=ne4pg2.g +scripfile=ne4pg2_scrip.nc + +echo "Running ${generatecsmesh}" >> ${test_log} 2>&1 +(${generatecsmesh} --alt --res 30 --file ${meshfile}) >> ${test_log} 2>&1 +if [ ! -f ${meshfile} ]; then + echo "ERROR: GenerateVolumetricMesh: no ${meshfile} file created" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +echo "Running ${generatevolumetricmesh}" >> ${test_log} 2>&1 +(${generatevolumetricmesh} --in ${meshfile} --out ${gridfile} --np 2 --uniform) >> ${test_log} 2>&1 +if [ ! -f ${gridfile} ]; then + echo "ERROR: GenerateVolumetricMesh: no ${gridfile} file created" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +echo "Running ${convertexodustoscrip}" >> ${test_log} 2>&1 +(${convertexodustoscrip} --in ${meshfile} --out ${scripfile}) >> ${test_log} 2>&1 +if [ ! -f ${scripfile} ]; then + echo "ERROR: ConvertExodusToSCRIP: no ${scripfile} file created" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + + + +# b) +# Get list of input grid files for each land surface input data file. This is done by running the +# components/clm/tools/shared/mkmapdata/mkmapdata.sh script in debug mode to output a list of needed +# files (along with the commands that will be used to generate each map file; also make sure GRIDFILE +# is set to the SCRIP file from the above step): +mkmapdata=${e3sm_root}/components/elm/tools/mkmapdata/mkmapdata.sh +if [ ! -f ${makemapdata} ]; then + echo "ERROR: mkmapdata.sh not found" + exit 1 +fi + + +# Gen env_mach_specific +${cime_root}/CIME/scripts/configure --mpilib mpich --macros-format Makefile >> ${test_log} 2>&1 + +echo "Running ${mkmapdata}" >> ${test_log} 2>&1 +(. .env_mach_specific.sh && set -x && ${mkmapdata} --gridfile ${scripfile} --inputdata-path ${inputdata_root} --res ne4pg2 --gridtype global --output-filetype 64bit_offset) >> ${test_log} 2>&1 + + +set +x +#awk '/ingrid/ {print $3}' clm.input_data_list > files.txt +missingfile="no" +#for filename in `cat files.txt`; do +# if [ ! -f ${filename} ]; then +# echo "${filename} not found" +# missingfile="yes" +# fi +#done + +if [ ${missingfile} == "yes" ]; then + echo "Error: missing files. Try downloading from" + echo "https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata" + echo "or" + echo "https://web.lcrc.anl.gov/public/e3sm/inputdata" + exit 1 +fi + +# d) Create mapping file + +############## +#### 3 ##### +############## + +echo "build mksurfdata_map" >> ${test_log} +if [ ! -f .env_mach_specific.sh ]; then + # try without mpi-serial flag + echo "ERROR running ${cime_root}/CIME/scripts/configure" >&2 + echo "It's possible mpi-serial doesn't work on this machine. Trying again with default" >&2 + ${cime_root}/CIME/scripts/configure --clean >> ${test_log} 2>&1 + (. .env_mach_specific.sh && ${cime_root}/CIME/scripts/configure --macros-format Makefile) >> ${test_log} 2>&1 + if [ ! -f .env_mach_specific.sh ]; then + echo "ERROR running ${cime_root}/CIME/scripts/configure" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 + fi +else + (. .env_mach_specific.sh && ${cime_root}/CIME/scripts/configure --macros-format Makefile --mpilib mpi-serial) >> ${test_log} 2>&1 +fi + +cp ${e3sm_root}/components/elm/tools/mksurfdata_map/src/* . +echo 'export USER_FC=$FC' >> .env_mach_specific.sh +echo 'export USER_CC=$CC' >> .env_mach_specific.sh +echo 'export LIB_NETCDF=$NETCDF_PATH/lib' >> .env_mach_specific.sh +echo 'export INC_NETCDF=$NETCDF_PATH/include' >> .env_mach_specific.sh +(. .env_mach_specific.sh && make) >> ${test_log} 2>&1 +if [ ! -f ${mksurfdat_map} ]; then + echo "ERROR finding/building mksurfdata_map" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +echo "Running mksurfdata.pl" >> ${test_log} 2>&1 +mapdir=${inputdat_root}/lnd/clm2/mappingdata/maps/ne4np4 +(. .env_mach_specific.sh && ${e3sm_root}/components/elm/tools/mksurfdata_map/mksurfdata.pl -res ne4np4 -y 2010 -d -dinlc ${inputdata_root} -usr_mapdir ${mapdir}) >> ${test_log} + + + + +exit 0 From 54a0e9c5bee51c99994cea80f811bcdbaa8a2821 Mon Sep 17 00:00:00 2001 From: Jason Sarich Date: Fri, 18 Nov 2022 10:47:19 -0600 Subject: [PATCH 2/4] Clean up grid test scripts --- .../tools/mkatmsrffile/test_mkatmsrffile.sh | 5 ++-- .../cube_to_target/test_cube_to_target.sh | 16 ++++--------- .../tools/mksurfdata_map/test_mksurfdat.sh | 24 +------------------ 3 files changed, 8 insertions(+), 37 deletions(-) diff --git a/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh b/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh index eb9d270f8575..bdb3ba6c363a 100755 --- a/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh +++ b/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh @@ -5,9 +5,6 @@ # --reference_files= # --inputdata_root= -# See step 9 in -# https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids - e3sm_root="default" test_root="default" inputdata_root="default" @@ -90,6 +87,8 @@ if [ ! -f .env_mach_specific.sh ]; then fi fi cp ${e3sm_root}/components/eam/tools/mkatmsrffile/* . + +# Edit Makefile to use variables created by configure sed "s:^FFLAGS:#FFLAGS:g" Makefile | sed "s:^INC:#INC^:g" | sed "s:^LIB:#LIB:g" > Makefile.tmp echo "include Macros.make" > Makefile echo 'FC=${MPIFC}' >> Makefile diff --git a/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh b/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh index 8410c24c2a15..cea86e01475b 100755 --- a/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh +++ b/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh @@ -2,13 +2,8 @@ # get arguments # Need --e3sm_root= - -# Also need tempest in PATH for now... - - -# test mkdurfdat.pl to generate land surface data -# See step 7 in -# https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids +# --reference_files= +# --inputdata_root= e3sm_root="default" test_root="default" @@ -79,7 +74,9 @@ if [ ! -f .env_mach_specific.sh ]; then exit 1 fi fi + cp ${e3sm_root}/components/eam/tools/topo_tool/cube_to_target/* . +#Edit Makefile to use macros defined by configure in Macros.make sed "s:^FFLAGS:#FFLAGS:g" Makefile | sed "s:^LDFLAGS:#LDFLAGS:g" > Makefile.tmp echo "include Macros.make" > Makefile echo 'FC=${MPIFC}' >> Makefile @@ -87,10 +84,7 @@ echo 'LDFLAGS=${SLIBS}' >> Makefile echo 'FFLAGS+=-I${NETCDF_PATH}/include' >> Makefile cat Makefile.tmp >> Makefile - - -# - +# Compile (. .env_mach_specific.sh && export FC=gfortran && export LIB_NETCDF=${NETCDF_FORTRAN_PATH}/lib && export INC_NETCDF=${NETCDF_FORTRAN_PATH/include} && make) >> ${test_log} 2>&1 if [ ! -f cube_to_target ]; then diff --git a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh index 5623b307a277..5372fe8cef5f 100755 --- a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh +++ b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh @@ -7,7 +7,6 @@ # Also need tempest in PATH for now... - # test mkdurfdat.pl to generate land surface data # See step 7 in # https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids @@ -77,9 +76,8 @@ rm -f ${test_log} generatecsmesh=`which GenerateCSMesh` generatevolumetricmesh=`which GenerateVolumetricMesh` convertexodustoscrip=`which ConvertMeshToSCRIP` -mksurfdata_map=`which mksurfdata_map` # TODO compile this +mksurfdata_map=`which mksurfdata_map` -#ne1024g=${cime_root}/tools/mapping/tests/reference_files/ne1024.g # These files will be created meshfile=ne4.g gridfile=ne4pg2.g @@ -130,24 +128,6 @@ echo "Running ${mkmapdata}" >> ${test_log} 2>&1 (. .env_mach_specific.sh && set -x && ${mkmapdata} --gridfile ${scripfile} --inputdata-path ${inputdata_root} --res ne4pg2 --gridtype global --output-filetype 64bit_offset) >> ${test_log} 2>&1 -set +x -#awk '/ingrid/ {print $3}' clm.input_data_list > files.txt -missingfile="no" -#for filename in `cat files.txt`; do -# if [ ! -f ${filename} ]; then -# echo "${filename} not found" -# missingfile="yes" -# fi -#done - -if [ ${missingfile} == "yes" ]; then - echo "Error: missing files. Try downloading from" - echo "https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata" - echo "or" - echo "https://web.lcrc.anl.gov/public/e3sm/inputdata" - exit 1 -fi - # d) Create mapping file ############## @@ -187,6 +167,4 @@ mapdir=${inputdat_root}/lnd/clm2/mappingdata/maps/ne4np4 (. .env_mach_specific.sh && ${e3sm_root}/components/elm/tools/mksurfdata_map/mksurfdata.pl -res ne4np4 -y 2010 -d -dinlc ${inputdata_root} -usr_mapdir ${mapdir}) >> ${test_log} - - exit 0 From 5225bf40c87ce2c52f019f242046915fee547170 Mon Sep 17 00:00:00 2001 From: Jason Sarich Date: Wed, 21 Dec 2022 10:59:21 -0600 Subject: [PATCH 3/4] Add documentation to tests --- .../tools/mkatmsrffile/test_mkatmsrffile.sh | 31 ++++++- .../cube_to_target/test_cube_to_target.sh | 82 ++++++++++++++++--- .../tools/mksurfdata_map/test_mksurfdat.sh | 80 ++++++++++++------ 3 files changed, 156 insertions(+), 37 deletions(-) diff --git a/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh b/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh index bdb3ba6c363a..a2b718103a69 100755 --- a/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh +++ b/components/eam/tools/mkatmsrffile/test_mkatmsrffile.sh @@ -1,9 +1,19 @@ #!/bin/bash -# get arguments -# Need --e3sm_root= -# --reference_files= -# --inputdata_root= +display_help() { + echo "Usage: $0 " >&2 + echo + echo " -e, --e3sm_root Specify location of E3SM" + echo " -h, --help Display this message" + echo " -i, --inputdata_root Specify location of climate inputdata" + echo " -r, --reference_files Specify location where files" + + echo " 1x1d.nc, ne30np4_pentagons.091226.nc," + echo " map_1x1_to_ne30np4_aave.nc" + echo " are located" + echo + echo "NOTE: requires tempestremap and ESMF tools to be in PATH environment variable" +} e3sm_root="default" test_root="default" @@ -28,21 +38,34 @@ case $arg in shift ;; + -*) + display_help + exit 1; + ;; + + -h|--help) + display_help + exit 0; + ;; + esac done if [[ ${e3sm_root} == "default" ]]; then echo "Error: e3sm_root not set" >&2 + display_help exit 1; fi if [[ ${inputdata_root} == "default" ]]; then echo "Error: inputdata_root not set" >&2 + display_help exit 1; fi if [[ ${reference_files} == "default" ]]; then echo "Error: reference_files not set" >&2 + display_help exit 1; fi diff --git a/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh b/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh index cea86e01475b..7122fed5fe1c 100755 --- a/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh +++ b/components/eam/tools/topo_tool/cube_to_target/test_cube_to_target.sh @@ -1,5 +1,15 @@ #!/bin/bash +display_help() { + echo "Usage: $0 " >&2 + echo + echo " -e, --e3sm_root Specify location of E3SM" + echo " -h, --help Display this message" + echo " -i, --inputdata_root Specify location of climate inputdata" + echo +} + + # get arguments # Need --e3sm_root= # --reference_files= @@ -8,7 +18,6 @@ e3sm_root="default" test_root="default" inputdata_root="default" -reference_files="default" for arg in "$@" do @@ -23,9 +32,14 @@ case $arg in shift ;; - -r=*|--reference_files=*) - reference_files="${arg#*=}" - shift + -*) + display_help + exit 1; + ;; + + -h|--help) + display_help + exit 0; ;; esac @@ -33,16 +47,13 @@ done if [[ ${e3sm_root} == "default" ]]; then echo "Error: e3sm_root not set" >&2 + display_help exit 1; fi if [[ ${inputdata_root} == "default" ]]; then echo "Error: inputdata_root not set" >&2 - exit 1; -fi - -if [[ ${reference_files} == "default" ]]; then - echo "Error: reference_files not set" >&2 + display_help exit 1; fi @@ -58,10 +69,61 @@ test_log=${PWD}/test.out rm -f ${test_log} +generatecsmesh=`which GenerateCSMesh` +generatevolumetricmesh=`which GenerateVolumetricMesh` +convertmeshtoscrip=`which ConvertMeshToSCRIP` + +if [ "${generatecsmesh}x" == "x" ]; then + echo "ERROR: tempestremap tool GenerateCSMesh not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +if [ "${generatevolumetricmesh}x" == "x" ]; then + echo "ERROR: tempestremap tool GenerateVolumetricMesh not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +if [ "${convertmeshtoscrip}x" == "x" ]; then + echo "ERROR: tempestremap tool ConvertMeshToScrip not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + + +meshfile=ne30.g +gridfile=ne30pg4.g +scripfile=ne30pg4_scrip.nc target_grid=${reference_files}/ne30pg4_scrip.nc input_topo=${inputdata_root}/atm/cam/topo/USGS-topo-cube3000.nc output_topo=${PWD}/output.nc +echo "Running ${generatecsmesh}" >> ${test_log} 2>&1 +(${generatecsmesh} --alt --res 30 --file ${meshfile}) >> ${test_log} 2>&1 +if [ ! -f ${meshfile} ]; then + echo "ERROR: GenerateCSMesh: no ${meshfile} file created" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +echo "Running ${generatevolumetricmesh}" >> ${test_log} 2>&1 +(${generatevolumetricmesh} --in ${meshfile} --out ${gridfile}) >> ${test_log} 2>&1 +if [ ! -f ${gridfile} ]; then + echo "ERROR: GenerateVolumetricMesh: no ${gridfile} file created" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +echo "Running ${convertmeshtoscrip}" >> ${test_log} 2>&1 +(${convertmeshtoscrip} --in ${meshfile} --out ${scripfile}) >> ${test_log} 2>&1 +if [ ! -f ${scripfile} ]; then + echo "ERROR: ConvertMeshToSCRIP: no ${scripfile} file created" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + + echo "build cube_to_data in ${PWD}/builds ..." >> ${test_log} mkdir -p builds cd builds @@ -94,6 +156,6 @@ if [ ! -f cube_to_target ]; then fi echo "Running cube_to_target" >> ${test_log} 2>&1 -(. .env_mach_specific.sh && ./cube_to_target --target-grid ${target_grid} --input-topography ${input_topo} --output-topography ${output_topo} ) >> ${test_log} +(. .env_mach_specific.sh && ./build/cube_to_target --target-grid ${target_grid} --input-topography ${input_topo} --output-topography ${output_topo} ) >> ${test_log} exit 0 diff --git a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh index 5372fe8cef5f..e35c3636c16d 100755 --- a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh +++ b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh @@ -1,19 +1,25 @@ #!/bin/bash +display_help() { + echo "Usage: $0 " >&2 + echo + echo " -e, --e3sm_root Specify location of E3SM" + echo " -h, --help Display this message" + echo " -i, --inputdata_root Specify location of climate inputdata" + echo + echo "NOTE: requires tempestremap and ESMF tools to be in PATH environment variable" +} + # get arguments # Need --e3sm_root= -# --ESMFBIN= # --inputdata_root= -# Also need tempest in PATH for now... - # test mkdurfdat.pl to generate land surface data # See step 7 in # https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/872579110/Running+E3SM+on+New+Grids e3sm_root="default" test_root="default" -esmfbin="default" inputdata_root="default" for arg in "$@" @@ -24,33 +30,34 @@ case $arg in shift ;; - -E=*|--ESMFBIN=*) - esmfbin="${arg#*=}" - shift - ;; - -i=*|--inputdata_root=*) inputdata_root="${arg#*=}" shift ;; + -*) + display_help + exit 1; + ;; + + -h|--help) + display_help + exit 0; + ;; + esac done if [[ ${inputdata_root} == "default" ]]; then echo "Error: inputdata_root not set" >&2 + display_help exit 1; fi if [[ ${e3sm_root} == "default" ]]; then echo "Error: e3sm_root not set" >&2 + display_help exit 1; fi -if [[ ${esmfbin} == "default" ]]; then - echo "Error: ESMFBIN not set" >&2 - exit 1; -fi - -export ESMFBIN_PATH=${esmfbin} output_root=$PWD cime_root=${e3sm_root}/cime @@ -73,10 +80,37 @@ rm -f ${test_log} # example, the ne1024np4 grid file is at # https://web.lcrc.anl.gov/public/e3sm/mapping/grids/ne1024np4_scrip_c20191023.nc) -generatecsmesh=`which GenerateCSMesh` -generatevolumetricmesh=`which GenerateVolumetricMesh` -convertexodustoscrip=`which ConvertMeshToSCRIP` -mksurfdata_map=`which mksurfdata_map` +generatecsmesh=$(which GenerateCSMesh) +generatevolumetricmesh=$(which GenerateVolumetricMesh) +convertmeshtoscrip=$(which ConvertMeshToSCRIP) +esmfregridweightgen=$(which ESMF_RegridWeightGen) + +#test for tempestremap and ESMF tools +if [ "${esmfregridweightgen}x" == "x" ]; then + echo "ERROR: ESMF tool ESMF_RegridWeightGen not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +if [ "${generatecsmesh}x" == "x" ]; then + echo "ERROR: tempestremap tool GenerateCSMesh not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +if [ "${generatevolumetricmesh}x" == "x" ]; then + echo "ERROR: tempestremap tool GenerateVolumetricMesh not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + +if [ "${convertmeshtoscrip}x" == "x" ]; then + echo "ERROR: tempestremap tool ConvertMeshToScrip not found in PATH" >&2 + echo "cat ${test_log} for more info" >&2 + exit 1 +fi + + # These files will be created meshfile=ne4.g @@ -84,9 +118,9 @@ gridfile=ne4pg2.g scripfile=ne4pg2_scrip.nc echo "Running ${generatecsmesh}" >> ${test_log} 2>&1 -(${generatecsmesh} --alt --res 30 --file ${meshfile}) >> ${test_log} 2>&1 +(${generatecsmesh} --alt --res 4 --file ${meshfile}) >> ${test_log} 2>&1 if [ ! -f ${meshfile} ]; then - echo "ERROR: GenerateVolumetricMesh: no ${meshfile} file created" >&2 + echo "ERROR: GenerateCSMesh: no ${meshfile} file created" >&2 echo "cat ${test_log} for more info" >&2 exit 1 fi @@ -99,8 +133,8 @@ if [ ! -f ${gridfile} ]; then exit 1 fi -echo "Running ${convertexodustoscrip}" >> ${test_log} 2>&1 -(${convertexodustoscrip} --in ${meshfile} --out ${scripfile}) >> ${test_log} 2>&1 +echo "Running ${convertmeshtoscrip}" >> ${test_log} 2>&1 +(${convertmeshtoscrip} --in ${meshfile} --out ${scripfile}) >> ${test_log} 2>&1 if [ ! -f ${scripfile} ]; then echo "ERROR: ConvertExodusToSCRIP: no ${scripfile} file created" >&2 echo "cat ${test_log} for more info" >&2 From a120eb65ebd2a44e1b92e2cf6e4f22ac2fbbc8ee Mon Sep 17 00:00:00 2001 From: Jason Sarich Date: Thu, 22 Dec 2022 13:24:22 -0600 Subject: [PATCH 4/4] fix compile problems and arguments for mksurfdata.pl --- .../tools/mksurfdata_map/test_mksurfdat.sh | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh index e35c3636c16d..89025b09726b 100755 --- a/components/elm/tools/mksurfdata_map/test_mksurfdat.sh +++ b/components/elm/tools/mksurfdata_map/test_mksurfdat.sh @@ -69,6 +69,8 @@ PATH=${test_root}/bin:${PATH} # versions of this file first test_log=${PWD}/test.out rm -f ${test_log} +mkdir -p src +cd src ########### ### 1 ### Create mapping files for each land surface type if needed @@ -114,8 +116,8 @@ fi # These files will be created meshfile=ne4.g -gridfile=ne4pg2.g -scripfile=ne4pg2_scrip.nc +gridfile=ne4pg4.g +scripfile=ne4pg4_scrip.nc echo "Running ${generatecsmesh}" >> ${test_log} 2>&1 (${generatecsmesh} --alt --res 4 --file ${meshfile}) >> ${test_log} 2>&1 @@ -126,7 +128,7 @@ if [ ! -f ${meshfile} ]; then fi echo "Running ${generatevolumetricmesh}" >> ${test_log} 2>&1 -(${generatevolumetricmesh} --in ${meshfile} --out ${gridfile} --np 2 --uniform) >> ${test_log} 2>&1 +(${generatevolumetricmesh} --in ${meshfile} --out ${gridfile} --np 4 --uniform) >> ${test_log} 2>&1 if [ ! -f ${gridfile} ]; then echo "ERROR: GenerateVolumetricMesh: no ${gridfile} file created" >&2 echo "cat ${test_log} for more info" >&2 @@ -159,7 +161,7 @@ fi ${cime_root}/CIME/scripts/configure --mpilib mpich --macros-format Makefile >> ${test_log} 2>&1 echo "Running ${mkmapdata}" >> ${test_log} 2>&1 -(. .env_mach_specific.sh && set -x && ${mkmapdata} --gridfile ${scripfile} --inputdata-path ${inputdata_root} --res ne4pg2 --gridtype global --output-filetype 64bit_offset) >> ${test_log} 2>&1 +(. .env_mach_specific.sh && set -x && ${mkmapdata} --gridfile ${scripfile} --inputdata-path ${inputdata_root} --res ne4pg4 --gridtype global --output-filetype 64bit_offset) >> ${test_log} 2>&1 # d) Create mapping file @@ -167,28 +169,18 @@ echo "Running ${mkmapdata}" >> ${test_log} 2>&1 ############## #### 3 ##### ############## - -echo "build mksurfdata_map" >> ${test_log} -if [ ! -f .env_mach_specific.sh ]; then - # try without mpi-serial flag - echo "ERROR running ${cime_root}/CIME/scripts/configure" >&2 - echo "It's possible mpi-serial doesn't work on this machine. Trying again with default" >&2 - ${cime_root}/CIME/scripts/configure --clean >> ${test_log} 2>&1 - (. .env_mach_specific.sh && ${cime_root}/CIME/scripts/configure --macros-format Makefile) >> ${test_log} 2>&1 - if [ ! -f .env_mach_specific.sh ]; then - echo "ERROR running ${cime_root}/CIME/scripts/configure" >&2 - echo "cat ${test_log} for more info" >&2 - exit 1 - fi -else - (. .env_mach_specific.sh && ${cime_root}/CIME/scripts/configure --macros-format Makefile --mpilib mpi-serial) >> ${test_log} 2>&1 -fi - +echo "build mksurfdata_map" >> ${test_log} 2>&1 +today=$(date +%y%m%d) cp ${e3sm_root}/components/elm/tools/mksurfdata_map/src/* . -echo 'export USER_FC=$FC' >> .env_mach_specific.sh -echo 'export USER_CC=$CC' >> .env_mach_specific.sh -echo 'export LIB_NETCDF=$NETCDF_PATH/lib' >> .env_mach_specific.sh -echo 'export INC_NETCDF=$NETCDF_PATH/include' >> .env_mach_specific.sh +cat <> .env_mach_specific.sh +export USER_FC="$(awk '/MPIFC :=/ {$1=$2=""; print $0}' Macros.make)" +export USER_CPPDEFS="$(awk '/CPPDEFS :=/ {$1=$2=$3=""; print $0}' Macros.make)" +export USER_FFLAGS="$(awk '/FFLAGS :=/ {$1=$2=""; print $0}' Macros.make)" +export USER_LDFLAGS="$(awk '/SLIBS :=/ {$1=$2=$3=""; print $0}' Macros.make)" +export LIB_NETCDF=$NETCDF_PATH/lib +export INC_NETCDF=$NETCDF_PATH/include +EOF +sed -i 's|\.\./\.\./\.\.|..|' Makefile.common (. .env_mach_specific.sh && make) >> ${test_log} 2>&1 if [ ! -f ${mksurfdat_map} ]; then echo "ERROR finding/building mksurfdata_map" >&2 @@ -197,8 +189,8 @@ if [ ! -f ${mksurfdat_map} ]; then fi echo "Running mksurfdata.pl" >> ${test_log} 2>&1 -mapdir=${inputdat_root}/lnd/clm2/mappingdata/maps/ne4np4 -(. .env_mach_specific.sh && ${e3sm_root}/components/elm/tools/mksurfdata_map/mksurfdata.pl -res ne4np4 -y 2010 -d -dinlc ${inputdata_root} -usr_mapdir ${mapdir}) >> ${test_log} +echo "${e3sm_root}/components/elm/tools/mksurfdata_map/mksurfdata.pl -res usrspec -usr_gname ne4pg4 -usr_gdate ${today} -y 2010 -d -dinlc ${inputdata_root} -usr_mapdir ${PWD}" >> ${test_log} 2>&1 +(. .env_mach_specific.sh && ${e3sm_root}/components/elm/tools/mksurfdata_map/mksurfdata.pl -res usrspec -usr_gname ne4pg4 -usr_gdate ${today} -y 2010 -d -dinlc ${inputdata_root} -usr_mapdir ${PWD}) >> ${test_log} 2>&1 exit 0