function B=mysort(A,I,dir);
// sorts the rows of A by column indices I either all increasing "i" or all decreasing "d".

AA=[A(:,I) A];
BB=gsort(AA,"lr",dir);
[ig,kk]=size(I);
[ig,n]=size(A);
J=(kk+1:kk+n);
B=BB(:,J);

return;

