% % I = intbet2outcrops(TRACER,LIMITS,LAT,LONG) % % This function computes the horizontal surface integral between two % outcrops of the TRACER field, given fixed limits eastward, westward % and southward. % % TRACER = TRACER(LAT,LONG) : surface tracer variable in 2D % LIMITS = [OUTCROP1 OUTCROP2 MAX_LAT1 MAX_LAT2 MAX_LONG1 MAX_LONG2] % : limit's values (MAX_LAT2 is used only if % the outcrop's surfaces reach them). % LAT : latitude axis (1D), degrees northward % LONG : longitude axis (1D), degrees east % I : single surface integral value % % 06/15/2006 % gmaze@mit.edu % function varargout = intbet2outcrops(TRACER,LIMITS,LAT,LONG) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % PRE-PROCESS and ERROR CHECK % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pv_checkpath % Check number of input: if nargin ~= 4 help intbet2outcrops.m error('intbet2outcrops.m : Wrong number of parameters') return end %if % Check dimensions: n = size(TRACER); if length(n)==2 [ny nx] = size(TRACER); if ny~=length(LAT) | nx~=length(LONG) help intbet2outcrops.m error('intbet2outcrops.m : Axis must have same dimensions than TRACER field'); return end %if else help intbet2outcrops.m error('intbet2outcrops.m : TRACER must be a 2D field') return end %if % Ensure that axis are of dim: (1,N) and well sorted (increasing values): a=size(LAT); if a(1) ~= 1, LAT=LAT'; end S = sort(LAT); if S ~= LAT help intbet2outcrops.m error('intbet2outcrops.m : LAT must be increasing values') return end %if a=size(LONG); if a(1) ~= 1, LONG=LONG'; end S = sort(LONG); if S ~= LONG help intbet2outcrops.m error('intbet2outcrops.m : LONG must be increasing values') return end %if % LIMITS definition: if length(LIMITS) ~= 6 help intbet2outcrops.m error('intbet2outcrops.m : LIMITS must contains 6 values') return end %if OUTCROPS = sort( LIMITS(1:2) ); LAT_MAX = sort( LIMITS(3:4) ); LONG_MAX = sort( LIMITS(5:6) ); %%%%%%%%%%%%%%%%%%%% % COMPUTE INTEGRAL % %%%%%%%%%%%%%%%%%%%% % We first determine the element surface matrix and points to integrate: [I1 I1mat dI1] = subfct_getsurf(TRACER,LAT,LONG,[OUTCROPS(1) LAT_MAX LONG_MAX]); [I2 I2mat dI2] = subfct_getsurf(TRACER,LAT,LONG,[OUTCROPS(2) LAT_MAX LONG_MAX]); % Then we determine the outcrop surface limits: I1mat = abs(I1mat - 1); Imat = (I1mat + I2mat)./2; Imat(find(Imat<1)) = 0; Imat = logical(Imat); % And the integral of the TRACER on it: I = sum(TRACER(Imat).*dI1(Imat)); %%%%%%%%%%% % OUTPUTS % %%%%%%%%%%% switch nargout case {0,1} varargout(1) = {I}; case 2 varargout(1) = {I}; varargout(2) = {Imat}; case 3 varargout(1) = {I}; varargout(2) = {Imat}; varargout(3) = {dI1}; end %switch nargout