[13730] | 1 | function expcoarsen(newfile,oldfile,resolution)
|
---|
[1090] | 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)
|
---|
[1084] | 12 |
|
---|
| 13 | %Some checks
|
---|
| 14 | if nargin~=3 | nargout
|
---|
| 15 | error('expcoarsen usage: expcoarsen(newfile,oldfile,resolution)')
|
---|
| 16 | elseif ~exist(oldfile)
|
---|
[13135] | 17 | error(['expcut error message: the file ' oldfile ' does not exist'])
|
---|
[1084] | 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);
|
---|
[12379] | 28 | A=expread(oldfile);
|
---|
[1084] | 29 | numprofiles=size(A,2);
|
---|
| 30 |
|
---|
| 31 | %Go through the profiles
|
---|
[1219] | 32 | count=1;
|
---|
| 33 | while count<=numprofiles,
|
---|
[1084] | 34 |
|
---|
| 35 | %get number of points and initialize j
|
---|
[1219] | 36 | numpoints=length(A(count).x);
|
---|
[1084] | 37 | j=1;
|
---|
| 38 |
|
---|
[1085] | 39 | %stop if we have reached end of profile (always keep the last point)
|
---|
[1131] | 40 | while j<numpoints,
|
---|
[1084] | 41 |
|
---|
| 42 | %See whether we keep this point or not
|
---|
[1219] | 43 | distance=sqrt((A(count).x(j)-A(count).x(j+1))^2+(A(count).y(j)-A(count).y(j+1))^2);
|
---|
[1131] | 44 | if distance<resolution & j<numpoints-1 %do not remove last point
|
---|
[1219] | 45 | A(count).x(j+1)=[];
|
---|
| 46 | A(count).y(j+1)=[];
|
---|
[1084] | 47 | numpoints=numpoints-1;
|
---|
| 48 | else
|
---|
[1264] | 49 | division=floor(distance/resolution)+1;
|
---|
| 50 | if division>=2,
|
---|
[1219] | 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)];
|
---|
[1131] | 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
|
---|
[1084] | 63 | end
|
---|
| 64 | end
|
---|
[1219] | 65 | if length(A(count).x)<=1,
|
---|
| 66 | A(count)=[];
|
---|
| 67 | numprofiles=numprofiles-1;
|
---|
| 68 | else
|
---|
| 69 | count=count+1;
|
---|
| 70 | end
|
---|
[1084] | 71 | end
|
---|
| 72 |
|
---|
[1093] | 73 | %write output
|
---|
[1084] | 74 | expwrite(A,newfile);
|
---|