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 | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | iunit |
file unit number |
||
character(kind=CK, len=:), | intent(out), | allocatable | :: | line |
current line |
subroutine get_current_line_from_file_stream(json,iunit,line) implicit none class(json_core),intent(inout) :: json integer(IK),intent(in) :: iunit !! file unit number character(kind=CK,len=:),allocatable,intent(out) :: line !! current line integer(IK) :: istart !! start position of current line integer(IK) :: iend !! end position of current line integer(IK) :: ios !! file read `iostat` code character(kind=CK,len=1) :: c !! a character read from the file logical :: done !! flag to exit the loop istart = json%ipos do if (istart<=1) then istart = 1 exit end if read(iunit,pos=istart,iostat=ios) c done = ios /= 0_IK if (.not. done) done = c==newline if (done) then if (istart/=1) istart = istart - 1 exit end if istart = istart-1 !rewind until the beginning of the line end do iend = json%ipos do read(iunit,pos=iend,iostat=ios) c if (IS_IOSTAT_END(ios)) then ! account for end of file without linebreak iend=iend-1 exit end if 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