From 64b6aa37a154a1754e9f415910c68ab425a97658 Mon Sep 17 00:00:00 2001 From: Anton Steketee <79179784+anton-seaice@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:35:15 +1000 Subject: [PATCH] Confirm backward compatibility for PIO reads on non-parallel files (#966) Add ability for netcdf file reading to fall back to regular netcdf if a file is initially opened (for instance with hdf5 reading) and fails to open properly. For some versions of the PIO library (<2.5.10), attempting a parallel read with filetype netcdf4 (hdf5) of a file which does not support parallel reads fails. The expected behaviour (which is fixed in latest PIO versions) is to fall back to a serial read. The change ensures support for older PIO versions. --- cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90 | 10 ++++++++-- .../cicedyn/infrastructure/io/io_pio2/ice_restart.F90 | 7 +------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90 index 9028fa9b7..94331edf1 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90 @@ -236,8 +236,14 @@ subroutine ice_pio_init(mode, filename, File, clobber, fformat, & write(nu_diag,*) subname//' opening file for reading '//trim(filename) endif status = pio_openfile(ice_pio_subsystem, File, pio_iotype, trim(filename), pio_nowrite) - call ice_pio_check( status, subname//' ERROR: Failed to open file '//trim(filename), & - file=__FILE__,line=__LINE__) + if (status /= PIO_NOERR) then + if (my_task == master_task) then + write(nu_diag,*) subname//' opening '//trim(filename)//' as type '//trim(fformat)//' failed, retrying as type cdf1' + endif + status = pio_openfile(ice_pio_subsystem, File, PIO_IOTYPE_NETCDF, trim(filename), pio_nowrite) + call ice_pio_check( status, subname//' ERROR: Failed to open file '//trim(filename), & + file=__FILE__,line=__LINE__) + endif else if(my_task==master_task) then write(nu_diag,*) subname//' ERROR: file not found '//trim(filename) diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 index fdb9330d2..b487c243d 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 @@ -78,13 +78,8 @@ subroutine init_restart_read(ice_ic) end if File%fh=-1 -! tcraig, including fformat here causes some problems when restart_format=hdf5 -! and reading non hdf5 files with spack built PIO. Excluding the fformat -! argument here defaults the PIO format to cdf1 which then reads -! any netcdf format file fine. call ice_pio_init(mode='read', filename=trim(filename), File=File, & -! fformat=trim(restart_format), rearr=trim(restart_rearranger), & - rearr=trim(restart_rearranger), & + fformat=trim(restart_format), rearr=trim(restart_rearranger), & iotasks=restart_iotasks, root=restart_root, stride=restart_stride, & debug=first_call)