function tlprintf(varargin)
%TLPRINTF print formatted axis tick label.
% TLPRINTF with no input arguments prompts the user for the
% desired format of axes tick labels.
%
% TLPRINTF(FORMAT) formats all axes tick labels using the format
% string FORMAT (see SPRINTF for details).
%
% TLPRINTF(XFORMAT, YFORMAT) formats x-axis tick labels according to
% XFORMAT and y-axis tick labels according to YFORMAT. When YFORMAT
% is specified with XFORMAT set to [] or '', only the y-axis tick
% labels are altered.
%
% TLPRINTF(XFORMAT, YFORMAT, ZFORMAT) same as above with the
% addition of a format specification ZFORMAT for the z-axis tick
% label.
%
% See also SPRINTF, GCA, GET, SET.
% Author(s): D. Gilbert
% A. Prasad
% Original author info from file
%Author: Denis Gilbert, Ph.D., physical oceanography
%Maurice Lamontagne Institute, Dept. of Fisheries and Oceans Canada
%email: gilbertd@dfo-mpo.gc.ca Web: http://www.qc.dfo-mpo.gc.ca/iml/
% Check input arguments
error(nargchk(0,3,nargin));
% Interpret input arguments
if nargin == 0,
prompt={'X-axis tick label format', ...
'Y-axis tick label format', ...
'Z-axis tick label format', ...
};
def={'0.00','0.00','0.00'};
dlgTitle = 'tlprintf: format specification';
lineNo = 1;
answer = inputdlg(prompt,dlgTitle,lineNo,def);
xFormat = answer{1};
yFormat = answer{2};
zFormat = answer{3};
% Determine format
decimals = length(xFormat) - find(xFormat == '.');
xFormat = ['%0.' num2str(decimals) 'f'];
decimals = length(yFormat) - find(yFormat == '.');
yFormat = ['%0.' num2str(decimals) 'f'];
decimals = length(zFormat) - find(zFormat == '.');
zFormat = ['%0.' num2str(decimals) 'f'];
elseif nargin == 1,
% Identical formats if one argument
xFormat = varargin{1};
yFormat = xFormat;
zFormat = xFormat;
elseif nargin == 2,
xFormat = varargin{1};
yFormat = varargin{2};
zFormat = [];
elseif nargin == 3,
xFormat = varargin{1};
yFormat = varargin{2};
zFormat = varargin{3};
end
% X-axis operations
if ~isempty(xFormat),
xTick = get(gca,'XTick');
for i = 1:length(xTick)
xTickLabel{i} = sprintf(xFormat,xTick(i));
end
set(gca,'XTickLabel', xTickLabel)
end
% Y-axis operations
if ~isempty(yFormat),
yTick = get(gca,'YTick');
for i = 1:length(yTick)
yTicklabel{i} = sprintf(yFormat,yTick(i));
end
set(gca,'YTickLabel', yTicklabel)
end
% Z-axis operations
if ~isempty(zFormat),
zTick = get(gca,'zTick');
for i = 1:length(zTick)
zTicklabel{i} = sprintf(zFormat,zTick(i));
end
set(gca,'ZTickLabel', zTicklabel)
end