1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/utils.F,v 1.6 1999/05/18 17:39:22 adcroft Exp $ |
2 |
|
3 |
#include "CPP_EEOPTIONS.h" |
4 |
|
5 |
C-- File utils.F: General purpose support routines |
6 |
C-- Contents |
7 |
C-- U DATE - Returns date and time. |
8 |
C-- IFNBLNK - Returns index of first non-blank string character. |
9 |
C-- ILNBLNK - Returns index of last non-blank string character. |
10 |
C-- IO_ERRCOUNT - Reads IO error counter. |
11 |
C-- LCASE - Translates to lower case. |
12 |
C--UM MACHINE - Returns character string identifying computer. |
13 |
C-- UCASE - Translates to upper case. |
14 |
C-- Routines marked "M" contain specific machine dependent code. |
15 |
C-- Routines marked "U" contain UNIX OS calls. |
16 |
|
17 |
CStartOfInterface |
18 |
SUBROUTINE DATE ( string , myThreadId ) |
19 |
C /==========================================================\ |
20 |
C | SUBROUTINE DATE | |
21 |
C | o Return current date | |
22 |
C \==========================================================/ |
23 |
IMPLICIT NONE |
24 |
#include "SIZE.h" |
25 |
#include "EEPARAMS.h" |
26 |
C |
27 |
CHARACTER*(*) string |
28 |
INTEGER myThreadId |
29 |
CEndOfInterface |
30 |
C |
31 |
INTEGER lDate |
32 |
CHARACTER*(MAX_LEN_MBUF) msgBuffer |
33 |
C |
34 |
lDate = 24 |
35 |
IF ( LEN(string) .LT. lDate ) GOTO 901 |
36 |
string = ' ' |
37 |
#ifndef TARGET_T3E |
38 |
CALL FDATE( string ) |
39 |
#endif |
40 |
C |
41 |
1000 CONTINUE |
42 |
RETURN |
43 |
901 CONTINUE |
44 |
WRITE(msgBuffer,'(A)') |
45 |
&' ' |
46 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
47 |
&SQUEEZE_RIGHT,myThreadId) |
48 |
WRITE(msgBuffer,'(A)') |
49 |
&'*** WARNING WARNING WARNING WARNING WARNING WARNING ***' |
50 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
51 |
&SQUEEZE_RIGHT,myThreadId) |
52 |
WRITE(msgBuffer,'(A)') |
53 |
&'procedure: "DATE".' |
54 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
55 |
&SQUEEZE_RIGHT,myThreadId) |
56 |
WRITE(msgBuffer,'(A)') |
57 |
&'Variable passed to S/R DATE is too small.' |
58 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
59 |
&SQUEEZE_RIGHT,myThreadId) |
60 |
WRITE(msgBuffer,'(A)') |
61 |
&' Argument must be at least',lDate,'characters long.' |
62 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
63 |
&SQUEEZE_RIGHT,myThreadId) |
64 |
WRITE(msgBuffer,'(A)') |
65 |
&'*******************************************************' |
66 |
CALL PRINT_MESSAGE(msgBuffer,standardMessageUnit, |
67 |
&SQUEEZE_RIGHT,myThreadId) |
68 |
GOTO 1000 |
69 |
END |
70 |
|
71 |
CStartOfInterface |
72 |
INTEGER FUNCTION IFNBLNK( string ) |
73 |
C /==========================================================\ |
74 |
C | FUNCTION IFNBLNK | |
75 |
C | o Find first non-blank in character string. | |
76 |
C \==========================================================/ |
77 |
IMPLICIT NONE |
78 |
C |
79 |
CHARACTER*(*) string |
80 |
CEndOfInterface |
81 |
C |
82 |
INTEGER L, LS |
83 |
C |
84 |
LS = LEN(string) |
85 |
IFNBLNK = 0 |
86 |
DO 10 L = 1, LS |
87 |
IF ( string(L:L) .EQ. ' ' ) GOTO 10 |
88 |
IFNBLNK = L |
89 |
GOTO 11 |
90 |
10 CONTINUE |
91 |
11 CONTINUE |
92 |
C |
93 |
RETURN |
94 |
END |
95 |
|
96 |
CStartOfInterface |
97 |
INTEGER FUNCTION ILNBLNK( string ) |
98 |
C /==========================================================\ |
99 |
C | FUNCTION ILNBLNK | |
100 |
C | o Find last non-blank in character string. | |
101 |
C \==========================================================/ |
102 |
IMPLICIT NONE |
103 |
CHARACTER*(*) string |
104 |
CEndOfInterface |
105 |
INTEGER L, LS |
106 |
C |
107 |
LS = LEN(string) |
108 |
ILNBLNK = LS |
109 |
DO 10 L = LS, 1, -1 |
110 |
IF ( string(L:L) .EQ. ' ' ) GOTO 10 |
111 |
ILNBLNK = L |
112 |
GOTO 11 |
113 |
10 CONTINUE |
114 |
11 CONTINUE |
115 |
C |
116 |
RETURN |
117 |
END |
118 |
|
119 |
CStartofinterface |
120 |
INTEGER FUNCTION IO_ERRCOUNT(myThid) |
121 |
C /==========================================================\ |
122 |
C | FUNCTION IO_ERRCOUNT | |
123 |
C | o Reads IO error counter. | |
124 |
C \==========================================================/ |
125 |
IMPLICIT NONE |
126 |
C == Global variables == |
127 |
#include "SIZE.h" |
128 |
#include "EEPARAMS.h" |
129 |
#include "DFILE.h" |
130 |
|
131 |
C == Routine arguments == |
132 |
INTEGER myThid |
133 |
CEndofinterface |
134 |
|
135 |
IO_ERRCOUNT = ioErrorCount(myThid) |
136 |
|
137 |
RETURN |
138 |
END |
139 |
|
140 |
CStartOfInterface |
141 |
SUBROUTINE LCASE ( string ) |
142 |
C /==========================================================\ |
143 |
C | SUBROUTINE LCASE | |
144 |
C | o Convert character string to all lower case. | |
145 |
C \==========================================================/ |
146 |
IMPLICIT NONE |
147 |
CHARACTER*(*) string |
148 |
CEndOfInterface |
149 |
CHARACTER*26 LOWER |
150 |
DATA LOWER /'abcdefghijklmnopqrstuvwxyz'/ |
151 |
SAVE LOWER |
152 |
CHARACTER*26 UPPER |
153 |
DATA UPPER /'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ |
154 |
SAVE UPPER |
155 |
INTEGER I, L |
156 |
C |
157 |
DO 10 I = 1, LEN(string) |
158 |
L = INDEX(UPPER,string(I:I)) |
159 |
IF ( L .EQ. 0 ) GOTO 10 |
160 |
string(I:I) = LOWER(L:L) |
161 |
10 CONTINUE |
162 |
C |
163 |
RETURN |
164 |
END |
165 |
|
166 |
CStartOfInterface |
167 |
SUBROUTINE MACHINE ( string ) |
168 |
C /==========================================================\ |
169 |
C | SUBROUTINE MACHINE | |
170 |
C | o Return computer identifier in string. | |
171 |
C \==========================================================/ |
172 |
IMPLICIT NONE |
173 |
#include "SIZE.h" |
174 |
#include "EEPARAMS.h" |
175 |
CHARACTER*(*) string |
176 |
CEndOfInterface |
177 |
C |
178 |
INTEGER IFNBLNK |
179 |
INTEGER ILNBLNK |
180 |
EXTERNAL IFNBLNK |
181 |
EXTERNAL ILNBLNK |
182 |
C |
183 |
INTEGER iFirst |
184 |
INTEGER iLast |
185 |
INTEGER iEnd |
186 |
INTEGER iFree |
187 |
INTEGER idSize |
188 |
CHARACTER*1024 strTmp |
189 |
CHARACTER*1024 idString |
190 |
|
191 |
strTmp = 'UNKNOWN' |
192 |
iFree = 1 |
193 |
idSize = LEN(string) |
194 |
#ifdef TARGET_T3E |
195 |
IFirst = 0 |
196 |
CALL PXFGETENV('USER',iFirst,strTmp,ILast,Iend ) |
197 |
#else |
198 |
CALL GETENV('USER',strTmp ) |
199 |
#endif |
200 |
IF ( strTmp .NE. ' ' ) THEN |
201 |
iFirst = IFNBLNK(strTmp) |
202 |
iLast = ILNBLNK(strTmp) |
203 |
iEnd = iLast-iFirst+1 |
204 |
IF (iEnd .GE. 0 ) THEN |
205 |
idString(iFree:) = strTmp(iFirst:iFirst+iEnd) |
206 |
ENDIF |
207 |
iFree = iFree+iEnd+1 |
208 |
IF ( iFree .LE. idSize ) THEN |
209 |
idString(iFree:iFree) = '@' |
210 |
iFree = iFree+1 |
211 |
ENDIF |
212 |
ENDIF |
213 |
strTmp = 'UNKNOWN' |
214 |
#ifdef TARGET_T3E |
215 |
IFirst = 0 |
216 |
CALL PXFGETENV('HOST',iFirst,strTmp,ILast,Iend ) |
217 |
#else |
218 |
CALL GETENV('HOST',strTmp ) |
219 |
#endif |
220 |
IF ( strTmp .NE. ' ' ) THEN |
221 |
iFirst = IFNBLNK(strTmp) |
222 |
iLast = ILNBLNK(strTmp) |
223 |
iEnd = iLast-iFirst+1 |
224 |
iEnd = MIN(iEnd,idSize-iFree) |
225 |
iEnd = iEnd-1 |
226 |
IF (iEnd .GE. 0 ) THEN |
227 |
idString(iFree:) = strTmp(iFirst:iFirst+iEnd) |
228 |
ENDIF |
229 |
iFree = iFree+iEnd+1 |
230 |
ENDIF |
231 |
C |
232 |
string = idString |
233 |
C |
234 |
1000 CONTINUE |
235 |
RETURN |
236 |
END |
237 |
C*********************************************************************** |
238 |
SUBROUTINE UCASE ( string ) |
239 |
IMPLICIT NONE |
240 |
C Translate string to upper case. |
241 |
CHARACTER*(*) string |
242 |
CHARACTER*26 LOWER |
243 |
DATA LOWER /'abcdefghijklmnopqrstuvwxyz'/ |
244 |
SAVE LOWER |
245 |
CHARACTER*26 UPPER |
246 |
DATA UPPER /'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ |
247 |
SAVE UPPER |
248 |
INTEGER I, L |
249 |
C |
250 |
DO 10 I = 1, LEN(string) |
251 |
L = INDEX(LOWER,string(I:I)) |
252 |
IF ( L .EQ. 0 ) GOTO 10 |
253 |
string(I:I) = UPPER(L:L) |
254 |
10 CONTINUE |
255 |
C |
256 |
RETURN |
257 |
END |
258 |
C************************************************************************ |