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

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

Fixed removepoints

File size: 8.9 KB
RevLine 
[1]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%
[3018]6% expmaster(newprofile,'optionname',optionvalue)
[1]7% creation of an argus file newprofile
8%
[3018]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='-')
[3019]14% - linewidth (default=0.2)
15% - marker (default='+')
16% - markersize (default=7)
[3018]17% - markeredgecolor (default='r')
[1]18%
19% Usage:
20% expmaster(newfile,varargin)
21%
[3018]22% Example:
23% expmaster('domain.exp','include',{'domain1.exp' 'domain2.exp'},'color','g','marker','+')
24%
[1]25% See also EXPDOC
26
[3020]27%recover options
28options=pairoptions(varargin{:});
29
[1]30%Some checks
31if ~nargin | nargout
32 error('expmaster usage: expmaster(newfile,varargin)')
[3018]33elseif exist(newfile,'file'),
[1302]34 %recursive call to expmaster if file already exists
[3020]35 if ~exist(options,'include'),
[3018]36 expmaster(newfile,'include',newfile,varargin{:});
[1302]37 return;
38 end
39
40 %check modification
[1]41 choice=input(['A file ' newfile ' already exists, do you want to modify it? (y/n)'],'s');
42 if ~strcmpi(choice,'y'),
[1087]43 disp('no modification done ... exiting');
44 return
[1]45 end
46end
47
[3018]48%Add default options
49options=addfielddefault(options,'color','r');
50options=addfielddefault(options,'selectioncolor','b');
51options=addfielddefault(options,'LineStyle','-');
[3019]52options=addfielddefault(options,'LineWidth',0.2);
53options=addfielddefault(options,'Marker','+');
54options=addfielddefault(options,'MarkerSize',7);
[3018]55options=addfielddefault(options,'MarkerEdgeColor','r');
56
[1]57%put all the argus profiles given in input in one structure A
58A=struct([]);
59numprofiles=0;
60numpoints=0;
61closed=[];
[3018]62
63%initialize the variables with files provided by 'include' option
64if 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
[3248]86 if (B(i).x(1)==B(i).x(end) & B(i).y(1)==B(i).y(end) & length(B(i).x)>1 )
[3018]87 closed(numprofiles)=1;
88 else
89 closed(numprofiles)=0;
90 end
[1]91 end
92 end
93 end
94end
95
96%Get root of newfile
97[path root ext ver]=fileparts(newfile);
98
[33]99%get current figure
[285]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)
[1294]102 P=get(gcf,'position');
[2652]103 F=getframe(gca);
[285]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
[1294]112 figure; set(gcf,'position',P);
[285]113 imagesc(x_m,y_m,F); set(gca,'Ydir','normal');
[897]114 prevplot=1;
115 prevplot2=1;
[285]116else
117 figure
[897]118 prevplot=0;
119 prevplot2=0;
[285]120end
[1]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
[33]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;
[1]142 end
[33]143 end
144 A(list)=[];
145 closed(list)=[];
[1]146
[3018]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
[3248]152 if length(A(i).x)==1,
153 plot(A(i).x,A(i).y,'color',getfieldvalueerr(options,'color'),'LineStyle',getfieldvalueerr(options,'LineStyle'),'LineWidth',getfieldvalueerr(options,'LineWidth'),...
154 'MarkerEdgeColor',getfieldvalueerr(options,'MarkerEdgeColor'),'MarkerSize',getfieldvalueerr(options,'MarkerSize'),'Marker','o');
155 else
156 plot(A(i).x,A(i).y,'color',getfieldvalueerr(options,'color'),'LineStyle',getfieldvalueerr(options,'LineStyle'),'LineWidth',getfieldvalueerr(options,'LineWidth'));
157 end
[3018]158 prevplot2=prevplot2+1;
159 end
160 end
161
[33]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
[1]179
180
[33]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};
[1]191 end
[33]192 end
[1]193
[33]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};
[1]204 end
[33]205 end
[1]206
[33]207 switch button
[1]208
209 case 1
210
[3018]211 [A,numprofiles,numpoints,closed]=addprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]220 [A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]229 [A,numprofiles,numpoints,closed]=removeprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]238 [A,numprofiles,numpoints,closed]=modifyposition(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]247 [A,numprofiles,numpoints,closed]=addinsideprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]256 [A,numprofiles,numpoints,closed]=addendprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]265 [A,numprofiles,numpoints,closed]=removepoints(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]274 [A,numprofiles,numpoints,closed]=removeseveralpoints(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]283 [A,numprofiles,numpoints,closed]=cutprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]292 [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root,options);
[33]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
[3018]301 [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[33]309 case 12
[1]310
[3018]311 [A,numprofiles,numpoints,closed]=closeprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[33]318 %QUIT
319 case 15
[1]320
321 loop=0;
322
323 otherwise
324
325 %do nothing
326
[33]327 end
[1]328
329end
330
331hold off
332
333%write contour using expwrite
[33]334title('New file written, exiting...','FontSize',14);
[1]335if isempty(A)
336 disp('Profile empty, no file written')
337else
338 expwrite(A,newfile);
339end
[33]340
341%close window
342close;
Note: See TracBrowser for help on using the repository browser.