NCEPLIBS-bufr  12.0.0
msgini.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Initialize a new uncompressed BUFR message for output.
3 C>
4 C> @author Woollen @date 1994-01-06
5 
6 C> This subroutine initializes, within the internal arrays, a new
7 C> uncompressed BUFR message for output. Arrays are filled in common blocks
8 C> msgptr and modules @ref moda_msgcwd and @ref moda_bitbuf.
9 C>
10 C> @param[in] LUN - integer: I/O stream index into internal memory arrays.
11 C>
12 C> @author Woollen @date 1994-01-06
13  SUBROUTINE msgini(LUN)
14 
15  USE moda_msgcwd
16  USE moda_ufbcpl
17  USE moda_bitbuf
18  USE moda_tables
19 
20  COMMON /padesc/ ibct,ipd1,ipd2,ipd3,ipd4
21  COMMON /msgptr/ nby0,nby1,nby2,nby3,nby4,nby5
22 
23  CHARACTER*128 BORT_STR
24  CHARACTER*8 SUBTAG
25  CHARACTER*4 BUFR,SEVN
26  CHARACTER*1 TAB
27 
28  DATA bufr/'BUFR'/
29  DATA sevn/'7777'/
30 
31 C-----------------------------------------------------------------------
32 C-----------------------------------------------------------------------
33 
34 C GET THE MESSAGE TAG AND TYPE, AND BREAK UP THE DATE
35 C ---------------------------------------------------
36 
37  subtag = tag(inode(lun))(1:8)
38 c .... Given SUBSET, NEMTBA returns MTYP,MSBT,INOD
39  CALL nemtba(lun,subtag,mtyp,msbt,inod)
40  IF(inode(lun).NE.inod) GOTO 900
41  CALL nemtab(lun,subtag,isub,tab,iret)
42  IF(iret.EQ.0) GOTO 901
43 
44 C DATE CAN BE YYMMDDHH OR YYYYMMDDHH
45 C ----------------------------------
46 
47  mcen = mod(idate(lun)/10**8,100)+1
48  mear = mod(idate(lun)/10**6,100)
49  mmon = mod(idate(lun)/10**4,100)
50  mday = mod(idate(lun)/10**2,100)
51  mour = mod(idate(lun) ,100)
52  mmin = 0
53 
54 c .... DK: Can this happen?? (investigate)
55  IF(mcen.EQ.1) GOTO 902
56 
57  IF(mear.EQ.0) mcen = mcen-1
58  IF(mear.EQ.0) mear = 100
59 
60 C INITIALIZE THE MESSAGE
61 C ----------------------
62 
63  mbit = 0
64  nby0 = 8
65  nby1 = 18
66  nby2 = 0
67  nby3 = 20
68  nby4 = 4
69  nby5 = 4
70  nbyt = nby0+nby1+nby2+nby3+nby4+nby5
71 
72 C SECTION 0
73 C ---------
74 
75  CALL pkc(bufr , 4 , mbay(1,lun),mbit)
76  CALL pkb(nbyt , 24 , mbay(1,lun),mbit)
77  CALL pkb( 3 , 8 , mbay(1,lun),mbit)
78 
79 C SECTION 1
80 C ---------
81 
82  CALL pkb(nby1 , 24 , mbay(1,lun),mbit)
83  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
84  CALL pkb( 3 , 8 , mbay(1,lun),mbit)
85  CALL pkb( 7 , 8 , mbay(1,lun),mbit)
86  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
87  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
88  CALL pkb(mtyp , 8 , mbay(1,lun),mbit)
89  CALL pkb(msbt , 8 , mbay(1,lun),mbit)
90  CALL pkb( 36 , 8 , mbay(1,lun),mbit)
91  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
92  CALL pkb(mear , 8 , mbay(1,lun),mbit)
93  CALL pkb(mmon , 8 , mbay(1,lun),mbit)
94  CALL pkb(mday , 8 , mbay(1,lun),mbit)
95  CALL pkb(mour , 8 , mbay(1,lun),mbit)
96  CALL pkb(mmin , 8 , mbay(1,lun),mbit)
97  CALL pkb(mcen , 8 , mbay(1,lun),mbit)
98 
99 C SECTION 3
100 C ---------
101 
102  CALL pkb(nby3 , 24 , mbay(1,lun),mbit)
103  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
104  CALL pkb( 0 , 16 , mbay(1,lun),mbit)
105  CALL pkb(2**7 , 8 , mbay(1,lun),mbit)
106  CALL pkb(ibct , 16 , mbay(1,lun),mbit)
107  CALL pkb(isub , 16 , mbay(1,lun),mbit)
108  CALL pkb(ipd1 , 16 , mbay(1,lun),mbit)
109  CALL pkb(ipd2 , 16 , mbay(1,lun),mbit)
110  CALL pkb(ipd3 , 16 , mbay(1,lun),mbit)
111  CALL pkb(ipd4 , 16 , mbay(1,lun),mbit)
112  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
113 
114 C SECTION 4
115 C ---------
116 
117  CALL pkb(nby4 , 24 , mbay(1,lun),mbit)
118  CALL pkb( 0 , 8 , mbay(1,lun),mbit)
119 
120 C SECTION 5
121 C ---------
122 
123  CALL pkc(sevn , 4 , mbay(1,lun),mbit)
124 
125 C DOUBLE CHECK INITIAL MESSAGE LENGTH
126 C -----------------------------------
127 
128  IF(mod(mbit,8).NE.0) GOTO 903
129  IF(mbit/8.NE.nbyt ) GOTO 904
130 
131  nmsg(lun) = nmsg(lun)+1
132  nsub(lun) = 0
133  mbyt(lun) = nbyt
134 
135  luncpy(lun)=0
136 
137 C EXITS
138 C -----
139 
140  RETURN
141 900 WRITE(bort_str,'("BUFRLIB: MSGINI - MISMATCH BETWEEN INODE (=",'//
142  . 'I7,") & POSITIONAL INDEX, INOD (",I7,") OF SUBTAG (",A,") IN '//
143  . 'DICTIONARY")') inode(lun),inod,subtag
144  CALL bort(bort_str)
145 901 WRITE(bort_str,'("BUFRLIB: MSGINI - TABLE A MESSAGE TYPE '//
146  . 'MNEMONIC ",A," NOT FOUND IN INTERNAL TABLE D ARRAYS")') subtag
147  CALL bort(bort_str)
148 902 CALL bort
149  . ('BUFRLIB: MSGINI - BUFR MESSAGE DATE (IDATE) is 0000000000')
150 903 CALL bort('BUFRLIB: MSGINI - INITIALIZED MESSAGE DOES NOT END '//
151  . 'ON A BYTE BOUNDARY')
152 904 WRITE(bort_str,'("BUFRLIB: MSGINI - NUMBER OF BYTES STORED FOR '//
153  . 'INITIALIZED MESSAGE (",I6,") IS NOT THE SAME AS FIRST '//
154  . 'CALCULATED, NBYT (",I6)') mbit/8,nbyt
155  CALL bort(bort_str)
156  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine msgini(LUN)
This subroutine initializes, within the internal arrays, a new uncompressed BUFR message for output.
Definition: msgini.f:14
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
integer, dimension(:), allocatable idate
Section 1 date-time of message.
integer, dimension(:), allocatable nmsg
Current message pointer within logical unit.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
This module contains array and variable declarations used to store the internal jump/link table.
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.
This module contains an array declaration used to store, for each I/O stream index,...
integer, dimension(:), allocatable luncpy
Logical unit numbers used to copy long character strings between BUFR data subsets.
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