read_base Subroutine

private subroutine read_base(this, unit)

Uses

Read base optimiser information

Type Bound

base_optimiser_type

Arguments

Type IntentOptional Attributes Name
class(base_optimiser_type), intent(inout) :: this

Instance of the base optimiser

integer, intent(in) :: unit

File unit


Source Code

  subroutine read_base(this, unit)
    !! Read base optimiser information
    use athena__tools_infile, only: assign_val, assign_vec
    use coreutils, only: to_lower, to_upper, icount
    implicit none

    ! Arguments
    class(base_optimiser_type), intent(inout) :: this
    !! Instance of the base optimiser
    integer, intent(in) :: unit
    !! File unit

    ! Local variables
    integer :: stat
    !! File status
    integer :: itmp1
    !! Temporary integer
    character(256) :: buffer, tag, err_msg
    !! Buffer for reading lines, tag for identifying lines, error message


    ! Loop over tags in layer card
    !---------------------------------------------------------------------------
    tag_loop: do

       ! Check for end of file
       !------------------------------------------------------------------------
       read(unit,'(A)',iostat=stat) buffer
       if(stat.ne.0)then
          write(err_msg,'("file encountered error (EoF?) before END ",A)') &
               to_upper(this%name)
          call stop_program(err_msg)
          return
       end if
       if(trim(adjustl(buffer)).eq."") cycle tag_loop

       ! Check for end of layer card
       !------------------------------------------------------------------------
       if(trim(adjustl(buffer)).eq."END OPTIMISER")then
          backspace(unit)
          exit tag_loop
       end if

       tag=trim(adjustl(buffer))
       if(scan(buffer,"=").ne.0) tag=trim(tag(:scan(tag,"=")-1))

       ! Read parameters from save file
       !------------------------------------------------------------------------
       select case(trim(tag))
       case("NAME")
          call assign_val(buffer, this%name, itmp1)
       case("LEARNING_RATE")
          call assign_val(buffer, this%learning_rate, itmp1)
       case("ITERATION")
          call assign_val(buffer, this%iter, itmp1)
       case("EPOCH")
          call assign_val(buffer, this%epoch, itmp1)
       case("REGULARISATION")
          call assign_val(buffer, this%regularisation, itmp1)
       case default
          ! Don't look for "e" due to scientific notation of numbers
          ! ... i.e. exponent (E+00)
          if(scan(to_lower(trim(adjustl(buffer))),&
               'abcdfghijklmnopqrstuvwxyz').eq.0)then
             cycle tag_loop
          elseif(tag(:3).eq.'END')then
             cycle tag_loop
          end if
          write(err_msg,'("Unrecognised line in input file: ",A)') &
               trim(adjustl(buffer))
          call stop_program(err_msg)
          return
       end select
    end do tag_loop


    ! Check for end of layer card
    !---------------------------------------------------------------------------
    read(unit,'(A)') buffer
    if(trim(adjustl(buffer)).ne."END OPTIMISER")then
       write(0,*) trim(adjustl(buffer))
       write(err_msg,'("END OPTIMISER not where expected")')
       call stop_program(err_msg)
       return
    end if

  end subroutine read_base