Skip to content

Commit

Permalink
Confirm backward compatibility for PIO reads on non-parallel files (C…
Browse files Browse the repository at this point in the history
…ICE-Consortium#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.
  • Loading branch information
anton-seaice authored Aug 8, 2024
1 parent 350d34a commit 64b6aa3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 8 additions & 2 deletions cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 64b6aa3

Please sign in to comment.