Index: /trunk/src/calc_field.m
===================================================================
--- /trunk/src/calc_field.m	(revision 579)
+++ /trunk/src/calc_field.m	(revision 580)
@@ -1,3 +1,4 @@
-%'calc_field': defines fields (velocity, vort, div...) from civx data (old conventions) and calculate them.
+%'calc_field': defines fields (velocity, vort, div...) OBSOLETE: fusionner
+%avec calc_field_interp et calc_field_tps
 %---------------------------------------------------------------------
 % [DataOut,errormsg]=calc_field(FieldList,DataIn,Coord_interp)
@@ -44,6 +45,6 @@
     'U';... %u velocity component
     'V';... %v velocity component
-    'w';... %w velocity component
-    'w_normal';... %w velocity component normal to the plane
+    'W';... %w velocity component
+    'W_normal';... %w velocity component normal to the plane
     'error'}; %error associated to a vector (for stereo or patch)
 ColorList={'C';...%image correlation corresponding to a vel vector
Index: /trunk/src/find_field_cells.m
===================================================================
--- /trunk/src/find_field_cells.m	(revision 579)
+++ /trunk/src/find_field_cells.m	(revision 580)
@@ -205,8 +205,8 @@
 VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables
 check_coord_select= cellfun(@numel,VarDimName)==1|cellfun(@ischar,VarDimName)==1;% find remaining variables with a single dimension
-check_coord(~check_select)=check_coord_select;
-ListCoordIndex=ivar_remain(check_coord);% indices of remaining variables with a single dimension
-ListCoordName=Data.ListVarName(ListCoordIndex);% corresponding names of remaining variables with a single dimension
-ListDimName=Data.VarDimName(ListCoordIndex);% dimension names of remaining variables with a single dimension
+%check_coord(~check_select)=check_coord_select;
+ListCoordIndex=ivar_remain(check_coord_select);% indices of remaining variables with a single dimension
+ListCoordName=ListVarName(check_coord_select);% corresponding names of remaining variables with a single dimension
+ListDimName=VarDimName(check_coord_select);% dimension names of remaining variables with a single dimension
 
 %remove redondant variables -> keep only one variable per dimension
@@ -222,5 +222,5 @@
     end
 end
-ListCoordIndex=ListCoordIndex(check_keep);% list of coordinate variable indices
+ListCoordIndex=ListCoordIndex(check_coord_select);% list of coordinate variable indices
 ListCoordName=ListCoordName(check_keep);% list of coordinate variable names
 ListDimName=ListDimName(check_keep);% list of coordinate dimension names
Index: /trunk/src/read_civdata.m
===================================================================
--- /trunk/src/read_civdata.m	(revision 579)
+++ /trunk/src/read_civdata.m	(revision 580)
@@ -2,5 +2,5 @@
 %------------------------------------------------------------------
 %
-% function [Field,VelTypeOut]=read_civxdata(filename,FieldNames,VelType)
+% function [Field,VelTypeOut]=read_civdata(filename,FieldNames,VelType)
 %
 % OUTPUT:
@@ -26,6 +26,4 @@
 %                    .FF: error flag, =0 for good vectors
 %                     .C: scalar associated with velocity (used for vector colors)
-%                    .DijU; matrix of spatial derivatives (DijU(1,1,:)=DUDX,
-%                        DijU(1,2,:)=DUDY, Dij(2,1,:)=DVDX, DijU(2,2,:)=DVDY
 %
 % VelTypeOut: velocity type corresponding to the selected field: ='civ1','interp1','interp2','civ2'....
Index: /trunk/src/read_field.m
===================================================================
--- /trunk/src/read_field.m	(revision 579)
+++ /trunk/src/read_field.m	(revision 580)
@@ -7,5 +7,4 @@
 % ParamOut: structure representing parameters:
 %        .FieldName; field name
-%        .FieldList: menu of possible fields
 %        .VelType
 %        .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2  (fix1)....     
@@ -131,11 +130,10 @@
 if ~isempty(A)
     if isstruct(ParamOut)
-    ParamOut.FieldName='image';
-    ParamOut.FieldList={'image'};
+        ParamOut.FieldName='image';
     end
     Npz=1;%default
     npxy=size(A);
-%     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
-%     Rangy=[npxy(1)-0.5 0.5]; %
+    %     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
+    %     Rangy=[npxy(1)-0.5 0.5]; %
     Field.NbDim=2;%default
     Field.AName='image';
@@ -147,6 +145,6 @@
             Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
             if isstruct(ParamOut)
-            ParamOut.Npx=npxy(2);% display image size on the interface
-            ParamOut.Npy=npxy(1);
+                ParamOut.Npx=npxy(2);% display image size on the interface
+                ParamOut.Npy=npxy(1);
             end
             Field.VarAttribute{3}.Mesh=1;
@@ -159,7 +157,7 @@
             Field.AX=[0.5 npxy(3)-0.5]; % coordinates of the first and last pixel centers
             if isstruct(ParamOut)
-            ParamOut.Npx=npxy(3);% display image size on the interface
-            ParamOut.Npy=npxy(2);
-             end
+                ParamOut.Npx=npxy(3);% display image size on the interface
+                ParamOut.Npy=npxy(2);
+            end
             Field.VarAttribute{4}.Mesh=1;
         end
Index: /trunk/src/sub_field.m
===================================================================
--- /trunk/src/sub_field.m	(revision 579)
+++ /trunk/src/sub_field.m	(revision 580)
@@ -105,5 +105,5 @@
 end
 
-%look for coordinates common to Field in Field_1
+%% look for coordinates common to Field in Field_1
 ind_remove=zeros(size(Field_1.ListVarName));
 for ilist=1:numel(Field_1.ListVarName)
@@ -121,5 +121,5 @@
                    NewDim={NewDim};
                end
-               Field_1.VarDimName=regexprep_r(Field_1.VarDimName,OldDim{1},NewDim{1});
+               Field_1.VarDimName=regexprep_r(Field_1.VarDimName,['^' OldDim{1} '$'],NewDim{1});
             end
         end
@@ -130,5 +130,5 @@
 Field_1.VarAttribute(find(ind_remove))=[];
 
-%append the other variables of the second field, modifying their name if needed
+%% append the other variables of the second field, modifying their name if needed
 for ilist=1:numel(Field_1.ListVarName)
     VarName=Field_1.ListVarName{ilist};
@@ -138,4 +138,7 @@
     else  % variable name exists in Field     
             VarNameNew=[VarName '_1'];   
+            if isfield(Field_1.VarAttribute{ilist},'FieldName')
+                Field_1.VarAttribute{ilist}.FieldName=regexprep_r(Field_1.VarAttribute{ilist}.FieldName,VarName,VarNameNew);
+            end
     end
         SubData.ListVarName=[SubData.ListVarName {VarNameNew}];
@@ -146,9 +149,7 @@
 end
 
-%append the other variables of the second field, modifying their name if needed
-
 %% substrat fields when possible
 %[CellVarIndex,NbDim,CellVarType,errormsg]=find_field_cells(SubData);
-[CellInfo,NbDim,errormsg]=find_field_cells(SubData)
+[CellInfo,NbDim,errormsg]=find_field_cells(SubData);
 ind_remove=zeros(size(SubData.ListVarName));
 ivar=[];
@@ -179,8 +180,9 @@
 SubData.VarDimName(find(ind_remove))=[];
 SubData.VarAttribute(find(ind_remove))=[];
+%end
 
-function OutputCell=regexprep_r(InputCell,dimname,dimname_new)
+function OutputCell=regexprep_r(InputCell,search_string,new_string)
 for icell=1:numel(InputCell)
-    OutputCell{icell}=regexprep(InputCell{icell},['^' dimname '$'],dimname_new);
+    OutputCell{icell}=regexprep(InputCell{icell},search_string,new_string);
 end
         
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 579)
+++ /trunk/src/uvmat.m	(revision 580)
@@ -1025,4 +1025,8 @@
         set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
         set(handles_Fields,'Value',2) % set menu to 'velocity
+        if index==1
+            set(handles.FieldName_1,'Value',1);
+            set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field
+        end
         set(handles.ColorScalar,'Value',1)
         set(handles.ColorScalar,'String',ColorList)
@@ -2138,5 +2142,5 @@
         return
     end
-    Name=FileName_1;
+   % Name=FileName_1;
     switch UvData.FileType{2}
         case {'civx','civdata','netcdf'};
@@ -2188,5 +2192,5 @@
     test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
     if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1')
-           test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;%&& strcmp(FieldName_1,UvData.FieldName_1);
+           test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;
     end
     if test_keepdata_1
@@ -2199,5 +2203,5 @@
         ParamIn_1.GUIName='get_field_1';
         end  
-        [Field{2},ParamOut_1,errormsg] = read_field(Name,UvData.FileType{2},ParamIn_1,frame_index_1);
+        [Field{2},ParamOut_1,errormsg] = read_field(FileName_1,UvData.FileType{2},ParamIn_1,frame_index_1);
         if ~isempty(errormsg)
             errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg];
@@ -2256,8 +2260,8 @@
 test_veltype_1=0;
 if isempty(FileName_1)
-%     set(handles.FieldName_1,'Value',1); %update the field menu
-%     if isstruct(ParamOut)
-%     set(handles.FieldName_1,'String',[{''};ParamOut.FieldList]); %update the field menu
-%     end
+    %     set(handles.FieldName_1,'Value',1); %update the field menu
+    %     if isstruct(ParamOut)
+    %     set(handles.FieldName_1,'String',[{''};ParamOut.FieldList]); %update the field menu
+    %     end
 elseif ~test_keepdata_1
     if (~strcmp(UvData.FileType{2},'netcdf')&&~strcmp(UvData.FileType{2},'civdata')&&~strcmp(UvData.FileType{2},'civx'))|| isequal(FieldName_1,'get_field...')
@@ -2273,15 +2277,17 @@
     % update the second field menu: the same quantity
     if isstruct(ParamOut_1)
-    set(handles.FieldName_1,'String',[{''};ParamOut_1.FieldList]); %update the field menu
-    % display the FieldName menu from the input file and pick the selected one: 
-    field_index=strcmp(ParamOut_1.FieldName,ParamOut_1.FieldList);
-    set(handles.FieldName_1,'Value',find(field_index,1)+1)  
-    end
-    
+%        set(handles.FieldName_1,'String',[{''};ParamOut_1.FieldList]); %update the field menu
+        % display the FieldName menu from the input file and pick the selected one:
+        FieldList=get(handles.FieldName_1,'String');
+        field_index=strcmp(ParamOut_1.FieldName,FieldList);
+        if ~isempty(field_index)
+            set(handles.FieldName_1,'Value',find(field_index,1))
+        end
+    end
 end
 if test_veltype||test_veltype_1
-     set(handles.FixVelType,'Visible','on')
+    set(handles.FixVelType,'Visible','on')
 else
-     set(handles.FixVelType,'Visible','off')
+    set(handles.FixVelType,'Visible','off')
 end
 
@@ -2963,4 +2969,11 @@
     set(handles.VelType_1,'Value',1);%set to blank state
     set(handles.num_Opacity,'String','')% desactivate opacity setting
+    FieldList=get(handles.FieldName,'String');
+    if numel(FieldList)>1   % if a choice of fields exists
+        set(handles.FieldName_1,'Value',1)% set second field choice to blank
+        set(handles.FieldName_1,'String',[{''};FieldList])% reproduce the menu FieldName plus a blank option
+    else
+        set(handles.FieldName_1,'String',{''})% set second field choice to blank
+    end
     if ~strcmp(get(handles.VelType,'Visible'),'on')
         set(handles.VelType_1,'Visible','off')
@@ -3194,8 +3207,18 @@
         end
     otherwise
-        if check_new
-            UvData.FileType{2}=UvData.FileType{1};
+        check_refresh=1;
+        if check_new% if a second field was not previously entered, we just read another field in the first input file
             set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
             set(handles.FileExt_1,'String',get(handles.FileExt,'String'))
+            
+            UvData.FileType{2}=UvData.FileType{1};
+            UvData.XmlData{2}= UvData.XmlData{1};
+            transform=get(handles.path_transform,'UserData');
+             if (~isa(transform,'function_handle')||nargin(transform)<3)
+                set(handles.uvmat,'UserData',UvData)
+                set(handles.transform_fct,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
+                transform_fct_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
+                 check_refresh=0;
+             end             
         end
         if ~isequal(field,'image')
@@ -3205,5 +3228,6 @@
         end
         set(handles.uvmat,'UserData',UvData)
-        if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
+ 
+        if check_refresh && ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
             run0_Callback(hObject, eventdata, handles)
         end
@@ -3280,8 +3304,8 @@
         FileName_1='';% we plot the first input field without the second field
         set(handles.SubField,'Value',0)
-        SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current display, removing the second field
+        SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current plot, removing the second field
 elseif get(handles.SubField,'Value')% if subfield is already 'on'
      FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file
-     check_refresh=1;%will refresh the current display
+     check_refresh=1;%will refresh the current plot
 else% we introduce the same file (with a different field) for the second series
      FileName_1=FileName;% we compare two fields in the same file 
@@ -3291,6 +3315,7 @@
      transform=get(handles.path_transform,'UserData');
      if (~isa(transform,'function_handle')||nargin(transform)<3)
-        set(handles.transform_fct,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
-        transform_fct_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current display
+        set(handles.uvmat,'UserData',UvData)
+        set(handles.transform_fct,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
+        transform_fct_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
      else
          check_refresh=1;
@@ -3298,5 +3323,5 @@
 end
 
-% refresh the current display if it has not been done previously
+% refresh the current plot if it has not been done previously
 if check_refresh
     UvData.FileName_1='';% desactivate the use of a constant second file
@@ -3321,7 +3346,9 @@
 end
 
-%-----------------------------------------------
+
+%-----------------------------------------------------------------------
 % --- reset civ buttons
 function reset_vel_type(handles_civ0,handle1)
+%-----------------------------------------------------------------------
 for ibutton=1:length(handles_civ0)
     set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
@@ -3332,8 +3359,8 @@
 end
 
-%-------------------------------------------------------
+%-----------------------------------------------------------------------
 % --- Executes on button press in MENUVOLUME.
-%-------------------------------------------------------
 function VOLUME_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------------------------
 %errordlg('command VOL not implemented yet')
 if ishandle(handles.UVMAT_title)
