NCEPLIBS-bufr  12.0.1
usrtpl.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Store the subset template into internal arrays.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Store the subset template into internal arrays.
7 C>
8 C> This subroutine stores the subset template into internal
9 C> subset arrays in module @ref moda_usrint for cases of node expansion,
10 C> such as when the node is either a Table A mnemonic or a delayed
11 C> replication factor.
12 C>
13 C> @param[in] LUN - integer: File ID.
14 C> @param[in] INVN - integer: Starting jump/link table index of the node
15 C> to be expanded within the subset template.
16 C> @param[in] NBMP - integer: Number of times by which INVN is to be
17 C> expanded (i.e. number of replications of node).
18 C>
19 C> @author J. Woollen @date 1994-01-06
20 
21  SUBROUTINE usrtpl(LUN,INVN,NBMP)
22 
23  USE modv_maxjl
24  USE modv_maxss
25 
26  USE moda_usrint
27  USE moda_msgcwd
28  USE moda_tables
29  USE moda_ivttmp
30  use moda_stcode
31 
32  COMMON /quiet / iprt
33 
34  CHARACTER*128 BORT_STR,ERRSTR
35  LOGICAL DRP,DRS,DRB,DRX
36 
37 C-----------------------------------------------------------------------
38 C-----------------------------------------------------------------------
39 
40  IF(iprt.GE.2) THEN
41  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
42  WRITE ( unit=errstr, fmt='(A,I3,A,I7,A,I5,A,A10)' )
43  . 'BUFRLIB: USRTPL - LUN:INVN:NBMP:TAG(INODE(LUN)) = ',
44  . lun, ':', invn, ':', nbmp, ':', tag(inode(lun))
45  CALL errwrt(errstr)
46  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
47  CALL errwrt(' ')
48  ENDIF
49 
50  IF(nbmp.LE.0) THEN
51  IF(iprt.GE.1) THEN
52  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
53  CALL errwrt(.LE.'BUFRLIB: USRTPL - NBMP 0 - IMMEDIATE RETURN')
54  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
55  CALL errwrt(' ')
56  ENDIF
57  GOTO 100
58  ENDIF
59 
60  drp = .false.
61  drs = .false.
62  drx = .false.
63 
64 C SET UP A NODE EXPANSION
65 C -----------------------
66 
67  IF(invn.EQ.1) THEN
68 c .... case where node is a Table A mnemonic (nodi is positional index)
69  nodi = inode(lun)
70  inv(1,lun) = nodi
71  nval(lun) = 1
72  IF(nbmp.NE.1) GOTO 900
73  ELSEIF(invn.GT.0 .AND. invn.LE.nval(lun)) THEN
74 c .... case where node is (hopefully) a delayed replication factor
75  nodi = inv(invn,lun)
76  drp = typ(nodi) .EQ. 'DRP'
77  drs = typ(nodi) .EQ. 'DRS'
78  drb = typ(nodi) .EQ. 'DRB'
79  drx = drp .OR. drs .OR. drb
80  ival = nint(val(invn,lun))
81  jval = 2**ibt(nodi)-1
82  val(invn,lun) = ival+nbmp
83  IF(drb.AND.nbmp.NE.1) GOTO 901
84  IF(.NOT.drx ) GOTO 902
85  IF(ival.LT.0. ) GOTO 903
86  IF(ival+nbmp.GT.jval) GOTO 904
87  ELSE
88  GOTO 905
89  ENDIF
90 
91 C RECALL A PRE-FAB NODE EXPANSION SEGMENT
92 C ---------------------------------------
93 
94  newn = 0
95  n1 = iseq(nodi,1)
96  n2 = iseq(nodi,2)
97 
98  IF(n1.EQ.0 ) GOTO 906
99  IF(n2-n1+1.GT.maxjl) GOTO 907
100 
101  DO n=n1,n2
102  newn = newn+1
103  itmp(newn) = jseq(n)
104  vtmp(newn) = vali(jseq(n))
105  ENDDO
106 
107 C MOVE OLD NODES - STORE NEW ONES
108 C -------------------------------
109 
110  IF(nval(lun)+newn*nbmp.GT.maxss) GOTO 908
111 
112  DO j=nval(lun),invn+1,-1
113  inv(j+newn*nbmp,lun) = inv(j,lun)
114  val(j+newn*nbmp,lun) = val(j,lun)
115  ENDDO
116 
117  IF(drp.OR.drs) vtmp(1) = newn
118  knvn = invn
119 
120  DO i=1,nbmp
121  DO j=1,newn
122  knvn = knvn+1
123  inv(knvn,lun) = itmp(j)
124  val(knvn,lun) = vtmp(j)
125  ENDDO
126  ENDDO
127 
128 C RESET POINTERS AND COUNTERS
129 C ---------------------------
130 
131  nval(lun) = nval(lun) + newn*nbmp
132 
133  IF(iprt.GE.2) THEN
134  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
135  WRITE ( unit=errstr, fmt='(A,A,A10,2(A,I5),A,I7)' )
136  . 'BUFRLIB: USRTPL - TAG(INV(INVN,LUN)):NEWN:NBMP:',
137  . 'NVAL(LUN) = ', tag(inv(invn,lun)), ':', newn, ':',
138  . nbmp, ':', nval(lun)
139  CALL errwrt(errstr)
140  DO i=1,newn
141  WRITE ( unit=errstr, fmt='(2(A,I5),A,A10)' )
142  . 'For I = ', i, ', ITMP(I) = ', itmp(i),
143  . ', TAG(ITMP(I)) = ', tag(itmp(i))
144  CALL errwrt(errstr)
145  ENDDO
146  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
147  CALL errwrt(' ')
148  ENDIF
149 
150  IF(drx) THEN
151  node = nodi
152  invr = invn
153 4 node = jmpb(node)
154  IF(node.GT.0) THEN
155  IF(itp(node).EQ.0) THEN
156  DO invr=invr-1,1,-1
157  IF(inv(invr,lun).EQ.node) THEN
158  val(invr,lun) = val(invr,lun)+newn*nbmp
159  GOTO 4
160  ENDIF
161  ENDDO
162  GOTO 909
163  ELSE
164  GOTO 4
165  ENDIF
166  ENDIF
167  ENDIF
168 
169 C EXITS
170 C -----
171 
172 100 RETURN
173 900 WRITE(bort_str,'("BUFRLIB: USRTPL - THIRD ARGUMENT (INPUT) = ",'//
174  . 'I4,", MUST BE 1 WHEN SECOND ARGUMENT (INPUT) IS 1 (SUBSET '//
175  . 'NODE) (",A,")")') nbmp,tag(nodi)
176  CALL bort(bort_str)
177 901 WRITE(bort_str,'("BUFRLIB: USRTPL - THIRD ARGUMENT (INPUT) = ",'//
178  . 'I4,", MUST BE 1 WHEN NODE IS DRB (1-BIT DELAYED REPL. FACTOR)'//
179  . ' (",A,")")') nbmp,tag(nodi)
180  CALL bort(bort_str)
181 902 WRITE(bort_str,'("BUFRLIB: USRTPL - NODE IS OF TYPE ",A," - IT '//
182  . 'MUST BE EITHER A SUBSET OR DELAYED REPL. FACTOR (",A,")")')
183  . typ(nodi),tag(nodi)
184  CALL bort(bort_str)
185 903 WRITE(bort_str,'("BUFRLIB: USRTPL - REPLICATION FACTOR IS '//
186  . 'NEGATIVE (=",I5,") (",A,")")') ival,tag(nodi)
187  CALL bort(bort_str)
188 904 WRITE(bort_str,'("BUFRLIB: USRTPL - REPLICATION FACTOR OVERFLOW'//
189  . ' (EXCEEDS MAXIMUM OF",I6," (",A,")")') jval,tag(nodi)
190  call errwrt(bort_str)
191  iscodes(lun) = 1
192  return
193 905 WRITE(bort_str,'("BUFRLIB: USRTPL - INVENTORY INDEX {FIRST '//
194  . 'ARGUMENT (INPUT)} OUT OF BOUNDS (=",I5,", RANGE IS 1 TO",I6,"'//
195  . ') ")') invn,nval(lun)
196  CALL bort(bort_str)
197 906 WRITE(bort_str,'("BUFRLIB: USRTPL - UNSET EXPANSION SEGMENT (",'//
198  . 'A,")")') tag(nodi)
199  CALL bort(bort_str)
200 907 WRITE(bort_str,'("BUFRLIB: USRTPL - TEMPLATE ARRAY OVERFLOW, '//
201  . 'EXCEEDS THE LIMIT (",I6,") (",A,")")') maxjl,tag(nodi)
202  CALL bort(bort_str)
203 908 WRITE(bort_str,'("BUFRLIB: USRTPL - INVENTORY OVERFLOW (",I6,")'//
204  . ', EXCEEDS THE LIMIT (",I6,") (",A,")")')
205  . nval(lun)+newn*nbmp,maxss,tag(nodi)
206  CALL bort(bort_str)
207 909 WRITE(bort_str,'("BUFRLIB: USRTPL - BAD BACKUP STRATEGY (",A,'//
208  . '")")') tag(nodi)
209  CALL bort(bort_str)
210  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
This module contains arrays which provide working space in several subprograms (usrtpl() and ufbcup()...
real *8, dimension(:), allocatable vtmp
val array elements for new sections of a growing subset buffer.
integer, dimension(:), allocatable itmp
inv array elements for new sections of a growing subset buffer.
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 an array declaration used to store a status code for each internal I/O stream in...
integer, dimension(:), allocatable iscodes
Abnormal status codes.
This module contains array and variable declarations used to store the internal jump/link table.
integer, dimension(:), allocatable jseq
Temporary storage used in expanding sequences.
integer, dimension(:,:), allocatable iseq
Temporary storage used in expanding sequences.
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
real *8, dimension(:), allocatable vali
Initialized data values corresponding to typ:
character *3, dimension(:), allocatable typ
Type indicators corresponding to tag:
integer, dimension(:), allocatable jmpb
Jump backward indices corresponding to tag and typ:
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
This module contains declarations for arrays used to store data values and associated metadata for th...
integer, dimension(:), allocatable nval
Number of data values in BUFR data subset.
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 MAXJL variable.
integer maxjl
Maximum number of entries in the internal jump/link table.
This module declares and initializes the MAXSS variable.
integer maxss
Maximum number of data values that can be read from or written into a data subset by the BUFRLIB soft...
subroutine usrtpl(LUN, INVN, NBMP)
Store the subset template into internal arrays.
Definition: usrtpl.f:22