anchor.diff: -
  +! Copyright (c) 2015 Alex Kramer <kramer.alex.kramer@gmail.com>
  +! See the LICENSE.txt file in the top-level directory of this distribution
  +!
  +! This module implements handling of plaintext configuration / parameter files
  +!
  +! We assume that a configuration file has (up to) three types of lines:
  +! (a) blank lines
  +! (b) comment lines, starting with "!"
  +! (c) parameter lines, of the form "param = value"
  +! Note that in case (c), we do not allow Fortran comments after `value`.
  +!
  +! Moreover, we assume that the possible parameter values can be double
  +! precision real numbers, integers, logical values, or character strings.
  +!
  +! Example module usage:
  +!   call config_init("params.conf")
  +!   call config.get_param("param1", value, success)
  +!   call config_cleanup()
   module config
   
     use globvars, only: dp
  
positive.code:   public :: config_get_param
  
    interface config_get_param
       ! Get parameter
       module procedure config_get_int
       module procedure config_get_real_dp
       module procedure config_get_logical
       module procedure config_get_char
    end interface config_get_param
  
    integer, parameter :: default_line_length = 80
  
    integer :: num_params
    integer :: line_length
  
    character(:), allocatable :: param_lines(:)
  
  contains
  
    subroutine config_init(filename, max_line_length)
      character(*), intent(in) :: filename
      integer, intent(in), optional :: max_line_length
  
  
negative.code:   end subroutine config_cleanup
  
    subroutine config_get_int(param_name, val, found)
      ! Get integer parameter
      !
      ! param_name :: name of parameter to find
      ! val :: integer variable to be set with parameter value
      ! found :: logical indicating whether val has been set
      character(*), intent(in) :: param_name
      integer, intent(out) :: val
      logical, intent(out) :: found
  