read_network_settings Module Subroutine

module subroutine read_network_settings(this, unit)

Uses

Read the network settings from a file

Arguments

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

Instance of network

integer, intent(in) :: unit

File unit


Source Code

  module subroutine read_network_settings(this, unit)
    !! Read the network settings from a file
    use athena__tools_infile, only: assign_val, assign_vec
    use coreutils, only: to_lower, to_upper, icount
    implicit none

    ! Arguments
    class(network_type), intent(inout) :: this
    !! Instance of network
    integer, intent(in) :: unit
    !! File unit

    ! Local variables
    integer :: stat
    !! File status
    integer :: itmp1
    !! Temporary integer
    character(20) :: accuracy_method, loss_method
    !! Methods for accuracy and loss
    character(256) :: buffer, tag, err_msg, name_
    !! Buffer for reading lines, tag for identifying lines, error message


    ! Loop over tags in layer card
    !---------------------------------------------------------------------------
    accuracy_method = ""
    loss_method = ""
    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 NETWORK_SETTINGS")then
          backspace(unit)
          exit tag_loop
       end if

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

       ! Read parameters from save file
       !------------------------------------------------------------------------
       select case(trim(tag))
       case("ATHENA_VERSION")
          ! Ignore this tag, it is only for information
       case("NAME")
          call assign_val(buffer, name_, itmp1)
          if(len(trim(adjustl(name_))) .gt. 0)then
             this%name = trim(adjustl(name_))
          end if
       case("EPOCH")
          call assign_val(buffer, this%epoch, itmp1)
       case("BATCH_SIZE")
          call assign_val(buffer, this%batch_size, itmp1)
       case("ACCURACY")
          call assign_val(buffer, this%accuracy_val, itmp1)
       case("LOSS")
          call assign_val(buffer, this%loss_val, itmp1)
       case("ACCURACY_METHOD")
          call assign_val(buffer, accuracy_method, itmp1)
          call this%set_accuracy(accuracy_method)
       case("LOSS_METHOD")
          call assign_val(buffer, loss_method, itmp1)
          call this%set_loss(loss_method)
       case("OPTIMISER")
          backspace(unit)
          call this%read_optimiser_settings(unit)
       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 NETWORK_SETTINGS")then
       write(0,*) trim(adjustl(buffer))
       write(err_msg,'("END NETWORK_SETTINGS not where expected")')
       call stop_program(err_msg)
       return
    end if

  end subroutine read_network_settings