source: issm/branches/trunk-jpl-damage/src/m/classes/plotoptions.m@ 11427

Last change on this file since 11427 was 8372, checked in by Mathieu Morlighem, 14 years ago

trunk: initial value of forcings must be a struct otherwise matlab complains

File size: 4.3 KB
Line 
1%PLOTOPTIONS class definition
2%
3% Usage:
4% plotoptions = plotoptions(varargin)
5
6classdef plotoptions
7 properties (SetAccess=public)
8 % {{{1
9 numberofplots = 0;
10 figurenumber = 1;
11 list = cell(0,0);
12 %}}}
13 end
14 methods
15 function opt=plotoptions(varargin) % {{{1
16 opt=buildlist(opt,varargin{:});
17 end
18 %}}}
19 function disp(opt) % {{{1
20 disp(sprintf('\n%s = \n',inputname(1)));
21 disp(sprintf(' numberofplots: %i',opt.numberofplots));
22 disp(sprintf(' figurenumber: %i',opt.figurenumber));
23 if ~isempty(opt.list),
24 disp(sprintf(' list: (%ix%i)',size(opt.list,1),size(opt.list,2)));
25 for i=1:size(opt.list,1),
26 unit=opt.list{i};
27 disp(sprintf('\n options of plot number %i',i));
28 for j=1:size(unit.list,1)
29 if ischar(unit.list{j,2}),
30 disp(sprintf(' field: %-10s value: ''%s''',unit.list{j,1},unit.list{j,2}));
31 elseif isnumeric(unit.list{j,2}) & length(unit.list{j,2})==1,
32 disp(sprintf(' field: %-10s value: %g',unit.list{j,1},unit.list{j,2}));
33 else
34 disp(sprintf(' field: %-10s value: (%ix%i)',unit.list{j,1},size(unit.list{j,2},1),size(unit.list{j,2},2)));
35 end
36 end
37 end
38 else
39 disp(sprintf(' list: empty'));
40 end
41 end
42 %}}}
43 function opt=buildlist(opt,varargin) % {{{1
44
45 %check length of input
46 if mod((nargin-1),2),
47 error('buildlist error message: an even number of plotoptions is required')
48 end
49
50 %first: build a pairoptions out of varargin:
51 rawoptions=pairoptions(varargin{:});
52
53 %get figure number
54 opt.figurenumber=getfieldvalue(rawoptions,'figure',1);
55
56 %get number of data to be plotted
57 numberofplots=fieldoccurences(rawoptions,'data');
58 opt.numberofplots=numberofplots;
59
60 %figure out wether alloptions flog is on
61 if strcmpi(getfieldvalue(rawoptions,'alloptions','off'),'on'),
62 allflag=1;
63 else
64 allflag=0;
65 end
66
67 %initialize opt.list
68 opt.list=cell(numberofplots,1);
69 for i=1:numberofplots,
70 opt.list{i}=pairoptions;
71 end
72
73 %process plot options
74 for i=1:size(rawoptions.list,1),
75
76 %If alloptions flag has is on, apply to all plots
77 if (allflag & ~strcmpi(rawoptions.list{i,1},'data') & ~ismember('#',rawoptions.list{i,1})),
78 for j=1:numberofplots,
79 opt.list{j}=addfield(opt.list{j},rawoptions.list{i,1},rawoptions.list{i,2});
80 end
81
82 %option contains '#'
83 elseif ismember('#',rawoptions.list{i,1}),
84
85 %get suplot(s) associated
86 string=strsplit(rawoptions.list{i,1},'#');
87 plotnums=string{end};
88 field=string{1};
89
90 %divide plotnums if there is a comma ','
91 plotnums=strsplit_strict(plotnums,',');
92
93 %loop over plotnums
94 for k=1:length(plotnums);
95 plotnum=plotnums{k};
96
97 %Empty
98 if isempty(plotnum),
99 continue;
100
101 %#all
102 elseif strcmpi(plotnum,'all');
103 for j=1:numberofplots,
104 opt.list{j}=addfield(opt.list{j},field,rawoptions.list{i,2});
105 end
106
107 %#i-j
108 elseif ismember('-',plotnum)
109 nums=strsplit(plotnum,'-');
110 if length(nums)~=2, continue; end
111 if ~isnumeric(nums)
112 error(['the option #i-j is not set properly for ' field]);
113 end
114 for j=nums(1):nums(2),
115 opt.list{j}=addfield(opt.list{j},field,rawoptions.list{i,2});
116 end
117
118 %#i
119 else
120 %assign to subplot
121 if str2num(plotnum)>numberofplots,
122 error(['opt error message: ' field ' cannot be assigned (' plotnum ' exceed maximum number of plot)']);
123 end
124 opt.list{str2num(plotnum)}=addfield(opt.list{str2num(plotnum)},field,rawoptions.list{i,2});
125 end
126 end
127
128 %assign option field to corresponding subplot
129 else
130
131 %go through all subplot and assign to the first one free
132 j=1;
133 while (j<=numberofplots),
134 if ~exist(opt.list{j},rawoptions.list{i,1});
135 opt.list{j}=addfield(opt.list{j},rawoptions.list{i,1},rawoptions.list{i,2});
136 break
137 else
138 j=j+1;
139 end
140 end
141 if j>numberofplots,
142 disp(['plot info message: too many ''' rawoptions.list{i,1} ''' options']);
143 end
144 end
145 end
146
147 %check that there is no duplicates
148 for i=1:numberofplots,
149 opt.list{i}=deleteduplicates(opt.list{i},1);
150 end
151 end
152 %}}}
153 end
154end
Note: See TracBrowser for help on using the repository browser.