Reads the contents of the file into the allocatable string str. If there are any problems, str will be returned unallocated.
Will this routine work if the file contains unicode characters??
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | filename | |||
character(len=:), | intent(out), | allocatable | :: | str |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
subroutine read_file(filename,str)
!! Reads the contents of the file into the allocatable string str.
!! If there are any problems, str will be returned unallocated.
!!
!!@warning Will this routine work if the file contains unicode characters??
implicit none
character(len=*),intent(in) :: filename
character(len=:),allocatable,intent(out) :: str
integer :: iunit,istat,filesize
open( newunit = iunit,&
file = filename,&
status = 'OLD',&
form = 'UNFORMATTED',&
access = 'STREAM',&
iostat = istat )
if (istat==0) then
inquire(file=filename, size=filesize)
if (filesize>0) then
allocate( character(len=filesize) :: str )
read(iunit,pos=1,iostat=istat) str
if (istat/=0) deallocate(str)
close(iunit, iostat=istat)
end if
end if
end subroutine read_file