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