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