-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_utils.f90
More file actions
63 lines (50 loc) · 1.83 KB
/
string_utils.f90
File metadata and controls
63 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
!
! String utility module
!
! This module contains helper functions that don't exist in the standard
! set of Fortran intrinsics.
!
module string_utils
! Set defaults for module
implicit none
private
! Declare the public functions exposed by this module
public :: ucase
public :: lcase
public :: str2int
! Helper strings to aid in the converstion of upper to lower and
! vice-versa
character (len=*), private, parameter :: LOWER_CASE = &
'abcdefghijklmnopqrstuvwxyz'
character (len=*), private, parameter :: UPPER_CASE = &
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
contains
! Convert string to all uppercase
pure function ucase(Input_String) result(Output_String)
character (len=*), intent (in) :: Input_String
character (len(Input_String)) :: Output_String
integer :: i,n
Output_String = Input_String
do i=1, len(Output_String)
n = index(LOWER_CASE, Output_String(i:i))
if (n /= 0) Output_String(i:i) = UPPER_CASE(n:n)
end do
end function ucase
! Convert string to all lowercase
pure function lcase(Input_String) result(Output_String)
character (len=*), intent (in) :: Input_String
character (len(Input_String)) :: Output_String
integer :: i,n
Output_String = Input_String
do i=1, len(Output_String)
n = index(UPPER_CASE, Output_String(i:i))
if (n /= 0) Output_String(i:i) = LOWER_CASE(n:n)
end do
end function lcase
subroutine str2int(input_string, output_integer, status_result)
character(len=*), intent(in) :: input_string
integer, intent(out) :: output_integer
integer, intent(out) :: status_result
read(input_string,*,iostat=status_result) output_integer
end subroutine str2int
end module string_utils