check the status during various io operations on files
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int32) | :: | istat_ |
result of iostat in open/read/write/close |
|||
character(len=*), | intent(in) | :: | iomsg_ |
result of iomsg in open/read/write/close |
||
integer(kind=int32), | intent(in) | :: | channel_ |
name of the file |
||
character(len=1), | intent(in) | :: | op_ |
'o' for opening of the file, 'r' for reading, 'w' for writing, 'c' for closing |
||
integer(kind=int32), | intent(in), | optional | :: | unit_ |
optional, unit where the message will be written |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=:), | private, | allocatable | :: | add_prefix_ |
subroutine file_io_status(istat_, iomsg_, channel_, op_, unit_)
!! check the status during various io operations on files
!---------------------------------------------------------------------!
integer(int32) :: istat_
!! result of iostat in open/read/write/close
character(len = *), intent(in) :: iomsg_
!! result of iomsg in open/read/write/close
integer(int32), intent(in) :: channel_
!! name of the file
character(len = 1), intent(in) :: op_
!! 'o' for opening of the file, 'r' for reading, 'w' for writing,
!! 'c' for closing
integer(int32), optional, intent(in) :: unit_
!! optional, unit where the message will be written
!---------------------------------------------------------------------!
character(len = :), allocatable :: add_prefix_
!---------------------------------------------------------------------!
add_prefix_ = ''
if (istat_ /= 0) then
select case(op_)
case('o')
add_prefix_ = 'opening file on channel: '// &
integer_to_character(channel_)
case('r')
add_prefix_ = 'reading file on channel: '// &
integer_to_character(channel_)
case('w')
add_prefix_ = 'writing to file on channel: '// &
integer_to_character(channel_)
case('c')
add_prefix_ = 'closing file on channel: '// &
integer_to_character(channel_)
case default
call write_error &
('Incorrect op_ argument in file_io_status subroutine ('&
//trim(op_)//')')
end select
call write_error(trim(add_prefix_) // " with message: " // &
iomsg_, unit_)
endif
!---------------------------------------------------------------------!
end subroutine file_io_status