Skip to content

Commit

Permalink
updates for pio error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana Vertenstein committed Jun 6, 2024
1 parent d729df9 commit 410b04a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/riverroute/mosart_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ subroutine ncd_pio_openfile(file, fname, mode)
integer , intent(in) :: mode ! file mode

! Local variables
integer :: oldmethod
integer :: ierr
character(len=*),parameter :: subname='ncd_pio_openfile' ! subroutine name
!-----------------------------------------------------------------------

call pio_seterrorhandling(file, PIO_BCAST_ERROR)
call pio_seterrorhandling(pio_subsystem, PIO_BCAST_ERROR, oldmethod)
ierr = pio_openfile(pio_subsystem, file, io_type, fname, mode)
if(ierr/= PIO_NOERR) then
call shr_sys_abort(subname//'ERROR: Failed to open file')
else if(pio_iotask_rank(pio_subsystem)==0 .and. mainproc) then
write(iulog,*) 'Opened existing file ', trim(fname), file%fh
end if
call pio_seterrorhandling(pio_subsystem, oldmethod)

end subroutine ncd_pio_openfile

Expand Down Expand Up @@ -237,6 +239,7 @@ subroutine ncd_pio_createfile(file, fname)
character(len=*), intent(in) :: fname ! File name to create

! Local variables
integer :: oldmethod
integer :: ierr
integer :: iomode
character(len=*),parameter :: subname='ncd_pio_createfile' ! subroutine name
Expand All @@ -247,13 +250,14 @@ subroutine ncd_pio_createfile(file, fname)
if(io_type == PIO_IOTYPE_NETCDF .or. io_type == PIO_IOTYPE_PNETCDF) then
iomode = ior(iomode, io_format)
endif
call pio_seterrorhandling(file, PIO_BCAST_ERROR)
call pio_seterrorhandling(pio_subsystem, PIO_BCAST_ERROR, oldmethod)
ierr = pio_createfile(pio_subsystem, file, io_type, fname, iomode)
if(ierr/= PIO_NOERR) then
call shr_sys_abort( subname//' ERROR: Failed to open file to write: '//trim(fname))
else if(pio_iotask_rank(pio_subsystem)==0 .and. mainproc) then
write(iulog,*) 'Opened file ', trim(fname), ' to write', file%fh
end if
call pio_seterrorhandling(pio_subsystem, oldmethod)

end subroutine ncd_pio_createfile

Expand All @@ -272,6 +276,7 @@ subroutine check_var(ncid, varname, vardesc, readvar, print_err )
logical, optional, intent(in) :: print_err ! If should print about error

! Local variables
integer :: oldmethod
integer :: ret ! return value
logical :: log_err ! if should log error
character(len=*),parameter :: subname='check_var' ! subroutine name
Expand All @@ -284,14 +289,15 @@ subroutine check_var(ncid, varname, vardesc, readvar, print_err )
log_err = .true.
end if
readvar = .true.
call pio_seterrorhandling(ncid, PIO_BCAST_ERROR)
call pio_seterrorhandling(ncid, PIO_BCAST_ERROR, oldmethod)
ret = pio_inq_varid (ncid, varname, vardesc)
if (ret /= PIO_NOERR) then
readvar = .false.
if (mainproc .and. log_err) &
write(iulog,*) subname//': variable ',trim(varname),' is not on dataset'
if (mainproc .and. log_err) then
write(iulog,*) subname//': variable ',trim(varname),' is not on dataset'
end if
end if
call pio_seterrorhandling(ncid, PIO_INTERNAL_ERROR)
call pio_seterrorhandling(ncid, oldmethod)

end subroutine check_var

Expand Down Expand Up @@ -355,11 +361,12 @@ subroutine ncd_inqdid(ncid,name,dimid,dimexist)
logical,optional, intent(out):: dimexist ! if this dimension exists or not

! Local variables
integer :: oldmethod
integer :: status
!-----------------------------------------------------------------------

if ( present(dimexist) )then
call pio_seterrorhandling(ncid, PIO_BCAST_ERROR)
call pio_seterrorhandling(ncid, PIO_BCAST_ERROR, oldmethod)
end if
status = PIO_inq_dimid(ncid,name,dimid)
if ( present(dimexist) )then
Expand All @@ -368,7 +375,7 @@ subroutine ncd_inqdid(ncid,name,dimid,dimexist)
else
dimexist = .false.
end if
call pio_seterrorhandling(ncid, PIO_INTERNAL_ERROR)
call pio_seterrorhandling(ncid, oldmethod)
end if

end subroutine ncd_inqdid
Expand Down Expand Up @@ -430,6 +437,7 @@ subroutine ncd_inqfdims(ncid, isgrid2d, ni, nj, ns)
integer , intent(out) :: nj
integer , intent(out) :: ns
! Local variables
integer :: oldmethod
integer :: dimid ! netCDF id
integer :: ier ! error status
character(len=CS) :: subname = 'surfrd_filedims' ! subroutine name
Expand All @@ -438,7 +446,7 @@ subroutine ncd_inqfdims(ncid, isgrid2d, ni, nj, ns)
ni = 0
nj = 0

call pio_seterrorhandling(ncid, PIO_BCAST_ERROR)
call pio_seterrorhandling(ncid, PIO_BCAST_ERROR, oldmethod)
ier = pio_inq_dimid (ncid, 'lon', dimid)
if (ier == PIO_NOERR) ier = pio_inq_dimlen(ncid, dimid, ni)
ier = pio_inq_dimid (ncid, 'lat', dimid)
Expand All @@ -460,7 +468,7 @@ subroutine ncd_inqfdims(ncid, isgrid2d, ni, nj, ns)
if (ier == PIO_NOERR) nj = 1
end if

call pio_seterrorhandling(ncid, PIO_INTERNAL_ERROR)
call pio_seterrorhandling(ncid, oldmethod)

if (ni == 0 .or. nj == 0) then
write(iulog,*) trim(subname),' ERROR: ni,nj = ',ni,nj,' cannot be zero '
Expand Down Expand Up @@ -492,21 +500,22 @@ subroutine ncd_inqvid(ncid,name,varid,vardesc,readvar)
logical, optional, intent(out) :: readvar ! does variable exist

! Local variables
integer :: oldmethod
integer :: ret ! return code
character(len=*),parameter :: subname='ncd_inqvid' ! subroutine name
!-----------------------------------------------------------------------

if (present(readvar)) then
readvar = .false.
call pio_seterrorhandling(ncid, PIO_BCAST_ERROR)
call pio_seterrorhandling(pio_subsystem, PIO_BCAST_ERROR, oldmethod)
ret = pio_inq_varid(ncid,name,vardesc)
if (ret /= PIO_NOERR) then
if (mainproc) write(iulog,*) subname//': variable ',trim(name),' is not on dataset'
readvar = .false.
else
readvar = .true.
end if
call pio_seterrorhandling(ncid, PIO_INTERNAL_ERROR)
call pio_seterrorhandling(ncid, oldmethod)
else
ret = pio_inq_varid(ncid,name,vardesc)
endif
Expand Down
2 changes: 1 addition & 1 deletion src/riverroute/mosart_vars.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module mosart_vars
character(len=CS) :: bypass_routing_option ! bypass routing model method
character(len=CS) :: qgwl_runoff_option ! method for handling qgwl runoff
integer :: budget_frq = -24 ! budget check frequency
logical :: separate_glc2cn_fluxes ! true => send fluxes from glc through mozart separately to mediator
logical :: separate_glc2ocn_fluxes ! true => send fluxes from glc through mozart separately to mediator

! Metadata variables used in history and restart generation
character(len=CL) :: caseid = ' ' ! case id
Expand Down

0 comments on commit 410b04a

Please sign in to comment.