source: issm/oecreview/Archive/24684-25833/ISSM-25401-25402.diff

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

CHG: added 24684-25833

File size: 2.1 KB
  • ../trunk-jpl/src/m/contrib/adhikari/latelonge.m

     
     1function [late,longe] = latelonge(md_mesh)
     2%latelonge :: computes lat,long at elemental centroids on spherical surface
     3%
     4%   Usage:
     5%      [late,longe]=latelonge(md.mesh)
     6
     7nv = md_mesh.numberofvertices;
     8if length(md_mesh.lat)~=nv | length(md_mesh.long)~=nv
     9        error('lat,long not defined properly at vertices.');
     10end
     11
     12% lat -> [0,180]; long -> [0,360] to compute centroids
     13lat=90-md_mesh.lat;             lon=md_mesh.long;
     14lon(lon<0)=180+(180+lon(lon<0));
     15
     16ax_0=lat(md_mesh.elements(:,1)); ay_0=lon(md_mesh.elements(:,1));
     17bx_0=lat(md_mesh.elements(:,2)); by_0=lon(md_mesh.elements(:,2));
     18cx_0=lat(md_mesh.elements(:,3)); cy_0=lon(md_mesh.elements(:,3));
     19% find whether long is 0 or 360! This is important to compute centroids as well as elemental area
     20for ii=1:md_mesh.numberofelements
     21        if (min([ay_0(ii),by_0(ii),cy_0(ii)])==0 && max([ay_0(ii),by_0(ii),cy_0(ii)])>180)
     22                if ay_0(ii)==0
     23                        ay_0(ii)=360;
     24                end
     25                if by_0(ii)==0
     26                        by_0(ii)=360;
     27                end
     28                if cy_0(ii)==0
     29                        cy_0(ii)=360;
     30                end
     31        end
     32end
     33% correction at the north pole
     34ay_0(ax_0==0)=(by_0(ax_0==0)+cy_0(ax_0==0))./2;
     35by_0(bx_0==0)=(cy_0(bx_0==0)+ay_0(bx_0==0))./2;
     36cy_0(cx_0==0)=(ay_0(cx_0==0)+by_0(cx_0==0))./2;
     37% correction at the south pole
     38ay_0(ax_0==180)=(by_0(ax_0==180)+cy_0(ax_0==180))./2;
     39by_0(bx_0==180)=(cy_0(bx_0==180)+ay_0(bx_0==180))./2;
     40cy_0(cx_0==180)=(ay_0(cx_0==180)+by_0(cx_0==180))./2;
     41%
     42late=(ax_0+bx_0+cx_0)/3;
     43longe=(ay_0+by_0+cy_0)/3;
     44
     45% bak to [-90 90] [-180 180] ranges.
     46late = 90-late;
     47longe(longe>180) = longe(longe>180)-360;
     48
     49
Note: See TracBrowser for help on using the repository browser.