SUBROUTINE BF_SRCH ( ifn, isbyte, length, nxtbyt, messg, iret ) C************************************************************************ C* BF_SRCH * C* * C* This subroutine searchs for the next BUFR record. If no record is * C* found, iret = -1. * C* * C* BF_SRCH ( IFN, ISBYTE, LENGTH, NXTBYT, MESSG, IRET ) * C* * C* Input parameter: * C* IFN INTEGER BUFR file number * C* ISBYTE INTEGER Byte at which to begin search * C* * C* Output parameters: * C* LENGTH INTEGER Length of BUFR record in bytes * C* NXTBYT INTEGER Next byte to start search * C* MESSG INTEGER BUFR message * C* IRET INTEGER Return code * C* 0 = normal return * C* -1 = no BUFR record found * C* -2 = BUFR record not read * C** * C* Log: * C* K. Brill/NMC 5/94 * C************************************************************************ INTEGER messg (*) C* CHARACTER check*4 CHARACTER*32 errstr INTEGER idata (4) LOGICAL done C----------------------------------------------------------------------- iret = 0 done = .false. C* ipass = 0 ioffst = isbyte - 1 DO WHILE ( iret .eq. 0 .and. .not. done ) C C* Look at the next 4 bytes to see if a BUFR header is there. C CALL DA_READ ( ifn, 4, ioffst, check, iret ) IF ( iret .ne. 0 ) THEN iret = -1 errstr = 'READ failed before BUFR found.' CALL ER_WMSG ( 'BF', iret, 'READ FAILED', ier ) RETURN ELSE iq = INDEX ( check, 'BUFR' ) IF ( iq .ne. 0 ) THEN istbyt = ioffst ioffst = ioffst + 4 done = .true. ELSE ioffst = ioffst + 1 END IF END IF END DO C C* Read in next four bytes to get the length. C CALL DA_READ ( ifn, 4, ioffst, idata, ier ) C* CALL GB_BYIN ( idata, 1, idata, ier ) C C* Compute the length. C CALL GB_IBYT ( idata, 3, .false., length, ier ) C C* Get the entire BUFR message. C CALL DA_READ ( ifn, length, istbyt, messg, ier ) IF ( ier .ne. 0 ) THEN iret = -2 errstr = 'BUFR record not read.' CALL ER_WMSG ( 'BF', iret, errstr, ier ) RETURN END IF nxtbyt = istbyt + length + 1 C* RETURN C* END