module OW_io

use sep
use OW_type
use OW_parms_areal

contains

subroutine ow_cig_io(zn,ihor,tag,cig)
   
character*3          :: tag
real                 :: cig(:,:,:,:,:)
integer              :: zn, ix, iy, ihx, ihy,ihor

if (tag.eq."rec")
   call sreed_window("rec_cig",4,(/sog%xm%n,sog%ym%n,sog%shx%n,sog%shy%n,zn,nhorz/),&
                                 (/sog%xm%n,sog%ym%n,sog%shx%n,sog%shy%n,    zn,1/),&
                                 (/       0,       0,        0,        0,  ihor-1/),&
                                 (/       1,       1,        1,        1,       1/),&
                                 4,cig) 
else
   call sreed_window("sou_cig",4,(/sog%xm%n,sog%ym%n,sog%shx%n,sog%shy%n,zn,nhorz/),&
                                 (/sog%xm%n,sog%ym%n,sog%shx%n,sog%shy%n,    zn,1/),&
                                 (/       0,       0,        0,        0,  ihor-1/),&
                                 (/       1,       1,        1,        1,       1/),&
                                 4,cig) 
   do ihx=1,sog%shx%n;do ihy=1,sog%shy%n;do iy=1,sog%ym%n;do ix=1,sog%xm%n
      temp(ix,iy,ihx,ihy,:)=cig(ix,iy,sog%shx%n-ihx+1,sog%shy%n-ihy+1,:)
   end do;end do;end do;end do
   cig=temp
   deallocate(temp)
end if
end subroutine
