c ETOPO5データを切り出すプログラム
c 2001/01/29 by A.Tsubota
c コンパイル時 要-byteswapio

c 変数定義

       parameter(im=4320,jm=2160)
       parameter(nlo=4320,nla=2160,nle=nlo*2)

       integer*2 iv(nlo)
       dimension map(im,jm)
       real*8 fblon,felon,felat,fblat

c 必要緯度経度読み込み

       open(3,file='init.dat')
       read(3,*) idate,itime,fblon,felon,felat,fblat
       close(3)

c 読み込み

       dd=5.0/60.0
       ddd=5.0/120.0

       fw=fblon+ddd
       fe=felon-ddd
       fn=fblat-ddd
       fs=felat+ddd

       iw=int(fblon)*12
       ie=int(felon)*12
       in=int(90-fblat)*12
       is=int(90-felat)*12
       if(felat.eq.-90.) then
         is=is-1
       end if

       open(31,file='topo/etopo5.dem',access='direct',recl=nle)

       do j=in,is
          la=j+1
c          write(6,*) j
          read(31,rec=la) iv
c           write(6,*) iv
          do i=iw,ie
             imo=i-iw+1
             jmo=j-in+1
             map(imo,jmo)=iv(i)
          end do
       end do

       close(31)

       open(32,file='topo/etopo5.xyz',status='new')
       do j=1,jmo
          do i=1,imo
             alon=fblon+(i-1.)*dd
             alat=fblat-(j-1.)*dd
             write(32,'(2f10.5,2x,i7)') alon,alat,map(i,j)
          end do
       end do

       close(32)

 999   continue
       stop
       end
 
