      program dstep
      implicit none
      integer :: ierror=0
c
c      J. Mahaffy 2/1/97
c
c
c     Test the vramp function for a ramp between 5 and 7 s.
c     and a ramp between 15 and 20 seconds
c
c
      print *, 'Testing function vramp'
      call testit( 5.,7.0,ierror)
      call testit (15.,20., ierror)
      if ( ierror.eq.0) then
         print *, 'Function vramp is OK'
      else
         print *, '**** Problems with vramp, change and retry ****'
      endif
c
      stop
      end
c
c        1         2         3         4         5         6         7
c23456789012345678901234567890123456789012345678901234567890123456789012
c
      subroutine testit(t1,t2,ierror)
c     
c     test the function vramp with 4 calls at small time, large time, and
c     times at either side of the step. This assumes that t1>0
c                                          
      implicit none 
      real t1,t2, vramp
      integer ierror
      logical near
c
c     John Mahaffy 2/1/97
c     
c     t1 - time at which voltage steps from zero to one
c
c     Check zero time
c
      print *, 'Testing for ramp from ',t1, 'seconds to ',
     $         t2,' seconds'
      if (vramp(0.,t1,t2).ne.0) then
      	 print *, '*** vramp gives wrong result when t=0 ***'
         ierror=ierror+1
      endif
c
      if (vramp(t1-.001,t1,t2).ne.0) then
         print *, '*** vramp gives wrong result for time just before',
     $            ' the ramp'
         ierror=ierror+1
      endif
c
      if (.not. near(vramp(.75*t1+.25*t2,t1,t2),.25) ) then
         print *, '*** vramp gives wrong result for the interpolation'
         ierror=ierror+1
      endif
c
      if (.not. near(vramp(.25*t1+.75*t2,t1,t2),.75) ) then
         print *, '*** vramp gives wrong result for the interpolation'
         ierror=ierror+1
      endif
c
      if (.not.near(vramp(t2+.001,t1,t2),1.0) ) then
         print *, '*** vramp gives wrong result for time just after',
     $            ' the ramp'
         ierror=ierror+1
      endif
c
      if (.not.near(vramp(t2+1000.,t1,t2),1.0) ) then
         print *, '*** vramp gives the wrong result at large time'
         ierror=ierror+1
      endif
c
      return
      end
c
      logical function near (var1,var2)
      implicit none
c
c     Checks to see if the real varables var1 and var2 are close to
c     each other.  This uses the Fortran 90 Intrinsic function EPSILON
c     to find the closest that you should expect to represent 1.0
c     with the internal REAL representation used on the variable passed
c     as an argument.
c
c     var1   -   first number to be compared
c     var2   -   second number to be compared
c
      real var1, var2
c
      near = .true.
      if ( var1 .gt. 0.) then
         if (var1.gt.var2*(1.+2*epsilon(var2)).or.
     $       var1.lt.var2*(1.-2*epsilon(var2)) )  near = .false.
       else  if (var1.lt.0.) then
         if (var1.lt.var2*(1.+2*epsilon(var2)).or.
     $       var1.gt.var2*(1.-2*epsilon(var2)) )  near = .false.
       else
         if (var2.gt.epsilon(var2).or. var2.lt.-epsilon(var2))
     $       near = .false.
       endif
       end
c
c        1         2         3         4         5         6         7
c23456789012345678901234567890123456789012345678901234567890123456789012
c
c   Insert your function below this line
c-----------------------------------------------------------------------
      function vramp(t,t1,t2)
      implicit none
c
c     Function outputs a voltage with a linear ramp from zero before
c     t=t1 to one after t=t2
c
c     t   -   time
c     t1  -   time for the start of the linear ramp from 0.
c     t2  -   time for the completion of the linear ramp to 1.
c
c     John Mahaffy 2/1/97
c
      real t,t1,t2,vramp
c
      if (t.lt.t1) then
         vramp = 0.
      else if (t.gt.t2) then
         vramp = 1.0
      else
         vramp = (t-t1)/(t2-t1)
      endif
      return
      end
        
 


     
 
                

