read_profiling_input Subroutine

private subroutine read_profiling_input(filename, params)

Reads the &profiling_input block.

This parser is intentionally explicit because profiling is optional and should be robust to block ordering in case.nml.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
type(case_params_t), intent(inout) :: params

Calls

proc~~read_profiling_input~~CallsGraph proc~read_profiling_input mod_input::read_profiling_input proc~fatal_error mod_kinds::fatal_error proc~read_profiling_input->proc~fatal_error proc~lowercase mod_kinds::lowercase proc~read_profiling_input->proc~lowercase

Called by

proc~~read_profiling_input~~CalledByGraph proc~read_profiling_input mod_input::read_profiling_input proc~read_case_params mod_input::read_case_params proc~read_case_params->proc~read_profiling_input program~lowmach_react_hex lowmach_react_hex program~lowmach_react_hex->proc~read_case_params

Source Code

   subroutine read_profiling_input(filename, params)
      character(len=*), intent(in) :: filename
      type(case_params_t), intent(inout) :: params

      character(len=512) :: line
      character(len=256) :: key, value
      integer :: unit_id, ios, eqpos, comment_pos, comma_pos
      logical :: in_block, found_block

      in_block = .false.
      found_block = .false.

      open(newunit=unit_id, file=trim(filename), status='old', action='read', iostat=ios)
      if (ios /= 0) return

      do
         read(unit_id, '(a)', iostat=ios) line
         if (ios /= 0) exit

         comment_pos = index(line, '!')
         if (comment_pos > 0) line = line(:comment_pos-1)

         line = adjustl(line)
         if (len_trim(line) == 0) cycle

         if (.not. in_block) then
            if (index(lowercase(line), '&profiling_input') == 1) then
               in_block = .true.
               found_block = .true.
            end if
            cycle
         end if

         if (index(line, '/') > 0) exit

         eqpos = index(line, '=')
         if (eqpos <= 0) cycle

         key = trim(adjustl(lowercase(line(:eqpos-1))))
         value = trim(adjustl(lowercase(line(eqpos+1:))))

         comma_pos = index(value, ',')
         if (comma_pos > 0) value = value(:comma_pos-1)
         value = trim(value)

         select case (trim(key))
         case ('enable_profiling')
            call parse_logical_value(value, params%enable_profiling, 'enable_profiling')
         case ('nested_profiling')
            call parse_logical_value(value, params%nested_profiling, 'nested_profiling')
         case default
            call fatal_error('input', 'unknown variable in &profiling_input: '//trim(key))
         end select
      end do

      close(unit_id)

      if (found_block .and. in_block .and. ios /= 0) then
         call fatal_error('input', 'unterminated &profiling_input block')
      end if

   contains

      !> Parses a string representation of a logical value into a Fortran logical.
      !!
      !! Supports common formats like '.true.', 'true', 't', and their false counterparts.
      !!
      !! @param value_text The string to parse.
      !! @param output_value The resulting logical value.
      !! @param field_name The name of the field being parsed (used for error reporting).
      subroutine parse_logical_value(value_text, output_value, field_name)
         character(len=*), intent(in) :: value_text
         logical, intent(out) :: output_value
         character(len=*), intent(in) :: field_name

         select case (trim(value_text))
         case ('.true.', 'true', 't', '.t.')
            output_value = .true.
         case ('.false.', 'false', 'f', '.f.')
            output_value = .false.
         case default
            call fatal_error('input', 'invalid logical for '//trim(field_name)//': '//trim(value_text))
         end select
      end subroutine parse_logical_value

   end subroutine read_profiling_input