      parameter(iq=360,jq=160,kq=45)
      dimension x(iq),y(jq),z(kq)
      dimension vk(iq,jq,kq)
      dimension plt(iq,jq)
      parameter(nbr3=3*((iq+2)*(jq+2)*2/32+32))
      dimension ibr(nbr3),xt(4),yt(4)
      dimension ipat(15)
      character clevel(15)*9,ctitle*9
      pai=2.*asin(1.0)
c--
c--input file------
      open(10,file='KV-GLOBAL.DATA',form='unformatted')
      read(10) (x(i),i=1,iq),(y(j),j=1,jq),(z(k),k=1,kq)
      read(10) (((vk(i,j,k),i=1,iq),j=1,jq),k=1,kq)
c--
c--Plot initialization--
      write(*,*) 'workstation id(i) ? '
      call sgpwsn
      read(*,*) iws
      call gropn(iws)
      call sglset('lfull',.true.)
      call slrat(1.,18.6/26.)
c--
      do 1000 k=1,kq
c********************************************************
      do 10 j=1,jq
      do 10 i=1,iq
       plt(i,j)=vk(i,j,k)
   10 continue    
      call grfrm
      call grswnd(x(1),x(iq),y(1),y(jq))
      ux1=0.07
      ux2=1.-ux1+0.025
      uy1=0.5*18.6/26.-0.5*(ux2-ux1)*(y(jq)-y(1))/(x(iq)-x(1))
      uy2=0.5*18.6/26.+0.5*(ux2-ux1)*(y(jq)-y(1))/(x(iq)-x(1))
      call grsvpt(ux1,ux2,uy1,uy2)
      call grstrn(1)
      call grstrf
c--Kv plot--
      call gllset('lmiss',.true.)
      call glrset('rmiss',999.)
      call ueitlv
      call sglset('lsoftf',.true.)
      do n=1,7
       x1=10.**(-4.500+(n-2)*0.5)
       x2=10.**(-4.500+(n-1)*0.5)
       if(n.eq.1) x1=x1/10000.
       if(n.eq.8) x2=x2*10000.
       if(n.eq.1) ipat(n)=  600
       if(n.eq.2) ipat(n)=40655
       if(n.eq.3) ipat(n)=60655
       if(n.eq.4) ipat(n)=65655
       if(n.eq.5) ipat(n)=70655
       if(n.eq.6) ipat(n)=75655
       if(n.eq.7) ipat(n)=85655
       call uestlv(x1,x2,ipat(n))
      end do
      call uetone(plt,iq,iq,jq)
c--Topo plot--
      do j=1,jq
      do i=1,iq
       if(plt(i,j).eq.999.) then
        plt(i,j)= 100.
       else
        plt(i,j)=-100.
       end if
      end do
      end do
      call ueitlv
      call glrset('rmiss',999.)
      call uestlv(0.,100.,615)
      call uetone(plt,iq,iq,jq)
c--Memori,Label plot--
c--small memori--
      mxs1=int(x( 1))/2*2+2
      mxe1=int(x(iq))/2*2
      dmx1=2
      mys1=int(y( 1))/2*2+2
      mye1=int(y(jq))/2*2
      dmy1=2
c--large memori--
      mxs2=int(x( 1))/20*20+20
      mxe2=int(x(iq))/20*20
      dmx2=20
      mys2=int(y( 1))/20*20
      mye2=int(y(jq))/20*20
      dmy2=20
c--
      call uzrset('rsizel1',0.0075)
      call uzrset('rsizec1',0.0075)
      call uzrset('rsizet1',-0.005)
      call uzrset('rsizet2',-0.010)
      call memori(mxs1,mxe1,dmx1,mys1,mye1,dmy1,
     @            mxs2,mxe2,dmx2,mys2,mye2,dmy2)
      call uxsttl('b','longitude',0.)
      call uysttl('l','latitude' ,0.)
      write(ctitle,'("Z=",F6.1,"m")') z(k)
      call uzrset('rsizec1',0.0075*2.)
      call uxsttl('t',ctitle,0.)                                
c--Tone Bar--
      call sglset('lsoftf',.true.)     
      call sglset('lcntl',.true.)
      clevel(1)='        '
      clevel(2)='10|-4.50"'
      clevel(3)='10|-4.00"'
      clevel(4)='10|-3.50"'
      clevel(5)='10|-3.00"'
      clevel(6)='10|-2.50"'
      clevel(7)='10|-2.00"'
      uxx1=(ux1+ux2)*0.5-0.3
      uxx2=(ux1+ux2)*0.5+0.3
      uyy1=uy1-0.06
      uyy2=uyy1+0.015
      do 20 n=1,7
       xt(1)=(float(n-1)*uxx2+float(7-n+1)*uxx1)/7
       xt(2)=(float(n  )*uxx2+float(7-n  )*uxx1)/7
       xt(3)=xt(2)
       xt(4)=xt(1)
       yt(1)=uyy1
       yt(2)=uyy1
       yt(3)=uyy2
       yt(4)=uyy2
       call sgtnzv(4,xt,yt,ipat(n))
       call sglnv(xt(1),yt(1),xt(2),yt(2))
       call sglnv(xt(2),yt(2),xt(3),yt(3))
       call sglnv(xt(3),yt(3),xt(4),yt(4))
       call sglnv(xt(4),yt(4),xt(1),yt(1))
       call sgtxzv(xt(1),yt(1)-0.01,clevel(n),0.01,0,0,3)
   20 continue  
      call sgtxzv(uxx2+0.03,(uyy1+uyy2)*0.5,'(m|2"s|-1")',
     @     0.01,0,0,3) 
c***************************************************************
 1000 continue
  999 call sgcls  
      stop
      end
c
c
c
      subroutine memori(mxs1,mxe1,dmx1,mys1,mye1,dmy1,
     @                  mxs2,mxe2,dmx2,mys2,mye2,dmy2)
      dimension rx1(400),rx2(40),ry1(400),ry2(40)
      character cx2(40)*4,cy2(40)*3
c--syomemori--
      im1=0
      do i=mxs1,mxe1,dmx1
       im1=im1+1
       rx1(im1)=float(i)
      end do
      jm1=0
      do i=mys1,mye1,dmy1
       jm1=jm1+1
       ry1(jm1)=float(i)
      end do
      im2=0
      do i=mxs2,mxe2,dmx2
       im2=im2+1
       rx2(im2)=float(i)
       if(rx2(im2).le.180.) then
        write(cx2(im2),'(I3,"E")') int(rx2(im2))
       else
        write(cx2(im2),'(I3,"W")') 360-int(rx2(im2))
       end if
      end do    
      jm2=0
      do i=mys2,mye2,dmy2
       jm2=jm2+1
       ry2(jm2)=float(i)
       if(ry2(jm2).gt.0) then
        write(cy2(jm2),'(I2,"N")') int(ry2(jm2))
       end if
       if(ry2(jm2).eq.0.    ) ry2(jm2)=0.0001
       if(ry2(jm2).eq.0.0001) cy2(jm2)=" EQ"
       if(ry2(jm2).lt.0) then
        write(cy2(jm2),'(I2,"S")') int(abs(ry2(jm2)))
       end if
      end do
c--
      call uxaxlb('b',rx1,im1,rx2,cx2,4,im2)
      call uxaxlb('t',rx1,im1,rx2,cx2,4,im2)
      call uyaxlb('l',ry1,jm1,ry2,cy2,3,jm2)
      call uyaxlb('r',ry1,jm1,ry2,cy2,3,jm2)
      return
      end
