You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: m_scale.m
    path of file: ./repos/tracacode/1911-COAWST/script/mfiles/m_map
    
    the code of the file until where you have to start completion: function scale_factor=m_scale(scale_factor)
% M_SCALE Draws the map at a specified scale
%         After M_GRID has been called, the map is sized to fit within
%         the plot region of the current axes. If you want to force the
%         map to appear at a specific scale (e.g. 1:250000), call
%
%         M_SCALE(scale_factor)
%
%         where the map scale is 1:scale_factor. The map will be drawn
%         with its origin at bottom left within the figure limits (which
%         can be set with calls to ORIENT or by setting the 'paperposition'
%         property of the figure).

    
function scale_factor=m_scale(scale_factor)
% M_SCALE Draws the map at a specified scale
%         After M_GRID has been called, the map is sized to fit within
%         the plot region of the current axes. If you want to force the
%         map to appear at a specific scale (e.g. 1:250000), call
%
%         M_SCALE(scale_factor)
%
%         where the map scale is 1:scale_factor. The map will be drawn
%         with its origin at bottom left within the figure limits (which
%         can be set with calls to ORIENT or by setting the 'paperposition'
%         property of the figure).
%
%         M_SCALE('auto') returns to autoscaling.
%
%         SC=M_SCALE returns the current scale (this is useful if you want to
%         know roughly wht scale you currently have)
%
%         see also M_PROJ, M_GRID.

% Rich Pawlowicz (rich@ocgy.ubc.ca) 13/Nov/1998
% This software is provided "as is" without warranty of any kind. But
% it's mine, so you can't sell it.

%     1/Feb/99 - added scale calculations for return value.
% 6/Nov/00 - eliminate returned stuff if ';' neglected (thx to D Byrne)
% 4/DEc/11 - isstr to ischar
%

% Need earth radius, in centimeters.
erad=637813700; %cm (from WGS-84)

if nargin==0

 au=get(gca,'units');
 set(gca,'units','centimeter');
 a_pos=get(gca,'position');
 set(gca,'units',au);

 map_x=diff(get(gca,'xlim'));
 map_y=diff(get(gca,'ylim'));


 if map_x>10 % we are probably using meters (i.e. UTM coords)
   scale_factor=max(map_x/(a_pos(3)/100),map_y/(a_pos(4)/100));
 else
   scale_factor=max(map_x*erad/(a_pos(3)),map_y*erad/(a_pos(4)));
 end