function y=cshift(x,dim,nshift)
% CSHIFT circular shift operation 
% cshift(x,dim,shift)
[nx nz]=size(x);

if dim == 1

if nshift < 0

	for i=1:nx+nshift
	    y(i,:)=x(i-nshift,:);
	end
	for i=1:abs(nshift)
	    y(nx+nshift+i,:)=x(i,:);
	end

end

if nshift > 0

	for i=nshift+1:nx
	    y(i,:)=x(i-nshift,:);
	end
	for i=1:nshift
	    y(i,:)=x(nx-nshift+i,:);
	end 

end

end

if dim == 2

if nshift < 0

	for i=1:nz+nshift
	    y(:,i)=x(:,i-nshift);
	end
	for i=1:abs(nshift)
	    y(:,nz+nshift+i)=x(:,i);
	end

end

end

if dim == 2

if nshift > 0

	for i=nshift+1:nz
	    y(:,i)=x(:,i-nshift);
	end
	for i=1:nshift
	    y(:,i)=x(:,nz-nshift+i);
	end 

end

end

if nshift == 0

y=x;

end
