PB3D  [2.45]
Ideal linear high-n MHD stability in 3-D
str_utilities.f90
Go to the documentation of this file.
1 !------------------------------------------------------------------------------!
3 !------------------------------------------------------------------------------!
5 #include <wrappers.h>
6  use num_vars, only: dp, max_str_ln
7  implicit none
8  private
11 
12 contains
17  elemental character(len=max_str_ln) function i2str(k)
18  ! input / output
19  integer, intent(in) :: k
20 
21  write (i2str, *) k
22  i2str = adjustl(i2str)
23  end function i2str
29  elemental character(len=max_str_ln) function ii2str(k)
30  ! input / output
31  integer(kind=8), intent(in) :: k
32 
33  write (ii2str, *) k
34  ii2str = adjustl(ii2str)
35  end function ii2str
36 
41  elemental character(len=max_str_ln) function r2str(k)
42  ! input / output
43  real(dp), intent(in) :: k
44 
45  write (r2str, '(ES23.16)') k
46  r2str = adjustl(r2str)
47  end function r2str
53  elemental character(len=max_str_ln) function r2strt(k)
54  ! input / output
55  real(dp), intent(in) :: k
56 
57  write (r2strt, '(ES9.2)') k
58  r2strt = adjustl(r2strt)
59  end function r2strt
60 
65  elemental character(len=max_str_ln) function c2str(k)
66  ! input / output
67  complex(dp), intent(in) :: k
68 
69  ! local variables
70  character(len=max_str_ln) :: dum_str ! dummy string
71 
72  write (c2str, '(ES23.16)') rp(k)
73  write (dum_str, '(ES23.16)') abs(imag(k))
74  if (imag(k).lt.0) then
75  c2str = trim(c2str)//' -'
76  else
77  c2str = trim(c2str)//' +'
78  end if
79  c2str = trim(c2str)//' '//dum_str
80  c2str = adjustl(c2str)
81  end function c2str
87  elemental character(len=max_str_ln) function c2strt(k)
88  ! input / output
89  complex(dp), intent(in) :: k
90 
91  ! local variables
92  character(len=max_str_ln) :: dum_str ! dummy string
93 
94  write (c2strt, '(ES9.2)') rp(k)
95  write (dum_str, '(ES9.2)') abs(imag(k))
96  if (imag(k).lt.0) then
97  c2strt = trim(c2strt)//' -'
98  else
99  c2strt = trim(c2strt)//' +'
100  end if
101  c2strt = trim(c2strt)//' '//trim(dum_str)//' i'
102  c2strt = adjustl(c2strt)
103  end function c2strt
104 
108  function strh2l(input_string) result(output_string)
109  ! input / output
110  character(*), intent(in) :: input_string
111  character(len(input_string)) :: output_string
112 
113  ! local variables
114  integer :: i, n
115  character(*), parameter :: lower_case = 'abcdefghijklmnopqrstuvwxyz'
116  character(*), parameter :: upper_case = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
117 
118  ! copy input string
119  output_string = input_string
120 
121  ! convert case character by character
122  do i = 1, len(output_string)
123  n = index(upper_case, output_string(i:i))
124  if ( n /= 0 ) output_string(i:i) = lower_case(n:n)
125  end do
126  end function strh2l
130  function strl2h(input_string) result(output_string)
131  ! input / output
132  character(*), intent(in) :: input_string
133  character(len(input_string)) :: output_string
134 
135  ! local variables
136  integer :: i, n
137  character(*), parameter :: lower_case = 'abcdefghijklmnopqrstuvwxyz'
138  character(*), parameter :: upper_case = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
139 
140  ! copy input string
141  output_string = input_string
142 
143  ! convert case character by character
144  do i = 1, len(output_string)
145  n = index(lower_case, output_string(i:i))
146  if ( n /= 0 ) output_string(i:i) = upper_case(n:n)
147  end do
148  end function strl2h
149 
151  function merge_strings(input_strings)
152  ! input / output
153  character(*), intent(in) :: input_strings(:)
154  character((len(input_strings)+2)*size(input_strings)) :: merge_strings
155 
156  ! local variables
157  integer :: id ! counter
158 
159  ! start with first string
160  if (size(input_strings).gt.0) then
161  merge_strings = trim(input_strings(1))
162 
163  ! loop over next strings
164  do id = 2,size(input_strings)
165  merge_strings = trim(merge_strings)//', '//&
166  &trim(input_strings(id))
167  end do
168  else
169  merge_strings = ''
170  end if
171  end function merge_strings
172 end module str_utilities
num_vars::dp
integer, parameter, public dp
double precision
Definition: num_vars.f90:46
str_utilities::ii2str
elemental character(len=max_str_ln) function, public ii2str(k)
Convert an integer to string.
Definition: str_utilities.f90:30
num_vars
Numerical variables used by most other modules.
Definition: num_vars.f90:4
num_vars::max_str_ln
integer, parameter, public max_str_ln
maximum length of strings
Definition: num_vars.f90:50
str_utilities::i2str
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
Definition: str_utilities.f90:18
str_utilities
Operations on strings.
Definition: str_utilities.f90:4
str_utilities::r2strt
elemental character(len=max_str_ln) function, public r2strt(k)
Convert a real (double) to string.
Definition: str_utilities.f90:54
str_utilities::strh2l
character(len(input_string)) function, public strh2l(input_string)
Convert a string to lowercase.
Definition: str_utilities.f90:109
str_utilities::strl2h
character(len(input_string)) function, public strl2h(input_string)
convert a string to uppercase.
Definition: str_utilities.f90:131
str_utilities::r2str
elemental character(len=max_str_ln) function, public r2str(k)
Convert a real (double) to string.
Definition: str_utilities.f90:42
str_utilities::c2strt
elemental character(len=max_str_ln) function, public c2strt(k)
Convert a complex (double) to string.
Definition: str_utilities.f90:88
str_utilities::merge_strings
character((len(input_strings)+2) *size(input_strings)) function, public merge_strings(input_strings)
Merge array of strings.
Definition: str_utilities.f90:152
str_utilities::c2str
elemental character(len=max_str_ln) function, public c2str(k)
Convert a complex (double) to string.
Definition: str_utilities.f90:66