get_current_line_from_file_sequential Subroutine

private subroutine get_current_line_from_file_sequential(iunit, line)

Arguments

Type IntentOptional AttributesName
integer(kind=IK), intent(in) :: iunit

file unit number

character(kind=CK,len=:), intent(out), allocatable:: line

current line

Description

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).

Called By

proc~~get_current_line_from_file_sequential~~CalledByGraph proc~get_current_line_from_file_sequential get_current_line_from_file_sequential proc~annotate_invalid_json annotate_invalid_json proc~annotate_invalid_json->proc~get_current_line_from_file_sequential proc~json_parse_file json_parse_file proc~json_parse_file->proc~annotate_invalid_json proc~json_parse_string json_parse_string proc~json_parse_string->proc~annotate_invalid_json interface~json_parse json_parse interface~json_parse->proc~json_parse_file interface~json_parse->proc~json_parse_string proc~test_14 test_14 proc~test_14->interface~json_parse proc~test_8 test_8 proc~test_8->interface~json_parse proc~json_file_load json_file_load proc~json_file_load->interface~json_parse proc~json_file_load_from_string json_file_load_from_string proc~json_file_load_from_string->interface~json_parse program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8 proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->proc~json_file_load_from_string proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->proc~json_parse_string
Help

Variables

TypeVisibility AttributesNameInitial
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

Source Code

    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