       include 'fgraph.fi'
       subroutine zoom(icol1,icol2,irow1,irow2,ztype,ierr)
       save itemp,jtemp
       common/gridsp/ iright,jupp
       common/scalef/ iwc0,jwc0,nxhpix,nyhpix,xpix,ypix,xscr,yscr
       common /setxy/ xx(2),yy(2),xp1(4),yp1(4),iplotr,sizel,
     & ncharx,nchary,sizex,sizey,adelx,adely,pllx,plly,
     & lintx,linty,xscale,yscale,xxscal,yyscal,mscale,delx,dely
c       character*40 ifile,ifile2,ifile3,acfile
c       character*6 access
c       common/files/ifile,ifile2,ifile3,acfile,mxhach,access
       character*1 ctype,ztype
       common/captur/icapt,iwhite,ctype
c       integer*2 displaycursor,toggle,cmode
       data itemp/1/,jtemp/1/

       ierr = 0
c******MOUSE RETURNS VIRTUAL COORDINATES
c******THIS TAKES CARE OF HORIZONTAL RESOLUTION OF 320
       if(iplotr.eq.8.or.iplotr.eq.11) then
       ipixf=2
       else
       ipixf=1
       endif

c       toggle = 1
c       cmode = displaycursor(toggle)
c******FIND THE ROWS AND COLUMNS OF THE GRID THAT CORRESPOND
c******TO THE BOUNDING RECTANGLE OF THE CURSOR POSITIONS 

10     call tgin(lx,ly)
       lx=lx/ipixf
       if(lx.lt.iwc0) lx=iwc0
       if(ly.gt.jwc0) ly=jwc0
       if(lx.gt.iright) lx=iright
       if(ly.lt.jupp) ly=jupp
       icol1 = (lx-iwc0)/xpix + itemp
       irow1 = (jwc0-ly)/ypix + jtemp 

c******MAKE DELAY BETWEEN MOUSE CLICKS
c******SOMEHOW THIS APPEARS NECESSARY TO MAKE THE MOUSE WORK
c******CORRECTLLY ALL THE TIME

       call sleep(1.)

       call tgin(iux,iuy)
       iux=iux/ipixf
       if(iux.lt.iwc0) iux=iwc0
       if(iuy.gt.jwc0) iuy=jwc0
       if(iux.gt.iright) iux=iright
       if(iuy.lt.jupp) iuy=jupp
       icol2 = (iux-iwc0)/xpix + itemp 
       irow2 = (jwc0-iuy)/ypix + jtemp 

       if(ztype.eq.'m') then
         if(icol2.le.icol1.or.irow2.le.irow1) then
         ierr = 1
         return
         endif
       endif

c******THE FOLLOWING TWO STATEMENTS ARE NEEDED WHEN ZOOMING
c******REPEATIVELY ON AN ORIGINAL DIRECT ACCESS FILE WHEN
c******SUBSETS ARE NOT CREATED

c       if(access.eq.'direct'.and.ctype.ne.'l') then
c       itemp = icol1
c       jtemp = irow1
c       endif

c      hides the cursor
       m1=2
       call mouse(m1,m2,m3,m4)
       return
       end
c******************************************************************************
       subroutine tgin(ix,iy)
c      initialize mouse
       m1=0
       call mouse(m1,m2,m3,m4)

c      show mouse cursor
       m1=1
       call mouse(m1,m2,m3,m4)

c      get mouse position coordinates
       m2=0
       m1=3
10     call mouse(m1,m2,ix,iy)
       if(m2.eq.0) go to 10
       return
       end
