[21780] | 1 | function expcoarsen(newfile,varargin)
|
---|
[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)
|
---|
[21780] | 9 | % expcoarsen(file,resolution)
|
---|
[1090] | 10 | %
|
---|
| 11 | % Example:
|
---|
| 12 | % expcoarsen('DomainOutline.exp','Antarctica.exp',4000)
|
---|
[1084] | 13 |
|
---|
| 14 | %Some checks
|
---|
[21780] | 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'])
|
---|
[1084] | 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
|
---|
[14059] | 36 | [path root ext]=fileparts(oldfile);
|
---|
[12379] | 37 | A=expread(oldfile);
|
---|
[1084] | 38 | numprofiles=size(A,2);
|
---|
| 39 |
|
---|
| 40 | %Go through the profiles
|
---|
[1219] | 41 | count=1;
|
---|
| 42 | while count<=numprofiles,
|
---|
[1084] | 43 |
|
---|
| 44 | %get number of points and initialize j
|
---|
[1219] | 45 | numpoints=length(A(count).x);
|
---|
[1084] | 46 | j=1;
|
---|
| 47 |
|
---|
[1085] | 48 | %stop if we have reached end of profile (always keep the last point)
|
---|
[1131] | 49 | while j<numpoints,
|
---|
[1084] | 50 |
|
---|
| 51 | %See whether we keep this point or not
|
---|
[1219] | 52 | distance=sqrt((A(count).x(j)-A(count).x(j+1))^2+(A(count).y(j)-A(count).y(j+1))^2);
|
---|
[1131] | 53 | if distance<resolution & j<numpoints-1 %do not remove last point
|
---|
[1219] | 54 | A(count).x(j+1)=[];
|
---|
| 55 | A(count).y(j+1)=[];
|
---|
[1084] | 56 | numpoints=numpoints-1;
|
---|
| 57 | else
|
---|
[1264] | 58 | division=floor(distance/resolution)+1;
|
---|
| 59 | if division>=2,
|
---|
[1219] | 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)];
|
---|
[1131] | 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
|
---|
[1084] | 72 | end
|
---|
| 73 | end
|
---|
[1219] | 74 | if length(A(count).x)<=1,
|
---|
| 75 | A(count)=[];
|
---|
| 76 | numprofiles=numprofiles-1;
|
---|
| 77 | else
|
---|
| 78 | count=count+1;
|
---|
| 79 | end
|
---|
[1084] | 80 | end
|
---|
| 81 |
|
---|
[1093] | 82 | %write output
|
---|
[1084] | 83 | expwrite(A,newfile);
|
---|