Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=IK), | intent(in) | :: | iunit | file unit number |
||
character(kind=CK,len=:), | intent(out), | allocatable | :: | line | current line |
Rewind the file to the beginning of the current line, and return this line. The file is assumed to be opened. This is the STREAM version (see also get_current_line_from_file_sequential).
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=IK), | public | :: | istart | ||||
integer(kind=IK), | public | :: | iend | ||||
integer(kind=IK), | public | :: | ios | ||||
character(kind=CK,len=1), | public | :: | c |
subroutine get_current_line_from_file_stream(iunit,line)
implicit none
integer(IK),intent(in) :: iunit !! file unit number
character(kind=CK,len=:),allocatable,intent(out) :: line !! current line
integer(IK) :: istart,iend,ios
character(kind=CK,len=1) :: c
!updated for the new STREAM version:
istart = ipos
do
if (istart<=1) then
istart = 1
exit
end if
read(iunit,pos=istart,iostat=ios) c
if (c==newline .or. ios/=0) then
if (istart/=1) istart = istart - 1
exit
end if
istart = istart-1 !rewind until the beginning of the line
end do
iend = ipos
do
read(iunit,pos=iend,iostat=ios) c
if (c==newline .or. ios/=0) exit
iend=iend+1
end do
allocate( character(kind=CK,len=iend-istart+1) :: line )
read(iunit,pos=istart,iostat=ios) line
end subroutine get_current_line_from_file_stream