c
c     Copyright (c) 1999,2000, Compaq Computer Corporation
c
c     See the file "license.terms" for information on usage and redistribution
c     of this file, and for a DISCLAIMER OF ALL WARRANTIES.
c
c     Utility routines created during extension of Postmini to
c     handle triangular grids.
c
      subroutine minmax_rectarray(array, isize, jsize, iactual,
     1                            x, y,
     2                            xmin, xmax, ymin, ymax, lfull,
     3                            fmin, fmax)
      implicit none
c
c     Computes the min/max of array(iactual,*) over [1..isize,1..jsize]
c
      integer isize, jsize, iactual
      logical lfull
      real xmin, xmax, ymin, ymax, x(isize), y(jsize)
      real array(iactual,1), fmin, fmax
c
      include 'sysdep.cmn'
c
c     locals
      integer i,j
      integer ixmin, ixmax, iymin, iymax
c
      if( lfull ) then
         ixmin = 1
         ixmax = isize
         iymin = 1
         iymax = jsize
      else
         call find_greatest_subset_of_array(x, y,
     1     xmin, xmax, ymin, ymax, isize, jsize,
     2     ixmin, ixmax, iymin, iymax)
      endif
c
      fmin = PM_MAX_FLOAT
      fmax = -PM_MAX_FLOAT
      do 100 j=iymin,iymax
         do 100 i=ixmin,ixmax
            if( fmin .gt. array(i,j) ) then
               fmin = array(i,j)
            endif
            if( fmax .lt. array(i,j) ) then
                fmax = array(i,j)
           endif
100   continue
c
      return
      end
c
      subroutine minmax_triarray(array, ipts, isize,
     1                           cord, xmin, xmax, ymin, ymax,
     2                           lfull, fmin, fmax)
      implicit none
c
c     Computes the min/max of array(isize) over [1..ipts]
c
      integer ipts, isize
      real xmin, xmax, ymin, ymax, cord(2,ipts)
      real array(isize), fmin, fmax
      logical lfull
c
      include 'sysdep.cmn'
c
c     locals
      integer i
c     Statement function for test of point outide region
      real x, y, h1, h2, v1, v2
      logical loutside
      loutside(x,y,h1,h2,v1,v2) = x .lt. h1 .or. x .gt. h2 .or.
     1                            y .lt. v1 .or. y .gt. v2
c
      fmin = PM_MAX_FLOAT
      fmax = -PM_MAX_FLOAT
      do 100 i=1,ipts
         if( .NOT. lfull ) then
            if( loutside(cord(1,i),cord(2,i), xmin, xmax, ymin, ymax))
     1         goto 100
         endif
         if( fmin .gt. array(i) ) then
            fmin = array(i)
         endif
         if( fmax .lt. array(i) ) then
            fmax = array(i)
         endif
100   continue
c
      return
      end
c
      subroutine negate_array(dest, source, ni, nj,
     1      tri_npts, data_is_trimesh, do_negate)
      implicit none
c
      integer ni, nj, tri_npts
      real dest(1), source(1)
      logical data_is_trimesh, do_negate
c
c     locals
      integer i, ilimit
      real h
c
      if( do_negate ) then
         h = -1.0
      else
         h = 1.0
      endif
c
      if( data_is_trimesh ) then
         ilimit = tri_npts
      else
         ilimit = ni*nj
      endif
c
      do 100 i=1,ilimit
         dest(i) = h*source(i)
100   continue
c
      return
      end
c
      subroutine log10_array(dest, ni, nj, tri_npts, data_is_trimesh)
      implicit none
c
      integer ni, nj, tri_npts
      real dest(1)
      logical data_is_trimesh
c
c     locals
      integer i, ilimit
c
c     This is a modified log10 function for use in analyzing
c     device/process simulator data. Since the quantity may be signed,
c     a simple log cannot be taken. The compromise is that quantities
c     will be hard limited to 1.0 in minimum value. The original sign
c     of the quantity is transferred to the result.
c
      if( data_is_trimesh ) then
         ilimit = tri_npts
      else
         ilimit = ni*nj
      endif
      do 100 i=1,ilimit
         dest(i) = SIGN(ALOG10(ABS(dest(i))+1.0),dest(i))
100   continue
c
      return
      end

