Index: trunk/src/series/aver_stat.m
===================================================================
--- trunk/src/series/aver_stat.m	(revision 40)
+++ trunk/src/series/aver_stat.m	(revision 41)
@@ -32,4 +32,17 @@
 WaitbarPos=get(hseries.waitbar_frame,'Position');
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%projection object
+test_object=get(hseries.GetObject,'Value');
+if test_object%isfield(Series,'sethandles')
+    hset_object=findobj(allchild(0),'Name','set_object');
+    ProjObject=read_set_object(guidata(hset_object));
+    %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
+    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Style ' before averaging']);
+    if ~isequal(answeryes,'Yes')
+        return
+    end
+end
+
 %root input file and type
 if ~iscell(Series.RootPath)% case of a single input field series
@@ -145,4 +158,8 @@
 end
 if ~isequal(FieldName,{'get_field...'})
+    if isequal(FieldName,{''}) && ~testima
+        msgbox_uvmat('ERROR','an input field needs to be selected')
+        return
+    end
     testcivx=testnc;
 end
@@ -235,8 +252,4 @@
 % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
 subdir_result='aver_stat';
-% filebasesub=fullfile(RootPath{1},subdir_result,RootFile{1});
-% if isempty(SubDir{1}) % create a subdirectory '/aver_stat'
-%     subdir_result='aver_stat';
-%     filebasemean=fullfile(RootPath{1},subdir_result);
 if ~exist(fullfile(RootPath{1},subdir_result),'dir')
     dircur=pwd; %record current working directory
@@ -249,26 +262,11 @@
 end
 filebase_out=filebase{1}; 
-% else
-%    subdir_result=SubDir{1};
-%    filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input
-% end
-%output nomtype (to generalise)
 NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
-    
-% if NbSlice==1  
-%     filebase_out=[filebasesub '_mean'];
-% else
-%     filebase_out=[filebasesub '_' NbSlice_name 'mean'];
-%     answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
-%     if ~isequal(answeryes,'Yes')
-%         return
-%     end
-% end
 
 % coordinate transform or other user defined transform
-Coord_menu=get(hseries.CoordType,'String');
-menu_val=get(hseries.CoordType,'Value');
-usrfct=Coord_menu{menu_val};
-testfct=~isequal(usrfct,'');
+transform_fct=[];%default
+if isfield(Series,'transform_fct')
+    transform_fct=Series.transform_fct;
+end
 
 %slice loop
@@ -312,5 +310,5 @@
              end   
              % coordinate transform (or other user defined transform)
-             if ~isequal(Series.CoordType,'')
+             if ~isempty(transform_fct)
                  % z index
                 if ~isempty(NbSlice_calib)
@@ -318,10 +316,10 @@
                 end
                 if nbview==2
-                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
+                    [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
                     if isempty(Data{2})
                         Data(2)=[];
                     end
                 else
-                    Data{1}=feval(Series.CoordType,Data{1},XmlData);
+                    Data{1}=transform_fct(Data{1},XmlData);
                 end
              end     
@@ -338,6 +336,6 @@
                 Field=Data{1};
             end
-            if isfield(Series,'ProjObject')
-                [Field,errormsg]=proj_field(Field,Series.ProjObject);
+            if test_object
+                [Field,errormsg]=proj_field(Field,ProjObject);
                  if ~isempty(errormsg)
                     msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg])
Index: trunk/src/series/ima2vol.m
===================================================================
--- trunk/src/series/ima2vol.m	(revision 41)
+++ trunk/src/series/ima2vol.m	(revision 41)
@@ -0,0 +1,129 @@
+% relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc
+%----------------------------------------------------------------------
+function GUI_input=ima2vol(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)
+if ~exist('num_i1','var')
+    GUI_input={};
+    return %exit the function 
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+basename=fullfile(Series.RootPath,Series.RootFile) ;
+
+%create dir of the new images
+[dir_images,namebase]=fileparts(basename);
+[path,subdir_ima]=fileparts(dir_images);
+curdir=pwd;
+cd(path);
+mkdir([subdir_ima '_ij']);
+cd(curdir);
+basename_new=fullfile(path,[subdir_ima '_ij'],namebase);
+
+% read imadoc
+[XmlData,warntext]=imadoc2struct([basename '.xml']);
+nbfield1=size(XmlData.Time,1)
+nbfield2=size(XmlData.Time,2)
+
+answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
+test_level=isequal(answer,'Yes')
+
+%copy the xml file
+if exist([basename '.xml'],'file')
+    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
+    t=xmltree([basename_new '.xml']);
+    
+    %update information on the first image name in the series
+    uid_Heading=find(t,'ImaDoc/Heading');
+    if isempty(uid_Heading)
+        [t,uid_Heading]=add(t,1,'element','Heading');
+    end   
+    uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
+    ImageName=name_generator(basename_new,num_i1(1),num_j1(1),'.png','_i_j');
+    [pth,ImageName]=fileparts(ImageName);
+    ImageName=[ImageName '.png']
+    if isempty(uid_ImageName)
+       [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
+    end
+    uid_value=children(t,uid_ImageName);
+    if isempty(uid_value)
+        t=add(t,uid_ImageName,'chardata',ImageName)%indicate  name of the first image, with ;png extension
+    else
+        t=set(t,uid_value(1),'value',ImageName)%indicate  name of the first image, with ;png extension
+    end  
+
+%     %add information about image transform
+%     [t,new_uid]=add(t,1,'element','ImageTransform');
+%     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
+%     [t]=add(t,NameFunction_uid,'chardata','sub_background');      
+%     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
+%     [t]=add(t,new_uid,'chardata',num2str(nbslice_i));
+%     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
+%     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
+%     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
+%     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images 
+    save(t,[basename_new '.xml'])
+end
+
+%main loop
+ vol=[];
+for ifile=1:nbfield1*nbfield2
+    update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
+    filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
+    num_j=mod(ifile-1,nbfield2)+1;
+    num_i=floor((ifile-1)/nbfield2)+1;
+    A=imread(filename);
+    if test_level
+         A=levels(A);
+    end 
+    vol=[vol;A];%concacene along y
+    if num_j==nbfield2
+         filename_new=name_generator(basename_new,num_i,1,'.vol','_i');
+         imwrite(vol,filename_new,'png')
+         vol=[];
+    end      
+end
+
+
+
+function C=levels(A)
+%whos A;
+B=double(A(:,:,1));
+windowsize=round(min(size(B,1),size(B,2))/20);
+windowsize=floor(windowsize/2)*2+1;
+ix=[1/2-windowsize/2:-1/2+windowsize/2];%
+%del=np/3;
+%fct=exp(-(ix/del).^2);
+fct2=cos(ix/(windowsize-1)/2*pi/2);
+%Mfiltre=(ones(5,5)/5^2);
+%Mfiltre=fct2';
+Mfiltre=fct2'*fct2;
+Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
+
+C=filter2(ones(windowsize)/windowsize^2,B);
+C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
+C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
+C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
+C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
+C=tanh(B./(2*C));
+[n,c]=hist(reshape(C,1,[]),100);
+% figure;plot(c,n);
+
+[m,i]=max(n);
+c_max=c(i);
+[dummy,index]=sort(abs(c-c(i)));
+n=n(index);
+c=c(index);
+i_select = find(cumsum(n)<0.95*sum(n));
+if isempty(i_select)
+    i_select = 1:length(c);
+end
+c_select=c(i_select);
+n_select=n(i_select);
+cmin=min(c_select);
+cmax=max(c_select);
+C=(C-cmin)/(cmax-cmin)*256;
+C=uint8(C);
Index: trunk/src/series/merge_proj.m
===================================================================
--- trunk/src/series/merge_proj.m	(revision 40)
+++ trunk/src/series/merge_proj.m	(revision 41)
@@ -23,4 +23,24 @@
 WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame
 %-------------------------------------------------
+
+%projection object
+test_object=get(hseries.GetObject,'Value');
+if test_object
+    hset_object=findobj(allchild(0),'Name','set_object');
+    ProjObject=read_set_object(guidata(hset_object));
+    if ~isfield(ProjObject,'Style')
+            msgbox_uvmat('ERROR','Undefined projection object style')
+            return
+    end
+    if ~isequal(ProjObject.Style,'plane')
+            msgbox_uvmat('ERROR','The projection object must be a plane')
+            return
+    end
+    %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
+    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Style]);
+    if ~isequal(answeryes,'Yes')
+        return
+    end
+end
 
 %numbers of view fields (nbre of inputs in RootPath)
@@ -125,4 +145,10 @@
 end
 
+% coordinate transform or other user defined transform
+transform_fct=[];%default
+if isfield(Series,'transform_fct')
+    transform_fct=Series.transform_fct;
+end
+
 % Field and velocity type (the same for all views)
 Field_str=get(hseries.FieldMenu,'String');
@@ -170,4 +196,5 @@
     testcivx=testnc;
 end
+
 %name of output files and directory:
 % res_subdir=fullfile(Series.RootPath{1},[Series.SubDir{1} '_STAT']);
@@ -178,5 +205,5 @@
 if isequal(length(RootPath),1)
     fulldir=RootPath{1};
-    subdir='GRID';
+    subdir='merge_proj';
     res_subdir=fullfile(fulldir,subdir);
 else
@@ -209,19 +236,4 @@
 filebasesub=fullfile(res_subdir,Series.RootFile{1});
 filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
-
-%projection object
-if isfield(Series,'sethandles')
-    if ishandle(Series.sethandles.set_object)
-        Series.ProjObject=read_set_object(Series.sethandles);
-        if ~isfield(Series.ProjObject,'Style')
-            msgbox_uvmat('ERROR','Undefined projection object style')
-            return
-        end
-        if ~isequal(Series.ProjObject.Style,'plane')
-            msgbox_uvmat('ERROR','The projection object must be a plane')
-            return
-        end
-    end
-end
 
     %MAIN LOOP
@@ -271,6 +283,6 @@
                 Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
             end
-            if ~isequal(transform,'')
-                Field{iview}=feval(Series.CoordType,Field{iview},XmlData{iview});%transform to phys if requested
+            if ~isempty(transform_fct)
+                Field{iview}=transform_fct(Field{iview},XmlData{iview});%transform to phys if requested
             end
             if testcivx
@@ -279,6 +291,6 @@
 
             %projection on object (gridded plane)
-            if isfield(Series,'ProjObject')
-                Field{iview}=proj_field(Field{iview},Series.ProjObject);
+            if test_object
+                Field{iview}=proj_field(Field{iview},ProjObject);
             end
         end    
Index: trunk/src/series/relabel_i_j.m
===================================================================
--- trunk/src/series/relabel_i_j.m	(revision 40)
+++ trunk/src/series/relabel_i_j.m	(revision 41)
@@ -29,5 +29,5 @@
 nbfield2=size(XmlData.Time,2)
 
-answer=msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m')
+answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
 test_level=isequal(answer,'Yes')
 
Index: trunk/src/series/time_series.m
===================================================================
--- trunk/src/series/time_series.m	(revision 40)
+++ trunk/src/series/time_series.m	(revision 41)
@@ -34,8 +34,9 @@
 %projection object
 test_object=get(hseries.GetObject,'Value');
-if test_object%isfield(Series,'sethandles')
-    Series.ProjObject=read_set_object(Series.sethandles);
+if test_object
+    hset_object=findobj(allchild(0),'Name','set_object');
+    ProjObject=read_set_object(guidata(hset_object));
     %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
-    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' Series.ProjObject.Style]);
+    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Style]);
     if ~isequal(answeryes,'Yes')
         return
@@ -170,19 +171,19 @@
 
 % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
-filebasesub=fullfile(RootPath{1},RootFile{1});
-if NbSlice==1
-    filebase_out=[filebasesub '_time'];
-else
-    filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
-    increment=num_i1{1}(2)-num_i1{1}(1);
-    if ~isequal(increment,1) % if an increment is set
-        answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!']); 
-    else    
-        answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
-    end
-    if ~isequal(answeryes,'Yes')
-        return
-    end
-end
+% filebasesub=fullfile(RootPath{1},RootFile{1});
+% if NbSlice==1
+%     filebase_out=[filebasesub '_time'];
+% else
+%     filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
+%     increment=num_i1{1}(2)-num_i1{1}(1);
+%     if ~isequal(increment,1) % if an increment is set
+%         answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!']); 
+%     else    
+%         answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
+%     end
+%     if ~isequal(answeryes,'Yes')
+%         return
+%     end
+% end
 VelType_str=get(hseries.VelTypeMenu,'String');
 VelType_val=get(hseries.VelTypeMenu,'Value');
@@ -269,9 +270,27 @@
 end
 
-% image or scalar processing programme set by user
-Coord_menu=get(hseries.CoordType,'String');
-menu_val=get(hseries.CoordType,'Value');
-usrfct=Coord_menu{menu_val};
-testfct=~isequal(usrfct,'');
+% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
+subdir_result='time_series';
+% filebasesub=fullfile(RootPath{1},subdir_result,RootFile{1});
+% if isempty(SubDir{1}) % create a subdirectory '/aver_stat'
+%     subdir_result='aver_stat';
+%     filebasemean=fullfile(RootPath{1},subdir_result);
+if ~exist(fullfile(RootPath{1},subdir_result),'dir')
+    dircur=pwd; %record current working directory
+    cd(RootPath{1})% goes to the iamge directory
+    [m1,m2,m3]=mkdir(subdir_result);
+    if ~isequal(m2,'')
+         msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
+    end
+    cd(dircur) %back to the initial working directory
+end
+filebase_out=filebase{1}; 
+NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
+
+% coordinate transform or other user defined transform
+transform_fct=[];%default
+if isfield(Series,'transform_fct')
+    transform_fct=Series.transform_fct;
+end
 
 % to update:
@@ -331,15 +350,20 @@
                 end
              end
-            % geometry transform or other user defined transform
-            if ~isequal(Series.CoordType,'')           
+             
+             % coordinate transform (or other user defined transform)
+            if ~isempty(transform_fct)
+                 % z index
+                if ~isempty(NbSlice_calib)
+                    Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform
+                end
                 if nbview==2
-                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
+                    [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
                     if isempty(Data{2})
                         Data(2)=[];
                     end
                 else
-                    Data{1}=feval(Series.CoordType,Data{1},XmlData{1});
-                end
-            end
+                    Data{1}=transform_fct(Data{1},XmlData);
+                end
+            end     
             if testcivx
                     Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
@@ -354,7 +378,6 @@
                 Field=Data{1};
             end
-            if isfield(Series,'ProjObject')
-                Series.ProjObject
-                [Field,errormsg]=proj_field(Field,Series.ProjObject);
+            if test_object
+                [Field,errormsg]=proj_field(Field,ProjObject);
                 if ~isempty(errormsg)
                     msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg])
@@ -393,5 +416,4 @@
                                 end
                                 % check whether the variable ivar is a dimension variable
-                                %index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar
                                 DimCell=Field.VarDimName{ivar};
                                 if ischar(DimCell)
@@ -416,5 +438,5 @@
                     if testsum(ivar)==2% test for recorded variable 
                         eval(['VarVal=Field.' VarName ';']);
-                        if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
+                        if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
                             if isempty(VarVal)
                                 msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
