diff --git a/src/gen_modules_clock.F90 b/src/gen_modules_clock.F90 index a64c704e4..99f861e0c 100755 --- a/src/gen_modules_clock.F90 +++ b/src/gen_modules_clock.F90 @@ -2,6 +2,8 @@ module g_clock !combining RT and Lars version ! use g_config + use iso_fortran_env, only: error_unit + use mpi implicit none save real(kind=WP) :: timeold, timenew !time in a day, unit: sec @@ -75,6 +77,9 @@ subroutine clock_init(partit) type(t_partit), intent(in), target :: partit integer :: i, daystart, yearstart real(kind=WP) :: aux1, aux2, timestart + integer :: ierr + integer :: file_unit + character(512) :: errmsg ! the model initialized at timestart=timenew @@ -82,10 +87,17 @@ subroutine clock_init(partit) yearstart=yearnew ! init clock for this run - open(99,file=trim(ResultPath)//trim(runid)//'.clock',status='old') - read(99,*) timeold, dayold, yearold - read(99,*) timenew, daynew, yearnew - close(99) + open(newunit=file_unit, file=trim(ResultPath)//trim(runid)//'.clock', action='read', & + status='old', iostat=ierr, iomsg=errmsg) + if (ierr /= 0) then + write (unit=error_unit, fmt='(3A)') & + '### error: can not open file ', trim(ResultPath)//trim(runid)//'.clock', & + ', error: ' // trim(errmsg) + call MPI_Abort(MPI_COMM_WORLD, 1, ierr) + end if + read(unit=file_unit, fmt=*) timeold, dayold, yearold + read(unit=file_unit, fmt=*) timenew, daynew, yearnew + close(unit=file_unit) if(daynew==0) daynew=1 ! check if this is a restart or not @@ -156,6 +168,9 @@ subroutine clock_finish real(kind=WP) :: dum_timenew !time in a day, unit: sec integer :: dum_daynew !day in a year integer :: dum_yearnew !year before and after time step + integer :: ierr + integer :: file_unit + character(512) :: errmsg dum_timenew = timenew dum_daynew = daynew @@ -166,10 +181,17 @@ subroutine clock_finish dum_yearnew=yearold+1 endif - open(99,file=trim(ResultPath)//trim(runid)//'.clock',status='unknown') - write(99,*) timeold, dayold, yearold - write(99,*) dum_timenew, dum_daynew, dum_yearnew - close(99) + open(newunit=file_unit, file=trim(ResultPath)//trim(runid)//'.clock', action='write', & + status='unknown', iostat=ierr, iomsg=errmsg) + if (ierr /= 0) then + write (unit=error_unit, fmt='(3A)') & + '### error: can not open file ', trim(ResultPath)//trim(runid)//'.clock', & + ', error: ' // trim(errmsg) + call MPI_Abort(MPI_COMM_WORLD, 1, ierr) + end if + write(unit=file_unit, fmt=*) timeold, dayold, yearold + write(unit=file_unit, fmt=*) dum_timenew, dum_daynew, dum_yearnew + close(unit=file_unit) end subroutine clock_finish ! !---------------------------------------------------------------------------- @@ -210,4 +232,4 @@ end subroutine is_fleapyr ! !---------------------------------------------------------------------------- ! -end module g_clock +end module g_clock \ No newline at end of file diff --git a/src/oce_mesh.F90 b/src/oce_mesh.F90 index 1843e345b..0dba2f221 100755 --- a/src/oce_mesh.F90 +++ b/src/oce_mesh.F90 @@ -179,6 +179,7 @@ END SUBROUTINE mesh_setup ! Reads distributed mesh ! The mesh will be read only by 0 proc and broadcasted to the others. SUBROUTINE read_mesh(partit, mesh) +use iso_fortran_env, only: error_unit USE o_PARAM USE g_CONFIG USE MOD_MESH @@ -205,8 +206,10 @@ SUBROUTINE read_mesh(partit, mesh) integer, allocatable, dimension(:,:) :: ibuff real(kind=WP), allocatable, dimension(:,:) :: rbuff integer, allocatable, dimension(:,:) :: auxbuff ! will be used for reading aux3d.out - integer :: fileunit, iostat + integer :: fileunit character(32) :: mesh_checksum + integer :: ioerr + character(512) :: errmsg #include "associate_part_def.h" #include "associate_mesh_def.h" @@ -235,7 +238,14 @@ SUBROUTINE read_mesh(partit, mesh) if (mype==0) then file_name=trim(dist_mesh_dir)//'rpart.out' fileID=10 - open(fileID, file=trim(file_name)) + open(unit=fileID, file=trim(file_name), action='read', status='old', & + iostat=ioerr, iomsg=errmsg) + if (ioerr /= 0) then + write (unit=error_unit, fmt='(3A)') & + '### error: can not open file ', file_name, & + ', error: ' // trim(errmsg) + call MPI_Abort(MPI_COMM_FESOM, 1, ierror) + end if allocate(partit%part(npes+1)) part=>partit%part read(fileID,*) n @@ -254,7 +264,7 @@ SUBROUTINE read_mesh(partit, mesh) write(*,*) n write(*,*) 'error: NPES does not coincide with that of the mesh' call par_ex(partit%MPI_COMM_FESOM, partit%mype, 1) - STOP + call MPI_Abort(MPI_COMM_FESOM, 1, ierror) end if ! broadcasting partitioning vector to the other procs if (mype/=0) then @@ -2853,4 +2863,4 @@ subroutine check_total_volume(partit, mesh) end subroutine check_total_volume ! ! -!_______________________________________________________________________________ +!_______________________________________________________________________________ \ No newline at end of file