subroutine writestat_3D_short_nc(ncid,nvar,ncname,vars,nrec,dim1,dim2,dim3)
implicit none
integer, intent(in) :: ncid,nvar,dim1,dim2,dim3
integer, intent(in) :: nrec
integer(KIND=selected_int_kind(4)),dimension(dim1,dim2,dim3,nvar),intent(in) :: vars
character(*), dimension(:,:),intent(in) :: ncname
integer :: iret,n,varid
!write(*,*) '3Dnc short'
do n=1,nvar
iret = nf90_inq_varid(ncid, ncname(n,1), VarID)
iret = nf90_put_var(ncid, VarID, vars(1:dim1,1:dim2,1:dim3,n),(/1,1,1,nrec/),(/dim1,dim2,dim3,1/))
end do
iret = nf90_sync(ncid)
end subroutine writestat_3D_short_nc