source: issm/trunk-jpl/src/m/exp/expcoarsen.m@ 13730

Last change on this file since 13730 was 13730, checked in by Mathieu Morlighem, 12 years ago

CHG: per matlab's request, removed all unnecessary semicolon

File size: 1.9 KB
RevLine 
[13730]1function 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
14if nargin~=3 | nargout
15 error('expcoarsen usage: expcoarsen(newfile,oldfile,resolution)')
16elseif ~exist(oldfile)
[13135]17 error(['expcut error message: the file ' oldfile ' does not exist'])
[1084]18elseif 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
24end
25
26%Get exp oldfile
27[path root ext ver]=fileparts(oldfile);
[12379]28A=expread(oldfile);
[1084]29numprofiles=size(A,2);
30
31%Go through the profiles
[1219]32count=1;
33while 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]71end
72
[1093]73%write output
[1084]74expwrite(A,newfile);
Note: See TracBrowser for help on using the repository browser.