Index: /trunk/src/phys_ima.m
===================================================================
--- /trunk/src/phys_ima.m	(revision 1128)
+++ /trunk/src/phys_ima.m	(revision 1129)
@@ -11,6 +11,6 @@
 % XmlData: cell array of structures defining the calibration parameters for each image
 % ZIndex: index of the reference plane used to define the phys position in 3D
-
-function [A_out,Rangx,Rangy]=phys_ima(A,XmlData,ZIndex)
+% resolution_factor: factor to control the number of pixels of the new image, default value =1 : same nbre of pixels as the original
+function [A_out,Rangx,Rangy]=phys_ima(A,XmlData,ZIndex,resolution_factor)
 xcorner=[];
 ycorner=[];
@@ -21,4 +21,7 @@
 if isstruct(XmlData)
     XmlData={XmlData};
+end
+if ~exist('resolution_factor','var')
+resolution_factor=1;
 end
 
@@ -50,6 +53,6 @@
 test_multi=(max(npx)~=min(npx)) || (max(npy)~=min(npy)); %different image lengths
 
-npX=1+round((Rangx(2)-Rangx(1))/max(dx));% nbre of pixels in the new image (use the largest resolution max(dx) in the set of images)
-npY=1+round((Rangy(1)-Rangy(2))/max(dy));
+npX=1+round(resolution_factor*(Rangx(2)-Rangx(1))/max(dx));% nbre of pixels in the new image (use the largest resolution max(dx) in the set of images)
+npY=1+round(resolution_factor*(Rangy(1)-Rangy(2))/max(dy));
 
 x=linspace(Rangx(1),Rangx(2),npX);
Index: /trunk/src/series/aver_stat.m
===================================================================
--- /trunk/src/series/aver_stat.m	(revision 1128)
+++ /trunk/src/series/aver_stat.m	(revision 1129)
@@ -298,4 +298,5 @@
         for iview=1:NbView
             % reading input file(s)
+            filecell{iview,index}
             [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
             if ~isempty(errormsg)
@@ -469,5 +470,7 @@
     
     %% writing the result file
-    OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
+    RootPathOut=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+    OutputDir=[Param.OutputSubDir Param.OutputDirExt];
+    OutputFile=fullfile_uvmat(RootPathOut,OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
     if strcmp(FileExtOut,'.png') %case of images
         if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
Index: /trunk/src/series/extract_multitif.m
===================================================================
--- /trunk/src/series/extract_multitif.m	(revision 1128)
+++ /trunk/src/series/extract_multitif.m	(revision 1129)
@@ -1,5 +1,18 @@
 %'extract_multitif': read image series from PCO cameras (tiff image series) and write .png images
-%------------------------------------------------------------------------
-    
+% use a single geometric calibration, with information on the slice positions in case of 3D scanning
+%------------------------------------------------------
+% the output file indexing is based on the xml file requested by the
+% function when it is selected (or possibly inserted in this function in the section TEST)
+%  This xml file must contain the following information:
+%   NbDti: the number of 'bursts' -1
+%   NbDtj: number of frames in each burst-1, or number of repetition of a burst sequence defined by Dtj
+%   NbDtk: number of repetitions of a slice scanning process -1 (ignored by default)
+% Therefore the total number of frames is  (NbDti+1)*(NbDtj+1)*(NbDtk+1)
+% The frame series is stored in a single folder with two indices i:(NbDti+1)*(NbDtk+1) 
+%
+% To run the function in the cluster in parallel for each multitif file, indicate nb-slice_i equal to the
+% number input multitif files
+
+
 % function ParamOut=extract_multitif(Param)
 %
Index: /trunk/src/series/extract_multitif_multislice.m
===================================================================
--- /trunk/src/series/extract_multitif_multislice.m	(revision 1129)
+++ /trunk/src/series/extract_multitif_multislice.m	(revision 1129)
@@ -0,0 +1,225 @@
+%'extract_multitif_multiplane': read image series from PCO cameras (tiff image series) and write .png images
+% case of multislice views with a distinct geometric calibration for each slice
+%------------------------------------------------------
+% the output file indexing is based on the xml file requested by the
+% function when it is selected (or possibly inserted in this function in the section TEST)
+%  This xml file must contain the following information:
+%   NbDti: the number of slices -1
+%   NbDtj: number of frames in each slice -1
+%   NbDtk: number of repetitions of the slice scanning process -1
+% Therefore the total number of frames is  (NbDti+1)*(NbDtj+1)*(NbDtk+1)
+% The frame series in each slice is stored in a separate folder labeled by_i, i=1:NbDti+1, 
+% an xml file with the same name must be created with the appropiate geometric calibration and  time interval Dti between
+% successive image names in each folder are labeled as _1k_1,_1k_2...._2k_1,_2k_2,...
+%
+% To run the function in the cluster in parallel for each multitif file, indicate nb-slice_i equal to the
+% number input multitif files
+
+%------------------------------------------------------------------------
+    
+% function ParamOut=extract_multitif_multiplane(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-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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=extract_multitif(Param)
+
+%%%%%%%%%%%%%%%%%    INPUT PREPARATION MODE (no RUN)    %%%%%%%%%%%%%%%%%
+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='on';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='on'; % impose calculation in a single process (no parallel processing to avoid 'holes'))
+    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'off';%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='.png';%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
+    ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
+    ParamOut.CPUTime=10;% expected time for writting the output of one source image ( in minute)
+    %% root input file(s) and type
+    % check the existence of the first file in the series
+        first_j=[];% note that the function will propose to cover the whole range of indices
+    if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end
+    last_j=[];
+    if isfield(Param.IndexRange,'MaxIndex_j'); last_j=Param.IndexRange.MaxIndex_j; end
+    PairString='';
+    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
+    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
+    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
+        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
+    if ~exist(FirstFileName,'file')
+        msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
+    end
+
+    %% check the validity of  input file types
+    FileInfo=get_file_info(FirstFileName);
+    if ~strcmp(FileInfo.FileType,'multimage')
+        msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not an image'])
+        return
+    end
+    ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml');  
+    return
+end
+%%%%%%%%%%%%%%%%%    STOP HERE FOR PAMETER INPUT MODE   %%%%%%%%%%%%%%%%% 
+
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
+RUNHandle=[];
+WaitbarHandle=[];
+if ischar(Param)
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+else
+    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
+end
+
+%% Timing
+XmlInputFile=Param.ActionInput.XmlFile;
+[XmlInput,errormsg]=imadoc2struct(XmlInputFile,'Camera');
+if ~isempty(errormsg)
+    disp(['bad xml input file: ' errormsg])
+    return
+end
+ImagesPerLevel=size(XmlInput.Time,2)-1;%100;%use the xmlinformation to get the nbre of j indices
+
+%% output directory
+Nbre_level=XmlInput.Camera.BurstTiming.NbDti+1;
+for idir=1:Nbre_level
+OutputDir{idir}=fullfile(Param.InputTable{1,1},[Param.OutputSubDir '_' num2str(idir) Param.OutputDirExt]);
+if ~exist(OutputDir{idir},'dir')
+    mkdir(OutputDir{idir})
+end
+end
+
+%% create the xml file for timing if it does not exist : example to adapt
+TEST=0;
+if TEST
+    count0=14;
+    Dtj=0.05;% time interval between frames
+    ImagesPerLevel=455;% total number of images per position, ImagesPerLevel-Nbj images skiiped during motion between two positions
+    Nbj=390; %Nbre of images kept at a given position
+    Dti=Dtj*ImagesPerLevel;
+    NbLevel=11;
+    NbScan=3;
+    TimeReturn=268.5; %time needed to return back to the first position (in sec)
+    NbReturn=round(TimeReturn/Dtj);
+    NbSkipReturn=NbReturn+1-NbLevel*ImagesPerLevel;
+    
+    Newxml=fullfile(Param.InputTable{1,1},[Param.InputTable{1,2} '.xml']);
+    if ~exist(Newxml,'file')
+        XmlInput.Camera.CameraName='PCO';
+        XmlInput.Camera.TimeUnit='s';
+        XmlInput.Camera.BurstTiming.FrameFrequency=1;
+        XmlInput.Camera.BurstTiming.Time=0;% for 200
+        XmlInput.Camera.BurstTiming.Dtj=Dtj;
+        XmlInput.Camera.BurstTiming.NbDtj=Nbj-1;
+        XmlInput.Camera.BurstTiming.Dti=Dti;
+        XmlInput.Camera.BurstTiming.NbDti=NbLevel-1;
+        XmlInput.Camera.BurstTiming.Dtk=TimeReturn;
+        XmlInput.Camera.BurstTiming.NbDtk=NbScan-1;
+        t=struct2xml(XmlInput);
+        t=set(t,1,'name','ImaDoc');
+        save(t,Newxml);
+    end
+end
+
+%% loop on the files
+% include the first tiff file with no index in the first iteration
+if Param.IndexRange.first_i==1% first slice of processing
+    firstindex=0;% to read the first multitif with no number
+   count=0;
+else
+    firstindex=Param.IndexRange.first_i;
+    ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif');
+    NbFrames=numel(imfinfo(ImageName));%nbre of frames in each multitif image
+   count=Param.IndexRange.first_i*NbFrames;
+end
+for ifile=firstindex:Param.IndexRange.last_i
+    tic
+    if firstindex==0 && ifile==0% first slice of processing
+        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif')
+    else
+        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},['im@' num2str(ifile,'%04d') '.tif'])
+    end
+    NbFrames=numel(imfinfo(ImageName));% nbre of frames in each multitif file
+    for iframe=1:NbFrames
+        if isequal(ImagesPerLevel,1)% mode series
+            OutputFile=fullfile(OutputDir,['img_' num2str(count+1) '.png']);
+        else % indices i and j
+            i_index=fix(count/ImagesPerLevel)+1;
+            dir_index=mod(i_index-1,XmlInput.Camera.BurstTiming.NbDti+1)+1;
+            inew=floor((i_index-1)/(XmlInput.Camera.BurstTiming.NbDti+1))+1;
+            j_index=mod(count,ImagesPerLevel)+1;
+            OutputFile=fullfile(OutputDir{dir_index},['img_' num2str(inew) 'k_' num2str(j_index) '.png']);
+        end
+        if Param.CheckOverwrite ||~exist(OutputFile,'file')
+           A=imread(ImageName,iframe);
+           imwrite(A,OutputFile,'BitDepth',16);
+            disp([OutputFile ' written'])
+        else
+            disp([OutputFile ' already exists'])
+        end
+        count=count+1;
+    end
+    tt=toc;
+    disp(['elapsed time (in min.) for the file im@' num2str(ifile,'%04d')])
+    disp(num2str(tt/60))
+end
+
+
+
Index: /trunk/src/series/stereo_input.m
===================================================================
--- /trunk/src/series/stereo_input.m	(revision 1128)
+++ /trunk/src/series/stereo_input.m	(revision 1129)
@@ -243,5 +243,5 @@
 %show the reference image edit box if relevant (not needed for movies or in the absence of time information
 if numel(time)>=2 % if there are at least two time values to define dt
-    if size(time,1)<MaxIndex_i;
+    if size(time,1)<MaxIndex_i
         msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
     elseif size(time,2)<MaxIndex_j
@@ -2974,2 +2974,25 @@
 
 % Hint: get(hObject,'Value') returns toggle state of CheckLSM
+
+
+
+function num_resolution_Callback(hObject, eventdata, handles)
+% hObject    handle to num_resolution (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+
+% Hints: get(hObject,'String') returns contents of num_resolution as text
+%        str2double(get(hObject,'String')) returns contents of num_resolution as a double
+
+
+% --- Executes during object creation, after setting all properties.
+function num_resolution_CreateFcn(hObject, eventdata, handles)
+% hObject    handle to num_resolution (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+%       See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+    set(hObject,'BackgroundColor','white');
+end
Index: /trunk/src/series/turb_stat.m
===================================================================
--- /trunk/src/series/turb_stat.m	(revision 1128)
+++ /trunk/src/series/turb_stat.m	(revision 1129)
@@ -1,3 +1,3 @@
-%'aver_stat': calculate Reynolds steress components over time series
+%'aver_stat': calculate Reynolds stress components over time series
 %------------------------------------------------------------------------
 % function ParamOut=turb_stat(Param)
@@ -89,7 +89,4 @@
 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
@@ -201,9 +198,15 @@
 Counter_1=0;
 
+if Param.IndexRange.NbSlice==1
+    interval=Param.IndexRange.incr_i% statistics is done taking into account the input index increment
+else
+    interval=Param.IndexRange.NbSlice;% statistics is done slice by slice without taking into account the input index increment
+end
+
 %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
-% for i_slice=1:Param.IndexRange.NbSlice
-%     i_slice
+for i_slice=1:Param.IndexRange.NbSlice
+    i_slice
     ind_first=Param.IndexRange.first_i;
-    for index_i=ind_first:Param.IndexRange.NbSlice:Param.IndexRange.last_i
+    for index_i=ind_first:interval:Param.IndexRange.last_i
         if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
             disp('program stopped by user')
@@ -211,8 +214,6 @@
         end
         for index_j=first_j:last_j
-            InputFile=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},index_i,index_i,index_j,index_j);
-            [Field,tild,errormsg] = read_field(InputFile,FileType{iview},InputFields{iview});
-            
-            %[Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
+            InputFile=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},index_i,index_i,index_j,index_j)
+            [Field,tild,errormsg] = read_field(InputFile,FileType{iview},InputFields{iview});       
             
             %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
@@ -289,5 +290,7 @@
     
     %% writing the result file as netcdf file
-    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,ind_first,ind_first,first_j,last_j);
+    RootPathOut=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+    OutputDir=[Param.OutputSubDir Param.OutputDirExt];
+    OutputFile=fullfile_uvmat(RootPathOut,OutputDir,RootFile{1},FileExtOut,NomTypeOut,ind_first,ind_first,first_j,last_j);
     %case of netcdf input file , determine global attributes
     errormsg=struct2nc(OutputFile,DataOut); %save result file
@@ -296,7 +299,7 @@
     else
         disp(['error in writting result file: ' errormsg])
-    end
-    
-% end
+    end    
+end
+
 %% open the result file with uvmat (in RUN mode)
 if checkrun && isequal(Param.IndexRange.NbSlice,1)
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1128)
+++ /trunk/src/uvmat.m	(revision 1129)
@@ -1657,8 +1657,8 @@
 
 %% rescale the image
-[nby,nbx]=size(UvData.Field.A);
-x=linspace(UvData.Field.Coord_x(1),UvData.Field.Coord_x(2),nbx)-nbx/2;
-y=linspace(UvData.Field.Coord_y(1),UvData.Field.Coord_y(2),nby)-nby/2;
-[X,Y]=meshgrid(x,y);
+% [nby,nbx]=size(UvData.Field.A);
+% x=linspace(UvData.Field.Coord_x(1),UvData.Field.Coord_x(2),nbx)-nbx/2;
+% y=linspace(UvData.Field.Coord_y(1),UvData.Field.Coord_y(2),nby)-nby/2;
+% [X,Y]=meshgrid(x,y);
 %coeff_quad=0.15*4/(nbx*nbx);% image luminosity reduced by 10% at the edge
 %UvData.Field.A=double(UvData.Field.A).*(1+coeff_quad*(X.*X+Y.*Y));
@@ -1686,7 +1686,8 @@
     ylabel('radius from light source')
     title('ref line in polar coordinates')
-    azimuth_ima=linspace(DataPol.Coord_y(1),DataPol.Coord_y(2),size(DataPol.A,1))-360;%array of angular indices on the transformed image
-    dist_source = interp1(theta_ref,r_ref,azimuth_ima);% get the polar position of the reference line
-    dist_source_pixel=round(size(DataPol.A,2)*(dist_source-DataPol.Coord_x(1))/(DataPol.Coord_x(2)-DataPol.Coord_x(1)));
+    %azimuth_ima=linspace(DataPol.Coord_y(1),DataPol.Coord_y(2),size(DataPol.A,1));%array of angular indices on the transformed image
+   % dist_source = interp1(theta_ref,r_ref,azimuth_ima);% get the polar position of the reference line
+    dist_source = interp1(theta_ref,r_ref,DataPol.theta);% get the polar position of the reference line
+    dist_source_pixel=floor(size(DataPol.A,2)*(dist_source-DataPol.radius(1))/(DataPol.radius(end)-DataPol.radius(1)))+1;
     line_nan= isnan(dist_source);
     dist_source_pixel(line_nan)=1;
@@ -1710,9 +1711,9 @@
 %% get the image A*r
 [npy,npx]=size(Anorm);
-AX=DataPol.Coord_x;
-AY=DataPol.Coord_y;
-dX=(AX(2)-AX(1))/(npx-1);
-dY=(AY(1)-AY(2))/(npy-1);%mesh of new pixels
-[R,Theta]=meshgrid(linspace(AX(1),AX(2),npx),linspace(AY(1),AY(2),npy));
+AX=DataPol.radius;
+AY=DataPol.theta;
+% dX=(AX(2)-AX(1))/(npx-1);
+% dY=(AY(1)-AY(2))/(npy-1);%mesh of new pixels
+[R,Theta]=meshgrid(linspace(AX(1),AX(end),npx),linspace(AY(1),AY(end),npy));%matrix of radius and angles with the same size as DataPol
 A=R.*Anorm;
 A=(A<=0).*ones(npy,npx)+(A>0).*A; %replaces zeros by ones
@@ -1734,4 +1735,6 @@
 gamma_coeff=NaN(1,npy);
 fitlength=NaN(1,npy);
+%[ThetaMask,RMask] = cart2pol(MaskData.Coord(:,1)-x0,MaskData.Coord(:,2)-y0);
+%ThetaMask=ThetaMask*180/pi
 for iY=1:npy% loop on the y index of the image in polar coordinate
     ALine=A(iY,:);%profile of image luminosity log (vs radial index)
@@ -1752,6 +1755,13 @@
     p = polyfit(RLine,ALine,1);
     gamma_coeff(iY)=-p(1);
-    fitlength(iY)=numel(find(check_good));
-end
+   fitlength(iY)=numel(find(check_good));
+end
+
+%% plot the decay coef versus theta
+figure(13)
+plot(Theta(:,1),100*gamma_coeff)
+xlabel('angle(degree)')
+ylabel('decay coeff(m-1)')
+
 
 %% show and store the rescaled image
@@ -1760,8 +1770,5 @@
 view_field(DataPol);
 imwrite(DataPol.A,NewImageName,'BitDepth',16)
-figure(13)
-plot(Theta(:,1),100*gamma_coeff)
-xlabel('angle(degree)')
-ylabel('decay coeff(m-1)')
+
 
 %% keep the average of gamma_coeff
