Go to the documentation of this file.
6 implicit none ;
private
24 character(len=*),
intent(in) :: input_string
25 character(len=len(input_string)) ::
lowercase
29 integer,
parameter :: co=iachar(
'a')-iachar(
'A')
33 do k=1, len_trim(input_string)
42 character(len=*),
intent(in) :: input_string
43 character(len=len(input_string)) ::
uppercase
47 integer,
parameter :: co=iachar(
'A')-iachar(
'a')
51 do k=1, len_trim(input_string)
60 integer,
intent(in) :: i
63 character(len=19) :: tmp
64 write(tmp(1:19),
'(I19)') i
65 write(
left_int(1:19),
'(A)') adjustl(tmp)
71 integer,
intent(in) :: i(:)
74 character(len=1320) :: tmp
87 real,
intent(in) :: val
92 if ((abs(val) < 1.0e4) .and. (abs(val) >= 1.0e-3))
then
111 if ((l<2) .or. (
left_real(l-1:l) ==
".0") .or. &
115 elseif (val == 0.)
then
118 if ((abs(val) <= 1.0e-100) .or. (abs(val) >= 1.0e100))
then
119 write(
left_real(1:32),
'(ES24.14E3)') val
121 write(
left_real(1:32),
'(ES24.15E3)') val
140 real,
intent(in) :: r(:)
141 character(len=*),
optional,
intent(in) :: sep
145 integer :: j, n, b, ns
147 character(len=10) :: separator
150 if (
present(sep))
then
151 separator=sep ; ns=len(sep)
153 separator=
', ' ; ns=2
158 if (r(j)==r(j+1))
then
180 character(len=*),
intent(in) :: str
181 real,
intent(in) :: val
187 read(str(1:),*,err=987) scannedval
196 character(len=*),
intent(in) :: string
197 integer,
intent(in) :: n
206 character(len=120) function extract_word(string, separators, n)
207 character(len=*),
intent(in) :: string
208 character(len=*),
intent(in) :: separators
209 integer,
intent(in) :: n
211 integer :: ns, i, b, e, nw
212 logical :: lastcharisseperator
214 lastcharisseperator = .true.
215 ns = len_trim(string)
216 i = 0; b=0; e=0; nw=0
219 if (lastcharisseperator)
then
220 if (verify(string(i:i),separators)==0)
then
223 lastcharisseperator = .false.
228 if (verify(string(i:i),separators)==0)
then
229 lastcharisseperator = .true.
239 if (b<=ns .and. nw==n-1)
extract_word = trim(string(b:ns))
244 character(len=*),
intent(in) :: string
245 character(len=*),
intent(in) :: separators
246 integer,
intent(in) :: n
247 integer,
optional,
intent(in) :: missing_value
249 integer :: ns, i, b, e, nw
250 character(len=20) :: word
254 if (len_trim(word)>0)
then
257 if (
present(missing_value))
then
267 real function extract_real(string, separators, n, missing_value)
268 character(len=*),
intent(in) :: string
269 character(len=*),
intent(in) :: separators
270 integer,
intent(in) :: n
271 real,
optional,
intent(in) :: missing_value
273 integer :: ns, i, b, e, nw
274 character(len=20) :: word
278 if (len_trim(word)>0)
then
281 if (
present(missing_value))
then
292 character(len=*),
intent(in) :: string
295 logical :: lastcharisseperator
296 lastcharisseperator = .true.
297 ns = len_trim(string)
301 if (string(i:i) /=
' ')
then
315 logical,
intent(in) :: verbose
317 integer :: i(5) = (/ -1, 1, 3, 3, 0 /)
318 real :: r(8) = (/ 0., 1., -2., 1.3, 3.e-11, 3.e-11, 3.e-11, -5.1e12 /)
322 write(*,*)
'==== MOM_string_functions: string_functions_unit_tests ==='
352 if (.not. fail)
write(*,*)
'Pass'
357 logical function localtests(verbose,str1,str2)
358 logical,
intent(in) :: verbose
359 character(len=*),
intent(in) :: str1
360 character(len=*),
intent(in) :: str2
364 write(*,*)
'>'//trim(str1)//
'<'
365 if (
localtests)
write(*,*) trim(str1),
':',trim(str2),
'<-- FAIL'
371 logical,
intent(in) :: verbose
372 integer,
intent(in) :: i1
373 integer,
intent(in) :: i2
378 if (
localtesti)
write(*,*) i1,
'!=',i2,
'<-- FAIL'
384 logical,
intent(in) :: verbose
385 real,
intent(in) :: r1
386 real,
intent(in) :: r2
391 if (
localtestr)
write(*,*) r1,
'!=',r2,
'<-- FAIL'
398 character(len=*),
intent(in) :: dir
400 character(len=len(dir)+2) ::
slasher
402 if (len_trim(dir) == 0)
then
404 elseif (dir(len_trim(dir):len_trim(dir)) ==
'/')
then
character(len=120) function, public extract_word(string, separators, n)
Returns the string corresponding to the nth word in the argument or "" if the string is not long enou...
character(len=120) function, public remove_spaces(string)
Returns string with all spaces removed.
Handy functions for manipulating strings.
real function, public extract_real(string, separators, n, missing_value)
Returns the real corresponding to the nth word in the argument.
character(len=len(input_string)) function, public uppercase(input_string)
Return a string in which all uppercase letters have been replaced by their lowercase counterparts.
character(len=1320) function, public left_reals(r, sep)
Returns a character string of a comma-separated, compact formatted, reals e.g. "1....
logical function isformattedfloatequalto(str, val)
Returns True if the string can be read/parsed to give the exact value of "val".
logical function localtests(verbose, str1, str2)
True if str1 does not match str2. False otherwise.
logical function localtesti(verbose, i1, i2)
True if i1 is not equal to i2. False otherwise.
character(len=1320) function, public left_ints(i)
Returns a character string of a comma-separated, compact formatted, integers e.g. "1,...
character(len=19) function, public left_int(i)
Returns a character string of a left-formatted integer e.g. "123 " (assumes 19 digit maximum)
character(len=120) function, public extractword(string, n)
Returns the string corresponding to the nth word in the argument or "" if the string is not long enou...
character(len=len(dir)+2) function, public slasher(dir)
Returns a directory name that is terminated with a "/" or "./" if the argument is an empty string.
logical function, public string_functions_unit_tests(verbose)
Returns true if a unit test of string_functions fails.
logical function localtestr(verbose, r1, r2)
True if r1 is not equal to r2. False otherwise.
character(len=len(input_string)) function, public lowercase(input_string)
Return a string in which all uppercase letters have been replaced by their lowercase counterparts.
character(len=32) function, public left_real(val)
Returns a left-justified string with a real formatted like '(G)'.
integer function, public extract_integer(string, separators, n, missing_value)
Returns the integer corresponding to the nth word in the argument.