  program readpartpos
  
! read particle positions written by FpWRF 3.3.2
! Petra Seibert, 7/2017

  integer, parameter :: nspec = 2
  integer :: ioutgrid_option
!  integer, allocatable, dimension(:)   :: npoint,itramem
!  real,    allocatable, dimension(:)   :: ztra1
!  real,    allocatable, dimension(:,:) :: xmass1
  real, dimension(nspec) :: xmass1
  character (len=150) :: outfile, fname

  open (9, file='filelist')
10 read (9,'(a)',end=90) fname
  
    open (10,file=trim(fname),form='unformatted')
    print*, 'reading ',trim(fname)
    read (10) itime, numpart_out, ioutgrid_option
    print*, 'simulation time:',itime, 's', itime/3600., 'hrs'
    print*, '#particles in this file:', numpart_out !, outgrid_option
    if (ioutgrid_option .eq. 1) then
      print*, 'output is lat-lon grid'
    else
      print*, 'output is on WRF projection'
    endif
    print*
    write (outfile,900) itime/3600
  900 format ('partpos_',i2.2,'.dat')
  !  allocate (ztra1(numpart_out), xmass1(numpart_out,nspec)) ! etc

    open (20, file=trim(outfile)  )
    do i = 1, numpart_out
!      print*, 'reading particle #',i
      read (10) npoint,xlon,ylat,ztra1,itramem,topo, &
        pvi,qvi,rhoi,hmixi,tri,tti,(xmass1(j),j=1,nspec)
      write (20,901) i,xlon,ylat,ztra1,xmass1,topo,ztra1+topo,hmixi+topo
  901 format (i7,3f10.4,2es12.3,3f8.1)
    enddo
  goto 10
  
90 close (9)
  
  end
  
