1 SUBROUTINE UFBREP
(LUNIO
,USR
,I1
,I2
,IRET
,STR
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: WOOLLEN ORG: NP20 DATE: 1994-01-06
8 C ABSTRACT: THIS SUBROUTINE WRITES OR READS SPECIFIED VALUES TO OR
9 C FROM THE CURRENT BUFR DATA SUBSET WITHIN INTERNAL ARRAYS, WITH THE
10 C DIRECTION OF THE DATA TRANSFER DETERMINED BY THE CONTEXT OF
11 C ABS(LUNIO) (I.E., IF ABS(LUNIO) POINTS TO A BUFR FILE THAT IS OPEN
12 C FOR INPUT, THEN DATA VALUES ARE READ FROM THE INTERNAL DATA SUBSET;
13 C OTHERWISE, DATA VALUES ARE WRITTEN TO THE INTERNAL DATA SUBSET).
14 C THE DATA VALUES CORRESPOND TO MNEMONICS WHICH ARE EITHER:
15 C 1) PART OF A REGULAR (I.E., NON-DELAYED) REPLICATION SEQUENCE
17 C 2) REPLICATED BY BEING DIRECTLY LISTED MORE THAN ONCE WITHIN AN
18 C OVERALL SUBSET DEFINITION
20 C THE DIFFERENCE IN THE WAY UFBREP WORKS AS COMPARED TO UFBINT IS IN
21 C THE WAY THE MNEMONIC STRING IS INTERPRETED TO DEFINE WHICH ELEMENTS
22 C ARE PROCESSED AND IN WHAT ORDER. UFBREP INTERPRETS THE FIRST
23 C MNEMONIC IN THE STRING AS A "PIVOT". THIS MEANS THE 2ND DIMENSION
24 C OF THE DATA RETURNED (AS INDICATED BY ARGUMENT I2) IS DEFINED BY
25 C OCCURRENCES OF THE PIVOT ELEMENT FOUND WITHIN THE OVERALL SUBSET
26 C DEFINITION. FOR EXAMPLE, IF THE SUBSET DEFINITION CONTAINS THE
27 C FOLLOWING SEQUENCE OF MNEMONICS:
28 C {..,A,..,B,..,C,..,D,..,A,..,C,..,D,..,B,..
29 C A,..,B,..,D,..,C,..,A,..,C,..,B,..,D,..},
30 C THEN READING A SUBSET VIA UFBREP WITH STR = "A B C D" RETURNS THE
31 C FOLLOWING 4X4 MATRIX OF VALUES IN USR, USING A AS THE "PIVOT"
32 C MNEMONIC SINCE IT WAS THE FIRST MNEMONIC IN THE STRING:
37 C NOTE THAT, WHEN USING UFBREP, THE ORDER OF THE NON-PIVOT MNEMONICS
38 C BETWEEN EACH PIVOT IS IMMATERIAL, I.E., IN THE ABOVE EXAMPLE, UFBREP
39 C FINDS ALL OF THE OCCURRENCES OF MNEMONICS B, C AND D BETWEEN EACH
40 C PIVOT BECAUSE IT SEARCHES INDEPENDENTLY FOR EACH ONE BETWEEN
43 C IN CONTRAST, NOTE THERE IS ALSO A SEPARATE SUBROUTINE UFBSTP WHICH
44 C IS SIMILAR TO UFBREP, EXCEPT THAT UFBSTP ALWAYS STEPS FORWARD WHEN
45 C SEARCHING FOR EACH SUCCESSIVE NON-PIVOT MNEMONIC, RATHER THAN
46 C SEARCHING INDEPENDENTLY FOR EACH ONE BETWEEN SUCCESSIVE PIVOTS.
47 C SO IN THE ABOVE EXAMPLE WITH STR="A B C D" AND STARTING FROM EACH
48 C SUCCESSIVE PIVOT MNEMONIC A, UFBSTP WOULD SEARCH FORWARD FOR THE
49 C NEXT OCCURRENCE OF MNEMONIC B, THEN IF FOUND SEARCH FORWARD FROM
50 C THERE FOR THE NEXT OCCURRENCE OF C, THEN IF FOUND SEARCH FORWARD
51 C FROM THERE FOR THE NEXT OCCURRENCE OF D, ETC. UP UNTIL REACHING
52 C THE NEXT OCCURRENCE OF THE PIVOT MNEMONIC A (OR THE END OF THE DATA
53 C SUBSET), WITHOUT EVER DOING ANY BACKTRACKING. SO IN THE ABOVE
54 C EXAMPLE UFBSTP WOULD RETURN THE FOLLOWING 4x4 MATRIX OF VALUES IN
55 C ARRAY USR, WHERE XX DENOTES A "MISSING" VALUE:
61 C PROGRAM HISTORY LOG:
62 C 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
63 C 1998-07-08 J. WOOLLEN -- REPLACED CALL TO CRAY LIBRARY ROUTINE
64 C "ABORT" WITH CALL TO NEW INTERNAL BUFRLIB
66 C 1999-11-18 J. WOOLLEN -- THE NUMBER OF BUFR FILES WHICH CAN BE
67 C OPENED AT ONE TIME INCREASED FROM 10 TO 32
68 C (NECESSARY IN ORDER TO PROCESS MULTIPLE
69 C BUFR FILES UNDER THE MPI)
70 C 2003-05-19 J. WOOLLEN -- DISABLED THE PARSING SWITCH WHICH CONTROLS
71 C CHECKING FOR IN THE SAME REPLICATION GROUP,
72 C UFBREP DOES NOT NEED THIS CHECK, AND IT
73 C INTERFERES WITH WHAT UFBREP CAN DO
75 C 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
77 C 2003-11-04 D. KEYSER -- MAXJL (MAXIMUM NUMBER OF JUMP/LINK ENTRIES)
78 C INCREASED FROM 15000 TO 16000 (WAS IN
79 C VERIFICATION VERSION); UNIFIED/PORTABLE FOR
80 C WRF; ADDED DOCUMENTATION (INCLUDING
81 C HISTORY); OUTPUTS MORE COMPLETE DIAGNOSTIC
82 C INFO WHEN ROUTINE TERMINATES ABNORMALLY OR
83 C UNUSUAL THINGS HAPPEN; CHANGED CALL FROM
84 C BORT TO BORT2 IN SOME CASES
85 C 2004-08-18 J. ATOR -- ADDED SAVE FOR IFIRST1 AND IFIRST2 FLAGS
86 C 2009-03-31 J. WOOLLEN -- ADD DOCUMENTATION
87 C 2009-04-21 J. ATOR -- USE ERRWRT
89 C USAGE: CALL UFBREP (LUNIO, USR, I1, I2, IRET, STR)
90 C INPUT ARGUMENT LIST:
91 C LUNIO - INTEGER: ABSOLUTE VALUE IS FORTRAN LOGICAL UNIT NUMBER
93 C - IF BUFR FILE OPEN FOR OUTPUT AND LUNIO IS LESS
94 C THAN ZERO, UFBREP TREATS THE BUFR FILE AS THOUGH
95 C IT WERE OPEN FOR INPUT
96 C USR - ONLY IF BUFR FILE OPEN FOR OUTPUT:
97 C REAL*8: (I1,I2) STARTING ADDRESS OF DATA VALUES
98 C WRITTEN TO DATA SUBSET
99 C I1 - INTEGER: LENGTH OF FIRST DIMENSION OF USR OR THE
100 C NUMBER OF BLANK-SEPARATED MNEMONICS IN STR (FORMER
101 C MUST BE AT LEAST AS LARGE AS LATTER)
103 C - IF BUFR FILE OPEN FOR INPUT: LENGTH OF SECOND
105 C - IF BUFR FILE OPEN FOR OUTPUT: NUMBER OF "LEVELS"
106 C OF DATA VALUES TO BE WRITTEN TO DATA SUBSET
107 C STR - CHARACTER*(*): STRING OF BLANK-SEPARATED TABLE B
108 C MNEMONICS IN ONE-TO-ONE CORRESPONDENCE WITH FIRST
110 C - IF BUFR FILE OPEN FOR INPUT: THERE ARE THREE
111 C "GENERIC" MNEMONICS NOT RELATED TO TABLE B,
112 C THESE RETURN THE FOLLOWING INFORMATION IN
113 C CORRESPONDING USR LOCATION:
114 C 'NUL' WHICH ALWAYS RETURNS BMISS ("MISSING")
115 C 'IREC' WHICH ALWAYS RETURNS THE CURRENT BUFR
116 C MESSAGE (RECORD) NUMBER IN WHICH THIS
118 C 'ISUB' WHICH ALWAYS RETURNS THE CURRENT SUBSET
119 C NUMBER OF THIS SUBSET WITHIN THE BUFR
120 C MESSAGE (RECORD) NUMBER 'IREC'
122 C OUTPUT ARGUMENT LIST:
123 C USR - ONLY IF BUFR FILE OPEN FOR INPUT:
124 C REAL*8: (I1,I2) STARTING ADDRESS OF DATA VALUES
125 C READ FROM DATA SUBSET
127 C - IF BUFR FILE OPEN FOR INPUT: NUMBER OF "LEVELS" OF
128 C DATA VALUES READ FROM DATA SUBSET (MUST BE NO
130 C - IF BUFR FILE OPEN FOR OUTPUT: NUMBER OF "LEVELS"
131 C OF DATA VALUES WRITTEN TO DATA SUBSET (SHOULD BE
135 C THIS ROUTINE CALLS: BORT BORT2 ERRWRT STATUS
137 C THIS ROUTINE IS CALLED BY: None
138 C Normally called only by application
142 C LANGUAGE: FORTRAN 77
143 C MACHINE: PORTABLE TO ALL PLATFORMS
147 INCLUDE
'bufrlib.prm'
149 COMMON /MSGCWD
/ NMSG
(NFILES
),NSUB
(NFILES
),MSUB
(NFILES
),
150 . INODE
(NFILES
),IDATE
(NFILES
)
151 COMMON /USRINT
/ NVAL
(NFILES
),INV
(MAXSS
,NFILES
),VAL
(MAXSS
,NFILES
)
156 CHARACTER*128 BORT_STR1
,BORT_STR2
,ERRSTR
157 REAL*8 USR
(I1
,I2
),VAL
159 DATA IFIRST1
/0/,IFIRST2
/0/
161 SAVE IFIRST1
, IFIRST2
163 C----------------------------------------------------------------------
164 C----------------------------------------------------------------------
168 C CHECK THE FILE STATUS AND I-NODE
169 C --------------------------------
172 CALL STATUS
(LUNIT
,LUN
,IL
,IM
)
175 IF(INODE
(LUN
).NE
.INV
(1,LUN
)) GOTO 902
177 IO
= MIN
(MAX
(0,IL
),1)
178 IF(LUNIO
.NE
.LUNIT
) IO
= 0
182 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
183 ERRSTR
= 'BUFRLIB: UFBREP - 3rd ARG. (INPUT) IS .LE. 0, ' //
184 . 'SO RETURN WITH 5th ARG. (IRET) = 0; 6th ARG. (STR) ='
187 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
192 IF(IPRT
.EQ
.-1) IFIRST1
= 1
193 IF(IO
.EQ
.0 .OR
. IFIRST1
.EQ
.0 .OR
. IPRT
.GE
.1) THEN
194 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
195 ERRSTR
= 'BUFRLIB: UFBREP - 4th ARG. (INPUT) IS .LE. 0, ' //
196 . 'SO RETURN WITH 5th ARG. (IRET) = 0; 6th ARG. (STR) ='
199 IF(IPRT
.EQ
.0 .AND
. IO
.EQ
.1) THEN
200 ERRSTR
= 'Note: Only the first occurrence of this WARNING ' //
201 . 'message is printed, there may be more. To output all ' //
204 ERRSTR
= 'modify your application program to add ' //
205 . '"CALL OPENBF(0,''QUIET'',1)" prior to the first call ' //
206 . 'to a BUFRLIB routine.'
209 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
216 C INITIALIZE USR ARRAY PRECEEDING AN INPUT OPERATION
217 C --------------------------------------------------
227 C PARSE OR RECALL THE INPUT STRING - READ/WRITE VALUES
228 C ----------------------------------------------------
232 CALL STRING
(STR
,LUN
,I1
,IO
)
234 C CALL THE MNEMONIC READER/WRITER
235 C -------------------------------
237 CALL UFBRP
(LUN
,USR
,I1
,I2
,IO
,IRET
)
240 IF(IO
.EQ
.1 .AND
. IRET
.LT
.I2
) GOTO 903
245 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
246 ERRSTR
= 'BUFRLIB: UFBREP - NO SPECIFIED VALUES READ IN, ' //
247 . 'SO RETURN WITH 5th ARG. (IRET) = 0; 6th ARG. (STR) ='
250 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
254 IF(IPRT
.EQ
.-1) IFIRST2
= 1
255 IF(IFIRST2
.EQ
.0 .OR
. IPRT
.GE
.1) THEN
256 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
257 ERRSTR
= 'BUFRLIB: UFBREP - NO SPECIFIED VALUES WRITTEN OUT, ' //
258 . 'SO RETURN WITH 5th ARG. (IRET) = 0; 6th ARG. (STR) ='
261 CALL ERRWRT
('MAY NOT BE IN THE BUFR TABLE(?)')
263 ERRSTR
= 'Note: Only the first occurrence of this WARNING ' //
264 . 'message is printed, there may be more. To output all ' //
267 ERRSTR
= 'modify your application program to add ' //
268 . '"CALL OPENBF(0,''QUIET'',1)" prior to the first call ' //
269 . 'to a BUFRLIB routine.'
272 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
283 900 CALL BORT
('BUFRLIB: UFBREP - BUFR FILE IS CLOSED, IT MUST BE'//
285 901 CALL BORT
('BUFRLIB: UFBREP - A MESSAGE MUST BE OPEN IN BUFR '//
287 902 CALL BORT
('BUFRLIB: UFBREP - LOCATION OF INTERNAL TABLE FOR '//
288 . 'BUFR FILE DOES NOT AGREE WITH EXPECTED LOCATION IN INTERNAL '//
290 903 WRITE(BORT_STR1
,'("BUFRLIB: UFBREP - MNEMONIC STRING READ IN IS'//
292 WRITE(BORT_STR2
,'(18X,"THE NUMBER OF ''LEVELS'' ACTUALLY '//
293 . 'WRITTEN (",I3,") LESS THAN THE NUMBER REQUESTED (",I3,") - '//
294 . 'INCOMPLETE WRITE")') IRET
,I2
295 CALL BORT2
(BORT_STR1
,BORT_STR2
)