diff --git a/sources/io.F90 b/sources/io.F90 index 93fcf99..25bbd57 100644 --- a/sources/io.F90 +++ b/sources/io.F90 @@ -251,6 +251,7 @@ module io use hdf5 , only : h5pset_deflate_f, h5pset_filter_f #endif /* HDF5 */ use iso_fortran_env, only : error_unit + use mpitools , only : nproc use parameters , only : get_parameter ! local variables are not implicit by default @@ -264,6 +265,8 @@ module io ! local variables ! + logical :: test + character(len=255) :: dname character(len=255) :: sformat = "xml" character(len=255) :: precise = "off" character(len=255) :: ghosts = "on" @@ -275,6 +278,7 @@ module io integer, dimension(1) :: cd_values = 3 #endif /* HDF5 */ + #ifdef HDF5 ! local parameters ! @@ -341,6 +345,38 @@ module io restart_format = snapshot_xml end select +! check the last available restart snapshot +! + if (nrest < 0) then + + test = .true. + nrest = 0 + + select case(restart_format) +#ifdef HDF5 + case(snapshot_hdf5) + do while (test) + nrest = nrest + 1 + write(dname, "(a,'r',i6.6,'_',i5.5,'.h5')") & + trim(respath), nrest, nproc + inquire(file = dname, exist = test) + end do +#endif /* HDF5 */ + case default + do while (test) + nrest = nrest + 1 + write(dname, "(a,'restart-',i5.5)") trim(respath), nrest +#ifdef __INTEL_COMPILER + inquire(directory = dname, exist = test) +#else /* __INTEL_COMPILER */ + inquire(file = dname, exist = test) +#endif /* __INTEL_COMPILER */ + end do + end select + + nrest = nrest - 1 + end if + ! get compression format and level for XML+binary files ! call get_parameter("compression_format", cformat) @@ -4219,8 +4255,8 @@ module io ! restore forcing coefficients ! call read_attribute(gid, 'nmodes', lnmodes) - if (lnmodes == nmodes .and. lnmodes > 0) then - call read_attribute(gid, 'fcoefs', fcoefs) + if (lnmodes == nmodes) then + if (lnmodes > 0) call read_attribute(gid, 'fcoefs', fcoefs) else write(error_unit,"('[',a,']: ',a)") trim(loc) & , "The number of driving modes does not match!"