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

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

modification of a file if nargin==1

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