LCOV - code coverage report
Current view: top level - physics/rrtmgp/ext/gas-optics - mo_gas_optics_util_string.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 24 100.0 %
Date: 2025-03-13 19:21:45 Functions: 3 3 100.0 %

          Line data    Source code
       1             : ! This code is part of RRTM for GCM Applications - Parallel (RRTMGP)
       2             : !
       3             : ! Contacts: Robert Pincus and Eli Mlawer
       4             : ! email:  rrtmgp@aer.com
       5             : !
       6             : ! Copyright 2015-,  Atmospheric and Environmental Research,
       7             : ! Regents of the University of Colorado, Trustees of Columbia University.  All right reserved.
       8             : !
       9             : ! Use and duplication is permitted under the terms of the
      10             : !    BSD 3-clause license, see http://opensource.org/licenses/BSD-3-Clause
      11             : ! -------------------------------------------------------------------------------------------------
      12             : !>
      13             : !> Routines for handling strings:
      14             : !>
      15             : !>   - convert to lower case
      16             : !>   - does a string exist within an array of strings?
      17             : !>   - what is the location of a string with an array?
      18             : !>
      19             : ! -------------------------------------------------------------------------------------------------
      20             : module mo_gas_optics_util_string
      21             :   implicit none
      22             :   private
      23             :   public :: lower_case, string_in_array, string_loc_in_array
      24             : 
      25             :   ! List of character for case conversion
      26             :   character(len=26), parameter :: LOWER_CASE_CHARS = 'abcdefghijklmnopqrstuvwxyz'
      27             :   character(len=26), parameter :: UPPER_CASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
      28             : 
      29             : contains
      30             :   ! -------------------------------------------------------------------------------------------------
      31             :   !> Convert stringo to lower case 
      32     9039545 :   pure function lower_case( input_string ) result( output_string )
      33             :     character(len=*), intent(in) :: input_string
      34             :     character(len=len(input_string)) :: output_string
      35             :     integer :: i, n
      36             : 
      37             :     ! Copy input string
      38     8976569 :     output_string = input_string
      39             : 
      40             :     ! Convert case character by character
      41    49710061 :     do i = 1, len(output_string)
      42    40670516 :       n = index(UPPER_CASE_CHARS, output_string(i:i))
      43    49710061 :       if ( n /= 0 ) output_string(i:i) = LOWER_CASE_CHARS(n:n)
      44             :     end do
      45     9039545 :   end function
      46             :   ! --------------------------------------------------------------------------------------
      47             :   !
      48             :   !> Is string somewhere in array?
      49             :   !
      50      527395 :   pure function string_in_array(string, array)
      51             :     character(len=*),               intent(in) :: string
      52             :     character(len=*), dimension(:), intent(in) :: array
      53             :     logical                                    :: string_in_array
      54             : 
      55             :     integer :: i
      56      527395 :     character(len=len_trim(string)) :: lc_string
      57             : 
      58      527395 :     string_in_array = .false.
      59      527395 :     lc_string = lower_case(trim(string))
      60     2110544 :     do i = 1, size(array)
      61     4133536 :       if(lc_string == lower_case(trim(array(i)))) then
      62      439843 :         string_in_array = .true.
      63     2462835 :         exit
      64             :       end if
      65             :     end do
      66      527395 :   end function string_in_array
      67             :   ! --------------------------------------------------------------------------------------
      68             :   !
      69             :   !> what is the location of a string in an array 
      70             :   !
      71      967175 :   pure function string_loc_in_array(string, array)
      72             :     character(len=*),               intent(in) :: string
      73             :     character(len=*), dimension(:), intent(in) :: array
      74             :     integer                                    :: string_loc_in_array
      75             : 
      76             :     integer :: i
      77      967175 :     character(len=len_trim(string)) :: lc_string
      78             : 
      79      967175 :     string_loc_in_array = -1
      80      967175 :     lc_string = lower_case(trim(string))
      81     5208071 :     do i = 1, size(array)
      82    10353166 :       if(lc_string == lower_case(trim(array(i)))) then
      83      904199 :         string_loc_in_array = i
      84     6049294 :         exit
      85             :       end if
      86             :     end do
      87      967175 :   end function string_loc_in_array
      88             :   ! --------------------------------------------------------------------------------------
      89             : end module

Generated by: LCOV version 1.14