program pcaunzip_lite
! simple version of pcaunzip that uncompresses PCZ4-format files only
! Charlie Laughton 1/5/10
!
! The full version of the pcazip software is available from
! www.ccpb.ac.uk/software
!
implicit none
  character(80)       :: title
  character(4)        :: version
  integer             :: natoms, nframes, nvecs, idum, i
  real                :: quality, eval
  real, allocatable   :: xavg(:),x(:),evecs(:,:),proj(:,:)

  open(5,form="unformatted", access="stream")
  read(5) version
  if(version /= "PCZ4") then
    write(0,'("Error - unsupported file format")')
    call exit(1)
  endif
  read(5) title,natoms,nframes,nvecs,quality,idum,idum,idum,idum
  allocate(xavg(3*natoms),x(3*natoms),evecs(3*natoms,nvecs))
  allocate(proj(nvecs,nframes))
  read(5) xavg
  do i=1,nvecs
    read(5) evecs(:,i),eval,proj(i,:)
  end do
  write(6,'(a80)') title
  do i=1,nframes
    x=xavg+matmul(evecs,proj(:,i))
    write(6,'(10f8.3)') x
  end do
end program pcaunzip_lite
