C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MTMRNG      GET RANGE OF TIME COVERED BY DATA FILE
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 01-07-05
C
C ABSTRACT: GET THE RANGE OF TIME COVERED BY A SINGLE DATA FILE
C   FOR A SINGLE DATASET
C
C PROGRAM HISTORY LOG:
C   01-07-05  M. BARTH    ORIGINAL VERSION
C   01-08-11  M. BARTH    CLEANED UP ERROR CODES AND MESSAGES
C
C USAGE:    CALL MTMRNG (TPL,NCTPL,CUTOFF,INCR,STATUS)
C
C   INPUT ARGUMENT LIST:
C     TPL      - C       NAME OF THE NETCDF TEMPLATE FOR THIS DATASET
C     NCTPL    - I       NUMBER OF CHARACTERS IN TPL
C
C   OUTPUT ARGUMENT LIST:
C     CUTOFF   - I       LAST MINUTE STORED IN THE FILE
C     INCR     - I       NUMBER OF SECONDS IN RANGE OF TIME COVERED
C                        BY THE FILE
C     STATUS   - I       SUCCESS_P OR BAD_FILE_P
C
C   INPUT FILE:
C     TPL      THE NETCDF TEMPLATE
C
C SUBPROGRAMS CALLED:
C     UNIQUE:  MERROR
C     NETCDF:  NCAGT, NCCLOS, NCOPEN
C
C REMARKS:
C   THIS ROUTINE USES THE AWIPS CONVENTION FOR POINT DATA FILES.
C   THE filePeriod GLOBAL ATTRIBUTE SPECIFIES THE NUMBER OF SECONDS
C   COVERED BY A FILE (WHICH IS NAMED AT THE TOP OF THE HOUR).  THE
C   fileEndOffset GLOBAL ATTRIBUTE SPECIFIES THE LAST SECOND THAT
C   CAN BE COVERED IN THE FILE.  HERE ARE A FEW EXAMPLES:
C
C   PERIOD   OFFSET   FILE TIME         COVERS
C   ------   ------   ---------         ------
C   3600     0        1200              1101 - 1200
C   3600     2640     1200              1145 - 1244
C   3600     3599     1200              1200 - 1259
C   43200    43199    1200              1200 - 2359
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$


      SUBROUTINE MTMRNG (TPL,NCTPL,CUTOFF,INCR,STATUS)

C     -----------------------------------------------------------------
C     INCLUDES AND COMMONS
C     -----------------------------------------------------------------
      INCLUDE 'IMPLICIT'
      INCLUDE 'MADISCON'
      INCLUDE 'NETCDFI'

C     -----------------------------------------------------------------
C     ARGUMENTS
C     -----------------------------------------------------------------
      CHARACTER*(*) TPL
      INTEGER NCTPL,CUTOFF,INCR,STATUS

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER NCID,RCODE
      CHARACTER*255 ERRTPL

C     *****************************************************************
C     ******************* BEGIN OF MTMRNG *****************************
C     *****************************************************************

      STATUS = BAD_FILE_P

C     ------------------------------------------------------------------
C     OPEN THE TEMPLATE FILE.  THEN READ IN THE ATTRIBUTES USED TO
C     DEFINE THE TIME RANGE COVERED BY THE FILE, CONVERT THE CUTOFF TO
C     MINUTES, CLOSE THE TEMPLATE, AND THAT'S ALL THERE IS TO IT.
C     ------------------------------------------------------------------
      ERRTPL = TPL(1:NCTPL)
      NCID = NCOPN(TPL,NCNOWRIT,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MTMRNG: BIF - NCOPN ERROR ON '//ERRTPL(1:NCTPL))
         GO TO 900
      ENDIF
      CALL NCAGT(NCID,NCGLOBAL,'filePeriod',INCR,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MTMRNG: BIF - NCAGT ERROR filePeriod '//
     1               ERRTPL(1:NCTPL))
         GO TO 900
      ENDIF

      CALL NCAGT(NCID,NCGLOBAL,'fileEndOffset',CUTOFF,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MTMRNG: BIF - NCAGT ERROR fileEndOffset '//
     1                ERRTPL(1:NCTPL))
         GO TO 900
      ENDIF
      CUTOFF = CUTOFF/60

      STATUS = SUCCESS_P

 900  CALL NCCLOS(NCID,RCODE)

      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**---------------------------------------------------------------------
