NCEPLIBS-bufr  11.7.0
 All Data Structures Files Functions Variables Pages
wrdlen.F
Go to the documentation of this file.
1 C> @file
2 C> @brief Determine important information about the local machine.
3 
4 C> This subroutine figures out some important information about the
5 C> local machine on which the BUFRLIB software is being run, including
6 C> the native endianness, the number of bytes in an integer, and
7 C> whether the machine uses the ASCII or EBCDIC character set.
8 C>
9 C> <p>This subroutine isn't normally called directly by any
10 C> application program, because it's automatically called internally
11 C> from within subroutine openbf() during the first time that subroutine
12 C> is called by any application program. It's also called as needed
13 C> from within several other subroutines, but it always keeps track of
14 C> its results as well as whether it has already been called during
15 C> the life of an application program, and that way if it does end
16 C> up being called more than once, it will just quietly return without
17 C> having to recompute all of its results from the first call.
18 C>
19 C> @authors J. Woollen
20 C> @authors J. Ator
21 C> @date 1994-01-06
22 C>
23 C> <b>Program history log:</b>
24 C> | Date | Programmer | Comments |
25 C> | -----|------------|----------|
26 C> | 1994-01-06 | J. Woollen | Original author |
27 C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine ABORT with call to new internal routine bort() |
28 C> | 2003-11-04 | J. Ator | Added documentation |
29 C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
30 C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added documentation; outputs more complete diagnostic info when routine terminates abnormally, initialized NBYTW to zero during the first call |
31 C> | 2004-08-18 | J. Ator | Added SAVE For IFIRST flag and immediate return if IFIRST=1 |
32 C> | 2007-01-19 | J. Ator | Big-endian vs. little-endian is now determined at compile time and configured within BUFRLIB via conditional compilation directives |
33 C> | 2009-03-23 | J. Ator | Call bvers() to get version number |
34 C>
35  SUBROUTINE wrdlen
36 
37  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
38  COMMON /charac/ iascii,iatoe(0:255),ietoa(0:255)
39  COMMON /quiet / iprt
40 
41  CHARACTER*128 bort_str,errstr
42  CHARACTER*8 cint,dint,cvstr
43  CHARACTER*6 cndian,clang
44  equivalence(cint,int)
45  equivalence(dint,jnt)
46  LOGICAL print
47 
48  DATA ifirst/0/
49 
50  SAVE ifirst
51 
52 C-----------------------------------------------------------------------
53 C-----------------------------------------------------------------------
54 
55 C HAS THIS SUBROUTINE ALREADY BEEN CALLED?
56 
57  IF(ifirst.EQ.0) THEN
58 
59 C NO, SO CHECK WHETHER DIAGNOSTIC INFORMATION SHOULD BE PRINTED
60 C AND THEN PROCEED THROUGH THE REST OF THE SUBROUTINE.
61 
62  print = iprt.GE.1
63  ifirst = 1
64  ELSE
65 
66 C YES, SO THERE IS NO NEED TO PROCEED ANY FURTHER.
67 
68  RETURN
69  ENDIF
70 
71 C COUNT THE BITS IN A WORD - MAX 64 ALLOWED
72 C -----------------------------------------
73 
74  int = 1
75  DO i=1,65
76  int = ishft(int,1)
77  IF(int.EQ.0) goto 10
78  ENDDO
79  10 IF(i.GE.65) goto 900
80  IF(mod(i,8).NE.0) goto 901
81 
82 C NBITW is no. of bits in a word, NBYTW is no. of bytes in a word
83 C ---------------------------------------------------------------
84 
85  nbitw = i
86  nbytw = i/8
87 
88 C INDEX THE BYTE STORAGE ORDER - HIGH BYTE TO LOW BYTE
89 C -----------------------------------------------------
90 
91  jnt = 0
92 
93  DO i = 1,8
94  iord(i) = 9999
95  ENDDO
96 
97  DO i=1,nbytw
98  int = ishft(1,(nbytw-i)*8)
99  DO j=1,nbytw
100  IF(cint(j:j).NE.dint(j:j)) goto 20
101  ENDDO
102 c .... DK: Can the below ever happen since upper loop bounds is NBYTW?
103  20 IF(j.GT.nbytw) goto 902
104  iord(i) = j
105  ENDDO
106 
107 C SETUP AN ASCII/EBCDIC TRANSLATOR AND DETERMINE WHICH IS NATIVE
108 C --------------------------------------------------------------
109 
110  ia = iupm('A',8)
111  IF(ia.EQ. 65) THEN
112  iascii = 1
113  clang = 'ASCII '
114  ELSEIF(ia.EQ.193) THEN
115  iascii = 0
116  clang = 'EBCDIC'
117  ELSE
118  goto 903
119  ENDIF
120 
121  DO i=0,255
122  ietoa(i) = 0
123  iatoe(i) = 0
124  ENDDO
125 
126  ietoa( 1) = 1
127  iatoe( 1) = 1
128  ietoa( 2) = 2
129  iatoe( 2) = 2
130  ietoa( 3) = 3
131  iatoe( 3) = 3
132  ietoa( 5) = 9
133  iatoe( 9) = 5
134  ietoa( 7) = 127
135  iatoe(127) = 7
136  ietoa( 11) = 11
137  iatoe( 11) = 11
138  ietoa( 12) = 12
139  iatoe( 12) = 12
140  ietoa( 13) = 13
141  iatoe( 13) = 13
142  ietoa( 14) = 14
143  iatoe( 14) = 14
144  ietoa( 15) = 15
145  iatoe( 15) = 15
146  ietoa( 16) = 16
147  iatoe( 16) = 16
148  ietoa( 17) = 17
149  iatoe( 17) = 17
150  ietoa( 18) = 18
151  iatoe( 18) = 18
152  ietoa( 19) = 19
153  iatoe( 19) = 19
154  ietoa( 22) = 8
155  iatoe( 8) = 22
156  ietoa( 24) = 24
157  iatoe( 24) = 24
158  ietoa( 25) = 25
159  iatoe( 25) = 25
160  ietoa( 29) = 29
161  iatoe( 29) = 29
162  ietoa( 31) = 31
163  iatoe( 31) = 31
164  ietoa( 34) = 28
165  iatoe( 28) = 34
166  ietoa( 37) = 10
167  iatoe( 10) = 37
168  ietoa( 38) = 23
169  iatoe( 23) = 38
170  ietoa( 39) = 27
171  iatoe( 27) = 39
172  ietoa( 45) = 5
173  iatoe( 5) = 45
174  ietoa( 46) = 6
175  iatoe( 6) = 46
176  ietoa( 47) = 7
177  iatoe( 7) = 47
178  ietoa( 50) = 22
179  iatoe( 22) = 50
180  ietoa( 53) = 30
181  iatoe( 30) = 53
182  ietoa( 55) = 4
183  iatoe( 4) = 55
184  ietoa( 60) = 20
185  iatoe( 20) = 60
186  ietoa( 61) = 21
187  iatoe( 21) = 61
188  ietoa( 63) = 26
189  iatoe( 26) = 63
190  ietoa( 64) = 32
191  iatoe( 32) = 64
192  ietoa( 74) = 91
193  iatoe( 91) = 74
194  ietoa( 75) = 46
195  iatoe( 46) = 75
196  ietoa( 76) = 60
197  iatoe( 60) = 76
198  ietoa( 77) = 40
199  iatoe( 40) = 77
200  ietoa( 78) = 43
201  iatoe( 43) = 78
202  ietoa( 79) = 33
203  iatoe( 33) = 79
204  ietoa( 80) = 38
205  iatoe( 38) = 80
206  ietoa( 90) = 93
207  iatoe( 93) = 90
208  ietoa( 91) = 36
209  iatoe( 36) = 91
210  ietoa( 92) = 42
211  iatoe( 42) = 92
212  ietoa( 93) = 41
213  iatoe( 41) = 93
214  ietoa( 94) = 59
215  iatoe( 59) = 94
216  ietoa( 95) = 94
217  iatoe( 94) = 95
218  ietoa( 96) = 45
219  iatoe( 45) = 96
220  ietoa( 97) = 47
221  iatoe( 47) = 97
222  ietoa(106) = 124
223  iatoe(124) = 106
224  ietoa(107) = 44
225  iatoe( 44) = 107
226  ietoa(108) = 37
227  iatoe( 37) = 108
228  ietoa(109) = 95
229  iatoe( 95) = 109
230  ietoa(110) = 62
231  iatoe( 62) = 110
232  ietoa(111) = 63
233  iatoe( 63) = 111
234  ietoa(121) = 96
235  iatoe( 96) = 121
236  ietoa(122) = 58
237  iatoe( 58) = 122
238  ietoa(123) = 35
239  iatoe( 35) = 123
240  ietoa(124) = 64
241  iatoe( 64) = 124
242  ietoa(125) = 39
243  iatoe( 39) = 125
244  ietoa(126) = 61
245  iatoe( 61) = 126
246  ietoa(127) = 34
247  iatoe( 34) = 127
248  ietoa(129) = 97
249  iatoe( 97) = 129
250  ietoa(130) = 98
251  iatoe( 98) = 130
252  ietoa(131) = 99
253  iatoe( 99) = 131
254  ietoa(132) = 100
255  iatoe(100) = 132
256  ietoa(133) = 101
257  iatoe(101) = 133
258  ietoa(134) = 102
259  iatoe(102) = 134
260  ietoa(135) = 103
261  iatoe(103) = 135
262  ietoa(136) = 104
263  iatoe(104) = 136
264  ietoa(137) = 105
265  iatoe(105) = 137
266  ietoa(145) = 106
267  iatoe(106) = 145
268  ietoa(146) = 107
269  iatoe(107) = 146
270  ietoa(147) = 108
271  iatoe(108) = 147
272  ietoa(148) = 109
273  iatoe(109) = 148
274  ietoa(149) = 110
275  iatoe(110) = 149
276  ietoa(150) = 111
277  iatoe(111) = 150
278  ietoa(151) = 112
279  iatoe(112) = 151
280  ietoa(152) = 113
281  iatoe(113) = 152
282  ietoa(153) = 114
283  iatoe(114) = 153
284  ietoa(161) = 126
285  iatoe(126) = 161
286  ietoa(162) = 115
287  iatoe(115) = 162
288  ietoa(163) = 116
289  iatoe(116) = 163
290  ietoa(164) = 117
291  iatoe(117) = 164
292  ietoa(165) = 118
293  iatoe(118) = 165
294  ietoa(166) = 119
295  iatoe(119) = 166
296  ietoa(167) = 120
297  iatoe(120) = 167
298  ietoa(168) = 121
299  iatoe(121) = 168
300  ietoa(169) = 122
301  iatoe(122) = 169
302  ietoa(173) = 91
303  iatoe( 91) = 173
304  ietoa(176) = 48
305  iatoe( 48) = 176
306  ietoa(177) = 49
307  iatoe( 49) = 177
308  ietoa(178) = 50
309  iatoe( 50) = 178
310  ietoa(179) = 51
311  iatoe( 51) = 179
312  ietoa(180) = 52
313  iatoe( 52) = 180
314  ietoa(181) = 53
315  iatoe( 53) = 181
316  ietoa(182) = 54
317  iatoe( 54) = 182
318  ietoa(183) = 55
319  iatoe( 55) = 183
320  ietoa(184) = 56
321  iatoe( 56) = 184
322  ietoa(185) = 57
323  iatoe( 57) = 185
324  ietoa(189) = 93
325  iatoe( 93) = 189
326  ietoa(192) = 123
327  iatoe(123) = 192
328  ietoa(193) = 65
329  iatoe( 65) = 193
330  ietoa(194) = 66
331  iatoe( 66) = 194
332  ietoa(195) = 67
333  iatoe( 67) = 195
334  ietoa(196) = 68
335  iatoe( 68) = 196
336  ietoa(197) = 69
337  iatoe( 69) = 197
338  ietoa(198) = 70
339  iatoe( 70) = 198
340  ietoa(199) = 71
341  iatoe( 71) = 199
342  ietoa(200) = 72
343  iatoe( 72) = 200
344  ietoa(201) = 73
345  iatoe( 73) = 201
346  ietoa(208) = 125
347  iatoe(125) = 208
348  ietoa(209) = 74
349  iatoe( 74) = 209
350  ietoa(210) = 75
351  iatoe( 75) = 210
352  ietoa(211) = 76
353  iatoe( 76) = 211
354  ietoa(212) = 77
355  iatoe( 77) = 212
356  ietoa(213) = 78
357  iatoe( 78) = 213
358  ietoa(214) = 79
359  iatoe( 79) = 214
360  ietoa(215) = 80
361  iatoe( 80) = 215
362  ietoa(216) = 81
363  iatoe( 81) = 216
364  ietoa(217) = 82
365  iatoe( 82) = 217
366  ietoa(224) = 92
367  iatoe( 92) = 224
368  ietoa(226) = 83
369  iatoe( 83) = 226
370  ietoa(227) = 84
371  iatoe( 84) = 227
372  ietoa(228) = 85
373  iatoe( 85) = 228
374  ietoa(229) = 86
375  iatoe( 86) = 229
376  ietoa(230) = 87
377  iatoe( 87) = 230
378  ietoa(231) = 88
379  iatoe( 88) = 231
380  ietoa(232) = 89
381  iatoe( 89) = 232
382  ietoa(233) = 90
383  iatoe( 90) = 233
384  ietoa(240) = 48
385  iatoe( 48) = 240
386  ietoa(241) = 49
387  iatoe( 49) = 241
388  ietoa(242) = 50
389  iatoe( 50) = 242
390  ietoa(243) = 51
391  iatoe( 51) = 243
392  ietoa(244) = 52
393  iatoe( 52) = 244
394  ietoa(245) = 53
395  iatoe( 53) = 245
396  ietoa(246) = 54
397  iatoe( 54) = 246
398  ietoa(247) = 55
399  iatoe( 55) = 247
400  ietoa(248) = 56
401  iatoe( 56) = 248
402  ietoa(249) = 57
403  iatoe( 57) = 249
404 
405 C SHOW SOME RESULTS
406 C -----------------
407 
408  IF(print) THEN
409  CALL bvers(cvstr)
410 #ifdef BIG_ENDIAN
411  cndian = ' BIG '
412 #else
413  cndian = 'LITTLE'
414 #endif
415  errstr = '=============== ' //
416  . 'WELCOME TO THE BUFR ARCHIVE LIBRARY' // ' =============='
417  CALL errwrt(errstr)
418  WRITE ( unit=errstr, fmt='(A,I2)' )
419  . ' MACHINE CHARACTERISTICS: NUMBER OF BYTES PER WORD =', nbytw
420  CALL errwrt(errstr)
421  WRITE ( unit=errstr, fmt='(A,I3)' )
422  . ' NUMBER OF BITS PER WORD =', nbitw
423  CALL errwrt(errstr)
424  errstr = ' BYTE ORDER IS ' // cndian //
425  . ' ENDIAN'
426  CALL errwrt(errstr)
427  errstr = ' ' // clang //
428  . ' IS THE NATIVE LANGUAGE'
429  CALL errwrt(errstr)
430  errstr = '====================== VERSION: ' // cvstr //
431  . '=========================='
432  CALL errwrt(errstr)
433  CALL errwrt(' ')
434  ENDIF
435 
436 C EXITS
437 C -----
438 
439  RETURN
440  900 WRITE(bort_str,'("BUFRLIB: WRDLEN - MACHINE WORD LENGTH IS '//
441  . 'LIMITED TO 64 BITS (THIS MACHINE APPARENTLY HAS",I4," BIT '//
442  . 'WORDS!)")') i
443  CALL bort(bort_str)
444  901 WRITE(bort_str,'("BUFRLIB: WRDLEN - MACHINE WORD LENGTH (",I4,"'//
445  . ') IS NOT A MULTIPLE OF 8 (THIS MACHINE HAS WORDS NOT ON WHOLE'//
446  . ' BYTE BOUNDARIES!)")') i
447  CALL bort(bort_str)
448  902 WRITE(bort_str,'("BUFRLIB: WRDLEN - BYTE ORDER CHECKING MISTAKE'//
449  . .GT.', LOOP INDEX J (HERE =",I3,") IS NO. OF BYTES PER WORD '//
450  . 'ON THIS MACHINE (",I3,")")') j,nbytw
451  CALL bort(bort_str)
452  903 WRITE(bort_str,'("BUFRLIB: WRDLEN - CAN''T DETERMINE MACHINE '//
453  . 'NATIVE LANGUAGE (CHAR. A UNPACKS TO INT.",I4," NEITHER ASCII '//
454  . ' (65) NOR EBCDIC (193)")') ia
455  CALL bort(bort_str)
456  END
function iupm(CBAY, NBITS)
THIS FUNCTION UNPACKS AND RETURNS A BINARY INTEGER WORD CONTAINED WITHIN NBITS BITS OF A CHARACTER ST...
Definition: iupm.f:40
subroutine wrdlen
This subroutine figures out some important information about the local machine on which the BUFRLIB s...
Definition: wrdlen.F:35
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:41
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22