Changeset 399 for trunk/src/calc_field.m
- Timestamp:
- Apr 27, 2012, 12:28:47 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/calc_field.m
r397 r399 1 1 %'calc_field': defines fields (velocity, vort, div...) from civx data and calculate them 2 2 %--------------------------------------------------------------------- 3 % [DataOut,errormsg]=calc_field(Field Name,DataIn)3 % [DataOut,errormsg]=calc_field(FieldList,DataIn,Coord_interp) 4 4 % 5 5 % OUTPUT: … … 16 16 % 17 17 % INPUT: 18 % Field Name: string representing the name of the field18 % FieldList: cell array of strings representing the name(s) of the field(s) to calculate 19 19 % DataIn: structure representing the field, as defined in check_field_srtructure.m 20 % Coord_interp(:,nb_coord) optional set of coordinates to interpolate the field (use with thin plate shell) 20 21 % 21 22 % FUNCTION related … … 23 24 % file, depending on the scalar 24 25 25 function [DataOut,errormsg]=calc_field(Field Name,DataIn,Coord_interp)26 function [DataOut,errormsg]=calc_field(FieldList,DataIn,Coord_interp) 26 27 27 28 %list of defined scalars to display in menus (in addition to 'ima_cor'). … … 46 47 'error'}; %error associated to a vector (for stereo or patch) 47 48 errormsg=[]; %default error message 48 if ~exist('Field Name','var')49 if ~exist('FieldList','var') 49 50 DataOut=list_field;% gives the list of possible fields in the absence of input 50 51 else … … 52 53 DataIn=[]; 53 54 end 54 if ischar(Field Name)55 Field Name={FieldName};%convert a string input to a cell with one string element55 if ischar(FieldList) 56 FieldList={FieldList};%convert a string input to a cell with one string element 56 57 end 57 58 if isfield(DataIn,'Z')&& isequal(size(DataIn.Z),size(DataIn.X)) … … 78 79 XMin=min(min(DataIn.SubRange(1,:,:))); 79 80 YMin=min(min(DataIn.SubRange(2,:,:))); 80 % if ~exist('Coord_interp','var')81 % Mesh=sqrt((YMax-YMin)*(XMax-XMin)/numel(DataIn.Coord_tps(:,1,:)));%2D82 % xI=XMin:Mesh:XMax;83 % yI=YMin:Mesh:YMax;84 % [XI,YI]=meshgrid(xI,yI);% interpolation grid85 % Coord_interp(:,1)=reshape(XI,[],1);86 % Coord_interp(:,2)=reshape(YI,[],1);87 % DataOut.coord_y=[yI(1) yI(end)];88 % DataOut.coord_x=[xI(1) xI(end)];89 % end90 81 check_der=0; 91 82 check_val=0; 92 for ilist=1:length(FieldName) 93 switch FieldName{ilist} 83 nb_sites=size(Coord_interp,1); 84 nb_coord=size(Coord_interp,2); 85 for ilist=1:length(FieldList) 86 switch FieldList{ilist} 94 87 case 'velocity' 95 88 check_val=1; 96 DataOut.U=zeros( size(Coord_interp,1));97 DataOut.V=zeros( size(Coord_interp,1));89 DataOut.U=zeros(nb_sites,1); 90 DataOut.V=zeros(nb_sites,1); 98 91 case{'vort','div','strain'}% case of spatial derivatives 99 92 check_der=1; 100 DataOut.(Field Name{ilist})=zeros(size(Coord_interp,1));101 otherwise % case of a scalar102 check_val=1;103 DataOut.(FieldName{ilist})=zeros(size(Coord_interp,1));104 end 105 end 106 nbval=zeros( size(Coord_interp,1));93 DataOut.(FieldList{ilist})=zeros(nb_sites,1); 94 % otherwise % case of a scalar 95 % check_val=1; 96 % DataOut.(FieldList{ilist})=zeros(size(Coord_interp,1)); 97 end 98 end 99 nbval=zeros(nb_sites,1); 107 100 NbSubDomain=size(DataIn.SubRange,3); 101 %DataIn.Coord_tps=DataIn.Coord_tps(1:end-3,:,:);% suppress the 3 zeros used to fit with the dimensions of variables 108 102 for isub=1:NbSubDomain 109 if isfield(DataIn,'NbSites') 110 nbvec_sub=DataIn.NbSites(isub); 111 else 112 nbvec_sub=numel(find(DataIn.Indices_tps(:,isub))); 113 end 114 ind_sel=find(Coord_interp>=DataIn.SubRange(:,1,isub) & Coord_interp<=DataIn.SubRange(:,2,isub)); 103 nbvec_sub=DataIn.NbSites(isub); 104 check_range=(Coord_interp >=ones(nb_sites,1)*DataIn.SubRange(:,1,isub)' & Coord_interp<=ones(nb_sites,1)*DataIn.SubRange(:,2,isub)'); 105 ind_sel=find(sum(check_range,2)==nb_coord); 115 106 %rho smoothing parameter 116 107 % epoints = Coord_interp(ind_sel) ;% coordinates of interpolation sites … … 118 109 nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for eacn interpolation point (in case of subdomain overlap) 119 110 if check_val 120 EM = tps_eval(Coord_interp(ind_sel ),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the velocity from tps 'sources'111 EM = tps_eval(Coord_interp(ind_sel,:),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the velocity from tps 'sources' 121 112 end 122 113 if check_der 123 [EMDX,EMDY] = tps_eval_dxy(Coord_interp(ind_sel ),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the spatial derivatives from tps 'sources'124 end 125 for ilist=1:length(Field Name)126 switch Field Name{ilist}114 [EMDX,EMDY] = tps_eval_dxy(Coord_interp(ind_sel,:),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the spatial derivatives from tps 'sources' 115 end 116 for ilist=1:length(FieldList) 117 switch FieldList{ilist} 127 118 case 'velocity' 128 119 ListFields={'U', 'V'}; … … 154 145 end 155 146 DataOut.FF=nbval==0; %put errorflag to 1 for points outside the interpolation rang 156 DataOut.FF=reshape(DataOut.FF,numel(yI),numel(xI));147 % DataOut.FF=reshape(DataOut.FF,numel(yI),numel(xI)); 157 148 nbval(nbval==0)=1; 158 switch FieldName{1}159 case {'velocity','u','v'}160 DataOut.U=reshape(DataOut.U./nbval,numel(yI),numel(xI));161 DataOut.V=reshape(DataOut.V./nbval,numel(yI),numel(xI));162 case 'vort'163 DataOut.vort=reshape(DataOut.vort,numel(yI),numel(xI));164 case 'div'165 DataOut.div=reshape(DataOut.div,numel(yI),numel(xI));166 case 'strain'167 DataOut.strain=reshape(DataOut.strain,numel(yI),numel(xI));168 end149 % switch FieldList{1} 150 % case {'velocity','u','v'} 151 % DataOut.U=reshape(DataOut.U./nbval,numel(yI),numel(xI)); 152 % DataOut.V=reshape(DataOut.V./nbval,numel(yI),numel(xI)); 153 % case 'vort' 154 % DataOut.vort=reshape(DataOut.vort,numel(yI),numel(xI)); 155 % case 'div' 156 % DataOut.div=reshape(DataOut.div,numel(yI),numel(xI)); 157 % case 'strain' 158 % DataOut.strain=reshape(DataOut.strain,numel(yI),numel(xI)); 159 % end 169 160 DataOut.ListVarName=[DataOut.ListVarName ListFields]; 170 161 for ilist=3:numel(DataOut.ListVarName) … … 179 170 %% civx data 180 171 DataOut=DataIn; 181 for ilist=1:length(Field Name)182 if ~isempty(Field Name{ilist})183 [VarName,Value,Role,units]=feval(Field Name{ilist},DataIn);%calculate field with appropriate function named FieldName{ilist}172 for ilist=1:length(FieldList) 173 if ~isempty(FieldList{ilist}) 174 [VarName,Value,Role,units]=feval(FieldList{ilist},DataIn);%calculate field with appropriate function named FieldList{ilist} 184 175 ListVarName=[ListVarName VarName]; 185 176 ValueList=[ValueList Value];
Note: See TracChangeset
for help on using the changeset viewer.