1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/utils.F,v 1.10 2001/02/04 14:38:44 cnh Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
C-- File utils.F: General purpose support routines |
7 |
C-- Contents |
8 |
C-- U DATE - Returns date and time. |
9 |
C-- IFNBLNK - Returns index of first non-blank string character. |
10 |
C-- ILNBLNK - Returns index of last non-blank string character. |
11 |
C-- IO_ERRCOUNT - Reads IO error counter. |
12 |
C-- LCASE - Translates to lower case. |
13 |
C--UM MACHINE - Returns character string identifying computer. |
14 |
C-- UCASE - Translates to upper case. |
15 |
C-- Routines marked "M" contain specific machine dependent code. |
16 |
C-- Routines marked "U" contain UNIX OS calls. |
17 |
|
18 |
CBOP |
19 |
C !ROUTINE: DATE |
20 |
|
21 |
C !INTERFACE: |
22 |
SUBROUTINE DATE ( string , myThreadId ) |
23 |
IMPLICIT NONE |
24 |
|
25 |
C !DESCRIPTION: |
26 |
C *==========================================================* |
27 |
C | SUBROUTINE DATE | |
28 |
C | o Return current date | |
29 |
C *==========================================================* |
30 |
|
31 |
C !USES: |
32 |
#include "SIZE.h" |
33 |
#include "EEPARAMS.h" |
34 |
|
35 |
C !INPUT/OUTPUT PARAMETERS: |
36 |
C string :: Date returned in string |
37 |
C myThreadId :: My thread number |
38 |
CHARACTER*(*) string |
39 |
INTEGER myThreadId |
40 |
C |
41 |
C !LOCAL VARIABLES: |
42 |
C lDate :: Length of date string |
43 |
C msgBuffer :: Temp. for building error messages |
44 |
INTEGER lDate |
45 |
CHARACTER*(MAX_LEN_MBUF) msgBuffer |
46 |
CEOP |
47 |
C |
48 |
lDate = 24 |
49 |
IF ( LEN(string) .LT. lDate ) GOTO 901 |
50 |
string = ' ' |
51 |
#ifndef TARGET_T3E |
52 |
#ifndef TARGET_CRAY_VECTOR |
53 |
CALL FDATE( string ) |
54 |
#endif |
55 |
#endif |
56 |
C |
57 |
1000 CONTINUE |
58 |
RETURN |
59 |
901 CONTINUE |
60 |
WRITE(msgBuffer,'(A)') |
61 |
&' ' |
62 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
63 |
&SQUEEZE_RIGHT,myThreadId) |
64 |
WRITE(msgBuffer,'(A)') |
65 |
&'*** WARNING WARNING WARNING WARNING WARNING WARNING ***' |
66 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
67 |
&SQUEEZE_RIGHT,myThreadId) |
68 |
WRITE(msgBuffer,'(A)') |
69 |
&'procedure: "DATE".' |
70 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
71 |
&SQUEEZE_RIGHT,myThreadId) |
72 |
WRITE(msgBuffer,'(A)') |
73 |
&'Variable passed to S/R DATE is too small.' |
74 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
75 |
&SQUEEZE_RIGHT,myThreadId) |
76 |
WRITE(msgBuffer,'(A)') |
77 |
&' Argument must be at least',lDate,'characters long.' |
78 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
79 |
&SQUEEZE_RIGHT,myThreadId) |
80 |
WRITE(msgBuffer,'(A)') |
81 |
&'*******************************************************' |
82 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
83 |
&SQUEEZE_RIGHT,myThreadId) |
84 |
GOTO 1000 |
85 |
END |
86 |
|
87 |
CBOP |
88 |
C !ROUTINE: IFNBLNK |
89 |
|
90 |
C !INTERFACE: |
91 |
INTEGER FUNCTION IFNBLNK( string ) |
92 |
IMPLICIT NONE |
93 |
|
94 |
C !DESCRIPTION: |
95 |
C *==========================================================* |
96 |
C | FUNCTION IFNBLNK | |
97 |
C | o Find first non-blank in character string. | |
98 |
C *==========================================================* |
99 |
C |
100 |
C !INPUT PARAMETERS: |
101 |
C string :: String to find first non-blank in. |
102 |
CHARACTER*(*) string |
103 |
|
104 |
C !LOCAL VARIABLES: |
105 |
C L, LS :: Temps for string locations |
106 |
INTEGER L, LS |
107 |
CEOP |
108 |
C |
109 |
LS = LEN(string) |
110 |
IFNBLNK = 0 |
111 |
DO 10 L = 1, LS |
112 |
IF ( string(L:L) .EQ. ' ' ) GOTO 10 |
113 |
IFNBLNK = L |
114 |
GOTO 11 |
115 |
10 CONTINUE |
116 |
11 CONTINUE |
117 |
C |
118 |
RETURN |
119 |
END |
120 |
|
121 |
CBOP |
122 |
C !ROUTINE: ILNBLNK |
123 |
|
124 |
C !INTERFACE: |
125 |
INTEGER FUNCTION ILNBLNK( string ) |
126 |
IMPLICIT NONE |
127 |
|
128 |
C !DESCRIPTION: |
129 |
C *==========================================================* |
130 |
C | FUNCTION ILNBLNK | |
131 |
C | o Find last non-blank in character string. | |
132 |
C *==========================================================* |
133 |
|
134 |
C !INPUT PARAMETERS: |
135 |
C string :: string to scan |
136 |
CHARACTER*(*) string |
137 |
|
138 |
C !LOCAL VARIABLES: |
139 |
C L, LS :: Temps. used in scanning string |
140 |
INTEGER L, LS |
141 |
CEOP |
142 |
C |
143 |
LS = LEN(string) |
144 |
ILNBLNK = LS |
145 |
DO 10 L = LS, 1, -1 |
146 |
IF ( string(L:L) .EQ. ' ' ) GOTO 10 |
147 |
ILNBLNK = L |
148 |
GOTO 11 |
149 |
10 CONTINUE |
150 |
11 CONTINUE |
151 |
C |
152 |
RETURN |
153 |
END |
154 |
|
155 |
CBOP |
156 |
C !ROUTINE: IO_ERRCOUNT |
157 |
|
158 |
C !INTERFACE: |
159 |
INTEGER FUNCTION IO_ERRCOUNT(myThid) |
160 |
IMPLICIT NONE |
161 |
|
162 |
C !DESCRIPTION: |
163 |
C *==========================================================* |
164 |
C | FUNCTION IO_ERRCOUNT | |
165 |
C | o Reads IO error counter. | |
166 |
C *==========================================================* |
167 |
|
168 |
C !USES: |
169 |
C == Global variables == |
170 |
#include "SIZE.h" |
171 |
#include "EEPARAMS.h" |
172 |
|
173 |
C !INPUT PARAMETERS: |
174 |
C == Routine arguments == |
175 |
C myThid :: My thread number |
176 |
INTEGER myThid |
177 |
|
178 |
CEOP |
179 |
|
180 |
IO_ERRCOUNT = ioErrorCount(myThid) |
181 |
|
182 |
RETURN |
183 |
END |
184 |
|
185 |
CBOP |
186 |
|
187 |
C !ROUTINE: LCASE |
188 |
|
189 |
C !INTERFACE: |
190 |
SUBROUTINE LCASE ( string ) |
191 |
IMPLICIT NONE |
192 |
|
193 |
C !DESCRIPTION: |
194 |
C *==========================================================* |
195 |
C | SUBROUTINE LCASE | |
196 |
C | o Convert character string to all lower case. | |
197 |
C *==========================================================* |
198 |
|
199 |
C !INPUT/OUTPUT PARAMETERS: |
200 |
CHARACTER*(*) string |
201 |
|
202 |
C !LOCALVARIABLES: |
203 |
CHARACTER*26 LOWER |
204 |
DATA LOWER /'abcdefghijklmnopqrstuvwxyz'/ |
205 |
SAVE LOWER |
206 |
CHARACTER*26 UPPER |
207 |
DATA UPPER /'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ |
208 |
SAVE UPPER |
209 |
INTEGER I, L |
210 |
CEOP |
211 |
|
212 |
C |
213 |
DO 10 I = 1, LEN(string) |
214 |
L = INDEX(UPPER,string(I:I)) |
215 |
IF ( L .EQ. 0 ) GOTO 10 |
216 |
string(I:I) = LOWER(L:L) |
217 |
10 CONTINUE |
218 |
C |
219 |
RETURN |
220 |
END |
221 |
|
222 |
CBOP |
223 |
C !ROUTINE: MACHINE |
224 |
|
225 |
C !INTERFACE: |
226 |
SUBROUTINE MACHINE ( string ) |
227 |
IMPLICIT NONE |
228 |
|
229 |
C !DESCRIPTION: |
230 |
C *==========================================================* |
231 |
C | SUBROUTINE MACHINE | |
232 |
C | o Return computer identifier in string. | |
233 |
C *==========================================================* |
234 |
|
235 |
C !USES: |
236 |
#include "SIZE.h" |
237 |
#include "EEPARAMS.h" |
238 |
INTEGER IFNBLNK |
239 |
INTEGER ILNBLNK |
240 |
EXTERNAL IFNBLNK |
241 |
EXTERNAL ILNBLNK |
242 |
|
243 |
C !OUTPUT PARAMETERS: |
244 |
C string :: Machine identifier |
245 |
CHARACTER*(*) string |
246 |
|
247 |
C !LOCAL VARIABLES: |
248 |
C iFirst, iLast, :: String indexing temps. |
249 |
C iEnd, iFree, idSize |
250 |
C strTmp, idString :: Temps. for strings. |
251 |
INTEGER iFirst |
252 |
INTEGER iLast |
253 |
INTEGER iEnd |
254 |
INTEGER iFree |
255 |
INTEGER idSize |
256 |
CHARACTER*1024 strTmp |
257 |
CHARACTER*1024 idString |
258 |
CEOP |
259 |
|
260 |
strTmp = 'UNKNOWN' |
261 |
iFree = 1 |
262 |
idSize = LEN(string) |
263 |
#if (defined (TARGET_T3E) || defined (TARGET_CRAY_VECTOR)) |
264 |
IFirst = 0 |
265 |
CALL PXFGETENV('USER',iFirst,strTmp,ILast,Iend ) |
266 |
#else |
267 |
CALL GETENV('USER',strTmp ) |
268 |
#endif |
269 |
IF ( strTmp .NE. ' ' ) THEN |
270 |
iFirst = IFNBLNK(strTmp) |
271 |
iLast = ILNBLNK(strTmp) |
272 |
iEnd = iLast-iFirst+1 |
273 |
IF (iEnd .GE. 0 ) THEN |
274 |
idString(iFree:) = strTmp(iFirst:iFirst+iEnd) |
275 |
ENDIF |
276 |
iFree = iFree+iEnd+1 |
277 |
IF ( iFree .LE. idSize ) THEN |
278 |
idString(iFree:iFree) = '@' |
279 |
iFree = iFree+1 |
280 |
ENDIF |
281 |
ENDIF |
282 |
strTmp = 'UNKNOWN' |
283 |
#if (defined (TARGET_T3E) || defined (TARGET_CRAY_VECTOR)) |
284 |
IFirst = 0 |
285 |
CALL PXFGETENV('HOST',iFirst,strTmp,ILast,Iend ) |
286 |
#else |
287 |
CALL GETENV('HOST',strTmp ) |
288 |
#endif |
289 |
IF ( strTmp .NE. ' ' ) THEN |
290 |
iFirst = IFNBLNK(strTmp) |
291 |
iLast = ILNBLNK(strTmp) |
292 |
iEnd = iLast-iFirst+1 |
293 |
iEnd = MIN(iEnd,idSize-iFree) |
294 |
iEnd = iEnd-1 |
295 |
IF (iEnd .GE. 0 ) THEN |
296 |
idString(iFree:) = strTmp(iFirst:iFirst+iEnd) |
297 |
ENDIF |
298 |
iFree = iFree+iEnd+1 |
299 |
ENDIF |
300 |
C |
301 |
string = idString |
302 |
C |
303 |
1000 CONTINUE |
304 |
RETURN |
305 |
END |
306 |
|
307 |
CBOP |
308 |
C !ROUTINE: UCASE |
309 |
|
310 |
C !INTERFACE: |
311 |
SUBROUTINE UCASE ( string ) |
312 |
IMPLICIT NONE |
313 |
|
314 |
C !DESCRIPTION: |
315 |
C Translate string to upper case. |
316 |
|
317 |
C !INPUT/OUTPUT PARAMETERS: |
318 |
CHARACTER*(*) string |
319 |
|
320 |
C !LOCAL VARIABLES: |
321 |
CHARACTER*26 LOWER |
322 |
DATA LOWER /'abcdefghijklmnopqrstuvwxyz'/ |
323 |
SAVE LOWER |
324 |
CHARACTER*26 UPPER |
325 |
DATA UPPER /'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ |
326 |
SAVE UPPER |
327 |
INTEGER I, L |
328 |
CEOP |
329 |
|
330 |
C |
331 |
DO 10 I = 1, LEN(string) |
332 |
L = INDEX(LOWER,string(I:I)) |
333 |
IF ( L .EQ. 0 ) GOTO 10 |
334 |
string(I:I) = UPPER(L:L) |
335 |
10 CONTINUE |
336 |
C |
337 |
RETURN |
338 |
END |
339 |
C************************************************************************ |