NCEPLIBS-bufr  12.0.0
cmsgini.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Initialize a new compressed BUFR message for output.
3 C>
4 C> @author Woollen @date 2002-05-14
5 
6 C> This subroutine initializes a new BUFR message for output in compressed format.
7 C>
8 C> @param[in] LUN - integer: I/O stream index into internal memory arrays.
9 C> @param[out] MESG - integer(*): BUFR message.
10 C> @param[in] SUBSET - character*8: Table A mnemonic for type of BUFR message being written.
11 C> @param[in] IDATE - integer: date-time stored within Section 1 of BUFR message being written,
12 C> in format of either YYMMDDHH or YYYYMMDDHH, depending on datelen() value.
13 C> @param[in] NSUB - integer: number of subsets in MESG
14 C> @param[inout] NBYT - integer:
15 C> - On input, contains the length (in bytes) of Section 4, except for
16 C> the first 4 bytes
17 C> - On output, contains the length (in bytes) of the entire BUFR message, up
18 C> to the point in Section 4 where compressed data are to be written
19 C>
20 C> @author Woollen @date 2002-05-14
21 
22  SUBROUTINE cmsgini(LUN,MESG,SUBSET,IDATE,NSUB,NBYT)
23 
24  CHARACTER*128 BORT_STR
25  CHARACTER*8 SUBSET
26  CHARACTER*4 BUFR
27  CHARACTER*1 TAB
28  dimension mesg(*)
29 
30  DATA bufr/'BUFR'/
31 
32 C-----------------------------------------------------------------------
33 C-----------------------------------------------------------------------
34 
35 C GET THE MESSAGE TAG AND TYPE, AND BREAK UP THE DATE
36 C ---------------------------------------------------
37 
38 c .... Given SUBSET, NEMTBA returns MTYP,MSBT,INOD
39  CALL nemtba(lun,subset,mtyp,msbt,inod)
40  CALL nemtab(lun,subset,isub,tab,iret)
41  IF(iret.EQ.0) GOTO 900
42 
43 C DATE CAN BE YYMMDDHH OR YYYYMMDDHH
44 C ----------------------------------
45 
46  jdate = i4dy(idate)
47  mcen = mod(jdate/10**8,100)+1
48  mear = mod(jdate/10**6,100)
49  mmon = mod(jdate/10**4,100)
50  mday = mod(jdate/10**2,100)
51  mour = mod(jdate ,100)
52  mmin = 0
53 
54 c .... DK: Don't think this can happen, because IDATE=0 is returned
55 c as 2000000000 by I4DY meaning MCEN would be 21
56  IF(mcen.EQ.1) GOTO 901
57 
58  IF(mear.EQ.0) mcen = mcen-1
59  IF(mear.EQ.0) mear = 100
60 
61 C INITIALIZE THE MESSAGE
62 C ----------------------
63 
64  mbit = 0
65 
66 C SECTION 0
67 C ---------
68 
69  CALL pkc(bufr , 4 , mesg,mbit)
70 
71 C NOTE THAT THE ACTUAL SECTION 0 LENGTH WILL BE COMPUTED AND
72 C STORED BELOW; FOR NOW, WE ARE REALLY ONLY INTERESTED IN
73 C ADVANCING MBIT BY THE CORRECT AMOUNT, SO WE'LL JUST STORE
74 C A DEFAULT VALUE OF 0.
75 
76  CALL pkb( 0 , 24 , mesg,mbit)
77  CALL pkb( 3 , 8 , mesg,mbit)
78 
79 C SECTION 1
80 C ---------
81 
82  len1 = 18
83 
84  CALL pkb(len1 , 24 , mesg,mbit)
85  CALL pkb( 0 , 8 , mesg,mbit)
86  CALL pkb( 3 , 8 , mesg,mbit)
87  CALL pkb( 7 , 8 , mesg,mbit)
88  CALL pkb( 0 , 8 , mesg,mbit)
89  CALL pkb( 0 , 8 , mesg,mbit)
90  CALL pkb(mtyp , 8 , mesg,mbit)
91  CALL pkb(msbt , 8 , mesg,mbit)
92  CALL pkb( 36 , 8 , mesg,mbit)
93  CALL pkb( 0 , 8 , mesg,mbit)
94  CALL pkb(mear , 8 , mesg,mbit)
95  CALL pkb(mmon , 8 , mesg,mbit)
96  CALL pkb(mday , 8 , mesg,mbit)
97  CALL pkb(mour , 8 , mesg,mbit)
98  CALL pkb(mmin , 8 , mesg,mbit)
99  CALL pkb(mcen , 8 , mesg,mbit)
100 
101 C SECTION 3
102 C ---------
103 
104  len3 = 10
105 
106  CALL pkb(len3 , 24 , mesg,mbit)
107  CALL pkb( 0 , 8 , mesg,mbit)
108  CALL pkb(nsub , 16 , mesg,mbit)
109  CALL pkb( 192 , 8 , mesg,mbit)
110  CALL pkb(isub , 16 , mesg,mbit)
111  CALL pkb( 0 , 8 , mesg,mbit)
112 
113 C SECTION 4
114 C ---------
115 
116 C STORE THE TOTAL LENGTH OF SECTION 4.
117 
118 C REMEMBER THAT THE INPUT VALUE OF NBYT ONLY CONTAINS THE
119 C LENGTH OF THE "COMPRESSED DATA PORTION" OF SECTION 4, SO
120 C WE NEED TO ADD FOUR BYTES TO THIS NUMBER IN ORDER TO
121 C ACCOUNT FOR THE TOTAL LENGTH OF SECTION 4.
122 
123  CALL pkb((nbyt+4) , 24 , mesg,mbit)
124  CALL pkb( 0 , 8 , mesg,mbit)
125 
126 C THE ACTUAL "COMPRESSED DATA PORTION" OF SECTION 4 WILL
127 C BE FILLED IN LATER BY SUBROUTINE WRCMPS.
128 
129 C SECTION 5
130 C ---------
131 
132 C THIS SECTION WILL BE FILLED IN LATER BY SUBROUTINE WRCMPS.
133 
134 C RETURN WITH THE CORRECT NEW MESSAGE BYTE COUNT
135 C ----------------------------------------------
136 
137 C NOW, NOTING THAT MBIT CURRENTLY POINTS TO THE LAST BIT OF
138 C THE FOURTH BYTE OF SECTION 4, THEN WE HAVE:
139 C (TOTAL LENGTH OF BUFR MESSAGE (IN SECTION 0)) =
140 C (LENGTH OF MESSAGE UP THROUGH FOURTH BYTE OF SECTION 4)
141 C + (LENGTH OF "COMPRESSED DATA PORTION" OF SECTION 4)
142 C + (LENGTH OF SECTION 5)
143  mbyt =
144  . mbit/8
145  . + nbyt
146  . + 4
147 
148 C NOW, MAKE NBYT POINT TO THE CURRENT LOCATION OF MBIT
149 C (I.E. THE BYTE AFTER WHICH TO ACTUALLY BEGIN WRITING THE
150 C COMPRESSED DATA INTO SECTION 4).
151 
152  nbyt = mbit/8
153 
154 C NOW, STORE THE TOTAL LENGTH OF THE BUFR MESSAGE (IN SECTION 0).
155 
156  mbit = 32
157  CALL pkb(mbyt,24,mesg,mbit)
158 
159 C EXITS
160 C -----
161 
162  RETURN
163 900 WRITE(bort_str,'("BUFRLIB: CMSGINI - TABLE A MESSAGE TYPE '//
164  . 'MNEMONIC ",A," NOT FOUND IN INTERNAL TABLE D ARRAYS")') subset
165  CALL bort(bort_str)
166 901 CALL bort
167  . ('BUFRLIB: CMSGINI - BUFR MESSAGE DATE (IDATE) is 0000000000')
168  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine cmsgini(LUN, MESG, SUBSET, IDATE, NSUB, NBYT)
This subroutine initializes a new BUFR message for output in compressed format.
Definition: cmsgini.f:23
recursive function i4dy(IDATE)
This function converts a date-time with a 2-digit year (YYMMDDHH) to a date-time with a 4-digit year ...
Definition: i4dy.f:24
subroutine nemtab(LUN, NEMO, IDN, TAB, IRET)
Get information about a descriptor, based on the mnemonic.
Definition: nemtab.f:29
subroutine nemtba(LUN, NEMO, MTYP, MSBT, INOD)
This subroutine searches for a descriptor within Table A of the internal DX BUFR tables.
Definition: nemtba.f:25
subroutine pkb(NVAL, NBITS, IBAY, IBIT)
This subroutine encodes an integer value within a specified number of bits of an integer array,...
Definition: pkb.f:28
subroutine pkc(CHR, NCHR, IBAY, IBIT)
Encode a character string within an integer array.
Definition: pkc.f:31