NCEPLIBS-bufr  12.0.0
ufbget.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read one or more data values from a data subset.
3 C>
4 C> @author Woollen @date 1994-01-06
5 
6 C> Read one or more data values from a data subset.
7 C>
8 C> This subroutine unpacks and returns the values for one-dimensional
9 C> descriptors in the input string without advancing the subset pointer.
10 C>
11 C> @param[in] LUNIT - integer: fortran logical unit number for BUFR file.
12 C> @param[out] TAB - real*8(*): data values.
13 C> @param[in] I1 - integer: size of TAB as allocated within the calling program.
14 C> @param[out] IRET - integer: return code:
15 C> - 0 normal return.
16 C> - -1 there are no more subsets in the BUFR message.
17 C> @param[in] STR - character*(*): string of blank-separated Table B
18 C> mnemonics in one-to-one correspondence with the number of data values
19 C> that will be read from the data subset into TAB.
20 C>
21 C> @author Woollen @date 1994-01-06
22  RECURSIVE SUBROUTINE ufbget(LUNIT,TAB,I1,IRET,STR)
23 
24  USE modv_bmiss
25  USE modv_im8b
26 
27  USE moda_usrint
28  USE moda_usrbit
29  USE moda_msgcwd
30  USE moda_bitbuf
31  USE moda_tables
32 
33  COMMON /usrstr/ nnod,ncon,nods(20),nodc(10),ivls(10),kons(10)
34 
35  CHARACTER*(*) str
36  CHARACTER*8 cval
37  equivalence(cval,rval)
38  INTEGER*8 ival
39  real*8 rval,tab(i1),ups
40 
41 C-----------------------------------------------------------------------
42 C-----------------------------------------------------------------------
43 
44 C CHECK FOR I8 INTEGERS
45 C ---------------------
46 
47  IF(im8b) THEN
48  im8b=.false.
49 
50  CALL x84(lunit,my_lunit,1)
51  CALL x84(i1,my_i1,1)
52  CALL ufbget(my_lunit,tab,my_i1,iret,str)
53  CALL x48(iret,iret,1)
54 
55  im8b=.true.
56  RETURN
57  ENDIF
58 
59  iret = 0
60 
61  DO i=1,i1
62  tab(i) = bmiss
63  ENDDO
64 
65 C MAKE SURE A FILE/MESSAGE IS OPEN FOR INPUT
66 C ------------------------------------------
67 
68  CALL status(lunit,lun,il,im)
69  IF(il.EQ.0) GOTO 900
70  IF(il.GT.0) GOTO 901
71  IF(im.EQ.0) GOTO 902
72 
73 C SEE IF THERE IS ANOTHER SUBSET IN THE MESSAGE
74 C ---------------------------------------------
75 
76  IF(nsub(lun).EQ.msub(lun)) THEN
77  iret = -1
78  GOTO 100
79  ENDIF
80 
81 C PARSE THE STRING
82 C ----------------
83 
84  CALL string(str,lun,i1,0)
85 
86 C EXPAND THE TEMPLATE FOR THIS SUBSET AS LITTLE AS POSSIBLE
87 C ---------------------------------------------------------
88 
89  n = 1
90  nbit(n) = 0
91  mbit(n) = mbyt(lun)*8 + 16
92  CALL usrtpl(lun,n,n)
93 
94 10 DO n=n+1,nval(lun)
95  node = inv(n,lun)
96  nbit(n) = ibt(node)
97  mbit(n) = mbit(n-1)+nbit(n-1)
98  IF(node.EQ.nods(nnod)) THEN
99  nval(lun) = n
100  GOTO 20
101  ELSEIF(itp(node).EQ.1) THEN
102  CALL upb8(ival,nbit(n),mbit(n),mbay(1,lun))
103  nbmp=int(ival)
104  CALL usrtpl(lun,n,nbmp)
105  GOTO 10
106  ENDIF
107  ENDDO
108 20 CONTINUE
109 
110 C UNPACK ONLY THE NODES FOUND IN THE STRING
111 C -----------------------------------------
112 
113  DO i=1,nnod
114  node = nods(i)
115  invn = invwin(node,lun,1,nval(lun))
116  IF(invn.GT.0) THEN
117  CALL upb8(ival,nbit(invn),mbit(invn),mbay(1,lun))
118  IF(itp(node).EQ.1) THEN
119  tab(i) = ival
120  ELSEIF(itp(node).EQ.2) THEN
121  IF(ival.LT.2_8**(ibt(node))-1) tab(i) = ups(ival,node)
122  ELSEIF(itp(node).EQ.3) THEN
123  cval = ' '
124  kbit = mbit(invn)
125  CALL upc(cval,nbit(invn)/8,mbay(1,lun),kbit,.true.)
126  tab(i) = rval
127  ENDIF
128  ELSE
129  tab(i) = bmiss
130  ENDIF
131  ENDDO
132 
133 C EXITS
134 C -----
135 
136 100 RETURN
137 900 CALL bort('BUFRLIB: UFBGET - INPUT BUFR FILE IS CLOSED, IT MUST'//
138  . ' BE OPEN FOR INPUT')
139 901 CALL bort('BUFRLIB: UFBGET - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
140  . ', IT MUST BE OPEN FOR INPUT')
141 902 CALL bort('BUFRLIB: UFBGET - A MESSAGE MUST BE OPEN IN INPUT '//
142  . 'BUFR FILE, NONE ARE')
143  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
function invwin(NODE, LUN, INV1, INV2)
This function looks for a specified node within the portion of the current subset buffer bounded by t...
Definition: invwin.f:22
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 msub
Total number of data subsets in message.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
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.
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...
This module declares and initializes the IM8B variable.
logical, public im8b
Status indicator to keep track of whether all future calls to BUFRLIB subroutines and functions from ...
recursive subroutine status(LUNIT, LUN, IL, IM)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
Definition: status.f:36
subroutine string(STR, LUN, I1, IO)
This subroutine checks to see if a user-specified character string is in the string cache (arrays in ...
Definition: string.f:28
recursive subroutine ufbget(LUNIT, TAB, I1, IRET, STR)
Read one or more data values from a data subset.
Definition: ufbget.f:23
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
subroutine usrtpl(LUN, INVN, NBMP)
Store the subset template into internal arrays.
Definition: usrtpl.f:22
subroutine x48(IIN4, IOUT8, NVAL)
Encode one or more 4-byte integer values as 8-byte integer values.
Definition: x48.F:19
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19