Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 492)
+++ /trunk/src/civ.m	(revision 493)
@@ -341,4 +341,5 @@
 
 %% case of netcdf file as input, get the civ processing stage and look for a coresponding image
+imageinput=fileinput;%default
 if strcmp(ExtInput,'.nc')
     NomTypeNc=NomTypeInput;
@@ -351,4 +352,5 @@
         set(handles.RootFile_1,'Visible','Off');
     end
+    imageinput='';
     Data=nc2struct(fileinput,'ListGlobalAttribute','Conventions','absolut_time_T0','CivStage','Civ2_ImageA','Civ1_ImageA','Civ2_ImageB','Civ1_ImageB','fix','patch','civ2','fix2');
     if isfield(Data,'Txt')
@@ -359,5 +361,5 @@
     if strcmp(Data.Conventions,'uvmat/civdata')% case of new civ data,
         set(handles.Program,'Value',2) %select civ/Matlab by default
-        ListProgram_Callback([],[], handles)
+        Program_Callback([],[], handles)
         if ~isempty(Data.CivStage)%test for civ files
             ind_opening=Data.CivStage;
@@ -404,5 +406,7 @@
         end
     end
+    if ~exist(imageinput,'file')
     imageinput=fullfile_uvmat(RootPath,regexprep(SubDir,'.civ(_?)(\d*)$',''),RootFile,'.png',NomTypeIma,i1,[],j1);
+    end
 end
 
@@ -419,6 +423,6 @@
             '*.*',  'All Files (*.*)'};
         [FileName, PathName] = uigetfile( menu, 'Pick an input image file',fileparts(fileparts(fileinput)));
-        fileinput=[PathName FileName];%complete file name
-        if ~exist(fileinput,'file')
+        imageinput=[PathName FileName];%complete file name
+        if ~exist(imageinput,'file')
             return %abandon of the browser is cancelled
         end
@@ -428,8 +432,8 @@
 
 %% scan the image file series 
-[FilePath,FileName,ImaExt]=fileparts(fileinput);
+[FilePath,FileName,ImaExt]=fileparts(imageinput);
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-[RootPath,SubdirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName ImaExt]);
+[RootPath,SubdirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,MovieObject]=find_file_series(FilePath,[FileName ImaExt]);
 switch FileType
     case {'image','multimage','video','mmreader'}
@@ -442,5 +446,5 @@
 set(handles.RootFile,'String',RootFile)
 if strcmp(ExtInput,'.nc')
-    SubDirCiv=regexprep(SubDir,[SubdirImages '^'],'');%suppress the root  SuddirImages;
+    SubDirCiv=regexprep(SubDir,['^' SubdirImages],'');%suppress the root  SuddirImages;
 else
     SubDirCiv= '.civ';
@@ -450,14 +454,4 @@
 browse=get(handles.RootPath,'UserData');
 browse.incr_pair=[0 0];%default
-
-%% fill reference indices from the input file indices
-num_ref_i=i1;%efaulmt ref index
-if ~isempty(i2)
-    num_ref_i=floor((num_ref_i+i2)/2);
-end
-num_ref_j=j1;
-if ~isempty(j2)
-    num_ref_j=floor((num_ref_j+j2)/2);
-end
 
 %% scan the images if a civ file has been opened
@@ -467,17 +461,21 @@
 MaxIndex_j=max(j1_series(j1_series>0));
 
+%% fill reference indices from the input file indices
+num_ref_i=str2num(get(handles.ref_i,'String'));
+num_ref_j=str2num(get(handles.ref_j,'String'));
+% for movies don't modify except if the current ref is outside index bounds
+if strcmp(ExtInput,'.nc')|| ~(strcmp(FileType,'mmreader')||strcmp(FileType,'VideoReader') && num_ref_i<=MaxIndex_i && num_ref_j<=MaxIndex_j)
+    num_ref_i=i1;%default ref index
+    if ~isempty(i2)
+        num_ref_i=floor((num_ref_i+i2)/2);
+    end
+    num_ref_j=j1;
+    if ~isempty(j2)
+        num_ref_j=floor((num_ref_j+j2)/2);
+    end
+end
+
 %% look for an image documentation file
 XmlFileName=find_imadoc(RootPath,SubDir,RootFile,ImaExt);
-% SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
-% filexml=fullfile(RootPath,[SubDirBase '.xml']);% new convention: xml above the image dir
-% if ~exist(filexml,'file')
-%     filexml=fullfile(RootPath,SubDir,[RootFile '.xml']);%old convention: xml within the image directroy
-%     if ~exist(filexml,'file')
-%         filexml=fullfile(RootPath,SubDir,[RootFile '.civ']);%very old convention: .civ file
-%         if ~exist(filexml,'file')
-%             filexml='';
-%         end
-%     end
-% end
 if isempty(XmlFileName)
     if (strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
@@ -501,11 +499,4 @@
     [XmlData,warntext]=imadoc2struct(XmlFileName);
     nom_type_read=[];
-%     if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
-%         [~,tild,tild,tild,tild,tild,tild,tild,nom_type_read]=fileparts_uvmat(XmlData.Heading.ImageName);
-%         fullname=fullfile(fileparts(RootName),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
-%         if ~exist(fullname,'file')
-%             msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
-%         end
-%     end
     if isfield(XmlData,'Time') && ~isempty(XmlData.Time)
         time=XmlData.Time;
@@ -1079,9 +1070,9 @@
 end% default configuration
 if ~isfield(s,'RunParam')
-    s.RunParam.Civ1Bin='bin/civ1';
-    s.RunParam.Civ2Bin='bin/civ2';
-    s.RunParam.FixBin='bin/fix_flag';
-    s.RunParam.PatchBin='bin/patch_up';
-    s.RunParam.CivmBin='bin/civ_matlab';
+    Param.xml.Civ1Bin=fullfile('bin','civ1');
+    Param.xml.Civ2Bin=fullfile('bin','civ2');
+    Param.xml.FixBin=fullfile('bin','fix_flag');
+    Param.xml.PatchBin=fullfile('bin','patch_up');
+    Param.xml.CivmBin=fullfile('bin','civ_matlab');
 end
 if strcmp(Param.RunMode,'cluster') %computation dispatched on a cluster
@@ -1096,10 +1087,10 @@
         end
     else
-        %standard configuration
-        Param.xml.Civ1Bin='bin/civ1';
-        Param.xml.Civ2Bin='bin/civ2';
-        Param.xml.FixBin='bin/fix_flag';
-        Param.xml.PatchBin='bin/patch_up';
-        s.RunParam.CivmBin='bin/civ_matlab';
+        %default configuration
+        Param.xml.Civ1Bin=fullfile('bin','civ1');
+        Param.xml.Civ2Bin=fullfile('bin','civ2');
+        Param.xml.FixBin=fullfile('bin','fix_flag');
+        Param.xml.PatchBin=fullfile('bin','patch_up');
+        Param.xml.CivmBin=fullfile('bin','civ_matlab');
         Param.xml.BatchMode='oar';% TODO : allow choice for sge
     end
@@ -1107,16 +1098,14 @@
     if isfield(s,'RunParam')
         Param.xml=s.RunParam;
-    else %standard default configuration
-        s.RunParam.Civ1Bin='bin/civ1';
-        s.RunParam.Civ2Bin='bin/civ2';
-        s.RunParam.FixBin='bin/fix_flag';
-        s.RunParam.PatchBin='bin/patch_up';
-        s.RunParam.CivmBin='bin/civ_matlab';
+    else %default configuration
+        Param.xml.Civ1Bin=fullfile('bin','civ1');
+        Param.xml.Civ2Bin=fullfile('bin','civ2');
+        Param.xml.FixBin=fullfile('bin','fix_flag');
+        Param.xml.PatchBin=fullfile('bin','patch_up');
+        Param.xml.CivmBin=fullfile('bin','civ_matlab');
     end
 end
 
 %% check if the binaries exist : to move in civ_opening
-% ListProgram=get(handles.Program,'String');
-% Param.CivMode=ListProgram{get(handles.Program,'Value')};
 binary_list={};
 switch Param.Program
@@ -1950,5 +1939,4 @@
                 for j=1:nbslice
                      filename=fullfile_uvmat(RootPath,subdir_civ1_new,RootFile_A,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));
-                   % filename=name_generator(filebase_A,i1_civ1(ifile),j1_civ1(j),'.nc',NomType_nc,1,i2_civ1(ifile),j2_civ1(j),subdir_civ1_new);%
                     detect=exist(filename,'file')==2;
                     if detect% if a netcdf file already exists
@@ -2828,6 +2816,7 @@
 
 %% reads .nc subdirectoy and image numbers from the interface
-subdir_civ1=get(handles.SubdirCiv1,'String');%subdirectory subdir_civ1 for the netcdf data
-subdir_civ2=get(handles.SubdirCiv2,'String');%subdirectory subdir_civ2 for the netcdf data
+SubDirImages=get(handles.SubdirImages,'String');
+subdir_civ1=[SubDirImages get(handles.SubdirCiv1,'String')];%subdirectory subdir_civ1 for the netcdf data
+subdir_civ2=[SubDirImages get(handles.SubdirCiv2,'String')];%subdirectory subdir_civ2 for the netcdf data
 ref_i=str2double(get(handles.ref_i,'String'));
 if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
Index: /trunk/src/civ_matlab.m
===================================================================
--- /trunk/src/civ_matlab.m	(revision 492)
+++ /trunk/src/civ_matlab.m	(revision 493)
@@ -60,28 +60,28 @@
 if ischar(Param)
     Param=xml2struct(Param); %if Param is the name of an xml file, read this file as a Matlab structure
-    if isfield(Param,'Civ1')
-        if strcmp(Param.Civ1.FileTypeA,'video')
-            Param.Civ1.ImageA=VideoReader(Param.Civ1.ImageA);
-        elseif strcmp(Param.Civ1.FileTypeA,'mmreader')
-            Param.Civ1.ImageA=mmreader(Param.Civ1.ImageA);
-        end
-        if strcmp(Param.Civ1.FileTypeB,'video')
-            Param.Civ1.ImageB=VideoReader(Param.Civ1.ImageB);
-        elseif strcmp(Param.Civ1.FileTypeB,'mmreader')
-            Param.Civ1.ImageB=mmreader(Param.Civ1.ImageB);
-        end
-    end
-    if isfield(Param,'Civ2')
-        if strcmp(Param.Civ2.FileTypeA,'video')
-            Param.Civ2.ImageA=VideoReader(Param.Civ2.ImageA);
-        elseif strcmp(Param.Civ2.FileTypeA,'mmreader')
-            Param.Civ2.ImageA=mmreader(Param.Civ2.ImageA);
-        end
-         if strcmp(Param.Civ2.FileTypeB,'video')
-            Param.Civ2.ImageB=VideoReader(Param.Civ2.ImageB);
-        elseif strcmp(Param.Civ2.FileTypeB,'mmreader')
-            Param.Civ2.ImageB=mmreader(Param.Civ2.ImageB);
-        end
-    end
+%     if isfield(Param,'Civ1')
+%         if strcmp(Param.Civ1.FileTypeA,'video')
+%             Param.Civ1.ImageA=VideoReader(regexprep(Param.Civ1.ImageA,'''','\'));% remove spurious ' appearing in Windows;
+%         elseif strcmp(Param.Civ1.FileTypeA,'mmreader')
+%             Param.Civ1.ImageA=mmreader(regexprep(Param.Civ1.ImageA,'''','\'));% remove spurious ' appearing in Windows
+%         end
+%         if strcmp(Param.Civ1.FileTypeB,'video')
+%             Param.Civ1.ImageB=VideoReader(regexprep(Param.Civ1.ImageB,'''','\'));% remove spurious ' appearing in Windows
+%         elseif strcmp(Param.Civ1.FileTypeB,'mmreader')
+%             Param.Civ1.ImageB=mmreader(regexprep(Param.Civ1.ImageB,'''','\'));% remove spurious ' appearing in Windows
+%         end
+%     end
+%     if isfield(Param,'Civ2')
+%         if strcmp(Param.Civ2.FileTypeA,'video')
+%             Param.Civ2.ImageA=VideoReader(regexprep(Param.Civ2.ImageA,'''','\'));% remove spurious ' appearing in Windows;
+%         elseif strcmp(Param.Civ2.FileTypeA,'mmreader')
+%             Param.Civ2.ImageA=mmreader(regexprep(Param.Civ2.ImageA,'''','\'));% remove spurious ' appearing in Windows
+%             if strcmp(Param.Civ2.FileTypeB,'video')
+%                 Param.Civ2.ImageB=VideoReader(regexprep(Param.Civ2.ImageB,'''','\'));% remove spurious ' appearing in Windows
+%             elseif strcmp(Param.Civ2.FileTypeB,'mmreader')
+%                 Param.Civ2.ImageB=mmreader(regexprep(Param.Civ2.ImageB,'''','\'));% remove spurious ' appearing in Windows
+%             end;
+%         end
+%     end
 end
 
@@ -90,4 +90,5 @@
     %     check_civ1=1;% test for further use of civ1 results
     % %% prepare images
+
     par_civ1=Param.Civ1;
     if isfield(par_civ1,'reverse_pair')
@@ -102,19 +103,23 @@
         end
     else
-        if isfield(par_civ1,'ImageA')&&(ischar(par_civ1.ImageA)||strcmp(class(par_civ1.ImageA),'VideoReader')) % case with no image: only the PIV grid is calculated           
-            [Field,ParamOut,errormsg] = read_field(Param.Civ1.ImageA,par_civ1.FileTypeA,par_civ1.ImageA,par_civ1.FrameIndexA);
-            if ~isempty(errormsg)
-                errormsg=['error in civ_matlab/read_field:' errormsg];
-                return
-            end
-            par_civ1.ImageA=Field.A;%= image matrix A in the first input field 
-        end
-        if isfield(par_civ1,'ImageB')&& (ischar(par_civ1.ImageB)||strcmp(class(par_civ1.ImageB),'VideoReader'))
-            [Field,ParamOut,errormsg] = read_field(Param.Civ1.ImageB,par_civ1.FileTypeB,par_civ1.ImageB,par_civ1.FrameIndexB);
-            if ~isempty(errormsg)
-                errormsg=['error in civ_matlab/read_field:' errormsg];
-                return
-            end
-            par_civ1.ImageB=Field.A;%= image matrix A in the second input field 
+        if isfield(par_civ1,'ImageA')%&&...
+            %    (ischar(par_civ1.ImageA)||strcmp(class(par_civ1.ImageA),'VideoReader')||strcmp(class(par_civ1.ImageA),'mmreader')) % case with no image: only the PIV grid is calculated           
+             Param.Civ1.ImageA=regexprep(Param.Civ1.ImageA,'''','\');
+            [par_civ1.ImageA,ParamOut] = read_image(Param.Civ1.ImageA,par_civ1.FileTypeA,par_civ1.ImageA,par_civ1.FrameIndexA);
+%             if ~isempty(errormsg)
+%                 errormsg=['error in civ_matlab/read_field:' errormsg];
+%                 return
+%             end
+            %par_civ1.ImageA=Field.A;%= image matrix A in the first input field 
+        end
+        if isfield(par_civ1,'ImageB')%&& ...
+              %  (ischar(par_civ1.ImageB)||strcmp(class(par_civ1.ImageB),'VideoReader')||strcmp(class(par_civ1.ImageB),'mmreader'))
+             Param.Civ1.ImageB=regexprep(Param.Civ1.ImageB,'''','\');
+            [par_civ1.ImageB,ParamOut] = read_image(Param.Civ1.ImageB,par_civ1.FileTypeB,par_civ1.ImageB,par_civ1.FrameIndexB);
+%             if ~isempty(errormsg)
+%                 errormsg=['error in civ_matlab/read_field:' errormsg];
+%                 return
+%             end
+           % par_civ1.ImageB=Field.A;%= image matrix A in the second input field 
         end
     end
@@ -444,5 +449,16 @@
 %
 %INPUT:
-% image1:first image (matrix)
+% par_civ: structure of input parameters, with fields:
+%  .CorrBoxSize
+%  .SearchBoxSize
+%  .SearchBoxShift
+%  .ImageHeight
+%  .ImageWidth
+%  .Dx, Dy
+%  .Grid
+%  .Mask
+%  .MinIma
+%  .MaxIma
+%  .image1:first image (matrix)
 % image2: second image (matrix)
 % ibx2,iby2: half size of the correlation box along x and y, in px (size=(2*iby2+1,2*ibx2+1)
Index: /trunk/src/read_field.m
===================================================================
--- /trunk/src/read_field.m	(revision 492)
+++ /trunk/src/read_field.m	(revision 493)
@@ -154,6 +154,18 @@
                 ParamOut.FieldList={'get_field...'};
             end
-        case {'video','mmreader'}
-            A=read(ParamIn,num);
+        case 'video'
+            if strcmp(class(ParamIn),'VideoReader')
+                A=read(ParamIn,num);
+            else
+                ParamOut=VideoReader(FileName);
+                A=read(ParamOut,num);
+            end
+        case 'mmreader'
+            if strcmp(class(ParamIn),'mmreader')
+                A=read(ParamIn,num);
+            else
+                ParamOut=mmreader(FileName);
+                A=read(ParamOut,num);
+            end
         case 'vol'
             A=imread(FileName);
Index: /trunk/src/read_image.m
===================================================================
--- /trunk/src/read_image.m	(revision 492)
+++ /trunk/src/read_image.m	(revision 493)
@@ -1,9 +1,22 @@
 %--read images or video objects
-function A=read_image(FileName,FileType,VideoObject,num)
+function [A,ParamOut]=read_image(FileName,FileType,VideoObject,num)
 %------------------------------------------------------------------------
 %num is the view number needed for an avi movie
+ParamOut=VideoObject;%default
 switch FileType
-    case {'video','mmreader'}
-        A=read(VideoObject,num);
+         case 'video'
+            if strcmp(class(VideoObject),'VideoReader')
+                A=read(VideoObject,num);
+            else
+                ParamOut=VideoReader(FileName);
+                A=read(ParamOut,num);
+            end
+        case 'mmreader'
+            if strcmp(class(VideoObject),'mmreader')
+                A=read(VideoObject,num);
+            else
+                ParamOut=mmreader(FileName);
+                A=read(ParamOut,num);
+            end
     case 'multimage'
         A=imread(FileName,num);
Index: /trunk/src/struct2xml.m
===================================================================
--- /trunk/src/struct2xml.m	(revision 492)
+++ /trunk/src/struct2xml.m	(revision 493)
@@ -47,4 +47,5 @@
  if ischar(val)
      [t,new_uid]=add(t,uid,'element',key);
+     val=regexprep(val,'\','\\');
      [t]=add(t,new_uid,'chardata',val);
  elseif isnumeric(val)||islogical(val)
