NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
ufbpos.f
Go to the documentation of this file.
1 C> @file
2 C> @author WOOLLEN @date 1995-11-22
3 
4 C> THIS SUBROUTINE SHOULD ONLY BE CALLED WHEN LOGICAL UNIT
5 C> LUNIT HAS BEEN OPENED FOR INPUT OPERATIONS. IT POSITIONS THE
6 C> MESSAGE POINTER TO A USER-SPECIFIED BUFR MESSAGE NUMBER IN THE FILE
7 C> CONNECTED TO LUNIT AND THEN CALLS BUFR ARCHIVE LIBRARY SUBROUTINE
8 C> READMG TO READ THIS BUFR MESSAGE INTO A MESSAGE BUFFER (ARRAY MBAY
9 C> IN MODULE BITBUF). IT THEN POSITIONS THE SUBSET POINTER TO
10 C> A USER-SPECIFIED SUBSET NUMBER WITHIN THE BUFR MESSAGE AND CALLS
11 C> BUFR ARCHIVE LIBRARY SUBROUTINE READSB TO READ THIS SUBSET INTO
12 C> INTERNAL SUBSET ARRAYS. THE BUFR MESSAGE HERE MAY BE EITHER
13 C> COMPRESSED OR UNCOMPRESSED. THE USER-SPECIFIED MESSAGE NUMBER DOES
14 C> NOT INCLUDE ANY DICTIONARY MESSAGES THAT MAY BE AT THE TOP OF THE
15 C> FILE).
16 C>
17 C> PROGRAM HISTORY LOG:
18 C> 1995-11-22 J. WOOLLEN -- ORIGINAL AUTHOR (WAS IN-LINED IN PROGRAM
19 C> NAM_STNMLIST)
20 C> 2005-03-04 D. KEYSER -- ADDED TO BUFR ARCHIVE LIBRARY; ADDED
21 C> DOCUMENTATION
22 C> 2005-11-29 J. ATOR -- USE IUPBS01 AND RDMSGW
23 C> 2006-04-14 J. ATOR -- REMOVE UNNECESSARY MOIN INITIALIZATION
24 C> 2009-03-23 J. ATOR -- MODIFIED TO HANDLE EMBEDDED BUFR TABLE
25 C> (DICTIONARY) MESSAGES
26 C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
27 C>
28 C> USAGE: CALL UFBPOS( LUNIT, IREC, ISUB, SUBSET, JDATE )
29 C> INPUT ARGUMENT LIST:
30 C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
31 C> IREC - INTEGER: POINTER TO BUFR MESSAGE NUMBER (RECORD) IN
32 C> FILE (DOES NOT INCLUDE ANY DICTIONARY MESSSAGES THAT
33 C> MAY BE AT THE TOP OF THE FILE)
34 C> ISUB - INTEGER: POINTER TO SUBSET NUMBER TO READ IN BUFR
35 C> MESSAGE
36 C>
37 C> OUTPUT ARGUMENT LIST:
38 C> SUBSET - CHARACTER*8: TABLE A MNEMONIC FOR TYPE OF BUFR MESSAGE
39 C> BEING READ
40 C> JDATE - INTEGER: DATE-TIME STORED WITHIN SECTION 1 OF BUFR
41 C> MESSAGE BEING READ, IN FORMAT OF EITHER YYMMDDHH OR
42 C> YYYYMMDDHH, DEPENDING ON DATELEN() VALUE
43 C>
44 C> REMARKS:
45 C> THIS ROUTINE CALLS: BORT CEWIND NMSUB READMG
46 C> READSB STATUS UFBCNT UPB
47 C> THIS ROUTINE IS CALLED BY: None
48 C> Normally called only by application
49 C> programs.
50 C>
51  SUBROUTINE ufbpos(LUNIT,IREC,ISUB,SUBSET,JDATE)
52 
53  USE moda_msgcwd
54  USE moda_bitbuf
55 
56  CHARACTER*128 bort_str
57  CHARACTER*8 subset
58 
59 C-----------------------------------------------------------------------
60 C----------------------------------------------------------------------
61 
62 C MAKE SURE A FILE IS OPEN FOR INPUT
63 C ----------------------------------
64 
65  CALL status(lunit,lun,il,im)
66  IF(il.EQ.0) goto 900
67  IF(il.GT.0) goto 901
68 
69  IF(irec.LE.0) goto 902
70  IF(isub.LE.0) goto 903
71 
72 C SEE WHERE POINTERS ARE CURRENTLY LOCATED
73 C ----------------------------------------
74 
75  CALL ufbcnt(lunit,jrec,jsub)
76 
77 C REWIND FILE IF REQUESTED POINTERS ARE BEHIND CURRENT POINTERS
78 C -------------------------------------------------------------
79 
80  IF(irec.LT.jrec .OR. (irec.EQ.jrec.AND.isub.LT.jsub)) THEN
81  CALL cewind(lun)
82  nmsg(lun) = 0
83  nsub(lun) = 0
84  CALL ufbcnt(lunit,jrec,jsub)
85  ENDIF
86 
87 C READ SUBSET #ISUB FROM MESSAGE #IREC FROM FILE
88 C ----------------------------------------------
89 
90  DO WHILE (irec.GT.jrec)
91  CALL readmg(lunit,subset,jdate,iret)
92  IF(iret.LT.0) goto 904
93  CALL ufbcnt(lunit,jrec,jsub)
94  ENDDO
95 
96  ksub = nmsub(lunit)
97  IF(isub.GT.ksub) goto 905
98 
99  DO WHILE (isub-1.GT.jsub)
100  ibit = mbyt(lun)*8
101  CALL upb(nbyt,16,mbay(1,lun),ibit)
102  mbyt(lun) = mbyt(lun) + nbyt
103  nsub(lun) = nsub(lun) + 1
104  CALL ufbcnt(lunit,jrec,jsub)
105  ENDDO
106 
107  CALL readsb(lunit,iret)
108  IF(iret.NE.0) goto 905
109 
110 C EXITS
111 C -----
112 
113  RETURN
114 900 CALL bort('BUFRLIB: UFBPOS - INPUT BUFR FILE IS CLOSED, IT MUST'//
115  . ' BE OPEN FOR INPUT')
116 901 CALL bort('BUFRLIB: UFBPOS - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
117  . ', IT MUST BE OPEN FOR INPUT')
118 902 WRITE(bort_str,'("BUFRLIB: UFBPOS - REQUESTED MESSAGE NUMBER '//
119  . 'TO READ IN (",I5,") IS NOT VALID")') irec
120  CALL bort(bort_str)
121 903 WRITE(bort_str,'("BUFRLIB: UFBPOS - REQUESTED SUBSET NUMBER '//
122  . 'TO READ IN (",I5,") IS NOT VALID")') isub
123  CALL bort(bort_str)
124 904 WRITE(bort_str,'("BUFRLIB: UFBPOS - REQUESTED MESSAGE NUMBER '//
125  . 'TO READ IN (",I5,") EXCEEDS THE NUMBER OF MESSAGES IN THE '//
126  . 'FILE (",I5,")")') irec,jrec
127  CALL bort(bort_str)
128 905 WRITE(bort_str,'("BUFRLIB: UFBPOS - REQ. SUBSET NUMBER TO READ'//
129  . ' IN (",I3,") EXCEEDS THE NUMBER OF SUBSETS (",I3,") IN THE '//
130  . 'REQ. MESSAGE (",I5,")")') isub,ksub,irec
131  CALL bort(bort_str)
132  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 ufbpos(LUNIT, IREC, ISUB, SUBSET, JDATE)
THIS SUBROUTINE SHOULD ONLY BE CALLED WHEN LOGICAL UNIT LUNIT HAS BEEN OPENED FOR INPUT OPERATIONS...
Definition: ufbpos.f:51
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:61
void cewind(f77int *nfile)
This subroutine rewinds a BUFR file back to its beginning.
Definition: cread.c:90
function nmsub(LUNIT)
This function returns the total number of data subsets available within the BUFR message that was mos...
Definition: nmsub.f:31
subroutine ufbcnt(LUNIT, KMSG, KSUB)
THIS SUBROUTINE RETURNS A COUNT OF THE CURRENT MESSAGE NUMBER AND SUBSET NUMBER, WHERE THE MESSAGE NU...
Definition: ufbcnt.f:55
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
subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
This subroutine reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays...
Definition: readmg.f:99
subroutine readsb(LUNIT, IRET)
This subroutine reads the next data subset from a BUFR message into internal arrays.
Definition: readsb.f:59