source: issm/trunk/src/m/utils/Exp/expmaster.m@ 5088

Last change on this file since 5088 was 5088, checked in by Mathieu Morlighem, 15 years ago

no more getfieldvalueerr. Use getfieldvalue with no default value

File size: 8.9 KB
Line 
1function 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=0.2)
15% - marker (default='+')
16% - markersize (default=7)
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%recover options
28options=pairoptions(varargin{:});
29
30%Some checks
31if ~nargin | nargout
32 error('expmaster usage: expmaster(newfile,varargin)')
33elseif exist(newfile,'file'),
34 %recursive call to expmaster if file already exists
35 if ~exist(options,'include'),
36 expmaster(newfile,'include',newfile,varargin{:});
37 return;
38 end
39
40 %check modification
41 choice=input(['A file ' newfile ' already exists, do you want to modify it? (y/n)'],'s');
42 if ~strcmpi(choice,'y'),
43 disp('no modification done ... exiting');
44 return
45 end
46end
47
48%Add default options
49options=addfielddefault(options,'color','r');
50options=addfielddefault(options,'selectioncolor','b');
51options=addfielddefault(options,'LineStyle','-');
52options=addfielddefault(options,'LineWidth',0.2);
53options=addfielddefault(options,'Marker','+');
54options=addfielddefault(options,'MarkerSize',7);
55options=addfielddefault(options,'MarkerEdgeColor','r');
56
57%put all the argus profiles given in input in one structure A
58A=struct([]);
59numprofiles=0;
60numpoints=0;
61closed=[];
62
63%initialize the variables with files provided by 'include' option
64if exist(options,'include'),
65 files=getfieldvalue(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) & length(B(i).x)>1 )
87 closed(numprofiles)=1;
88 else
89 closed(numprofiles)=0;
90 end
91 end
92 end
93 end
94end
95
96%Get root of newfile
97[path root ext ver]=fileparts(newfile);
98
99%get current figure
100if ~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;
116else
117 figure
118 prevplot=0;
119 prevplot2=0;
120end
121
122%plot existing profile if any
123hold on
124
125%Build backup structre for do and redo
126backup=cell(1,3);
127backup{1,1}=A;
128backup{1,2}=numprofiles;
129backup{1,3}=numpoints;
130backup{1,4}=closed;
131
132loop=1;
133counter=1;
134while 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 if length(A(i).x)==1,
153 plot(A(i).x,A(i).y,'color',getfieldvalue(options,'color'),'LineStyle',getfieldvalue(options,'LineStyle'),'LineWidth',getfieldvalue(options,'LineWidth'),...
154 'MarkerEdgeColor',getfieldvalue(options,'MarkerEdgeColor'),'MarkerSize',getfieldvalue(options,'MarkerSize'),'Marker','o');
155 else
156 plot(A(i).x,A(i).y,'color',getfieldvalue(options,'color'),'LineStyle',getfieldvalue(options,'LineStyle'),'LineWidth',getfieldvalue(options,'LineWidth'));
157 end
158 prevplot2=prevplot2+1;
159 end
160 end
161
162 %display menu
163 title('Main Menu','FontSize',14);
164 button=menu('Menu','add a profile (open)',...%1
165 'add a contour (closed)',... %2
166 'remove a profile',... %3
167 'modify the position of a point',... %4
168 'add points inside a profile',... %5
169 'add points at the end of a profile',... %6
170 'remove points',... %7
171 'remove several points',... %8
172 'cut a segment',... %9
173 'cut a large area',... %10
174 'merge profiles',... %11
175 'close profile',... %12
176 'undo',... %13
177 'redo',... %14
178 'quit'); %15
179
180
181 %UNDO??
182 if button==13;
183 if counter==1
184 disp('Already at oldest change');
185 else
186 counter=counter-1;
187 A=backup{counter,1};
188 numprofiles=backup{counter,2};
189 numpoints=backup{counter,3};
190 closed=backup{counter,4};
191 end
192 end
193
194 %REDO??
195 if button==14
196 if counter==size(backup,1)
197 disp('Already at newest change');
198 else
199 counter=counter+1;
200 A=backup{counter,1};
201 numprofiles=backup{counter,2};
202 numpoints=backup{counter,3};
203 closed=backup{counter,4};
204 end
205 end
206
207 switch button
208
209 case 1
210
211 [A,numprofiles,numpoints,closed]=addprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
212 counter=counter+1;
213 backup{counter,1}=A;
214 backup{counter,2}=numprofiles;
215 backup{counter,3}=numpoints;
216 backup{counter,4}=closed;
217
218 case 2
219
220 [A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot2,root,options);
221 counter=counter+1;
222 backup{counter,1}=A;
223 backup{counter,2}=numprofiles;
224 backup{counter,3}=numpoints;
225 backup{counter,4}=closed;
226
227 case 3
228
229 [A,numprofiles,numpoints,closed]=removeprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
230 counter=counter+1;
231 backup{counter,1}=A;
232 backup{counter,2}=numprofiles;
233 backup{counter,3}=numpoints;
234 backup{counter,4}=closed;
235
236 case 4
237
238 [A,numprofiles,numpoints,closed]=modifyposition(A,numprofiles,numpoints,closed,prevplot,root,options);
239 counter=counter+1;
240 backup{counter,1}=A;
241 backup{counter,2}=numprofiles;
242 backup{counter,3}=numpoints;
243 backup{counter,4}=closed;
244
245 case 5
246
247 [A,numprofiles,numpoints,closed]=addinsideprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
248 counter=counter+1;
249 backup{counter,1}=A;
250 backup{counter,2}=numprofiles;
251 backup{counter,3}=numpoints;
252 backup{counter,4}=closed;
253
254 case 6
255
256 [A,numprofiles,numpoints,closed]=addendprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
257 counter=counter+1;
258 backup{counter,1}=A;
259 backup{counter,2}=numprofiles;
260 backup{counter,3}=numpoints;
261 backup{counter,4}=closed;
262
263 case 7
264
265 [A,numprofiles,numpoints,closed]=removepoints(A,numprofiles,numpoints,closed,prevplot,root,options);
266 counter=counter+1;
267 backup{counter,1}=A;
268 backup{counter,2}=numprofiles;
269 backup{counter,3}=numpoints;
270 backup{counter,4}=closed;
271
272 case 8
273
274 [A,numprofiles,numpoints,closed]=removeseveralpoints(A,numprofiles,numpoints,closed,prevplot,root,options);
275 counter=counter+1;
276 backup{counter,1}=A;
277 backup{counter,2}=numprofiles;
278 backup{counter,3}=numpoints;
279 backup{counter,4}=closed;
280
281 case 9
282
283 [A,numprofiles,numpoints,closed]=cutprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
284 counter=counter+1;
285 backup{counter,1}=A;
286 backup{counter,2}=numprofiles;
287 backup{counter,3}=numpoints;
288 backup{counter,4}=closed;
289
290 case 10
291
292 [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root,options);
293 counter=counter+1;
294 backup{counter,1}=A;
295 backup{counter,2}=numprofiles;
296 backup{counter,3}=numpoints;
297 backup{counter,4}=closed;
298
299 case 11
300
301 [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root,options);
302 counter=counter+1;
303 backup{counter,1}=A;
304 backup{counter,2}=numprofiles;
305 backup{counter,3}=numpoints;
306 backup{counter,4}=closed;
307
308
309 case 12
310
311 [A,numprofiles,numpoints,closed]=closeprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
312 counter=counter+1;
313 backup{counter,1}=A;
314 backup{counter,2}=numprofiles;
315 backup{counter,3}=numpoints;
316 backup{counter,4}=closed;
317
318 %QUIT
319 case 15
320
321 loop=0;
322
323 otherwise
324
325 %do nothing
326
327 end
328
329end
330
331hold off
332
333%write contour using expwrite
334title('New file written, exiting...','FontSize',14);
335if isempty(A)
336 disp('Profile empty, no file written')
337else
338 expwrite(A,newfile);
339end
340
341%close window
342close;
Note: See TracBrowser for help on using the repository browser.