NCEPLIBS-bufr  11.7.0
 All Data Structures Files Functions Variables Pages
rewnbf.f
Go to the documentation of this file.
1 C> @file
2 C> @author WOOLLEN @date 2003-11-04
3 
4 C> THIS SUBROUTINE, DEPENDING ON THE VALUE OF ISR, WILL
5 C> EITHER:
6 C> 1) STORE THE CURRENT PARAMETERS ASSOCIATED WITH A BUFR FILE
7 C> CONNECTED TO LUNIT (READ/WRITE POINTERS, ETC.), SET THE FILE STATUS
8 C> TO READ, THEN REWIND THE BUFR FILE AND POSITION IT SUCH THAT THE
9 C> NEXT BUFR MESSAGE READ WILL BE THE FIRST MESSAGE IN THE FILE
10 C> CONTAINING ACTUAL SUBSETS WITH DATA; OR
11 C> 2) RESTORE THE BUFR FILE CONNECTED TO LUNIT TO THE PARAMETERS
12 C> IT HAD PRIOR TO 1) ABOVE USING THE INFORMATION SAVED IN 1) ABOVE.
13 C>
14 C> THIS ALLOWS INFORMATION TO BE EXTRACTED FROM A PARTICULAR SUBSET IN
15 C> A BUFR FILE WHICH IS IN THE MIDST OF BEING READ FROM OR WRITTEN TO
16 C> BY AN APPLICATION PROGRAM. NOTE THAT FOR A PARTICULAR BUFR FILE 1)
17 C> ABOVE MUST PRECEDE 2) ABOVE. AN APPLICATION PROGRAM MIGHT FIRST
18 C> CALL THIS SUBROUTINE WITH ISR = 0, THEN CALL EITHER BUFR ARCHIVE
19 C> LIBRARY SUBROUTINE RDMGSB OR UFBINX TO GET INFO FROM A SUBSET, THEN
20 C> CALL THIS ROUTINE AGAIN WITH ISR = 1 TO RESTORE THE POINTERS IN THE
21 C> BUFR FILE TO THEIR ORIGINAL LOCATION. ALSO, BUFR ARCHIVE LIBRARY
22 C> SUBROUTINE UFBTAB WILL CALL THIS ROUTINE IF THE BUFR FILE IT IS
23 C> ACTING UPON IS ALREADY OPEN FOR INPUT OR OUTPUT.
24 C>
25 C> PROGRAM HISTORY LOG:
26 C> 2003-11-04 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN VERIFICATION
27 C> VERSION BUT MAY HAVE BEEN IN THE PRODUCTION
28 C> VERSION AT ONE TIME AND THEN REMOVED)
29 C> 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED
30 C> DOCUMENTATION; OUTPUTS MORE COMPLETE
31 C> DIAGNOSTIC INFO WHEN ROUTINE TERMINATES
32 C> ABNORMALLY
33 C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
34 C> 20,000 TO 50,000 BYTES
35 C> 2009-03-23 J. ATOR -- MODIFIED TO HANDLE EMBEDDED BUFR TABLE
36 C> (DICTIONARY) MESSAGES
37 C> 2011-09-26 J. WOOLLEN -- FIXED BUG TO PREVENT SKIP OF FIRST DATA
38 C> MESSAGE AFTER REWIND
39 C> 2012-09-15 J. WOOLLEN -- MODIFIED FOR C/I/O/BUFR INTERFACE;
40 C> REPLACE FORTRAN REWIND WITH C CEWIND
41 C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
42 C>
43 C> USAGE: CALL REWNBF (LUNIT, ISR)
44 C> INPUT ARGUMENT LIST:
45 C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
46 C> ISR - INTEGER: SWITCH:
47 C> 0 = store current parameters associated with
48 C> BUFR file, set file status to read, rewind
49 C> file such that next message read is first
50 C> message containing subset data
51 C> 1 = restore BUFR file with parameters saved
52 C> from the previous call to this routine with
53 C> ISR=0
54 C>
55 C> INPUT FILES:
56 C> UNIT "LUNIT" - BUFR FILE
57 C>
58 C> REMARKS:
59 C> THIS ROUTINE CALLS: BORT I4DY READMG STATUS
60 C> WTSTAT CEWIND
61 C> THIS ROUTINE IS CALLED BY: UFBINX UFBTAB
62 C> Also called by application programs.
63 C>
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 
74 C-----------------------------------------------------------------------
75 C-----------------------------------------------------------------------
76 
77 C TRY TO TRAP BAD CALL PROBLEMS
78 C -----------------------------
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 
91 C STORE FILE PARAMETERS AND SET FOR READING
92 C -----------------------------------------
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 
111 C REWIND THE FILE
112 C ---------------
113 
114  CALL cewind(lun)
115 
116 C RESTORE FILE PARAMETERS AND POSITION IT TO WHERE IT WAS SAVED
117 C -------------------------------------------------------------
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 
142 C EXITS
143 C -----
144 
145  RETURN
146 900 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)
150 901 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)
154 902 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)
158 903 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)
162 905 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
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:31
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:52
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:55
void cewind(f77int *nfile)
This subroutine rewinds a BUFR file back to its beginning.
Definition: cread.c:100
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
This subroutine reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays...
Definition: readmg.f:73
subroutine rewnbf(LUNIT, ISR)
THIS SUBROUTINE, DEPENDING ON THE VALUE OF ISR, WILL EITHER: 1) STORE THE CURRENT PARAMETERS ASSOCIAT...
Definition: rewnbf.f:64