subroutine writeoffset(ncid, ncname, var, nrec, dim1, dim2, dim3)
use mpi
use modmpi, only : MY_REAL
implicit none
integer, intent(in) :: ncid, nrec, dim1, dim2, dim3
real, intent(in) :: var(dim1,dim2,dim3)
character(*), intent(in) :: ncname
integer :: iret, VarID, ierr, status(MPI_STATUS_SIZE)
integer, dimension(4) :: startpos, countpos
integer :: step, src
real, dimension(dim1,dim2,dim3) :: bufin, bufout
call MPI_BARRIER(comm1dy, ierr)
bufin = var
iret = nf90_inq_varid(ncid, ncname, VarID)
countpos = (/ dim1,dim2,dim3, 1 /)
do step = 1, nprocy
if (myid1dy == 0) then
src = step - 1
startpos = (/ 1, 1 + src*dim2, 1, nrec /)
iret = nf90_put_var(ncid, VarID, bufin, start=startpos, count=countpos)
end if
call MPI_SENDRECV( &
bufin, size(bufin), MY_REAL, nbrboty, 1000+step, &
bufout, size(bufout), MY_REAL, nbrtopy, 1000+step, &
comm1dy, status, ierr )
bufin = bufout
end do
if (myid1dy == 0) then
iret = nf90_sync(ncid)
end if
end subroutine writeoffset