NCEPLIBS-bufr 11.7.1
rewnbf.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 2003-11-04
3
4C> THIS SUBROUTINE, DEPENDING ON THE VALUE OF ISR, WILL
5C> EITHER:
6C> 1) STORE THE CURRENT PARAMETERS ASSOCIATED WITH A BUFR FILE
7C> CONNECTED TO LUNIT (READ/WRITE POINTERS, ETC.), SET THE FILE STATUS
8C> TO READ, THEN REWIND THE BUFR FILE AND POSITION IT SUCH THAT THE
9C> NEXT BUFR MESSAGE READ WILL BE THE FIRST MESSAGE IN THE FILE
10C> CONTAINING ACTUAL SUBSETS WITH DATA; OR
11C> 2) RESTORE THE BUFR FILE CONNECTED TO LUNIT TO THE PARAMETERS
12C> IT HAD PRIOR TO 1) ABOVE USING THE INFORMATION SAVED IN 1) ABOVE.
13C>
14C> THIS ALLOWS INFORMATION TO BE EXTRACTED FROM A PARTICULAR SUBSET IN
15C> A BUFR FILE WHICH IS IN THE MIDST OF BEING READ FROM OR WRITTEN TO
16C> BY AN APPLICATION PROGRAM. NOTE THAT FOR A PARTICULAR BUFR FILE 1)
17C> ABOVE MUST PRECEDE 2) ABOVE. AN APPLICATION PROGRAM MIGHT FIRST
18C> CALL THIS SUBROUTINE WITH ISR = 0, THEN CALL EITHER BUFR ARCHIVE
19C> LIBRARY SUBROUTINE RDMGSB OR UFBINX TO GET INFO FROM A SUBSET, THEN
20C> CALL THIS ROUTINE AGAIN WITH ISR = 1 TO RESTORE THE POINTERS IN THE
21C> BUFR FILE TO THEIR ORIGINAL LOCATION. ALSO, BUFR ARCHIVE LIBRARY
22C> SUBROUTINE UFBTAB WILL CALL THIS ROUTINE IF THE BUFR FILE IT IS
23C> ACTING UPON IS ALREADY OPEN FOR INPUT OR OUTPUT.
24C>
25C> PROGRAM HISTORY LOG:
26C> 2003-11-04 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN VERIFICATION
27C> VERSION BUT MAY HAVE BEEN IN THE PRODUCTION
28C> VERSION AT ONE TIME AND THEN REMOVED)
29C> 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED
30C> DOCUMENTATION; OUTPUTS MORE COMPLETE
31C> DIAGNOSTIC INFO WHEN ROUTINE TERMINATES
32C> ABNORMALLY
33C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
34C> 20,000 TO 50,000 BYTES
35C> 2009-03-23 J. ATOR -- MODIFIED TO HANDLE EMBEDDED BUFR TABLE
36C> (DICTIONARY) MESSAGES
37C> 2011-09-26 J. WOOLLEN -- FIXED BUG TO PREVENT SKIP OF FIRST DATA
38C> MESSAGE AFTER REWIND
39C> 2012-09-15 J. WOOLLEN -- MODIFIED FOR C/I/O/BUFR INTERFACE;
40C> REPLACE FORTRAN REWIND WITH C CEWIND
41C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
42C>
43C> USAGE: CALL REWNBF (LUNIT, ISR)
44C> INPUT ARGUMENT LIST:
45C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
46C> ISR - INTEGER: SWITCH:
47C> 0 = store current parameters associated with
48C> BUFR file, set file status to read, rewind
49C> file such that next message read is first
50C> message containing subset data
51C> 1 = restore BUFR file with parameters saved
52C> from the previous call to this routine with
53C> ISR=0
54C>
55C> INPUT FILES:
56C> UNIT "LUNIT" - BUFR FILE
57C>
58C> REMARKS:
59C> THIS ROUTINE CALLS: BORT I4DY READMG STATUS
60C> WTSTAT CEWIND
61C> THIS ROUTINE IS CALLED BY: UFBINX UFBTAB
62C> Also called by application programs.
63C>
64 SUBROUTINE rewnbf(LUNIT,ISR)
65
66 USE moda_msgcwd
67 USE moda_bitbuf
68 USE moda_bufrsr
69
70 CHARACTER*128 BORT_STR
71
72 CHARACTER*8 SUBSET
73
74C-----------------------------------------------------------------------
75C-----------------------------------------------------------------------
76
77C TRY TO TRAP BAD CALL PROBLEMS
78C -----------------------------
79
80 IF(isr.EQ.0) THEN
81 CALL status(lunit,lun,il,im)
82 IF(jsr(lun).NE.0) GOTO 900
83 IF(il.EQ.0) GOTO 901
84 ELSEIF(isr.EQ.1) THEN
85 lun = junn
86 IF(jsr(junn).NE.1) GOTO 902
87 ELSE
88 GOTO 903
89 ENDIF
90
91C STORE FILE PARAMETERS AND SET FOR READING
92C -----------------------------------------
93
94 IF(isr.EQ.0) THEN
95 junn = lun
96 jill = il
97 jimm = im
98 jbit = ibit
99 jbyt = mbyt(lun)
100 jmsg = nmsg(lun)
101 jsub = nsub(lun)
102 ksub = msub(lun)
103 jnod = inode(lun)
104 jdat = idate(lun)
105 DO i=1,jbyt
106 jbay(i) = mbay(i,lun)
107 ENDDO
108 CALL wtstat(lunit,lun,-1,0)
109 ENDIF
110
111C REWIND THE FILE
112C ---------------
113
114 CALL cewind(lun)
115
116C RESTORE FILE PARAMETERS AND POSITION IT TO WHERE IT WAS SAVED
117C -------------------------------------------------------------
118
119 IF(isr.EQ.1) THEN
120 lun = junn
121 il = jill
122 im = jimm
123 ibit = jbit
124 mbyt(lun) = jbyt
125 nmsg(lun) = jmsg
126 nsub(lun) = jsub
127 msub(lun) = ksub
128 inode(lun) = jnod
129 idate(lun) = i4dy(jdat)
130 DO i=1,jbyt
131 mbay(i,lun) = jbay(i)
132 ENDDO
133 DO imsg=1,jmsg
134 CALL readmg(lunit,subset,kdate,ier)
135 IF(ier.LT.0) GOTO 905
136 ENDDO
137 CALL wtstat(lunit,lun,il,im)
138 ENDIF
139
140 jsr(lun) = mod(jsr(lun)+1,2)
141
142C EXITS
143C -----
144
145 RETURN
146900 WRITE(bort_str,'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '//
147 . 'PARAMETERS FOR FILE FOR WHICH THEY HAVE ALREADY BEEN SAVED '//
148 . '(AND NOT YET RESTORED) (UNIT",I3,")")') lunit
149 CALL bort(bort_str)
150901 WRITE(bort_str,'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '//
151 . 'PARAMETERS FOR BUFR FILE WHICH IS NOT OPENED FOR EITHER INPUT'//
152 . ' OR OUTPUT) (UNIT",I3,")")') lunit
153 CALL bort(bort_str)
154902 WRITE(bort_str,'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '//
155 . 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")')
156 . lunit
157 CALL bort(bort_str)
158903 WRITE(bort_str,'("BUFRLIB: REWNBF - SAVE/RESTORE SWITCH (INPUT '//
159 . 'ARGUMENT ISR) IS NOT ZERO OR ONE (HERE =",I4,") (UNIT",I3,")")')
160 . isr,lunit
161 CALL bort(bort_str)
162905 WRITE(bort_str,'("BUFRLIB: REWNBF - HIT END OF FILE BEFORE '//
163 . 'REPOSITIONING BUFR FILE IN UNIT",I3," TO ORIGINAL MESSAGE '//
164 . 'NO.",I5)') lunit,jmsg
165 CALL bort(bort_str)
166 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
void cewind(f77int *nfile)
This subroutine rewinds a BUFR file back to its beginning.
Definition: cread.c:100
function i4dy(IDATE)
This function converts a date-time with a 2-digit year (YYMMDDHH) to a date-time with a 4-digit year ...
Definition: i4dy.f:32
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:25
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:26
subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
This subroutine reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays.
Definition: readmg.f:74
subroutine rewnbf(LUNIT, ISR)
THIS SUBROUTINE, DEPENDING ON THE VALUE OF ISR, WILL EITHER: 1) STORE THE CURRENT PARAMETERS ASSOCIAT...
Definition: rewnbf.f:65
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:56
subroutine wtstat(LUNIT, LUN, IL, IM)
This subroutine can be used to connect or disconnect a specified Fortran logical unit number to/from ...
Definition: wtstat.f:53