NCEPLIBS-bufr  12.0.0
rdtree.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read the next uncompressed BUFR data subset into internal arrays.
3 C>
4 C> @author Woollen @date 1994-01-06
5 
6 C> This subroutine unpacks the next subset from the internal
7 c> uncompressed message buffer (array mbay in module @ref moda_bitbuf) and
8 c> stores the unpacked subset within the internal array val(*,lun)
9 c> in module @ref moda_usrint.
10 C>
11 C> @param[in] LUN - integer: I/O stream index into internal memory arrays.
12 C> @param[out] IRET - integer: return code:
13 C> - 0 normal return
14 C> - -1 An error occurred, possibly due to a corrupt subset in the input message.
15 C>
16 C> @author Woollen @date 1994-01-06
17  SUBROUTINE rdtree(LUN,IRET)
18 
19  USE modv_bmiss
20  USE moda_usrint
21  USE moda_usrbit
22  USE moda_ival
23  USE moda_bitbuf
24  USE moda_tables
25 
26  CHARACTER*8 CVAL
27  equivalence(cval,rval)
28  real*8 rval,ups
29 
30 C-----------------------------------------------------------------------
31 C-----------------------------------------------------------------------
32 
33  iret = 0
34 
35 C CYCLE THROUGH A SUBSET SETTING UP THE TEMPLATE
36 C ----------------------------------------------
37 
38  mbit(1) = ibit
39  nbit(1) = 0
40  CALL rcstpl(lun,ier)
41  IF(ier.NE.0) THEN
42  iret = -1
43  RETURN
44  ENDIF
45 
46 C UNPACK A SUBSET INTO THE USER ARRAY IVAL
47 C ----------------------------------------
48 
49  DO n=1,nval(lun)
50  CALL upb8(ival(n),nbit(n),mbit(n),mbay(1,lun))
51  ENDDO
52 
53 C LOOP THROUGH EACH ELEMENT OF THE SUBSET, CONVERTING THE UNPACKED
54 C VALUES TO THE PROPER TYPES
55 C ----------------------------------------------------------------
56 
57  DO n=1,nval(lun)
58  node = inv(n,lun)
59  IF(itp(node).EQ.1) THEN
60 
61 C The unpacked value is a delayed descriptor replication factor.
62 
63  val(n,lun) = ival(n)
64  ELSEIF(itp(node).EQ.2) THEN
65 
66 C The unpacked value is a real.
67 
68  IF (ival(n).LT.2_8**ibt(node)-1) THEN
69  val(n,lun) = ups(ival(n),node)
70  ELSE
71  val(n,lun) = bmiss
72  ENDIF
73  ELSEIF(itp(node).EQ.3) THEN
74 
75 C The value is a character string, so unpack it using an
76 C equivalenced REAL*8 value. Note that a maximum of 8 characters
77 C will be unpacked here, so a separate subsequent call to BUFR
78 C archive library subroutine READLC will be needed to fully
79 C unpack any string longer than 8 characters.
80 
81  cval = ' '
82  kbit = mbit(n)
83  nbt = min(8,nbit(n)/8)
84  CALL upc(cval,nbt,mbay(1,lun),kbit,.true.)
85  IF (nbit(n).LE.64 .AND. icbfms(cval,nbt).NE.0) THEN
86  val(n,lun) = bmiss
87  ELSE
88  val(n,lun) = rval
89  ENDIF
90  ENDIF
91  ENDDO
92 
93  ibit = nbit(nval(lun))+mbit(nval(lun))
94 
95  RETURN
96  END
recursive function icbfms(STR, LSTR)
This function provides a handy way to check whether a character string returned from a previous call ...
Definition: icbfms.f:25
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer ibit
Bit pointer within IBAY.
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
This module contains a declaration for an array used to pack or unpack all of the values of a BUFR da...
integer(8), dimension(:), allocatable ival
BUFR data subset values.
This module contains array and variable declarations used to store the internal jump/link table.
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
This module contains array declarations for internal storage of pointers to BUFR data subset values.
integer, dimension(:), allocatable nbit
Length (in bits) of each packed data value in data subset.
integer, dimension(:), allocatable mbit
Pointer in data subset to first bit of each packed data value.
This module contains declarations for arrays used to store data values and associated metadata for th...
integer, dimension(:), allocatable nval
Number of data values in BUFR data subset.
real *8, dimension(:,:), allocatable, target val
Data values.
integer, dimension(:,:), allocatable, target inv
Inventory pointer which links each data value to its corresponding node in the internal jump/link tab...
This module declares and initializes the BMISS variable.
Definition: modules_vars.F90:9
real *8, public bmiss
Current placeholder value to represent "missing" data when reading from or writing to BUFR files; thi...
subroutine rcstpl(LUN, IRET)
This subroutine initializes space in internal subset array space (inv and val) in modules moda_usrint...
Definition: rcstpl.f:18
subroutine rdtree(LUN, IRET)
This subroutine unpacks the next subset from the internal uncompressed message buffer (array mbay in ...
Definition: rdtree.f:18
subroutine upb8(nval, nbits, ibit, ibay)
This subroutine decodes an 8-byte integer value from within a specified number of bits of an integer ...
Definition: upb8.f:26
subroutine upc(CHR, NCHR, IBAY, IBIT, CNVNULL)
Decode a character string from an integer array.
Definition: upc.f:32
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:22