SUBROUTINE BT_BLNX ( kray, lenb, bulltn, iret ) C************************************************************************ C* BT_BLNX * C* * C* This subroutine checks if the bulletin contains trackob reports. If * C* it does not, then no action is taken. If it does, then a check is * C* made to see whether each hourly trackob report begins with the groups* C* NNXX YYMMJ and ends with the ship's call sign. If it does, then no * C* further action is needed. If it does not, then the appropriate NNXX * C* YYMMJ groups are inserted before each hourly report and the ship's * C* call sign is inserted at the end of each report. This procedure is * C* done to have the reports in this bulletin be formatted in the way * C* that the decoding routines expect them. * C* A check is made of the bulletin to see if it contains garbled * C* reports. If it does, the garbled reports will be tossed out. When * C* the first report in a bulletin is garbled, the bulletin is rejected. * C* * C* Input parameters: * C* KRAY INTEGER Working array * C* * C* Input and output parameters: * C* LENB INTEGER On input, length of bulletin; on* C* ouput, length of bulletin after * C* NNXX YYMMJ groups and ship's * C* call sign added to bulletin * C* BULLTN CHAR* On input, raw bulletin; on * C* output, raw bulletin with NNXXX * C* YYMMJ groups and ship's call * C* sign added to it * C* * C* Output parameters: * C* IFLG4 INTEGER Flag to indicate whether to * C* save 4-group values * C* IRET INTEGER Return code * C* 0 = normal return * C* 1 = problems * C* * C** * C* Log: * C* R. Hollern/NCEP 3/99 * C* R. Hollern/NCEP 4/00 Added check for JJVV and KKYY reports * C* and corrected logic problem * C* J. Ator/NCEP 11/12 Increase istgr2 size from 50 to 300 * C************************************************************************ INCLUDE 'btcmn.cmn' C* INTEGER innxx(50) C* CHARACTER*(*) bulltn, kray C* LOGICAL more, more1, more2 C* CHARACTER*20 istrg1, ishipc, istrg2(300) C----------------------------------------------------------------------- iret = 0 jr = 0 jend = lenb - 10 C i = 1 C DO WHILE ( i .lt. jend ) C IF ( bulltn(i:i+3) .eq. 'NNXX' ) THEN C C* Location in bulltn of start of NNXX string. C jr = jr + 1 innxx(jr) = i ELSE IF ( bulltn(i:i+3) .eq. 'JJYY' .or. + bulltn(i:i+3) .eq. 'JJVV' ) THEN C C* Bathy reports. C RETURN ELSE IF ( bulltn(i:i+3) .eq. 'KKXX' .or. + bulltn(i:i+3) .eq. 'KKYY' ) THEN C C* Tesac reports. C RETURN END IF C i = i + 1 C IF ( jr .eq. 50 ) i = jend C END DO C IF ( jr .eq. 0 ) THEN iret = 1 RETURN END IF C C* Check if bulletin contains garbled reports. C more = .true. ij = 0 C DO WHILE ( more ) C C* Next NNXX report. C ij = ij + 1 C IF ( ij .eq. jr ) more = .false. C ka = innxx(ij) C IF ( ij .lt. jr ) THEN kb = innxx(ij+1) - 8 ELSE kb = lenb - 8 END IF C i = 0 C C* If any groups in report are not separated by a blank, C* then reject this report or entire bulletin. C i = 0 ik = ka more1 = .true. C DO WHILE ( more1 ) C IF ( bulltn(ik:ik) .eq. ' ' ) THEN i = 0 ELSE i = i + 1 END IF C IF ( i .gt. 7 ) THEN IF ( ij .eq. 1 ) THEN iret = 1 ierrno = -4 CALL BT_ERRS ( ierrno, bulltn(ka:ka+20), jret ) RETURN ELSE C C* This report is garbled, but previous ones C* may not be. C lenb = ka - 1 jr = ij - 1 more = .false. ik = kb ierrno = -5 CALL BT_ERRS ( ierrno, bulltn(ka:ka+20), jret ) END IF END IF C ik = ik + 1 C IF ( ik .ge. kb ) THEN more1 = .false. END IF C END DO C END DO C C* Get the ship's call sign. C IF ( bulltn(lenb:lenb) .eq. '=' ) THEN mm = lenb - 1 ELSE mm = lenb END IF C ishipc = ' ' mshp = 0 more2 = .true. ij = mm C DO WHILE ( more2 ) IF ( bulltn(ij:ij) .eq. ' ' ) THEN ishipc = bulltn(ij+1:mm) more2 = .false. ELSE mshp = mshp + 1 ij = ij - 1 END IF END DO C DO ij = 1, jr C ka = innxx(ij) istrg1 = bulltn(ka:ka+10) C C* Build string consisting of ship's call sign D...D followed C* by the groups NNXX YYMMJ. C istrg2(ij) = ' ' istrg2(ij) = ishipc(1:mshp+1) // istrg1(1:11) C END DO C jr = 0 jh = 0 j = 0 l1 = -1 C C* Insert D...D NNXX YYMMJ groups before the appropriate hourly C* reports. C DO i = 1,lenb C IF ( bulltn(i:i+3) .eq. 'NNXX' ) THEN jr = jr + 1 jh = 1 l1 = INDEX ( istrg2 (jr) , ' ' ) END IF C IF ( bulltn( i+5:i+6 ) .EQ. '/ ' .AND. jh .EQ. 1 ) THEN C C* IF the report started with 'NNXX', then the next two C* groups will be YYMMJ GGgg/. C j = j + 1 kray ( j:j ) = bulltn ( i:i ) jh = 0 ELSE IF ( jh .eq. 0 .and. + ( bulltn( i+5:i+7 ) .eq. '/ 1' .or. + bulltn( i+5:i+7 ) .eq. '/ 3' .or. + bulltn( i+5:i+7 ) .eq. '/ 5' .or. + bulltn( i+5:i+7 ) .eq. '/ 7' ) ) THEN C IF ( l1 .eq. -1 ) THEN iret = 1 RETURN END IF C C* Insert the NNXX YYMMJ groups at start of report. C j = j + 1 kray ( j:j ) = bulltn ( i:i ) j = j + 1 kray ( j:j+l1-1 ) = istrg2(jr) ( 1:l1) j = j + l1 - 1 ELSE j = j + 1 kray ( j:j ) = bulltn ( i:i ) END IF C END DO C lenb = j C C* Move modified bulletin back into bulltn array. C DO i = 1, lenb bulltn ( i:i ) = kray ( i:i ) END DO C* RETURN END