1 | function expcoarsen(newfile,oldfile,resolution)
|
---|
2 | %EXPCOARSEN - coarsen an exp contour
|
---|
3 | %
|
---|
4 | % This routine read an Argus file and remove points with respect to
|
---|
5 | % the resolution (in meters) given in input.
|
---|
6 | %
|
---|
7 | % Usage:
|
---|
8 | % expcoarsen(newfile,oldfile,resolution)
|
---|
9 | %
|
---|
10 | % Example:
|
---|
11 | % expcoarsen('DomainOutline.exp','Antarctica.exp',4000)
|
---|
12 |
|
---|
13 | %Some checks
|
---|
14 | if nargin~=3 | nargout
|
---|
15 | error('expcoarsen usage: expcoarsen(newfile,oldfile,resolution)')
|
---|
16 | elseif ~exist(oldfile)
|
---|
17 | error(['expcut error message: the file ' oldfile ' does not exist'])
|
---|
18 | elseif exist(newfile),
|
---|
19 | choice=input(['A file ' newfile ' already exists, do you want to modify it? (y/n)'],'s');
|
---|
20 | if ~strcmpi(choice,'y'),
|
---|
21 | disp('no modification done ... exiting');
|
---|
22 | return;
|
---|
23 | end
|
---|
24 | end
|
---|
25 |
|
---|
26 | %Get exp oldfile
|
---|
27 | [path root ext ver]=fileparts(oldfile);
|
---|
28 | A=expread(oldfile);
|
---|
29 | numprofiles=size(A,2);
|
---|
30 |
|
---|
31 | %Go through the profiles
|
---|
32 | count=1;
|
---|
33 | while count<=numprofiles,
|
---|
34 |
|
---|
35 | %get number of points and initialize j
|
---|
36 | numpoints=length(A(count).x);
|
---|
37 | j=1;
|
---|
38 |
|
---|
39 | %stop if we have reached end of profile (always keep the last point)
|
---|
40 | while j<numpoints,
|
---|
41 |
|
---|
42 | %See whether we keep this point or not
|
---|
43 | distance=sqrt((A(count).x(j)-A(count).x(j+1))^2+(A(count).y(j)-A(count).y(j+1))^2);
|
---|
44 | if distance<resolution & j<numpoints-1 %do not remove last point
|
---|
45 | A(count).x(j+1)=[];
|
---|
46 | A(count).y(j+1)=[];
|
---|
47 | numpoints=numpoints-1;
|
---|
48 | else
|
---|
49 | division=floor(distance/resolution)+1;
|
---|
50 | if division>=2,
|
---|
51 | x=linspace(A(count).x(j),A(count).x(j+1),division)';
|
---|
52 | y=linspace(A(count).y(j),A(count).y(j+1),division)';
|
---|
53 | A(count).x=[A(count).x(1:j);x(2:end-1); A(count).x(j+1:end)];
|
---|
54 | A(count).y=[A(count).y(1:j);y(2:end-1); A(count).y(j+1:end)];
|
---|
55 |
|
---|
56 | %update current point
|
---|
57 | j=j+1+division-2;
|
---|
58 | numpoints=numpoints+division-2;
|
---|
59 | else
|
---|
60 | %update current point
|
---|
61 | j=j+1;
|
---|
62 | end
|
---|
63 | end
|
---|
64 | end
|
---|
65 | if length(A(count).x)<=1,
|
---|
66 | A(count)=[];
|
---|
67 | numprofiles=numprofiles-1;
|
---|
68 | else
|
---|
69 | count=count+1;
|
---|
70 | end
|
---|
71 | end
|
---|
72 |
|
---|
73 | %write output
|
---|
74 | expwrite(A,newfile);
|
---|