SUBROUTINE CX_SECS( lenmsg, crexmsg, jpos, iret ) C************************************************************************ C* CX_SC01 * C* * C* This subroutine checks that the CREX message contains a valid * C* Section 0 - the Indicator section and a valid Section 4 - the End * C* section. If either of these two sections are missing or incorrectly * C* coded, this is a fatal error and the message cannot be decoded. A * C* search is also made for Section 3 - the Optional section. If the * C* message contains a Section 3, it is not decoded. A log message is * C* generated to inform the user of this. * C* * C* CX_SECS ( LENMSG, CREXMSG, JPOS, IRET ) * C* * C* Input parameters: * C* LENMSG INTEGER CREX message length * C* CREXMSG CHAR* CREX message * C* * C* Input and output parameters: * C* JPOS INTEGER Points to start of Section 0 on * C* input; to start of Section 1 * C* on output * C* * C* Output parameters: * C* IRET INTEGER Return code * C* 0 = normal return * C* 1 = CREX message rejected * C* * C** * C* Log: * C* R. Hollern/NCEP 8/03 * C************************************************************************ INCLUDE 'cxcmn.cmn' C* INTEGER lenmsg, jpos, iret C* LOGICAL bbb C* CHARACTER*(*) crexmsg C----------------------------------------------------------------------- iret = 0 loglvl = 2 C jpos = INDEX ( crexmsg(1:lenmsg), 'CREX++' ) C IF ( jpos .eq. 0 ) THEN C C* Reject message. C iret = 1 logmsg = ' ' logmsg(1:38) = 'CREX Section 0 problems -- FATAL ERROR' CALL DC_WLOG( loglvl, 'CX', 2, logmsg, ierwlg ) RETURN END IF C jpos = jpos + 7 C C* Check that the CREX message contains the "End Section (7777). C C* Search backwards for the 7777 group. C bbb = .true. C ipos = lenmsg C DO WHILE ( bbb ) IF ( crexmsg(ipos:ipos) .eq. '7' ) THEN IF ( crexmsg(ipos-3:ipos-1) .ne. '777' .OR. + ipos .lt. 20 ) THEN C C* Reject message. C iret = 1 logmsg = ' ' logmsg(1:34) = 'CREX Section 4 - End Section 7777 ' logmsg(35:62) = 'group missing -- FATAL ERROR' CALL DC_WLOG( loglvl, 'CX', 2, logmsg, ierwlg ) RETURN ELSE bbb = .false. END IF ELSE ipos = ipos - 1 END IF END DO C C* Check if the message contains Section 3 - Optional section. C icnt = 0 C DO i = 1, lenmsg C IF ( crexmsg(i:i+1) .eq. '++' ) THEN icnt = icnt + 1 END IF C IF ( icnt .eq. 3 ) THEN C ipos = INDEX ( crexmsg(i:lenmsg), 'SUPP' ) C IF ( ipos .gt. 0 ) THEN logmsg = ' ' logmsg(1:34) = 'CREX Section 3 - OPTIONAL SECTION ' logmsg(35:52) = 'is not decoded!!! ' CALL DC_WLOG( loglvl, 'CX', 2, logmsg, ierwlg ) END IF C RETURN END IF C END DO C* RETURN END