source: issm/oecreview/Archive/24684-25833/ISSM-24845-24846.diff@ 25834

Last change on this file since 25834 was 25834, checked in by Mathieu Morlighem, 4 years ago

CHG: added 24684-25833

File size: 3.3 KB
RevLine 
[25834]1Index: ../trunk-jpl/src/m/contrib/larour/glacier_inventory.m
2===================================================================
3--- ../trunk-jpl/src/m/contrib/larour/glacier_inventory.m (revision 24845)
4+++ ../trunk-jpl/src/m/contrib/larour/glacier_inventory.m (revision 24846)
5@@ -141,6 +141,9 @@
6 end %}}}
7
8 for gid=1:length(self.glacier_connectivity),
9+ if mod(gid,1000)==0,
10+ disp(num2str(gid/length(self.glacier_connectivity)*100));
11+ end
12 el=self.glacier_connectivity(gid); latel=md.mesh.lat(md.mesh.elements(el,:)); longel=md.mesh.long(md.mesh.elements(el,:));
13 x1=latel(1); x2=latel(2); x3=latel(3);
14 y1=longel(1); y2=longel(2); y3=longel(3);
15@@ -150,56 +153,21 @@
16 y0=self.regions(rid).CenLon(lid);
17
18 if ~isintriangle(x0,x1,x2,x3,y0,y1,y2,y3),
19- %plot([x1,x2,x3,x1],[y1,y2,y3,y1],'k*-'); text(x1,y1,'1'); text(x2,y2,'2'); text(x3,y3,'3'); plot(x0,y0,'r*');
20- %error(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
21- disp(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
22- counter=counter+1
23- end
24- end
25-
26- end % }}}
27- function connectivity_check2(self,md) % {{{
28- disp(sprintf(' Checking glacier connectivity:'));
29- figure(1),clf,hold on;
30-
31- %some quick checks: % {{{
32- if ~isempty(find(self.glacier_connectivity>md.mesh.numberofelements)),
33- error('glacier_connectivity table is pointing to elements that are > md.mesh.numberofelements!');
34- end
35- if ~isempty(find(self.glacier_connectivity<0)),
36- error('glacier_connectivity table is pointing to elements that are < 0!');
37- end %}}}
38-
39- for gid=1:length(self.glacier_connectivity),
40- el=self.glacier_connectivity(gid); latel=md.mesh.lat(md.mesh.elements(el,:)); longel=md.mesh.long(md.mesh.elements(el,:));
41- [lid,rid]=self.gidtolid(gid);
42- lat=self.regions(rid).CenLat(lid);
43- long=self.regions(rid).CenLon(lid);
44+
45+ %check in local coordinate system:
46+ proj=laea(x0,y0);
47+ [xp,yp]=gdaltransform([y0,y1,y2,y3],[x0,x1,x2,x3],'EPSG:4326',proj);
48+ x0=xp(1); x1=xp(2); x2=xp(3); x3=xp(4);
49+ y0=yp(1); y1=yp(2); y2=yp(3); y3=yp(4);
50
51- proj=laea(lat,long);
52- [longel;long]
53- [x,y]=gdaltransform([longel;long],[latel;lat],'EPSG:4326',proj);
54- x1=x(1); y1=y(1); x2=x(2); y2=y(2); x3=x(3); y3=y(3); x0=x(4); y0=y(4);
55-
56- %test if x0,y0 is in the 1,2,3 triangle:
57- epsilon=10^-10;
58- delta=x2*y3-y2*x3-x1*y3+y1*x3+x1*y2-y1*x2;
59-
60- %first area coordinate
61- area_1=((y3-y2)*(x0-x3)-(x3-x2)*(y0-y3))./delta
62- %second area coordinate
63- area_2=((x3-x1)*(y0-y3)-(y3-y1)*(x0-x3))./delta
64- %third area coordinate
65- area_3=1-area_1-area_2
66-
67- isintriangle=((area_1>=0-epsilon) & (area_2>=0-epsilon) & (area_3>=0-epsilon));
68-
69- plot([x1,x2,x3,x1],[y1,y2,y3,y1],'k*-');
70- plot(x0,y0,'r*');
71- if ~isintriangle,
72- error();
73+ if ~isintriangle(x0,x1,x2,x3,y0,y1,y2,y3),
74+
75+ plot([x1,x2,x3,x1],[y1,y2,y3,y1],'k*-'); text(x1,y1,'1'); text(x2,y2,'2'); text(x3,y3,'3'); plot(x0,y0,'r*');
76+ error(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
77+ disp(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
78+ counter=counter+1
79+ end
80 end
81-
82 end
83
84 end % }}}
Note: See TracBrowser for help on using the repository browser.