function res = ooz(input,sz,chr);
% function res = ooz(input,sz,chr);
%
% 2005 Mar 03 - Last Update
% David S. Ciochetto
% Physical Oceanography at Dalhousie University
%
% A routine to take a integer, such as in a for loop,
% (input) and add leading zeros until it is length (sz).
% It converts the integer to a string including the leading
% zeros. Thus it replaces num2str(input) and adds formatting.
% Useful for experiments that repeat a number of trials or
% in ocenaography casts. When you print output to a figure,
% the length will remain the same and not shift the text.
% The position of the values will be predictable and nicer
% for movie clips of your data. Can be used elsewhere for
% string formatting in plot commands. (chr) is an optional
% input to add other characters than leading zeros such as
% spaces, 'x' or '-'... This has to be a single char not a string.
%
% INPUT:
%		input = number to add leading zeros to.
%		sz = total length of the resulting string
%		chr = (optional) leading character to add if 0's are not desired (e.g. ' ')
%				If specified, should be only one character in length!
% e.g.
% for i=98:105
%   ooz(i,3)    % filename = ['day ' ooz(i,3)]
% end
% 
% results in the following consecuitive text strings.
% filename = 'day 098'
% 		"				day 099
% 		"				day 100
% 		"				day 101
% 		"				...
%
% NOTES:
%		1.Intended for use with integer values but can be used with real numbers if
%		you round them first somehow. (Maybe using tsigfig.m. This has not been tried
%		yet and is unpredictable.)
%
%		2. ooz.m will substitute leading zeros if more than a single character is sent
%				to chr
%
% USES:
%
% SEE ALSO:
%		tsigfig.m
%

if ~exist('chr')
	chr = '0';
end

if length(chr) > 1
	disp('ooz.m ERROR: leading characters can not be strings.')
	disp('              changing to default of leading zeros.')
	chr = '0';
end

res1=num2str(input);
while length(res1)<sz
  res1=[chr res1];
end
res=res1;
