NCEPLIBS-bufr  12.0.0
wrdlen.F
Go to the documentation of this file.
1 C> @file
2 C> @brief Determine important information about the local machine.
3 C>
4 C> @author J. Woollen @author J. Ator @date 1994-01-06
5 
6 C> Determine important information about the local machine.
7 C>
8 C> This subroutine figures out some important information about the
9 C> local machine on which the NCEPLIBS-bufr software is being run,
10 C> including the native endianness and the number of bytes in an integer.
11 C>
12 C> This subroutine isn't normally called directly by any
13 C> application program, because it's automatically called internally
14 C> from within subroutine openbf() during the first time that subroutine
15 C> is called by any application program. It's also called as needed
16 C> from within several other subroutines, but it always keeps track of
17 C> its results as well as whether it has already been called during
18 C> the life of an application program, and that way if it does end
19 C> up being called more than once, it will just quietly return without
20 C> having to recompute all of its results from the first call.
21 C>
22 C> @author J. Woollen @author J. Ator @date 1994-01-06
23 
24  SUBROUTINE wrdlen
25 
26  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
27  COMMON /quiet / iprt
28 
29  CHARACTER*128 BORT_STR,ERRSTR
30  CHARACTER*8 CINT,DINT,CVSTR
31  CHARACTER*6 CNDIAN
32  equivalence(cint,int)
33  equivalence(dint,jnt)
34  LOGICAL PRINT
35 
36  DATA ifirst/0/
37 
38  SAVE ifirst
39 
40 C-----------------------------------------------------------------------
41 C-----------------------------------------------------------------------
42 
43 C HAS THIS SUBROUTINE ALREADY BEEN CALLED?
44 
45  IF(ifirst.EQ.0) THEN
46 
47 C NO, SO CHECK WHETHER DIAGNOSTIC INFORMATION SHOULD BE PRINTED
48 C AND THEN PROCEED THROUGH THE REST OF THE SUBROUTINE.
49 
50  print = iprt.GE.1
51  ifirst = 1
52  ELSE
53 
54 C YES, SO THERE IS NO NEED TO PROCEED ANY FURTHER.
55 
56  RETURN
57  ENDIF
58 
59 C COUNT THE BITS IN A WORD - MAX 64 ALLOWED
60 C -----------------------------------------
61 
62  int = 1
63  DO i=1,65
64  int = ishft(int,1)
65  IF(int.EQ.0) GOTO 10
66  ENDDO
67  10 IF(i.GE.65) GOTO 900
68  IF(mod(i,8).NE.0) GOTO 901
69 
70 C NBITW is no. of bits in a word, NBYTW is no. of bytes in a word
71 C ---------------------------------------------------------------
72 
73  nbitw = i
74  nbytw = i/8
75 
76 C INDEX THE BYTE STORAGE ORDER - HIGH BYTE TO LOW BYTE
77 C -----------------------------------------------------
78 
79  jnt = 0
80 
81  DO i = 1,8
82  iord(i) = 9999
83  ENDDO
84 
85  DO i=1,nbytw
86  int = ishft(1,(nbytw-i)*8)
87  DO j=1,nbytw
88  IF(cint(j:j).NE.dint(j:j)) GOTO 20
89  ENDDO
90 c .... DK: Can the below ever happen since upper loop bounds is NBYTW?
91  20 IF(j.GT.nbytw) GOTO 902
92  iord(i) = j
93  ENDDO
94 
95 C SHOW SOME RESULTS
96 C -----------------
97 
98  IF(print) THEN
99  CALL bvers(cvstr)
100 #ifdef BIG_ENDIAN
101  cndian = ' BIG '
102 #else
103  cndian = 'LITTLE'
104 #endif
105  errstr = '=============== ' //
106  . 'WELCOME TO THE BUFR ARCHIVE LIBRARY' // ' =============='
107  CALL errwrt(errstr)
108  WRITE ( unit=errstr, fmt='(A,I2)' )
109  . ' MACHINE CHARACTERISTICS: NUMBER OF BYTES PER WORD =', nbytw
110  CALL errwrt(errstr)
111  WRITE ( unit=errstr, fmt='(A,I3)' )
112  . ' NUMBER OF BITS PER WORD =', nbitw
113  CALL errwrt(errstr)
114  errstr = ' BYTE ORDER IS ' // cndian //
115  . ' ENDIAN'
116  CALL errwrt(errstr)
117  CALL errwrt(errstr)
118  errstr = '====================== VERSION: ' // cvstr //
119  . '=========================='
120  CALL errwrt(errstr)
121  CALL errwrt(' ')
122  ENDIF
123 
124 C EXITS
125 C -----
126 
127  RETURN
128  900 WRITE(bort_str,'("BUFRLIB: WRDLEN - MACHINE WORD LENGTH IS '//
129  . 'LIMITED TO 64 BITS (THIS MACHINE APPARENTLY HAS",I4," BIT '//
130  . 'WORDS!)")') i
131  CALL bort(bort_str)
132  901 WRITE(bort_str,'("BUFRLIB: WRDLEN - MACHINE WORD LENGTH (",I4,"'//
133  . ') IS NOT A MULTIPLE OF 8 (THIS MACHINE HAS WORDS NOT ON WHOLE'//
134  . ' BYTE BOUNDARIES!)")') i
135  CALL bort(bort_str)
136  902 WRITE(bort_str,'("BUFRLIB: WRDLEN - BYTE ORDER CHECKING MISTAKE'//
137  . .GT.', LOOP INDEX J (HERE =",I3,") IS NO. OF BYTES PER WORD '//
138  . 'ON THIS MACHINE (",I3,")")') j,nbytw
139  CALL bort(bort_str)
140  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine bvers(CVERSTR)
Get the version number of the NCEPLIBS-bufr software.
Definition: bvers.f:15
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
subroutine wrdlen
Determine important information about the local machine.
Definition: wrdlen.F:25