forked from m3g/packmol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strlength.f90
96 lines (85 loc) · 2.21 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
!
! Written by Leandro Martínez, 2009-2011.
! Copyright (c) 2009-2018, 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)
use sizes
implicit none
integer :: strlength
character(len=strl) :: string
logical empty_char
strlength = strl
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)
use sizes
implicit none
integer :: i
logical :: empty_char
character(len=strl) :: alltospace, record
do i = 1, strl
if ( empty_char(record(i:i)) ) then
alltospace(i:i) = " "
else
alltospace(i:i) = record(i:i)
end if
end do
end function alltospace
subroutine parse_spaces(record)
use input, only : forbidden_char
use sizes
implicit none
integer :: i, strlength
character(len=strl) :: record
! Replace spaces within quotes by ~
i = 0
do while(i < strlength(record))
i = i + 1
if ( record(i:i) == '"' ) then
i = i + 1
do while(record(i:i) /= '"')
i = i + 1
if( i > strlength(record) ) then
write(*,*) ' ERROR: Could not find ending quotes in line: ', trim(record)
stop
end if
if(record(i:i) == " ") then
record(i:i) = forbidden_char
end if
end do
end if
end do
! Replace spaces after \ by the forbidden_char and remove the \
i = 0
do while(i < strlength(record)-1)
i = i + 1
if (record(i:i) == "\" .and. record(i+1:i+1) == " ") then
record(i:i) = forbidden_char
record = record(1:i)//record(i+2:strlength(record))
end if
end do
end