c 観測報デコードデータファイルのうち
c 3110または3160データのリストを取り出す
c 2000/12/27 by A.Tsubota
c コンパイル時 要-byteswapio

      integer*2 idata(4000)
      integer*2 idt1(14),idt2(10),idt3(20),idt4(4000),idt5(4000)
      integer*2 no(4)
      integer l1,l,iunit,ounit,no1,no2

      iunit=10
      open(iunit,file='inputdat',access='direct',recl=2)
      ounit=11
      open(ounit,file='datalist',status='new')

      read(*,*) l

      if(l.eq.1) then
        l1=3110
        else
	  l1=3160
      end if

      nc=1
 10   call get_record(iunit,idata,ndata)
      if (ndata.gt.0) then
*     write(*,*) nc,ndata,(idata(i),i=1,7)
         call get_data(idata,ndata,idt1,ndt1,idt2,ndt2,idt3,ndt3,
     &                 idt4,ndt4,idt5,ndt5)
*     write(*,*) nc,idt1

         else
            go to 9000
      end if

      if(idt1(8).eq.l1) then
        do i=1,4
          no1=256
 20       no2=idt3(i)-no1
          if(no2.ge.256) then
            no1=no1+256
            go to 20
          end if
          no1=no1/256
          no2=no2*256
          no(i)=no1+no2
        end do
        write(11,100) nc,idt1(8),idt2(5),idt2(6),
     &                no(1),no(2),no(3),no(4),idt1(9),idt1(10)
100     format(i7,i7,i6,i6,2x,4a2,i7,i8)
      end if
      nc=nc+1
      go to 10

 9000 close(iunit)
      close(ounit)

      stop
      end
c
      subroutine get_data(idata,ndata,idt1,ndt1,idt2,ndt2,idt3,ndt3,
     &                    idt4,ndt4,idt5,ndt5)
      integer*2 idata(*),idt1(*),idt2(*),idt3(*),idt4(*),idt5(*)

      ndt1=idata(2)
      ndt2=idata(3)
      ndt3=idata(4)
      ndt4=idata(5)
      ndt5=idata(6)

      nn=0
      do 10 n=1,ndt1
         nn=nn+1
         idt1(n)=idata(nn)
 10   continue
      do 20 n=1,ndt2
         nn=nn+1
         idt2(n)=idata(nn)
 20   continue
      do 30 n=1,ndt3
         nn=nn+1
         idt3(n)=idata(nn)
 30   continue
      do 40 n=1,ndt4
         nn=nn+1
         idt4(n)=idata(nn)
 40   continue
      do 50 n=1,ndt5
         nn=nn+1
         idt5(n)=idata(nn)
 50   continue
      return
      end
c
      subroutine get_record(iunit,idata,ndata)
      integer*2 idata(*)
      data nrec/1/

      call get_1_data(iunit,nrec,idata(1),ist)
      if (ist.eq.-1) then
         ndata=ist
         return
         else
            nrec=nrec+1
            ndata=1
      end if

      do 10 n=2,idata(1)
         call get_1_data(iunit,nrec,idata(n),ist)
         if (ist.eq.-1) then
            ndata=ist
            return
            else
               nrec=nrec+1
               ndata=n
         end if
 10   continue
      return
      end
c
      subroutine get_1_data(i_unit,n_rec,i_data,i_st)
      integer*2 i_data

      read(i_unit,rec=n_rec,end=9000,err=8000) i_data
      i_st=0
      return
 8000 write(*,*) 'Error!'
      i_st=-1
      return
 9000 i_st=-1
      return
      end
