From 38b1209eeaaa5f129800cb3adb0a70a061f11bcb Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 11 Sep 2024 12:19:19 -0400 Subject: [PATCH 01/11] attempt to add a test for frenctools --- .github/workflows/main.yml | 2 +- t/Makefile.am | 3 ++- t/Test34-timavg.sh | 27 ++++++++++++++++++++ t/test_time_avg.py | 51 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100755 t/Test34-timavg.sh create mode 100644 t/test_time_avg.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37f4487f..81a5b562 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: with_mpi: ['','--with-mpi'] enable_quad_precision: ['', '--enable-quad-precision'] container: - image: noaagfdl/fre-nctools-base:2.0.0-focal + image: ghcr.io/noaa-gfdl/fre-nctools-ci-rocky-gnu:14.2.0 env: MPI: ${{ matrix.with_mpi }} QUAD_P: ${{ matrix.enable_quad_precision }} diff --git a/t/Makefile.am b/t/Makefile.am index 7d88c42f..ea1da269 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -68,7 +68,8 @@ TESTS = Test01-check_programs_exist.sh \ Test29-make_vgrid.sh \ Test31-fregrid_stretched.sh \ Test32-fregrid_no_stretched.sh \ - Test33-reference_make_hgrid.sh + Test33-reference_make_hgrid.sh \ + Test34-timavg.sh EXTRA_DIST = $(TESTS) \ Test02-input\ diff --git a/t/Test34-timavg.sh b/t/Test34-timavg.sh new file mode 100755 index 00000000..3f3d9b96 --- /dev/null +++ b/t/Test34-timavg.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +#*********************************************************************** +# GNU Lesser General Public License +# +# This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools). +# +# FRE-NCTools is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# FRE-NCTools is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with FRE-NCTools. If not, see +# . +#*********************************************************************** + +load test_utils + +@test "Test timavg" { + python $top_srcdir/t/test_time_avg.py +} diff --git a/t/test_time_avg.py b/t/test_time_avg.py new file mode 100644 index 00000000..d0fe0365 --- /dev/null +++ b/t/test_time_avg.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import xarray as xr +import numpy as np +import os + +def init_fake_data(a, count=0., factor=1.): + with np.nditer(a, op_flags=['readwrite']) as it: + for x in it: + count = count + 1 + x[...] = count * factor + +class TestTimeAvg(): + def create_input(self): + print("Creating input files to test with") + nx = 96 + ny = 96 + nt = 12 + + a = np.zeros([nt, ny, nx]) + for k in range(0,nt): + for j in range(0,ny): + for i in range(0,nx): + a[k, j, i] = (i+1.)*1000 + (j+1.)*10 + (k+1.)/100. + self.a = a + + Time_attrs = {"units": "days since 2000-01-01", "axis": "T", "calendar_type": "JULIAN", "calendar": "julian"} + ds1 = xr.Dataset( + data_vars={ + ## This is backwards #FORTRAN4LYFE + "a": (("Time", "y", "x"), a), + "Time": (("Time", np.arange(nt)*1.0+1, Time_attrs)) + }, + coords={ + "x": np.arange(nx)*1.0, + "y": np.arange(ny)*1.0, + }, + ) + ds1.to_netcdf("20120101.ice_shelf.nc", unlimited_dims="Time") + + + def check_output(self): + out_file = xr.open_dataset("wut.nc") + if not (out_file.a.values == np.average(self.a, axis=0)).all(): + raise Exception("Test failed") + + +test_class = TestTimeAvg() +test_class.create_input() +os.system(os.path.dirname(os.path.realpath(__file__))+"/../postprocessing/timavg/timavg.csh -m -o wut.nc 20120101.ice_shelf.nc") +test_class.check_output() \ No newline at end of file From ea14300eb735a022aff921ecb349c3dd6b97ae9f Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 11 Sep 2024 12:23:45 -0400 Subject: [PATCH 02/11] fix? --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 81a5b562..21d0d1b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: QUAD_P: ${{ matrix.enable_quad_precision }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - name: Configure @@ -37,7 +37,7 @@ jobs: SKIP_TESTS: 4 run: make -C build -j check LOG_DRIVER_FLAGS=--comments - name: Save log file on failure - uses: actions/upload-artifact@v2.2.1 + uses: actions/upload-artifact@v3 if: failure() with: name: test-suite.log From 140c1b3b00905026a77bc6efe84e633d31323a38 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 11 Sep 2024 13:23:15 -0400 Subject: [PATCH 03/11] It fails as expected? --- t/Test34-timavg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/Test34-timavg.sh b/t/Test34-timavg.sh index 3f3d9b96..b44ec603 100755 --- a/t/Test34-timavg.sh +++ b/t/Test34-timavg.sh @@ -23,5 +23,5 @@ load test_utils @test "Test timavg" { - python $top_srcdir/t/test_time_avg.py + python3 $top_srcdir/t/test_time_avg.py } From 2e1bded138c4960f7efaa6c648623366be5d5a56 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Mon, 16 Sep 2024 10:46:42 -0400 Subject: [PATCH 04/11] check for xarray and python in the configure script, call the fortran executable instead of the .csh script --- configure.ac | 4 ++- m4/ax_python_module.m4 | 55 ++++++++++++++++++++++++++++++++++++++++++ t/Test34-timavg.sh | 11 +++++++++ t/test_time_avg.py | 5 +++- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 m4/ax_python_module.m4 diff --git a/configure.ac b/configure.ac index f633b308..53ae6fb2 100644 --- a/configure.ac +++ b/configure.ac @@ -125,9 +125,11 @@ AM_CONDITIONAL([WITH_ASCIIDOC], [test -n "$ASCIIDOC"]) AC_CHECK_PROGS(BATS, [bats]) AC_CHECK_PROGS(PROVE, [prove]) - AM_CONDITIONAL([WITH_CHECK_PROGS], [test -n "$PROVE" -a -n "$BATS"]) +AC_CHECK_PROGS(python3, [required]) +AC_PYTHON_MODULE(xarray, required, python3) + # Check if openacc.h exists if test "$enable_acc" = yes ; then AC_CHECK_HEADERS([openacc.h], [], [AC_MSG_ERROR(["Cannot find OpenACC header file"])] ) diff --git a/m4/ax_python_module.m4 b/m4/ax_python_module.m4 new file mode 100644 index 00000000..79001d05 --- /dev/null +++ b/m4/ax_python_module.m4 @@ -0,0 +1,55 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_python_module.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PYTHON_MODULE(modname[, fatal, python]) +# +# DESCRIPTION +# +# Checks for Python module. +# +# If fatal is non-empty then absence of a module will trigger an error. +# The third parameter can either be "python" for Python 2 or "python3" for +# Python 3; defaults to Python 2. +# +# LICENSE +# +# Copyright (c) 2008 Andrew Collier +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE]) +AC_DEFUN([AX_PYTHON_MODULE],[ + + if test -z "$3"; + then + PYTHON_TEST="python2" + else + PYTHON_TEST="$3" + fi + + PYTHON_NAME=`basename $PYTHON_TEST` + AC_MSG_CHECKING($PYTHON_NAME module: $1) + $PYTHON_TEST -c "import $1" 2>/dev/null + if test $? -eq 0; + then + AC_MSG_RESULT(yes) + eval AS_TR_CPP(HAVE_PYMOD_$1)=yes + else + AC_MSG_RESULT(no) + eval AS_TR_CPP(HAVE_PYMOD_$1)=no + # + if test -n "$2" + then + AC_MSG_ERROR(failed to find required module $1) + exit 1 + fi + fi +]) \ No newline at end of file diff --git a/t/Test34-timavg.sh b/t/Test34-timavg.sh index b44ec603..e5d4828c 100755 --- a/t/Test34-timavg.sh +++ b/t/Test34-timavg.sh @@ -23,5 +23,16 @@ load test_utils @test "Test timavg" { +cat <<_EOF > input.nml + &input + file_names(1) = '20120101.ice_shelf.nc' , + file_name_out = 'new.nc' , + use_end_time = .false. , + verbose = .false. , + add_cell_methods = .false. , + skip_tavg_errors = .false. , + suppress_warnings = .false., + &end +_EOF python3 $top_srcdir/t/test_time_avg.py } diff --git a/t/test_time_avg.py b/t/test_time_avg.py index d0fe0365..627ff680 100644 --- a/t/test_time_avg.py +++ b/t/test_time_avg.py @@ -47,5 +47,8 @@ def check_output(self): test_class = TestTimeAvg() test_class.create_input() -os.system(os.path.dirname(os.path.realpath(__file__))+"/../postprocessing/timavg/timavg.csh -m -o wut.nc 20120101.ice_shelf.nc") +try: + os.system("TAVG.exe < input.nml") +except: + raise Exception("Failed to run timavg") test_class.check_output() \ No newline at end of file From 621696c69abe23ad6eb1b6de6e3db0c25b8bbc95 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Mon, 16 Sep 2024 12:21:31 -0400 Subject: [PATCH 05/11] Update error conditions --- t/test_time_avg.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/t/test_time_avg.py b/t/test_time_avg.py index 627ff680..7b39a9f0 100644 --- a/t/test_time_avg.py +++ b/t/test_time_avg.py @@ -40,15 +40,19 @@ def create_input(self): def check_output(self): - out_file = xr.open_dataset("wut.nc") + out_file = xr.open_dataset("new.nc") if not (out_file.a.values == np.average(self.a, axis=0)).all(): raise Exception("Test failed") test_class = TestTimeAvg() test_class.create_input() + +exit_code = os.system("TAVG.exe < input.nml") +if exit_code != 0 : + raise Exception("Failed to run timavg") + try: - os.system("TAVG.exe < input.nml") + test_class.check_output() except: - raise Exception("Failed to run timavg") -test_class.check_output() \ No newline at end of file + raise Exception("Failed to check the timavg output") From d6360515e3be8b69178baae702fc19ca67ecb5aa Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Mon, 16 Sep 2024 14:58:46 -0400 Subject: [PATCH 06/11] finish setting up the tests --- configure.ac | 8 +- postprocessing/timavg/time_average.f90 | 2 + t/Makefile.am | 7 ++ t/Test34-timavg.sh | 21 +++-- t/test_time_avg.py | 115 +++++++++++++++++-------- 5 files changed, 107 insertions(+), 46 deletions(-) diff --git a/configure.ac b/configure.ac index 53ae6fb2..06a71ebb 100644 --- a/configure.ac +++ b/configure.ac @@ -127,8 +127,12 @@ AC_CHECK_PROGS(BATS, [bats]) AC_CHECK_PROGS(PROVE, [prove]) AM_CONDITIONAL([WITH_CHECK_PROGS], [test -n "$PROVE" -a -n "$BATS"]) -AC_CHECK_PROGS(python3, [required]) -AC_PYTHON_MODULE(xarray, required, python3) +AC_PYTHON_MODULE(xarray, [], python3) +if test ${HAVE_PYMOD_XARRAY} = yes; then + AM_CONDITIONAL([SKIP_XARRAY_TESTS], true ) +else + AM_CONDITIONAL([SKIP_XARRAY_TESTS], false ) +fi # Check if openacc.h exists if test "$enable_acc" = yes ; then diff --git a/postprocessing/timavg/time_average.f90 b/postprocessing/timavg/time_average.f90 index 0ee5afa1..e444ef60 100644 --- a/postprocessing/timavg/time_average.f90 +++ b/postprocessing/timavg/time_average.f90 @@ -600,7 +600,9 @@ program time_average if (itime > 0) then istat = NF90_GET_VAR (ncid_in, varid_recdim, time, start=(/itime/)) if (istat /= NF90_NOERR) call error_handler ('getting time coord value', ncode=istat) + endif + if (do_avg .and. itime > 0) then !--- read time bnds_info istat = NF90_GET_VAR (ncid_in, time_bnds_id, tavg(1:2), (/1, itime/)) if (istat /= NF90_NOERR) call error_handler & diff --git a/t/Makefile.am b/t/Makefile.am index ea1da269..cf51ae9d 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -23,8 +23,15 @@ else skip_MPI="skip" endif +if SKIP_XARRAY_TESTS +skipflag="skip" +else +skipflag="" +endif + TESTS_ENVIRONMENT = top_srcdir=$(abs_top_srcdir); export top_srcdir;\ export skip_mpi=$(skip_MPI); \ + export skip_xarray=$(skipflag); \ for d in $$( find $(abs_top_builddir)/postprocessing $(abs_top_builddir)/tools -mindepth 1 -not -path '*/\.*' -type d ); do \ PATH="$$d"'$(PATH_SEPARATOR)'"$$PATH"; \ done; diff --git a/t/Test34-timavg.sh b/t/Test34-timavg.sh index e5d4828c..b8f28298 100755 --- a/t/Test34-timavg.sh +++ b/t/Test34-timavg.sh @@ -23,16 +23,21 @@ load test_utils @test "Test timavg" { -cat <<_EOF > input.nml +if [ -z "$skip_mpi" ]; then +cat <<_EOF > instantaneous.nml &input - file_names(1) = '20120101.ice_shelf.nc' , - file_name_out = 'new.nc' , - use_end_time = .false. , - verbose = .false. , - add_cell_methods = .false. , - skip_tavg_errors = .false. , - suppress_warnings = .false., + file_names(1) = 'timavg_instantaneous_in.nc' , + file_name_out = 'timavg_instantaneous_out.nc' , &end _EOF + +cat <<_EOF > standard.nml + &input + file_names(1) = 'timavg_standard_in.nc' , + file_name_out = 'timavg_standard_out.nc' , + &end +_EOF + python3 $top_srcdir/t/test_time_avg.py +fi } diff --git a/t/test_time_avg.py b/t/test_time_avg.py index 7b39a9f0..35fc6d26 100644 --- a/t/test_time_avg.py +++ b/t/test_time_avg.py @@ -4,55 +4,98 @@ import numpy as np import os -def init_fake_data(a, count=0., factor=1.): - with np.nditer(a, op_flags=['readwrite']) as it: - for x in it: - count = count + 1 - x[...] = count * factor +class TestTimeAvg: + def __init__(self, Test_case): + self.Test_case = Test_case + if self.Test_case == 1: + self.In_file = "timavg_instantaneous_in.nc" + self.Out_file = "timavg_instantaneous_out.nc" + self.Namelist_file = "instantaneous.nml" + self.Error_msg = "timavg with instantaneous input" + elif self.Test_case == 2: + self.In_file = "timavg_standard_in.nc" + self.Out_file = "timavg_standard_out.nc" + self.Namelist_file = "standard.nml" + self.Error_msg = "timavg with standard input" -class TestTimeAvg(): - def create_input(self): - print("Creating input files to test with") - nx = 96 - ny = 96 - nt = 12 - - a = np.zeros([nt, ny, nx]) - for k in range(0,nt): - for j in range(0,ny): - for i in range(0,nx): - a[k, j, i] = (i+1.)*1000 + (j+1.)*10 + (k+1.)/100. - self.a = a - - Time_attrs = {"units": "days since 2000-01-01", "axis": "T", "calendar_type": "JULIAN", "calendar": "julian"} + + def create_instantaneous(self): + Time_attrs = {"units": "days since 2000-01-01", "axis": "T", "calendar_type": "JULIAN", "calendar": "julian"} + ds1 = xr.Dataset( + data_vars={ + ## This is backwards #FORTRAN4LYFE + "a": (("Time", "y", "x"), self.a), + "Time": (("Time", self.time_data, Time_attrs)) + }, + coords={ + "x": np.arange(self.nx)*1.0, + "y": np.arange(self.ny)*1.0, + }, + ) + ds1.to_netcdf(self.In_file, unlimited_dims="Time") + + def create_standard(self): + Time_attrs = {"units": "days since 2000-01-01", "axis": "T", "calendar_type": "JULIAN", "calendar": "julian", + "bounds": "time_bnds"} ds1 = xr.Dataset( data_vars={ ## This is backwards #FORTRAN4LYFE - "a": (("Time", "y", "x"), a), - "Time": (("Time", np.arange(nt)*1.0+1, Time_attrs)) + "a": (("Time", "y", "x"), self.a), + "Time": (("Time", self.time_data, Time_attrs)), + "time_bnds": (("Time", "nv"), self.time_bnds_data) }, coords={ - "x": np.arange(nx)*1.0, - "y": np.arange(ny)*1.0, + "x": np.arange(self.nx)*1.0, + "y": np.arange(self.ny)*1.0, + "nv": np.arange(2)*1.0+1, }, ) - ds1.to_netcdf("20120101.ice_shelf.nc", unlimited_dims="Time") + ds1.to_netcdf(self.In_file, unlimited_dims="Time") + + + def create_input(self): + self.nx = 96 + self.ny = 96 + self.nt = 12 + self.time_data = np.arange(self.nt)*1.0+1 + + self.a = np.zeros([self.nt, self.ny, self.nx]) + for k in range(0,self.nt): + for j in range(0,self.ny): + for i in range(0,self.nx): + self.a[k, j, i] = (i+1.)*1000 + (j+1.)*10 + (k+1.)/100. + + if self.Test_case == 1: + self.create_instantaneous() + elif self.Test_case == 2: + self.time_bnds_data = np.zeros([self.nt, 2]) + self.time_bnds_data[:,1] = self.time_data[0:] + self.time_bnds_data[1:,0] = self.time_data[0:-1] + self.create_standard() + + + def run_test(self): + exit_code = os.system("TAVG.exe < " + self.Namelist_file) + if exit_code != 0 : + raise Exception(self.Error_msg + ":: Failed to complete") def check_output(self): - out_file = xr.open_dataset("new.nc") + out_file = xr.open_dataset(self.Out_file) if not (out_file.a.values == np.average(self.a, axis=0)).all(): - raise Exception("Test failed") + raise Exception(self.Error_msg + ":: answers were not the expected result!") -test_class = TestTimeAvg() +# Test time_average when the input is instantaneous (so no time bounds) +Test_Instantaneous = 1 +test_class = TestTimeAvg(Test_Instantaneous) test_class.create_input() +test_class.run_test() +test_class.check_output() -exit_code = os.system("TAVG.exe < input.nml") -if exit_code != 0 : - raise Exception("Failed to run timavg") - -try: - test_class.check_output() -except: - raise Exception("Failed to check the timavg output") +# Test time_average when the input is standard (with time_bounds, no average_* variables) +Test_Standard = 2 +test_class = TestTimeAvg(Test_Standard) +test_class.create_input() +test_class.run_test() +test_class.check_output() From 04b843073a949e4183a4d5aaf529d6938285290d Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Mon, 16 Sep 2024 15:00:41 -0400 Subject: [PATCH 07/11] fix typo --- t/Makefile.am | 2 +- t/Test34-timavg.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/Makefile.am b/t/Makefile.am index cf51ae9d..581e7dca 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -31,7 +31,7 @@ endif TESTS_ENVIRONMENT = top_srcdir=$(abs_top_srcdir); export top_srcdir;\ export skip_mpi=$(skip_MPI); \ - export skip_xarray=$(skipflag); \ + export skipflag=$(skipflag); \ for d in $$( find $(abs_top_builddir)/postprocessing $(abs_top_builddir)/tools -mindepth 1 -not -path '*/\.*' -type d ); do \ PATH="$$d"'$(PATH_SEPARATOR)'"$$PATH"; \ done; diff --git a/t/Test34-timavg.sh b/t/Test34-timavg.sh index b8f28298..12c118ab 100755 --- a/t/Test34-timavg.sh +++ b/t/Test34-timavg.sh @@ -23,7 +23,7 @@ load test_utils @test "Test timavg" { -if [ -z "$skip_mpi" ]; then +if [ -z "$skipflag" ]; then cat <<_EOF > instantaneous.nml &input file_names(1) = 'timavg_instantaneous_in.nc' , From 2e8a08acd74d383e55cd248b16863761d5265298 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 18 Sep 2024 11:52:25 -0400 Subject: [PATCH 08/11] Fix logic --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 06a71ebb..1ab28d18 100644 --- a/configure.ac +++ b/configure.ac @@ -129,9 +129,9 @@ AM_CONDITIONAL([WITH_CHECK_PROGS], [test -n "$PROVE" -a -n "$BATS"]) AC_PYTHON_MODULE(xarray, [], python3) if test ${HAVE_PYMOD_XARRAY} = yes; then - AM_CONDITIONAL([SKIP_XARRAY_TESTS], true ) -else AM_CONDITIONAL([SKIP_XARRAY_TESTS], false ) +else + AM_CONDITIONAL([SKIP_XARRAY_TESTS], true ) fi # Check if openacc.h exists From 3efe0e91ac96cc8b15adc9fd3ebeae85167a651d Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Thu, 19 Sep 2024 08:49:01 -0400 Subject: [PATCH 09/11] init tbnds_present to .false. rearrange the if statements to be consistent with what it is done in the 2023 version --- postprocessing/timavg/time_average.f90 | 38 ++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/postprocessing/timavg/time_average.f90 b/postprocessing/timavg/time_average.f90 index e444ef60..1467accf 100644 --- a/postprocessing/timavg/time_average.f90 +++ b/postprocessing/timavg/time_average.f90 @@ -597,29 +597,26 @@ program time_average do itime = 0, numtime ! get time coordinate value + tavg = 1 if (itime > 0) then istat = NF90_GET_VAR (ncid_in, varid_recdim, time, start=(/itime/)) if (istat /= NF90_NOERR) call error_handler ('getting time coord value', ncode=istat) - endif - - if (do_avg .and. itime > 0) then - !--- read time bnds_info - istat = NF90_GET_VAR (ncid_in, time_bnds_id, tavg(1:2), (/1, itime/)) - if (istat /= NF90_NOERR) call error_handler & - ('reading time bnds', ncode=istat) - tavg(3) = tavg(2) - tavg(1) - else - tavg = 1 - endif - - if (do_climo_avg .and. itime == numtime) then - ! use midpoint of last time interval for climatological time - if (change_bounds_to_climo) then - climo_time = 0.5*(tavg(1)+tavg(2)) - else - ! use last time if already climo time - climo_time = time - endif + if (do_avg) then + !--- read time bnds_info + istat = NF90_GET_VAR (ncid_in, time_bnds_id, tavg(1:2), (/1, itime/)) + if (istat /= NF90_NOERR) call error_handler & + ('reading time bnds', ncode=istat) + tavg(3) = tavg(2) - tavg(1) + if (do_climo_avg .and. itime == numtime) then + ! use midpoint of last time interval for climatological time + if (change_bounds_to_climo) then + climo_time = 0.5*(tavg(1)+tavg(2)) + else + ! use last time if already climo time + climo_time = time + endif + endif + endif endif !----------------------------------------------------------------------- !-------------------- Loop through variables --------------------------- @@ -1094,6 +1091,7 @@ subroutine check_for_climo_avg ( ncid, tname, tunits, ntimes, & ! read the time bounds for the two time periods + tbnds_present = .false. if (tbnds_name(1:1) .ne. ' ') tbnds_present = .true. if (tbnds_present) then istat = NF90_INQ_VARID ( ncid, trim(tbnds_name), varid(1) ) From c9c775d25217f328cbe1de842c35efe6d3fdcfe1 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Thu, 19 Sep 2024 16:29:09 -0400 Subject: [PATCH 10/11] add module load to gfdl and ncrc environments --- site-configs/gfdl-ws/env.sh | 2 ++ site-configs/gfdl/env.sh | 2 ++ site-configs/ncrc5/env.sh | 2 ++ site-configs/ncrc6/env.sh | 2 ++ 4 files changed, 8 insertions(+) diff --git a/site-configs/gfdl-ws/env.sh b/site-configs/gfdl-ws/env.sh index 6e4e01ab..aff6b9ee 100755 --- a/site-configs/gfdl-ws/env.sh +++ b/site-configs/gfdl-ws/env.sh @@ -56,3 +56,5 @@ module load mpich/$mpi_version # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site + +module load python \ No newline at end of file diff --git a/site-configs/gfdl/env.sh b/site-configs/gfdl/env.sh index 81b07056..ba721969 100755 --- a/site-configs/gfdl/env.sh +++ b/site-configs/gfdl/env.sh @@ -59,3 +59,5 @@ module load mpich/$mpi_version # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site + +module load python diff --git a/site-configs/ncrc5/env.sh b/site-configs/ncrc5/env.sh index 772724d7..4a937bc8 100755 --- a/site-configs/ncrc5/env.sh +++ b/site-configs/ncrc5/env.sh @@ -54,3 +54,5 @@ setenv NC_BLKSZ 64K # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site + +module load python \ No newline at end of file diff --git a/site-configs/ncrc6/env.sh b/site-configs/ncrc6/env.sh index 1c88c125..c0fc60e2 100755 --- a/site-configs/ncrc6/env.sh +++ b/site-configs/ncrc6/env.sh @@ -54,3 +54,5 @@ setenv NC_BLKSZ 64K # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site + +module load python \ No newline at end of file From 847a4bd2104ea7ed7740da48dece7d9de428968d Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Fri, 20 Sep 2024 10:40:26 -0400 Subject: [PATCH 11/11] move the module load python to the start of the script --- site-configs/gfdl-ws/env.sh | 5 ++--- site-configs/gfdl/env.sh | 6 +++--- site-configs/ncrc5/env.sh | 3 +-- site-configs/ncrc6/env.sh | 3 +-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/site-configs/gfdl-ws/env.sh b/site-configs/gfdl-ws/env.sh index aff6b9ee..4cafa09f 100755 --- a/site-configs/gfdl-ws/env.sh +++ b/site-configs/gfdl-ws/env.sh @@ -42,9 +42,10 @@ mpi_version=4.1.1 module remove-path MODULEPATH /app/spack/${env_version}/modulefiles/linux-rhel8-x86_64 module prepend-path MODULEPATH /app/spack/${env_version}/modulefiles/linux-rhel8-x86_64 -# bats and nccmp are needed for tests +# bats, nccmp, and python are needed for tests module load bats module load nccmp +module load python # Load the GCC compilers module load gcc/$gcc_version @@ -56,5 +57,3 @@ module load mpich/$mpi_version # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site - -module load python \ No newline at end of file diff --git a/site-configs/gfdl/env.sh b/site-configs/gfdl/env.sh index ba721969..14109995 100755 --- a/site-configs/gfdl/env.sh +++ b/site-configs/gfdl/env.sh @@ -42,9 +42,11 @@ mpi_version=4.1.1 module remove-path MODULEPATH /app/spack/${env_version}/modulefiles/linux-rhel7-x86_64 module prepend-path MODULEPATH /app/spack/${env_version}/modulefiles/linux-rhel7-x86_64 -# bats and nccmp are needed for tests +# bats, nccmp, and python are needed for tests module load bats module load nccmp +module load python + # Need newer autoconf/automake than what pan has at the system level module load autoconf module load automake @@ -59,5 +61,3 @@ module load mpich/$mpi_version # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site - -module load python diff --git a/site-configs/ncrc5/env.sh b/site-configs/ncrc5/env.sh index 4a937bc8..16b6d799 100755 --- a/site-configs/ncrc5/env.sh +++ b/site-configs/ncrc5/env.sh @@ -32,6 +32,7 @@ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! module rm PrgEnv-pgi PrgEnv-intel PrgEnv-gnu PrgEnv-cray +module load python module load PrgEnv-gnu/8.3.3 module load gcc/12.2.0 module load cray-hdf5/1.12.2.3 @@ -54,5 +55,3 @@ setenv NC_BLKSZ 64K # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site - -module load python \ No newline at end of file diff --git a/site-configs/ncrc6/env.sh b/site-configs/ncrc6/env.sh index c0fc60e2..6cd8aa75 100755 --- a/site-configs/ncrc6/env.sh +++ b/site-configs/ncrc6/env.sh @@ -32,6 +32,7 @@ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! module rm PrgEnv-pgi PrgEnv-intel PrgEnv-gnu PrgEnv-cray +module load python module load PrgEnv-gnu/8.5.0 module load gcc-native/12.3 module load cray-hdf5/1.12.2.11 @@ -54,5 +55,3 @@ setenv NC_BLKSZ 64K # Set CONFIG_SITE to the correct config.site file for the system setenv CONFIG_SITE $( dirname $(readlink -f $0) )/config.site - -module load python \ No newline at end of file