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

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

superimpose figures

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