NCEPLIBS-bufr 11.7.1
ufbinx.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 2003-11-04
3
4C> THIS SUBROUTINE EITHER OPENS A BUFR FILE CONNECTED TO
5C> LOGICAL UNIT LUNIT FOR INPUT OPERATIONS (IF IT IS NOT ALREADY
6C> OPENED AS SUCH), OR SAVES ITS POSITION AND REWINDS IT TO THE FIRST
7C> DATA MESSAGE (IF BUFR FILE ALREADY OPENED), THEN (VIA A CALL TO
8C> BUFR ARCHIVE LIBRARY SUBROUTINE UFBINT) READS SPECIFIED VALUES FROM
9C> INTERNAL SUBSET ARRAYS ASSOCIATED WITH A PARTICULAR SUBSET FROM A
10C> PARTICULAR BUFR MESSAGE IN A MESSAGE BUFFER. THE PARTICULAR SUBSET
11C> AND BUFR MESSAGE ARE BASED BASED ON THE SUBSET NUMBER IN THE
12C> MESSAGE AND THE MESSAGE NUMBER IN THE BUFR FILE. FINALLY, THIS
13C> SUBROUTINE EITHER CLOSES THE BUFR FILE IN LUNIT (IF IS WAS OPENED
14C> HERE) OR RESTORES IT TO ITS PREVIOUS READ/WRITE STATUS AND POSITION
15C> (IF IT WAS NOT OPENED HERE). SEE UFBINT FOR MORE INFORMATION ON
16C> THE READING OF VALUES OUT OF A BUFR MESSAGE SUBSET. NOTE: THE
17C> MESSAGE NUMBER HERE DOES NOT INCLUDE THE DICTIONARY MESSAGES AT THE
18C> BEGINNING OF THE FILE.
19C>
20C> PROGRAM HISTORY LOG:
21C> 2003-11-04 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN VERIFICATION
22C> VERSION BUT MAY HAVE BEEN IN THE PRODUCTION
23C> VERSION AT ONE TIME AND THEN REMOVED)
24C> 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED
25C> DOCUMENTATION; OUTPUTS MORE COMPLETE
26C> DIAGNOSTIC INFO WHEN ROUTINE TERMINATES
27C> ABNORMALLY
28C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
29C> 20,000 TO 50,000 BYTES
30C> 2009-03-23 J. ATOR -- MODIFY LOGIC TO HANDLE BUFR TABLE MESSAGES
31C> ENCOUNTERED ANYWHERE IN THE FILE (AND NOT
32C> JUST AT THE BEGINNING!)
33C> 2012-09-15 J. WOOLLEN -- MODIFIED FOR C/I/O/BUFR INTERFACE
34C> USE 'INX' ARGUMENT TO OPENBF
35C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
36C>
37C> USAGE: CALL UFBINX (LUNIT, IMSG, ISUB, USR, I1, I2, IRET, STR)
38C> INPUT ARGUMENT LIST:
39C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
40C> IMSG - INTEGER: POINTER TO BUFR MESSAGE NUMBER TO READ IN
41C> BUFR FILE
42C> ISUB - INTEGER: POINTER TO SUBSET NUMBER TO READ IN BUFR
43C> MESSAGE
44C> I1 - INTEGER: LENGTH OF FIRST DIMENSION OF USR (MUST BE AT
45C> LEAST AS LARGE AS THE NUMBER OF BLANK-SEPARATED
46C> MNEMONICS IN STR)
47C> I2 - INTEGER: LENGTH OF SECOND DIMENSION OF USR
48C> STR - CHARACTER*(*): STRING OF BLANK-SEPARATED TABLE B
49C> MNEMONICS IN ONE-TO-ONE CORRESPONDENCE WITH FIRST
50C> DIMENSION OF USR {THIS CAN ALSO BE A SINGLE TABLE D
51C> (SEQUENCE) MNEMONIC WITH EITHER 8- OR 16-BIT DELAYED
52C> REPLICATION (SEE REMARKS 1 IN UFBINT DOCBLOCK)}
53C>
54C> OUTPUT ARGUMENT LIST:
55C> USR - REAL*8: (I1,I2) STARTING ADDRESS OF DATA VALUES READ
56C> FROM DATA SUBSET
57C> IRET - INTEGER: NUMBER OF "LEVELS" OF DATA VALUES READ FROM
58C> DATA SUBSET (MUST BE NO LARGER THAN I2)
59C>
60C> INPUT FILES:
61C> UNIT "LUNIT" - BUFR FILE
62C>
63C> REMARKS:
64C> THIS ROUTINE CALLS: BORT CLOSBF OPENBF READMG
65C> READSB REWNBF STATUS UFBINT
66C> UPB
67C> THIS ROUTINE IS CALLED BY: None
68C> Normally called only by application
69C> programs.
70C>
71 SUBROUTINE ufbinx(LUNIT,IMSG,ISUB,USR,I1,I2,IRET,STR)
72
73 USE moda_msgcwd
74 USE moda_bitbuf
75
76 CHARACTER*(*) STR
77 CHARACTER*128 BORT_STR
78 CHARACTER*8 SUBSET
79 LOGICAL OPENIT
80 real*8 usr(i1,i2)
81
82C-----------------------------------------------------------------------
83C-----------------------------------------------------------------------
84
85 CALL status(lunit,lun,il,im)
86 openit = il.EQ.0
87
88 IF(openit) THEN
89
90C OPEN BUFR FILE CONNECTED TO UNIT LUNIT IF IT IS NOT ALREADY OPEN
91C ----------------------------------------------------------------
92
93 CALL openbf(lunit,'INX',lunit)
94 ELSE
95
96C IF BUFR FILE ALREADY OPENED, SAVE POSITION & REWIND TO FIRST DATA MSG
97C ---------------------------------------------------------------------
98
99 CALL rewnbf(lunit,0)
100 ENDIF
101
102C SKIP TO MESSAGE # IMSG
103C ----------------------
104
105C Note that we need to use subroutine READMG to actually read in all
106C of the messages (including the first (IMSG-1) messages!), just in
107C case there are any embedded dictionary messages in the file.
108
109 DO i=1,imsg
110 CALL readmg(lunit,subset,jdate,jret)
111 IF(jret.LT.0) GOTO 901
112 ENDDO
113
114C POSITION AT SUBSET # ISUB
115C -------------------------
116
117 DO i=1,isub-1
118 IF(nsub(lun).GT.msub(lun)) GOTO 902
119 ibit = mbyt(lun)*8
120 CALL upb(nbyt,16,mbay(1,lun),ibit)
121 mbyt(lun) = mbyt(lun) + nbyt
122 nsub(lun) = nsub(lun) + 1
123 ENDDO
124
125 CALL readsb(lunit,jret)
126 IF(jret.NE.0) GOTO 902
127
128 CALL ufbint(lunit,usr,i1,i2,iret,str)
129
130 IF(openit) THEN
131
132C CLOSE BUFR FILE IF IT WAS OPENED HERE
133C -------------------------------------
134
135 CALL closbf(lunit)
136 ELSE
137
138
139C RESTORE BUFR FILE TO PREV. STATUS & POSITION IF NOT ORIG. OPENED HERE
140C ---------------------------------------------------------------------
141
142 CALL rewnbf(lunit,1)
143 ENDIF
144
145C EXITS
146C -----
147
148 RETURN
149901 WRITE(bort_str,'("BUFRLIB: UFBINX - HIT END OF FILE BEFORE '//
150 . 'READING REQUESTED MESSAGE NO.",I5," IN BUFR FILE CONNECTED TO'//
151 . ' UNIT",I4)') imsg,lunit
152 CALL bort(bort_str)
153902 WRITE(bort_str,'("BUFRLIB: UFBINX - ALL SUBSETS READ BEFORE '//
154 . 'READING REQ. SUBSET NO.",I3," IN REQ. MSG NO.",I5," IN BUFR '//
155 . 'FILE CONNECTED TO UNIT",I4)') isub,imsg,lunit
156 CALL bort(bort_str)
157 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.f:35
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:25
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:26
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:139
subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
This subroutine reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays.
Definition: readmg.f:74
subroutine readsb(LUNIT, IRET)
This subroutine reads the next data subset from a BUFR message into internal arrays.
Definition: readsb.f:48
subroutine rewnbf(LUNIT, ISR)
THIS SUBROUTINE, DEPENDING ON THE VALUE OF ISR, WILL EITHER: 1) STORE THE CURRENT PARAMETERS ASSOCIAT...
Definition: rewnbf.f:65
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:56
subroutine ufbint(LUNIN, USR, I1, I2, IRET, STR)
This subroutine reads or writes one or more data values from or to the BUFR data subset that is curre...
Definition: ufbint.f:153
subroutine ufbinx(LUNIT, IMSG, ISUB, USR, I1, I2, IRET, STR)
THIS SUBROUTINE EITHER OPENS A BUFR FILE CONNECTED TO LOGICAL UNIT LUNIT FOR INPUT OPERATIONS (IF IT ...
Definition: ufbinx.f:72
subroutine upb(NVAL, NBITS, IBAY, IBIT)
THIS SUBROUTINE UNPACKS AND RETURNS A BINARY INTEGER CONTAINED WITHIN NBITS BITS OF IBAY,...
Definition: upb.f:50