input_unit Function

public function input_unit(nml)

Rewind the input file to start of namelist nml, and return the unit of the file opened by init_input_unit

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: nml

Name of namelist to find start of

Return Value integer


Contents

Source Code


Source Code

  function input_unit (nml)
    implicit none
    !> Name of namelist to find start of
    character(*), intent (in) :: nml
    integer :: input_unit, iostat
    character(500) :: line
    intrinsic adjustl, trim
    input_unit = input_unit_no
    if (input_unit_no > 0) then
       rewind (unit=input_unit_no)
       do
          read (unit=input_unit_no, fmt="(a)", iostat=iostat) line
          if (iostat /= 0) then
             rewind (unit=input_unit_no)
             exit
          end if
          if (trim(adjustl(line)) == "&"//nml) then
             backspace (unit=input_unit_no)
             return
          end if
       end do
    end if
    write (unit=error_unit_no, fmt="('Couldn''t find namelist: ',a)") nml
    write (unit=*, fmt="('Couldn''t find namelist: ',a)") nml
  end function input_unit