
         Program particle

         Parameter(nx=3150000,ny=100)
         Parameter(nn=10000000,nu=1)

         Integer ksave(nx),msave(nx)
         integer ipsd(ny),ipar(nx),irc(nx)
         Integer mv(nx),ksayv(nx),kv(nx)
         Integer jdv(nx),ipv(nx)
         Integer jptr(nn)
         Real vv(nn),hsave(nx),hv(nn)
         Real dsave(nx),velave(ny),cor(ny)
         Real vsave(nx),dtr(nn),dxtr(nn),atr(nn)
         Real jtr(nn),ktr(nn),mtr(nn),iptr(nn)

         character*60 infile,outfile
         character*60 infile11,infile12,infile13
         Character*60 outfile2,infile3,infile2
         character*60 infile4,infile0

         Open(10,file='filevelocitysnow',status='unknown')

         do ll=1,nu

         read(10,30)na,infile,infile2,infile3,outfile
 30      format(i3,1x,a10,1x,a10,1x,a15,1x,a44)

         open(11,file=infile,status='unknown')
         open(12,file=infile2,status='unknown')
         open(18,file=infile3,status='unknown')
         open(20,file=outfile,status='unknown')

        
         k1=0
         do i=1,na
         read(11,32)infile11
         read(12,32)infile12
         read(18,10)infile13
 32      format(a35)
 10      format(a35)

         open(13,file=infile11,status='unknown')
         open(14,file=infile12,status='unknown')
         open(15,file=infile13,status='unknown')

         do k=1,5
         read(13,*)
         read(14,*)
         enddo
         read(13,*)iyear,mon,iday,ka
         read(14,*)
         do k=1,3
         read(13,*)
         read(14,*)
         enddo

         k2=1
         ksay=1
         is=0
         do k=1,nx
         read(13,*,err=999,end=999)irec,ipa,dmm,
     *   hvel,vvel,ma
         if(mon.eq.10)jday=iday+273
         if(mon.eq.11)jday=iday+304
         if(mon.eq.12)jday=iday+334
         if(mon.eq.1)jday=iday
         if(mon.eq.2)jday=iday+31
         if(mon.eq.3)jday=iday+59
         if(mon.eq.4)jday=iday+90
         if(ipa.gt.0 .and. dmm.gt. 0.)then
         k1=k1+1
         vter=9.65-10.3*exp(-0.6*dmm)
         rat=vvel/vter
         if(rat.le.3.)then
         is=is+1
         jdv(is)=jday
         mv(is)=ma
         kv(is)=ka
         ipv(is)=ipa
         vv(is)=vvel
         hv(is)=hvel
         ksayv(is)=ksay
         ksave(k1)=ka
         msave(k1)=ma
         dsave(k1)=dcor+0.001
         vsave(k1)=vvel
         hsave(k1)=hvel
         endif
         endif
 999     enddo


         do k=1,nx
         read(14,*,err=998,end=998)irc(k2),ipar(k2),dm2,
     *   hve2,vve2,mb
         if(mon.eq.10)jday=iday+273
         if(mon.eq.11)jday=iday+304
         if(mon.eq.12)jday=iday+334
         if(mon.eq.1)jday=iday
         if(mon.eq.2)jday=iday+31
         if(mon.eq.3)jday=iday+59
         if(mon.eq.4)jday=iday+90
         if(k.eq.1)then
         dave=dm2
         vave=vve2
         have=hve2
         isay=1
         endif
         if(ipar(k2).gt.0 .and. dm2.gt.0. )then
         if(k.gt.1 .and. ipar(k2).eq.ipar(k2-1))then
         isay=isay+1
         dave=dave+dm2
         vave=vave+vve2
         have=have+hve2
         mc=mb
         else
         dave=dave/float(isay)
         vave=vave/float(isay)
         have=have/float(isay)
         vte=9.65-10.3*exp(-0.6*dave)
         rat1=vave/vte
         if(k.gt.1. and. rat1.le.3.)then
         is=is+1
         ipv(is)=ipar(k2-1)
         kv(is)=ka
         mv(is)=mc
         jdv(is)=jday 
         vv(is)=vave
         hv(is)=have
         ksayv(is)=isay
         k1=k1+1
         ksave(k1)=ka
         msave(k1)=mc
         dsave(k1)=dave+0.001
         vsave(k1)=vave
         hsave(k1)=have
         isay=1
         dave=dm2
         vave=vve2
         have=hve2
         endif
         endif
         endif
         k2=k2+1
 998     enddo


         do k=1,5
         read(15,*)
         enddo
         read(15,*)iyear,mon,iday,ka
         do k=1,3
         read(15,*)
         enddo

         if(mon.eq.10)jday=iday+273
         if(mon.eq.11)jday=iday+304
         if(mon.eq.12)jday=iday+334
         if(mon.eq.1)jday=iday
         if(mon.eq.2)jday=iday+31
         if(mon.eq.3)jday=iday+59
         if(mon.eq.4)jday=iday+90

         k1=1
         do kk=1,nx
         read(15,*,err=979,end=979)irec,jptr(k1),krq,
     *   dmm,kgrey,wc,wd,ma
         if(kk.eq.1)dave=dmm
         if(kk.eq.1)isay=1
         if(kk.eq.1)mb=ma
         if(kk.gt.1 .and. jptr(k1).eq.jptr(k1-1))then
         isay=isay+1
         dave=dave+dmm
         mb=ma
         else
         dave=dave/float(isay)
         if(k1.gt.1)then
         do j=1,is
         if(jday.eq.jdv(j) .and. ka.eq.kv(j) .and.
     *   mb.eq.mv(j) .and. jptr(k1-1).eq.ipv(j))then
         write(20,39)jptr(k1-1),iyear,jday,ka,mb,dave,
     *   vv(j),hv(j),ksayv(j),isay
 39      format(i10,4i5,3f10.2,2i5)
         endif
         enddo
         endif
         isay=1
         dave=dmm
         mb=ma
         endif
         k1=k1+1
 979     enddo

         print*,i,is,ll

         enddo

         enddo

     
         stop
         end
