      FUNCTION TICK(DT)
Status: R

C
C*********************************************************************
C*********************** ARIES   MODEL *******************************
C********************* FUNCTION     TICK *****************************
C********************** 9 FEBRUARY 1987 ******************************
C*********************************************************************
C
      PARAMETER (NALARMS=20)
      INTEGER TICK, TOCK, SETALARM, SECND, MINUTE, HOUR, DAYOFYR
     *,       DAY, MONTH, YEAR, PASSED, ALARMS(NALARMS), ALARMT(NALARMS)
     *,       SECOFDY , SETA
      LOGICAL ALARM, CUCKOO, PRPTUL
C
      DOUBLE PRECISION CTIME, SETTIME, CPRPTM, SETPRP, SET, TIME0, TIMEI
     *,      BTIME
C
      INTEGER DAYS(12)
      DATA  DAYS/31,28,31,30,31,30,31,31,30,31,30,31/
C
      DATA  ALARMT/NALARMS*31536000/, PRPTUL/.FALSE./
      DATA  TIME0/0.0/, TIMEI/0.0/, BTIME/0.0/
C
      ENTRY TOCK(DT)
      IT=TIME0 +.001 - BTIME
      TIME0 = TIME0 + DT
      JT=TIME0 +.001 - BTIME
      DO 100 L=1,NALARMS
      TOCK = (JT/ALARMT(L)-IT/ALARMT(L))
      ALARMS(L) = TOCK
100   CONTINUE
      RETURN
C
      ENTRY SETTIME(SET)
      TIME0 = SET
      BTIME = SET
      SETTIME=SET
      RETURN
C
      ENTRY SETALARM(M,SETA)
      ALARMT(M)=SETA
      SETALARM=SETA
      RETURN
C
      ENTRY CTIME()
      CTIME=TIME0
      RETURN
C
      ENTRY ALARM(M)
      ALARM=ALARMS(M).NE.0
      RETURN
C
      ENTRY CUCKOO()
      CUCKOO=.FALSE.
      DO 200 L=1,NALARMS
      CUCKOO=ALARMS(L).NE.0 .OR. CUCKOO
200   CONTINUE
      RETURN
C
      ENTRY SECND()
      SECND=TIME0 + 0.001
      IF (PRPTUL) SECND=TIMEI + 0.001
      SECND=MOD(SECND,60)
      RETURN
C
      ENTRY MINUTE()
      MINUTE=TIME0 + 0.001
      IF (PRPTUL) MINUTE=TIMEI + 0.001
      MINUTE=MOD(MINUTE/60,60)
      RETURN
C
      ENTRY HOUR()
      HOUR=TIME0 + 0.001
      IF (PRPTUL) HOUR=TIMEI + 0.001
      HOUR=MOD(HOUR/3600,24)
      RETURN
C
      ENTRY DAYOFYR()
      DAYOFYR=TIME0 + 0.001
      IF (PRPTUL) DAYOFYR=TIMEI + 0.001
      DAYOFYR=MOD(DAYOFYR/86400,365)+1
      RETURN
C
      ENTRY SECOFDY()
      SECOFDY=TIME0 + 0.001
C     IF (PRPTUL) SECOFDY=TIMEI + 0.001
      SECOFDY=MOD(SECOFDY,86400)
      RETURN
C
      ENTRY DAY()
      DAY=TIME0 + 0.001
      IF (PRPTUL) DAY=TIMEI + 0.001
      DAY=MOD(DAY/86400,365)+1
      PASSED=0
      DO 300 MON=1,12
      PASSED=PASSED+DAYS(MON)
      IF (DAY. GT. PASSED) GO TO 300
      DAY = DAY-(PASSED-DAYS(MON))
      RETURN
 300  CONTINUE
      PRINT *, 'ERROR IN DAY-TIME'
      STOP
C
      ENTRY MONTH()
      JDAY   = TIME0 + 0.001
      IF (PRPTUL) JDAY=TIMEI + 0.001
      JDAY   = MOD(JDAY/86400,365)+1
      PASSED = 0
      DO 400 MONTH=1,12
      PASSED = PASSED+DAYS(MONTH)
      IF (JDAY .GT. PASSED) GO TO 400
      RETURN
 400  CONTINUE
      PRINT *, 'ERROR IN MONTH-TIME'
      STOP
C
      ENTRY YEAR()
      YEAR = TIME0 + 0.001
      IF (PRPTUL) YEAR = TIMEI + 0.001
      YEAR = YEAR/(365*86400)
      RETURN
C
      ENTRY SETPRP()
      PRINT *,' IN SETPRP : PRPTUL=',PRPTUL
      PRINT *,' IN SETPRP : TIMEI=',TIMEI
      IF (PRPTUL) THEN
         PRINT *,' PRPTUL ALREADY DEFINED : TIMEI = ', TIMEI
         RETURN
      ENDIF
      PRPTUL = .TRUE.
      TIMEI  = TIME0
      SETPRP = TIMEI
      RETURN
C
      ENTRY CPRPTM()
      CPRPTM = -1
      IF (PRPTUL) CPRPTM = TIMEI
      RETURN
C
      ENTRY CLRPRP()
      PRPTUL = .FALSE.
      TIME0  = INT(TIMEI/86400.D0)*86400.D0 + MOD(TIME0,86400.D0)
      RETURN
      END
      SUBROUTINE VQSAT(T,P,Q,DQDT,LEN,LDQDT)
C
C
C*********************************************************************
C*********************** ARIES   MODEL *******************************
C********************* SUBROUTINE  VQSAT *****************************
C********************** 9 FEBRUARY 1987 ******************************
C*********************************************************************
C
C
      LOGICAL LDQDT
C
      PARAMETER (ESFAC=0.622)
      PARAMETER (B6= 6.136820929E-11*ESFAC)
      PARAMETER (B5= 2.034080948E-8 *ESFAC)
      PARAMETER (B4= 3.031240396E-6 *ESFAC)
      PARAMETER (B3= 2.650648471E-4 *ESFAC)
      PARAMETER (B2= 1.428945805E-2 *ESFAC)
      PARAMETER (B1= 4.436518521E-1 *ESFAC)
      PARAMETER (B0= 6.107799961E+0 *ESFAC)
      PARAMETER (C1= B1   )
      PARAMETER (C2= B2*2.)
      PARAMETER (C3= B3*3.)
      PARAMETER (C4= B4*4.)
      PARAMETER (C5= B5*5.)
      PARAMETER (C6= B6*6.)
      PARAMETER (TMIN=223.15,TMAX=323.15, TICE=273.16, ONE=1.0)
C
      DIMENSION T(LEN), P(LEN), Q(LEN), DQDT(LEN)
     *,         B(7),   C(6)
      DATA B/B0,B1,B2,B3,B4,B5,B6/
      DATA C/   C1,C2,C3,C4,C5,C6/
      data ia/8933/
C
c     print *,' in vqsat: t=',t(ia),' p=',p(ia),' ia=',ia
      DO 10 I=1,LEN
      IF (T(I) .LT. TMIN) THEN
         T(I) = TMIN
      ELSEIF (T(I) .GT. TMAX) THEN
         T(I) = TMAX
      ENDIF
   10 CONTINUE
c     print *,' : t=',t(ia),' p=',p(ia),' len=',len
      DO 20 I=1,LEN
      P(I) = ONE / P(I)
      T(I) = T(I) - TICE
   20 CONTINUE
C
      CALL POLY(Q,T,B,7,LEN)
      DO 30 I=1,LEN
      Q(I) = Q(I)*P(I)
C     Q(I) = ((((((B(7)*T(I) + B(6))*T(I) + B(5))*T(I) + B(4))*T(I)
C    *                       + B(3))*T(I) + B(2))*T(I) + B(1)) * P(I)
   30 CONTINUE
c     print *,' : q=',q(ia),' p=',p(ia)
C
      IF (LDQDT)  THEN
      CALL POLY(DQDT,T,C,6,LEN)
      DO 40 I=1,LEN
      DQDT(I) = DQDT(I)*P(I)
C     DQDT(I) = ((((((C(7)*T(I) + C(6))*T(I) + C(5))*T(I) + C(4))*T(I)
C    *                       + C(3))*T(I) + C(2))*T(I) + C(1)) * P(I)
   40 CONTINUE
      ENDIF
C
C     PRINT *,' INVQ: Q=',Q(74),' DQDT=',DQDT(74),' T=',T(74),'P=',P(74)
      RETURN
      END

