       subroutine mnmx3d ( qty, i1, j1, k1, i2, j2, k2, qmin, qmax
     1                   , nlog )
c
c    dac:zeus3d.mnmx3d <----------- finds extrema of a regular 3-d array
c                                                             july, 1992
c
c    written by: David Clarke
c    modified 1:
c
c  PURPOSE: This subroutine returns the maximum and minimum value of a
c  rectangular 3-D array.  It differs from MNMX by using "  max" and
c  "  min" instead of "ISMAX" and "ISMIN" (thereby reducing execution
c  time by about 30%) and by not returning the grid location of the
c  extrema.
c
c  INPUT VARIABLES:
c    qty             the 3-D array to be searched for extrema.
c    i1              inner i index.
c    j1              inner j index.
c    k1              inner k index.
c    i2              outer i index.
c    j2              outer j index.
c    k2              outer k index.
c    nlog            =0 => return extrema
c                    =1 => return log10 of extrema
c
c  OUTPUT VARIABLES:
c    qmin            minimum value
c    qmax            maximum value
c
c  LOCAL VARIABLES:
c    qmink           minimum value for each k-sweep
c    qmaxk           maximum value for each k-sweep
c
c----------------------------------------------------------------------
c
c
c-----------------------------------------------------------------------
c------------------------ IMPLICIT STATEMENTS --------------------------
c-----------------------------------------------------------------------
c
       implicit      none
c
c-----------------------------------------------------------------------
c----------------------------- PARAMETERS ------------------------------
c-----------------------------------------------------------------------
c
c      Primary parameters:
c
       integer       in      , jn      , kn      , ijkn    , nxpx
     1             , nypx    , nxrd    , nyrd    , niov    , nios
     2             , ntsl    , mn      , nmd     , isig
       real*8        pi  , tiny  , huge  , one  , mone  , haf  , zro
c
       parameter     ( in = 5005, jn = 1, kn = 10, ijkn = 5005)
       parameter     ( nxpx = 1, nypx = 1, nxrd =   1, nyrd =   1 )
       parameter     ( niov =  20, nios =  20, ntsl =1000 )
       parameter     ( mn   =   1, nmd  =   1 )
       parameter     ( pi   = 3.1415926535898 )
       parameter     ( isig = 9, tiny = 1.0d-99, huge = 1.0d+99 )
       parameter     ( one  = 1.0d+00, mone = -1.0d+00
     1                               , haf  =  0.5d+00, zro = 0.0d+00)
c
c      Secondary parameters:
c
       integer        idim    , jdim
     1              , nt01    , nt02    , nt03    , nt04    , nt05
     2              , nt06    , nt07    , nt08    , nt09    , nt10
     3              , nt11    , nt12    , nt13    , nt14    , nt15
     4              , nt16    , nt17    , nt18    , nt19    , nt20
       parameter     ( idim =   kn, jdim =   in )
       parameter     ( nt01 = 600, nt02 = 600, nt03 =   7, nt04 =   5 )
       parameter     ( nt05 =  18, nt06 =   1, nt07 =  10, nt08 =  12 )
       parameter     ( nt09 =   5, nt10 =  54, nt11 =   8 )
       parameter     ( nt12 =        16, nt17 =         4 )
       parameter     ( nt13 = nt12 +  4, nt18 = nt17 +  1 )
       parameter     ( nt14 = nt13     , nt19 = nt18      )
       parameter     ( nt15 = nt14 + 30, nt20 = nt19 +  3 )
       parameter     ( nt16 = nt14 + 42 )
c
c-----------------------------------------------------------------------
c-------------------- SCRATCH SPACE (WORKER ARRAYS) --------------------
c-----------------------------------------------------------------------
c
c      1-D worker arrays
c
       real*8        wa1d    (ijkn), wb1d    (ijkn), wc1d    (ijkn)
     1             , wd1d    (ijkn), we1d    (ijkn), wf1d    (ijkn)
     2             , wg1d    (ijkn), wh1d    (ijkn), wi1d    (ijkn)
     3             , wj1d    (ijkn), wk1d    (ijkn), wl1d    (ijkn)
     4             , wm1d    (ijkn), wn1d    (ijkn), wo1d    (ijkn)
     5             , wp1d    (ijkn), wq1d    (ijkn), wr1d    (ijkn)
     6             , ws1d    (ijkn), wt1d    (ijkn), wu1d    (ijkn)
     7             , wv1d    (ijkn), ww1d    (ijkn), wx1d    (ijkn)
     8             , wy1d    (ijkn), wz1d    (ijkn)
c
c      2-D worker arrays
c
       real*8        wa2d    (idim,jdim), wa2dt   (jdim,idim)
     1             , wb2d    (idim,jdim), wb2dt   (jdim,idim)
     1             , wc2d    (idim,jdim), wc2dt   (jdim,idim)
     2             , wd2d    (idim,jdim), wd2dt   (jdim,idim)
     1             , we2d    (idim,jdim), we2dt   (jdim,idim)
     2             , wf2d    (idim,jdim), wf2dt   (jdim,idim)
c
c      3-D worker arrays
c
       real*8        wa3d    (  in,  jn,  kn), wb3d    (  in,  jn,  kn)
     1             , wc3d    (  in,  jn,  kn), wd3d    (  in,  jn,  kn)
     2             , we3d    (  in,  jn,  kn), wf3d    (  in,  jn,  kn)
     3             , wg3d    (  in,  jn,  kn)
c
       equivalence   ( wa2d    , wa2dt    ), ( wb2d    , wb2dt    )
     1             , ( wc2d    , wc2dt    ), ( wd2d    , wd2dt    )
     2             , ( we2d    , we2dt    ), ( wf2d    , wf2dt    )
       equivalence   ( wa3d    , wa2d     ), ( wb3d    , wb2d     )
     1             , ( wc3d    , wc2d     ), ( wd3d    , wd2d     )
     2             , ( we3d    , we2d     ), ( wf3d    , wf2d     )
c
c---------------------------- Common Blocks ----------------------------
c
       common / scratchr /
     1               wa1d    , wb1d    , wc1d    , wd1d    , we1d
     2             , wf1d    , wg1d    , wh1d    , wi1d    , wj1d
     3             , wk1d    , wl1d    , wm1d    , wn1d    , wo1d
     4             , wp1d    , wq1d    , wr1d    , ws1d    , wt1d
     5             , wu1d    , wv1d    , ww1d    , wx1d    , wy1d
     6             , wz1d
       common / scratchr /
     1               wa3d    , wb3d    , wc3d    , wd3d    , we3d
     2             , wf3d
     3             , wg3d
c
       integer       i       , j       , k       , i1      , j1
     1             , k1      , i2      , j2      , k2      , nlog
       real*8        qmin    , qmax
c
       real*8        qmink   (ijkn), qmaxk   (ijkn)
c
c      Careful!  "wa1d" - "wi1d" are used by BININT.
c
       equivalence   ( qmink   , wy1d     ), ( qmaxk   , wz1d     )
c
       real*8        qty     (  in,  jn,  kn)
c
c-----------------------------------------------------------------------
c
c      Extrema are first determined for each k-sweep.  Then the global
c  extrema are found among the sweep extrema.  This is done to aid the
c  EDITOR auto-tasking process.
c
       k = k1
       j = j1
       i = i1
       qmin = huge
       qmax =-huge
       do 30 k=k1,k2
           do 10 i=i1,i2
             qmin =   min ( qmin, qty(i,j,k) )
             qmax =   max ( qmax, qty(i,j,k) )
10         continue
20       continue
30     continue
c
c      Take log10 of extrema, if desired.
c
       if (nlog .eq. 1) then
         qmin =  log10 (   max ( tiny, qmin ) )
         qmax =  log10 (   max ( tiny, qmax ) )
       endif
c
       return
       end
