forked from m3g/packmol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrlength.f90
60 lines (49 loc) · 1.27 KB
/
strlength.f90
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
!
! Written by Leandro Martínez, 2009-2011.
! Copyright (c) 2009-2011, Leandro Martínez, Jose Mario Martinez,
! Ernesto G. Birgin.
!
! Function that determines the length of a string (better than
! intrinsic "len" because considers tabs as empty characters)
!
function strlength(string)
implicit none
integer :: strlength
character(len=200) :: string
logical empty_char
strlength = 200
do while(empty_char(string(strlength:strlength)))
strlength = strlength - 1
if ( strlength == 0 ) exit
end do
end function strlength
!
! Function that determines if a character is empty (empty, space, or tab)
! (nice suggestion from Ian Harvey -IanH0073- at github)
!
function empty_char(ch)
character :: ch
logical empty_char
empty_char = .false.
if ( ch == '' .or. &
ch == achar(9) .or. &
ch == achar(32) ) then
empty_char = .true.
end if
end function empty_char
!
! Function that replaces all non-space empty characters by spaces
!
function alltospace(record)
implicit none
integer :: i
logical :: empty_char
character(len=200) :: alltospace, record
do i = 1, 200
if ( empty_char(record(i:i)) ) then
alltospace(i:i) = " "
else
alltospace(i:i) = record(i:i)
end if
end do
end function alltospace