function unew=switch(u,nrow,g)
%function unew=switch(u,nrow,g)
%        u is a 3-d array
%        unew has the 1st two dimensions reversed
%        g is optional index array of good values that will allow 
%        unew to be compressed

[ni,nj]=size(u);
unew=[];
for j=1:nj
	dum=r3d(u,nrow,0,0,j);
	dum=dum';
	if nargin==2
		unew(:,j)=dum;
	else
		unew(:,j)=dum(g);
	end
end
