NCEPLIBS-bufr 11.7.1
rdmgsb.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 2003-11-04
3
4C> THIS SUBROUTINE OPENS A BUFR FILE IN LOGICAL UNIT LUNIT FOR
5C> INPUT OPERATIONS, THEN READS A PARTICULAR SUBSET INTO INTERNAL
6C> SUBSET ARRAYS FROM A PARTICULAR BUFR MESSAGE IN A MESSAGE BUFFER.
7C> THIS IS BASED ON THE SUBSET NUMBER IN THE MESSAGE AND THE MESSAGE
8C> NUMBER IN THE BUFR FILE. THE MESSAGE NUMBER DOES NOT INCLUDE THE
9C> DICTIONARY MESSAGES AT THE BEGINNING OF THE FILE.
10C>
11C> PROGRAM HISTORY LOG:
12C> 2003-11-04 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN VERIFICATION
13C> VERSION BUT MAY HAVE BEEN IN THE PRODUCTION
14C> VERSION AT ONE TIME AND THEN REMOVED)
15C> 2003-11-04 D. KEYSER -- INCORPORATED INTO "UNIFIED" BUFR ARCHIVE
16C> LIBRARY; UNIFIED/PORTABLE FOR WRF; ADDED
17C> DOCUMENTATION; OUTPUTS MORE COMPLETE
18C> DIAGNOSTIC INFO WHEN ROUTINE TERMINATES
19C> ABNORMALLY
20C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
21C> 20,000 TO 50,000 BYTES
22C> 2009-03-23 J. ATOR -- MODIFY LOGIC TO HANDLE BUFR TABLE MESSAGES
23C> ENCOUNTERED ANYWHERE IN THE FILE (AND NOT
24C> JUST AT THE BEGINNING!)
25C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
26C>
27C> USAGE: CALL RDMGSB (LUNIT, IMSG, ISUB)
28C> INPUT ARGUMENT LIST:
29C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
30C> IMSG - INTEGER: POINTER TO BUFR MESSAGE NUMBER TO READ IN
31C> BUFR FILE
32C> ISUB - INTEGER: POINTER TO SUBSET NUMBER TO READ IN BUFR
33C> MESSAGE
34C>
35C> INPUT FILES:
36C> UNIT "LUNIT" - BUFR FILE
37C>
38C> REMARKS:
39C> THIS ROUTINE CALLS: BORT OPENBF READMG READSB
40C> STATUS UPB
41C> THIS ROUTINE IS CALLED BY: None
42C> Normally called only by application
43C> programs.
44C>
45 SUBROUTINE rdmgsb(LUNIT,IMSG,ISUB)
46
47 USE moda_msgcwd
48 USE moda_bitbuf
49
50 CHARACTER*128 BORT_STR
51 CHARACTER*8 SUBSET
52
53C-----------------------------------------------------------------------
54C-----------------------------------------------------------------------
55
56C OPEN THE FILE AND SKIP TO MESSAGE # IMSG
57C ----------------------------------------
58
59 CALL openbf(lunit,'IN',lunit)
60 CALL status(lunit,lun,il,im)
61
62C Note that we need to use subroutine READMG to actually read in all
63C of the messages (including the first (IMSG-1) messages!), just in
64C case there are any embedded dictionary messages in the file.
65
66 DO i=1,imsg
67 CALL readmg(lunit,subset,jdate,iret)
68 IF(iret.LT.0) GOTO 901
69 ENDDO
70
71C POSITION AT SUBSET # ISUB
72C -------------------------
73
74 DO i=1,isub-1
75 IF(nsub(lun).GT.msub(lun)) GOTO 902
76 ibit = mbyt(lun)*8
77 CALL upb(nbyt,16,mbay(1,lun),ibit)
78 mbyt(lun) = mbyt(lun) + nbyt
79 nsub(lun) = nsub(lun) + 1
80 ENDDO
81
82 CALL readsb(lunit,iret)
83 IF(iret.NE.0) GOTO 902
84
85C EXITS
86C -----
87
88 RETURN
89900 WRITE(bort_str,'("BUFRLIB: RDMGSB - ERROR READING MESSAGE '//
90 . '(RECORD) NUMBER",I5," IN INPUT BUFR FILE CONNECTED TO UNIT",'//
91 . 'I4)') i,lunit
92 CALL bort(bort_str)
93901 WRITE(bort_str,'("BUFRLIB: RDMGSB - HIT END OF FILE BEFORE '//
94 . 'READING REQUESTED MESSAGE NO.",I5," IN BUFR FILE CONNECTED TO'//
95 . ' UNIT",I4)') imsg,lunit
96 CALL bort(bort_str)
97902 WRITE(bort_str,'("BUFRLIB: RDMGSB - ALL SUBSETS READ BEFORE '//
98 . 'READING REQ. SUBSET NO.",I3," IN REQ. MSG NO.",I5," IN BUFR '//
99 . 'FILE CONNECTED TO UNIT",I4)') isub,imsg,lunit
100 CALL bort(bort_str)
101 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
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 openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:139
subroutine rdmgsb(LUNIT, IMSG, ISUB)
THIS SUBROUTINE OPENS A BUFR FILE IN LOGICAL UNIT LUNIT FOR INPUT OPERATIONS, THEN READS A PARTICULAR...
Definition: rdmgsb.f:46
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 readsb(LUNIT, IRET)
This subroutine reads the next data subset from a BUFR message into internal arrays.
Definition: readsb.f:48
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 upb(NVAL, NBITS, IBAY, IBIT)
THIS SUBROUTINE UNPACKS AND RETURNS A BINARY INTEGER CONTAINED WITHIN NBITS BITS OF IBAY,...
Definition: upb.f:50