1 | function expmaster(newfile,varargin)
|
---|
2 | %EXPMASTER - allow to create, modify, add, cut, .. segments of domain outline together
|
---|
3 | %
|
---|
4 | % this routine is used to create, modify, cut,... an Argus file (.exp)
|
---|
5 | %
|
---|
6 | % expmaster(newprofile,'optionname',optionvalue)
|
---|
7 | % creation of an argus file newprofile
|
---|
8 | %
|
---|
9 | % Available options:
|
---|
10 | % - include: include list of existing ARGUS files
|
---|
11 | % - color: line color (default='r')
|
---|
12 | % - selectioncolor: line color of selected profiles (default='b')
|
---|
13 | % - linestyle (default='-')
|
---|
14 | % - linewidth (default=1)
|
---|
15 | % - marker (default='s')
|
---|
16 | % - markersize (default=10)
|
---|
17 | % - markeredgecolor (default='r')
|
---|
18 | %
|
---|
19 | % Usage:
|
---|
20 | % expmaster(newfile,varargin)
|
---|
21 | %
|
---|
22 | % Example:
|
---|
23 | % expmaster('domain.exp','include',{'domain1.exp' 'domain2.exp'},'color','g','marker','+')
|
---|
24 | %
|
---|
25 | % See also EXPDOC
|
---|
26 |
|
---|
27 | %Some checks
|
---|
28 | if ~nargin | nargout
|
---|
29 | error('expmaster usage: expmaster(newfile,varargin)')
|
---|
30 | elseif exist(newfile,'file'),
|
---|
31 | %recursive call to expmaster if file already exists
|
---|
32 | if nargin==1,
|
---|
33 | expmaster(newfile,'include',newfile,varargin{:});
|
---|
34 | return;
|
---|
35 | end
|
---|
36 |
|
---|
37 | %check modification
|
---|
38 | choice=input(['A file ' newfile ' already exists, do you want to modify it? (y/n)'],'s');
|
---|
39 | if ~strcmpi(choice,'y'),
|
---|
40 | disp('no modification done ... exiting');
|
---|
41 | return
|
---|
42 | end
|
---|
43 | end
|
---|
44 |
|
---|
45 | %recover options
|
---|
46 | options=pairoptions(varargin{:});
|
---|
47 |
|
---|
48 | %Add default options
|
---|
49 | options=addfielddefault(options,'color','r');
|
---|
50 | options=addfielddefault(options,'selectioncolor','b');
|
---|
51 | options=addfielddefault(options,'LineStyle','-');
|
---|
52 | options=addfielddefault(options,'LineWidth',1);
|
---|
53 | options=addfielddefault(options,'Marker','s');
|
---|
54 | options=addfielddefault(options,'MarkerSize',10);
|
---|
55 | options=addfielddefault(options,'MarkerEdgeColor','r');
|
---|
56 |
|
---|
57 | %put all the argus profiles given in input in one structure A
|
---|
58 | A=struct([]);
|
---|
59 | numprofiles=0;
|
---|
60 | numpoints=0;
|
---|
61 | closed=[];
|
---|
62 |
|
---|
63 | %initialize the variables with files provided by 'include' option
|
---|
64 | if exist(options,'include'),
|
---|
65 | files=getfieldvalueerr(options,'include');
|
---|
66 | if ischar(files), files={files}; end
|
---|
67 | for i=1:length(files),
|
---|
68 | filename=files{i};
|
---|
69 | if ~exist(filename,'file'),
|
---|
70 | error(['expmaster error message:, ' filename ' does not exist. Exiting...']);
|
---|
71 | else
|
---|
72 | %read file
|
---|
73 | B=expread(filename,1);
|
---|
74 | %go through all profiles of B
|
---|
75 | for i=1:size(B,2)
|
---|
76 | %plug profile in A
|
---|
77 | if numprofiles
|
---|
78 | A(numprofiles+1)=B(i);
|
---|
79 | else
|
---|
80 | A=B(i);
|
---|
81 | end
|
---|
82 | %update numprofiles and numpoints
|
---|
83 | numpoints=numpoints+length(B(i).x);
|
---|
84 | numprofiles=numprofiles+1;
|
---|
85 | %figure out if the profile is closed or not
|
---|
86 | if (B(i).x(1)==B(i).x(end) & B(i).y(1)==B(i).y(end))
|
---|
87 | closed(numprofiles)=1;
|
---|
88 | else
|
---|
89 | closed(numprofiles)=0;
|
---|
90 | end
|
---|
91 | end
|
---|
92 | end
|
---|
93 | end
|
---|
94 | end
|
---|
95 |
|
---|
96 | %Get root of newfile
|
---|
97 | [path root ext ver]=fileparts(newfile);
|
---|
98 |
|
---|
99 | %get current figure
|
---|
100 | if ~isempty(get(0,'children')),%if there is already a figure (return the number of opened figures)
|
---|
101 | set(gcf,'Renderer','zbuffer'); %fixes a bug on Mac OS X (not needed in future Matlab version)
|
---|
102 | P=get(gcf,'position');
|
---|
103 | F=getframe(gca);
|
---|
104 | F=F.cdata;
|
---|
105 | %get current axis
|
---|
106 | xlim=get(gca,'Xlim');
|
---|
107 | ylim=get(gca,'Ylim');
|
---|
108 | %recreate x_m and y_m
|
---|
109 | x_m=linspace(xlim(1),xlim(2),size(F,2));
|
---|
110 | y_m=linspace(ylim(2),ylim(1),size(F,1)); %getframe reverse axis...
|
---|
111 | %plot the data in another figure
|
---|
112 | figure; set(gcf,'position',P);
|
---|
113 | imagesc(x_m,y_m,F); set(gca,'Ydir','normal');
|
---|
114 | prevplot=1;
|
---|
115 | prevplot2=1;
|
---|
116 | else
|
---|
117 | figure
|
---|
118 | prevplot=0;
|
---|
119 | prevplot2=0;
|
---|
120 | end
|
---|
121 |
|
---|
122 | %plot existing profile if any
|
---|
123 | hold on
|
---|
124 |
|
---|
125 | %Build backup structre for do and redo
|
---|
126 | backup=cell(1,3);
|
---|
127 | backup{1,1}=A;
|
---|
128 | backup{1,2}=numprofiles;
|
---|
129 | backup{1,3}=numpoints;
|
---|
130 | backup{1,4}=closed;
|
---|
131 |
|
---|
132 | loop=1;
|
---|
133 | counter=1;
|
---|
134 | while loop
|
---|
135 |
|
---|
136 | %Go through A and rule out the empty profiles
|
---|
137 | list=[];
|
---|
138 | for i=1:size(A,2);
|
---|
139 | if length(A(i).x)==0
|
---|
140 | list(end+1)=i;
|
---|
141 | numprofiles=numprofiles-1;
|
---|
142 | end
|
---|
143 | end
|
---|
144 | A(list)=[];
|
---|
145 | closed(list)=[];
|
---|
146 |
|
---|
147 | %Now erase all that have been done and plot the new structure A as it is
|
---|
148 | undoplots(prevplot);
|
---|
149 | if numprofiles
|
---|
150 | prevplot2=1;
|
---|
151 | for i=1:numprofiles
|
---|
152 | plot(A(i).x,A(i).y,'color',getfieldvalueerr(options,'color'),'LineStyle',getfieldvalueerr(options,'LineStyle'),'LineWidth',getfieldvalueerr(options,'LineWidth'));
|
---|
153 | prevplot2=prevplot2+1;
|
---|
154 | end
|
---|
155 | end
|
---|
156 |
|
---|
157 | %display menu
|
---|
158 | title('Main Menu','FontSize',14);
|
---|
159 | button=menu('Menu','add a profile (open)',...%1
|
---|
160 | 'add a contour (closed)',... %2
|
---|
161 | 'remove a profile',... %3
|
---|
162 | 'modify the position of a point',... %4
|
---|
163 | 'add points inside a profile',... %5
|
---|
164 | 'add points at the end of a profile',... %6
|
---|
165 | 'remove points',... %7
|
---|
166 | 'remove several points',... %8
|
---|
167 | 'cut a segment',... %9
|
---|
168 | 'cut a large area',... %10
|
---|
169 | 'merge profiles',... %11
|
---|
170 | 'close profile',... %12
|
---|
171 | 'undo',... %13
|
---|
172 | 'redo',... %14
|
---|
173 | 'quit'); %15
|
---|
174 |
|
---|
175 |
|
---|
176 | %UNDO??
|
---|
177 | if button==13;
|
---|
178 | if counter==1
|
---|
179 | disp('Already at oldest change');
|
---|
180 | else
|
---|
181 | counter=counter-1;
|
---|
182 | A=backup{counter,1};
|
---|
183 | numprofiles=backup{counter,2};
|
---|
184 | numpoints=backup{counter,3};
|
---|
185 | closed=backup{counter,4};
|
---|
186 | end
|
---|
187 | end
|
---|
188 |
|
---|
189 | %REDO??
|
---|
190 | if button==14
|
---|
191 | if counter==size(backup,1)
|
---|
192 | disp('Already at newest change');
|
---|
193 | else
|
---|
194 | counter=counter+1;
|
---|
195 | A=backup{counter,1};
|
---|
196 | numprofiles=backup{counter,2};
|
---|
197 | numpoints=backup{counter,3};
|
---|
198 | closed=backup{counter,4};
|
---|
199 | end
|
---|
200 | end
|
---|
201 |
|
---|
202 | switch button
|
---|
203 |
|
---|
204 | case 1
|
---|
205 |
|
---|
206 | [A,numprofiles,numpoints,closed]=addprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
|
---|
207 | counter=counter+1;
|
---|
208 | backup{counter,1}=A;
|
---|
209 | backup{counter,2}=numprofiles;
|
---|
210 | backup{counter,3}=numpoints;
|
---|
211 | backup{counter,4}=closed;
|
---|
212 |
|
---|
213 | case 2
|
---|
214 |
|
---|
215 | [A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot2,root,options);
|
---|
216 | counter=counter+1;
|
---|
217 | backup{counter,1}=A;
|
---|
218 | backup{counter,2}=numprofiles;
|
---|
219 | backup{counter,3}=numpoints;
|
---|
220 | backup{counter,4}=closed;
|
---|
221 |
|
---|
222 | case 3
|
---|
223 |
|
---|
224 | [A,numprofiles,numpoints,closed]=removeprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
|
---|
225 | counter=counter+1;
|
---|
226 | backup{counter,1}=A;
|
---|
227 | backup{counter,2}=numprofiles;
|
---|
228 | backup{counter,3}=numpoints;
|
---|
229 | backup{counter,4}=closed;
|
---|
230 |
|
---|
231 | case 4
|
---|
232 |
|
---|
233 | [A,numprofiles,numpoints,closed]=modifyposition(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
234 | counter=counter+1;
|
---|
235 | backup{counter,1}=A;
|
---|
236 | backup{counter,2}=numprofiles;
|
---|
237 | backup{counter,3}=numpoints;
|
---|
238 | backup{counter,4}=closed;
|
---|
239 |
|
---|
240 | case 5
|
---|
241 |
|
---|
242 | [A,numprofiles,numpoints,closed]=addinsideprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
243 | counter=counter+1;
|
---|
244 | backup{counter,1}=A;
|
---|
245 | backup{counter,2}=numprofiles;
|
---|
246 | backup{counter,3}=numpoints;
|
---|
247 | backup{counter,4}=closed;
|
---|
248 |
|
---|
249 | case 6
|
---|
250 |
|
---|
251 | [A,numprofiles,numpoints,closed]=addendprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
|
---|
252 | counter=counter+1;
|
---|
253 | backup{counter,1}=A;
|
---|
254 | backup{counter,2}=numprofiles;
|
---|
255 | backup{counter,3}=numpoints;
|
---|
256 | backup{counter,4}=closed;
|
---|
257 |
|
---|
258 | case 7
|
---|
259 |
|
---|
260 | [A,numprofiles,numpoints,closed]=removepoints(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
261 | counter=counter+1;
|
---|
262 | backup{counter,1}=A;
|
---|
263 | backup{counter,2}=numprofiles;
|
---|
264 | backup{counter,3}=numpoints;
|
---|
265 | backup{counter,4}=closed;
|
---|
266 |
|
---|
267 | case 8
|
---|
268 |
|
---|
269 | [A,numprofiles,numpoints,closed]=removeseveralpoints(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
270 | counter=counter+1;
|
---|
271 | backup{counter,1}=A;
|
---|
272 | backup{counter,2}=numprofiles;
|
---|
273 | backup{counter,3}=numpoints;
|
---|
274 | backup{counter,4}=closed;
|
---|
275 |
|
---|
276 | case 9
|
---|
277 |
|
---|
278 | [A,numprofiles,numpoints,closed]=cutprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
279 | counter=counter+1;
|
---|
280 | backup{counter,1}=A;
|
---|
281 | backup{counter,2}=numprofiles;
|
---|
282 | backup{counter,3}=numpoints;
|
---|
283 | backup{counter,4}=closed;
|
---|
284 |
|
---|
285 | case 10
|
---|
286 |
|
---|
287 | [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
288 | counter=counter+1;
|
---|
289 | backup{counter,1}=A;
|
---|
290 | backup{counter,2}=numprofiles;
|
---|
291 | backup{counter,3}=numpoints;
|
---|
292 | backup{counter,4}=closed;
|
---|
293 |
|
---|
294 | case 11
|
---|
295 |
|
---|
296 | [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
297 | counter=counter+1;
|
---|
298 | backup{counter,1}=A;
|
---|
299 | backup{counter,2}=numprofiles;
|
---|
300 | backup{counter,3}=numpoints;
|
---|
301 | backup{counter,4}=closed;
|
---|
302 |
|
---|
303 |
|
---|
304 | case 12
|
---|
305 |
|
---|
306 | [A,numprofiles,numpoints,closed]=closeprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
|
---|
307 | counter=counter+1;
|
---|
308 | backup{counter,1}=A;
|
---|
309 | backup{counter,2}=numprofiles;
|
---|
310 | backup{counter,3}=numpoints;
|
---|
311 | backup{counter,4}=closed;
|
---|
312 |
|
---|
313 | %QUIT
|
---|
314 | case 15
|
---|
315 |
|
---|
316 | loop=0;
|
---|
317 |
|
---|
318 | otherwise
|
---|
319 |
|
---|
320 | %do nothing
|
---|
321 |
|
---|
322 | end
|
---|
323 |
|
---|
324 | end
|
---|
325 |
|
---|
326 | hold off
|
---|
327 |
|
---|
328 | %write contour using expwrite
|
---|
329 | title('New file written, exiting...','FontSize',14);
|
---|
330 | if isempty(A)
|
---|
331 | disp('Profile empty, no file written')
|
---|
332 | else
|
---|
333 | expwrite(A,newfile);
|
---|
334 | end
|
---|
335 |
|
---|
336 | %close window
|
---|
337 | close;
|
---|