function out = clockwise(m)
  out = m;
  if (length(m) > 1)
      r = size(m,1);
      c = size(m,2);
      
      for i=2:c
          out(1,i) = m(1,i-1);
          out(r,c-i+1) = m(r,c-i+2);
      end;
      
      for j=2:r
          out(j-1,1) = m(j,1);
          out(r-j+2,c) = m(r-j+1,c);
      end;
      
      if (length(m) > 2)
        out(2:r-1,2:c-1)=clockwise(m(2:r-1,2:c-1));
      end;
  end;
