NCEPLIBS-bufr 11.7.1
blocks.f
Go to the documentation of this file.
1C> @file
2C> @brief Encapsulate a BUFR message with IEEE Fortran control
3C> words.
4
5C> This subroutine encapsulates a BUFR message with IEEE Fortran
6C> control words as specified via the most recent call to
7C> subroutine setblock().
8C>
9C> <p>A previous call to subroutine setblock() is required in
10C> order to activate encapsulation with control words, and to
11C> specify whether the control words should be encoded using
12C> big-endian or little-endian byte ordering. In such cases,
13C> the input parameter MBAY is then modified to
14C> add the specified control words to the existing BUFR message
15C> whenever this subroutine is called, and MWRD is also
16C> modified accordingly.
17C>
18C> <p>Alternatively, if subroutine setblock() was never previously
19C> called, or if no encapsulation was specified during the most
20C> recent call to subroutine setblock(), then this subroutine
21C> simply returns without modifying either of its input parameters.
22C>
23C> @author J. Woollen
24C> @date 2012-09-15
25C>
26C> @param[in,out] MBAY -- integer(*): BUFR message, possibly with
27C> added control words on output
28C> @param[in,out] MWRD -- integer: Size (in integers) of contents
29C> of MBAY
30C>
31C> @remarks
32C> - For more information about IEEE Fortran control words, as
33C> well as their historical use within the BUFRLIB software, see
34C> the documentation for subroutine setblock().
35C> - Whenever a BUFR message in MBAY is to be encapsulated with
36C> control words, the user must ensure the availability of
37C> sufficient extra space when allocating MBAY within the
38C> application program.
39C>
40C> <b>Program history log:</b>
41C> | Date | Programmer | Comments |
42C> | -----|------------|----------|
43C> | 2012-09-15 | J. Ator | Original author |
44C>
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
59c----------------------------------------------------------------------
60c----------------------------------------------------------------------
61
62 if(iblock.eq.0) return
63
64 if(ifirst.eq.0) then
65
66c Initialize some arrays for later use. Note that Fortran
67c 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
82c make room in mbay for control words - one at each end of the record
83c -------------------------------------------------------------------
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
91c store the endianized control word in bytes in dint/jint
92c -------------------------------------------------------
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
101c increment mrwd and install the control words in their proper places
102c -------------------------------------------------------------------
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:46