Changeset 862 for trunk/src/sub_field.m


Ignore:
Timestamp:
Jan 30, 2015, 8:37:03 PM (9 years ago)
Author:
sommeria
Message:

bugs repaired

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sub_field.m

    r811 r862  
    150150
    151151%% append the other variables of the second field, modifying their name if needed
    152 for ilist=1:numel(Field_1.ListVarName)
     152ListVarNameNew=Field_1.ListVarName;
     153check_rename=zeros(size(ListVarNameNew));
     154for ilist=1:numel(ListVarNameNew)
    153155    VarName=Field_1.ListVarName{ilist};
    154     ind_prev=find(strcmp(VarName,Field.ListVarName));
    155     if isempty(ind_prev)% variable name does not exist in Field
    156         VarNameNew=VarName;
    157     else  % variable name exists in Field     
    158             VarNameNew=[VarName '_1'];   
    159             if isfield(Field_1.VarAttribute{ilist},'FieldName')
    160                 Field_1.VarAttribute{ilist}.FieldName=regexprep_r(Field_1.VarAttribute{ilist}.FieldName,VarName,VarNameNew);
    161             end
    162     end
    163         SubData.ListVarName=[SubData.ListVarName {VarNameNew}];
    164         SubData.VarDimName=[SubData.VarDimName Field_1.VarDimName(ilist)];
    165         SubData.(VarNameNew)=Field_1.(VarName);
    166         SubData.VarAttribute=[SubData.VarAttribute Field_1.VarAttribute(ilist)];
    167         SubData.VarAttribute{end}.CheckSub=1;% mark that the field needs to be substracted
     156    ind_prev=find(strcmp(ListVarNameNew{ilist},Field.ListVarName),1);% look for duplicated variable name
     157    if ~isempty(ind_prev)% variable name exists in Field
     158        check_rename(ilist)=1;
     159        ListVarNameNew{ilist}=[ListVarNameNew{ilist} '_1'];
     160    end
     161    SubData.ListVarName=[SubData.ListVarName ListVarNameNew{ilist}];
     162    SubData.VarDimName=[SubData.VarDimName Field_1.VarDimName(ilist)];
     163    SubData.(ListVarNameNew{ilist})=Field_1.(VarName);% teke the values of the old variable for the newly named one
     164    %SubData.VarAttribute=[SubData.VarAttribute Field_1.VarDimName(ilist)];
     165end
     166
     167%% replace variable name in field expression FieldName, e.g. 'norm(U,V)'-> 'norm(U_1,V_1)'
     168for ilist=1:numel(ListVarNameNew)
     169    if check_rename(ilist)&&  isfield(Field_1.VarAttribute{ilist},'FieldName')
     170        for ivar=1:numel(find(check_rename))
     171            Field_1.VarAttribute{ilist}.FieldName=regexprep_r(Field_1.VarAttribute{ilist}.FieldName,...
     172                Field_1.ListVarName{ivar},ListVarNameNew{ivar});
     173        end
     174    end
     175    SubData.VarAttribute=[SubData.VarAttribute Field_1.VarAttribute(ilist)];
     176    SubData.VarAttribute{end}.CheckSub=1;% mark that the field needs to be substracted as an attribute
    168177end
    169178
     
    198207SubData.VarDimName(find(ind_remove))=[];
    199208SubData.VarAttribute(find(ind_remove))=[];
    200 'end'
    201209
    202210function OutputCell=regexprep_r(InputCell,search_string,new_string)
Note: See TracChangeset for help on using the changeset viewer.