NCEPLIBS-bufr  11.6.0
 All Data Structures Files Functions Variables Pages
rdmgsb.f
Go to the documentation of this file.
1 C> @file
2 C> @author WOOLLEN @date 2003-11-04
3 
4 C> THIS SUBROUTINE OPENS A BUFR FILE IN LOGICAL UNIT LUNIT FOR
5 C> INPUT OPERATIONS, THEN READS A PARTICULAR SUBSET INTO INTERNAL
6 C> SUBSET ARRAYS FROM A PARTICULAR BUFR MESSAGE IN A MESSAGE BUFFER.
7 C> THIS IS BASED ON THE SUBSET NUMBER IN THE MESSAGE AND THE MESSAGE
8 C> NUMBER IN THE BUFR FILE. THE MESSAGE NUMBER DOES NOT INCLUDE THE
9 C> DICTIONARY MESSAGES AT THE BEGINNING OF THE FILE.
10 C>
11 C> PROGRAM HISTORY LOG:
12 C> 2003-11-04 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN VERIFICATION
13 C> VERSION BUT MAY HAVE BEEN IN THE PRODUCTION
14 C> VERSION AT ONE TIME AND THEN REMOVED)
15 C> 2003-11-04 D. KEYSER -- INCORPORATED INTO "UNIFIED" BUFR ARCHIVE
16 C> LIBRARY; UNIFIED/PORTABLE FOR WRF; ADDED
17 C> DOCUMENTATION; OUTPUTS MORE COMPLETE
18 C> DIAGNOSTIC INFO WHEN ROUTINE TERMINATES
19 C> ABNORMALLY
20 C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
21 C> 20,000 TO 50,000 BYTES
22 C> 2009-03-23 J. ATOR -- MODIFY LOGIC TO HANDLE BUFR TABLE MESSAGES
23 C> ENCOUNTERED ANYWHERE IN THE FILE (AND NOT
24 C> JUST AT THE BEGINNING!)
25 C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
26 C>
27 C> USAGE: CALL RDMGSB (LUNIT, IMSG, ISUB)
28 C> INPUT ARGUMENT LIST:
29 C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
30 C> IMSG - INTEGER: POINTER TO BUFR MESSAGE NUMBER TO READ IN
31 C> BUFR FILE
32 C> ISUB - INTEGER: POINTER TO SUBSET NUMBER TO READ IN BUFR
33 C> MESSAGE
34 C>
35 C> INPUT FILES:
36 C> UNIT "LUNIT" - BUFR FILE
37 C>
38 C> REMARKS:
39 C> THIS ROUTINE CALLS: BORT OPENBF READMG READSB
40 C> STATUS UPB
41 C> THIS ROUTINE IS CALLED BY: None
42 C> Normally called only by application
43 C> programs.
44 C>
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 
53 C-----------------------------------------------------------------------
54 C-----------------------------------------------------------------------
55 
56 C OPEN THE FILE AND SKIP TO MESSAGE # IMSG
57 C ----------------------------------------
58 
59  CALL openbf(lunit,'IN',lunit)
60  CALL status(lunit,lun,il,im)
61 
62 C Note that we need to use subroutine READMG to actually read in all
63 C of the messages (including the first (IMSG-1) messages!), just in
64 C 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 
71 C POSITION AT SUBSET # ISUB
72 C -------------------------
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 
85 C EXITS
86 C -----
87 
88  RETURN
89 900 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)
93 901 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)
97 902 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 upb(NVAL, NBITS, IBAY, IBIT)
THIS SUBROUTINE UNPACKS AND RETURNS A BINARY INTEGER CONTAINED WITHIN NBITS BITS OF IBAY...
Definition: upb.f:49
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
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:138
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 rdmgsb(LUNIT, IMSG, ISUB)
THIS SUBROUTINE OPENS A BUFR FILE IN LOGICAL UNIT LUNIT FOR INPUT OPERATIONS, THEN READS A PARTICULAR...
Definition: rdmgsb.f:45
subroutine readsb(LUNIT, IRET)
This subroutine reads the next data subset from a BUFR message into internal arrays.
Definition: readsb.f:47