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

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

CHG: added 24684-25833

File size: 3.3 KB
  • ../trunk-jpl/src/m/contrib/larour/glacier_inventory.m

     
    141141                        end  %}}}
    142142                       
    143143                        for gid=1:length(self.glacier_connectivity),
     144                                if mod(gid,1000)==0,
     145                                        disp(num2str(gid/length(self.glacier_connectivity)*100));
     146                                end
    144147                                el=self.glacier_connectivity(gid); latel=md.mesh.lat(md.mesh.elements(el,:)); longel=md.mesh.long(md.mesh.elements(el,:));
    145148                                x1=latel(1); x2=latel(2); x3=latel(3);
    146149                                y1=longel(1); y2=longel(2); y3=longel(3);
     
    150153                                y0=self.regions(rid).CenLon(lid);
    151154                               
    152155                                if ~isintriangle(x0,x1,x2,x3,y0,y1,y2,y3),
    153                                         %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*');
    154                                         %error(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
    155                                         disp(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
    156                                         counter=counter+1
    157                                 end
    158                         end
    159 
    160                 end % }}}
    161                 function connectivity_check2(self,md) % {{{
    162                         disp(sprintf('   Checking glacier connectivity:'));
    163                         figure(1),clf,hold on;
    164                        
    165                         %some quick checks:  % {{{
    166                         if ~isempty(find(self.glacier_connectivity>md.mesh.numberofelements)),
    167                                 error('glacier_connectivity table is pointing to elements that are > md.mesh.numberofelements!');
    168                         end
    169                         if ~isempty(find(self.glacier_connectivity<0)),
    170                                 error('glacier_connectivity table is pointing to elements that are < 0!');
    171                         end  %}}}
    172                        
    173                         for gid=1:length(self.glacier_connectivity),
    174                                 el=self.glacier_connectivity(gid); latel=md.mesh.lat(md.mesh.elements(el,:)); longel=md.mesh.long(md.mesh.elements(el,:));
    175                                 [lid,rid]=self.gidtolid(gid);
    176                                 lat=self.regions(rid).CenLat(lid);
    177                                 long=self.regions(rid).CenLon(lid);
     156                                       
     157                                        %check in local coordinate system:
     158                                        proj=laea(x0,y0);
     159                                        [xp,yp]=gdaltransform([y0,y1,y2,y3],[x0,x1,x2,x3],'EPSG:4326',proj);
     160                                        x0=xp(1); x1=xp(2); x2=xp(3); x3=xp(4);
     161                                        y0=yp(1); y1=yp(2); y2=yp(3); y3=yp(4);
    178162                               
    179                                 proj=laea(lat,long);
    180                                 [longel;long]
    181                                 [x,y]=gdaltransform([longel;long],[latel;lat],'EPSG:4326',proj);
    182                                 x1=x(1); y1=y(1); x2=x(2); y2=y(2); x3=x(3); y3=y(3); x0=x(4); y0=y(4);
    183                                
    184                                 %test if x0,y0 is in the 1,2,3 triangle:
    185                                 epsilon=10^-10;
    186                                 delta=x2*y3-y2*x3-x1*y3+y1*x3+x1*y2-y1*x2;
    187 
    188                                 %first area coordinate
    189                                 area_1=((y3-y2)*(x0-x3)-(x3-x2)*(y0-y3))./delta
    190                                 %second area coordinate
    191                                 area_2=((x3-x1)*(y0-y3)-(y3-y1)*(x0-x3))./delta
    192                                 %third area coordinate
    193                                 area_3=1-area_1-area_2
    194 
    195                                 isintriangle=((area_1>=0-epsilon) & (area_2>=0-epsilon) & (area_3>=0-epsilon));
    196 
    197                                 plot([x1,x2,x3,x1],[y1,y2,y3,y1],'k*-');
    198                                 plot(x0,y0,'r*');
    199                                 if ~isintriangle,
    200                                         error();
     163                                        if ~isintriangle(x0,x1,x2,x3,y0,y1,y2,y3),
     164                                       
     165                                                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*');
     166                                                error(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
     167                                                disp(sprintf('Vertex %i in region %i and lid %i is not within element %i',gid,rid,lid,el));
     168                                                counter=counter+1
     169                                        end
    201170                                end
    202 
    203171                        end
    204172
    205173                end % }}}
Note: See TracBrowser for help on using the repository browser.