NCEPLIBS-bufr  11.6.0
 All Data Structures Files Functions Variables Pages
rdcmps.f
Go to the documentation of this file.
1 C> @file
2 C> @author WOOLLEN @date 2000-09-19
3 
4 C> THIS SUBROUTINE UNCOMPRESSES AND UNPACKS THE NEXT SUBSET
5 C> FROM THE INTERNAL COMPRESSED MESSAGE BUFFER (ARRAY MBAY IN MODULE
6 C> BITBUF) AND STORES THE UNPACKED SUBSET WITHIN THE INTERNAL
7 C> ARRAY VAL(*,LUN) IN MODULE USRINT.
8 C>
9 C> PROGRAM HISTORY LOG:
10 C> 2000-09-19 J. WOOLLEN -- ORIGINAL AUTHOR
11 C> 2002-05-14 J. WOOLLEN -- IMPROVED GENERALITY, PREVIOUSLY RDCMPS
12 C> WOULD NOT RECOGNIZE COMPRESSED DELAYED
13 C> REPLICATION AS A LEGITIMATE DATA STRUCTURE
14 C> 2003-11-04 J. ATOR -- ADDED DOCUMENTATION
15 C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
16 C> INTERDEPENDENCIES
17 C> 2003-11-04 D. KEYSER -- MAXJL (MAXIMUM NUMBER OF JUMP/LINK ENTRIES)
18 C> INCREASED FROM 15000 TO 16000 (WAS IN
19 C> VERIFICATION VERSION); UNIFIED/PORTABLE FOR
20 C> WRF; ADDED HISTORY DOCUMENTATION
21 C> 2004-08-18 J. ATOR -- INITIALIZE CVAL TO EMPTY BEFORE CALLING UPC;
22 C> CORRECT LOGIC FOR WHEN A CHARACTER VALUE IS
23 C> THE SAME FOR ALL SUBSETS IN A MESSAGE;
24 C> MAXIMUM MESSAGE LENGTH INCREASED FROM
25 C> 20,000 TO 50,000 BYTES
26 C> 2009-03-23 J. ATOR -- PREVENT OVERFLOW OF CVAL AND CREF FOR
27 C> STRINGS LONGER THAN 8 CHARACTERS
28 C> 2012-03-02 J. ATOR -- USE FUNCTION UPS
29 C> 2012-06-04 J. ATOR -- SET DECODED REAL*8 VALUE TO "MISSING" WHEN
30 C> CORRESPONDING CHARACTER FIELD HAS ALL BITS
31 C> SET TO 1
32 C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
33 C>
34 C> USAGE: CALL RDCMPS (LUN)
35 C> INPUT ARGUMENT LIST:
36 C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
37 C>
38 C> REMARKS:
39 C> THIS ROUTINE CALLS: BORT ICBFMS IGETRFEL STRBTM
40 C> UPB UPC UPS USRTPL
41 C> THIS ROUTINE IS CALLED BY: READSB
42 C> Normally not called by any application
43 C> programs.
44 C>
45  SUBROUTINE rdcmps(LUN)
46 
47  USE modv_bmiss
48 
49  USE moda_usrint
50  USE moda_msgcwd
51  USE moda_bitbuf
52  USE moda_tables
53  USE moda_rlccmn
54 
55  CHARACTER*128 bort_str
56  CHARACTER*8 cref,cval
57  equivalence(cval,rval)
58  REAL*8 rval,ups
59 
60 C-----------------------------------------------------------------------
61 C Statement function to compute BUFR "missing value" for field
62 C of length LBIT bits (all bits "on"):
63 
64  lps(lbit) = max(2**(lbit)-1,1)
65 C-----------------------------------------------------------------------
66 
67 C SETUP THE SUBSET TEMPLATE
68 C -------------------------
69 
70  CALL usrtpl(lun,1,1)
71 
72 C UNCOMPRESS A SUBSET INTO THE VAL ARRAY ACCORDING TO TABLE B
73 C -----------------------------------------------------------
74 
75  nsbs = nsub(lun)
76 
77 C Note that we are going to unpack the (NSBS)th subset from within
78 C the current BUFR message.
79 
80  ibit = mbyt(lun)
81  nrst = 0
82 
83 C Loop through each element of the subset.
84 
85  n = 0
86 
87 1 DO n=n+1,nval(lun)
88  node = inv(n,lun)
89  nrfelm(n,lun) = igetrfel(n,lun)
90  nbit = ibt(node)
91  ityp = itp(node)
92 
93 C In each of the following code blocks, the "local reference value"
94 C for the element is determined first, followed by the 6-bit value
95 C which indicates how many bits are used to store the increment
96 C (i.e. offset) from this "local reference value". Then, we jump
97 C ahead to where this increment is stored for this particular subset,
98 C unpack it, and add it to the "local reference value" to determine
99 C the final uncompressed value for this element from this subset.
100 
101 C Note that, if an element has the same final uncompressed value
102 C for each subset in the message, then the encoding rules for BUFR
103 C compression dictate that the "local reference value" will be equal
104 C to this value, the 6-bit increment length indicator will have
105 C a value of zero, and the actual increments themselves will be
106 C omitted from the message.
107 
108  IF(ityp.EQ.1.OR.ityp.EQ.2) THEN
109 
110 C This is a numeric element.
111 
112  CALL upb(lref,nbit,mbay(1,lun),ibit)
113  CALL upb(linc, 6,mbay(1,lun),ibit)
114  jbit = ibit + linc*(nsbs-1)
115  CALL upb(ninc,linc,mbay(1,lun),jbit)
116  IF(ninc.EQ.lps(linc)) THEN
117  ival = lps(nbit)
118  ELSE
119  ival = lref+ninc
120  ENDIF
121  IF(ityp.EQ.1) THEN
122  CALL usrtpl(lun,n,ival)
123  goto 1
124  ENDIF
125  IF(ival.LT.lps(nbit)) val(n,lun) = ups(ival,node)
126  CALL strbtm(n,lun)
127  ibit = ibit + linc*msub(lun)
128  ELSEIF(ityp.EQ.3) THEN
129 
130 C This is a character element. If there are more than 8
131 C characters, then only the first 8 will be unpacked by this
132 C routine, and a separate subsequent call to BUFR archive library
133 C subroutine READLC will be required to unpack the remainder of
134 C the string. In this case, pointers will be saved within
135 C COMMON /RLCCMN/ for later use within READLC.
136 
137 C Unpack the local reference value.
138 
139  lelm = nbit/8
140  nchr = min(8,lelm)
141  ibsv = ibit
142  cref = ' '
143  CALL upc(cref,nchr,mbay(1,lun),ibit,.true.)
144  IF(lelm.GT.8) THEN
145  ibit = ibit + (lelm-8)*8
146  nrst = nrst + 1
147  IF(nrst.GT.mxrst) goto 900
148  crtag(nrst) = tag(node)
149  ENDIF
150 
151 C Unpack the increment length indicator. For character elements,
152 C this length is in bytes rather than bits.
153 
154  CALL upb(linc, 6,mbay(1,lun),ibit)
155  IF(linc.EQ.0) THEN
156  IF(lelm.GT.8) THEN
157  irnch(nrst) = lelm
158  irbit(nrst) = ibsv
159  ENDIF
160  cval = cref
161  ELSE
162  jbit = ibit + linc*(nsbs-1)*8
163  IF(lelm.GT.8) THEN
164  irnch(nrst) = linc
165  irbit(nrst) = jbit
166  ENDIF
167  nchr = min(8,linc)
168  cval = ' '
169  CALL upc(cval,nchr,mbay(1,lun),jbit,.true.)
170  ENDIF
171  IF (lelm.LE.8 .AND. icbfms(cval,nchr).NE.0) THEN
172  val(n,lun) = bmiss
173  ELSE
174  val(n,lun) = rval
175  ENDIF
176  ibit = ibit + 8*linc*msub(lun)
177  ENDIF
178  ENDDO
179 
180  RETURN
181 900 WRITE(bort_str,'("BUFRLIB: RDCMPS - NUMBER OF LONG CHARACTER ' //
182  . 'STRINGS EXCEEDS THE LIMIT (",I4,")")') mxrst
183  CALL bort(bort_str)
184  END
subroutine upb(NVAL, NBITS, IBAY, IBIT)
THIS SUBROUTINE UNPACKS AND RETURNS A BINARY INTEGER CONTAINED WITHIN NBITS BITS OF IBAY...
Definition: upb.f:49
INTEGER function icbfms(STR, LSTR)
This function provides a handy way to check whether a character string returned from a previous call ...
Definition: icbfms.f:31
subroutine strbtm(N, LUN)
THIS SUBROUTINE STORES INTERNAL INFORMATION IN MODULE BITMAPS IF THE INPUT ELEMENT IS PART OF A BITMA...
Definition: strbtm.f:21
subroutine usrtpl(LUN, INVN, NBMP)
THIS SUBROUTINE STORES THE SUBSET TEMPLATE INTO INTERNAL SUBSET ARRAYS IN MODULE USRINT FOR CASES OF ...
Definition: usrtpl.f:51
This module declares and initializes the BMISS variable.
Definition: modv_BMISS.f90:9
subroutine upc(CHR, NCHR, IBAY, IBIT, CNVNULL)
THIS SUBROUTINE UNPACKS AND RETURNS A CHARACTER STRING OF LENGTH NCHR CONTAINED WITHIN NCHR BYTES OF ...
Definition: upc.f:49
This module contains array and variable declarations used to store the internal jump/link table...
Definition: moda_tables.F:13
subroutine rdcmps(LUN)
THIS SUBROUTINE UNCOMPRESSES AND UNPACKS THE NEXT SUBSET FROM THE INTERNAL COMPRESSED MESSAGE BUFFER ...
Definition: rdcmps.f:45
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22
INTEGER function igetrfel(N, LUN)
THIS FUNCTION CHECKS WHETHER THE INPUT ELEMENT REFERS TO A PREVIOUS ELEMENT WITHIN THE SAME SUBSET VI...
Definition: igetrfel.f:35
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
REAL *8 function ups(IVAL, NODE)
THIS FUNCTION UNPACKS A REAL*8 USER VALUE FROM A PACKED BUFR INTEGER BY APPLYING THE PROPER SCALE AND...
Definition: ups.f:31