NCEPLIBS-bufr  11.7.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> | Date | Programmer | Comments |
42 C> | -----|------------|----------|
43 C> | 2012-09-15 | J. Ator | Original author |
44 C>
45  SUBROUTINE blocks(MBAY,MWRD)
46 
47  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
48  COMMON /endord/ iblock,iordbe(4),iordle(4)
49 
50  INTEGER*4 mbay(mwrd),iint,jint
51 
52  CHARACTER*1 cint(4),dint(4)
53  equivalence(cint,iint)
54  equivalence(dint,jint)
55 
56  DATA ifirst/0/
57  SAVE ifirst
58 
59 c----------------------------------------------------------------------
60 c----------------------------------------------------------------------
61 
62  if(iblock.eq.0) return
63 
64  if(ifirst.eq.0) then
65 
66 c Initialize some arrays for later use. Note that Fortran
67 c record control words are always 4 bytes.
68 
69  iint=0; cint(1)=char(1)
70  do i=1,4
71  if(cint(1).eq.char(01)) then
72  iordbe(i)=4-i+1
73  iordle(i)=i
74  else
75  iordle(i)=4-i+1
76  iordbe(i)=i
77  endif
78  enddo
79  ifirst=1
80  endif
81 
82 c make room in mbay for control words - one at each end of the record
83 c -------------------------------------------------------------------
84 
85  if(nbytw.eq.8) mwrd=mwrd*2
86 
87  do m=mwrd,1,-1
88  mbay(m+1) = mbay(m)
89  enddo
90 
91 c store the endianized control word in bytes in dint/jint
92 c -------------------------------------------------------
93 
94  iint=mwrd*4
95 
96  do i=1,4
97  if(iblock.eq.+1) dint(i)=cint(iordbe(i))
98  if(iblock.eq.-1) dint(i)=cint(iordle(i))
99  enddo
100 
101 c increment mrwd and install the control words in their proper places
102 c -------------------------------------------------------------------
103 
104  mwrd = mwrd+2
105  mbay(1) = jint
106  mbay(mwrd) = jint
107 
108  if(nbytw.eq.8) mwrd=mwrd/2
109 
110  return
111  end
subroutine blocks(MBAY, MWRD)
This subroutine encapsulates a BUFR message with IEEE Fortran control words as specified via the most...
Definition: blocks.f:45