Index: trunk/src/series/civ_input.m
===================================================================
--- trunk/src/series/civ_input.m	(revision 1195)
+++ trunk/src/series/civ_input.m	(revision 1196)
@@ -186,5 +186,5 @@
 % CoordUnit='';%default
 % pxcm_search=1;
-if isfield(SeriesData,'Time') &&numel(SeriesData.Time')>=1 && ~isempty(SeriesData.Time{1})
+if isfield(SeriesData,'Time') && numel(SeriesData.Time')>=1 && ~isempty(SeriesData.Time{1})
     time=SeriesData.Time{1};
 end
@@ -192,13 +192,4 @@
     TimeUnit=Param.IndexRange.TimeUnit;
 end 
-% if isfield(SeriesData,'GeometryCalib')
-%     tsai=SeriesData.GeometryCalib;
-%     if isfield(tsai,'fx_fy')
-%         pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
-%     end
-%     if isfield(tsai,'CoordUnit')
-%         CoordUnit=tsai.CoordUnit;
-%     end
-% end
 
 %% timing display
@@ -249,4 +240,9 @@
         set(handles.(ListOptions{index}),'value',0)
         fill_civ_input(Data,handles); %fill civ_input with the parameters retrieved from an input Civ file
+        if index<=3
+        set(handles.(ListOptions{index}),'Visible','off')
+        PanelTag=regexprep(ListOptions{index},'Check','')
+        set(handles.(PanelTag),'Visible','off')
+        end
     end
     if isempty(FileInfo)
@@ -259,10 +255,7 @@
             set(handles.(ListOptions{index}),'String',regexprep(ListOptions{index},'Check','redo '))
         end
-%         for index = ind_opening+1:6
-%             set(handles.(ListOptions{index}),'value',1)
-%         end
         set(handles.CheckCiv3,'Visible','off')% make visible the switch 'iterate/repet' for Civ2.
-        set(handles.CheckCiv3,'Value',0)% select'iterate/repet' by default
-    else
+        %set(handles.CheckCiv3,'Value',0)% select'iterate/repet' by default
+    else %civ3 proposed
         for index = 1:3
             set(handles.(ListOptions{index}),'value',0)
@@ -273,4 +266,5 @@
         set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
         set(handles.CheckCiv3,'Value',1)% select'iterate/repet' by default
+        set(handles.CheckCiv3,'String',{'civ3'})% select'iterate/repet' by default
     end
     checkrefresh=1;
@@ -631,9 +625,6 @@
 for ilist=1:length(options)
     if checkbox(ilist)
-%          set(handles.(options{ilist}),'Visible','on')
         set(handles.(options{ilist}),'Enable','on')
-%         set(handles.(['Check' options{ilist}]),'Strin
     else
-%         set(handles.(options{ilist}),'Visible','off')
         set(handles.(options{ilist}),'Enable','off')
     end
Index: trunk/src/series/civ_series.m
===================================================================
--- trunk/src/series/civ_series.m	(revision 1195)
+++ trunk/src/series/civ_series.m	(revision 1196)
@@ -974,5 +974,5 @@
     Data.VarAttribute{4}.scale_factor=1/inv_scale_factor;
     Data.VarAttribute{5}.Role='ancillary';
-    Data.VarAttribute{5}.scale_factor=1/inv_scale_factor;
+    Data.VarAttribute{5}.scale_factor=1/100;%scla factor for correlation
     Data.VarAttribute{6}.Role='errorflag';
     Data.X=uint16(Civ_X);
@@ -980,11 +980,9 @@
     Data.U=int16(inv_scale_factor*Civ_U);
     Data.V=int16(inv_scale_factor*Civ_V);
-    Data.C=uint8(inv_scale_factor*Civ_C);
+    Data.C=uint8(100*Civ_C);
     Data.FF=uint8(Civ_FF);
+    % add smoothed field if ptch is done
     if (Param.ActionInput.CheckPatch1 && ~Param.ActionInput.CheckCiv2) ||Param.ActionInput.CheckPatch2
         nbvar=6;
-        %     Data.ListVarName=[Data.ListVarName {'U_smooth','V_smooth','SubRange','NbCentres','Coord_tps','U_tps','V_tps'}];
-        %         Data.VarDimName=[Data.VarDimName {'nb_vec','nb_vec',{'nb_coord','nb_bounds','nb_subdomain'},{'nb_subdomain'},...
-        %             {'nb_tps','nb_coord','nb_subdomain'},{'nb_tps','nb_subdomain'},{'nb_tps','nb_subdomain'}}];
         Data.ListVarName=[Data.ListVarName {'U_smooth','V_smooth'}];
         Data.VarDimName=[Data.VarDimName {'nb_vec','nb_vec'}];
@@ -995,19 +993,5 @@
         Data.U_smooth=int16(inv_scale_factor*Civ_U_smooth);
         Data.V_smooth=int16(inv_scale_factor*Civ_V_smooth);
-        %         Data.VarAttribute{nbvar+5}.Role='coord_tps';
-        %         Data.VarAttribute{nbvar+6}.Role='vector_x';
-        %         Data.VarAttribute{nbvar+7}.Role='vector_y';
-        %         Data.U_smooth=int16(inv_scale_factor*U_smooth);
-        %         Data.V_smooth=int16(inv_scale_factor*V_smooth);
-        %         Data.SubRange=SubRange;
-        %         Data.NbCentres=NbCentres;
-        %         Data.Coord_tps=Coord_tps;
-        %         Data.U_tps=U_tps;
-        %         Data.V_tps=V_tps;
-    end
-    %
-    %      if ~isempty(inv_scale_factor)
-    %              Data=compress_data(Data,inv_scale_factor);% compress the data using integers instead of (single precision)floating reals
-    %      end
+    end
     errormsg=struct2nc(ncfile_out,Data);
     if isempty(errormsg)
Index: trunk/src/series/merge_proj.m
===================================================================
--- trunk/src/series/merge_proj.m	(revision 1195)
+++ trunk/src/series/merge_proj.m	(revision 1196)
@@ -92,4 +92,25 @@
         msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
     end
+    VelocityRange=[];%default
+    VelGradientRange=[];%default
+    if isfield(Param,'ActionInput')
+        if isfield(Param.ActionInput,'VelocityRange') 
+           VelocityRange= Param.ActionInput.VelocityRange;
+        end
+        if isfield(Param.ActionInput,'VelGradientRange') 
+           VelGradientRange= Param.ActionInput.VelGradientRange;
+        end
+    end   
+    prompt = {'velocity range (max modulus) for 16 bit integer records (32 bit reals if empty)';...
+        'range (max modulus) for vel derivatives (curl, div...) for 16 bit integer records (32 bit reals if empty)'};
+    dlg_title = 'set scale_factor for result writing as 16 bit integer (instead of 32 bit reals by default)';
+    num_lines= 2;
+    def     = { num2str(VelocityRange),num2str(VelGradientRange)};
+    answer = inputdlg(prompt,dlg_title,num_lines,def);
+    if isempty(answer)
+        return
+    end
+    ParamOut.ActionInput.VelocityRange=str2num(answer{1});
+    ParamOut.ActionInput.VelGradientRange=str2num(answer{2});   
     return
 end
@@ -109,4 +130,12 @@
     WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
 end
+scale_factor_inv_uv=[];
+if isfield(Param.ActionInput,'VelocityRange') && ~isempty(Param.ActionInput.VelocityRange)
+    scale_factor_inv_uv=floor(32767/Param.ActionInput.VelocityRange);
+end
+scale_factor_inv_dudv=[];
+if isfield(Param.ActionInput,'VelGradientRange') && ~isempty(Param.ActionInput.VelGradientRange)
+    scale_factor_inv_dudv=floor(32767/Param.ActionInput.VelGradientRange);
+end
 
 %% define the directory for result file (with path=RootPath{1})
@@ -139,5 +168,7 @@
 
 %% determine the file type on each line from the first input file 
-NcTypeOptions={'netcdf','civx','civdata','pivdata_fluidimage'};
+NcTypeOptions={'netcdf','civx','civdata','civdata_compress','pivdata_fluidimage'};
+frame_index=cell(NbView,1);FileInfo=cell(NbView,1);MovieObject=cell(NbView,1);ParamIn=cell(NbView,1);
+FileType=cell(NbView,1);CheckImage=zeros(NbView,1);CheckNc=zeros(NbView,1);
 for iview=1:NbView
     if ~exist(filecell{iview,1}','file')
@@ -150,11 +181,11 @@
         FileType{iview}='netcdf';
     end
-    CheckImage{iview}=strcmp(FileInfo{iview}.FieldType,'image');% =1 for images
-    if CheckImage{iview}
+    CheckImage(iview)=strcmp(FileInfo{iview}.FieldType,'image');% =1 for images
+    if CheckImage(iview)
         ParamIn{iview}=MovieObject{iview};
     else
         ParamIn{iview}=Param.InputFields;
     end
-    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
+    CheckNc(iview)=ismember(FileType{iview},NcTypeOptions);% =1 for netcdf files
     if ~isempty(j1_series{iview})
         frame_index{iview}=j1_series{iview};
@@ -163,5 +194,5 @@
     end
 end
-if NbView >1 && max(cell2mat(CheckImage))>0 && ~isfield(Param,'ProjObject')
+if NbView >1 && max(CheckImage)>0 && ~isfield(Param,'ProjObject')
     disp_uvmat('ERROR','projection on a common grid is needed to concatene images: use a Projection Object of type ''plane'' with ProjMode=''interp_lin''',checkrun)
     return
@@ -201,22 +232,18 @@
     end
 end
-%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
- % EDIT FROM HERE
 
 %% check the validity of  input file types
-for iview=1:NbView
-    if ~isequal(CheckImage{iview},1)&&~isequal(CheckNc{iview},1)
-        disp_uvmat('ERROR','input set of input series: need  either netcdf either image series',checkrun)
+if ~(CheckImage | CheckNc)
+        disp_uvmat('ERROR',' netcdf or  image series needed as input',checkrun)
         return
-    end
 end
 
 %% output file type
-if min(cell2mat(CheckImage))==1 && (~Param.CheckObject || strcmp(Param.ProjObject.Type,'plane'))
+if min(CheckImage)==1 && (~Param.CheckObject || strcmp(Param.ProjObject.Type,'plane'))
     FileExtOut='.png'; %image output (input and proj result = image)
 else
     FileExtOut='.nc'; %netcdf output
 end
-if isempty(j1_series{1})
+if isempty(j1_series{1})||max(j1_series{1})==1
     NomTypeOut='_1';
 else
@@ -232,9 +259,5 @@
 
 
-%% Set field names and velocity types
-%use Param.InputFields for all views
-
 %% MAIN LOOP ON FIELDS
-%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
 
     %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
@@ -261,5 +284,4 @@
     end
     j1=1;
-    j2=1;
     if ~isempty(j1_series{1})
         j1=j1_series{1}(index);
@@ -277,5 +299,5 @@
     for iview=1:NbView
         %% reading input file(s)      
-        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},ParamIn{iview},frame_index{iview}(index));
+        [Data{iview},~,errormsg] = read_field(filecell{iview,index},FileType{iview},ParamIn{iview},frame_index{iview}(index));
         if isempty(errormsg)
             disp([filecell{iview,index} ' read OK'])
@@ -307,9 +329,8 @@
         
         %% calculate tps coefficients if needed
-
-        check_proj_tps= strcmp(FileType{iview},'civdata') && isfield(Param,'ProjObject')&&~isempty(Param.ProjObject)...
+        check_proj_tps= ismember(FileType{iview},{'civdata','civdata_compress'}) && isfield(Param,'ProjObject')&&~isempty(Param.ProjObject)...
             && strcmp(Param.ProjObject.ProjMode,'interp_tps')&&~isfield(Data{iview},'Coord_tps');
         if check_proj_tps
-        Data{iview}=tps_coeff_field(Data{iview},check_proj_tps);
+            Data{iview}=tps_coeff_field(Data{iview},check_proj_tps);
         end
         
@@ -326,5 +347,5 @@
         if Param.CheckMask % introduce multilevel mask like for civ
             NbSlice=Param.MaskTable{iview,2};
-            [RootPath_mask,SubDir_mask,RootFile_mask,i1_mask,i2_mask,j1_mask,j2_mask,Ext_mask]=fileparts_uvmat(Param.MaskTable{iview,1});
+            [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.MaskTable{iview,1});
             i1_mask=mod(i1-1,NbSlice)+1;
             maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask);
@@ -334,6 +355,6 @@
             [MaskData,~,errormsg] = read_field(maskname,'image');
             if ~isempty(NbSlice_calib)
-            MaskData.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
-        end
+                MaskData.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
+            end
             if ~isempty(transform_fct) && nargin(transform_fct)>=2
                 MaskData=transform_fct(MaskData,XmlData{iview});
@@ -351,6 +372,4 @@
     else
         MergeData=transform_fct(Data{1},XmlData{1},Data{2}); %combine the two input file series
-    % else
-    %     MergeData=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});%combine the two input file series with calibration parameters
     end
     if ~isempty(errormsg)
@@ -362,5 +381,5 @@
     if ~isempty(time)
         timeread=time(index);   
-    elseif ~isempty(find(timeread))% time defined from ImaDoc
+    elseif ~isempty(find(timeread, 1))% time defined from ImaDoc
         timeread=mean(timeread(timeread~=0));% take average over times form the files (when defined)
     else
@@ -372,8 +391,8 @@
     if strcmp(FileExtOut,'.png')    %output as image
         if index==1
-            if strcmp(class(MergeData.A),'uint8')
-            BitDepth=8;
+            if isa(MergeData.A,'uint8')
+                BitDepth=8;
             else
-              BitDepth=16;  
+                BitDepth=16;
             end
             %write xml calibration file, using the first file
@@ -429,5 +448,5 @@
             MergeData.Time=timeread;
         end
-        % position of projection plane 
+        % position of projection plane
         if isfield(Data{1},'ProjObjectCoord')&& isfield(Data{1},'ProjObjectAngle')
             ProjObjectCoord=Data{1}.ProjObjectCoord;
@@ -471,4 +490,28 @@
             end
         end
+        if ~isempty(scale_factor_inv_uv)
+            index_U=find(strcmp(MergeData.ListVarName,'U'));
+            if ~isempty(index_U)
+                MergeData.VarAttribute{index_U}.scale_factor=1/scale_factor_inv_uv;
+                MergeData.U=int16(scale_factor_inv_uv*MergeData.U);
+            end
+            index_V=find(strcmp(MergeData.ListVarName,'V'));
+            if ~isempty(index_V)
+                MergeData.VarAttribute{index_V}.scale_factor=1/scale_factor_inv_uv;
+                MergeData.V=int16(scale_factor_inv_uv*MergeData.V);
+            end
+        end
+        if ~isempty(scale_factor_inv_dudv)
+            index_var=find(strcmp(MergeData.ListVarName,'curl'));
+            if ~isempty(index_var)
+                MergeData.VarAttribute{index_var}.scale_factor=1/scale_factor_inv_dudv;
+                MergeData.curl=int16(scale_factor_inv_uv*MergeData.curl);
+            end
+            index_var=find(strcmp(MergeData.ListVarName,'div'));
+            if ~isempty(index_var)
+                MergeData.VarAttribute{index_var}.scale_factor=1/scale_factor_inv_dudv;
+                MergeData.div=int16(scale_factor_inv_dudv*MergeData.div);
+            end
+        end
         error=struct2nc(OutputFile,MergeData);%save result file
         if isempty(error)
@@ -495,5 +538,5 @@
 NbView=length(Data);
 if NbView==1% if there is only one field, just reproduce it in MergeData
-    return 
+    return
 end
 
