Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 1000)
+++ /trunk/src/geometry_calib.m	(revision 1001)
@@ -168,4 +168,6 @@
 % --- Executes on button press APPLY (used to launch the calibration).
 function APPLY_Callback(hObject, eventdata, handles)
+set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
+
 %------------------------------------------------------------------------
 %% look for the GUI uvmat and check for an image as input
@@ -173,4 +175,8 @@
 huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
+if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
+    msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
+  return
+end
 
 RootPath='';
@@ -186,5 +192,60 @@
     outputfile=answer{1};
 end
-[GeometryCalib,index]=calibrate(handles,hhuvmat);% apply calibration
+
+%% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
+Coord=get(handles.ListCoord,'Data');
+
+  
+%% read the type of calibration
+calib_cell=get(handles.calib_type,'String');
+val=get(handles.calib_type,'Value');
+CalibFcn=['calib_' calib_cell{val}];
+
+%% read the intrinsic parameters
+Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String')); 
+Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
+Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
+Intrinsic.f1=str2num(get(handles.fx,'String'));
+Intrinsic.f2=str2num(get(handles.fy,'String'));
+Intrinsic.k=str2num(get(handles.kc,'String'));
+Intrinsic.Cx=str2num(get(handles.Cx,'String'));
+Intrinsic.Cy=str2num(get(handles.Cy,'String'));
+if isempty(Intrinsic.k)
+    Intrinsic.k=0;
+end
+if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
+    Intrinsic.Cx=Intrinsic.Npx/2;
+    Intrinsic.Cy=Intrinsic.Npy/2;
+end  
+
+%% Apply calibration
+[GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
+
+%% record the coordinate unit
+unitlist=get(handles.CoordUnit,'String');
+unit=unitlist{get(handles.CoordUnit,'value')};
+GeometryCalib.CoordUnit=unit;
+
+%% record the coordinates of the calibration points
+GeometryCalib.SourceCalib.PointCoord=Coord;
+
+%% display calibration results on the GUI geometry_calib
+display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
+display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
+%     (rotation and translation of camera with  respect to the phys coordinates)
+
+%% store the calibration data, by default in the xml file of the currently displayed image
+answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
+    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
+    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
+if strcmp(answer,'Yes') %store the calibration data
+    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
+        msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
+        GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
+    end   
+else
+    GeometryCalib=[];
+    index=1;
+end
 
 if isempty(GeometryCalib) % if calibration cancelled
@@ -228,9 +289,78 @@
 function REPLICATE_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
+set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
 
 %% look for the GUI uvmat and check for an image as input
 huvmat=findobj(allchild(0),'Name','uvmat');
 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
-GeometryCalib=calibrate(handles,hhuvmat);% apply calibration
+
+%% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
+Coord=get(handles.ListCoord,'Data');
+  
+%% read the type of calibration
+calib_cell=get(handles.calib_type,'String');
+val=get(handles.calib_type,'Value');
+CalibFcn=['calib_' calib_cell{val}];
+
+%% read the intrinsic parameters
+Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
+Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
+Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
+Intrinsic.f1=str2num(get(handles.fx,'String'));
+Intrinsic.f2=str2num(get(handles.fy,'String'));
+Intrinsic.k=str2num(get(handles.kc,'String'));
+Intrinsic.Cx=str2num(get(handles.Cx,'String'));
+Intrinsic.Cy=str2num(get(handles.Cy,'String'));
+if isempty(Intrinsic.k)
+    Intrinsic.k=0;
+end
+if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
+    Intrinsic.Cx=Intrinsic.Npx/2;
+    Intrinsic.Cy=Intrinsic.Npy/2;
+end
+
+%% apply to cropped images if requested
+answer=msgbox_uvmat('INPUT_Y-N','apply to cropped images?');
+if strcmp(answer,'Yes')
+    prompt = {'npy_lower'};
+    dlg_title = 'remove image the npy_lower image lines (removal of the upper linedoes not change calibration)';
+    num_lines= 1;
+    def     = {'0'};
+    answer = inputdlg(prompt,dlg_title,num_lines,def);
+    npy_crop=str2num(answer{1});
+    Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window
+    Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band
+end
+
+%% Apply calibration
+[GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
+
+
+%% record the coordinate unit
+unitlist=get(handles.CoordUnit,'String');
+unit=unitlist{get(handles.CoordUnit,'value')};
+GeometryCalib.CoordUnit=unit;
+
+%% record the coordinates of the calibration points
+GeometryCalib.SourceCalib.PointCoord=Coord;
+
+%% display calibration results on the GUI geometry_calib
+display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
+display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
+%     (rotation and translation of camera with  respect to the phys coordinates)
+
+%% store the calibration data, by default in the xml file of the currently displayed image
+answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
+    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
+    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
+if strcmp(answer,'Yes') %store the calibration data
+    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
+        msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
+        GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
+    end   
+else
+    GeometryCalib=[];
+    index=1;
+end
 
 %% open the GUI browse_data
@@ -265,18 +395,14 @@
 %------------------------------------------------------------------------
 % --- activate calibration and store parameters in ouputfile .
-function [GeometryCalib,index]=calibrate(handles,hhuvmat)
-%------------------------------------------------------------------------
-set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
-%% read the current calibration points
+function [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)
+%------------------------------------------------------------------------
+
 index=[];
-Coord=get(handles.ListCoord,'Data');
-Coord(:,6)=[];
+
 % apply the calibration, whose type is selected in  handles.calib_type
-GeometryCalib=[];
 if ~isempty(Coord)
-    calib_cell=get(handles.calib_type,'String');
-    val=get(handles.calib_type,'Value');
-    GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles);
+    GeometryCalib=feval(CalibFcn,Coord,Intrinsic);
 else
+    GeometryCalib=[];
     msgbox_uvmat('ERROR','No calibration points, abort')
 end 
@@ -306,39 +432,9 @@
     end
 end
-%set the coordinate unit
-unitlist=get(handles.CoordUnit,'String');
-unit=unitlist{get(handles.CoordUnit,'value')};
-GeometryCalib.CoordUnit=unit;
-%record the points
-GeometryCalib.SourceCalib.PointCoord=Coord;
-display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
-
-% Display extrinsinc parameters (rotation and translation of camera with  respect to the phys coordiantes)
-set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
-set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
-set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
-set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
-set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
-set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
-
-%% store the calibration data, by default in the xml file of the currently displayed image
-answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
-    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
-    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
-if strcmp(answer,'Yes') %store the calibration data
-    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
-        msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
-        GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
-    end
-    
-else
-    GeometryCalib=[];
-    index=1;
-end
 
 
 %------------------------------------------------------------------------
 % --- determine the parameters for a calibration by an affine function (rescaling and offset, no rotation)
-function GeometryCalib=calib_rescale(Coord,handles)
+function GeometryCalib=calib_rescale(Coord,Intrinsic)
 %------------------------------------------------------------------------
 X=Coord(:,1);
@@ -358,5 +454,5 @@
 %------------------------------------------------------------------------
 % --- determine the parameters for a calibration by a linear transform matrix (rescale and rotation)
-function GeometryCalib=calib_linear(Coord,handles) 
+function GeometryCalib=calib_linear(Coord,Intrinsic) 
 %------------------------------------------------------------------------
 X=Coord(:,1);
@@ -388,5 +484,5 @@
 % --- determine the tsai parameters for a view normal to the grid plane
 % NOT USED
-function GeometryCalib=calib_normal(Coord,handles)
+function GeometryCalib=calib_normal(Coord,Intrinsic)
 %------------------------------------------------------------------------
 Calib.f1=str2num(get(handles.fx,'String'));
@@ -451,12 +547,8 @@
 
 %------------------------------------------------------------------------
-function GeometryCalib=calib_3D_linear(Coord,handles)
-%------------------------------------------------------------------------
-path_uvmat=which('uvmat');% check the path detected for source file uvmat
-path_UVMAT=fileparts(path_uvmat); %path to UVMAT
-huvmat=findobj(allchild(0),'Tag','uvmat');
-hhuvmat=guidata(huvmat);
-coord_files=get(handles.ListCoordFiles,'String');
-if ischar(coord_files)
+function GeometryCalib=calib_3D_linear(Coord,Intrinsic)
+%------------------------------------------------------------------------
+coord_files=Intrinsic.coord_files;
+if ischar(Intrinsic.coord_files)
     coord_files={coord_files};
 end
@@ -466,10 +558,7 @@
 %retrieve the calibration points stored in the files listed in the popup list ListCoordFiles
 x_1=Coord(:,4:5)';%px coordinates of the ref points
-if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
-    msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
-  return
-end
-nx=str2num(get(hhuvmat.num_Npx,'String'));
-ny=str2num(get(hhuvmat.num_Npy,'String'));
+
+nx=Intrinsic.Npx;
+ny=Intrinsic.Npy;
 x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
 X_1=Coord(:,1:3)';%phys coordinates of the ref points
@@ -1221,12 +1310,23 @@
 set(handles.kc,'String',num2str(kc,'%1.4f'))
 
-
-% --- Executes when user attempts to close geometry_calib.
+%------------------------------------------------------------------------
+% ---display calibration extrinsic parameters
+function display_extrinsic(GeometryCalib,handles)
+%------------------------------------------------------------------------
+set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
+set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
+set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
+set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
+set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
+set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
+
+%------------------------------------------------------------------------
+% --- executes when user attempts to close geometry_calib.
 function geometry_calib_CloseRequestFcn(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 delete(hObject); % closes the figure
 
 %------------------------------------------------------------------------
-% --- Executes on button press in PLOT.
+% --- executes on button press in PLOT.
 %------------------------------------------------------------------------
 function PLOT_Callback(hObject, eventdata, handles)
Index: /trunk/src/nc2struct.m
===================================================================
--- /trunk/src/nc2struct.m	(revision 1000)
+++ /trunk/src/nc2struct.m	(revision 1001)
@@ -1,2 +1,3 @@
+
 %'nc2struct': transform a NetCDF file in a corresponding matlab structure
 % it reads all the global attributes and all variables, or a selected list.
Index: /trunk/src/plot_field.m
===================================================================
--- /trunk/src/plot_field.m	(revision 1000)
+++ /trunk/src/plot_field.m	(revision 1001)
@@ -696,12 +696,12 @@
             vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x});
             vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y});
+            XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
+            YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
             if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
-                XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
-                YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
                 vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors
                 vec_Y=reshape(Data.(YName),[],1);
             elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
-                y=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)});
-                x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)});
+                y=Data.(YName);
+                x=Data.(XName);
                 if numel(y)==2 % y defined by first and last values on aregular mesh
                     y=linspace(y(1),y(2),size(vec_U,1));
@@ -744,6 +744,6 @@
             XName=Data.ListVarName{ivar_X};
             YName=Data.ListVarName{ivar_Y};
-            eval(['Coord_x=reshape(Data.' XName ',1,[]);'])
-            eval(['Coord_y=reshape(Data.' YName ',1,[]);'])
+            Coord_x=reshape(Data.(XName),1,[]);
+            Coord_y=reshape(Data.(YName),1,[]);
             [A,Coord_x,Coord_y]=proj_grid(Coord_x',Coord_y',A',[],[],'np>256');  % interpolate on a grid
             if isfield(Data,'VarAttribute')
@@ -757,6 +757,7 @@
         elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
             YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
+            XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
             Coord_y=Data.(YName);
-            Coord_x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)});
+            Coord_x=Data.(XName);
             test_interp_X=0; %default, regularly meshed X coordinate
             test_interp_Y=0; %default, regularly meshed Y coordinate
@@ -774,5 +775,5 @@
                 DCoord_y_max=max(DCoord_y);
                 if sign(DCoord_y_min)~=sign(DCoord_y_max);% =1 for increasing values, 0 otherwise
-                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ];
+                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' YName ];
                     return
                 end
Index: /trunk/src/read_field.m
===================================================================
--- /trunk/src/read_field.m	(revision 1000)
+++ /trunk/src/read_field.m	(revision 1001)
@@ -152,5 +152,5 @@
             [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar]);
             if numel(num)~=1
-                NbCoord=NbCoord+1;% adds time coordinate, except if q single time hqs been selected
+                NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected
             end
         else
@@ -160,5 +160,6 @@
             return
         end
-        %scan all the variables beyond the two first ones, ParamIn.Coord_x and ParamIn.Coord_y.
+        CheckStructured=1;
+        %scan all the variables beyond the two first NbCoord ones describing the coordinates.
         for ilist=NbCoord+1:numel(Field.VarDimName)
             if isequal(Field.VarDimName{1},Field.VarDimName{ilist}) % if a variable has the same dimension as the coordinate, it denotes a field with unstructured coordinates
@@ -168,7 +169,21 @@
                     Field.VarAttribute{3}.Role='coord_z';
                 end
+                CheckUnstructured=0;
                 break
             end
         end
+        if CheckStructured
+            for ilist=NbCoord+1:numel(Field.VarDimName)
+                rank(1)=find(strcmp(ParamIn.Coord_x,Field.VarDimName{ilist}));
+                rank(2)=find(strcmp(ParamIn.Coord_y,Field.VarDimName{ilist}));
+                if NbCoord==3
+                rank(3)=find(strcmp(ParamIn.Coord_z,Field.VarDimName{ilist}));
+                end
+                rank=flip(rank);
+                VarName=Field.ListVarName{ilist};
+                Field.(VarName)=permute(Field.(VarName),rank);
+                Field.VarDimName{ilist}=Field.VarDimName{ilist}(rank);% permute the order of dimensions
+            end
+        end             
         NormName='';
         UName='';
@@ -225,4 +240,5 @@
                 Field.VarAttribute=[cell(1,numel(Field.ListDimName)) Field.VarAttribute];
             end
+            
         end
     case 'video'
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 1000)
+++ /trunk/src/series.m	(revision 1001)
@@ -1,2 +1,5 @@
+
+
+
 %'series': master function associated to the GUI series.m for analysis field series  
 %------------------------------------------------------------------------
@@ -185,4 +188,5 @@
 TransformPathList=cell(NbBuiltinTransform,1); % initiate the cell matrix of Action fct paths
 TransformPathList(:)={path_transform_fct}; % set the default path to series fcts to all list members
+SeriesData.TransformPath=path_transform_fct;% store the standard path for trqnsform functions (needed for compilation)
 
 %% get the user defined functions stored in the personal file uvmat_perso.mat 
@@ -1526,6 +1530,19 @@
 if strcmp(ActionExt,'.sh')
     TransformPath='';
-    if ~isempty(get(handles.ActionExt,'UserData'))
-        TransformPath=get(handles.ActionExt,'UserData');
+    if isfield(SeriesData,'TransformPath')
+        TransformPath=SeriesData.TransformPath;
+        if isfield(SeriesData,'TransformList')
+            TransformList=get(handles.TransformName,'String');
+            TransformIndex=get(handles.TransformName,'Value');
+            TransformName=TransformList{TransformIndex};
+            if ~ismember(TransformName,SeriesData.TransformList)
+                TransformPath='';
+            end
+        end
+    end
+    if ~isempty(TransformPath)&&...
+          ~strcmp(TransformPath,get(handles.TransformPath,'String'))% if the transform is not in paths set for compilation
+        msgbox_uvmat('ERROR', 'compilation not available for this transform function, select .m')
+        return
     end
     set(handles.series,'Pointer','watch') % set the mouse pointer to 'watch'
@@ -2552,12 +2569,17 @@
 FieldTransformVisible='off';  %hidden by default
 if isfield(ParamOut,'FieldTransform')
-    FieldTransformVisible=ParamOut.FieldTransform;  
+    if ~strcmp(ParamOut.FieldTransform,'off')
+    FieldTransformVisible='on';  
+    end
+    if iscell(ParamOut.FieldTransform)
+        SeriesData.TransformList=ParamOut.FieldTransform;
+    end
     TransformName_Callback([],[], handles)
 end
 set(handles.FieldTransform,'Visible',FieldTransformVisible)
-if isfield(ParamOut,'TransformPath')
-    set(handles.ActionExt,'UserData',ParamOut.TransformPath)
+if isfield(ParamOut,'TransformPath');% record the path of transform function requested for compilation
+    set(handles.TransformPath,'UserData',ParamOut.TransformPath)
 else
-    set(handles.ActionExt,'UserData',[])
+    set(handles.TransformPath,'UserData',[])
 end
 
Index: /trunk/src/series/time_series.m
===================================================================
--- /trunk/src/series/time_series.m	(revision 1000)
+++ /trunk/src/series/time_series.m	(revision 1001)
@@ -67,6 +67,10 @@
     ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-    ParamOut.FieldTransform = 'on';%can use a transform function
-    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
+    ParamOut.FieldTransform = {'phys','phys_polar'};%can use a transform function, proposed list (needed for compilation)
+    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)    
+    if 1==2 % loop used to enforce compilation of transform fct, never entered.
+        phys
+        phys_polar
+    end
     ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
     ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
@@ -217,7 +221,7 @@
 transform_fct=[];%default
 if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
-    addpath(Param.FieldTransform.TransformPath)
+    %addpath(Param.FieldTransform.TransformPath)
     transform_fct=str2func(Param.FieldTransform.TransformName);
-    rmpath(Param.FieldTransform.TransformPath)
+    %rmpath(Param.FieldTransform.TransformPath)
     if isfield(Param,'TransformInput')
         XmlData{1}.TransformInput=Param.TransformInput;
Index: unk/src/series/turb_correlation.m
===================================================================
--- /trunk/src/series/turb_correlation.m	(revision 1000)
+++ 	(revision )
@@ -1,308 +1,0 @@
-%'aver_stat': calculate Reynolds steress components over time series
-%------------------------------------------------------------------------
-% function ParamOut=turb_stat(Param)
-%
-%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%OUTPUT
-% ParamOut: sets options in the GUI series.fig needed for the function
-%
-%INPUT:
-% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
-% In batch mode, Param is the name of the corresponding xml file containing the same information
-% when Param.Action.RUN=0 (as activated when the current Action is selected
-% in series), the function ouput paramOut set the activation of the needed GUI elements
-%
-% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
-% see the current structure Param)
-%    .InputTable: cell of input file names, (several lines for multiple input)
-%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
-%    .OutputSubDir: name of the subdirectory for data outputs
-%    .OutputDirExt: directory extension for data outputs
-%    .Action: .ActionName: name of the current activated function
-%             .ActionPath:   path of the current activated function
-%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
-%             .RUN =0 for GUI input, =1 for function activation
-%             .RunMode='local','background', 'cluster': type of function  use
-%             
-%    .IndexRange: set the file or frame indices on which the action must be performed
-%    .FieldTransform: .TransformName: name of the selected transform function
-%                     .TransformPath:   path  of the selected transform function
-%    .InputFields: sub structure describing the input fields withfields
-%              .FieldName: name(s) of the field
-%              .VelType: velocity type
-%              .FieldName_1: name of the second field in case of two input series
-%              .VelType_1: velocity type of the second field in case of two input series
-%              .Coord_y: name of y coordinate variable
-%              .Coord_x: name of x coordinate variable
-%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%=======================================================================
-% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
-%   http://www.legi.grenoble-inp.fr
-%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
-%
-%     This file is part of the toolbox UVMAT.
-%
-%     UVMAT is free software; you can redistribute it and/or modify
-%     it under the terms of the GNU General Public License as published
-%     by the Free Software Foundation; either version 2 of the license,
-%     or (at your option) any later version.
-%
-%     UVMAT is distributed in the hope that it will be useful,
-%     but WITHOUT ANY WARRANTY; without even the implied warranty of
-%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-%     GNU General Public License (see LICENSE.txt) for more details.
-%=======================================================================
-
-function ParamOut=turb_stat(Param)
-
-%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
-if isstruct(Param) && isequal(Param.Action.RUN,0)
-    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
-    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
-    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
-    ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
-    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-    ParamOut.FieldTransform = 'on';%can use a transform function
-    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
-    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
-    ParamOut.OutputDirExt='.staturb';%set the output dir extension
-    ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
-%     filecell=get_file_series(Param);%check existence of the first input file
-%     if ~exist(filecell{1,1},'file')
-%         msgbox_uvmat('WARNING','the first input file does not exist')
-%     end
-    return
-end
-
-%%%%%%%%%%%%  STANDARD PART  %%%%%%%%%%%%
-ParamOut=[];%default output
-%% read input parameters from an xml file if input is a file name (batch mode)
-checkrun=1;
-if ischar(Param)
-    Param=xml2struct(Param);% read Param as input file (batch case)
-    checkrun=0;
-end
-hseries=findobj(allchild(0),'Tag','series');
-RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
-WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
-
-%% define the directory for result file (with path=RootPath{1})
-OutputDir=[Param.OutputSubDir Param.OutputDirExt];
-    
-%% root input file(s) name, type and index series
-RootPath=Param.InputTable(:,1);
-RootFile=Param.InputTable(:,3);
-SubDir=Param.InputTable(:,2);
-NomType=Param.InputTable(:,4);
-FileExt=Param.InputTable(:,5);
-[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
-%%%%%%%%%%%%
-% The cell array filecell is the list of input file names, while
-% filecell{iview,fileindex}:
-%        iview: line in the table corresponding to a given file series
-%        fileindex: file index within  the file series, 
-% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
-% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
-%%%%%%%%%%%% NbView=1 : a single input series
-NbView=numel(i1_series);%number of input file series (lines in InputTable)
-NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
-NbField_i=size(i1_series{1},2); %nb of fields for the i index
-NbField=NbField_j*NbField_i; %total number of fields
-
-%% determine the file type on each line from the first input file 
-ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'};
-NcTypeOptions={'netcdf','civx','civdata'};
-for iview=1:NbView
-    if ~exist(filecell{iview,1}','file')
-        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
-        return
-    end
-    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
-    FileType{iview}=FileInfo{iview}.FileType;
-    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
-    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
-    if ~isempty(j1_series{iview})
-        frame_index{iview}=j1_series{iview};
-    else
-        frame_index{iview}=i1_series{iview};
-    end
-end
-
-%% calibration data and timing: read the ImaDoc files
-XmlData=[];
-[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
-if size(time,1)>1
-    diff_time=max(max(diff(time)));
-    if diff_time>0
-        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
-    end   
-end
-
-%% coordinate transform or other user defined transform
-transform_fct='';%default
-if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
-    addpath(Param.FieldTransform.TransformPath)
-    transform_fct=str2func(Param.FieldTransform.TransformName);
-    rmpath(Param.FieldTransform.TransformPath)
-end
-
-%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
- % EDIT FROM HERE
-
-%% check the validity of  input file types
-if CheckImage{1}
-    FileExtOut='.png'; % write result as .png images for image inputs
-elseif CheckNc{1}
-    FileExtOut='.nc';% write result as .nc files for netcdf inputs
-else
-    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
-    return
-end
-
-
-%% settings for the output file
-NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
-first_i=i1_series{1}(1);
-last_i=i1_series{1}(end);
-if isempty(j1_series{1})% if there is no second index j
-    first_j=1;last_j=1;
-else
-    first_j=j1_series{1}(1);
-    last_j=j1_series{1}(end);
-end
-
-%% Set field names and velocity types
-InputFields{1}=[];%default (case of images)
-if isfield(Param,'InputFields')
-    InputFields{1}=Param.InputFields;
-end
-
-nbfiles=0;
-nbmissing=0;
-
-%initialisation
-DataOut.ListGlobalAttribute= {'Conventions'};
-DataOut.Conventions= 'uvmat';
-DataOut.ListVarName={'coord_y', 'coord_x' ,'UMean' , 'VMean','u2Mean','v2Mean','u2Mean_1','v2Mean_1','uvMean','Counter'};
-DataOut.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},...
-    {'coord_y','coord_x'},{'coord_y','coord_x'}};
-DataOut.UMean=0;
-DataOut.VMean=0;
-DataOut.u2Mean=0;
-DataOut.v2Mean=0;
-DataOut.u2Mean_1=0;
-DataOut.v2Mean_1=0;
-DataOut.uvMean=0;
-DataOut.Counter=0;
-U2Mean=0;
-V2Mean=0;
-UVMean=0;
-U2Mean_1=0;
-V2Mean_1=0;
-Counter_1=0;
-
-%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
-for index=1:NbField
-    update_waitbar(WaitbarHandle,index/NbField)
-    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
-        disp('program stopped by user')
-        break
-    end
-    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
-
-    %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
-    if index==1 %first field
-        DataOut=Field;
-        DataOut.coord_y=Field.coord_y;
-        DataOut.coord_x=Field.coord_x;
-        Uprev=Field.U;
-        Vprev=Field.V;
-        if isfield(Field,'FF')
-        FFprev=Field.FF;
-        else
-            FFprev=true(size(Field.U));
-        end
-        [npy,npx]=size(Field.U);
-        DataOut.Ucorr=zeros(npy,npx);
-    end
-    FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U
-    UMean=sum(Field.U,2);
-    UMean=sum(FF,2);
-    UMean=UMean./UMean;
-    Field.U=Field.U-ones(npy,1)*UMean;% substract mean U at each position y
-    Field.U(FF)=0;% set to 0 the nan values
-    Field.V(FF)=0;
-    Ucorr=zeros(npy,npx);
-    for ishift=-(npx-1):(npx-1)% calculate the field U shifted 
-        U_shift=shiftdim(Field.U,[0 -ishift]);
-        if ishift<0
-        U_shift(:,1:-ishift)=0;
-        FF_shift(:,1:-ishift)=1;
-        elseif ishift>0
-            U_shift(:,end-ishift:end)=0;
-            FF_shift(:,1:end-ishift:end)=1;
-        end
-        UCorr(:,ishift+npx)=sum(Field.U.*U_shift,2);
-        nonNaNcounter=sum(~FF.*~FF_shift,2);
-        UCorr(:,ishift+npx)=UCorr(:,ishift+npx)./nonNaNcounter;
-    end
-    DataOut.UCorr=DataOut.UCorr+UCorr;
-    
-    %% continuer
-    
-    DataOut.UMean=DataOut.UMean+Field.U; %increment the sum
-    DataOut.VMean=DataOut.VMean+Field.V; %increment the sum
-    U2Mean=U2Mean+(Field.U).*(Field.U); %increment the U squared sum
-    V2Mean=V2Mean+(Field.V).*(Field.V); %increment the V squared sum
-    UVMean=UVMean+(Field.U).*(Field.V); %increment the sum
-    U2Mean_1=U2Mean_1+(Field.U).*Uprev; %increment the U squared sum
-    V2Mean_1=V2Mean_1+(Field.V).*Vprev; %increment the V squared sum
-    Uprev=Field.U; %store for next iteration
-    Vprev=Field.V;
-    FFprev=FF;
-end
-%%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
-DataOut.UCorr=DataOut.UCorr/NbField;
-%DataOut.Counter(DataOut.Counter==0)=1;% put counter to 1 when it is zero
-% DataOut.UMean=DataOut.UMean./DataOut.Counter; % normalize the mean
-% DataOut.VMean=DataOut.VMean./DataOut.Counter; % normalize the mean
-% U2Mean=U2Mean./DataOut.Counter; % normalize the mean
-% V2Mean=V2Mean./DataOut.Counter; % normalize the mean
-% UVMean=UVMean./DataOut.Counter; % normalize the mean
-% U2Mean_1=U2Mean_1./Counter_1; % normalize the mean
-% V2Mean_1=V2Mean_1./Counter_1; % normalize the mean
-% DataOut.u2Mean=U2Mean-DataOut.UMean.*DataOut.UMean; % normalize the mean
-% DataOut.v2Mean=V2Mean-DataOut.VMean.*DataOut.VMean; % normalize the mean
-% DataOut.uvMean=UVMean-DataOut.UMean.*DataOut.VMean; % normalize the mean \
-% DataOut.u2Mean_1=U2Mean_1-DataOut.UMean.*DataOut.UMean; % normalize the mean
-% DataOut.v2Mean_1=V2Mean_1-DataOut.VMean.*DataOut.VMean; % normalize the mean
-
-
-%% calculate the profiles
-% npx=numel(DataOut.coord_x);
-% band=ceil(npx/5) :floor(4*npx/5);% keep only the central band
-% for ivar=3:numel(DataOut.ListVarName)-1
-%     VarName=DataOut.ListVarName{ivar};% name of the variable
-%     DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Profile']}];%append the name of the profile variable
-%     DataOut.VarDimName=[DataOut.VarDimName {'coord_y'}];
-%    DataOut.([VarName 'Profile'])=mean(DataOut.(VarName)(:,band),2); %take the mean profile of U, excluding the edges
-% end
-
-%% writing the result file as netcdf file
-OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
- %case of netcdf input file , determine global attributes
- errormsg=struct2nc(OutputFile,DataOut); %save result file
- if isempty(errormsg)
-     disp([OutputFile ' written']);
- else
-     disp(['error in writting result file: ' errormsg])
- end
-
-
-%% open the result file with uvmat (in RUN mode)
-if checkrun
-    uvmat(OutputFile)% open the last result file with uvmat
-end
Index: /trunk/src/series/turb_correlation_time.m
===================================================================
--- /trunk/src/series/turb_correlation_time.m	(revision 1001)
+++ /trunk/src/series/turb_correlation_time.m	(revision 1001)
@@ -0,0 +1,350 @@
+%'turb_correlation_time': calculate the time correlation function at each point
+%------------------------------------------------------------------------
+% function ParamOut=turb_correlation_time(Param)
+%
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%OUTPUT
+% ParamOut: sets options in the GUI series.fig needed for the function
+%
+%INPUT:
+% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
+% In batch mode, Param is the name of the corresponding xml file containing the same information
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
+%
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
+%    .InputTable: cell of input file names, (several lines for multiple input)
+%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
+%    .OutputSubDir: name of the subdirectory for data outputs
+%    .OutputDirExt: directory extension for data outputs
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
+%    .IndexRange: set the file or frame indices on which the action must be performed
+%    .FieldTransform: .TransformName: name of the selected transform function
+%                     .TransformPath:   path  of the selected transform function
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name(s) of the field
+%              .VelType: velocity type
+%              .FieldName_1: name of the second field in case of two input series
+%              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%=======================================================================
+% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function ParamOut=turb_stat(Param)
+
+%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
+    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'on';%can use a transform function
+    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
+    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='.corr_t';%set the output dir extension
+    ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
+%     filecell=get_file_series(Param);%check existence of the first input file
+%     if ~exist(filecell{1,1},'file')
+%         msgbox_uvmat('WARNING','the first input file does not exist')
+%     end
+    return
+end
+
+%%%%%%%%%%%%  STANDARD PART  %%%%%%%%%%%%
+ParamOut=[];%default output
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
+if ischar(Param)
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+end
+
+hseries=findobj(allchild(0),'Tag','series');
+RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+
+%% define the directory for result file (with path=RootPath{1})
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];
+    
+%% root input file(s) name, type and index series
+RootPath=Param.InputTable(:,1);
+RootFile=Param.InputTable(:,3);
+SubDir=Param.InputTable(:,2);
+NomType=Param.InputTable(:,4);
+FileExt=Param.InputTable(:,5);
+[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+%%%%%%%%%%%%
+% The cell array filecell is the list of input file names, while
+% filecell{iview,fileindex}:
+%        iview: line in the table corresponding to a given file series
+%        fileindex: file index within  the file series, 
+% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
+% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
+%%%%%%%%%%%% NbView=1 : a single input series
+NbView=numel(i1_series);%number of input file series (lines in InputTable)
+NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
+NbField_i=size(i1_series{1},2); %nb of fields for the i index
+NbField=NbField_j*NbField_i; %total number of fields
+NpTime=256;% max number of times for each side of the time correlation fct
+NpTime=min(NpTime,floor(NbField/4)); %nbre of points for the correlation fct on each side of 0
+
+%% determine the file type on each line from the first input file 
+ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'};
+NcTypeOptions={'netcdf','civx','civdata'};
+for iview=1:NbView
+    if ~exist(filecell{iview,1}','file')
+        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
+        return
+    end
+    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
+    FileType{iview}=FileInfo{iview}.FileType;
+    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
+    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
+    if ~isempty(j1_series{iview})
+        frame_index{iview}=j1_series{iview};
+    else
+        frame_index{iview}=i1_series{iview};
+    end
+end
+
+%% calibration data and timing: read the ImaDoc files
+XmlData=[];
+[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
+if size(time,1)>1
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
+    end   
+end
+
+%% coordinate transform or other user defined transform
+transform_fct='';%default
+if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
+    addpath(Param.FieldTransform.TransformPath)
+    transform_fct=str2func(Param.FieldTransform.TransformName);
+    rmpath(Param.FieldTransform.TransformPath)
+end
+
+%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
+ % EDIT FROM HERE
+
+%% check the validity of  input file types
+if CheckImage{1}
+    FileExtOut='.png'; % write result as .png images for image inputs
+elseif CheckNc{1}
+    FileExtOut='.nc';% write result as .nc files for netcdf inputs
+else
+    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
+    return
+end
+
+
+%% settings for the output file
+NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
+first_i=i1_series{1}(1);
+last_i=i1_series{1}(end);
+if isempty(j1_series{1})% if there is no second index j
+    first_j=1;last_j=1;
+else
+    first_j=j1_series{1}(1);
+    last_j=j1_series{1}(end);
+end
+
+%% Set field names and velocity types
+InputFields{1}=[];%default (case of images)
+if isfield(Param,'InputFields')
+    InputFields{1}=Param.InputFields;
+end
+
+nbfiles=0;
+nbmissing=0;
+
+%initialisation
+DataOut.ListGlobalAttribute= {'Conventions'};
+DataOut.Conventions='uvmat';
+DataOut.ListVarName={'delta_t','coord_y','coord_x','UUCorr' , 'VVCorr','UVCorr','Counter'};
+DataOut.VarDimName={'delta_t','coord_y','coord_x',...
+    {'delta_t','coord_y','coord_x'},{'delta_t','coord_y','coord_x'},{'delta_t','coord_y','coord_x'},{'delta_t','coord_y','coord_x'}};
+
+%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+% First get mean values %
+disp('loop for mean started')
+Time=zeros(1,NbField);
+for index=1:NbField
+    update_waitbar(WaitbarHandle,index/NbField)
+    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        break
+    end
+    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
+    if index==1 %first field
+        if ~isempty(errormsg)
+            disp_uvmat('ERROR',errormsg,checkrun)
+            return
+        elseif ~isfield(Field,'U')||~isfield(Field,'V')
+            disp_uvmat('ERROR','this function requires the velocity components U and V as input',checkrun)
+            return
+        elseif ~isfield(Field,'Time')
+            disp_uvmat('ERROR','the attribute Time needs to be defined as input',checkrun)
+            return
+        end
+        [npy,npx]=size(Field.U);
+        UMean=zeros(npy,npx);
+        VMean=zeros(npy,npx);
+        Counter=false(npy,npx);
+        % transcripts the global attributes
+        if isfield(Field,'ListGlobalAttribute')
+            DataOut.ListGlobalAttribute= Field.ListGlobalAttribute;
+            for ilist=1:numel(Field.ListGlobalAttribute)
+                AttrName=Field.ListGlobalAttribute{ilist};
+                DataOut.(AttrName)=Field.(AttrName);
+            end
+        end
+    end
+    Time(index)=Field.Time;
+    FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U
+    Field.U(FF)=0;% set to 0 the nan values,
+    Field.V(FF)=0;
+    UMean=UMean+Field.U;
+    VMean=VMean+Field.V;
+    Counter=Counter+~FF;
+end
+UMean=UMean./Counter;
+VMean=VMean./Counter;
+
+
+%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+disp('loop for correlation started')
+for index=1:NbField
+    update_waitbar(WaitbarHandle,index/NbField)
+    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        break
+    end
+    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
+    
+    %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
+    if index==1 %first field
+        [npy,npx]=size(Field.U);      
+        dt=diff(Time);
+        Maxdt=max(dt); Mindt=min(dt);
+        if Maxdt-Mindt>0.001*Maxdt
+            disp_uvmat('ERROR','the time increment between fields is not constant',checkrun)
+            return
+        else
+            dt=(Maxdt+Mindt)/2;
+        end
+        DataOut.delta_t=(0:dt:dt*NpTime)';
+        DataOut.coord_x=Field.coord_x;
+        DataOut.coord_y=Field.coord_y;
+        DataOut.UUCorr=zeros(NpTime+1,npy,npx);
+        DataOut.VVCorr=zeros(NpTime+1,npy,npx);
+        DataOut.UVCorr=zeros(NpTime+1,npy,npx);
+        DataOut.Counter=zeros(NpTime+1,npy,npx);
+        U_shift=zeros(NpTime+1,npy,npx);
+        V_shift=zeros(NpTime+1,npy,npx);
+        FF_shift=zeros(NpTime+1,npy,npx);
+        UUCorr=zeros(NpTime+1,npy,npx);
+        VVCorr=zeros(NpTime+1,npy,npx);
+        UVCorr=zeros(NpTime+1,npy,npx);
+        FFCorr=false(NpTime+1,npy,npx);
+    end
+    FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U
+    Field.U(FF)=0;% set to 0 the nan values,'delta_x'
+    Field.V(FF)=0;
+    Field.U=Field.U-UMean;
+    Field.V=Field.V-VMean;
+    if index<=NpTime+1
+        U_shift(index,:,:)=Field.U;
+        V_shift(index,:,:)=Field.V;
+        FF_shift(index,:,:)=FF;
+    else
+        U_shift=circshift(U_shift,[-1 0 0]); %shift U by ishift along the first index
+        V_shift=circshift(V_shift,[-1 0 0]); %shift U by ishift along the first index
+        FF_shift=circshift(FF_shift,[-1 0 0]); %shift U by ishift along the first index
+        U_shift(NpTime+1,:,:)=Field.U;
+        V_shift(NpTime+1,:,:)=Field.V;
+        FF_shift(NpTime+1,:,:)=FF;
+    end
+    for ishift=1:NpTime% calculate the field U shifted
+        UUCorr(ishift,:,:)=Field.U.*U_shift(ishift,:,:);
+        VVCorr(ishift,:,:)=Field.V.*V_shift(ishift,:,:);
+        UVCorr(ishift,:,:)=Field.U.*V_shift(ishift,:,:);
+        FFCorr(ishift,:,:)=FF | FF_shift;
+    end
+    DataOut.UUCorr=DataOut.UUCorr+UUCorr;
+    DataOut.VVCorr=DataOut.VVCorr+VVCorr;
+    DataOut.UVCorr=DataOut.UVCorr+UVCorr;
+    DataOut.Counter=DataOut.Counter+~FFCorr;
+end
+%%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
+% DataOut.UUCorr=DataOut.UUCorr./DataOut.Counter;
+% DataOut.VVCorr=DataOut.VVCorr./DataOut.Counter;
+% DataOut.VUVCorr=DataOut.UVCorr./DataOut.Counter;
+%DataOut.Counter(DataOut.Counter==0)=1;% put counter to 1 when it is zero
+% DataOut.UMean=DataOut.UMean./DataOut.Counter; % normalize the mean
+% DataOut.VMean=DataOut.VMean./DataOut.Counter; % normalize the mean
+% U2Mean=U2Mean./DataOut.Counter; % normalize the mean
+% V2Mean=V2Mean./DataOut.Counter; % normalize the mean
+% UVMean=UVMean./DataOut.Counter; % normalize the mean
+% U2Mean_1=U2Mean_1./Counter_1; % normalize the mean
+% V2Mean_1=V2Mean_1./Counter_1; % normalize the mean
+% DataOut.u2Mean=U2Mean-DataOut.UMean.*DataOut.UMean; % normalize the meanFFCorr
+% DataOut.v2Mean=V2Mean-DataOut.VMean.*DataOut.VMean; % normalize the mean
+% DataOut.uvMean=UVMean-DataOut.UMean.*DataOut.VMean; % normalize the mean \
+% DataOut.u2Mean_1=U2Mean_1-DataOut.UMean.*DataOut.UMean; % normalize the mean
+% DataOut.v2Mean_1=V2Mean_1-DataOut.VMean.*DataOut.VMean; % normalize the mean
+
+
+%% calculate the profiles
+% npx=numel(DataOut.coord_x);
+% band=ceil(npx/5) :floor(4*npx/5);% keep only the central band
+% for ivar=3:numel(DataOut.ListVarName)-1
+%     VarName=DataOut.ListVarName{ivar};% name of the variable
+%     DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Profile']}];%append the name of the profile variable
+%     DataOut.VarDimName=[DataOut.VarDimName {'coord_y'}];
+%    DataOut.([VarName 'Profile'])=mean(DataOut.(VarName)(:,band),2); %take the mean profile of U, excluding the edges
+% end
+
+%% writing the result file as netcdf file
+OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
+ %case of netcdf input file , determine global attributes
+ errormsg=struct2nc(OutputFile,DataOut); %save result file
+ if isempty(errormsg)
+     disp([OutputFile ' written']);
+ else
+     disp(['error in writting result file: ' errormsg])
+ end
+
+
+%% open the result file with uvmat (in RUN mode)
+if checkrun
+    uvmat(OutputFile)% open the last result file with uvmat
+end
Index: /trunk/src/series/turb_correlation_x.m
===================================================================
--- /trunk/src/series/turb_correlation_x.m	(revision 1001)
+++ /trunk/src/series/turb_correlation_x.m	(revision 1001)
@@ -0,0 +1,332 @@
+%'turb_correlation_x': calculate the x wise correlation function at each point
+%------------------------------------------------------------------------
+% function ParamOut=turb_correlation_x(Param)
+%
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%OUTPUT
+% ParamOut: sets options in the GUI series.fig needed for the function
+%
+%INPUT:
+% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
+% In batch mode, Param is the name of the corresponding xml file containing the same information
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
+%
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
+%    .InputTable: cell of input file names, (several lines for multiple input)
+%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
+%    .OutputSubDir: name of the subdirectory for data outputs
+%    .OutputDirExt: directory extension for data outputs
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
+%    .IndexRange: set the file or frame indices on which the action must be performed
+%    .FieldTransform: .TransformName: name of the selected transform function
+%                     .TransformPath:   path  of the selected transform function
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name(s) of the field
+%              .VelType: velocity type
+%              .FieldName_1: name of the second field in case of two input series
+%              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%=======================================================================
+% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function ParamOut=turb_stat(Param)
+
+%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
+    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'on';%can use a transform function
+    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
+    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='.corr_x';%set the output dir extension
+    ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
+%     filecell=get_file_series(Param);%check existence of the first input file
+%     if ~exist(filecell{1,1},'file')
+%         msgbox_uvmat('WARNING','the first input file does not exist')
+%     end
+    return
+end
+
+%%%%%%%%%%%%  STANDARD PART  %%%%%%%%%%%%
+ParamOut=[];%default output
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
+if ischar(Param)
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+end
+hseries=findobj(allchild(0),'Tag','series');
+RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+
+%% define the directory for result file (with path=RootPath{1})
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];
+    
+%% root input file(s) name, type and index series
+RootPath=Param.InputTable(:,1);
+RootFile=Param.InputTable(:,3);
+SubDir=Param.InputTable(:,2);
+NomType=Param.InputTable(:,4);
+FileExt=Param.InputTable(:,5);
+[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+%%%%%%%%%%%%
+% The cell array filecell is the list of input file names, while
+% filecell{iview,fileindex}:
+%        iview: line in the table corresponding to a given file series
+%        fileindex: file index within  the file series, 
+% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
+% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
+%%%%%%%%%%%% NbView=1 : a single input series
+NbView=numel(i1_series);%number of input file series (lines in InputTable)
+NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
+NbField_i=size(i1_series{1},2); %nb of fields for the i index
+NbField=NbField_j*NbField_i; %total number of fields
+
+%% determine the file type on each line from the first input file 
+ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'};
+NcTypeOptions={'netcdf','civx','civdata'};
+for iview=1:NbView
+    if ~exist(filecell{iview,1}','file')
+        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
+        return
+    end
+    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
+    FileType{iview}=FileInfo{iview}.FileType;
+    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
+    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
+    if ~isempty(j1_series{iview})
+        frame_index{iview}=j1_series{iview};
+    else
+        frame_index{iview}=i1_series{iview};
+    end
+end
+
+%% calibration data and timing: read the ImaDoc files
+XmlData=[];
+[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
+if size(time,1)>1
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
+    end   
+end
+
+%% coordinate transform or other user defined transform
+transform_fct='';%default
+if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
+    addpath(Param.FieldTransform.TransformPath)
+    transform_fct=str2func(Param.FieldTransform.TransformName);
+    rmpath(Param.FieldTransform.TransformPath)
+end
+
+%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
+ % EDIT FROM HERE
+
+%% check the validity of  input file types
+if CheckImage{1}
+    FileExtOut='.png'; % write result as .png images for image inputs
+elseif CheckNc{1}
+    FileExtOut='.nc';% write result as .nc files for netcdf inputs
+else
+    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
+    return
+end
+
+
+%% settings for the output file
+NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
+first_i=i1_series{1}(1);
+last_i=i1_series{1}(end);
+if isempty(j1_series{1})% if there is no second index j
+    first_j=1;last_j=1;
+else
+    first_j=j1_series{1}(1);
+    last_j=j1_series{1}(end);
+end
+
+%% Set field names and velocity types
+InputFields{1}=[];%default (case of images)
+if isfield(Param,'InputFields')
+    InputFields{1}=Param.InputFields;
+end
+
+nbfiles=0;
+nbmissing=0;
+
+%initialisation
+DataOut.ListGlobalAttribute= {'Conventions'};
+DataOut.Conventions= 'uvmat';
+DataOut.ListVarName={'delta_x','coord_y','coord_x','UUCorr' , 'VVCorr','UVCorr','Counter'};
+DataOut.VarDimName={'delta_x','coord_y','coord_x',...
+    {'delta_x','coord_y','coord_x'},{'delta_x','coord_y','coord_x'},{'delta_x','coord_y','coord_x'},{'delta_x','coord_y','coord_x'}};
+DataOut.UUCorr=0;
+DataOut.Counter=0;
+
+%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+% First get mean values %
+disp('loop for mean started')
+for index=1:NbField
+    update_waitbar(WaitbarHandle,index/NbField)
+    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        break
+    end
+    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
+    if index==1 %first field
+        if ~isfield(Field,'U')||~isfield(Field,'V')
+            disp_uvmat('ERROR','this function requires the velocity components U and V as input',checkrun)
+            return
+        end
+        [npy,npx]=size(Field.U);
+        UMean=zeros(npy,npx);
+        VMean=zeros(npy,npx);
+        Counter=false(npy,npx);
+                % transcripts the global attributes
+        if isfield(Field,'ListGlobalAttribute')
+            DataOut.ListGlobalAttribute= Field.ListGlobalAttribute;
+            for ilist=1:numel(Field.ListGlobalAttribute)
+                AttrName=Field.ListGlobalAttribute{ilist};
+                DataOut.(AttrName)=Field.(AttrName);
+            end
+        end
+    end
+    FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U
+    Field.U(FF)=0;% set to 0 the nan values,
+    Field.V(FF)=0;
+    UMean=UMean+Field.U;
+    VMean=VMean+Field.V;
+    Counter=Counter+~FF;
+end
+UMean=UMean./Counter;
+VMean=VMean./Counter;
+
+
+%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+disp('loop for correlation started')
+for index=1:NbField
+    update_waitbar(WaitbarHandle,index/NbField)
+    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        break
+    end
+    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
+
+    %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
+    if index==1 %first field
+        [npy,npx]=size(Field.U);
+        npcorr=floor(npx/4); %nbre of points for the correlation fct on each side of 0
+        dx=(Field.coord_x(end)-Field.coord_x(1))/(numel(Field.coord_x)-1);
+        DataOut.delta_x=(-dx*npcorr:dx:dx*npcorr)';
+        DataOut.coord_x=Field.coord_x;
+        DataOut.coord_y=Field.coord_y;
+        DataOut.UUCorr=zeros(2*npcorr+1,npy,npx);
+        DataOut.VVCorr=zeros(2*npcorr+1,npy,npx);
+        DataOut.UVCorr=zeros(2*npcorr+1,npy,npx);
+        DataOut.Counter=zeros(2*npcorr+1,npy,npx);
+    end
+    FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U
+    Field.U(FF)=0;% set to 0 the nan values,'delta_x'
+    Field.V(FF)=0;
+    Field.U=Field.U-UMean;
+    Field.V=Field.V-VMean;
+    UUCorr=zeros(2*npcorr+1,npy,npx);
+    VVCorr=zeros(2*npcorr+1,npy,npx);
+    UVCorr=zeros(2*npcorr+1,npy,npx);
+    FFCorr=false(2*npcorr+1,npy,npx);
+    for ishift=-npcorr:npcorr% calculate the field U shifted
+        U_shift=circshift(Field.U,[0 -ishift]); %shift U by ishift along the index x
+        V_shift=circshift(Field.V,[0 -ishift]); %shift U by ishift along the index x
+        FF_shift=circshift(FF,[0 -ishift]); %shift U by ishift along the index x
+        if ishift<0
+            U_shift(:,1:-ishift)=0;
+            V_shift(:,1:-ishift)=0;
+            FF_shift(:,1:-ishift)=1;
+        elseif ishift>0
+            U_shift(:,end-ishift:end)=0;
+            V_shift(:,end-ishift:end)=0;
+            FF_shift(:,end-ishift:end)=1;
+        end
+        UUCorr(ishift+npcorr+1,:,:)=Field.U.*U_shift;
+        VVCorr(ishift+npcorr+1,:,:)=Field.V.*V_shift;
+        UVCorr(ishift+npcorr+1,:,:)=Field.U.*V_shift;
+        FFCorr(ishift+npcorr+1,:,:)=FF | FF_shift;      
+    end
+    DataOut.UUCorr=DataOut.UUCorr+UUCorr;
+    DataOut.VVCorr=DataOut.VVCorr+VVCorr;
+    DataOut.UVCorr=DataOut.UVCorr+UVCorr;
+    DataOut.Counter=DataOut.Counter+~FFCorr;
+end
+%%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
+DataOut.UUCorr=DataOut.UUCorr./DataOut.Counter;
+DataOut.VVCorr=DataOut.VVCorr./DataOut.Counter;
+DataOut.VUVCorr=DataOut.UVCorr./DataOut.Counter;
+%DataOut.Counter(DataOut.Counter==0)=1;% put counter to 1 when it is zero
+% DataOut.UMean=DataOut.UMean./DataOut.Counter; % normalize the mean
+% DataOut.VMean=DataOut.VMean./DataOut.Counter; % normalize the mean
+% U2Mean=U2Mean./DataOut.Counter; % normalize the mean
+% V2Mean=V2Mean./DataOut.Counter; % normalize the mean
+% UVMean=UVMean./DataOut.Counter; % normalize the mean
+% U2Mean_1=U2Mean_1./Counter_1; % normalize the mean
+% V2Mean_1=V2Mean_1./Counter_1; % normalize the mean
+% DataOut.u2Mean=U2Mean-DataOut.UMean.*DataOut.UMean; % normalize the meanFFCorr
+% DataOut.v2Mean=V2Mean-DataOut.VMean.*DataOut.VMean; % normalize the mean
+% DataOut.uvMean=UVMean-DataOut.UMean.*DataOut.VMean; % normalize the mean \
+% DataOut.u2Mean_1=U2Mean_1-DataOut.UMean.*DataOut.UMean; % normalize the mean
+% DataOut.v2Mean_1=V2Mean_1-DataOut.VMean.*DataOut.VMean; % normalize the mean
+
+
+%% calculate the profiles
+% npx=numel(DataOut.coord_x);
+% band=ceil(npx/5) :floor(4*npx/5);% keep only the central band
+% for ivar=3:numel(DataOut.ListVarName)-1
+%     VarName=DataOut.ListVarName{ivar};% name of the variable
+%     DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Profile']}];%append the name of the profile variable
+%     DataOut.VarDimName=[DataOut.VarDimName {'coord_y'}];
+%    DataOut.([VarName 'Profile'])=mean(DataOut.(VarName)(:,band),2); %take the mean profile of U, excluding the edges
+% end
+
+%% writing the result file as netcdf file
+OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
+ %case of netcdf input file , determine global attributes
+ errormsg=struct2nc(OutputFile,DataOut); %save result file
+ if isempty(errormsg)
+     disp([OutputFile ' written']);
+ else
+     disp(['error in writting result file: ' errormsg])
+ end
+
+
+%% open the result file with uvmat (in RUN mode)
+if checkrun
+    uvmat(OutputFile)% open the last result file with uvmat
+end
Index: /trunk/src/set_object.m
===================================================================
--- /trunk/src/set_object.m	(revision 1000)
+++ /trunk/src/set_object.m	(revision 1001)
@@ -380,22 +380,24 @@
 % set default values read in the plot of uvmat to initiate the mesh 
 if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
-            huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
+    huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
+    if ~isempty(huvmat)
         UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
-    if isempty(str2num(get(handles.num_DX,'String')))||isempty(str2num(get(handles.num_DY,'String')));     
-%         Field=UvData.Field;
-        if  isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh)
-            set(handles.num_DX,'String',num2str(UvData.Field.CoordMesh))
-            set(handles.num_DY,'String',num2str(UvData.Field.CoordMesh))
-            set(handles.num_RangeX_1,'String',num2str(UvData.Field.XMin))
-            set(handles.num_RangeX_2,'String',num2str(UvData.Field.XMax))
-            set(handles.num_RangeY_1,'String',num2str(UvData.Field.YMin))
-            set(handles.num_RangeY_2,'String',num2str(UvData.Field.YMax))
-        end
-        if isempty(get(handles.CoordUnit,'String'))&& isfield(UvData.Field,'CoordUnit')
-            set(handles.CoordUnit,'String',UvData.Field.CoordUnit)
-        end       
+        if isempty(str2num(get(handles.num_DX,'String')))||isempty(str2num(get(handles.num_DY,'String')));
+            %         Field=UvData.Field;
+            if  isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh)
+                set(handles.num_DX,'String',num2str(UvData.Field.CoordMesh))
+                set(handles.num_DY,'String',num2str(UvData.Field.CoordMesh))
+                set(handles.num_RangeX_1,'String',num2str(UvData.Field.XMin))
+                set(handles.num_RangeX_2,'String',num2str(UvData.Field.XMax))
+                set(handles.num_RangeY_1,'String',num2str(UvData.Field.YMin))
+                set(handles.num_RangeY_2,'String',num2str(UvData.Field.YMax))
+            end
+            if isempty(get(handles.CoordUnit,'String'))&& isfield(UvData.Field,'CoordUnit')
+                set(handles.CoordUnit,'String',UvData.Field.CoordUnit)
+            end
+        end
     end
     if isempty(str2num(get(handles.num_RangeInterp,'String'))) && isfield(UvData,'Field')
-     set(handles.num_RangeInterp,'String',num2str(3*UvData.Field.CoordMesh))% default interpolationlength= 3 meshes
+        set(handles.num_RangeInterp,'String',num2str(3*UvData.Field.CoordMesh))% default interpolationlength= 3 meshes
     end
 end
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1000)
+++ /trunk/src/uvmat.m	(revision 1001)
@@ -422,7 +422,7 @@
 %% reset position and scale of axis
 pos(1)=0.2*size_fig(3)+35;
-pos(2)=35;
+pos(2)=50;
 pos(3)=0.77*size_fig(3)-1.2*ColumnWidth;
-pos(4)=size_fig(4)-60;
+pos(4)=size_fig(4)-100;
 set(handles.PlotAxes,'Units','pixels')
 set(handles.PlotAxes,'Position',pos)
