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 SEQUENTIAL version (see also get_current_line_from_file_stream).
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=IK), | public, | parameter | :: | n_chunk | = | 256 | |
character(kind=CDK,len=*), | public, | parameter | :: | nfmt | = | '(A256)' | |
character(kind=CK,len=n_chunk), | public | :: | chunk | ||||
integer(kind=IK), | public | :: | istat | ||||
integer(kind=IK), | public | :: | isize |
subroutine get_current_line_from_file_sequential(iunit,line)
implicit none
integer(IK),intent(in) :: iunit !! file unit number
character(kind=CK,len=:),allocatable,intent(out) :: line !! current line
integer(IK),parameter :: n_chunk = 256 ! chunk size [arbitrary]
character(kind=CDK,len=*),parameter :: nfmt = '(A256)' ! corresponding format statement
character(kind=CK,len=n_chunk) :: chunk
integer(IK) :: istat,isize
!initialize:
line = ''
!rewind to beginning of the current record:
backspace(iunit, iostat=istat)
!loop to read in all the characters in the current record.
![the line is read in chunks until the end of the line is reached]
if (istat==0) then
do
isize=0
read(iunit,fmt=nfmt,advance='NO',size=isize,iostat=istat) chunk
if (istat==0) then
line = line//chunk
else
if (isize>0 .and. isize<=n_chunk) line = line//chunk(1:isize)
exit
end if
end do
end if
end subroutine get_current_line_from_file_sequential