


Eliminates the FVCOM nodes and elements in the lists mask_nodes and
mask_elems.
function FVCOM = restrict_spatial_indices(FVCOM,mask_nodes,mask_elems);
DESCRIPTION:
Loops through all variables in FVCOM and restricts spatial dimensions
INPUT:
FVCOM = Structure variable with FVCOM output data
mask_nodes = list of node indices to remove
mask_elems = list of elements indices to remove
OUTPUT:
FVCOM with fewer nodes and elements!
EXAMPLE USAGE:
FVCOM.temp = temperature field (node,levels,times)
FVCOM.u = velocity field (elements,levels,times)
mask_nodes = (1:300) can be the boundary/nesting nodes
mask_elems = (1:400) can be the boundary/nesting elements
FVCOM = restrict_spatial_indices(FVCOM,mask_nodes,mask_elems);
Author(s):
Ricardo Torres (Plymouth Marine Laboratory)

0001 function FVCOM = restrict_spatial_indices(FVCOM,mask_nodes,mask_elems); 0002 0003 % Eliminates the FVCOM nodes and elements in the lists mask_nodes and 0004 % mask_elems. 0005 % 0006 % function FVCOM = restrict_spatial_indices(FVCOM,mask_nodes,mask_elems); 0007 % 0008 % DESCRIPTION: 0009 % Loops through all variables in FVCOM and restricts spatial dimensions 0010 % 0011 % 0012 % INPUT: 0013 % FVCOM = Structure variable with FVCOM output data 0014 % mask_nodes = list of node indices to remove 0015 % mask_elems = list of elements indices to remove 0016 % 0017 % OUTPUT: 0018 % FVCOM with fewer nodes and elements! 0019 % 0020 % EXAMPLE USAGE: 0021 % FVCOM.temp = temperature field (node,levels,times) 0022 % FVCOM.u = velocity field (elements,levels,times) 0023 % mask_nodes = (1:300) can be the boundary/nesting nodes 0024 % mask_elems = (1:400) can be the boundary/nesting elements 0025 % FVCOM = restrict_spatial_indices(FVCOM,mask_nodes,mask_elems); 0026 % 0027 % Author(s): 0028 % Ricardo Torres (Plymouth Marine Laboratory) 0029 0030 % 0031 % Revision history: 0032 % 2018-09-17 First version 0033 % 0034 %========================================================================== 0035 0036 0037 [~, subname] = fileparts(mfilename('fullpath')); 0038 0039 global ftbverbose 0040 if ftbverbose 0041 fprintf('\nbegin : %s\n', subname) 0042 end 0043 0044 vnames = fields (FVCOM); 0045 0046 if isfield(FVCOM,'x'); 0047 nodes = length(FVCOM.x); 0048 elseif isfield(FVCOM,'lon') 0049 nodes = length(FVCOM.lon); 0050 else 0051 warning('No easily identifiable variable with node dimensions positions... e.g. x/y or lon/lat and I will continue') 0052 end 0053 0054 if isfield(FVCOM,'xc'); 0055 elems = length(FVCOM.xc); 0056 elseif isfield(FVCOM,'lonc') 0057 elems = length(FVCOM.lonc); 0058 else 0059 warning('No easily identifiable variable with element dimensions positions... e.g. xc/yc or lonc/latc and I cannot continue') 0060 end 0061 0062 if exist('nodes','var') 0063 else 0064 nodes=0; 0065 end 0066 if exist('elems','var') 0067 else 0068 elems=0; 0069 end 0070 0071 for vv=vnames' 0072 switch size(FVCOM.(vv{1}),1) % In FVCOM variable structure, the first dimension is always the spatial dimension if it is present 0073 case nodes 0074 disp(['Clipping variable FVCOM.',vv{1}]) 0075 switch ndims(FVCOM.(vv{1})) 0076 case 1 0077 FVCOM.(vv{1})(mask_nodes)=[]; 0078 case 2 0079 FVCOM.(vv{1})(mask_nodes,:)=[]; 0080 case 3 0081 FVCOM.(vv{1})(mask_nodes,:,:)=[]; 0082 end 0083 case elems 0084 disp(['Clipping variable FVCOM.',vv{1}]) 0085 switch ndims(FVCOM.(vv{1})) 0086 case 1 0087 FVCOM.(vv{1})(mask_elems)=[]; 0088 case 2 0089 FVCOM.(vv{1})(mask_elems,:)=[]; 0090 case 3 0091 FVCOM.(vv{1})(mask_elems,:,:)=[]; 0092 end 0093 end 0094 end 0095 0096 0097