Index: trunk/src/series/merge_proj.m
===================================================================
--- trunk/src/series/merge_proj.m	(revision 80)
+++ trunk/src/series/merge_proj.m	(revision 89)
@@ -1,3 +1,3 @@
-function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series);
+function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series)
 
 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
@@ -65,5 +65,5 @@
     if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
         if isequal(lower(FileExt{iview}),'.avi')
-            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+            MovieObject{iview}=mmreader(fullfile(Series.RootPath{iview},[Series.RootFile{iview} Series.FileExt{iview}]));
             test_movie(iview)=1;
         end
@@ -117,5 +117,5 @@
 %check coincidence in time
 multitime=0;
-if length(timecell)==0
+if isempty(timecell)
     time=[];
 elseif length(timecell)==1
@@ -160,11 +160,5 @@
 if isequal(FieldName,'get_field...')
     hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
-   % hhget_field=guidata(hget_field);%handles of GUI elements in get_field
     SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI
-%     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
-%         list_transform=get(hhget_field.menu_coord,'String');
-%         val_list=get(hhget_field.menu_coord,'Value');
-%         transform=list_transform{val_list};
-%     end
 end
 %detect whether all the files are 'images' or 'netcdf'
@@ -176,5 +170,5 @@
 for iview=1:nbview
      ext=FileExt{iview};
-     form=imformats(ext([2:end]));
+     form=imformats(ext(2:end));
      if isequal(lower(ext),'.vol')
          testvol=testvol+1;
@@ -286,7 +280,9 @@
                 Field{iview}=transform_fct(Field{iview},XmlData{iview});%transform to phys if requested
             end
+            min(Field{iview}.X)
             if testcivx
                     Field{iview}=calc_field(FieldName,Field{iview});
             end
+            min(Field{iview}.X)
 
             %projection on object (gridded plane)
@@ -386,7 +382,4 @@
         error=1;
     end
-%      if ~isequal(MergeData.VarDimIndex,Data{iview}.VarDimIndex)
-%         error=1;
-%      end
 end
 if error
@@ -394,2 +387,71 @@
     return
 end
+
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+[CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+ivar_new=0; % index of the current variable in the projected field
+icoord=0;
+for icell=1:length(CellVarIndex)
+    if NbDim(icell)==1
+        continue
+    end
+    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
+    VarType=VarTypeCell{icell};
+    ivar_X=VarType.coord_x;
+    ivar_Y=VarType.coord_y;
+    ivar_FF=VarType.errorflag;
+    if isempty(ivar_X)
+        test_grid=1;%test for input data on regular grid (e.g. image)coordinates
+    else
+        if length(ivar_Y)~=1
+                msgbox_uvmat('ERROR','y coordinate missing in proj_field.m')
+                return
+        end
+        test_grid=0;
+    end
+%    DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+    %case of input fields with unstructured coordinates
+    if ~test_grid
+        for ivar=VarIndex
+            VarName=MergeData.ListVarName{ivar};
+            for iview=1:nbview
+                eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName '];'])
+            end
+        end
+    %case of fields defined on a structured  grid 
+    else  
+%        DimValue=MergeData.DimValue(DimIndices);%set of dimension values
+        testFF=0;
+        for iview=2:nbview
+%             if ~isequal(DimValue,Data{iview}.DimValue(DimIndices))
+%                 MergeData.Txt='ERROR: attempt at merging structured fields with different sizes';
+%                 return
+%             end
+            for ivar=VarIndex
+                VarName=MergeData.ListVarName{ivar};
+                if isfield(MergeData,'VarAttribute')
+                    if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
+                        testFF=1;
+                    end
+                end
+                eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
+            end
+        end
+        if testFF
+            nbaver=nbview-MergeData.FF;
+            indgood=find(nbaver>0);
+            for ivar=VarIndex
+                VarName=MergeData.ListVarName{ivar};
+                eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
+            end 
+        else
+            for ivar=VarIndex
+                VarName=MergeData.ListVarName{ivar};
+                eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
+            end    
+        end
+    end
+end
+    
Index: trunk/src/series/sub_background.m
===================================================================
--- trunk/src/series/sub_background.m	(revision 80)
+++ trunk/src/series/sub_background.m	(revision 89)
@@ -65,4 +65,6 @@
 FileType=[];%default
 MovieObject=[];
+FileExt=Series.FileExt;
+
 if isequal(lower(FileExt),'.avi')
     hhh=which('mmreader');
@@ -78,5 +80,5 @@
    form=imformats(FileExt(2:end));
    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
-       if isequal(NomType,'*');
+       if isequal(Series.NomType,'*');
            FileType='multimage';
        else
@@ -237,5 +239,5 @@
         ifile=indselect(ifield);
         filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt,Series.NomType);
-        Aread=read_image(filename,FileType,num_i1(ifile),movieobject);
+        Aread=read_image(filename,FileType,num_i1(ifile),MovieObject);
         Ak(:,:,ifield)=Aread;           
     end
@@ -272,5 +274,5 @@
                     ifile=indselect(ifield+step*floor(nbaver/2)+iburst-1);
                     filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt,Series.NomType);
-                    Aread=read_image(filename,FileType,num_i1(ifile),movieobject);
+                    Aread=read_image(filename,FileType,num_i1(ifile),MovieObject);
                     Ak(:,:,nbaver_ima-step+iburst)=Aread;
                 end
@@ -316,10 +318,10 @@
 %------------------------------------------------------------------------
 %--read images and convert them to the uint16 format used for PIV
-function A=read_image(filename,type_ima,num,movieobject)
+function A=read_image(filename,type_ima,num,MovieObject)
 %------------------------------------------------------------------------
 %num is the view number needed for an avi movie
 switch type_ima
     case 'movie'
-        A=read(movieobject,num);
+        A=read(MovieObject,num);
     case 'avi'
         mov=aviread(filename,num);
