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: | 2024-12-17 22:39:59 |  | 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    44206825 :   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    44143849 :     output_string = input_string
          39             :
          40             :     ! Convert case character by character
          41   433782581 :     do i = 1, len(output_string)
          42   389575756 :       n = index(UPPER_CASE_CHARS, output_string(i:i))
          43   433782581 :       if ( n /= 0 ) output_string(i:i) = LOWER_CASE_CHARS(n:n)
          44             :     end do
          45    44206825 :   end function
          46             :   ! --------------------------------------------------------------------------------------
          47             :   !
          48             :   !> Is string somewhere in array?
          49             :   !
          50     5968835 :   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     5968835 :     character(len=len_trim(string)) :: lc_string
          57             :
          58     5968835 :     string_in_array = .false.
          59     5968835 :     lc_string = lower_case(trim(string))
          60    20953504 :     do i = 1, size(array)
          61    41819456 :       if(lc_string == lower_case(trim(array(i)))) then
          62     5881283 :         string_in_array = .true.
          63    26747235 :         exit
          64             :       end if
          65             :     end do
          66     5968835 :   end function string_in_array
          67             :   ! --------------------------------------------------------------------------------------
          68             :   !
          69             :   !> what is the location of a string in an array
          70             :   !
          71     2055463 :   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     2055463 :     character(len=len_trim(string)) :: lc_string
          78             :
          79     2055463 :     string_loc_in_array = -1
          80     2055463 :     lc_string = lower_case(trim(string))
          81     6296359 :     do i = 1, size(array)
          82    12529742 :       if(lc_string == lower_case(trim(array(i)))) then
          83     1992487 :         string_loc_in_array = i
          84     8225870 :         exit
          85             :       end if
          86             :     end do
          87     2055463 :   end function string_loc_in_array
          88             :   ! --------------------------------------------------------------------------------------
          89             : end module

Generated by: LCOV version 1.14