Checking units

A user written subroutine that manipulates values in the model must assume that the solve is running in a particular set of units. If the input file actually uses a different set of units, incorrect results are obtained. You check the units by calling routine TUNITS during initialization. For an example on how to perform the units check, see the following sample code.

 
      logical function checkunits
C
C     This routine checks model units against an internal set
C     of values. The tolerance for units checking is defined
C     by parameter unitstol.
C
      implicit none
      real unitscheck(5), unitstol
      parameter (unitstol=0.01)
C     Define SI units
      data unitscheck/1.0,1.0,1.0,-273.15,1.0/
C
      real uvals(5), xunits
      integer idum
      logical unitserror
      integer i
C
C
      call tunits(idum,uvals(1), uvals(2), uvals(3), uvals(4),
     + uvals(5))
C
C     Check each unit for error, allow a tolerance of 1%
C
      unitserror=.false.
      do i=1,5
         xunits=abs((uvals(i)/unitscheck(i))-1)
         if(xunits .gt. unitstol) then
            unitserror=.true.
         end if
      enddo
      if (unitserror) then
         call unitserrorhandler
      end if
      checkunits=unitserror
      return
      end