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

Last change on this file was 21780, checked in by Mathieu Morlighem, 8 years ago

CHG: some exp changes, check on NaNs, change header of expcoarsen for nargin=2, figure copy is a default again

File size: 2.0 KB
Line 
1function 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
15if nargin==2,
16 resolution = varargin{1};
17 oldfile= newfile;
18elseif nargin==3,
19 oldfile = varargin{1};
20 resolution = varargin{2};
21else
22 error('bad usage');
23end
24
25if ~exist(oldfile)
26 error(['expcoarsen error message: file ''' oldfile ''' does not exist'])
27elseif 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
33end
34
35%Get exp oldfile
36[path root ext]=fileparts(oldfile);
37A=expread(oldfile);
38numprofiles=size(A,2);
39
40%Go through the profiles
41count=1;
42while 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
80end
81
82%write output
83expwrite(A,newfile);
Note: See TracBrowser for help on using the repository browser.