Changeset 866 for trunk/src/sub_field.m
- Timestamp:
- Feb 8, 2015, 7:26:02 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sub_field.m
r864 r866 125 125 126 126 %% look for coordinates common to Field in Field_1 127 ind_remove= zeros(size(Field_1.ListVarName));127 ind_remove=false(size(Field_1.ListVarName)); 128 128 % loop on the variables of the second field Field_1 129 129 for ilist=1:numel(Field_1.ListVarName) 130 130 % case of variable with a single dimension 131 if ~isempty( regexp(Field_1.VarAttribute{ilist}.Role,'^coord'))131 if ~isempty(Field_1.VarAttribute{ilist}) && ~isempty(regexp(Field_1.VarAttribute{ilist}.Role,'^coord'))% if variable with Role coord... is found. 132 132 OldDimName=Field_1.VarDimName{ilist}; 133 133 if ischar(OldDimName), OldDimName={OldDimName}; end% transform char string to cell if relevant … … 147 147 end 148 148 end 149 Field_1.ListVarName(find(ind_remove))=[];%removes the redondent coordinate 150 Field_1.VarDimName(find(ind_remove))=[]; 151 Field_1.VarAttribute(find(ind_remove))=[]; 149 if ~isempty(find(ind_remove, 1)) 150 Field_1.ListVarName(ind_remove)=[];%removes the redondent coordinate 151 Field_1.VarDimName(ind_remove)=[]; 152 Field_1.VarAttribute(ind_remove)=[]; 153 end 152 154 153 155 %% append the other variables of the second field, modifying their name if needed 154 ListVarName New=Field_1.ListVarName;155 check_rename=zeros(size(ListVarNameNew));156 check_re move=zeros(size(ListVarNameNew));157 for ilist=1:numel(ListVarNameNew) 158 VarName=Field_1.ListVarName{ilist}; 159 ind_prev=find(strcmp(ListVarName New{ilist},Field.ListVarName),1);% look for duplicated variable name156 ListVarNameSub=Field_1.ListVarName; 157 ListVarNameNew=ListVarNameSub; 158 check_rename=zeros(size(ListVarNameSub)); 159 check_remove=zeros(size(ListVarNameSub)); 160 for ilist=1:numel(ListVarNameSub) 161 ind_prev=find(strcmp(ListVarNameSub{ilist},Field.ListVarName),1);% look for duplicated variable name 160 162 if ~isempty(ind_prev)% variable name exists in Field 161 % check_rename(ilist)=0; 162 check_remove(ilist)=1; 163 if isfield(Field_1.VarAttribute{ilist},'Role')&& ismember(Field_1.VarAttribute{ilist}.Role,{'scalar','vector_x','vector_y'}) 164 ListVarNameNew{ilist}=[ListVarNameNew{ilist} '_1']; 165 check_rename(ilist)=1; 166 end 167 end 168 SubData.ListVarName=[SubData.ListVarName ListVarNameNew{ilist}]; 169 SubData.VarDimName=[SubData.VarDimName Field_1.VarDimName(ilist)]; 170 Field_1.VarAttribute{ilist}.CheckSub=1; 171 SubData.VarAttribute=[SubData.VarAttribute Field_1.VarAttribute{ilist}]; 172 SubData.(ListVarNameNew{ilist})=Field_1.(VarName);% teke the values of the old variable for the newly named one 173 %SubData.VarAttribute=[SubData.VarAttribute Field_1.VarDimName(ilist)]; 174 end 175 176 %% replace variable name in field expression FieldName, e.g. 'norm(U,V)'-> 'norm(U_1,V_1)' 177 for ilist=1:numel(ListVarNameNew) 178 if check_rename(ilist)&& isfield(Field_1.VarAttribute{ilist},'FieldName') 179 for ivar=1:numel(find(check_rename)) 180 Field_1.VarAttribute{ilist}.FieldName=regexprep_r(Field_1.VarAttribute{ilist}.FieldName,... 181 Field_1.ListVarName{ivar},ListVarNameNew{ivar}); 182 end 183 end 184 SubData.VarAttribute=[SubData.VarAttribute Field_1.VarAttribute(ilist)]; 185 SubData.VarAttribute{end}.CheckSub=1;% mark that the field needs to be substracted as an attribute 186 end 163 if isfield(Field_1.VarAttribute{ilist},'Role')&&... 164 ismember(Field_1.VarAttribute{ilist}.Role,{'coord_x','coord_y','scalar','vector_x','vector_y','errorflag'}) 165 ListVarNameNew{ilist}=[ListVarNameSub{ilist} '_1'];%modify the name of the second variable 166 check_rename(ilist)=1; 167 else 168 check_remove(ilist)=1;% variable will be removed 169 end 170 end 171 end 172 ListVarNameSub=ListVarNameSub(~check_remove); %eliminate removed variables from the list of the second field 173 ListVarNameNew=ListVarNameNew(~check_remove); % %list of renaimed varaibles corresponding to ListVarNameSub 174 VarDimNameSub=Field_1.VarDimName(~check_remove); 175 VarAttributeSub=Field_1.VarAttribute(~check_remove); 176 check_rename=check_rename(~check_remove); 177 178 % apply the variable renaming and mark the second field variables with the attribute .CheckSub 179 for ilist=1:numel(ListVarNameSub) 180 SubData.(ListVarNameNew{ilist})=Field_1.(ListVarNameSub{ilist});% copy the variable content to the new name 181 if check_rename(ilist) 182 % replace name in field expression FieldName, e.g. 'norm(U,V)'-> 'norm(U_1,V_1)' 183 if isfield(VarAttributeSub{ilist},'FieldName') 184 for ivar=1:numel(find(check_rename)) 185 VarAttributeSub{ilist}.FieldName=regexprep_r(VarAttributeSub{ilist}.FieldName,... 186 ListVarNameSub{ivar},ListVarNameNew{ivar}); 187 end 188 end 189 end 190 VarAttributeSub{ilist}.CheckSub=1;% mark that the field needs to be substracted as an attribute 191 end 192 193 SubData.ListVarName=[SubData.ListVarName ListVarNameNew]; 194 SubData.VarDimName=[SubData.VarDimName VarDimNameSub]; 195 SubData.VarAttribute=[SubData.VarAttribute VarAttributeSub]; 187 196 188 197 %% substrat fields when possible 189 198 [CellInfo,NbDim,errormsg]=find_field_cells(SubData); 190 ind_remove= zeros(size(SubData.ListVarName));199 ind_remove=false(size(SubData.ListVarName)); 191 200 ivar=[]; 192 201 ivar_1=[]; 193 202 for icell=1:numel(CellInfo) 194 203 if ~isempty(CellInfo{icell}) 204 % if two scalar are in the same cell 195 205 if isfield(CellInfo{icell},'VarIndex_scalar') && numel(CellInfo{icell}.VarIndex_scalar)==2 && SubData.VarAttribute{CellInfo{icell}.VarIndex_scalar(2)}.CheckSub; 196 206 ivar=[ivar CellInfo{icell}.VarIndex_scalar(1)]; 197 207 ivar_1=[ivar_1 CellInfo{icell}.VarIndex_scalar(2)]; 198 208 end 209 % if two vector u components are in the same cell 199 210 if isfield(CellInfo{icell},'VarIndex_vector_x') && numel(CellInfo{icell}.VarIndex_vector_x)==2 && SubData.VarAttribute{CellInfo{icell}.VarIndex_vector_x(2)}.CheckSub; 200 211 ivar=[ivar CellInfo{icell}.VarIndex_vector_x(1)]; 201 212 ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_x(2)]; 202 213 end 214 % if two vector v components are in the same cell 203 215 if isfield(CellInfo{icell},'VarIndex_vector_y') && numel(CellInfo{icell}.VarIndex_vector_y)==2 && SubData.VarAttribute{CellInfo{icell}.VarIndex_vector_y(2)}.CheckSub; 204 216 ivar=[ivar CellInfo{icell}.VarIndex_vector_y(1)]; 205 217 ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_y(2)]; 206 218 end 207 end 208 end 219 % merge the error flags if needed 220 if isfield(CellInfo{icell},'VarIndex_errorflag') && numel(CellInfo{icell}.VarIndex_errorflag)==2 && SubData.VarAttribute{CellInfo{icell}.VarIndex_vector_y(2)}.CheckSub; 221 ivar_flag=CellInfo{icell}.VarIndex_errorflag(1); 222 ivar_flag_1=CellInfo{icell}.VarIndex_errorflag(2); 223 VarName=SubData.ListVarName{ivar_flag}; 224 VarName_1=SubData.ListVarName{ivar_flag_1}; 225 SubData.(VarName)=SubData.(VarName)~=0 | SubData.(VarName_1)~=0;% combine the error flags of the two fields 226 ind_remove(ivar_flag_1)=1; 227 end 228 end 229 end 230 % subtract fields if relevant 209 231 for imod=1:numel(ivar) 210 232 VarName=SubData.ListVarName{ivar(imod)}; … … 213 235 ind_remove(ivar_1(imod))=1; 214 236 end 215 SubData.ListVarName( find(ind_remove))=[];216 SubData.VarDimName( find(ind_remove))=[];217 SubData.VarAttribute( find(ind_remove))=[];237 SubData.ListVarName(ind_remove)=[]; 238 SubData.VarDimName(ind_remove)=[]; 239 SubData.VarAttribute(ind_remove)=[]; 218 240 219 241 function OutputCell=regexprep_r(InputCell,search_string,new_string)
Note: See TracChangeset
for help on using the changeset viewer.