1 SUBROUTINE REWNBF
(LUNIT
,ISR
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: WOOLLEN ORG: NP20 DATE: 2003-11-04
8 C ABSTRACT: THIS SUBROUTINE, DEPENDING ON THE VALUE OF ISR, WILL
10 C 1) STORE THE CURRENT PARAMETERS ASSOCIATED WITH A BUFR FILE
11 C CONNECTED TO LUNIT (READ/WRITE POINTERS, ETC.), SET THE FILE STATUS
12 C TO READ, THEN REWIND THE BUFR FILE AND POSITION IT SUCH THAT THE
13 C NEXT BUFR MESSAGE READ WILL BE THE FIRST MESSAGE IN THE FILE
14 C CONTAINING ACTUAL SUBSETS WITH DATA; OR
15 C 2) RESTORE THE BUFR FILE CONNECTED TO LUNIT TO THE PARAMETERS
16 C IT HAD PRIOR TO 1) ABOVE USING THE INFORMATION SAVED IN 1) ABOVE.
18 C THIS ALLOWS INFORMATION TO BE EXTRACTED FROM A PARTICULAR SUBSET IN
19 C A BUFR FILE WHICH IS IN THE MIDST OF BEING READ FROM OR WRITTEN TO
20 C BY AN APPLICATION PROGRAM. NOTE THAT FOR A PARTICULAR BUFR FILE 1)
21 C ABOVE MUST PRECEDE 2) ABOVE. AN APPLICATION PROGRAM MIGHT FIRST
22 C CALL THIS SUBROUTINE WITH ISR = 0, THEN CALL EITHER BUFR ARCHIVE
23 C LIBRARY SUBROUTINE RDMGSB OR UFBINX TO GET INFO FROM A SUBSET, THEN
24 C CALL THIS ROUTINE AGAIN WITH ISR = 1 TO RESTORE THE POINTERS IN THE
25 C BUFR FILE TO THEIR ORIGINAL LOCATION. ALSO, BUFR ARCHIVE LIBRARY
26 C SUBROUTINE UFBTAB WILL CALL THIS ROUTINE IF THE BUFR FILE IT IS
27 C ACTING UPON IS ALREADY OPEN FOR INPUT OR OUTPUT.
29 C PROGRAM HISTORY LOG:
30 C 2003-11-04 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN VERIFICATION
31 C VERSION BUT MAY HAVE BEEN IN THE PRODUCTION
32 C VERSION AT ONE TIME AND THEN REMOVED)
33 C 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED
34 C DOCUMENTATION; OUTPUTS MORE COMPLETE
35 C DIAGNOSTIC INFO WHEN ROUTINE TERMINATES
37 C 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
38 C 20,000 TO 50,000 BYTES
39 C 2009-03-23 J. ATOR -- MODIFIED TO HANDLE EMBEDDED BUFR TABLE
40 C (DICTIONARY) MESSAGES
41 C 2011-09-26 J. WOOLLEN -- FIXED BUG TO PREVENT SKIP OF FIRST DATA
42 C MESSAGE AFTER REWIND
43 C 2012-09-15 J. WOOLLEN -- MODIFIED FOR C/I/O/BUFR INTERFACE;
44 C REPLACE FORTRAN REWIND WITH C CEWIND
46 C USAGE: CALL REWNBF (LUNIT, ISR)
47 C INPUT ARGUMENT LIST:
48 C LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
49 C ISR - INTEGER: SWITCH:
50 C 0 = store current parameters associated with
51 C BUFR file, set file status to read, rewind
52 C file such that next message read is first
53 C message containing subset data
54 C 1 = restore BUFR file with parameters saved
55 C from the previous call to this routine with
59 C UNIT "LUNIT" - BUFR FILE
62 C THIS ROUTINE CALLS: BORT I4DY READMG STATUS
64 C THIS ROUTINE IS CALLED BY: UFBINX UFBTAB
65 C Also called by application programs.
68 C LANGUAGE: FORTRAN 77
69 C MACHINE: PORTABLE TO ALL PLATFORMS
75 COMMON /MSGCWD
/ NMSG
(NFILES
),NSUB
(NFILES
),MSUB
(NFILES
),
76 . INODE
(NFILES
),IDATE
(NFILES
)
77 COMMON /BITBUF
/ MAXBYT
,IBIT
,IBAY
(MXMSGLD4
),MBYT
(NFILES
),
78 . MBAY
(MXMSGLD4
,NFILES
)
79 COMMON /BUFRSR
/ JUNN
,JILL
,JIMM
,JBIT
,JBYT
,JMSG
,JSUB
,KSUB
,JNOD
,JDAT
,
80 . JSR
(NFILES
),JBAY
(MXMSGLD4
)
82 CHARACTER*128 BORT_STR
86 DIMENSION MESG
(MXMSGLD4
)
88 C-----------------------------------------------------------------------
89 C-----------------------------------------------------------------------
91 C TRY TO TRAP BAD CALL PROBLEMS
92 C -----------------------------
95 CALL STATUS
(LUNIT
,LUN
,IL
,IM
)
96 IF(JSR
(LUN
).NE
.0) GOTO 900
100 IF(JSR
(JUNN
).NE
.1) GOTO 902
105 C STORE FILE PARAMETERS AND SET FOR READING
106 C -----------------------------------------
120 JBAY
(I
) = MBAY
(I
,LUN
)
122 CALL WTSTAT
(LUNIT
,LUN
,-1,0)
130 C RESTORE FILE PARAMETERS AND POSITION IT TO WHERE IT WAS SAVED
131 C -------------------------------------------------------------
143 IDATE
(LUN
) = I4DY
(JDAT
)
145 MBAY
(I
,LUN
) = JBAY
(I
)
148 CALL READMG
(LUNIT
,SUBSET
,KDATE
,IER
)
149 IF(IER
.LT
.0) GOTO 905
151 CALL WTSTAT
(LUNIT
,LUN
,IL
,IM
)
154 JSR
(LUN
) = MOD
(JSR
(LUN
)+1,2)
160 900 WRITE(BORT_STR
,'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '//
161 . 'PARAMETERS FOR FILE FOR WHICH THEY HAVE ALREADY BEEN SAVED '//
162 . '(AND NOT YET RESTORED) (UNIT",I3,")")') LUNIT
164 901 WRITE(BORT_STR
,'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '//
165 . 'PARAMETERS FOR BUFR FILE WHICH IS NOT OPENED FOR EITHER INPUT'//
166 . ' OR OUTPUT) (UNIT",I3,")")') LUNIT
168 902 WRITE(BORT_STR
,'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '//
169 . 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")')
172 903 WRITE(BORT_STR
,'("BUFRLIB: REWNBF - SAVE/RESTORE SWITCH (INPUT '//
173 . 'ARGUMENT ISR) IS NOT ZERO OR ONE (HERE =",I4,") (UNIT",I3,")")')
176 905 WRITE(BORT_STR
,'("BUFRLIB: REWNBF - HIT END OF FILE BEFORE '//
177 . 'REPOSITIONING BUFR FILE IN UNIT",I3," TO ORIGINAL MESSAGE '//
178 . 'NO.",I5)') LUNIT
,JMSG