NCEPLIBS-bufr  12.0.0
ufbinx.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 2003-11-04
5 
6 C> Read one or more data values from a data subset.
7 C>
8 C> If logical unit LUNIT has already been opened for input operations
9 C> via a previous call to subroutine openbf(), then this subroutine
10 C> will save the current file position, rewind the file to the
11 C> beginning, reposition the file to a specified data subset
12 C> within a specified message, read one or more specified data values
13 C> from that data subset via an internal call to ufbint(), and then
14 C> restore the file to its previous position.
15 C>
16 C> Otherwise, if logical unit LUNIT has not already been opened for
17 C> input operations via a previous call to subroutine openbf(),
18 C> then this subroutine will open it via an internal call to
19 C> subroutine openbf(), position the file to a specified data subset
20 C> within a specified message, read one or more specified data values
21 C> from that data subset via an internal call to ufbint(), and then
22 C> close the file via an internal call to subroutine closbf().
23 C>
24 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
25 C> @param[in] IMSG - integer: Number of BUFR message to be read from
26 C> the BUFR file, counting from the beginning of the file, but <b>not</b>
27 C> counting any DX BUFR table messages which may be present in the file
28 C> @param[in] ISUB - integer: Number of data subset to be read from
29 C> read from the (IMSG)th BUFR message, counting from the beginning of
30 C> the message
31 C> @param[out] USR - real*8(*,*): Data values
32 C> @param[in] I1 - integer: First dimension of USR as allocated within the
33 C> calling program
34 C> @param[in] I2 - integer: Second dimension of USR as allocated within the
35 C> calling program
36 C> @param[out] IRET - integer: Number of replications of STR that were read
37 C> from the data subset
38 C> @param[in] STR - character*(*): string of blank-separated Table B
39 C> mnemonics in one-to-one correspondence with the number of data values
40 C> that will be read from the data subset into the first dimension of USR
41 C>
42 C> @author Woollen @date 2003-11-04
43  RECURSIVE SUBROUTINE ufbinx(LUNIT,IMSG,ISUB,USR,I1,I2,IRET,STR)
44 
45  USE modv_im8b
46 
47  USE moda_msgcwd
48  USE moda_bitbuf
49 
50  CHARACTER*(*) str
51  CHARACTER*128 bort_str
52  CHARACTER*8 subset
53  LOGICAL openit
54  real*8 usr(i1,i2)
55 
56 C-----------------------------------------------------------------------
57 C-----------------------------------------------------------------------
58 
59 C CHECK FOR I8 INTEGERS
60 C ---------------------
61 
62  IF(im8b) THEN
63  im8b=.false.
64 
65  CALL x84(lunit,my_lunit,1)
66  CALL x84(imsg,my_imsg,1)
67  CALL x84(isub,my_isub,1)
68  CALL x84(i1,my_i1,1)
69  CALL x84(i2,my_i2,1)
70  CALL ufbinx(my_lunit,my_imsg,my_isub,usr,my_i1,my_i2,iret,str)
71  CALL x48(iret,iret,1)
72 
73  im8b=.true.
74  RETURN
75  ENDIF
76 
77  CALL status(lunit,lun,il,im)
78  openit = il.EQ.0
79 
80  IF(openit) THEN
81 
82 C OPEN BUFR FILE CONNECTED TO UNIT LUNIT IF IT IS NOT ALREADY OPEN
83 C ----------------------------------------------------------------
84 
85  CALL openbf(lunit,'INX',lunit)
86  ELSE
87 
88 C IF BUFR FILE ALREADY OPENED, SAVE POSITION & REWIND TO FIRST DATA MSG
89 C ---------------------------------------------------------------------
90 
91  CALL rewnbf(lunit,0)
92  ENDIF
93 
94 C SKIP TO MESSAGE # IMSG
95 C ----------------------
96 
97 C Note that we need to use subroutine READMG to actually read in all
98 C of the messages (including the first (IMSG-1) messages!), just in
99 C case there are any embedded dictionary messages in the file.
100 
101  DO i=1,imsg
102  CALL readmg(lunit,subset,jdate,jret)
103  IF(jret.LT.0) GOTO 901
104  ENDDO
105 
106 C POSITION AT SUBSET # ISUB
107 C -------------------------
108 
109  DO i=1,isub-1
110  IF(nsub(lun).GT.msub(lun)) GOTO 902
111  ibit = mbyt(lun)*8
112  CALL upb(nbyt,16,mbay(1,lun),ibit)
113  mbyt(lun) = mbyt(lun) + nbyt
114  nsub(lun) = nsub(lun) + 1
115  ENDDO
116 
117  CALL readsb(lunit,jret)
118  IF(jret.NE.0) GOTO 902
119 
120  CALL ufbint(lunit,usr,i1,i2,iret,str)
121 
122  IF(openit) THEN
123 
124 C CLOSE BUFR FILE IF IT WAS OPENED HERE
125 C -------------------------------------
126 
127  CALL closbf(lunit)
128  ELSE
129 
130 
131 C RESTORE BUFR FILE TO PREV. STATUS & POSITION IF NOT ORIG. OPENED HERE
132 C ---------------------------------------------------------------------
133 
134  CALL rewnbf(lunit,1)
135  ENDIF
136 
137 C EXITS
138 C -----
139 
140  RETURN
141 901 WRITE(bort_str,'("BUFRLIB: UFBINX - HIT END OF FILE BEFORE '//
142  . 'READING REQUESTED MESSAGE NO.",I5," IN BUFR FILE CONNECTED TO'//
143  . ' UNIT",I4)') imsg,lunit
144  CALL bort(bort_str)
145 902 WRITE(bort_str,'("BUFRLIB: UFBINX - ALL SUBSETS READ BEFORE '//
146  . 'READING REQ. SUBSET NO.",I3," IN REQ. MSG NO.",I5," IN BUFR '//
147  . 'FILE CONNECTED TO UNIT",I4)') isub,imsg,lunit
148  CALL bort(bort_str)
149  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine closbf(LUNIT)
Close the connection between logical unit LUNIT and the NCEPLIBS-bufr software.
Definition: closbf.f:24
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.
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 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 openbf(LUNIT, IO, LUNDX)
Connects a new file to the NCEPLIBS-bufr software for input or output operations, or initializes the ...
Definition: openbf.f:124
recursive subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
Reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays.
Definition: readmg.f:52
recursive subroutine readsb(LUNIT, IRET)
Read the next data subset from a BUFR message.
Definition: readsb.f:33
subroutine rewnbf(LUNIT, ISR)
This subroutine, depending on the value of ISR, will either:
Definition: rewnbf.f:38
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
recursive subroutine ufbint(LUNIN, USR, I1, I2, IRET, STR)
Read/write one or more data values from/to a data subset.
Definition: ufbint.f:121
recursive subroutine ufbinx(LUNIT, IMSG, ISUB, USR, I1, I2, IRET, STR)
Read one or more data values from a data subset.
Definition: ufbinx.f:44
subroutine upb(NVAL, NBITS, IBAY, IBIT)
This subroutine decodes an integer value from within a specified number of bits of an integer array,...
Definition: upb.f:28
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