Index: trunk/src/series/merge_proj.m
===================================================================
--- trunk/src/series/merge_proj.m	(revision 605)
+++ trunk/src/series/merge_proj.m	(revision 606)
@@ -41,14 +41,15 @@
 function ParamOut=merge_proj(Param)
 
-%% set the input elements needed on the GUI series when the function is selected in the menu ActionName
+%% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
 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='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='on';...%can use projection object(option 'off'/'on',
-    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
+    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='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.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
+    ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
+    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
     ParamOut.OutputDirExt='.mproj';%set the output dir extension
     ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
@@ -57,12 +58,10 @@
         msgbox_uvmat('WARNING','the first input file does not exist')
     elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject')
-         msgbox_uvmat('WARNING','a projection object of type plane needs to be introduced for merge_proj')
-    end
-return
+        msgbox_uvmat('WARNING','a projection object of type plane needs to be introduced for merge_proj')
+    end
+    return
 end
 
 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-
-
 %% read input parameters from an xml file if input is a file name (batch mode)
 checkrun=1;
@@ -72,9 +71,9 @@
 end
 
-ParamOut=Param; %default output
+ParamOut=[] %default output
 if ~isfield(Param,'InputFields')
     Param.InputFields.FieldName='';
 end
-OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
 
 %% root input file type
@@ -93,19 +92,17 @@
 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
 %%%%%%%%%%%%
-NbSlice=1;%default
-if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
-    NbSlice=Param.IndexRange.NbSlice;
-end
-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
-nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
-nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
+% NbSlice=1;%default
+% if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
+%     NbSlice=Param.IndexRange.NbSlice;
+% end
+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'};
 NcTypeOptions={'netcdf','civx','civdata'};
-for iview=1:nbview
+for iview=1:NbView
     if ~exist(filecell{iview,1}','file')
         displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
@@ -122,5 +119,4 @@
 end
 
-
 %% calibration data and timing: read the ImaDoc files
 [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
@@ -133,11 +129,23 @@
 
 %% coordinate transform or other user defined transform
-transform_fct='';%default
+% transform_fct='';%default fct handle
+% if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
+%     if isdeployed
+%         transform_fct=Param.FieldTransform.TransformName;
+%         dd=phys([]);%activate phys for compilation
+%     else
+%         currentdir=pwd;
+%         cd(Param.FieldTransform.TransformPath)
+%         transform_fct=str2func(Param.FieldTransform.TransformName);
+%         cd (currentdir)
+%     end
+% end
+transform_fct='';%default fct handle
 if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
-    addpath(Param.FieldTransform.TransformPath)
-    transform_fct=str2func(Param.FieldTransform.TransformName);
-    rmpath(Param.FieldTransform.TransformPath)
-end
-
+        currentdir=pwd;
+        cd(Param.FieldTransform.TransformPath)
+        transform_fct=str2func(Param.FieldTransform.TransformName);
+        cd (currentdir)
+end
 %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
  % EDIT FROM HERE
@@ -152,5 +160,5 @@
     return
 end
-for iview=1:nbview
+for iview=1:NbView
 	if ~isequal(CheckImage{iview},CheckImage{1})||~isequal(CheckNc{iview},CheckNc{1})
         displ_uvmat('ERROR','input set of input series: need  either netcdf either image series',checkrun)
@@ -169,175 +177,175 @@
 %% MAIN LOOP ON SLICES
 %%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-for i_slice=1:NbSlice
-    index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
-    nbfiles=0;
-    nbmissing=0;
+% for i_slice=1:NbSlice
+%     index_slice=i_slice:NbSlice:NbField;% select file indices of the slice
+%     NbFiles=0;
+%     nbmissing=0;
 
     %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
-    for index=index_slice
-        if checkrun
-            stopstate=get(Param.RUNHandle,'BusyAction');
-            update_waitbar(Param.WaitbarHandle,index/nbfield)
-        else
-            stopstate='queue';
-        end
-        if ~isequal(stopstate,'queue')% enable STOP command
-            return
-        end
-        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
-        Data=cell(1,nbview);%initiate the set Data
-        nbtime=0;
-        for iview=1:nbview
-            %% reading input file(s)
-            [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
+for index=1:NbField
+    if checkrun
+        stopstate=get(Param.RUNHandle,'BusyAction');
+        update_waitbar(Param.WaitbarHandle,index/NbField)
+    else
+        stopstate='queue';
+    end
+    if ~isequal(stopstate,'queue')% enable STOP command
+        return
+    end
+    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
+    Data=cell(1,NbView);%initiate the set Data
+    nbtime=0;
+    for iview=1:NbView
+        %% reading input file(s)
+        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
+        if ~isempty(errormsg)
+            errormsg=['merge_proj/read_field/' errormsg];
+            display(errormsg)
+            break
+        end
+        timeread(iview)=0;
+        if isfield(Data{iview},'Time')
+            timeread(iview)=Data{iview}.Time;
+            nbtime=nbtime+1;
+        end
+        if ~isempty(NbSlice_calib)
+            Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
+        end
+
+        %% transform the input field (e.g; phys) if requested
+        if ~isempty(transform_fct)
+            if nargin(transform_fct)>=2
+                Data{iview}=transform_fct(Data{iview},XmlData{iview});
+            else
+                Data{iview}=transform_fct(Data{iview});
+            end
+        end
+%          Data{iview}=phys(Data{iview},XmlData{iview});
+        %% check whether tps is needed, then calculate tps coefficients if needed
+        check_tps=0;
+        if isfield(Param.InputFields,'FieldName')
+            if ischar(Param.InputFields.FieldName)
+                Param.InputFields.FieldName={Param.InputFields.FieldName};
+            end
+        else
+            Param.InputFields.FieldName={};
+        end
+        for ilist=1:numel(Param.InputFields.FieldName)
+            switch Param.InputFields.FieldName{ilist}
+                case {'vort','div','strain'}
+                    check_tps=1;
+            end
+        end
+
+        %% calculate tps coeff if needed
+        check_proj_tps= ~isempty(Param.ProjObject)&& strcmp(Param.ProjObject.ProjMode,'filter')&&~isfield(Data{iview},'Coord_tps');
+        Data{iview}=tps_coeff_field(Data{iview},check_proj_tps);
+
+        %% projection on object (gridded plane)
+        if Param.CheckObject
+            [Data{iview},errormsg]=proj_field(Data{iview},Param.ProjObject);
             if ~isempty(errormsg)
-                errormsg=['merge_proj/read_field/' errormsg];
-                display(errormsg)
-                break
-            end
-            timeread(iview)=0;
-            if isfield(Data{iview},'Time')
-                    timeread(iview)=Data{iview}.Time;
-                    nbtime=nbtime+1;
-                end
-            if ~isempty(NbSlice_calib)
-                Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
-            end
-            
-            %% transform the input field (e.g; phys) if requested
-            if ~isempty(transform_fct)
-                if nargin(transform_fct)>=2
-                    Data{iview}=transform_fct(Data{iview},XmlData{iview});
-                else
-                    Data{iview}=transform_fct(Data{iview});
-                end
-            end
-            
-            %% check whether tps is needed, then calculate tps coefficients if needed
-            check_tps=0;
-            if isfield(Param.InputFields,'FieldName')
-                if ischar(Param.InputFields.FieldName)
-                    Param.InputFields.FieldName={Param.InputFields.FieldName};
-                end
-            else
-                Param.InputFields.FieldName={};
-            end
-            for ilist=1:numel(Param.InputFields.FieldName)
-                switch Param.InputFields.FieldName{ilist}
-                    case {'vort','div','strain'}
-                        check_tps=1;
-                end
-            end
-                
-            %% calculate tps coeff if needed
-             check_proj_tps= ~isempty(Param.ProjObject)&& strcmp(Param.ProjObject.ProjMode,'filter')&&~isfield(Data{iview},'Coord_tps');
-            Data{iview}=tps_coeff_field(Data{iview},check_proj_tps);
-
-            %% projection on object (gridded plane)
-            if Param.CheckObject
-                [Data{iview},errormsg]=proj_field(Data{iview},Param.ProjObject);
-                if ~isempty(errormsg)
-                    displ_uvmat('ERROR',['error in merge_proge/proj_field: ' errormsg],checkrun)
-                    return
-                end
-            end
-        end
-        %----------END LOOP ON VIEWS----------------------
-        
-        %% merge the nbview fields
-        MergeData=merge_field(Data);
-        if isfield(MergeData,'Txt')
-            displ_uvmat('ERROR',MergeData.Txt,checkrun)
-            return
-        end
-        
-        % time of the merged field:
-        if ~isempty(time)% time defined from ImaDoc
-            timeread=time(:,index);
-        end
-        timeread=mean(timeread);
-        
-        % generating the name of the merged field
-        i1=i1_series{iview}(index);
-        if ~isempty(i2_series{iview})
-            i2=i2_series{iview}(index);
-        else
-            i2=i1;
-        end
-        j1=1;
-        j2=1;
-        if ~isempty(j1_series{iview})
-            j1=j1_series{iview}(index);
-            if ~isempty(j2_series{iview})
-                j2=j2_series{iview}(index);
-            else
-                j2=j1;
-            end
-        end
-        OutputFile=fullfile_uvmat(RootPath{1},OutputSubDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
-        
-        % recording the merged field
-        if CheckImage{1}    %in case of input images an image is produced
-            if isa(MergeData.A,'uint8')
-                bitdepth=8;
-            elseif isa(MergeData.A,'uint16')
-                bitdepth=16;
-            end
-            imwrite(MergeData.A,OutputFile,'BitDepth',bitdepth);
-            %write xml calibration file
-            siz=size(MergeData.A);
-            npy=siz(1);
-            npx=siz(2);
-            if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
-                Rangx=MergeData.VarAttribute{1}.Coord_2;
-                Rangy=MergeData.VarAttribute{1}.Coord_1;
-            elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
-                Rangx=[MergeData.AX(1) MergeData.AX(end)];
-                Rangy=[MergeData.AY(1) MergeData.AY(end)];
-            else
-                Rangx=[0.5 npx-0.5];
-                Rangy=[npy-0.5 0.5];%default
-            end
-            pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
-            pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
-            T_x=-pxcmx*Rangx(1)+0.5;
-            T_y=-pxcmy*Rangy(2)+0.5;
-            GeometryCal.focal=1;
-            GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
-            GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
-            ImaDoc.GeometryCalib=GeometryCal;
-%             t=struct2xml(ImaDoc);
-%             t=set(t,1,'name','ImaDoc');
-%             save(t,[filebase_merge '.xml'])
-%             display([filebase_merge '.xml saved'])
-        else
-            MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};
-            MergeData.Conventions='uvmat';
-            MergeData.nb_coord=2;
-            MergeData.nb_dim=2;
-            dt=[];
-            if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt)
-                dt=Data{1}.dt;
-            end
-            for iview =2:numel(Data)
-                if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt))
-                    dt=[];%dt not the same for all fields
-                end
-            end
-            if isempty(dt)
-                MergeData.ListGlobalAttribute(6)=[];
-            else
-                MergeData.dt=dt;
-            end
-            MergeData.Time=timeread;
-            error=struct2nc(OutputFile,MergeData);%save result file
-            if isempty(error)
-                display(['output file ' OutputFile ' written'])
-            else
-                display(error)
-            end
-        end
-    end
-end
+                displ_uvmat('ERROR',['error in merge_proge/proj_field: ' errormsg],checkrun)
+                return
+            end
+        end
+    end
+    %----------END LOOP ON VIEWS----------------------
+
+    %% merge the NbView fields
+    MergeData=merge_field(Data);
+    if isfield(MergeData,'Txt')
+        displ_uvmat('ERROR',MergeData.Txt,checkrun)
+        return
+    end
+
+    % time of the merged field:
+    if ~isempty(time)% time defined from ImaDoc
+        timeread=time(:,index);
+    end
+    timeread=mean(timeread);
+
+    % generating the name of the merged field
+    i1=i1_series{iview}(index);
+    if ~isempty(i2_series{iview})
+        i2=i2_series{iview}(index);
+    else
+        i2=i1;
+    end
+    j1=1;
+    j2=1;
+    if ~isempty(j1_series{iview})
+        j1=j1_series{iview}(index);
+        if ~isempty(j2_series{iview})
+            j2=j2_series{iview}(index);
+        else
+            j2=j1;
+        end
+    end
+    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
+
+    % recording the merged field
+    if CheckImage{1}    %in case of input images an image is produced
+        if isa(MergeData.A,'uint8')
+            bitdepth=8;
+        elseif isa(MergeData.A,'uint16')
+            bitdepth=16;
+        end
+        imwrite(MergeData.A,OutputFile,'BitDepth',bitdepth);
+        %write xml calibration file
+        siz=size(MergeData.A);
+        npy=siz(1);
+        npx=siz(2);
+        if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
+            Rangx=MergeData.VarAttribute{1}.Coord_2;
+            Rangy=MergeData.VarAttribute{1}.Coord_1;
+        elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
+            Rangx=[MergeData.AX(1) MergeData.AX(end)];
+            Rangy=[MergeData.AY(1) MergeData.AY(end)];
+        else
+            Rangx=[0.5 npx-0.5];
+            Rangy=[npy-0.5 0.5];%default
+        end
+        pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
+        pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
+        T_x=-pxcmx*Rangx(1)+0.5;
+        T_y=-pxcmy*Rangy(2)+0.5;
+        GeometryCal.focal=1;
+        GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
+        GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
+        ImaDoc.GeometryCalib=GeometryCal;
+        %             t=struct2xml(ImaDoc);
+        %             t=set(t,1,'name','ImaDoc');
+        %             save(t,[filebase_merge '.xml'])
+        %             display([filebase_merge '.xml saved'])
+    else
+        MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};
+        MergeData.Conventions='uvmat';
+        MergeData.nb_coord=2;
+        MergeData.nb_dim=2;
+        dt=[];
+        if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt)
+            dt=Data{1}.dt;
+        end
+        for iview =2:numel(Data)
+            if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt))
+                dt=[];%dt not the same for all fields
+            end
+        end
+        if isempty(dt)
+            MergeData.ListGlobalAttribute(6)=[];
+        else
+            MergeData.dt=dt;
+        end
+        MergeData.Time=timeread;
+        error=struct2nc(OutputFile,MergeData);%save result file
+        if isempty(error)
+            display(['output file ' OutputFile ' written'])
+        else
+            display(error)
+        end
+    end
+end
+
 
 %'merge_field': concatene fields
@@ -351,6 +359,6 @@
 MergeData=Data{1};%default
 error=0;
-nbview=length(Data);
-if nbview==1
+NbView=length(Data);
+if NbView==1
     return
 end
@@ -382,5 +390,5 @@
         for ivar=VarIndex
             VarName=MergeData.ListVarName{ivar};
-            for iview=1:nbview
+            for iview=1:NbView
                 MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
             end
@@ -389,5 +397,5 @@
     else  
         testFF=0;
-        for iview=2:nbview
+        for iview=2:NbView
             for ivar=VarIndex
                 VarName=MergeData.ListVarName{ivar};
@@ -401,5 +409,5 @@
         end
         if testFF
-            nbaver=nbview-MergeData.FF;
+            nbaver=NbView-MergeData.FF;
             indgood=find(nbaver>0);
             for ivar=VarIndex
@@ -410,5 +418,5 @@
             for ivar=VarIndex
                 VarName=MergeData.ListVarName{ivar};
-                MergeData.(VarName)=double(MergeData.(VarName))./nbview;
+                MergeData.(VarName)=double(MergeData.(VarName))./NbView;
             end    
         end
