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

Last change on this file since 897 was 897, checked in by Mathieu Morlighem, 16 years ago

fixed a bug thanks to Ala

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