SUBROUTINE TA_DECD ( cldt, tafile, bufrtn, nhours, iret ) C************************************************************************ C* TA_DECD * C* * C* This routine decodes files containing TAMDAR BUFR data from * C* AirDat/Panasonic into NCEP BUFR format. * C* * C* TA_DECD ( CLDT, TAFILE, BUFRTN, NHOURS, IRET ) * C* * C* Input parameters: * C* CLDT CHAR* Date-time from command line * C* TAFILE CHAR* TAMDAR BUFR file from AirDat * C* BUFRTN CHAR* NCEP BUFR table file * C* NHOURS INTEGER Max # of hours before run time * C* for creating BUFR output * C* * C* Output parameters: * C* IRET INTEGER Return code: * C* 0 = normal return * C* * C** * C* Log: * C* C. Caruso Magee/NCEP 07/07 * C* C. Caruso Magee/NCEP 10/07 Add pressure (007004) to input descriptor* C* list. * C* J. Ator/NCEP 10/08 Added capability to process from BUFRT2 * C* J. Ator/NCEP 11/15 Resurrected for WCOSS * C* J. Ator/NCEP 03/18 Update values for RSRD and EXPRSRD * C* J. Ator/NCEP 09/20 Add GNSA to list of processed parameters * C************************************************************************ INCLUDE 'GEMPRM.PRM' INCLUDE 'BRIDGE.PRM' C* CHARACTER*(*) cldt, tafile, bufrtn C* PARAMETER ( DCMXBFD4 = DCMXBF / 4 ) C* CHARACTER cbull*(DCMXBF), bfstyp*8, + rundt*12, sysdt*12, cval*8, logmsg*200, + tafiled*(DCMXLN), tafileb*(DCMXLN), + bufr(DCMXBF)*1, + bufrdn*(DCMXLN), bufrbn*(DCMXLN) C* INTEGER irundt ( 5 ), irptdt ( 5 ), + ibull ( DCMXBFD4 ), mbay ( DCMXBFD4 ) C* LOGICAL msgok C* PARAMETER ( MXMN = 10, MXLV = 5 ) C* REAL*8 r8in ( MXMN, MXLV ), + GETVALNB, r8afsi2, r8afsi7 C* EQUIVALENCE ( cbull (1:4), ibull (1) ) EQUIVALENCE ( bufr (1), mbay (1) ) C* INCLUDE 'ERMISS.FNC' C*----------------------------------------------------------------------- iret = 0 C C* Get the BUFR tables directory from the tables file. This C* directory will be passed to subroutine MTINFO as the location C* in which to search for any needed master table files. C CALL FL_PATH ( bufrtn, bufrdn, bufrbn, ierpth ) C C* Start a new entry for this TAMDAR file in the decoder log. C logmsg = '########################################' CALL DC_WLOG ( 2, 'DC', 2, logmsg, ierwlg ) CALL FL_PATH ( tafile, tafiled, tafileb, ierpth ) logmsg = 'TAMDAR filename: ' // tafileb CALL DC_WLOG ( 0, 'DC', 2, logmsg, ierwlg ) C C* Open the BUFR messages file. C CALL FL_GLUN ( iubfma, iergln ) IF ( iergln .ne. 0 ) THEN CALL DC_WLOG ( 0, 'FL', iergln, ' ', ierwlg ) RETURN END IF OPEN ( UNIT = iubfma, FILE = '.dummy/dctama', + FORM = 'UNFORMATTED' ) CALL OPENBF ( iubfma, 'SEC3', iubftn ) CALL MTINFO ( bufrdn, 98, 99 ) C C* Open the tables file for the NCEP BUFR (i.e. output) stream. C CALL FL_SOPN ( bufrtn, iubftn, ierspn ) IF ( ierspn .ne. 0 ) THEN CALL DC_WLOG ( 0, 'FL', ierspn, bufrtn, ierwlg ) RETURN END IF C C* Open the messages file for the NCEP BUFR (i.e. output) stream. C CALL FL_GLUN ( iubfmn, iergln ) IF ( iergln .ne. 0 ) THEN CALL DC_WLOG ( 0, 'FL', iergln, ' ', ierwlg ) RETURN END IF C C* Connect the tables and messages files for the C* NCEP BUFR (i.e. output) stream. C CALL OPENBF ( iubfmn, 'NUL', iubftn ) C C* Specify that NCEP BUFR (i.e. output) messages are to be C* encoded using edition 4 and up to 50K bytes in size. C CALL PKVS01 ( 'BEN', 4 ) CALL MAXOUT ( 50000 ) C C* Close the tables file for the NCEP BUFR (i.e. output) stream. C CALL FL_CLOS ( iubftn, iercls ) IF ( iercls .ne. 0 ) THEN CALL DC_WLOG ( 0, 'FL', iercls, ' ', ierwlg ) END IF C C* Get the system time. C itype = 1 CALL CSS_GTIM ( itype, sysdt, iergtm ) IF ( iergtm .ne. 0 ) THEN CALL DC_WLOG ( 2, 'SS', iergtm, ' ', ierwlg ) END IF C C* If a date-time was entered on the command line, then use it as C* the run date-time. Otherwise, use the system time as the run C* date-time. C IF ( cldt .eq. 'SYSTEM' ) THEN rundt = sysdt ELSE CALL TI_STAN ( cldt, sysdt, rundt, ierstn ) IF ( ierstn .ne. 0 ) THEN CALL DC_WLOG ( 2, 'TI', ierstn, ' ', ierwlg ) RETURN END IF END IF C C* Convert the run date-time to integer. C CALL TI_CTOI ( rundt, irundt, iercto ) IF ( iercto .ne. 0 ) THEN CALL DC_WLOG ( 2, 'TI', iercto, ' ', ierwlg ) RETURN END IF C C* Open the input file for reading BUFR messages. C CALL COBFL ( tafile, 'r' ) C DO WHILE ( .true. ) C C* Get the next BUFR message from the input file. C CALL CRBMG ( bufr, DCMXBF, nbyt, ierr ) IF ( ierr .eq. 0 ) THEN msgok = .true. C C* Pad the end of the message with zeroed-out bytes up to the C* next 8-byte boundary. C CALL PADMSG ( mbay, DCMXBFD4, npbyt ) lenb = nbyt + npbyt C C* Copy character array bufr into character string bull. C DO i = 1, lenb cbull ( i:i ) = bufr ( i ) END DO ELSE IF ( ierr .gt. 0 ) THEN C C* Skip this message. C msgok = .false. CALL UT_EMSG ( 0, 'CRBMG', ierr ) ELSE C C* We are finished processing this file. Make sure all BUFR C* output is flushed to the output stream and close up shop. C CALL UT_WBFR ( iubfmn, 'tamdar2', 1, ierwbf ) CALL CLOSBF ( iubfmn ) CALL FL_CLAL ( iercal ) CALL CCBFL RETURN END IF C IF ( msgok ) THEN C C* Read the BUFR message. C CALL READERME ( ibull, iubfma, bfstyp, ibfdt, ierrme ) IF ( ierrme .ne. 0 ) THEN msgok = .false. ELSE CALL TA_CKS3 ( ibull, iercs3 ) END IF END IF C nrept = 0 C DO WHILE ( msgok ) C C* Get the next report from this BUFR message. C IF ( IREADSB ( iubfma ) .ne. 0 ) THEN C C* There are no more reports in this message. C msgok = .false. C C* Print a count of the number of reports processed. C WRITE ( UNIT = logmsg, FMT = '( A, I4, A )' ) + 'processed BUFR message with ', nrept, ' reports' CALL DC_WLOG ( 2, 'DC', 2, logmsg, ierwlg ) ELSE nrept = nrept + 1 C C* Don't create BUFR output for reports that are more than C* NHOURS before or more than 3 hours after the run time. C CALL UFBINT ( iubfma, r8in, MXMN, MXLV, nlv, + 'YEAR MNTH DAYS HOUR MINU SECO' ) rptyr = UT_BMRI ( r8in (1,1) ) rptmo = UT_BMRI ( r8in (2,1) ) rptdy = UT_BMRI ( r8in (3,1) ) rpthr = UT_BMRI ( r8in (4,1) ) rptmi = UT_BMRI ( r8in (5,1) ) IF ( ( ERMISS ( rptyr ) ) .or. + ( ERMISS ( rptmo ) ) .or. + ( ERMISS ( rptdy ) ) .or. + ( ERMISS ( rpthr ) ) .or. + ( ERMISS ( rptmi ) ) ) THEN iertmk = -1 ELSE irptdt (1) = INT ( rptyr ) irptdt (2) = INT ( rptmo ) irptdt (3) = INT ( rptdy ) irptdt (4) = INT ( rpthr ) irptdt (5) = INT ( rptmi ) CALL DC_TMCK ( 2, irundt, irptdt, nhours, 180, + iertmk ) END IF C IF ( iertmk .eq. 0 ) THEN C C* Open a BUFR message for output. C ibfdt = ( irptdt (1) * 1000000 ) + + ( irptdt (2) * 10000 ) + + ( irptdt (3) * 100 ) + irptdt (4) CALL OPENMB ( iubfmn, 'NC004010', ibfdt ) C C* Store the date and time. C CALL UFBINT ( iubfmn, r8in, MXMN, 1, nlv, + 'YEAR MNTH DAYS HOUR MINU SECO' ) C C* Location metadata. C CALL UFBINT ( iubfma, r8in, MXMN, MXLV, nlv, + 'CLATH CLONH HMSL FLVLST IALR POAF SMMO GNSA' ) CALL UFBINT ( iubfmn, r8in, MXMN, 1, nlv, + 'CLATH CLONH HMSL FLVLST IALR POAF SMMO GNSA' ) C C* Tail number, aircraft type and observer ID. C CALL UT_BFCI ( iubfma, 'ACRN', cval, ier ) CALL UT_CIBF ( iubfmn, 'ACRN', cval, 8, ier ) CALL UT_BFCI ( iubfma, 'ACTP', cval, ier ) CALL UT_CIBF ( iubfmn, 'ACTP', cval, 8, ier ) CALL UT_BFCI ( iubfma, 'OBSVR', cval, ier ) CALL UT_CIBF ( iubfmn, 'OBSVR', cval, 4, ier ) C C* Temperature, wind and humidity. C CALL UFBINT ( iubfma, r8in, MXMN, MXLV, nlv, + 'TMDBST WDIR WSPD RAWHU' ) CALL UFBINT ( iubfmn, r8in, MXMN, 1, nlv, + 'TMDBST WDIR WSPD RAWHU' ) C C* Quality markers. C IF ( iercs3 .eq. 0 ) THEN C C* Confirm the associated field significance values. C r8afsi2 = GETVALNB( iubfma, 'SMMO', 1, 'AFSI', -1 ) r8afsi7 = GETVALNB( iubfma, 'RAWHU', 1, 'AFSI', -1 ) IF ( ( IBFMS ( r8afsi2 ) .eq. 0 ) .and. + ( IDNINT ( r8afsi2 ) .eq. 2 ) .and. + ( IBFMS ( r8afsi7 ) .eq. 0 ) .and. + ( IDNINT ( r8afsi7 ) .eq. 7 ) ) THEN CALL UFBREP ( iubfma, r8in, MXMN, MXLV, nlv, + '204002' ) DO ii = 1, nlv IF ( IBFMS ( r8in(1,ii) ) .eq. 1 ) + r8in(1,ii) = 3. END DO CALL UFBREP ( iubfmn, r8in, MXMN, nlv, nlv2, + 'QMRKH' ) CALL UFBINT ( iubfma, r8in, MXMN, MXLV, nlv, + '204007' ) CALL UFBINT ( iubfmn, r8in, MXMN, 1, nlv, + 'PCCF' ) END IF END IF C C* Correction indicator. C IF ( IUPBS01 ( ibull, 'USN' ) .gt. 0 ) THEN icorn = 1 ELSE icorn = 0 END IF CALL UT_RIBF ( iubfmn, 'CORN', FLOAT (icorn), ier ) C C* Receipt time. C CALL UT_RIBF ( iubfmn, 'RCTS', FLOAT (0), ier ) CALL UT_RIBF ( iubfmn, 'RCYR', + FLOAT ( irundt (1) ), ier ) CALL UT_RIBF ( iubfmn, 'RCMO', + FLOAT ( irundt (2) ), ier ) CALL UT_RIBF ( iubfmn, 'RCDY', + FLOAT ( irundt (3) ), ier ) CALL UT_RIBF ( iubfmn, 'RCHR', + FLOAT ( irundt (4) ), ier ) CALL UT_RIBF ( iubfmn, 'RCMI', + FLOAT ( irundt (5) ), ier ) C C* Restrictions on redistribution. C CALL UT_RIBF ( iubfmn, 'RSRD', 16., ier ) C C* Write the BUFR output to the BUFR output stream. C CALL UT_WBFR ( iubfmn, 'tamdar2', 0, ierwbf ) END IF END IF END DO END DO C* RETURN END