NCEPLIBS-bufr  12.0.0
ufbevn.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read one or more data values from an NCEP prepbufr file.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Read one or more data values from an NCEP prepbufr file.
7 C>
8 C> This subroutine reads one or more data values from the BUFR data
9 C> subset that is currently open within the BUFRLIB internal arrays.
10 C> It is specifically designed for use with NCEP prepbufr files,
11 C> which contain a third dimension of data events for every
12 C> reported data value at every replicated vertical level. It is
13 C> similar to subroutine ufbin3(), except that ufbin3() is used
14 C> for NCEP prepfits files and has one extra argument containing
15 C> the maximum number of data events for any data value, whereas
16 C> this subroutine is used for NCEP prepbufr files and stores the
17 C> same information internally within a COMMON block.
18 C>
19 C> It is the user's responsibility to ensure that USR is dimensioned
20 C> sufficiently large enough to accommodate the number of data values
21 C> that are to be read from the data subset. Note also
22 C> that USR is an array of real*8 values; therefore, any
23 C> character (i.e. CCITT IA5) value in the data subset will be
24 C> returned in real*8 format and must be converted back into character
25 C> format by the application program before it can be used as such.
26 C>
27 C> "Missing" values in USR are always denoted by a unique
28 C> placeholder value. This placeholder value is initially set
29 C> to a default value of 10E10_8, but it can be reset to
30 C> any substitute value of the user's choice via a separate
31 C> call to subroutine setbmiss(). In any case, any
32 C> returned value in USR can be easily checked for equivalence to the
33 C> current placeholder value via a call to function ibfms(), and a
34 C> positive result means that the value for the corresponding mnemonic
35 C> was encoded as "missing" in BUFR (i.e. all bits set to 1) within the
36 C> original data subset.
37 C>
38 C> @param[in] LUNIT - integer: Fortran logical unit number for
39 C> NCEP prepbufr file.
40 C> @param[out] USR - real*8(*,*): Data values.
41 C> @param[in] I1 - integer: First dimension of USR as allocated
42 C> within the calling program.
43 C> @param[in] I2 - integer: Second dimension of USR as allocated
44 C> within the calling program.
45 C> @param[in] I3 - integer: Third dimension of USR as allocated
46 C> within the calling program.
47 C> @param[out] IRET - integer: Number of replications of STR that were
48 C> read from the data subset, corresponding to the second dimension of USR.
49 C> @param[in] STR - character*(*): String of blank-separated Table B
50 C> mnemonics in one-to-one correspondence with the number of data
51 C> values that will be read from the data subset within the first
52 C> dimension of USR (see [DX BUFR Tables](@ref dfbftab) for further
53 C> information about Table B mnemonics).
54 C>
55 C> @author J. Woollen @date 1994-01-06
56  RECURSIVE SUBROUTINE ufbevn(LUNIT,USR,I1,I2,I3,IRET,STR)
57 
58  USE modv_im8b
59  USE modv_bmiss
60 
61  USE moda_usrint
62  USE moda_msgcwd
63 
64  COMMON /usrstr/ nnod,ncon,nods(20),nodc(10),ivls(10),kons(10)
65  COMMON /ufbn3c/ maxevn
66  COMMON /quiet / iprt
67 
68  CHARACTER*(*) str
69  CHARACTER*128 errstr
70  dimension invn(255)
71  real*8 usr(i1,i2,i3)
72 
73 C----------------------------------------------------------------------
74 C----------------------------------------------------------------------
75 
76 C CHECK FOR I8 INTEGERS
77 C ---------------------
78 
79  IF(im8b) THEN
80  im8b=.false.
81 
82  CALL x84(lunit,my_lunit,1)
83  CALL x84(i1,my_i1,1)
84  CALL x84(i2,my_i2,1)
85  CALL x84(i3,my_i3,1)
86  CALL ufbevn(my_lunit,usr,my_i1,my_i2,my_i3,iret,str)
87  CALL x48(iret,iret,1)
88 
89  im8b=.true.
90  RETURN
91  ENDIF
92 
93  maxevn = 0
94  iret = 0
95 
96 C CHECK THE FILE STATUS AND I-NODE
97 C --------------------------------
98 
99  CALL status(lunit,lun,il,im)
100  IF(il.EQ.0) GOTO 900
101  IF(il.GT.0) GOTO 901
102  IF(im.EQ.0) GOTO 902
103  IF(inode(lun).NE.inv(1,lun)) GOTO 903
104 
105  IF(i1.LE.0) THEN
106  IF(iprt.GE.0) THEN
107  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
108  errstr = .LE.'BUFRLIB: UFBEVN - 3rd ARG. (INPUT) IS 0, ' //
109  . 'SO RETURN WITH 6th ARG. (IRET) = 0; 7th ARG. (STR) ='
110  CALL errwrt(errstr)
111  CALL errwrt(str)
112  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
113  CALL errwrt(' ')
114  ENDIF
115  GOTO 100
116  ELSEIF(i2.LE.0) THEN
117  IF(iprt.GE.0) THEN
118  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
119  errstr = .LE.'BUFRLIB: UFBEVN - 4th ARG. (INPUT) IS 0, ' //
120  . 'SO RETURN WITH 6th ARG. (IRET) = 0; 7th ARG. (STR) ='
121  CALL errwrt(errstr)
122  CALL errwrt(str)
123  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
124  CALL errwrt(' ')
125  ENDIF
126  GOTO 100
127  ELSEIF(i3.LE.0) THEN
128  IF(iprt.GE.0) THEN
129  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
130  errstr = .LE.'BUFRLIB: UFBEVN - 5th ARG. (INPUT) IS 0, ' //
131  . 'SO RETURN WITH 6th ARG. (IRET) = 0; 7th ARG. (STR) ='
132  CALL errwrt(errstr)
133  CALL errwrt(str)
134  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
135  CALL errwrt(' ')
136  ENDIF
137  GOTO 100
138  ENDIF
139 
140 C PARSE OR RECALL THE INPUT STRING
141 C --------------------------------
142 
143  CALL string(str,lun,i1,0)
144 
145 C INITIALIZE USR ARRAY
146 C --------------------
147 
148  DO k=1,i3
149  DO j=1,i2
150  DO i=1,i1
151  usr(i,j,k) = bmiss
152  ENDDO
153  ENDDO
154  ENDDO
155 
156 C LOOP OVER COND WINDOWS
157 C ----------------------
158 
159  inc1 = 1
160  inc2 = 1
161 
162 1 CALL conwin(lun,inc1,inc2)
163  IF(nnod.EQ.0) THEN
164  iret = i2
165  GOTO 100
166  ELSEIF(inc1.EQ.0) THEN
167  GOTO 100
168  ELSE
169  DO i=1,nnod
170  IF(nods(i).GT.0) THEN
171  ins2 = inc1
172  CALL getwin(nods(i),lun,ins1,ins2)
173  IF(ins1.EQ.0) GOTO 100
174  GOTO 2
175  ENDIF
176  ENDDO
177  ins1 = inc1
178  ins2 = inc2
179  ENDIF
180 
181 C READ PUSH DOWN STACK DATA INTO 3D ARRAYS
182 C ----------------------------------------
183 
184 2 iret = iret+1
185  IF(iret.LE.i2) THEN
186  DO i=1,nnod
187  IF(nods(i).GT.0) THEN
188  nnvn = nvnwin(nods(i),lun,ins1,ins2,invn,i3)
189  maxevn = max(nnvn,maxevn)
190  DO n=1,nnvn
191  usr(i,iret,n) = val(invn(n),lun)
192  ENDDO
193  ENDIF
194  ENDDO
195  ENDIF
196 
197 C DECIDE WHAT TO DO NEXT
198 C ----------------------
199 
200  CALL nxtwin(lun,ins1,ins2)
201  IF(ins1.GT.0 .AND. ins1.LT.inc2) GOTO 2
202  IF(ncon.GT.0) GOTO 1
203 
204  IF(iret.EQ.0) THEN
205  IF(iprt.GE.1) THEN
206  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
207  errstr = 'BUFRLIB: UFBEVN - NO SPECIFIED VALUES READ IN, ' //
208  . 'SO RETURN WITH 6th ARG. (IRET) = 0; 7th ARG. (STR) ='
209  CALL errwrt(errstr)
210  CALL errwrt(str)
211  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
212  CALL errwrt(' ')
213  ENDIF
214  ENDIF
215 
216 C EXITS
217 C -----
218 
219 100 RETURN
220 900 CALL bort('BUFRLIB: UFBEVN - INPUT BUFR FILE IS CLOSED, IT MUST'//
221  . ' BE OPEN FOR INPUT')
222 901 CALL bort('BUFRLIB: UFBEVN - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
223  . ', IT MUST BE OPEN FOR INPUT')
224 902 CALL bort('BUFRLIB: UFBEVN - A MESSAGE MUST BE OPEN IN INPUT '//
225  . 'BUFR FILE, NONE ARE')
226 903 CALL bort('BUFRLIB: UFBEVN - LOCATION OF INTERNAL TABLE FOR '//
227  . 'INPUT BUFR FILE DOES NOT AGREE WITH EXPECTED LOCATION IN '//
228  . 'INTERNAL SUBSET ARRAY')
229  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine conwin(LUN, INC1, INC2)
This subroutine searches consecutive subset buffer segments for an element identified in the user str...
Definition: conwin.f:38
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
subroutine getwin(NODE, LUN, IWIN, JWIN)
Given a node index within the internal jump/link table, this subroutine looks within the current subs...
Definition: getwin.f:48
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
This module contains declarations for arrays used to store data values and associated metadata for th...
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...
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 ...
function nvnwin(NODE, LUN, INV1, INV2, INVN, NMAX)
This function looks for and returns all occurrences of a specified node within the portion of the cur...
Definition: nvnwin.f:24
subroutine nxtwin(LUN, IWIN, JWIN)
Given indices within the internal jump/link table which point to the start and end of an "rpc" window...
Definition: nxtwin.f:24
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 ufbevn(LUNIT, USR, I1, I2, I3, IRET, STR)
Read one or more data values from an NCEP prepbufr file.
Definition: ufbevn.f:57
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