c***********************************************************************
      SUBROUTINE phy_debug (u,v,w,p,cc,nx,ny,nz,t,string)
c***
c     debugging routine to write min and max and their position
c     of main fields
c***
      include "undefined.h"
      INTEGER nx,ny,nz,t
      DOUBLE PRECISION u(nx,ny,nz), v(nx,ny,nz), w(nx,ny,nz), 
     %                 p(nx,ny,nz), cc(nx,ny,nz)
      CHARACTER *(*) string
c***
      write (*,*) 'physics debug, timestep: ', t, ', ', string
      call writeminmax ('u', u, nx, ny, nz)
      call writeminmax ('v', v, nx, ny, nz)
      call writeminmax ('w', w, nx, ny, nz)
      call writeminmax ('p', p, nx, ny, nz)
      call writeminmax ('cc', cc, nx, ny, nz)
c***
      return 
      end

c***********************************************************************
      SUBROUTINE writeminmax(string,a,nx,ny,nz)
c***
      include "undefined.h"
      INTEGER nx,ny,nz,i,j,k,i1,j1,k1
      DOUBLE PRECISION a(nx,ny,nz), FINDMAX,FINDMIN,xmax,xmin
      CHARACTER *(*) string
      EXTERNAL FINDMAX,FINDMIN
c***
      xmax = FINDMAX(a,nx,ny,nz,i,j,k)
      xmin = FINDMIN(a,nx,ny,nz,i1,j1,k1)
      write(*,10)PPRANK,string,xmax,i,j,k,xmin,i1,j1,k1
   10 format(1i1,1x,a10,1p,1e12.5,'(',3i3,')',1x,'***',1x,
     %     1p,1e12.5,'(',3i3,')')
c***
      return
      end
