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