Skip to content

Commit

Permalink
ignore the error message from reading the restart if the variable is…
Browse files Browse the repository at this point in the history
… not in the file (i.e. the model should not stop but use the values with which the variable was initialised initially)
  • Loading branch information
dsidoren authored and koldunovn committed Jul 28, 2021
1 parent 42a82ca commit 233d72b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/io_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MODULE io_RESTART
integer :: ndim
integer :: dims(2) !<=2; assume there are no variables with dimension more than 2xNLxT
real(kind=WP), pointer :: pt1(:), pt2(:,:)
logical :: is_in_restart !if the variable is in the restart file
end type nc_vars
!
!--------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -560,9 +561,9 @@ subroutine read_restart(id, mesh, arg)
integer, optional, intent(in) :: arg
real(kind=WP), allocatable :: aux(:), laux(:)
integer :: i, lev, size1, size2, size_gen, size_lev, shape
integer :: rec2read, c, order
integer :: rec2read, c, order, ierror
real(kind=WP) :: rtime !timestamp of the record
logical :: file_exist=.False.
logical :: file_exist=.False., var_exist
type(t_mesh), intent(in) , target :: mesh

#include "associate_mesh.h"
Expand Down Expand Up @@ -605,10 +606,17 @@ subroutine read_restart(id, mesh, arg)
end if

call was_error(id); c=1

do i=1, id%nvar
shape=id%var(i)%ndim
if (mype==0) write(*,*) 'reading restart for ', trim(id%var(i)%name)
var_exist=id%var(i)%is_in_restart
call MPI_BCast(var_exist, 1, MPI_INTEGER, 0, MPI_COMM_FESOM, ierror)
if (var_exist) then
if (mype==0) write(*,*) 'reading restart for ', trim(id%var(i)%name)
else
if (mype==0) write(*,*) '...skip reading for ', trim(id%var(i)%name)
cycle
end if
!_______writing 2D fields________________________________________________
if (shape==1) then
size1=id%var(i)%dims(1)
Expand Down Expand Up @@ -681,7 +689,7 @@ subroutine assoc_ids(id)

type(nc_file), intent(inout) :: id
character(500) :: longname
integer :: c, j, k
integer :: c, j, k, status
real(kind=WP) :: rtime !timestamp of the record
! Serial output implemented so far
if (mype/=0) return
Expand Down Expand Up @@ -730,7 +738,11 @@ subroutine assoc_ids(id)
id%rec_count=max(id%rec_count, 1)
!___Associate physical variables____________________________________________
do j=1, id%nvar
id%error_status(c) = nf_inq_varid(id%ncid, id%var(j)%name, id%var(j)%code); c=c+1
status = nf_inq_varid(id%ncid, id%var(j)%name, id%var(j)%code); c=c+1
id%var(j)%is_in_restart=(status .eq. nf_noerr) !does the requested variable exist in the file
if (.not. id%var(j)%is_in_restart) then !if not give the error message
write(*,*) 'WARNING: entry ', trim(id%var(j)%name), ' does not exist in the restart file!'
end if
end do
id%error_status(c)=nf_close(id%ncid); c=c+1
id%error_count=c-1
Expand Down

0 comments on commit 233d72b

Please sign in to comment.