
subroutine Mean1DimFast ( A, B, offset, offset2, ndims, linf, lsup, alen, blen)
	integer offset,offset2,ndims,linf,lsup,i,j,z,tmp,alen,blen
	double precision A(0:alen-1),B(0:blen-1)

	tmp = offset * ndims

	do i=0,offset2-1
		do j=0,offset-1
			do z=linf,lsup-1
				if (A(tmp*i+(offset*z)+j)<0) then
           			A(tmp*i+(offset*z)+j)=0
            	end if
          		B((offset*i)+j) = B((offset*i)+j) + A((tmp*i)+(offset*z)+j)
          	end do
          	B((offset*i)+j) =  B((offset*i)+j) / ndims;
        end do
    end do

end subroutine Mean1DimFast