NCEPLIBS-bufr  12.0.1
ufbrw.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read/write one or more data values from/to a data subset.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> This subroutine writes or reads specified values to or from
7 C> the current BUFR data subset within internal arrays, with the
8 C> direction of the data transfer determined by the context of IO.
9 C> The data values correspond to internal arrays representing parsed
10 C> strings of mnemonics which are part of a delayed-replication
11 C> sequence, or for which there is no replication at all.
12 C>
13 C> This subroutine should never be directly called by an application
14 C> program; instead, an application program should directly call ufbint()
15 C> which will internally call this subroutine.
16 C>
17 C> @param[in] LUN - integer: I/O stream index into internal memory arrays.
18 C> @param[inout] USR - real*8(*,*): Data values
19 C> @param[in] I1 - integer: length of first dimension of USR.
20 C> @param[in] I2 - integer: length of second dimension of USR.
21 C> @param[in] IO - integer: status indicator for BUFR file associated
22 C> with LUN:
23 C> - 0 input file
24 C> - 1 output file
25 C> @param[out] IRET - integer: number of "levels" of data values read
26 C> from or written to data subset
27 C> - -1 none of the mnemonics in the string passed to ufbint() were found
28 C> in the data subset template
29 C>
30 C> @author J. Woollen @date 1994-01-06
31  SUBROUTINE ufbrw(LUN,USR,I1,I2,IO,IRET)
32 
33  USE modv_bmiss
34  USE moda_usrint
35  USE moda_tables
36 
37  COMMON /usrstr/ nnod,ncon,nods(20),nodc(10),ivls(10),kons(10)
38  COMMON /quiet / iprt
39 
40  CHARACTER*128 ERRSTR
41  real*8 usr(i1,i2)
42 
43 C----------------------------------------------------------------------
44 C----------------------------------------------------------------------
45 
46  iret = 0
47 
48 C LOOP OVER COND WINDOWS
49 C ----------------------
50 
51  inc1 = 1
52  inc2 = 1
53 
54 1 CALL conwin(lun,inc1,inc2)
55  IF(nnod.EQ.0) THEN
56  iret = i2
57  GOTO 100
58  ELSEIF(inc1.EQ.0) THEN
59  GOTO 100
60  ELSE
61  DO i=1,nnod
62  IF(nods(i).GT.0) THEN
63  ins2 = inc1
64  CALL getwin(nods(i),lun,ins1,ins2)
65  IF(ins1.EQ.0) GOTO 100
66  GOTO 2
67  ENDIF
68  ENDDO
69  iret = -1
70  GOTO 100
71  ENDIF
72 
73 C LOOP OVER STORE NODES
74 C ---------------------
75 
76 2 iret = iret+1
77 
78  IF(iprt.GE.2) THEN
79  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
80  WRITE ( unit=errstr, fmt='(5(A,I7))' )
81  . 'BUFRLIB: UFBRW - IRET:INS1:INS2:INC1:INC2 = ',
82  . iret, ':', ins1, ':', ins2, ':', inc1, ':', inc2
83  CALL errwrt(errstr)
84  kk = ins1
85  DO WHILE ( ( ins2 - kk ) .GE. 5 )
86  WRITE ( unit=errstr, fmt='(5A10)' )
87  . (tag(inv(i,lun)),i=kk,kk+4)
88  CALL errwrt(errstr)
89  kk = kk+5
90  ENDDO
91  WRITE ( unit=errstr, fmt='(5A10)' )
92  . (tag(inv(i,lun)),i=kk,ins2)
93  CALL errwrt(errstr)
94  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
95  CALL errwrt(' ')
96  ENDIF
97 
98 C WRITE USER VALUES
99 C -----------------
100 
101  IF(io.EQ.1 .AND. iret.LE.i2) THEN
102  DO i=1,nnod
103  IF(nods(i).GT.0) THEN
104  IF(ibfms(usr(i,iret)).EQ.0) THEN
105  invn = invwin(nods(i),lun,ins1,ins2)
106  IF(invn.EQ.0) THEN
107  CALL drstpl(nods(i),lun,ins1,ins2,invn)
108  IF(invn.EQ.0) THEN
109  iret = 0
110  GOTO 100
111  ENDIF
112  CALL newwin(lun,inc1,inc2)
113  val(invn,lun) = usr(i,iret)
114  ELSEIF(lstjpb(nods(i),lun,'RPS').EQ.0) THEN
115  val(invn,lun) = usr(i,iret)
116  ELSEIF(ibfms(val(invn,lun)).NE.0) THEN
117  val(invn,lun) = usr(i,iret)
118  ELSE
119  CALL drstpl(nods(i),lun,ins1,ins2,invn)
120  IF(invn.EQ.0) THEN
121  iret = 0
122  GOTO 100
123  ENDIF
124  CALL newwin(lun,inc1,inc2)
125  val(invn,lun) = usr(i,iret)
126  ENDIF
127  ENDIF
128  ENDIF
129  ENDDO
130  ENDIF
131 
132 C READ USER VALUES
133 C ----------------
134 
135  IF(io.EQ.0 .AND. iret.LE.i2) THEN
136  DO i=1,nnod
137  usr(i,iret) = bmiss
138  IF(nods(i).GT.0) THEN
139  invn = invwin(nods(i),lun,ins1,ins2)
140  IF(invn.GT.0) usr(i,iret) = val(invn,lun)
141  ENDIF
142  ENDDO
143  ENDIF
144 
145 C DECIDE WHAT TO DO NEXT
146 C ----------------------
147 
148  IF(io.EQ.1.AND.iret.EQ.i2) GOTO 100
149  CALL nxtwin(lun,ins1,ins2)
150  IF(ins1.GT.0 .AND. ins1.LT.inc2) GOTO 2
151  IF(ncon.GT.0) GOTO 1
152 
153 C EXIT
154 C ----
155 
156 100 RETURN
157  END
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 drstpl(INOD, LUN, INV1, INV2, INVN)
This subroutine is called by subroutine ufbrw() whenever it can't find a mnemonic it wants to write w...
Definition: drstpl.f:32
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
integer function ibfms(R8VAL)
Test whether a real*8 data value is "missing".
Definition: ibfms.f:28
function invwin(NODE, LUN, INV1, INV2)
This function looks for a specified node within the portion of the current subset buffer bounded by t...
Definition: invwin.f:22
function lstjpb(NODE, LUN, JBTYP)
This function searches backwards, beginning from a given node within the jump/link table,...
Definition: lstjpb.f:30
This module contains array and variable declarations used to store the internal jump/link table.
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.
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...
subroutine newwin(LUN, IWIN, JWIN)
Given an index within the internal jump/link table which points to the start of an "rpc" window (whic...
Definition: newwin.f:22
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
subroutine ufbrw(LUN, USR, I1, I2, IO, IRET)
This subroutine writes or reads specified values to or from the current BUFR data subset within inter...
Definition: ufbrw.f:32