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

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

fixed minor bug for Ala

File size: 8.6 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
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
[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
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
[33]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
[1]174
175
[33]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};
[1]186 end
[33]187 end
[1]188
[33]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};
[1]199 end
[33]200 end
[1]201
[33]202 switch button
[1]203
204 case 1
205
[3018]206 [A,numprofiles,numpoints,closed]=addprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]215 [A,numprofiles,numpoints,closed]=addcontour(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]224 [A,numprofiles,numpoints,closed]=removeprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]233 [A,numprofiles,numpoints,closed]=modifyposition(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]242 [A,numprofiles,numpoints,closed]=addinsideprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]251 [A,numprofiles,numpoints,closed]=addendprofile(A,numprofiles,numpoints,closed,prevplot2,root,options);
[1]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
[3018]260 [A,numprofiles,numpoints,closed]=removepoints(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]269 [A,numprofiles,numpoints,closed]=removeseveralpoints(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]278 [A,numprofiles,numpoints,closed]=cutprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[3018]287 [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root,options);
[33]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
[3018]296 [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[33]304 case 12
[1]305
[3018]306 [A,numprofiles,numpoints,closed]=closeprofile(A,numprofiles,numpoints,closed,prevplot,root,options);
[1]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
[33]313 %QUIT
314 case 15
[1]315
316 loop=0;
317
318 otherwise
319
320 %do nothing
321
[33]322 end
[1]323
324end
325
326hold off
327
328%write contour using expwrite
[33]329title('New file written, exiting...','FontSize',14);
[1]330if isempty(A)
331 disp('Profile empty, no file written')
332else
333 expwrite(A,newfile);
334end
[33]335
336%close window
337close;
Note: See TracBrowser for help on using the repository browser.