NCEPLIBS-bufr 11.7.1
parutg.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 1994-01-06
3
4C> THIS SUBROUTINE PARSES A USER-SPECIFIED TAG (MNEMONIC)
5C> (UTG) THAT REPRESENTS A VALUE EITHER BEING DECODED FROM A BUFR FILE
6C> (IF IT IS BEING READ) OR ENCODED INTO A BUFR FILE (IF IT IS BEING
7C> WRITTEN). THIS SUBROUTINE FIRST CHECKS TO SEE IF THE TAG CONTAINS
8C> A CONDITION CHARACTER ('=', '!', '<', '>', '^' OR '#'). IF IT DOES
9C> NOT, NOTHING HAPPENS AT THIS POINT. IF IT DOES, THEN THE TYPE OF
10C> CONDITION CHARACTER IS NOTED AND THE TAG IS STRIPPED OF ALL
11C> CHARACTERS AT AND BEYOND THE CONDITION CHARACTER. IN EITHER EVENT,
12C> THE RESULTANT TAG IS CHECKED AGAINST THOSE IN THE INTERNAL JUMP/
13C> LINK SUBSET TABLE (IN MODULE TABLES). IF FOUND, THE NODE
14C> ASSOCIATED WITH THE TAG IS RETURNED (AND IT IS EITHER A "CONDITION"
15C> NODE OR A "STORE" NODE DEPENDING OF THE PRESENCE OR ABSENCE OF A
16C> CONDITION CHARACTER IN UTG). OTHERWISE THE NODE IS RETURNED AS
17C> ZERO. IF THE TAG REPRESENTS A CONDITION NODE, THEN THE CONDITION
18C> VALUE (NUMERIC CHARACTERS BEYOND THE CONDITION CHARACTER IN THE
19C> USER-SPECIFIED TAG INPUT HERE) IS RETURNED.
20C>
21C> AS AN EXAMPLE OF CONDITION CHARACTER USAGE, CONSIDER THE FOLLOWING
22C> EXAMPLE OF A CALL TO UFBINT:
23C>
24C> REAL*8 USR(4,50)
25C> ....
26C> ....
27C> CALL UFBINT(LUNIN,USR,4,50,IRET,'PRLC<50000 TMDB WDIR WSPD')
28C>
29C> ASSUMING THAT LUNIN POINTS TO A BUFR FILE OPEN FOR INPUT (READING),
30C> THEN THE USR ARRAY NOW CONTAINS IRET LEVELS OF DATA (UP TO A MAXIMUM
31C> OF 50!) WHERE THE VALUE OF PRLC IS/WAS LESS THAN 50000, ALONG WITH
32C> THE CORRESPONDING VALUES FOR TMDB, WDIR AND WSPD AT THOSE LEVELS.
33C>
34C> AS ANOTHER EXAMPLE, CONSIDER THE FOLLOWING EXAMPLE OF A CALL TO
35C> READLC FOR A LONG CHARACTER STRING:
36C>
37C> CHARACTER*200 LCHR
38C> ....
39C> ....
40C> CALL READLC(LUNIN,LCHR,'NUMID#3')
41C>
42C> ASSUMING THAT LUNIN POINTS TO A BUFR FILE OPEN FOR INPUT (READING),
43C> THEN THE LCHR STRING NOW CONTAINS THE VALUE CORRESPONDING TO THE
44C> THIRD OCCURRENCE OF NUMID WITHIN THE CURRENT SUBSET.
45C>
46C> VALID CONDITION CODES INCLUDE:
47C> '<' - LESS THAN
48C> '>' - GREATER THAN
49C> '=' - EQUAL TO
50C> '!' - NOT EQUAL TO
51C> '#' - ORDINAL IDENTIFIER FOR A PARTICULAR OCCURRENCE OF A LONG
52C> CHARACTER STRING
53C>
54C> PROGRAM HISTORY LOG:
55C> 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
56C> 1998-07-08 J. WOOLLEN -- REPLACED CALL TO CRAY LIBRARY ROUTINE
57C> "ABORT" WITH CALL TO NEW INTERNAL BUFRLIB
58C> ROUTINE "BORT"
59C> 1999-11-18 J. WOOLLEN -- THE NUMBER OF BUFR FILES WHICH CAN BE
60C> OPENED AT ONE TIME INCREASED FROM 10 TO 32
61C> (NECESSARY IN ORDER TO PROCESS MULTIPLE
62C> BUFR FILES UNDER THE MPI)
63C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
64C> INTERDEPENDENCIES
65C> 2003-11-04 D. KEYSER -- MAXJL (MAXIMUM NUMBER OF JUMP/LINK ENTRIES)
66C> INCREASED FROM 15000 TO 16000 (WAS IN
67C> VERIFICATION VERSION); UNIFIED/PORTABLE FOR
68C> WRF; ADDED DOCUMENTATION (INCLUDING
69C> HISTORY); OUTPUTS MORE COMPLETE DIAGNOSTIC
70C> INFO WHEN ROUTINE TERMINATES ABNORMALLY;
71C> CHANGED CALL FROM BORT TO BORT2 IN SOME
72C> CASES; REPLACED PREVIOUS "RETURN 1"
73C> STATEMENT WITH "GOTO 900" (AND CALL TO
74C> BORT) SINCE THE ONLY ROUTINE THAT CALLS
75C> THIS ROUTINE, PARUSR, USED THIS ALTERNATE
76C> RETURN TO GO TO A STATEMENT WHICH CALLED
77C> BORT
78C> 2005-04-22 J. ATOR -- HANDLED SITUATION WHERE INPUT TAG CONTAINS
79C> 1-BIT DELAYED REPLICATION, AND IMPROVED
80C> DOCUMENTATION
81C> 2009-03-23 J. ATOR -- ADDED '#' CONDITION CODE
82C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
83C>
84C> USAGE: CALL PARUTG (LUN, IO, UTG, NOD, KON, VAL)
85C> INPUT ARGUMENT LIST:
86C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
87C> IO - INTEGER: STATUS INDICATOR FOR BUFR FILE ASSOCIATED
88C> WITH LUN:
89C> 0 = input file
90C> 1 = output file
91C> UTG CHARACTER*(*): USER-SUPPLIED TAG REPRESENTING A VALUE TO
92C> BE ENCODED/DECODED TO/FROM BUFR FILE
93C>
94C> OUTPUT ARGUMENT LIST:
95C> NOD - INTEGER: POSITIONAL INDEX IN INTERNAL JUMP/LINK SUBSET
96C> TABLE FOR TAG
97C> 0 = tag not found in table
98C> KON - INTEGER: INDICATOR FOR TYPE OF CONDITION CHARACTER
99C> FOUND IN UTG:
100C> 0 = no condition character found (NOD is a store
101C> node)
102C> 1 = character '=' found
103C> 2 = character '!' found
104C> 3 = character '<' found
105C> 4 = character '>' found
106C> 5 = character '^' found
107C> 6 = character '#' found
108C> (1-6 means NOD is a condition node, and
109C> specifically 5 is a "bump" node)
110C> VAL - REAL: CONDITION VALUE ASSOCIATED WITH CONDITION
111C> CHARACTER FOUND IN UTG
112C> 0 = UTG does not have a condition character
113C>
114C> REMARKS:
115C> THIS ROUTINE CALLS: BORT BORT2 STRNUM
116C> THIS ROUTINE IS CALLED BY: PARUSR READLC WRITLC
117C> Normally not called by any application
118C> programs.
119C>
120 SUBROUTINE parutg(LUN,IO,UTG,NOD,KON,VAL)
121
122 USE moda_msgcwd
123 USE moda_tables
124
125 COMMON /utgprm/ picky
126
127 CHARACTER*(*) UTG
128 CHARACTER*128 BORT_STR1,BORT_STR2
129 CHARACTER*20 ATAG
130 CHARACTER*3 ATYP,BTYP
131 CHARACTER*1 COND(6)
132 dimension btyp(8),iok(8)
133 LOGICAL PICKY
134
135 DATA nchk / 8/
136 DATA btyp /'SUB','SEQ','REP','RPC','RPS','DRB','DRP','DRS'/
137 DATA iok / -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 /
138
139C----------------------------------------------------------------------
140C For now, set PICKY (see below) to always be .FALSE.
141 picky = .false.
142 cond(1) = '='
143 cond(2) = '!'
144 cond(3) = '<'
145 cond(4) = '>'
146 cond(5) = '^'
147 cond(6) = '#'
148 ncond = 6
149C----------------------------------------------------------------------
150
151 atag = ' '
152 atyp = ' '
153 kon = 0
154 nod = 0
155 val = 0
156 ltg = min(20,len(utg))
157
158C PARSE UTG, SAVING INTO ATAG ONLY CHARACTERS PRIOR TO CONDITION CHAR.
159C --------------------------------------------------------------------
160
161C But first, take care of the special case where UTG denotes the
162C short (i.e. 1-bit) delayed replication of a Table D mnemonic.
163C This will prevent confusion later on since '<' and '>' are each
164C also valid as condition characters.
165
166 IF((utg(1:1).EQ.'<').AND.(index(utg(3:),'>').NE.0)) THEN
167 atag = utg
168 GO TO 1
169 ENDIF
170
171 DO i=1,ltg
172 IF(utg(i:i).EQ.' ') GOTO 1
173 DO j=1,ncond
174 IF(utg(i:i).EQ.cond(j)) THEN
175 kon = j
176 icv = i+1
177 GOTO 1
178 ENDIF
179 ENDDO
180 atag(i:i) = utg(i:i)
181 ENDDO
182
183C FIND THE NODE ASSOCIATED WITH ATAG IN THE SUBSET TABLE
184C ------------------------------------------------------
185
1861 inod = inode(lun)
187 DO nod=inod,isc(inod)
188 IF(atag.EQ.tag(nod)) GOTO 2
189 ENDDO
190
191C ATAG NOT FOUND IN SUBSET TABLE
192C ------------------------------
193
194C So what do we want to do? We could be "picky" and abort right
195C here, or we could allow for the possibility that, e.g. a user
196C application has been streamlined to always call UFBINT with the
197C same STR, even though some of the mnemonics contained within that
198C STR may not exist within the sequence definition of every
199C possible type/subtype that is being written by the application.
200C In such cases, by not being "picky", we could just allow BUFRLIB
201C to subsequently (and quietly, if IPRT happened to be set to -1
202C in COMMON /QUIET/!) not actually store the value corresponding
203C to such mnemonics, rather than loudly complaining and aborting.
204
205 IF(kon.EQ.0 .AND. (io.EQ.0.OR.atag.EQ.'NUL'.OR..NOT.picky)) THEN
206C i.e. (if this tag does not contain any condition characters)
207C .AND.
208C ((either the file is open for input) .OR.
209C (the tag consists of 'NUL') .OR.
210C (we aren't being "picky"))
211 nod = 0
212 GOTO 100
213 ELSE
214C abort...
215 GOTO 900
216 ENDIF
217
218C ATAG IS FOUND IN SUBSET TABLE, MAKE SURE IT HAS A VALID NODE TYPE
219C -----------------------------------------------------------------
220
2212 IF(kon.EQ.5) THEN
222c .... Cond. char "^" must be assoc. with a delayed replication
223c sequence (this is a "bump" node) (Note: This is obsolete but
224c remains for "old" programs using the BUFR ARCHIVE LIBRARY)
225 IF(typ(nod-1).NE.'DRP' .AND. typ(nod-1).NE.'DRS') GOTO 901
226 ELSEIF(kon.NE.6) THEN
227C Allow reading (but not writing) of delayed replication factors.
228 atyp = typ(nod)
229 DO i=1,nchk
230 IF(atyp.EQ.btyp(i) .AND. io.GT.iok(i)) GOTO 902
231 ENDDO
232 ENDIF
233
234C IF CONDITION NODE, GET CONDITION VALUE WHICH IS A NUMBER FOLLOWING IT
235C ---------------------------------------------------------------------
236
237 IF(kon.NE.0) THEN
238 CALL strnum(utg(icv:ltg),num)
239 IF(num.LT.0) GOTO 903
240 val = num
241 ENDIF
242
243C EXITS
244C -----
245
246100 RETURN
247900 WRITE(bort_str1,'("BUFRLIB: PARUTG - TRYING TO WRITE A MNEMONIC'//
248 . ' (",A,") WHICH DOES NOT EXIST IN SUBSET TABLE")') atag
249 WRITE(bort_str2,'(18X,"(UPON INPUT, IT CONTAINED THE CONDITION '//
250 . 'CHARACTER ",A,")")') utg(icv-1:icv-1)
251 CALL bort2(bort_str1,bort_str2)
252901 WRITE(bort_str1,'("BUFRLIB: PARUTG - BUMP NODE (MNEMONIC ",A,")'//
253 . ' MUST REFER TO A DELAYED REPLICATION SEQUENCE, HERE TYPE IS "'//
254 . ',A)') atag,typ(nod-1)
255 CALL bort(bort_str1)
256902 WRITE(bort_str1,'("BUFRLIB: PARUTG - ILLEGAL NODE TYPE: ",A," '//
257 . 'FOR MNEMONIC ",A)') atyp,atag
258 CALL bort(bort_str1)
259903 WRITE(bort_str1,'("BUFRLIB: PARUTG - CONDITION VALUE IN '//
260 . 'MNEMONIC ",A," ILLEGAL BECAUSE ALL OTHER CHARACTERS IN '//
261 . 'MNEMONIC MUST BE NUMERIC")') utg
262 CALL bort(bort_str1)
263 END
subroutine bort2(STR1, STR2)
This subroutine calls subroutine errwrt() to log two error messages, then calls subroutine bort_exit(...
Definition: bort2.f:23
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
This module contains array and variable declarations used to store the internal jump/link table.
Definition: moda_tables.F:13
integer, dimension(:), allocatable isc
Scale factors corresponding to tag and typ:
Definition: moda_tables.F:140
character *3, dimension(:), allocatable typ
Type indicators corresponding to tag:
Definition: moda_tables.F:133
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.
Definition: moda_tables.F:132
subroutine parutg(LUN, IO, UTG, NOD, KON, VAL)
THIS SUBROUTINE PARSES A USER-SPECIFIED TAG (MNEMONIC) (UTG) THAT REPRESENTS A VALUE EITHER BEING DEC...
Definition: parutg.f:121
subroutine strnum(STR, NUM)
This subroutine decodes an integer from a character string.
Definition: strnum.f:24