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