Home > atmlab > geoplots > gmt > cpt_from_colorrange.m

cpt_from_colorrange

PURPOSE ^

CPT_FROM_COLORRANGE configure colortable to desired color values and ranges

SYNOPSIS ^

function filecpt = cpt_from_colorrange(colorrange)

DESCRIPTION ^

 CPT_FROM_COLORRANGE configure colortable to desired color values and ranges

 Purpose: Make a colortable file with desired color values and ranges, that
 will be passed in the makecpt function that uses this input to make a color
 that can be used by GMT. i.e. makecpt -Ccolorrange.cpt etc.

 USAGE: e.g. file = cpt_from_colorrange(
        struct('colors',{{{0.25,'255/255/255'},{0.75,'0/0/0'}}},...
        'color_model','RGB'))

 IN: structure.
    colors = {{value,'color'},{value2,'color2'},etc.}; (manditory)
    color_model = 'RGB', 'HSV'

 OUT: filename

 Created by Salomon Eliasson
 $Id: cpt_from_colorrange.m 7954 2012-10-28 20:57:41Z seliasson $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

cpt_from_colorrange.m

SOURCE CODE ^

0001 function filecpt = cpt_from_colorrange(colorrange)
0002 % CPT_FROM_COLORRANGE configure colortable to desired color values and ranges
0003 %
0004 % Purpose: Make a colortable file with desired color values and ranges, that
0005 % will be passed in the makecpt function that uses this input to make a color
0006 % that can be used by GMT. i.e. makecpt -Ccolorrange.cpt etc.
0007 %
0008 % USAGE: e.g. file = cpt_from_colorrange(
0009 %        struct('colors',{{{0.25,'255/255/255'},{0.75,'0/0/0'}}},...
0010 %        'color_model','RGB'))
0011 %
0012 % IN: structure.
0013 %    colors = {{value,'color'},{value2,'color2'},etc.}; (manditory)
0014 %    color_model = 'RGB', 'HSV'
0015 %
0016 % OUT: filename
0017 %
0018 % Created by Salomon Eliasson
0019 % $Id: cpt_from_colorrange.m 7954 2012-10-28 20:57:41Z seliasson $
0020 
0021 % COLOR MODEL
0022 if ~isfield(colorrange,'color_model')
0023     model = 'RGB';
0024 else
0025     model = colorrange.color_model;
0026 end
0027 C = colorrange.colors;
0028 assert((length(C)-1)>0,['gmtlab:' mfilename,':badInput'],...
0029     ['Either there is only one level'...
0030     'or the cell is constructed incorrectly (see help gmt_plot)'])
0031 
0032 % format to print z-slice in cptfile
0033 strtab = '\t%s\t%s\t%s\t';
0034     
0035 filecpt = 'colorrange.cpt';
0036 fid = fopen(filecpt,'w');
0037 CO = onCleanup(@() fclose(fid));
0038 
0039 % header
0040 fprintf(fid,'%s\n','#cpt file created by: cpt_from_colorrange.m');
0041 fprintf(fid,'%s\n',sprintf('#COLOR_MODEL = %s',model));
0042 
0043 % make z-slices (val1 Red1 Green1 Blue1 val2 Red2 Green2 Blue2)
0044 for ii = 1:length(C)-1
0045     val    = C{ii}{1}; val2 = C{ii+1}{1};
0046     assert(~isequal(val,val2),['gmtlab:' mfilename ':badInput'],...
0047            'consecutive z values may not have the same value')
0048     color  = splitstring(C{ii}{2},'/');
0049     color2 = splitstring(C{ii+1}{2},'/'); 
0050     fprintf(fid,[sprintf('%s',getAnnotFormat(val)) strtab],...
0051         val, color{1}, color{2}, color{3});
0052     fprintf(fid,[sprintf('%s',getAnnotFormat(val2)) strtab '\n'],...
0053         val2,color2{1},color2{2},color2{3});
0054 end

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