NCEPLIBS-bufr  12.0.1
blocks.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Encapsulate a BUFR message with IEEE Fortran control
3 C> words.
4 C> @author J. Woollen @date 2012-09-15
5 
6 C> This subroutine encapsulates a BUFR message with IEEE Fortran
7 C> control words as specified via the most recent call to
8 C> subroutine setblock().
9 C>
10 C> A previous call to subroutine setblock() is required in
11 C> order to activate encapsulation with control words, and to
12 C> specify whether the control words should be encoded using
13 C> big-endian or little-endian byte ordering. In such cases,
14 C> the input parameter MBAY is then modified to
15 C> add the specified control words to the existing BUFR message
16 C> whenever this subroutine is called, and MWRD is also
17 C> modified accordingly.
18 C>
19 C> Alternatively, if subroutine setblock() was never previously
20 C> called, or if no encapsulation was specified during the most
21 C> recent call to subroutine setblock(), then this subroutine
22 C> simply returns without modifying either of its input parameters.
23 C> @date 2012-09-15
24 C>
25 C> @param[in,out] MBAY -- integer(*): BUFR message, possibly with
26 C> added control words on output
27 C> @param[in,out] MWRD -- integer: Size (in integers) of contents
28 C> of MBAY
29 C>
30 C> @remarks
31 C> - For more information about IEEE Fortran control words, as
32 C> well as their historical use within the BUFRLIB software, see
33 C> the documentation for subroutine setblock().
34 C> - Whenever a BUFR message in MBAY is to be encapsulated with
35 C> control words, the user must ensure the availability of
36 C> sufficient extra space when allocating MBAY within the
37 C> application program.
38 C>
39 C> @author J. Woollen @date 2012-09-15
40  SUBROUTINE blocks(MBAY,MWRD)
41 
42  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
43  COMMON /endord/ iblock,iordbe(4),iordle(4)
44 
45  INTEGER*4 MBAY(MWRD),IINT,JINT
46 
47  CHARACTER*1 CINT(4),DINT(4)
48  equivalence(cint,iint)
49  equivalence(dint,jint)
50 
51  DATA ifirst/0/
52  SAVE ifirst
53 
54 c----------------------------------------------------------------------
55 c----------------------------------------------------------------------
56 
57  if(iblock.eq.0) return
58 
59  if(ifirst.eq.0) then
60 
61 c Initialize some arrays for later use. Note that Fortran
62 c record control words are always 4 bytes.
63 
64  iint=0; cint(1)=char(1)
65  do i=1,4
66  if(cint(1).eq.char(01)) then
67  iordbe(i)=4-i+1
68  iordle(i)=i
69  else
70  iordle(i)=4-i+1
71  iordbe(i)=i
72  endif
73  enddo
74  ifirst=1
75  endif
76 
77 c make room in mbay for control words - one at each end of the record
78 c -------------------------------------------------------------------
79 
80  if(nbytw.eq.8) mwrd=mwrd*2
81 
82  do m=mwrd,1,-1
83  mbay(m+1) = mbay(m)
84  enddo
85 
86 c store the endianized control word in bytes in dint/jint
87 c -------------------------------------------------------
88 
89  iint=mwrd*4
90 
91  do i=1,4
92  if(iblock.eq.+1) dint(i)=cint(iordbe(i))
93  if(iblock.eq.-1) dint(i)=cint(iordle(i))
94  enddo
95 
96 c increment mrwd and install the control words in their proper places
97 c -------------------------------------------------------------------
98 
99  mwrd = mwrd+2
100  mbay(1) = jint
101  mbay(mwrd) = jint
102 
103  if(nbytw.eq.8) mwrd=mwrd/2
104 
105  return
106  end
subroutine blocks(MBAY, MWRD)
This subroutine encapsulates a BUFR message with IEEE Fortran control words as specified via the most...
Definition: blocks.f:41