C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MACARSTIME  GET ACARS TIMES VARIABLES
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 00-07-06
C
C ABSTRACT: READ ACARS RECEIPT TIMES OR TIMES OF MAXIMUM TURBULENCE
C   FOR ALL STATIONS FOR ONE VARIABLE AND TIME, AND CONVERT THEM TO 
C   ATIME-FORMAT CHARACTER STRING.
C
C PROGRAM HISTORY LOG:
C   00-07-06  M. BARTH    ORIGINAL VERSION
C   03-10-10  M. BARTH    CHANGES FOR AWIPS DATABASE
C   04-08-06  M. BARTH    RENAMED FROM MACARSRT IN ORDER TO ADD
C                         THE MAX TURB TIMES
C
C USAGE:    CALL MACARSTIME (VCN,ATIME,NSTA,CDATA,STATUS)
C
C   INPUT ARGUMENT LIST:
C     VCN      - I       VARIABLE CODE NUMBER OF THE DESIRED DATA
C     ATIME    - C       YYJJJHHMM OF THE DATA TO BE READ
C
C   OUTPUT ARGUMENT LIST:
C     NSTA     - I       NUMBER OF STATIONS RETURNED
C     CDATA    - CA      ARRAY OF RETURNED CHARACTER DATA
C     STATUS   - I       0 - SUCCESS, OR ERROR CODE
C
C   INPUT FILES:
C     MADIS ACARS NETCDF FILES FOR ATIME
C
C SUBPROGRAMS CALLED:
C     UNIQUE:    MERROR, MRDDBL, M_MKFNAM
C
C REMARKS:
C   THIS IS CALLED BY MGETACARSC, WHICH HAS ALREADY VALIDATED THE
C   CURRENT DATA SET IS ACARS, THE VCN IS FOR A TIME VARIABLE, 
C   THE VARIABLE EXISTS IN THE CURRENT DATABASE, ETC.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MACARSTIME(VCN,ATIME,NSTA,CDATA,STATUS)

C     ------------------------------------------------------------------
C     INCLUDES AND COMMONS
C     ------------------------------------------------------------------
      INCLUDE 'IMPLICIT'
      INCLUDE 'MADISCON'
      INCLUDE 'MADISCOM'
      INCLUDE 'STRCCOM'

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER VCN
      CHARACTER*9 ATIME
      INTEGER NSTA,STATUS
      CHARACTER*9 CDATA(*)

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER I,J,K,FNUM,DSN,CD,RTIME
      DOUBLE PRECISION DTIME(MXACARS_P)
      LOGICAL HAVE_ANY

C     ------------------------------------------------------------------
C     SET THE CURRENT DATASET TYPE TO ACARS.
C     ------------------------------------------------------------------
      CD = ACARS_DS_P
      DSN = MAX_SFCDSET_P + CD
      HAVE_ANY = .FALSE.

      NSTA = UAPT_LNUM(CD)
      IF(NSTA.EQ.0)THEN
         STATUS = NO_DATA_P
         GO TO 900
      ENDIF

      FNUM = 0

C     ------------------------------------------------------------------
C     NOTE THAT WE LOOP THROUGH UAPT_FNUM TO SEE WHICH FILES ARE NEEDED
C     AND NOT THROUGH UAPT_NFILES.  THIS IS DONE AS JUST BECAUSE A FILE
C     GOT READ DOESN'T MEAN ANY OF ITS RECORDS ACTUALLY WERE EXTRACTED
C     WHEN ALL THE FILTERING WAS DONE IN MUAPTSTA.  THEREFORE, WE'LL
C     ONLY PROCESS EACH FILE WITH RECORDS IN USE.
C     ------------------------------------------------------------------
      DO 100 I = 1, NSTA

C     ------------------------------------------------------------------
C     ALREADY HANDLED THIS FILE.
C     ------------------------------------------------------------------
         IF(FNUM.EQ.UAPT_FNUM(I,CD))GO TO 100

         IF(FNUM.EQ.0)THEN

C     ------------------------------------------------------------------
C     IF THIS IS THE FIRST TIME WE'VE BEEN HERE, FILL BLANKS INTO
C     THE CALLER'S ARRAY.  (NOTE THAT THERE ARE NO MISSING DATA FLAGS
C     FOR CHARACTER VARIABLES.)
C     ------------------------------------------------------------------
            DO 118 J = 1, NSTA

               CDATA(J) = '         '

 118        CONTINUE

         ENDIF

         FNUM = UAPT_FNUM(I,CD)

C     ------------------------------------------------------------------
C     READ THE VARIABLE.  IF THERE'S AN ERROR, THE SUBROUTINE WILL HAVE
C     SET STATUS & CALLED MERROR.  IF THERE ISN'T AN ERROR, INDICATE
C     THAT WE ACTUALLY READ SOMETHING.
C     ------------------------------------------------------------------
         IF(VCN.EQ.ACARSTT_VN_P)THEN

            CALL MRDDBL('timeMaxTurbulence',UAPT_NCID(FNUM,CD),
     1                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     2                  MISS_P,DTIME,STATUS)

         ELSE IF(CDBTYPE.EQ.FSL_DB_P)THEN

            CALL MRDDBL('timeReceived',UAPT_NCID(FNUM,CD),
     1                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     2                  MISS_P,DTIME,STATUS)

         ELSE IF(CDBTYPE.EQ.AWIPS_DB_P)THEN

            CALL MRDDBL('timeMdcrsHdr',UAPT_NCID(FNUM,CD),
     1                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     2                  MISS_P,DTIME,STATUS)

         ENDIF

         IF(STATUS.NE.SUCCESS_P)GO TO 900

         HAVE_ANY = .TRUE.

C     ------------------------------------------------------------------
C     EXTRACT DESIRED RECORDS AND CONVERT INTO A STRING IN THE CALLER'S
C     ARRAY.
C     ------------------------------------------------------------------
         DO 120 J = I, NSTA

            IF(UAPT_FNUM(J,CD).NE.FNUM)GO TO 100

            IF(DTIME(UAPT_RNUM(J,CD)).NE.MISS_P)THEN

               RTIME = DTIME(UAPT_RNUM(J,CD))
               RTIME = RTIME - 1325376000
               CALL M_MKFNAM(RTIME,CDATA(J),K)
               IF(K.NE.SUCCESS_P)CDATA(J) = '         '

            ENDIF

            IF(J.EQ.NSTA)GO TO 900

 120     CONTINUE

 100  CONTINUE

 900  IF(STATUS.NE.SUCCESS_P)THEN

         NSTA = 0

      ELSE IF(.NOT.HAVE_ANY)THEN

         STATUS = NO_DATA_P
         NSTA = 0

      ENDIF

      RETURN
      END

C**---------------------------------------------------------------------
C**REQUIRED STANDARD FSL DISCLAIMER (NOVEMBER 2000)
C**---------------------------------------------------------------------
C**  OPEN SOURCE LICENSE/DISCLAIMER,  FORECAST SYSTEMS LABORATORY
C**  NOAA/OAR/FSL, 325 BROADWAY BOULDER, CO 80305
C**
C**  THIS SOFTWARE IS DISTRIBUTED UNDER THE OPEN SOURCE DEFINITION, 
C**  WHICH MAY BE FOUND AT http://www.opensource.org/osd.html.
C**
C**  IN PARTICULAR, REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS,
C**  WITH OR WITHOUT MODIFICATION, ARE PERMITTED PROVIDED THAT THE 
C**  FOLLOWING CONDITIONS ARE MET:
C**
C**  - REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THIS NOTICE, THIS LIST
C**    OF CONDITIONS AND THE FOLLOWING DISCLAIMER.
C**
C**  - REDISTRIBUTIONS IN BINARY FORM MUST PROVIDE ACCESS TO THIS 
C**    NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING DISCLAIMER, AND
C**    THE UNDERLYING SOURCE CODE.
C**
C**  - ALL MODIFICATIONS TO THIS SOFTWARE MUST BE CLEARLY DOCUMENTED, 
C**    AND ARE SOLELY THE RESPONSIBILITY OF THE AGENT MAKING THE 
C**    MODIFICATIONS.
C**
C**  - IF SIGNIFICANT MODIFICATIONS OR ENHANCEMENTS ARE MADE TO THIS
C**    SOFTWARE, THE FSL SOFTWARE POLICY MANAGER 
C**    (softwaremgr.fsl@noaa.gov) BE NOTIFIED.
C**
C**  THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN AND 
C**  ARE FURNISHED "AS IS."  THE AUTHORS, THE UNITED STATES GOVERNMENT,
C**  ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND AGENTS MAKE NO 
C**  WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS OF THE SOFTWARE
C**  AND DOCUMENTATION FOR ANY PURPOSE.  THEY ASSUME NO RESPONSIBILITY 
C**  (1) FOR THE USE OF THE SOFTWARE AND DOCUMENTATION; OR (2) TO 
C**  PROVIDE TECHNICAL SUPPORT TO USERS.
C**---------------------------------------------------------------------
