New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
stringop.f90 in utils/tools/DOMAINcfg/src – NEMO

source: utils/tools/DOMAINcfg/src/stringop.f90

Last change on this file was 14623, checked in by ldebreu, 3 years ago

AGFdomcfg: 1) Update DOMAINcfg to be compliant with the removal of halo cells 2) Update most of the LBC ... subroutines to a recent NEMO 4 version #2638

File size: 5.4 KB
Line 
1MODULE stringop
2!$AGRIF_DO_NOT_TREAT
3!-
4!$Id: stringop.f90 2281 2010-10-15 14:21:13Z smasson $
5!-
6! This software is governed by the CeCILL license
7! See IOIPSL/IOIPSL_License_CeCILL.txt
8!---------------------------------------------------------------------
9CONTAINS
10!=
11SUBROUTINE cmpblank (str)
12!---------------------------------------------------------------------
13!- Compact blanks
14!---------------------------------------------------------------------
15  CHARACTER(LEN=*),INTENT(inout) :: str
16!-
17  INTEGER :: lcc,ipb
18!---------------------------------------------------------------------
19  lcc = LEN_TRIM(str)
20  ipb = 1
21  DO
22    IF (ipb >= lcc)   EXIT
23    IF (str(ipb:ipb+1) == '  ') THEN
24      str(ipb+1:) = str(ipb+2:lcc)
25      lcc = lcc-1
26    ELSE
27      ipb = ipb+1
28    ENDIF
29  ENDDO
30!----------------------
31END SUBROUTINE cmpblank
32!===
33INTEGER FUNCTION cntpos (c_c,l_c,c_r,l_r)
34!---------------------------------------------------------------------
35!- Finds number of occurences of c_r in c_c
36!---------------------------------------------------------------------
37  IMPLICIT NONE
38!-
39  CHARACTER(LEN=*),INTENT(in) :: c_c
40  INTEGER,INTENT(IN) :: l_c
41  CHARACTER(LEN=*),INTENT(in) :: c_r
42  INTEGER,INTENT(IN) :: l_r
43!-
44  INTEGER :: ipos,indx
45!---------------------------------------------------------------------
46  cntpos = 0
47  ipos   = 1
48  DO
49    indx = INDEX(c_c(ipos:l_c),c_r(1:l_r))
50    IF (indx > 0) THEN
51      cntpos = cntpos+1
52      ipos   = ipos+indx+l_r-1
53    ELSE
54      EXIT
55    ENDIF
56  ENDDO
57!------------------
58END FUNCTION cntpos
59!===
60INTEGER FUNCTION findpos (c_c,l_c,c_r,l_r)
61!---------------------------------------------------------------------
62!- Finds position of c_r in c_c
63!---------------------------------------------------------------------
64  IMPLICIT NONE
65!-
66  CHARACTER(LEN=*),INTENT(in) :: c_c
67  INTEGER,INTENT(IN) :: l_c
68  CHARACTER(LEN=*),INTENT(in) :: c_r
69  INTEGER,INTENT(IN) :: l_r
70!---------------------------------------------------------------------
71  findpos = INDEX(c_c(1:l_c),c_r(1:l_r))
72  IF (findpos == 0)  findpos=-1
73!-------------------
74END FUNCTION findpos
75!===
76SUBROUTINE find_str (str_tab,str,pos)
77!---------------------------------------------------------------------
78!- This subroutine looks for a string in a table
79!---------------------------------------------------------------------
80!- INPUT
81!-   str_tab  : Table  of strings
82!-   str      : Target we are looking for
83!- OUTPUT
84!-   pos      : -1 if str not found, else value in the table
85!---------------------------------------------------------------------
86  IMPLICIT NONE
87!-
88  CHARACTER(LEN=*),DIMENSION(:),INTENT(in) :: str_tab
89  CHARACTER(LEN=*),INTENT(in) :: str
90  INTEGER,INTENT(out) :: pos
91!-
92  INTEGER :: nb_str,i
93!---------------------------------------------------------------------
94  pos = -1
95  nb_str=SIZE(str_tab)
96  IF ( nb_str > 0 ) THEN
97    DO i=1,nb_str
98      IF ( TRIM(str_tab(i)) == TRIM(str) ) THEN
99        pos = i
100        EXIT
101      ENDIF
102    ENDDO
103  ENDIF
104!----------------------
105END SUBROUTINE find_str
106!===
107SUBROUTINE nocomma (str)
108!---------------------------------------------------------------------
109!- Replace commas with blanks
110!---------------------------------------------------------------------
111  IMPLICIT NONE
112!-
113  CHARACTER(LEN=*) :: str
114!-
115  INTEGER :: i
116!---------------------------------------------------------------------
117  DO i=1,LEN_TRIM(str)
118    IF (str(i:i) == ',')   str(i:i) = ' '
119  ENDDO
120!---------------------
121END SUBROUTINE nocomma
122!===
123SUBROUTINE strlowercase (str)
124!---------------------------------------------------------------------
125!- Converts a string into lowercase
126!---------------------------------------------------------------------
127  IMPLICIT NONE
128!-
129  CHARACTER(LEN=*) :: str
130!-
131  INTEGER :: i,ic
132!---------------------------------------------------------------------
133  DO i=1,LEN_TRIM(str)
134    ic = IACHAR(str(i:i))
135    IF ( (ic >= 65).AND.(ic <= 90) )  str(i:i) = ACHAR(ic+32)
136  ENDDO
137!--------------------------
138END SUBROUTINE strlowercase
139!===
140SUBROUTINE struppercase (str)
141!---------------------------------------------------------------------
142!- Converts a string into uppercase
143!---------------------------------------------------------------------
144  IMPLICIT NONE
145!-
146  CHARACTER(LEN=*) :: str
147!-
148  INTEGER :: i,ic
149!---------------------------------------------------------------------
150  DO i=1,LEN_TRIM(str)
151    ic = IACHAR(str(i:i))
152    IF ( (ic >= 97).AND.(ic <= 122) )  str(i:i) = ACHAR(ic-32)
153  ENDDO
154!--------------------------
155END SUBROUTINE struppercase
156!===
157SUBROUTINE str_xfw (c_string,c_word,l_ok)
158!---------------------------------------------------------------------
159!- Given a character string "c_string", of arbitrary length,
160!- returns a logical flag "l_ok" if a word is found in it,
161!- the first word "c_word" if found and the new string "c_string"
162!- without the first word "c_word"
163!---------------------------------------------------------------------
164  CHARACTER(LEN=*),INTENT(INOUT) :: c_string
165  CHARACTER(LEN=*),INTENT(OUT) :: c_word
166  LOGICAL,INTENT(OUT) :: l_ok
167!-
168  INTEGER :: i_b,i_e
169!---------------------------------------------------------------------
170  l_ok = (LEN_TRIM(c_string) > 0)
171  IF (l_ok) THEN
172    i_b = VERIFY(c_string,' ')
173    i_e = INDEX(c_string(i_b:),' ')
174    IF (i_e == 0) THEN
175      c_word = c_string(i_b:)
176      c_string = ""
177    ELSE
178      c_word = c_string(i_b:i_b+i_e-2)
179      c_string = ADJUSTL(c_string(i_b+i_e-1:))
180    ENDIF
181  ENDIF
182!---------------------
183END SUBROUTINE str_xfw
184!===
185!------------------
186!$AGRIF_END_DO_NOT_TREAT
187END MODULE stringop
Note: See TracBrowser for help on using the repository browser.