C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C
C SUBPROGRAM:    M_GTI4TM    RETURNS I4 TIME TO CALLING PRGRM
C   PRGMMR:  MILLER, P.      ORG: ERL/PROFS    DATE: 89-08-07
C
C ABSTRACT: THIS ROUTINE RETURNS I4 TIME GIVEN 6 INTEGERS CORRESPONDING
C   TO YEAR, MONTH, DAY, HOUR, MINUTE AND SECOND.
C
C PROGRAM HISTORY LOG:
C   81-02-12  MURRAY,     ORIGINAL VERSION
C   82-09-13  HOAGENSON,  CHANGED NAME FROM I4TIME_INT_G
C   88-10-04  MILLER,     CONVERTED TO STANDARD FORTRAN
C   98-07-10  BARTH, M.   REDEFINED I4TIME (NUMBER OF SECONDS FROM
C                         A BASELINE)
C                         OLD:  - WENT FROM 1/1/1960 THROUGH 12/31/2027
C                               - BASELINE 1/1/1960 0Z = 0 I4TIME
C                               - POSITIVE NUMBERS ONLY
C                         NEW:  - GOES FROM 1/1/1945 THROUGH 12/31/2079
C                               - BASELINE 1/1/2012 0Z = 0 I4TIME
C                               - NEGATIVE AND POSITIVE NUMBERS
C   99-09-15  M. BARTH    COPIED FROM MSAS AND MODIFIED FOR MADIS.
C   08-06-13  L. BENJAMIN CHANGED "MADISCON" INCLUDE TO 
C                         "INTQC1CON1".
C
C USAGE:    FUNCTION M_GTI4TM(NYEAR, NMONTH, NDAY, NHOUR, NMIN,
C   NSEC, ISTATS)
C   INPUT ARGUMENT LIST:
C     NYEAR    - 2- OR 4-DIGIT YEAR - INTEGER
C     NMONTH   - NUMBER OF MONTHS IN THE YEAR - INTEGER
C     NDAY     - NUMBER OF DAYS IN THE MONTH - INTEGER
C     NHOUR    - NUMBER OF HOURS IN THE DAY - INTEGER
C     NMIN     - NUMBER OF MINUTES IN THE HOUR - INTEGER
C     NSEC     - NUMBER OF SECONDS IN THE MINUTE - INTEGER
C
C   OUTPUT ARGUMENT LIST:
C     M_GTI4TM - AS A FUNCTION, RETURNS I4 TIME - INTEGER
C
C REMARKS: - GIVEN THE INPUT PARAMETERS, M_GTI4TM COMPUTES AND SUMS
C            THE NUMBER OF SECONDS TO RETURN I4 TIME.
C          - IF A 2-DIGIT YEAR IS SENT IN, THAT'S INTERPRETED TO
C            BE BETWEEN 1980 AND 2079.
C          - NOTE THAT THE BASELINE MUST ALWAYS BE A LEAP YEAR.
C          - NOTE THAT 2000 IS A LEAP YEAR.  IF THIS ROUTINE IS
C            MODIFIED FOR 2100 OR BEYOND, FULL LEAP YEAR LOGIC
C            MUST BE INCLUDED (YY00 IS NOT A LEAP YEAR UNLESS
C            YY00 IS DIVISIBLE BY 400).
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN 77 + EXTENSIONS
C   MACHINE: NAS 9000, VAX, UNIX
C
C$$$
      FUNCTION M_GTI4TM (NYEAR,NMONTH,NDAY,NHOUR,NMIN,NSEC,ISTATS)
C
      INCLUDE 'IMPLICIT'
      INCLUDE 'INTQC1CON1'

      INTEGER IBASE,ISTATS,NYR,NYEAR,NYRS,NSECYR,NLEAP,NSECDA,NMONTH
      INTEGER I,NDAY,NDAYS,NHOUR,NSECHR,NMIN,NSECMN,NSEC,ISIGN

      DIMENSION NDAYS(12)
      INTEGER M_GTI4TM
      INTEGER NSECMO(12), ISUM
      PARAMETER (IBASE=112)
      DATA NSECYR/31536000/NSECDA/86400/NSECHR/3600/NSECMN/60/
      DATA NSECMO/2678400,2419200,2678400,2592000,2678400,
     1 2592000,2678400,2678400,2592000,2678400,2592000,2678400/
      DATA NDAYS/31,29,31,30,31,30,31,31,30,31,30,31/
      ISTATS = SUCCESS_P
C
C SUM THE NUMBER OF YEARS.
C
      NYR=NYEAR
      IF (NYR.GT.1900) THEN
         NYR=NYR-1900
      ELSE IF (NYR.LT.80) THEN
         NYR = NYR + 100
      ENDIF
      NYRS=NYR-IBASE
      IF (ABS(NYRS).GT.67) GO TO 100
      IF(NYRS.LT.0)THEN
         ISIGN = -1
      ELSE
         ISIGN = 1
      ENDIF
      ISUM=NYRS*NSECYR
      NLEAP=(ABS(NYRS)/4)+1
      IF(ISIGN.LT.0)NLEAP = NLEAP - 1
      ISUM=ISUM+(ISIGN*NLEAP*NSECDA)
C
C SUM IN THE NUMBER OF MONTHS.
C
      IF (NMONTH.LT.1.OR.NMONTH.GT.12) GO TO 100
      IF (NMONTH.EQ.1) GO TO 20
      DO 10 I=1,NMONTH-1
         ISUM=ISUM + NSECMO(I)
10    CONTINUE
20    IF (MOD(ABS(NYRS),4).NE.0) GO TO 30
      IF (NMONTH.LE.2.AND.ISIGN.GT.0) THEN
         ISUM=ISUM-NSECDA
      ELSE IF(NMONTH.GT.2.AND.ISIGN.LT.0)THEN
         ISUM=ISUM+NSECDA
      ENDIF
C
C SUM IN THE NUMBER OF DAYS.
C
 30   IF (NDAY.LT.1.OR.NDAY.GT.NDAYS(NMONTH))
     1 GO TO 100
      ISUM=ISUM+((NDAY-1)*NSECDA)
C
C SUM IN THE NUMBER OF HOURS.
C
      IF (NHOUR.LT.0.OR.NHOUR.GT.23) GO TO 105
      ISUM=ISUM+(NHOUR*NSECHR)
C
C SUM IN THE NUMBER OF MINUTES.
C
      IF (NMIN.LT.0.OR.NMIN.GT.59) GO TO 105
      ISUM=ISUM+(NMIN*NSECMN)
C
C SUM IN THE NUMBER OF SECONDS.
C
      IF (NSEC.LT.0.OR.NSEC.GT.59) GO TO 105
      ISUM=ISUM+NSEC
C
      M_GTI4TM=ISUM
      RETURN
C
C RETURN ERROR CODE.
C
100    ISTATS = INV_TIME_P
      GO TO 110
105   ISTATS = INV_TIME_P
110    M_GTI4TM=0
      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**---------------------------------------------------------------------
