NCEPLIBS-bufr 11.7.1
rdtree.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 1994-01-06
3
4C> THIS SUBROUTINE UNPACKS THE NEXT SUBSET FROM THE INTERNAL
5C> UNCOMPRESSED MESSAGE BUFFER (ARRAY MBAY IN MODULE BITBUF) AND
6C> STORES THE UNPACKED SUBSET WITHIN THE INTERNAL ARRAY VAL(*,LUN)
7C> IN MODULE USRINT.
8C>
9C> PROGRAM HISTORY LOG:
10C> 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
11C> 1998-10-27 J. WOOLLEN -- MODIFIED TO CORRECT PROBLEMS CAUSED BY IN-
12C> LINING CODE WITH FPP DIRECTIVES
13C> 1999-11-18 J. WOOLLEN -- THE NUMBER OF BUFR FILES WHICH CAN BE
14C> OPENED AT ONE TIME INCREASED FROM 10 TO 32
15C> (NECESSARY IN ORDER TO PROCESS MULTIPLE
16C> BUFR FILES UNDER THE MPI)
17C> 2000-09-19 J. WOOLLEN -- MAXIMUM MESSAGE LENGTH INCREASED FROM
18C> 10,000 TO 20,000 BYTES
19C> 2003-11-04 J. WOOLLEN -- FIXED A BUG WHICH COULD ONLY OCCUR WHEN
20C> THE LAST ELEMENT IN A SUBSET IS A CHARACTER
21C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
22C> INTERDEPENDENCIES
23C> 2003-11-04 D. KEYSER -- MAXJL (MAXIMUM NUMBER OF JUMP/LINK ENTRIES)
24C> INCREASED FROM 15000 TO 16000 (WAS IN
25C> VERIFICATION VERSION); UNIFIED/PORTABLE FOR
26C> WRF; ADDED DOCUMENTATION (INCLUDING
27C> HISTORY)
28C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
29C> 20,000 TO 50,000 BYTES
30C> 2007-01-19 J. ATOR -- PREVENT OVERFLOW OF CVAL FOR STRINGS LONGER
31C> THAN 8 CHARACTERS
32C> 2012-03-02 J. ATOR -- USE FUNCTION UPS
33C> 2012-06-04 J. ATOR -- SET DECODED REAL*8 VALUE TO "MISSING" WHEN
34C> CORRESPONDING CHARACTER FIELD HAS ALL BITS
35C> SET TO 1
36C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
37C> 2016-11-09 J. ATOR -- ADDED IRET ARGUMENT AND CHECK FOR POSSIBLY
38C> CORRUPT SUBSETS
39C> 2022-05-06 J. WOOLLEN -- REPLACE UPBB WITH UPB8 FOR 8BYTE INTEGERS
40C>
41C> USAGE: CALL RDTREE (LUN,IRET)
42C> INPUT ARGUMENT LIST:
43C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
44C>
45C> OUTPUT ARGUMENT LIST:
46C> IRET - INTEGER: RETURN CODE:
47C> 0 = NORMAL RETURN
48C> -1 = AN ERROR OCCURRED, POSSIBLY DUE TO A
49C> CORRUPT SUBSET IN THE INPUT MESSAGE
50C>
51C> REMARKS:
52C> THIS ROUTINE CALLS: RCSTPL ICBFMS UPB8 UPC
53C> UPS
54C> THIS ROUTINE IS CALLED BY: READSB
55C> Normally not called by any application
56C> programs.
57C>
58 SUBROUTINE rdtree(LUN,IRET)
59
60 USE modv_bmiss
61 USE moda_usrint
62 USE moda_usrbit
63 USE moda_ival
64 USE moda_bitbuf
65 USE moda_tables
66
67 CHARACTER*8 CVAL
68 equivalence(cval,rval)
69 real*8 rval,ups
70
71C-----------------------------------------------------------------------
72C-----------------------------------------------------------------------
73
74 iret = 0
75
76C CYCLE THROUGH A SUBSET SETTING UP THE TEMPLATE
77C ----------------------------------------------
78
79 mbit(1) = ibit
80 nbit(1) = 0
81 CALL rcstpl(lun,ier)
82 IF(ier.NE.0) THEN
83 iret = -1
84 RETURN
85 ENDIF
86
87C UNPACK A SUBSET INTO THE USER ARRAY IVAL
88C ----------------------------------------
89
90 DO n=1,nval(lun)
91 CALL upb8(ival(n),nbit(n),mbit(n),mbay(1,lun))
92 ENDDO
93
94C LOOP THROUGH EACH ELEMENT OF THE SUBSET, CONVERTING THE UNPACKED
95C VALUES TO THE PROPER TYPES
96C ----------------------------------------------------------------
97
98 DO n=1,nval(lun)
99 node = inv(n,lun)
100 IF(itp(node).EQ.1) THEN
101
102C The unpacked value is a delayed descriptor replication factor.
103
104 val(n,lun) = ival(n)
105 ELSEIF(itp(node).EQ.2) THEN
106
107C The unpacked value is a real.
108
109 IF (ival(n).LT.2_8**ibt(node)-1) THEN
110 val(n,lun) = ups(ival(n),node)
111 ELSE
112 val(n,lun) = bmiss
113 ENDIF
114 ELSEIF(itp(node).EQ.3) THEN
115
116C The value is a character string, so unpack it using an
117C equivalenced REAL*8 value. Note that a maximum of 8 characters
118C will be unpacked here, so a separate subsequent call to BUFR
119C archive library subroutine READLC will be needed to fully
120C unpack any string longer than 8 characters.
121
122 cval = ' '
123 kbit = mbit(n)
124 nbt = min(8,nbit(n)/8)
125 CALL upc(cval,nbt,mbay(1,lun),kbit,.true.)
126 IF (nbit(n).LE.64 .AND. icbfms(cval,nbt).NE.0) THEN
127 val(n,lun) = bmiss
128 ELSE
129 val(n,lun) = rval
130 ENDIF
131 ENDIF
132 ENDDO
133
134 ibit = nbit(nval(lun))+mbit(nval(lun))
135
136 RETURN
137 END
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:32
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:26
This module contains array and variable declarations used to store the internal jump/link table.
Definition: moda_tables.F:13
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
Definition: moda_tables.F:141
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
Definition: moda_tables.F:138
This module declares and initializes the BMISS variable.
Definition: modv_BMISS.f90:9
real *8, public bmiss
Current placeholder value to represent "missing" data when reading from or writing to BUFR files; thi...
Definition: modv_BMISS.f90:15
subroutine rcstpl(LUN, IRET)
THIS SUBROUTINE STORES THE SUBSET TEMPLATE INTO INTERNAL SUBSET ARRAYS IN MODULES USRINT AND USRBIT.
Definition: rcstpl.f:60
subroutine rdtree(LUN, IRET)
THIS SUBROUTINE UNPACKS THE NEXT SUBSET FROM THE INTERNAL UNCOMPRESSED MESSAGE BUFFER (ARRAY MBAY IN ...
Definition: rdtree.f:59
subroutine upb8(nval, nbits, ibit, ibay)
THIS SUBROUTINE UNPACKS AND RETURNS AN 8-BYTE INTEGER CONTAINED WITHIN NBITS BITS OF IBAY,...
Definition: upb8.f:36
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:50
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:33