NCEPLIBS-bufr  12.0.1
rewnbf.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Store or restore parameters associated with a BUFR file.
3 C>
4 C> @author Woollen @date 2003-11-04
5 
6 C> This subroutine, depending on the value of ISR, will
7 C> either:
8 C> - store the current parameters associated with a BUFR file
9 C> connected to LUNIT (read/write pointers, etc.), set the file status
10 C> to read, then rewind the BUFR file and position it such that the
11 C> next BUFR message read will be the first message in the file
12 C> containing actual subsets with data; or
13 C> - restore the BUFR file connected to LUNIT to the parameters
14 C> it had prior to the previous call, and using the information that
15 C> was saved previously
16 C>
17 C> This allows information to be extracted from a particular subset in
18 C> a BUFR file which is in the midst of being read from or written to
19 C> by an application program. Note that, for any given BUFR file, a call
20 C> to this subroutine with ISR = 0 must precede a call to this same
21 C> subroutine with ISR = 1. 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. For example, this subroutine is
26 C> called internally by BUFR archive library subroutine ufbtab() whenever
27 C> the BUFR file it is acting upon is already open for input or output.
28 C>
29 C> @param[in] LUNIT - integer: fortran logical unit number for BUFR file.
30 C> @param[in] ISR - integer: switch:
31 C> - 0 store current parameters associated with BUFR file, set file status to read, and rewind
32 C> file such that next message read is first message containing subset data
33 C> - 1 restore BUFR file with parameters saved from the previous call to this routine with
34 C> ISR = 0
35 C>
36 C> @author Woollen @date 2003-11-04
37  SUBROUTINE rewnbf(LUNIT,ISR)
38 
39  use bufrlib
40 
41  USE moda_msgcwd
42  USE moda_bitbuf
43  USE moda_bufrsr
44 
45  CHARACTER*128 BORT_STR
46 
47  CHARACTER*8 SUBSET
48 
49 C-----------------------------------------------------------------------
50 C-----------------------------------------------------------------------
51 
52 C TRY TO TRAP BAD CALL PROBLEMS
53 C -----------------------------
54 
55  IF(isr.EQ.0) THEN
56  CALL status(lunit,lun,il,im)
57  IF(jsr(lun).NE.0) GOTO 900
58  IF(il.EQ.0) GOTO 901
59  ELSEIF(isr.EQ.1) THEN
60  lun = junn
61  IF(jsr(junn).NE.1) GOTO 902
62  ELSE
63  GOTO 903
64  ENDIF
65 
66 C STORE FILE PARAMETERS AND SET FOR READING
67 C -----------------------------------------
68 
69  IF(isr.EQ.0) THEN
70  junn = lun
71  jill = il
72  jimm = im
73  jbit = ibit
74  jbyt = mbyt(lun)
75  jmsg = nmsg(lun)
76  jsub = nsub(lun)
77  ksub = msub(lun)
78  jnod = inode(lun)
79  jdat = idate(lun)
80  DO i=1,jbyt
81  jbay(i) = mbay(i,lun)
82  ENDDO
83  CALL wtstat(lunit,lun,-1,0)
84  ENDIF
85 
86 C REWIND THE FILE
87 C ---------------
88 
89  CALL cewind_c(lun)
90 
91 C RESTORE FILE PARAMETERS AND POSITION IT TO WHERE IT WAS SAVED
92 C -------------------------------------------------------------
93 
94  IF(isr.EQ.1) THEN
95  lun = junn
96  il = jill
97  im = jimm
98  ibit = jbit
99  mbyt(lun) = jbyt
100  nmsg(lun) = jmsg
101  nsub(lun) = jsub
102  msub(lun) = ksub
103  inode(lun) = jnod
104  idate(lun) = i4dy(jdat)
105  DO i=1,jbyt
106  mbay(i,lun) = jbay(i)
107  ENDDO
108  DO imsg=1,jmsg
109  CALL readmg(lunit,subset,kdate,ier)
110  IF(ier.LT.0) GOTO 905
111  ENDDO
112  CALL wtstat(lunit,lun,il,im)
113  ENDIF
114 
115  jsr(lun) = mod(jsr(lun)+1,2)
116 
117 C EXITS
118 C -----
119 
120  RETURN
121 900 WRITE(bort_str,'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '//
122  . 'PARAMETERS FOR FILE FOR WHICH THEY HAVE ALREADY BEEN SAVED '//
123  . '(AND NOT YET RESTORED) (UNIT",I3,")")') lunit
124  CALL bort(bort_str)
125 901 WRITE(bort_str,'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '//
126  . 'PARAMETERS FOR BUFR FILE WHICH IS NOT OPENED FOR EITHER INPUT'//
127  . ' OR OUTPUT) (UNIT",I3,")")') lunit
128  CALL bort(bort_str)
129 902 WRITE(bort_str,'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '//
130  . 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")')
131  . lunit
132  CALL bort(bort_str)
133 903 WRITE(bort_str,'("BUFRLIB: REWNBF - SAVE/RESTORE SWITCH (INPUT '//
134  . 'ARGUMENT ISR) IS NOT ZERO OR ONE (HERE =",I4,") (UNIT",I3,")")')
135  . isr,lunit
136  CALL bort(bort_str)
137 905 WRITE(bort_str,'("BUFRLIB: REWNBF - HIT END OF FILE BEFORE '//
138  . 'REPOSITIONING BUFR FILE IN UNIT",I3," TO ORIGINAL MESSAGE '//
139  . 'NO.",I5)') lunit,jmsg
140  CALL bort(bort_str)
141  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive 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:24
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Definition: bufrlib.F90:11
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer ibit
Bit pointer within IBAY.
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
This module contains arrays and variables needed to store the current position within a BUFR file.
integer jill
File status indicator of BUFR file.
integer jimm
Message status indicator of BUFR file.
integer, dimension(:), allocatable jsr
Indicator of stack status when entering subroutine rewnbf().
integer jmsg
Sequential number of BUFR message, counting from the beginning of the file.
integer jdat
Section 1 date-time of BUFR message.
integer jnod
Positional index of Table A mnemonic within internal Table A.
integer jbit
Bit pointer within BUFR message.
integer jsub
Sequential number of BUFR data subset, counting from the beginning of the current BUFR message.
integer junn
Internal I/O stream index of BUFR file.
integer ksub
Bit-wise (integer) representation of FXY value associated with Table A mnemonic for BUFR message.
integer jbyt
Length (in bytes) of BUFR message.
integer, dimension(:), allocatable jbay
BUFR message.
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
integer, dimension(:), allocatable idate
Section 1 date-time of message.
integer, dimension(:), allocatable nmsg
Current message pointer within logical unit.
integer, dimension(:), allocatable msub
Total number of data subsets in message.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
recursive subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
Reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays.
Definition: readmg.f:52
subroutine rewnbf(LUNIT, ISR)
This subroutine, depending on the value of ISR, will either:
Definition: rewnbf.f:38
recursive subroutine status(LUNIT, LUN, IL, IM)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
Definition: status.f:36
subroutine wtstat(LUNIT, LUN, IL, IM)
Update file status in library internals.
Definition: wtstat.f:37