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 13708838 : 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 13614374 : output_string = input_string 39 : 40 : ! Convert case character by character 41 76197310 : do i = 1, len(output_string) 42 62488472 : n = index(UPPER_CASE_CHARS, output_string(i:i)) 43 76197310 : if ( n /= 0 ) output_string(i:i) = LOWER_CASE_CHARS(n:n) 44 : end do 45 13708838 : end function 46 : ! -------------------------------------------------------------------------------------- 47 : ! 48 : !> Is string somewhere in array? 49 : ! 50 814210 : 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 814210 : character(len=len_trim(string)) :: lc_string 57 : 58 814210 : string_in_array = .false. 59 814210 : lc_string = lower_case(trim(string)) 60 3245984 : do i = 1, size(array) 61 6360640 : if(lc_string == lower_case(trim(array(i)))) then 62 682882 : string_in_array = .true. 63 3797538 : exit 64 : end if 65 : end do 66 814210 : end function string_in_array 67 : ! -------------------------------------------------------------------------------------- 68 : ! 69 : !> what is the location of a string in an array 70 : ! 71 1455386 : 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 1455386 : character(len=len_trim(string)) :: lc_string 78 : 79 1455386 : string_loc_in_array = -1 80 1455386 : lc_string = lower_case(trim(string)) 81 7816730 : do i = 1, size(array) 82 15538996 : if(lc_string == lower_case(trim(array(i)))) then 83 1360922 : string_loc_in_array = i 84 9083188 : exit 85 : end if 86 : end do 87 1455386 : end function string_loc_in_array 88 : ! -------------------------------------------------------------------------------------- 89 : end module