Home > atmlab > geoplots > gmt > getAnnotFormat.m

getAnnotFormat

PURPOSE ^

% getAnnotFormat

SYNOPSIS ^

function annot_format = getAnnotFormat(quantity)

DESCRIPTION ^

% getAnnotFormat
 Guess a reasonable annotation format for gmtlab based on the provided quantity.
 in.tick_annotation_format overrides this function. 

 IN     quantity          (scalar or a vector)
 OUT    annot_format      string to be used in e.g. fprintf

 EXAMPLE  >> getAnnotFormat(0.00358)
          
          ans =

          '%.3f'
               
 Created by Salomon Eliasson

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

getAnnotFormat.m

SOURCE CODE ^

0001 function annot_format = getAnnotFormat(quantity)
0002 %% getAnnotFormat
0003 % Guess a reasonable annotation format for gmtlab based on the provided quantity.
0004 % in.tick_annotation_format overrides this function.
0005 %
0006 % IN     quantity          (scalar or a vector)
0007 % OUT    annot_format      string to be used in e.g. fprintf
0008 %
0009 % EXAMPLE  >> getAnnotFormat(0.00358)
0010 %
0011 %          ans =
0012 %
0013 %          '%.3f'
0014 %
0015 % Created by Salomon Eliasson
0016 
0017 assert(nargin==1,['gmtlab:' mfilename ':badInput'],...
0018     'USAGE: annot_format = getAnnotFormat(quantity)')
0019 
0020 % if quantity ~= 0
0021 %     sz = floor(log10(abs(quantity)));
0022 % end
0023 
0024 % doesn't matter if the value is possitive or negative
0025 quantity = abs(quantity); 
0026 
0027 cond1 = quantity == 0;
0028 cond2 = ceil(log10(quantity)) == 0;
0029 cond3 = quantity - floor(quantity) == 0;
0030 
0031 
0032 
0033 if cond1
0034     annot_format = '%.0f';
0035 elseif cond2 && cond3
0036     annot_format = '%1.0f';
0037     
0038 elseif cond2
0039     annot_format = sprintf('%%1.%if',...
0040         min(abs(floor(log10(quantity - floor(quantity))))));
0041     
0042 elseif cond3
0043     annot_format = sprintf('%%%i.0f',...
0044         min(abs(ceil(log10(quantity)))));
0045     
0046 else
0047     
0048     annot_format = sprintf('%%%i.%if',...
0049         min(abs(ceil(log10(quantity)))),...
0050         min(abs(floor(log10(quantity - floor(quantity))))));
0051 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005