module fileio

implicit none

contains
!=====================================================
subroutine io(nw,nz,nx,nreal,m)
integer		:: nw,nz,nx,nreal
real		:: m(:)
real, allocatable	:: out(:,:,:,:)
integer		:: iw,ix,iz,ir

  allocate(out(nw,nz,nx,nreal))

  do ir=1,nreal
  do ix=1,nx
  do iz=1,nz
  do iw=1,nw
     out(iw,iz,ix,ir)=m((ir-1)*nz*nx*nw+(ix-1)*nz*nw+(iz-1)*nw+iw)
  end do
  end do
  end do
  end do

  call to_history("n1",nw);call to_history("n1",1.);call to_history("d1",1.);
  call to_history("n2",nz);call to_history("n2",1.);call to_history("d2",1.);
  call to_history("n3",nx);call to_history("n3",1.);call to_history("d3",1.);
  call to_history("n4",nreal);call to_history("n4",1.);call to_history("d4",1.);
  call srite("out",m,4*nw*nx*nz*nreal)

end subroutine
end module
