Changeset 124 for trunk/src/calc_field.m
 Timestamp:
 Nov 18, 2010, 10:55:22 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/calc_field.m
r123 r124 1 %'calc_field': defines fields (velocity, vort, div...) from civx data and calculate them 1 %'calc_field': defines fields (velocity, vort, div...) from civx data and calculate them 2 2 % 3 3 % [DataOut,errormsg]=calc_field(FieldName,DataIn) 4 4 % 5 % OUTPUT: 6 % Scal: matlab vector representing the scalar values (length nbvec defined by var_read) 5 % OUTPUT: 6 % Scal: matlab vector representing the scalar values (length nbvec defined by var_read) 7 7 % if no input, Scal=list of programmed scalar names (to put in menus) 8 8 % if only the field name is put as input, vec_A=type of scalar, which can be: 9 9 % 'discrete': related to the individual velocity vectors, not interpolated by patch 10 10 % 'vel': scalar calculated solely from velocity components 11 % 'der': needs spatial derivatives 11 % 'der': needs spatial derivatives 12 12 % 'var': the scalar name directly corresponds to a field name in the netcdf files 13 13 % error: error flag … … 20 20 % 21 21 % FUNCTION related 22 % varname_generator.m: determines the field names to read in the netcdf file, depending on the scalar 22 % varname_generator.m: determines the field names to read in the netcdf 23 % file, depending on the scalar 23 24 24 25 function [DataOut,errormsg]=calc_field(FieldName,DataIn) 25 26 26 27 %list of defined scalars to display in menus (in addition to 'ima_cor'). 27 % a type is associated to each scalar: 28 % a type is associated to each scalar: 28 29 % 'discrete': related to the individual velocity vectors, not interpolated by patch 29 % 'vel': calculated from velocity components, continuous field (interpolated with velocity) 30 % 'der': needs spatial derivatives 30 % 'vel': calculated from velocity components, continuous field (interpolated with velocity) 31 % 'der': needs spatial derivatives 31 32 % 'var': the scalar name corresponds to a field name in the netcdf files 32 33 % a specific variable name for civ1 and civ2 fields are also associated, if … … 35 36 %list_scal={title, type, civ1 var name,civ2 var name} 36 37 list_field={'velocity';...%image correlation corresponding to a vel vector 37 38 39 40 41 42 43 44 45 46 38 'ima_cor';...%image correlation corresponding to a vel vector 39 'norm_vel';...%norm of the velocity 40 'vort';...%vorticity 41 'div';...%divergence 42 'strain';...%rate of strain 43 'u';... %u velocity component 44 'v';... %v velocity component 45 'w';... %w velocity component 46 'w_normal';... %w velocity component normal to the plane 47 'error'}; %error associated to a vector (for stereo or patch) 47 48 errormsg=[]; %default error message 48 if ~exist('FieldName','var') 49 if ~exist('FieldName','var') 49 50 DataOut=list_field;% gives the list of possible fields in the absence of input 50 51 else … … 59 60 else 60 61 nbcoord=2; 61 end 62 end 62 63 DataOut=DataIn; %reproduce global attribute 63 64 ListVarName={}; … … 65 66 RoleList={}; 66 67 units_cell={}; 67 for ilist=1:length(FieldName) 68 for ilist=1:length(FieldName) 68 69 [VarName,Value,Role,units]=feval(FieldName{ilist},DataIn);%calculate field with appropriate function named FieldName{ilist} 69 70 ListVarName=[ListVarName VarName]; … … 71 72 RoleList=[RoleList Role]; 72 73 units_cell=[units_cell units]; 73 end74 74 end 75 %erase previous data (except coordinates) 75 76 for ivar=nbcoord+1:length(DataOut.ListVarName) 76 77 VarName=DataOut.ListVarName{ivar}; 77 78 DataOut=rmfield(DataOut,VarName); 78 end 79 end 79 80 DataOut.ListVarName=DataOut.ListVarName(1:nbcoord); 80 81 if isfield(DataOut,'VarDimName') … … 88 89 DataOut.ListVarName=[DataOut.ListVarName ListVarName]; 89 90 for ivar=1:length(ListVarName) 90 DataOut.VarDimName{nbcoord+ivar}=DataOut.VarDimName{1}; 91 DataOut.VarAttribute{nbcoord+ivar}.Role=RoleList{ivar}; 91 DataOut.VarDimName{nbcoord+ivar}=DataOut.VarDimName{1}; 92 DataOut.VarAttribute{nbcoord+ivar}.Role=RoleList{ivar}; 92 93 DataOut.VarAttribute{nbcoord+ivar}.units=units_cell{ivar}; 93 94 eval(['DataOut.' ListVarName{ivar} '=ValueList{ivar};']) … … 115 116 VarName=[VarName {'V'}]; 116 117 ValCell=[ValCell {DataIn.V}]; 117 Role=[Role {'vector_y'}]; 118 Role=[Role {'vector_y'}]; 118 119 units_cell=[units_cell {units}]; 119 120 end … … 158 159 if isfield(DataIn,'U') && isfield(DataIn,'V') 159 160 VarName{1}='norm_vel'; 160 161 162 163 164 165 166 167 units={[DataIn.CoordUnit '/' DataIn.TimeUnit]}; 168 169 units={'pixel'}; 170 171 end 161 ValCell{1}=DataIn.U.*DataIn.U+ DataIn.V.*DataIn.V; 162 if isfield(DataIn,'W') && isequal(size(DataIn.W),size(DataIn.U)) 163 ValCell{1}=ValCell{1}+DataIn.W.*DataIn.W; 164 end 165 ValCell{1}=sqrt(ValCell{1}); 166 Role{1}='scalar'; 167 if isfield(DataIn,'CoordUnit') && isfield(DataIn,'TimeUnit') 168 units={[DataIn.CoordUnit '/' DataIn.TimeUnit]}; 169 else 170 units={'pixel'}; 171 end 172 end 172 173 173 174 … … 190 191 units={[]}; 191 192 end 192 end 193 end 193 194 194 195 %%%%%%%%%%%%% divergence%%%%%%%%%%%%%%%%%%%% … … 209 210 units={[]}; 210 211 end 211 end 212 end 212 213 213 214 %%%%%%%%%%%%% strain %%%%%%%%%%%%%%%%%%%% … … 218 219 units={}; 219 220 if isfield(DataIn,'DjUi') 220 VarName{1}='strain';221 ValCell{1}=DataIn.DjUi(:,1,2)+DataIn.DjUi(:,2,1);%DVDX+DUDY222 siz=size(ValCell{1});223 ValCell{1}=reshape(ValCell{1},siz(1),1);224 if isfield(DataIn,'TimeUnit')221 VarName{1}='strain'; 222 ValCell{1}=DataIn.DjUi(:,1,2)+DataIn.DjUi(:,2,1);%DVDX+DUDY 223 siz=size(ValCell{1}); 224 ValCell{1}=reshape(ValCell{1},siz(1),1); 225 if isfield(DataIn,'TimeUnit') 225 226 units={[DataIn.TimeUnit '1']}; 226 else227 else 227 228 units={[]}; 228 end229 end 229 end 230 end 230 231 231 232 %%%%%%%%%%%%% u %%%%%%%%%%%%%%%%%%%% … … 289 290 VarName{1}='W'; 290 291 ValCell{1}=DataIn.W; 291 Role{1}='vector_z';%will behave like a vector component by projection 292 Role{1}='vector_z';%will behave like a vector component by projection 292 293 if isfield(DataIn,'CoordUnit') && isfield(DataIn,'TimeUnit') 293 294 units={[DataIn.CoordUnit '/' DataIn.TimeUnit]};
Note: See TracChangeset
for help on using the changeset viewer.