c EZXPLOT routines in progress July, 1993

c EZXINIT creates an X window for plotting
c   Inputs:  nx = number of x pixels
c            ny = number of y pixels
      subroutine EZXINIT(nx,ny)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      call linitializewindow(nx,ny)
      call lsetcolor(1)          !set to black
      call llinestyle(0,0,0,0)   !set to fastest line width 
      nxpix=nx
      nypix=ny     
      return
      end

c EZXQUIT exits from X window after user hits mouse key
      subroutine EZXQUIT
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      print *,'Hit mouse key to exit X window'
      call EZXMESS('Hit mouse key to exit X window')
      call ldoit
      call lwaitforbuttondown(ibut,ix,iy,mod)
      call ldie
      return
      end

c EZXWIND defines local coordinates for plotting
c   Inputs:  x1,x2,y1,y2  =  reference rectangle in pixels
c            x3,x4,y3,y4  =  local values at boundaries of rectangle
      subroutine EZXWIND(x1,x2,yy1,yy2,x3,x4,y3,y4)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      if (x3.eq.x4.or.y3.eq.y4) then
         print *,'***Error in EZXWIND.  Singular coordinates'
         print *,'x3,x4,y3,y4 = ',x3,x4,y3,y4
      end if
      y1=nypix-yy1
      y2=nypix-yy2
      axplot=(x2-x1)/(x4-x3)
      ayplot=(y2-y1)/(y4-y3)
      bxplot=x1-x3*axplot
      byplot=y1-y3*ayplot
      xfrm1=x3
      xfrm2=x4
      yfrm1=y3
      yfrm2=y4
      return
      end

c EZXMOVE moves current pen position without drawing line
c   Inputs:  x,y  =  coordinates of pen      
      subroutine EZXMOVE(x,y)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      xpen=axplot*x+bxplot
      ypen=ayplot*y+byplot
      call lmoveto(nint(xpen),nint(ypen))
      return
      end

c EZXDRAW draws line from current pen position to new pen position
c   Inputs:  x,y  =  new pen position
      subroutine EZXDRAW(x,y)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      xpen=axplot*x+bxplot
      ypen=ayplot*y+byplot
      call llineto(nint(xpen),nint(ypen))
      return
      end

c EZXPOLY draws polygon 
      subroutine EZXPOLY(x,y,n)
      parameter (nbuf=5000)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      real x(*),y(*)
      integer*4 ix(nbuf),iy(nbuf)
      j=0
      do 10 i=1,n
         j=j+1
         ix(j)=nint(axplot*x(i)+bxplot)
         iy(j)=nint(ayplot*y(i)+byplot)
         if (j.eq.nbuf) then
            call llines(ix,iy,nbuf)
            ix(1)=ix(nbuf)
            iy(1)=iy(nbuf)
            j=1
         end if
10    continue
      if (j.ne.1) call llines(ix,iy,j)
      xpen=axplot*x(n)+bxplot
      ypen=ayplot*y(n)+byplot
      return
      end


c EZXPOLYFILL draws filled polygon 
      subroutine EZXPOLYFILL(x,y,n)
      parameter (nbuf=5000)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      real x(*),y(*)
      integer*4 ix(nbuf),iy(nbuf)
      j=0
      do 10 i=1,n
         j=j+1
         ix(j)=nint(axplot*x(i)+bxplot)
         iy(j)=nint(ayplot*y(i)+byplot)
10    continue
      if (j.ne.1) call lfillpolygon(ix,iy,j,1,0)
      xpen=axplot*x(n)+bxplot
      ypen=ayplot*y(n)+byplot
      return
      end


c EZXCIR draws circle of specified color
c  x,y = user coordinates of center
c  irad = radius in pixels
c  icol = color, 0=wht,1=blk,2=red,3=blu,4=yel,5=grn,6=brw,7=pur,8=cyn,9=mag
c  ifill = 0 for no fill, =1 for fill
      subroutine EZXCIR(x,y,irad,icol,ifill)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      xpen=axplot*x+bxplot
      ypen=ayplot*y+byplot
      if (icol.lt.0.or.icol.gt.20) then
         print *,'**EZXCIR warning: icol = ',icol
         icol=0
      endif
      call lsetcolor(icol)      
      if (ifill.eq.0) then
         call ldrawhollowcircle(nint(xpen),nint(ypen),irad)
      else
         call ldrawfilledcircle(nint(xpen),nint(ypen),irad)
      end if
      return
      end


c EZXLINE defines line width and dash length
c  iwid  = line width in pixels
c        = 0 for thinnest, fastest line
c  idash = dash length in pixels
c        = 0 for solid line
      subroutine EZXLINE(iwid,idash)
      call llinestyle(iwid,idash,0,0)
      return
      end

c EZXCOL defines plotting color
c  icol = color, 0=wht,1=blk,2=red,3=blu,4=yel,5=grn,6=brw,7=pur,8=cyn,9=mag
      subroutine EZXCOL(icol)
      if (icol.lt.0.or.icol.gt.20) then
         print *,'**EZXCOL warning: icol = ',icol
         icol=0
      endif
      call lsetcolor(icol)
      return
      end

c EZXFRAM draws rectangle on screen
c   Inputs:  x1,x2,y1,y2  =  coordinates of rectangle
      subroutine EZXFRAM(x1,x2,y1,y2)
      call EZXMOVE(x1,y1)
      call EZXDRAW(x2,y1)
      call EZXDRAW(x2,y2)
      call EZXDRAW(x1,y2)
      call EZXDRAW(x1,y1)
      return
      end

c EZXCLR erases the screen
      subroutine EZXCLR
      call lclearwindow
      return
      end

c EZXCLRB erases the screen within a rectangle
c   Inputs:  x1,x2,y1,y2 = boundary of rectangle
      subroutine EZXCLRB(x1,x2,y1,y2)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      xx1=axplot*x1+bxplot
      xx2=axplot*x2+bxplot
      yy1=ayplot*y1+byplot
      yy2=ayplot*y2+byplot
      dx=xx2-xx1
      dy=yy1-yy2
      call lclearpartwindow(nint(xx1),nint(yy2),nint(dx),nint(dy))
      return
      end

c EZXBOX draws a filled box in current color
c   Inputs:  x1,x2,y1,y2 = boundary of rectangle
      subroutine EZXBOX(x1,x2,y1,y2)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      xx1=axplot*x1+bxplot
      xx2=axplot*x2+bxplot
      yy1=ayplot*y1+byplot
      yy2=ayplot*y2+byplot
      dx=xx2-xx1
      dy=yy1-yy2
      call ldrawfilledbox(nint(xx1),nint(yy2),nint(dx),nint(dy))
      return
      end

c EZXLOADFONT loads desired font name
c   Input:  name  =  string defining font name
c   Returns:   i  =  index for font to be used by EZXSETFONT
      subroutine EZXLOADFONT(i,name)
      character*(*) name
      call lloadfont(i,name)
      return
      end
      
c EZXSETFONT sets font
c   Input:  i  =  font index (defined by EZXLOADFONT)
      subroutine EZXSETFONT(i)
      call lsetfont(i)
      return
      end

c EZXLAB writes text at current pen position
c   Input:  text = desired text
      subroutine EZXLAB(text)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      character*(*) text
      character text2*200
      m=min(len(text),200)
      call DEWEIRD(text,m,text2)
      do 10 i=m,1,-1
         if (text2(i:i).ne.' ') go to 20
10    continue
20    mm=i             !length of string without blanks
      call lprint(text2(1:mm))
      return
      end

      subroutine DEWEIRD(text1,n,text2)
      character*1 text1(n),text2(n)
      character abc*52,num*40
      save abc,num
      data abc/'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'/
! I removed \ from this line because it gives unknown escape sequence warning
!      data num/'0123456789!@#$%^&*()\-=|_+[]{};:"~,./<>?'/
      data num/'0123456789!@#$%^&*()--=|_+[]{};:"~,./<>?'/
      do 50 i=1,n
         text2(i)=' '
         do 30 j=1,52
            if (text1(i).eq.abc(j:j)) go to 45
30       continue
         do 40 j=1,40
            if (text1(i).eq.num(j:j)) go to 45
40       continue
         go to 50
45       text2(i)=text1(i)
50    continue
      return
      end

c EZXNUM write number at current pen position
c   Inputs:  fp  =  number (real)
c            fmt =  desired format (e.g., 'f5.2' or 'i3')
      subroutine EZXNUM(fp,fmt)
      character*(*) fmt
      character*20 fmt1,format,text,textnb
      if (fmt(1:1).eq.' ') go to 900
      fmt1='                    '
      fmt1=fmt
      if (fmt1(1:1).eq.' ') go to 900
      do 10 i=1,20
         if (fmt1(i:i).eq.' ') go to 11
10    continue
      go to 900
11    nc=i-1                  !last nonblank character
      format(1:1)='('
      format(2:nc+1)=fmt(1:nc)
      format(nc+2:nc+2)=')'
      if (fmt(1:1).eq.'I'.or.fmt(1:1).eq.'i') then
         ifp=nint(fp)
         write (text,format) ifp
      else
         write (text,format) fp
      end if
      nb=0
      nc=0
      do 20 i=1,20
         if (text(i:i).eq.' ') go to 20
         if (nb.eq.0) nb=i
         nc=i
20    continue
      ncnb=nc-nb+1
      if (ncnb.le.0) go to 900
      textnb(1:ncnb)=text(nb:nc)
      call EZXLAB(textnb(1:ncnb))
900   return
      end

c EZXANG sets angle to draw text
c   Input:  tang  =  angle of text (degrees c.w. from horizontal)
c                 =   0. for normal
c                 =  90. for up
c                 = 270. for down
      subroutine EZXANG(tang)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      call ltextangle(tang)
      return
      end

c EZXLORG allows the user to specify how text or numbers will be
c centered around the current pen position.  This will affect
c EZXLAB and EZXNUM.
c                          
c                 7xxxxxx8xxxxxx9
c     nlorg=      4      5      6     centers block as shown
c                 1xxxxxx2xxxxxx3
c
      subroutine EZXLORG(nlorg)
      call laligntext(nlorg)
      return
      end

c EZXTIC moves pen position nx pixels to the right and ny pixels up
c   Input:  nx,ny = number of pixels to move
c           nup   = 0 for move (no draw)
c           nup   = 1 for drawing line
      subroutine EZXTIC(nx,ny,nup)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      xoff=float(nx)
      yoff=float(ny)
      xpen2=xpen+xoff
      ypen2=ypen-yoff
      if (nup.eq.1) then
         call llineto(nint(xpen2),nint(ypen2))
      else
         call lmoveto(nint(xpen2),nint(ypen2))
      end if
      xpen=xpen2
      ypen=ypen2
      return
      end

c EZXAXES makes a frame with tics and tic labels as specified.
c xtic   =  small tic increment
c xlab   =  big tic increment (length is 2*nxticl)
c nxticl =  small tic length in pixels
c xfrmt  =  format for x axis numbers (next to big tics)
c etc.
      subroutine EZXAXES(xtic,xlab,nxticl,xfrmt,
     &                   ytic,ylab,nyticl,yfrmt)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      character*(*) xfrmt,yfrmt
      character*20 xfrmt1,yfrmt1
      xfrmt1=xfrmt
      yfrmt1=yfrmt
      x1=xfrm1
      x2=xfrm2
      y1=yfrm1
      y2=yfrm2
      if (x1.gt.x2) then             !switch if reverse order
         scr=x1
         x1=x2
         x2=scr
      end if
      if (y1.gt.y2) then             !switch if reverse order
         scr=y1
         y1=y2
         y2=scr
      end if
      call EZXFRAM(x1,x2,y1,y2)
      scrx1=x1-1./axplot         
      scrx2=x2+1./axplot
      scry1=y1-1./ayplot
      scry2=y2+1./ayplot
      call EZXFRAM(scrx1,scrx2,scry1,scry2)       !offset frame for bold axes
c
      xstart=float(int(abs(x1)/xtic+0.999999))*xtic
      if (x1.lt.0.) xstart=-xstart+xtic
      y0=yfrm1
      do 10 x=xstart,x2,xtic
         call EZXMOVE(x,y0)
10       call EZXTIC(0,nxticl,1)
      xstart=float(int(abs(x1)/xlab+0.999999))*xlab
      if (x1.lt.0.) xstart=-xstart+xlab
      call EZXLORG(8)
      do 20 x=xstart,x2,xlab
         call EZXMOVE(x,y0)
         call EZXTIC(0,2*nxticl,1)
         call EZXMOVE(x,y0)
         call EZXTIC(0,-3,0)
         if (xfrmt1(1:1).ne.' ') call EZXNUM(x,xfrmt1)
20    continue

      ystart=float(int(abs(y1)/ytic+0.999999))*ytic
      if (y1.lt.0.) ystart=-ystart+ytic
      x0=xfrm1
      do 30 y=ystart,y2,ytic
         call EZXMOVE(x0,y)
30       call EZXTIC(nyticl,0,1)
      ystart=float(int(abs(y1)/ylab+0.999999))*ylab
      if (y1.lt.0.) ystart=-ystart+ylab
      call EZXLORG(6)
      do 40 y=ystart,y2,ylab
         call EZXMOVE(x0,y)
         call EZXTIC(2*nyticl,0,1)
         call EZXMOVE(x0,y)
         call EZXTIC(-5,0,0)
         if (yfrmt1(1:1).ne.' ') call EZXNUM(y,yfrmt1)
40    continue
c
      call EZXLORG(1)
      call ldoit
      return
      end

c EZXLAX puts x and y axes labels on axes
c   Inputs:  xlabel = x-axis label
c            nxoff  = number of pixels to offset label
c            etc.
      subroutine EZXLAX(xlabel,nxoff,ylabel,nyoff)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      character*(*) xlabel,ylabel
      integer*4 nxoff,nyoff
      x1=xfrm1
      x2=xfrm2
      y1=yfrm1
      y2=yfrm2
      call EZXLORG(8)
      xavg=(x1+x2)/2.
      call EZXMOVE(xavg,y1)
      call EZXTIC(0,-nxoff,0)
      call EZXLAB(xlabel)
      call EZXLORG(2)
      call EZXANG(90.)
      yavg=(y1+y2)/2.
      call EZXMOVE(x1,yavg)
      call EZXTIC(-nyoff,0,0)
      call EZXLAB(ylabel)
      call EZXANG(0.)
      call EZXLORG(1)
      return
      end

c EZXTIT puts title above axes
c   Inputs:  title = title
c            nyoff  = number of pixels to offset label
      subroutine EZXTIT(title,nyoff)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      character*(*) title
      integer*4 nyoff
      x1=xfrm1
      x2=xfrm2
      y1=yfrm1
      y2=yfrm2
      call EZXLORG(2)
      xavg=(x1+x2)/2.
      call EZXMOVE(xavg,y2)
      call EZXTIC(0,nyoff,0)
      call EZXLAB(title)
      call EZXLORG(1)
      return
      end



c EZXSYMB plots symbols at current pen position
c n=1  --  +
c n=2  --  square
c n=3  --  triangle
c n=4  --  inverted triangle
c n=5  --  X
c n=6  --  diamond
c npix = symbol half-height in pixels
      subroutine EZXSYMB(n,npix)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      if (n.eq.1) then
         call EZXTIC(-npix,0,0)
         call EZXTIC(2*npix,0,1)
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(0,2*npix,1)
         call EZXTIC(0,-npix,0)
      else if (n.eq.2) then
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(2*npix,0,1)
         call EZXTIC(0,2*npix,1)
         call EZXTIC(-2*npix,0,1)
         call EZXTIC(0,-2*npix,1)
         call EZXTIC(npix,npix,0)
      else if (n.eq.3) then
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(2*npix,0,1)
         call EZXTIC(-npix,2*npix,1)
         call EZXTIC(-npix,-2*npix,1)
         call EZXTIC(npix,npix,0)
      else if (n.eq.4) then
         call EZXTIC(npix,npix,0)
         call EZXTIC(-2*npix,0,1)
         call EZXTIC(npix,-2*npix,1)
         call EZXTIC(npix,2*npix,1)
         call EZXTIC(-npix,-npix,0)
      else if (n.eq.5) then
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(2*npix,2*npix,1)
         call EZXTIC(-2*npix,0,0)
         call EZXTIC(2*npix,-2*npix,1)
         call EZXTIC(-npix,npix,0)
      else
         call EZXTIC(0,-npix,0)
         call EZXTIC(npix,npix,1)
         call EZXTIC(-npix,npix,1)
         call EZXTIC(-npix,-npix,1)
         call EZXTIC(npix,-npix,1)
         call EZXTIC(0,npix,0)
      end if
      return
      end
      
      
c EZXSYMBFAT plots fat symbols at current pen position
c n=1  --  +
c n=2  --  square
c n=3  --  triangle
c n=4  --  inverted triangle
c n=5  --  X
c n=6  --  diamond
c npix = symbol half-height in pixels
      subroutine EZXSYMBFAT(n,npix)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
     
      do ixoff=-1,1
      do iyoff=-1,1
         call EZXTIC(ixoff,iyoff,0)
     
      if (n.eq.1) then
         call EZXTIC(-npix,0,0)
         call EZXTIC(2*npix,0,1)
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(0,2*npix,1)
         call EZXTIC(0,-npix,0)
      else if (n.eq.2) then
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(2*npix,0,1)
         call EZXTIC(0,2*npix,1)
         call EZXTIC(-2*npix,0,1)
         call EZXTIC(0,-2*npix,1)
         call EZXTIC(npix,npix,0)
      else if (n.eq.3) then
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(2*npix,0,1)
         call EZXTIC(-npix,2*npix,1)
         call EZXTIC(-npix,-2*npix,1)
         call EZXTIC(npix,npix,0)
      else if (n.eq.4) then
         call EZXTIC(npix,npix,0)
         call EZXTIC(-2*npix,0,1)
         call EZXTIC(npix,-2*npix,1)
         call EZXTIC(npix,2*npix,1)
         call EZXTIC(-npix,-npix,0)
      else if (n.eq.5) then
         call EZXTIC(-npix,-npix,0)
         call EZXTIC(2*npix,2*npix,1)
         call EZXTIC(-2*npix,0,0)
         call EZXTIC(2*npix,-2*npix,1)
         call EZXTIC(-npix,npix,0)
      else
         call EZXTIC(0,-npix,0)
         call EZXTIC(npix,npix,1)
         call EZXTIC(-npix,npix,1)
         call EZXTIC(-npix,-npix,1)
         call EZXTIC(npix,-npix,1)
         call EZXTIC(0,npix,0)
      end if
      
         call EZXTIC(-ixoff,-iyoff,0)
         
      enddo
      enddo
      
            
      return
      end
     
      

c EZXDIG returns the mouse position when a mouse button is hit
c   Returns:  x,y =  local coordinates of mouse 
c             ibut = 1,2,3 for three mouse buttons
c                  = 4,5,6 for mouse buttons with shift key depressed
      subroutine EZXDIG(x,y,ibut)
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg
      call ldoit 
      call lwaitforbuttondown(ibut,ix,iy,imod)
      if (imod.ne.0) ibut=ibut+3
      xpen=float(ix)
      ypen=float(iy)
      x=(xpen-bxplot)/axplot
      y=(ypen-byplot)/ayplot  
      return
      end

c EZXMESS displays message at bottom of window
      subroutine EZXMESS(text)
      character*(*) text
      common/ezxcom/xpen,ypen,axplot,bxplot,ayplot,byplot,
     &             xfrm1,xfrm2,yfrm1,yfrm2,nxpix,nypix,
     &             cang,nctall,nopenseg 
      call ldoit
      call lclearpartwindow(0,nypix-20,nxpix,nypix)
      call EZXLORG(1)
      call EZXANG(0.)
      call lmoveto(1,nypix)
      call lprint(text)      
      return
      end

c EZXDUMP dumps screen to Postscript file
      subroutine EZXDUMP(filename)
      character*(*) filename
c      call lscreendump(filename)   !old version

      character*200 cmd              !Paul Earle version
c      call EZXMESS('Please click on window to dump')
      cmd= 'rm ' // filename
      call system(cmd)
      cmd= 'xwd | xpr -device ps > ' // filename
      call system(cmd)

      return
      end

c EZXNICE determines reasonable spacing for large
c and small tics for a given interval.
      subroutine EZXNICE(xmin,xmax,tic1,tic2)
      dx=abs(xmax-xmin)
      scale=10.**int(log10(dx))
      if (dx.lt.1.) scale=scale/10.
      dxnorm=dx/scale               !should be between 1 and 10
      if (dxnorm.le.1.1) then
         tic1=0.1
         tic2=0.2
      else if (dxnorm.le.2.1) then
         tic1=.1
         tic2=.5
      else if (dxnorm.le.4.1) then
         tic1=0.5
         tic2=1.0 
      else
         tic1=1.0
         tic2=2.0
      end if
      tic1=tic1*scale
      tic2=tic2*scale
      return
      end
