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