Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 2)
+++ trunk/src/civ.m	(revision 12)
@@ -22,5 +22,5 @@
 function varargout = civ(varargin)
 
-% Last Modified by GUIDE v2.5 29-Oct-2009 19:05:39
+% Last Modified by GUIDE v2.5 10-Jan-2010 22:04:45
 % Begin initialization code - DO NOT EDIT
 gui_Singleton = 1;
@@ -42,8 +42,8 @@
 % End initialization code - DO NOT EDIT
 
-%--------------------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes just before civ is made visible.
-%--------------------------------------------------------------------------
 function civ_OpeningFcn(hObject, eventdata, handles, varargin)
+%------------------------------------------------------------------------
 % This function has no output args, see OutputFcn.
 % hObject    handle to figure
@@ -106,7 +106,4 @@
 set(handles.ImaDoc,'String',ext)
 
-
-% set(handles.ImaDoc,'String',ext)
-  
 %read names of the .exe file to adjust the interface according to
 %available prog
@@ -125,5 +122,4 @@
 else
     syst='WIN';
-    %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ binary names
     xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
     if exist(xmlfile,'file')
@@ -150,19 +146,16 @@
 test_batch=1;
 if ~sge
-if isequal(todo_path,'') || isequal(todo_path,[])
-    display(['no batch distributed processing available:file path TODO.txt not defined in UVMAT/PARAM_' syst])
-    test_batch=0;
-end
-if exist(name_todo,'file')~=2 
-    msgbox_uvmat('WARNING',['no batch distributed processing available, queue file ' name_todo ' absent']);
-  %  test_batch=0;  % Problems to detect file on linux/nfs filesystems
-end
-end
-
-
+    if isequal(todo_path,'') || isequal(todo_path,[])
+        display(['no batch distributed processing available:file path TODO.txt not defined in UVMAT/PARAM_' syst])
+        test_batch=0;
+    end
+    if exist(name_todo,'file')~=2 
+        msgbox_uvmat('WARNING',['no batch distributed processing available, queue file ' name_todo ' absent']);
+      %  test_batch=0;  % Problems to detect file on linux/nfs filesystems
+    end
+end
 if test_batch==0
     set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
 end
-
 set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
 set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
@@ -215,5 +208,5 @@
 
 % set the range of fields (1:1 by default) and selected pair
-if isempty(num2)|isequal(num2,num1)
+if isempty(num2)||isequal(num2,num1)
     num_ref_i=num1;
 else
@@ -222,5 +215,5 @@
     browse.incr_pair(2)=0;
 end
-if isempty(num_b)|isequal(num_a,num_b)
+if isempty(num_b)||isequal(num_a,num_b)
     if isempty(num_a)
         num_ref_j=1;
@@ -248,9 +241,8 @@
 set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
 
-
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Outputs from this function are returned to the command line.
-%-----------------------------------------------------------------
 function varargout = civ_OutputFcn(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 % varargout  cell array for returning output args (see VARARGOUT);
 % hObject    handle to figure
@@ -260,7 +252,8 @@
 varargout{1} = handles.output;
 
-%------------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in browse_root.
 function browse_root_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 %get the input file properties
 filebase=get(handles.displ_filebase,'String');
@@ -321,5 +314,4 @@
    end
 end
-
 [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
 filebase=fullfile(RootPath,RootFile);
@@ -441,16 +433,14 @@
 displ_filebase_Callback(hObject, eventdata, handles);
 
-%------------------------------------------------
-
+%------------------------------------------------------------------------
 function ImaDoc_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 displ_filebase_Callback(hObject, eventdata, handles)
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 %function activated when a new filebase (image series) is introduced
-%------------------------------------------------------------
 function displ_filebase_Callback(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 global test_batch
-%set(gcf,'Pointer','watch')
 set(handles.compare,'Visible','on')
 ext_ima=get(handles.ext_ima,'String'); 
@@ -471,8 +461,8 @@
 if ~isempty(browse) 
     if isfield(browse,'nom_type_ima')
-        nom_type_ima=browse.nom_type_ima;
+        nom_type_ima=browse.nom_type_ima;% get an image nomenclature type already determined by an input image name
     end
     if isfield(browse,'field_count')
-        field_count=browse.field_count;
+        field_count=browse.field_count;% get an image index type already determined by an input file
     end
 end
@@ -480,9 +470,9 @@
 %default first_i and j and increments
 first_i=str2num(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
-if isempty(first_i)| first_i < 1
+if isempty(first_i)|| first_i < 1
     first_i=1; %default first_i
 end
 last_i=str2num(get(handles.last_i,'String'));
-if isempty(last_i)| last_i < first_i
+if isempty(last_i)|| last_i < first_i
     last_i=first_i;  %default last_i
 end
@@ -511,5 +501,4 @@
 
  %look for an image documentation file
-ext
 if ~isequal(ext,'.xml') && ~isequal(ext,'.civ')&& ~isequal(ext,'.avi')&& ~isequal(ext,'.AVI')
     if exist([filebase '.xml'],'file')
@@ -532,10 +521,10 @@
     drawnow
     %read the image documentation file if found
-if isequal(ext,'.civxml') | isequal(ext,'.xml')| isequal(ext,'.civ')
+if isequal(ext,'.civxml') || isequal(ext,'.xml')|| isequal(ext,'.civ')
     set(handles.ref_i,'Visible','On')%use a reference index
     set(handles.ref_j,'Visible','On')
     set(handles.dt,'Visible','Off')
-    set(handles.dt_text,'String','ref. ind.')
-elseif isequal(ext,'.avi') | isequal(ext,'.AVI')
+    set(handles.dt_text,'String','')
+elseif isequal(ext,'.avi') || isequal(ext,'.AVI')
     set(handles.ref_j,'Visible','Off')
     set(handles.dt,'Visible','Off')
@@ -547,4 +536,5 @@
     set(handles.dt_text,'String','dt(ms)=')
 end
+testima_xml=0;
 if isequal(ext,'.civxml')%TO ABANDON
     [nbfield,nburst,time]=read_civxml([filebase '.civxml']);
@@ -562,7 +552,12 @@
     ext_ima_read=[];
     nom_type_read=[];
-    XmlData.Heading
-    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')
+    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
         [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
+        fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName) %full name (including path) of the first image defined by the xmle file, 
+        if exist(fullname,'file')
+            testima_xml=1;
+        else
+            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
+        end
     end
     if isfield(XmlData,'Camera')
@@ -606,6 +601,6 @@
 elseif isequal(ext,'.civ')% case of .civ image documentation file
         [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
-        if error==2, warndlg(['no file ' filebase '.civ']);
-        elseif error==1, warndlg('inconsistent number of fields in the .civ file');
+        if error==2, msgbox_uvmat('WARNING',['no file ' filebase '.civ']);
+        elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
         end
 %         ext_ima='.png';
@@ -629,45 +624,66 @@
 set(handles.ImaDoc,'BackgroundColor',[1 1 1])
 
+%get the imabe nomenclature type if not defiend by the input file nor by the xml file
+if isempty(nom_type_ima)
+    %look for double image series '_i_j'
+    dirima=dir([filebase '_' num2str(first_i) '_' num2str(first_j) '.*']);
+    if isempty(dirima)
+       % look for images series  with sub marker '_'
+       dirima=dir([filebase '_*' num2str(first_i) '.*']);
+       if isempty(dirima)
+          % look for other images series 
+          dirima=dir([filebase '*' num2str(first_i) '.*']);
+          if ~isempty(dirima)
+              [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
+          end
+       else
+           [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
+       end
+    else
+       [pp,ff,fc,str2,str_a,str_b,ext_ima,nom_type_ima]=name2display(dirima(1).name);
+    end
+end   
+    
 % no image documentation file found: look for a series of existing images or .nc files 
 if isempty(time) && ~isequal(ext,'.nc') 
-        subdir=get(handles.subdir_civ1,'String');
-        incr_pair=[0 0];%default
-        if isfield(browse,'incr_pair')
-                incr_pair=browse.incr_pair;
-        end
-        nbdetect=0;%test of detected images
-        field_i=field_count;
-        idetect=1;
-        while idetect==1 %look for the maximum file number in the series
-                field_i=field_i+1;
+    subdir=get(handles.subdir_civ1,'String');
+    incr_pair=[0 0];%default
+    if isfield(browse,'incr_pair')
+            incr_pair=browse.incr_pair;
+    end
+    nbdetect=0;%test of detected images
+    field_i=field_count;
+    idetect=1;
+    while idetect==1 %look for the maximum file number in the series
+            field_i=field_i+1;
+            imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
+            if strcmp(nom_type_ima,'none')||strcmp(nom_type_ima,'')
+               idetect=0; %stop if the same image is repeated (if nom_type='none')
+               nbdetect=1;
+            else
+                idetect=(exist(imagename,'file')==2);
+            end
+            %SEE CASE OF NETCDF FILES
+            nbdetect=nbdetect+(exist(imagename,'file')==2);
+    end
+    nb_field=field_i;% last detected field number
+    field_i=field_count;%look for the minimum file number in the series
+    idetect=1;
+    while idetect==1 
+                field_i=field_i-1;
                 imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
-                if strcmp(nom_type_ima,'none')||strcmp(nom_type_ima,'')
-                   idetect=0; %stop if the same image is repeated (if nom_type='none')
-                   nbdetect=1;
+                if isequal(nom_type_ima,'none')||strcmp(nom_type_ima,'')
+                    idetect=0; %stop if the same image is repeated (if nom_type='none')
+                    nbdetect=1;
                 else
                     idetect=(exist(imagename,'file')==2);
                 end
-                %SEE CASE OF NETCDF FILES
-                nbdetect=nbdetect+(exist(imagename,'file')==2);
-        end
-        nb_field=field_i;% last detected field number
-        field_i=field_count;%look for the minimum file number in the series
-        idetect=1;
-        while idetect==1 
-                    field_i=field_i-1;
-                    imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
-                    if isequal(nom_type_ima,'none')||strcmp(nom_type_ima,'')
-                        idetect=0; %stop if the same image is repeted (if nom_type='none')
-                        nbdetect=1;
-                    else
-                        idetect=(exist(imagename,'file')==2);
-                    end
-                    nbdetect=nbdetect+idetect;
-        end
-        first_i=max(field_i+1,1);
-            %determine the set of times and possible intervals for CIV
-        dt=(1/1000)*str2num(get(handles.dt,'String'));
-        time=(dt*[0:nb_field-1])';
-        set(handles.mode,'String',{'series(Di)'})
+                nbdetect=nbdetect+idetect;
+    end
+    first_i=max(field_i+1,1);
+        %determine the set of times and possible intervals for CIV
+    dt=(1/1000)*str2num(get(handles.dt,'String'));
+    time=(dt*[0:nb_field-1])';
+    set(handles.mode,'String',{'series(Di)'})
 end
 if isequal(nom_type_ima,'none')% no file numbering used
@@ -683,8 +699,8 @@
         set(handles.displ_filebase,'UserData',time); %store the set of times
         if isempty(TimeUnit)
-            set(handles.dt_unit,'String','e-03');
+            set(handles.dt_unit,'String','dt in e-03');
             set(handles.TimeUnit,'String','');
         else
-            set(handles.dt_unit,'String',['m' TimeUnit]);
+            set(handles.dt_unit,'String',['dt in m' TimeUnit]);
             set(handles.TimeUnit,'String',TimeUnit);
         end
@@ -780,10 +796,9 @@
 set(gcf,'Pointer','arrow')
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
+%------------------------------------------------------------------------
 % --- Executes on button press in mode.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 function mode_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 browse=get(handles.browse_root,'UserData');
-
 compare_list=get(handles.compare,'String');
 val=get(handles.compare,'Value');
@@ -813,7 +828,4 @@
     displ_dt=1;%default
     nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
-%     if nbfield2<2
-%         nbfield2=2,
-%     end
     for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
         for numod_b=(numod_a+1):nbfield2
@@ -938,9 +950,9 @@
 find_netcpair_civ2(hObject, eventdata, handles)
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 % determine the menu for civ1 pairs depending on existing netcdf file at the middle of
 % the field series set by first_i, incr, last_i
-%----------------------------------------------------------------
 function find_netcpair_civ1(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 set(gcf,'Pointer','watch')
 %nomenclature types
@@ -971,6 +983,4 @@
 end
 if isempty(nom_type_nc)
-    'TESTciv'
-    nom_type_ima
      [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
 end
@@ -993,8 +1003,4 @@
 else
     ref_j=str2num(get(handles.ref_j,'String'));
-end
-if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
-    ref_i=floor((first_i+last_i)/2);
-    ref_j=1;
 end
 time=get(handles.displ_filebase,'UserData');%get the set of times
@@ -1127,9 +1133,10 @@
 set(handles.list_pair_civ2,'String',displ_pair');
 set(gcf,'Pointer','arrow')
-%--------------------------------------------------------------
+
+%------------------------------------------------------------------------
 % determine the menu for civ2 pairs depending on the existing netcdf file at the 
 %middle of the series set by first_i, incr, last_i 
-%--------------------------------------------------------------
 function find_netcpair_civ2(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 set(gcf,'Pointer','watch')
 %nomenclature types
@@ -1265,13 +1272,4 @@
           end
        end
-%    else
-%        for ipair=1:nbpair
-%          if select(ipair)
-%             displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
-%          else 
-%             displ_pair{ipair}='...'; %pair not displayed in the menu
-%          end
-%        end
-%     end
 elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
        for ipair=1:nbpair
@@ -1310,12 +1308,11 @@
 end
 set(handles.list_pair_civ2,'String',displ_pair');
-
-
 set(gcf,'Pointer','arrow')
-%----------------------------------------------------
+
+%------------------------------------------------------------------------
 %  determine the list of index pairs of processing file 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
     find_pair_indices(handles,mode)
+%------------------------------------------------------------------------
 first_i=str2num(get(handles.first_i,'String'));
 last_i=str2num(get(handles.last_i,'String'));
@@ -1459,9 +1456,8 @@
 end
 
-
-%-------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on selection change in list_pair_civ1.
 function list_pair_civ1_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------
+%------------------------------------------------------------------------
 %reproduce by default the chosen pair in the civ2 menu
 list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
@@ -1507,8 +1503,8 @@
 end 
 
-%------------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on selection change in list_pair_civ2.
 function list_pair_civ2_Callback(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu 
 
@@ -1545,8 +1541,8 @@
 end 
 
-%---------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in RUN.
-%------------------------------------------------------
 function RUN_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 global civ1_exe civ2_exe patch_exe patch_new_exe sge
 
@@ -1583,14 +1579,26 @@
 %check mask if selecetd
 if isequal(get(handles.get_mask_civ1,'Value'),1)
-     get_mask_civ1_Callback(hObject, eventdata, handles);
+    maskname=get(handles.mask_civ1,'String');
+    if ~exist(maskname,'file')
+        get_mask_civ1_Callback(hObject, eventdata, handles);
+    end
 end
 if isequal(get(handles.get_mask_fix1,'Value'),1)
+    maskname=get(handles.mask_fix1,'String');
+    if ~exist(maskname,'file')
      get_mask_fix1_Callback(hObject, eventdata, handles);
+    end
 end
 if isequal(get(handles.get_mask_civ2,'Value'),1)
+    maskname=get(handles.mask_civ2,'String');
+    if ~exist(maskname,'file')
      get_mask_civ2_Callback(hObject, eventdata, handles);
+    end
 end
 if isequal(get(handles.get_mask_fix2,'Value'),1)
+    maskname=get(handles.mask_fix2,'String');
+    if ~exist(maskname,'file')
      get_mask_fix2_Callback(hObject, eventdata, handles);
+    end
 end
 
@@ -1651,4 +1659,11 @@
 [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
        set_civ_filenames(handles,compare,box_test);
+if isempty(filecell)
+   set(handles.RUN, 'Enable','On')
+    set(handles.RUN,'BackgroundColor',[1 0 0])
+    set(handles.BATCH, 'Enable','On')
+    set(handles.BATCH,'BackgroundColor',[1 0 0])
+   return
+end
 display('files OK, processing...')   
 nbfield=size(num1_civ1,2);
@@ -1688,7 +1703,14 @@
     end   
     h = waitbar(0,['removing velocity vectors, fix1']);% display a wait bar 
-    test_mask=get(handles.get_mask_fix1,'Value');
-    maskdispl=get(handles.mask_fix1,'String');
-    maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
+    test_mask=get(handles.get_mask_fix1,'Value');    
+    if test_mask
+        maskdispl=get(handles.mask_fix1,'String');
+        if exist(maskdispl,'file')
+            test_mask=2;
+            maskname=maskdispl;
+        else
+            maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
+        end
+    end
     for ifile=1:nbfield
         waitbar(ifile/nbfield); %update the waitbar
@@ -1697,5 +1719,5 @@
                 maskname='noFile use default';
                 maskflag=0;
-            else
+            elseif test_mask==1
                 nbslice_mask=str2num(maskdispl(1:end-4)); % 
                 num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
@@ -1838,6 +1860,13 @@
     h = waitbar(0,['removing velocity vectors, fix2']);% display a wait bar
     test_mask=get(handles.get_mask_fix2,'Value');
-    maskdispl=get(handles.mask_fix2,'String');
-    maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
+    if test_mask
+        maskdispl=get(handles.mask_fix2,'String');
+        if exist(maskdispl,'file')
+            test_mask=2;
+            maskname=maskdispl;
+        else
+            maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
+        end
+    end
     for ifile=1:nbfield
         waitbar(ifile/nbfield); %update the waitbar
@@ -1846,5 +1875,5 @@
                 maskname='noFile use default';
                 maskflag=0;
-           else
+           elseif test_mask==1
                 nbslice_mask=str2num(maskdispl(1:end-4)); % 
                 num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
@@ -1984,9 +2013,8 @@
 saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
 
-
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in BATCH: remote processing
-%-----------------------------------------------------------
 function BATCH_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe
 compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
@@ -2024,14 +2052,26 @@
 %check mask if selecetd
 if isequal(get(handles.get_mask_civ1,'Value'),1)
-     get_mask_civ1_Callback(hObject, eventdata, handles);
+    maskname=get(handles.mask_civ1,'String');
+    if ~exist(maskname,'file')
+        get_mask_civ1_Callback(hObject, eventdata, handles);
+    end
 end
 if isequal(get(handles.get_mask_fix1,'Value'),1)
-     get_mask_fix1_Callback(hObject, eventdata, handles);
+    maskname=get(handles.mask_fix1,'String');
+    if ~exist(maskname,'file')
+        get_mask_fix1_Callback(hObject, eventdata, handles);
+    end
 end
 if isequal(get(handles.get_mask_civ2,'Value'),1)
+    maskname=get(handles.mask_civ2,'String');
+    if ~exist(maskname,'file')
      get_mask_civ2_Callback(hObject, eventdata, handles);
+    end
 end
 if isequal(get(handles.get_mask_fix2,'Value'),1)
+    maskname=get(handles.mask_fix2,'String');
+    if ~exist(maskname,'file')
      get_mask_fix2_Callback(hObject, eventdata, handles);
+    end
 end
 
@@ -2275,7 +2315,8 @@
         cmd='';
         if sge
+           %fid=fopen([filename '.cmx'],'w')
            cmd='#!/bin/bash';
-           cmd=char({cmd;'#$ -cwd'});
-           cmd=char({cmd;'hostname && date'});
+           cmd=[cmd '\n' '#$ -cwd'];
+           cmd=[cmd '\n' 'hostname && date'];
         end
         if civAll
@@ -2307,13 +2348,18 @@
             else
                 maskdispl=get(handles.mask_civ1,'String');
-                maskbase=[filebase '_' maskdispl]; % 
-                nbslice_mask=str2num(maskdispl(1:end-4)); % 
-                num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
-                par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
-                if exist(par_civ1.maskname,'file')
-                    par_civ1.maskflag='y'; 
+                if exist(maskdispl,'file')
+                    par_civ1.maskname=maskdispl;
+                    par_civ1.maskflag='y';   
                 else
-                    par_civ1.maskname='noFile use default';
-                    par_civ1.maskflag='n'; 
+                    maskbase=[filebase '_' maskdispl]; % 
+                    nbslice_mask=str2num(maskdispl(1:end-4)); % 
+                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
+                    par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+                    if exist(par_civ1.maskname,'file')
+                        par_civ1.maskflag='y'; 
+                    else
+                        par_civ1.maskname='noFile use default';
+                        par_civ1.maskflag='n'; 
+                    end
                 end
             end
@@ -2346,5 +2392,5 @@
             i_cmd=i_cmd+1;
             if isequal(civAll,0)
-                cmd=char({cmd;BATCH_CIV1(filename_cmx([1:end-4]),namelog,par_civ1,handles)});
+                cmd=[cmd '\n' BATCH_CIV1(filename_cmx(1:end-4),namelog,par_civ1,handles)];
             else
                  civAllCmd=[civAllCmd ' civ1 '];
@@ -2378,5 +2424,5 @@
                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
-           cmd=char({cmd ;cmd_FIX});
+           cmd=[cmd '\n' cmd_FIX];
            else
                 fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
@@ -2403,5 +2449,5 @@
         if isequal(civAll,0)
             cmd_PATCH=RUN_PATCH(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
-            cmd=char({cmd ;cmd_PATCH});
+            cmd=[cmd '\n' cmd_PATCH];
         else
             patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
@@ -2471,13 +2517,18 @@
             else
                 maskdispl=get(handles.mask_civ2,'String');
-                maskbase=[filebase '_' maskdispl]; % 
-                nbslice_mask=str2num(maskdispl(1:end-4)); % 
-                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
-                par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
-                if exist(par_civ2.maskname,'file')
-                    par_civ2.maskflag='y'; 
+                if exist(maskdispl,'file')
+                    par_civ2.maskname=maskdispl;
+                    par_civ2.maskflag='y';
                 else
-                    par_civ2.maskname='noFile use default';
-                    par_civ2.maskflag='n'; 
+                    maskbase=[filebase '_' maskdispl]; % 
+                    nbslice_mask=str2num(maskdispl(1:end-4)); % 
+                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
+                    par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
+                    if exist(par_civ2.maskname,'file')
+                        par_civ2.maskflag='y'; 
+                    else
+                        par_civ2.maskname='noFile use default';
+                        par_civ2.maskflag='n'; 
+                    end
                 end
             end
@@ -2510,7 +2561,7 @@
             if isequal(civAll,0)
                 if(isunix)
-                    cmd=char({cmd ; ['cp -f ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
+                    cmd=[cmd '\n' 'cp -f ' filename_cmx '2 ' filename_cmx '\n' cmd_CIV2];
                 else
-                    cmd=char({cmd ; ['copy /Y ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
+                    cmd=[cmd '\n' 'copy /Y ' filename_cmx '2 ' filename_cmx '\n' cmd_CIV2];
                 end
             else
@@ -2530,5 +2581,5 @@
      
      % FIX2
-       if box_test(5)==1
+     if box_test(5)==1
            test_mask=get(handles.get_mask_fix2,'Value');    
             if test_mask==0  
@@ -2545,5 +2596,5 @@
                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
-                cmd=char({cmd ;cmd_FIX});
+                cmd=[cmd '\n' cmd_FIX];
            else                      
                 fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
@@ -2567,80 +2618,81 @@
        
      %PATCH2
-    if box_test(6)==1
-        if isequal(civAll,0)
-            cmd_PATCH=RUN_PATCH(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp);
-            cmd=char({cmd; cmd_PATCH});
+       if box_test(6)==1
+            if isequal(civAll,0)
+                cmd_PATCH=RUN_PATCH(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp);
+                cmd=[cmd '\n' cmd_PATCH];
+            else
+                patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
+                patch2.nopt=subdomain_patch1;
+                patch2.maxdiff=thresh_patch1;
+                patch2.ro=rho_patch1;
+                test_grid=get(handles.get_gridpatch2,'Value');
+                if test_grid
+                    patch2.gridflag='y';
+                    gridname=get(handles.grid_patch2,'String');
+                    if isequal(gridname(end-3:end),'grid')
+                        nbslice_grid=str2num(gridname(1:end-4)); %
+                        if ~isempty(nbslice_grid)
+                            num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
+                            patch2.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
+                            if ~exist(patch2.gridPatch,'file')
+                               msgbox_uvmat('ERROR','grid file absent for patch2') 
+                            end
+                        elseif exist(gridname,'file')
+                            patch2.gridPatch=gridname; 
+                        else
+                            msgbox_uvmat('ERROR','grid file absent for patch2')
+                        end
+                    end
+                else
+                      patch2.gridPatch='n';
+                      patch2.gridflag='n';
+                      patch2.m=nx_patch2;
+                      patch2.n=ny_patch2;
+                end
+                patch2.convectFlow='n';
+                fieldnames=fields(patch2);
+                [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
+                for ilist=1:length(fieldnames)
+                   val=eval(['patch2.' fieldnames{ilist}]);
+                   if ischar(val)
+                      [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
+                      [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                   end
+                end             
+                civAllCmd=[civAllCmd ' patch2 '];
+            end     
+        end
+        if isequal(civAll,1)
+            save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
+            cmd=char({cmd;[Civ_exe ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
+        end
+
+      % create the .bat file:
+        if sge
+                [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
+                filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
         else
-            patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
-            patch2.nopt=subdomain_patch1;
-            patch2.maxdiff=thresh_patch1;
-            patch2.ro=rho_patch1;
-            test_grid=get(handles.get_gridpatch2,'Value');
-            if test_grid
-                 patch2.gridflag='y';
-                gridname=get(handles.grid_patch2,'String');
-                if isequal(gridname(end-3:end),'grid')
-                    nbslice_grid=str2num(gridname(1:end-4)); %
-                    if ~isempty(nbslice_grid)
-                        num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
-                        patch2.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
-                        if ~exist(patch2.gridPatch,'file')
-                           msgbox_uvmat('ERROR','grid file absent for patch2') 
-                        end
-                    elseif exist(gridname,'file')
-                        patch2.gridPatch=gridname; 
-                    else
-                        msgbox_uvmat('ERROR','grid file absent for patch2')
-                    end
-                end
+            filename_bat=filename_cmx;
+        end
+        filename_bat(end-2:end)='bat';
+        fid=fopen(filename_bat,'w');
+        fprintf(fid,cmd)
+        fclose(fid)
+        %dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
+        if sge
+            pvalue=num2str((1-ind_answer)*500);
+            namelog=[filename_bat '.patch.log'];
+            ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
+            eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
+        else
+            if(isunix)
+              cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
             else
-                  patch2.gridPatch='n';
-                  patch2.gridflag='n';
-                  patch2.m=nx_patch2;
-                  patch2.n=ny_patch2;
+               cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
             end
-            patch2.convectFlow='n';
-            fieldnames=fields(patch2);
-            [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
-            for ilist=1:length(fieldnames)
-               val=eval(['patch2.' fieldnames{ilist}]);
-               if ischar(val)
-                  [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
-                  [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
-               end
-            end             
-            civAllCmd=[civAllCmd ' patch2 '];
-        end     
-    end
-    if isequal(civAll,1)
-         civAllxml
-        save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
-        cmd=char({cmd;[Civ_exe ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
+            count= fprintf(p1,'%s\n', cmdtodo);
+        end
      end
-              
-  % create the .bat file:
-	if sge
-    		[Rootbat,Filebat,extbat]=fileparts(filename_cmx);
-    		filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
-	else
-  		filename_bat=filename_cmx;
-	end
-  filename_bat(end-2:end)='bat';
-
-    dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
-    if sge
-        pvalue=num2str((1-ind_answer)*500);
-        namelog=[filename_bat '.patch.log'];
-        ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
-        eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
-    else
-        if(isunix)
-          cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
-        else
-           cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
-        end
-        count= fprintf(p1,'%s\n', cmdtodo);
-    end
- end
 end
 if ~sge
@@ -2676,6 +2728,5 @@
 saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
 
-
-%----------------------------------------------------------
+%------------------------------------------------------------------------
 %OUTPUT:
 % filecell: structure of input and output files
@@ -2687,8 +2738,7 @@
 %         .ncA.civ1{i,j}, .ncA.civ2{i,j}; set of nc files for PIV results with camA (then .nc corresponds to camB)
 %         .st{i,j};   set of nc files for the combined stereo fields
-
 function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
     set_civ_filenames(handles,compare,box_test)
-
+%------------------------------------------------------------------------
 %get the filename root, nomenclature and numbers
 filebase=get(handles.displ_filebase,'String');
@@ -2795,8 +2845,5 @@
                 if ~exist(file_ref,'file')
                     msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                    set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
+                    filecell=[];
                     return
                 end
@@ -2849,8 +2896,5 @@
                 if ~exist(file_ref,'file')
                     msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                    set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
+                    filecell=[];
                     return
                 end
@@ -2868,5 +2912,6 @@
 [Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
 if ~exist(Path_ima,'dir')
-    warndlg_uvmat(['path to images ' Path_ima ' not found'],'ERROR')
+    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
+    filecell=[];
     return
 end
@@ -2877,4 +2922,5 @@
 if ~isempty(message) & ~isequal(message.UserWrite,1)
       msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
+      filecell=[];
       cd(currentdir);
       return
@@ -2947,9 +2993,5 @@
           if idetectmin==0,
                 msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
-                set(handles.RUN, 'Enable','On')
-                set(handles.RUN,'BackgroundColor',[1 0 0])
-                set(handles.BATCH, 'Enable','On')
-                set(handles.BATCH,'BackgroundColor',[1 0 0])
-                cd(currentdir)
+                filecell=[];
                 return
           end
@@ -2957,8 +2999,5 @@
           if idetectmin==0,
                 msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
-                set(handles.RUN, 'Enable','On')
-                set(handles.RUN,'BackgroundColor',[1 0 0])
-                set(handles.BATCH, 'Enable','On')
-                set(handles.BATCH,'BackgroundColor',[1 0 0])
+                filecell=[];
                 cd(currentdir)
                 return
@@ -2978,20 +3017,14 @@
               if idetectmin==0,
                     msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                    set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
-                      cd(currentdir)
-                      return
+                    filecell=[];
+                    cd(currentdir)
+                    return
               end
                [idetectmin,indexj]=min(idetect_1);
                if idetectmin==0,
-                    msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                    set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
-                    cd(currentdir)
-                    return
+                   msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
+                  filecell=[];
+                  cd(currentdir)
+                  return
                end
          end
@@ -3019,4 +3052,5 @@
                         set(handles.BATCH, 'Enable','On')
                     set(handles.BATCH,'BackgroundColor',[1 0 0])
+                    filecell=[];
                         cd(currentdir)
                         return
@@ -3096,8 +3130,5 @@
                 if ~exist(filename,'file')
                     msgbox_uvmat('ERROR',['input file ' filename ' not found'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                     set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
+                  filecell=[];
                     return
                 end
@@ -3107,8 +3138,5 @@
                         if isempty(Data.civ2)||isequal(Data.civ2,0)
                             msgbox_uvmat('ERROR',['no civ2 data in ' filename])
-                            set(handles.RUN, 'Enable','On')
-                            set(handles.RUN,'BackgroundColor',[1 0 0])
-                            set(handles.BATCH, 'Enable','On')
-                            set(handles.BATCH,'BackgroundColor',[1 0 0])
+                            filecell=[];
                             return
                         end  
@@ -3117,8 +3145,5 @@
                         if isempty(Data.patch)||isequal(Data.patch,0)
                             msgbox_uvmat('ERROR',['no patch data in ' filename])
-                            set(handles.RUN, 'Enable','On')
-                            set(handles.RUN,'BackgroundColor',[1 0 0])
-                            set(handles.BATCH, 'Enable','On')
-                            set(handles.BATCH,'BackgroundColor',[1 0 0])
+                            filecell=[];
                             return
                         end
@@ -3170,8 +3195,5 @@
             if idetectmin==0,
                     msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                           set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
+                    filecell=[];
                     return
             end
@@ -3192,8 +3214,5 @@
             if idetectmin==0,
                     msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                           set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
+                    filecell=[];
                     return
             end
@@ -3212,8 +3231,5 @@
                 if ~exist(filename,'file')
                     msgbox_uvmat('ERROR',['input file ' filename ' not found'])
-                    set(handles.RUN, 'Enable','On')
-                    set(handles.RUN,'BackgroundColor',[1 0 0])
-                    set(handles.BATCH, 'Enable','On')
-                    set(handles.BATCH,'BackgroundColor',[1 0 0])
+                    filecell=[];
                     return
                 else
@@ -3221,8 +3237,5 @@
                     if isempty(Data.civ2)||isequal(Data.civ2,0)         
                         msgbox_uvmat('ERROR',['no civ2 data in ' filename])
-                        set(handles.RUN, 'Enable','On')
-                        set(handles.RUN,'BackgroundColor',[1 0 0])
-                        set(handles.BATCH, 'Enable','On')
-                        set(handles.BATCH,'BackgroundColor',[1 0 0])
+                        filecell=[];
                         return
                     end
@@ -3325,8 +3338,8 @@
 end
 
-%---------------------------------------------------------
+%------------------------------------------------------------------------
 %CIV1  CIV1  CIV1 CIV1
-%----------------------------------------------------------
 function RUN_CIV1(handles,filecell,filecell_1,filecell_nc1,num1,num2,num_a,num_b,nom_type_nc)
+%------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 global civ1_exe sge%name of the executable for civ1 calculation
@@ -3490,5 +3503,40 @@
 		'ImageUsedBefore null null'};
 		textout=char(textcmx);
-		dlmwrite(filename_cmx,textout,'');
+% 		dlmwrite(filename_cmx,textout,'');
+        
+        
+     fid=fopen([filename_cmx],'w');
+fprintf(fid, ['##############   CMX file' '\n']);
+ fprintf(fid,   ['FirstImage ' filename_ima '\n' ]);
+ fprintf(fid,   ['LastImage  ' filename_ima_1 '\n' ]);
+  fprintf(fid,  ['XX' '\n' ]);
+  fprintf(fid,  ['Mask '  maskflag '\n' ]);
+  fprintf(fid,  ['MaskName '  maskname '\n' ]);
+ fprintf(fid,   ['ImageSize '  npx ' '  npy '\n' ]);   %VERIFIER CAS GENERAL ?
+ fprintf(fid,   ['CorrelationBoxesSize '  ibx ' '  iby '\n' ]);
+ fprintf(fid,   ['SearchBoxeSize '  isx ' '  isy '\n' ]);
+ fprintf(fid,   ['RO '  rho '\n' ]);
+ fprintf(fid,   ['GridSpacing '  dx ' '  dy '\n' ]);
+ fprintf(fid,   ['XX 1.0' '\n' ]);
+ fprintf(fid,   ['Dt_TO '  Dt ' '  T0 '\n' ]);
+  fprintf(fid,  ['PixCmXY '  pxcmx ' '  pxcmy '\n' ]);
+  fprintf(fid,  ['XX 1' '\n' ]);
+ fprintf(fid,   ['ShiftXY '  shiftx ' '   shifty '\n' ]);
+  fprintf(fid,  ['Grid '  gridflag '\n' ]);
+ fprintf(fid,   ['GridName '  gridname '\n' ]);
+ fprintf(fid,   ['XX 85' '\n' ]);
+ fprintf(fid,   ['XX 1.0' '\n' ]);
+ fprintf(fid,   ['XX 1.0' '\n' ]);
+ fprintf(fid,   ['Hart 1' '\n' ]);
+ fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
+ fprintf(fid,   ['Deformation 0' '\n' ]);
+  fprintf(fid,  ['CorrelationMin 0' '\n' ]);
+ fprintf(fid,   ['IntensityMin 0' '\n' ]);
+  fprintf(fid,  ['SeuilImage n' '\n' ]);
+ fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
+ fprintf(fid,   ['ImageToUse '  term_a ' '  term_b '\n' ]); % VERIFIER ?
+ fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
+fclose(fid);
+       
 		s=-1; 
         display(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog])
@@ -3504,8 +3552,8 @@
 end
 
-%---------------------------------------------------------------
+%------------------------------------------------------------------------
 % RUN CIV2   CIV2    CIV2   CIV2
-%-----------------------------------------------------------
 function RUN_CIV2(handles,filecell_2,filecell_3,filecell_nc1,filecell_nc2,num1,num2,num_a,num_b,nom_type_nc)
+%------------------------------------------------------------------------
 %filecell_2: names of first image
 %filecell_3: names of second images
@@ -3652,5 +3700,5 @@
 		['ImageUsedBefore ' filename_nc1]};
         textout=char(textcmx);
-        dlmwrite(filename_cmx,textout,'');     
+        dlmwrite(filename_cmx,textout,''); 
         s=-1;  
         display(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog])
@@ -3668,9 +3716,8 @@
 % close(h) 
 
-          
-%----------------------------------------
-%PATCH
-%---------------------------------------
+%------------------------------------------------------------------------
+% --- PATCH
 function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
+%------------------------------------------------------------------------
 global patch_exe patch_new_exe
         namelog=[filename_nc([1:end-3]) '_patch.log'];
@@ -3682,20 +3729,17 @@
                 ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
         end
-              
-%----------------------------------------
-%STEREO Interp
-%---------------------------------------
+
+%------------------------------------------------------------------------
+% --- STEREO Interp
 function cmd=RUN_STINTERP(stinterp_exe,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
+%------------------------------------------------------------------------
 namelog=[filename_nc([1:end-3]) '_stinterp.log'];
 cmd=[stinterp_exe ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
     ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
-  
-%----------------------------------------------------
-function first_j_Callback(hObject, eventdata, handles)
-last_j_Callback(hObject, eventdata, handles)
-
-%---------------------------------------------------------
+
+%------------------------------------------------------------------------
 % --- Executes on button press in CIV1.
 function CIV1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 val=get(handles.CIV1,'Value');
 if isequal(val,1)
@@ -3707,24 +3751,24 @@
 find_netcpair_civ1(hObject, eventdata, handles);
 
-%------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in FIX1.
 function FIX1_Callback(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 enable_fix1(handles,get(handles.FIX1,'Value'))
 
-
-%----------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in PATCH1.
 function PATCH1_Callback(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 if get(handles.PATCH1,'Value')==1
-enable_patch1(handles)
-else
-desable_patch1(handles)
-end
-
-%----------------------------------------------------------
+    enable_patch1(handles)
+else
+    desable_patch1(handles)
+end
+
+%------------------------------------------------------------------------
 % --- Executes on button press in CIV2.
 function CIV2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 state=get(handles.CIV2,'Value');
 enable_civ2(handles,state)
@@ -3734,7 +3778,8 @@
 end
 
-%---------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in FIX2.
 function FIX2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 if get(handles.FIX2,'Value')==1
     enable_fix2(handles)
@@ -3746,9 +3791,8 @@
 end
 
-
-%-------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in PATCH2.
 function PATCH2_Callback(hObject, eventdata, handles)
-%--------------------------------------------------------
+%------------------------------------------------------------------------
 if get(handles.PATCH2,'Value')==1
     enable_patch2(handles)
@@ -3760,16 +3804,25 @@
 end
 
-
-
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 function first_i_Callback(hObject, eventdata, handles)
-%------------------------------------------------------
-last_i_Callback(hObject, eventdata, handles)
-
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
+% last_i_Callback(hObject, eventdata, handles)
+first_i=str2num(get(handles.first_i,'String'));
+% last_i=str2num(get(handles.last_i,'String'));
+% ref_i=ceil((first_i+last_i)/2);
+set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
+ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
+
+%------------------------------------------------------------------------
+function first_j_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+first_j=str2num(get(handles.first_j,'String'));
+set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
+ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
+
+%------------------------------------------------------------------------
 % --- Executes on button press in calcul_search: determine the search range isx,isy
-%--------------------------------------------------------
 function calcul_search_Callback(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 %determine pair numbers
 list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
@@ -3820,9 +3873,8 @@
 set(handles.isy,'String',num2str(isy));
 
-
-%---------------------------------------------------------
-% Executes on carriage return on the subdir civ1 edit window
-%--------------------------------------------------------
+%------------------------------------------------------------------------
+% --- Executes on carriage return on the subdir civ1 edit window
 function subdir_civ1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 subdir=get(handles.subdir_civ1,'String');
 set(handles.subdir_civ2,'String',subdir);
@@ -3831,8 +3883,8 @@
 end
 
-%---------------------------------------------------------
-% Executes on carriage return on the subdir civ1 edit window
-%---------------------------------------------------------
+%------------------------------------------------------------------------
+% --- Executes on carriage return on the subdir civ1 edit window
 function subdir_civ2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 %update the list of available pairs from netcdf files in the new directory
 if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
@@ -3840,8 +3892,8 @@
 end
 
-%------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in get_mask_civ1.
-%------------------------------------------------------
 function get_mask_civ1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 maskval=get(handles.get_mask_civ1,'Value');
 if isequal(maskval,0)
@@ -3857,7 +3909,18 @@
             filebase_a=fullfile(common_path,get(handles.displ_filebase2,'String'));
             [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
-            if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice_mask)
+            if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
                 mask_displ='no mask';
             end
+    end
+    if isequal(mask_displ,'no mask')
+        [FileName, PathName, filterindex] = uigetfile( ...
+               {'*.png', ' (*.png)';
+                '*.png',  '.png files '; ...
+                '*.*', 'All Files (*.*)'}, ...
+                'Pick a mask file *.png',filebase);
+        mask_displ=fullfile(PathName,FileName);  
+        if ~exist(mask_displ,'file')
+            mask_displ='no mask';
+        end
     end
     if isequal(mask_displ,'no mask')
@@ -3876,7 +3939,8 @@
 end
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in get_mask_fix1.
 function get_mask_fix1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 maskval=get(handles.get_mask_fix1,'Value');
 if isequal(maskval,0)
@@ -3896,4 +3960,15 @@
 end
 if isequal(mask_displ,'no mask')
+    [FileName, PathName, filterindex] = uigetfile( ...
+           {'*.png', ' (*.png)';
+            '*.png',  '.png files '; ...
+            '*.*', 'All Files (*.*)'}, ...
+            'Pick a mask file *.png',filebase);
+    mask_displ=fullfile(PathName,FileName);  
+    if ~exist(mask_displ,'file')
+        mask_displ='no mask';
+    end
+end
+if isequal(mask_displ,'no mask')
     set(handles.get_mask_fix1,'Value',0)
     set(handles.get_mask_civ2,'Value',0)
@@ -3907,7 +3982,9 @@
 set(handles.mask_fix2,'String',mask_displ)
 end
-%-----------------------------------------
+
+%------------------------------------------------------------------------
 % --- Executes on button press in get_mask_civ2.
 function get_mask_civ2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 maskval=get(handles.get_mask_civ2,'Value');
 if isequal(maskval,0)
@@ -3927,4 +4004,15 @@
 end
 if isequal(mask_displ,'no mask')
+    [FileName, PathName, filterindex] = uigetfile( ...
+           {'*.png', ' (*.png)';
+            '*.png',  '.png files '; ...
+            '*.*', 'All Files (*.*)'}, ...
+            'Pick a mask file *.png',filebase);
+    mask_displ=fullfile(PathName,FileName);
+    if ~exist(mask_displ,'file')
+        mask_displ='no mask';
+    end
+end
+if isequal(mask_displ,'no mask')
     set(handles.get_mask_civ2,'Value',0)
     set(handles.get_mask_fix2,'Value',0)
@@ -3935,31 +4023,46 @@
 set(handles.mask_fix2,'String',mask_displ)
 end
-%-------------------------------------
+
+%------------------------------------------------------------------------
 % --- Executes on button press in get_mask_fix2.
 function get_mask_fix2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 maskval=get(handles.get_mask_fix2,'Value');
 if isequal(maskval,0)
     set(handles.mask_fix2,'String','')
 else
-mask_displ='no mask'; %default
-filebase=get(handles.displ_filebase,'String');
-[nbslice, flag_mask]=get_mask(filebase,handles);
-if isequal(flag_mask,1)
-      mask_displ=[num2str(nbslice) 'mask'];
-elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
-        filebase_a=get(handles.displ_filebase2,'String');
-        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
-        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+    mask_displ='no mask'; %default
+    filebase=get(handles.displ_filebase,'String');
+    [nbslice, flag_mask]=get_mask(filebase,handles);
+    if isequal(flag_mask,1)
+          mask_displ=[num2str(nbslice) 'mask'];
+    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
+            filebase_a=get(handles.displ_filebase2,'String');
+            [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
+            if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
+                mask_displ='no mask';
+            end
+    end
+    if isequal(mask_displ,'no mask')
+        [FileName, PathName, filterindex] = uigetfile( ...
+               {'*.png', ' (*.png)';
+                '*.png',  '.png files '; ...
+                '*.*', 'All Files (*.*)'}, ...
+                'Pick a mask file *.png',filebase);
+        mask_displ=fullfile(PathName,FileName);  
+        if ~exist(mask_displ,'file')
             mask_displ='no mask';
         end
-end
-if isequal(mask_displ,'no mask')
-    set(handles.get_mask_fix2,'Value',0)
-end 
-set(handles.mask_fix2,'String',mask_displ)
-end
-
-%---------------------------------------
+    end
+    if isequal(mask_displ,'no mask')
+        set(handles.get_mask_fix2,'Value',0)
+    end 
+    set(handles.mask_fix2,'String',mask_displ)
+end
+
+%------------------------------------------------------------------------
+% --- function called to look for mask files
 function [nbslice, flag_mask]=get_mask(filebase,handles)
+%------------------------------------------------------------------------
 %detect mask files, images with appropriate file base 
 %[filebase '_' xx 'mask'], xx=nbslice
@@ -3971,11 +4074,15 @@
 % subdir=get(handles.subdir_civ1,'String');
 [Path,Name]=fileparts(filebase);
+if ~isdir(Path)
+    msgbox_uvmat('ERROR','no path for input files')
+    return
+end
 currentdir=pwd;
 cd(Path);%move in the dir of the root name filebase
 maskfiles=dir([Name '_*mask_*.png']);%look for mask files
 cd(currentdir);%come back to the current working directory
-if isempty(maskfiles)
-    msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
-else
+if ~isempty(maskfiles)
+%     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
+% else
     flag_mask=1;
     maskname=maskfiles(1).name;% take the first mask file in the list
@@ -3998,7 +4105,8 @@
 end    
 
-%---------------------------------------
+%------------------------------------------------------------------------
+% --- function called to look for grid files
 function [nbslice, flag_mask]=get_grid(filebase,handles)
-
+%------------------------------------------------------------------------
 flag_mask=0;%default
 nbslice=1;
@@ -4027,20 +4135,10 @@
           nbslice=1;
     end
-end    
-%------------------------------
-
-function grid_civ1_Callback(hObject, eventdata, handles)
-% hObject    handle to grid_civ1 (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 grid_civ1 as text
-%        str2double(get(hObject,'String')) returns contents of grid_civ1 as a double
-
-
-%-----------------------------------------------------------
-% transform numbers to letters
-%--------------------------------------------
+end
+
+%------------------------------------------------------------------------
+% --- transform numbers to letters
 function str=num2stra(num,nom_type);
+%------------------------------------------------------------------------
 if isequal(nom_type,'png_old') | isequal(nom_type,'netc_old') |isequal(nom_type,'raw_SMD')
     str=char(96+num);
@@ -4051,24 +4149,33 @@
     str=num2str(num);
 end
-%---------------------------------------------------
+
+%------------------------------------------------------------------------
 function mask_civ1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 set(handles.mask_civ1,'UserData',[])
 set(handles.mask_civ1,'String','')
-%----------------------------------------------------
+
+%------------------------------------------------------------------------
 function mask_civ2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 set(handles.mask_civ2,'UserData',[])
 set(handles.mask_civ2,'String','')
-%----------------------------------------------------
+
+%------------------------------------------------------------------------
 function mask_fix1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 set(handles.mask_fix1,'UserData',[])
 set(handles.mask_fix1,'String','')
-%----------------------------------------------------
+
+%------------------------------------------------------------------------
 function mask_fix2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 set(handles.mask_fix2,'UserData',[])
 set(handles.mask_fix2,'String','')
 
-%--------------------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in list_subdir_civ1.
 function list_subdir_civ1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 list_subdir_civ1=get(handles.list_subdir_civ1,'String');
 val=get(handles.list_subdir_civ1,'Value');
@@ -4079,8 +4186,8 @@
 end
 
-
-%--------------------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in list_subdir_civ2.
 function list_subdir_civ2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 list_subdir_civ2=get(handles.list_subdir_civ2,'String');
 val=get(handles.list_subdir_civ2,'Value');
@@ -4091,26 +4198,8 @@
 end
 
-
-%----------------------------------------------
-function last_i_Callback(hObject, eventdata, handles)
-first_i=str2num(get(handles.first_i,'String'));
-last_i=str2num(get(handles.last_i,'String'));
-ref_i=ceil((first_i+last_i)/2);
-set(handles.ref_i,'String', num2str(ref_i))
-ref_i_Callback(hObject, eventdata, handles)
-
-%-------------------------------------------------------
-function last_j_Callback(hObject, eventdata, handles)
-first_j=str2num(get(handles.first_j,'String'));
-last_j=str2num(get(handles.last_j,'String'));
-ref_j=ceil((first_j+last_j)/2);
-set(handles.ref_j,'String', num2str(ref_j))
-ref_j_Callback(hObject, eventdata, handles)
-
-
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in browse_gridciv1.
 function browse_gridciv1_Callback(hObject, eventdata, handles)
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 value=get(handles.browse_gridciv1,'Value');
 testgrid=0;
@@ -4160,8 +4249,8 @@
 end
 
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in browse_gridciv1.
 function browse_gridciv2_Callback(hObject, eventdata, handles)
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 value=get(handles.browse_gridciv2,'Value');
 if value
@@ -4231,11 +4320,12 @@
 % set(handles.grid_patch2,'string',filegrid
 
-%-----------------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in get_gridpatch2.
 function get_gridpatch2_Callback(hObject, eventdata, handles)
-
-
-%----------------------------------------------------------
+%------------------------------------------------------------------------
+
+%------------------------------------------------------------------------
 function enable_civ1(handles,state)
+%------------------------------------------------------------------------
 if isequal(state,0)
     state='off';
@@ -4293,6 +4383,7 @@
 set(handles.rho_title,'Visible',state)
 
-%----------------------------------------------------------
+%------------------------------------------------------------------------
 function enable_fix1(handles,state)
+%------------------------------------------------------------------------
 if isequal(state,0)
     state='off';
@@ -4321,7 +4412,7 @@
 set(handles.field_ref1,'Visible',state)
 
-
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 function enable_patch1(handles)
+%------------------------------------------------------------------------
 global patch_new_exe
 set(handles.frame_patch1,'BackgroundColor',[1 1 0])
@@ -4343,6 +4434,7 @@
 set(handles.grid_patch1,'Visible','on')
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 function desable_patch1(handles)
+%------------------------------------------------------------------------
 set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
 set(handles.rho_patch1,'Visible','off')
@@ -4360,6 +4452,7 @@
 set(handles.grid_patch1,'Visible','off')
 
-%----------------------------------------------------------
+%------------------------------------------------------------------------
 function enable_civ2(handles,state)
+%------------------------------------------------------------------------
 if isequal(state,0)
     state='off';
@@ -4415,7 +4508,7 @@
 end
 
-
-%----------------------------------------------------------
+%------------------------------------------------------------------------
 function enable_fix2(handles)
+%------------------------------------------------------------------------
 set(handles.frame_fix2,'BackgroundColor',[1 1 0])
 set(handles.REMOVE2,'Visible','on')
@@ -4437,6 +4530,7 @@
 set(handles.field_ref2,'Visible','on')
 
-%----------------------------------------------------------
+%------------------------------------------------------------------------
 function desable_fix2(handles)
+%------------------------------------------------------------------------
 set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
 set(handles.REMOVE2,'Visible','off')
@@ -4460,6 +4554,7 @@
 end
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 function enable_patch2(handles)
+%------------------------------------------------------------------------
 set(handles.frame_patch2,'BackgroundColor',[1 1 0])
 %set(handles.rho_patch2,'Visible','on')
@@ -4479,6 +4574,7 @@
 set(handles.subdir_civ2_text,'Visible','on')
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 function desable_patch2(handles)
+%------------------------------------------------------------------------
 set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
 set(handles.rho_patch2,'Visible','off')
@@ -4500,6 +4596,7 @@
 end
 
-%--------------------------------------------------------------
+%------------------------------------------------------------------------
 function enable_pair1(handles,state)
+%------------------------------------------------------------------------
 set(handles.subdir_civ1,'Visible',state)
 set(handles.list_subdir_civ1,'Visible',state)
@@ -4508,26 +4605,12 @@
 set(handles.list_pair_civ1,'Visible',state)
 set(handles.PAIR_txt,'Visible',state)
-set(handles.dt_display_txt,'Visible',state)
+%set(handles.dt_display_txt,'Visible',state)
 set(handles.dt_unit,'Visible',state)
 set(handles.PAIR_frame,'Visible',state)
 
-% --- Executes on button press in test_interp.
-function test_interp_Callback(hObject, eventdata, handles)
-% hObject    handle to test_interp (see GCBO)
-% eventdata  reserved - to be defined in a future version of MATLAB
-% handles    structure with handles and user data (see GUIDATA)
-
-% Hint: get(hObject,'Value') returns toggle state of test_interp
-
-
-
-
-
-
-%------------------------------------------------
-%Read the parameters for civ1 on the interface
-%--------------------------------------------------
+%------------------------------------------------------------------------
+% --- Read the parameters for civ1 on the interface
 function par=read_param_civ1(handles,file_ima)
-
+%------------------------------------------------------------------------
 ibx_val=str2num(get(handles.ibx,'String'));
 par.ibx=num2str(ibx_val);
@@ -4551,91 +4634,91 @@
          par.isy='41'; %default
          set(handles.isy,'String','41');
-end;
+end
 if isempty(str2num(par.shiftx))
          par.shiftx='0';%default
          set(handles.shiftx,'String','0');
-end; 
+end 
 if isempty(str2num(par.shifty))
          par.shifty='0'; %default
          set(handles.shifty,'String','0');
-end;
-     par.rho=get(handles.rho,'String');
-     par.dx=get(handles.dx_civ1,'String');
-     par.dy=get(handles.dy_civ1,'String');
-     if isequal(str2num(par.dx),[]) 
-         if isempty(get(handles.grid_civ1,'String'));
-             par.dx='0'; %just read by civ program, not used
-         else
-            par.dx='20';%default
-            set(handles.dx_civ1,'String','20');
-         end
+end
+ par.rho=get(handles.rho,'String');
+ par.dx=get(handles.dx_civ1,'String');
+ par.dy=get(handles.dy_civ1,'String');
+ if isequal(str2num(par.dx),[]) 
+     if isempty(get(handles.grid_civ1,'String'));
+         par.dx='0'; %just read by civ program, not used
+     else
+        par.dx='20';%default
+        set(handles.dx_civ1,'String','20');
      end
-     if isequal(str2num(par.dy),[])
-         if isempty(get(handles.grid_civ1,'String'));
-             par.dy='0';%just read by civ program, not used
-         else
-            par.dy='20';%default
-            set(handles.dy_civ1_title,'String','20');
-         end
+ end
+ if isequal(str2num(par.dy),[])
+     if isempty(get(handles.grid_civ1,'String'));
+         par.dy='0';%just read by civ program, not used
+     else
+        par.dy='20';%default
+        set(handles.dy_civ1_title,'String','20');
      end
-        par.pxcmx='1'; %velocities are expressed in pixel dispalcement
-         par.pxcmy='1';
+ end
+    par.pxcmx='1'; %velocities are expressed in pixel dispalcement
+     par.pxcmy='1';
 %      end
-     A=imread(file_ima);%read the first image to get the size
-     sizim=size(A);
-     par.npx=num2str(sizim(2));
-     par.npy=num2str(sizim(1));
-     time=get(handles.displ_filebase,'UserData'); %get the set of times
-     par.gridname=get(handles.grid_civ1,'String');
-     par.gridflag='y';
-     if isequal(par.gridname,'')| isempty(par.gridname)
-         par.gridname='nogrid';
-         par.gridflag='n';
+ A=imread(file_ima);%read the first image to get the size
+ sizim=size(A);
+ par.npx=num2str(sizim(2));
+ par.npy=num2str(sizim(1));
+ time=get(handles.displ_filebase,'UserData'); %get the set of times
+ par.gridname=get(handles.grid_civ1,'String');
+ par.gridflag='y';
+ if isequal(par.gridname,'')| isempty(par.gridname)
+     par.gridname='nogrid';
+     par.gridflag='n';
+ end
+
+%------------------------------------------------------------------------
+function par=read_param_civ2(handles,file_ima)
+%------------------------------------------------------------------------
+par.ibx=get(handles.ibx_civ2,'String');
+par.iby=get(handles.iby_civ2,'String');
+par.rho=get(handles.rho_civ2,'String');
+par.decimal=int2str(get(handles.decimal,'Value'));
+par.deformation=int2str(get(handles.deformation,'Value'));
+par.dx=get(handles.dx_civ2,'String');
+par.dy=get(handles.dy_civ2,'String');
+if isequal(str2num(par.dx),[]) 
+     if isempty(get(handles.grid_civ2,'String'));
+         par.dx='0'; %just read by civ program, not used
+     else
+        par.dx='20';%default
+        set(handles.dx_civ2,'String','20');
      end
-     
-%----------------------------------------------------------------
-function par=read_param_civ2(handles,file_ima)
-    par.ibx=get(handles.ibx_civ2,'String');
-    par.iby=get(handles.iby_civ2,'String');
-    par.rho=get(handles.rho_civ2,'String');
-    par.decimal=int2str(get(handles.decimal,'Value'));
-    par.deformation=int2str(get(handles.deformation,'Value'));
-    par.dx=get(handles.dx_civ2,'String');
-    par.dy=get(handles.dy_civ2,'String');
-    if isequal(str2num(par.dx),[]) 
-         if isempty(get(handles.grid_civ2,'String'));
-             par.dx='0'; %just read by civ program, not used
-         else
-            par.dx='20';%default
-            set(handles.dx_civ2,'String','20');
-         end
+ end
+ if isequal(str2num(par.dy),[])
+     if isempty(get(handles.grid_civ2,'String'));
+         par.dy='0';%just read by civ program, not used
+     else
+        par.dy='20';%default
+        set(handles.dy_civ2,'String','20');
      end
-     if isequal(str2num(par.dy),[])
-         if isempty(get(handles.grid_civ2,'String'));
-             par.dy='0';%just read by civ program, not used
-         else
-            par.dy='20';%default
-            set(handles.dy_civ2,'String','20');
-         end
-     end
-     par.pxcmx='1';
-     par.pxcmy='1';
-    A=imread(file_ima);%read the first image to get the size
-    sizim=size(A);
-    par.npx=num2str(sizim(2));
-    par.npy=num2str(sizim(1));
-    time=get(handles.displ_filebase,'UserData'); %get the set of times
-    par.gridname=get(handles.grid_civ2,'String');
-    par.gridflag='y';
-    if isequal(par.gridname,'')| isempty(par.gridname)
-        par.gridname='nogrid';
-        par.gridflag='n';
-    end
-
-
-%---------------------------------------------------------
-%CIV1  CIV1  CIV1 CIV1
-%----------------------------------------------------------
+ end
+ par.pxcmx='1';
+ par.pxcmy='1';
+A=imread(file_ima);%read the first image to get the size
+sizim=size(A);
+par.npx=num2str(sizim(2));
+par.npy=num2str(sizim(1));
+time=get(handles.displ_filebase,'UserData'); %get the set of times
+par.gridname=get(handles.grid_civ2,'String');
+par.gridflag='y';
+if isequal(par.gridname,'')| isempty(par.gridname)
+    par.gridname='nogrid';
+    par.gridflag='n';
+end
+
+%------------------------------------------------------------------------
+% --- CIV1  CIV1  CIV1 CIV1
 function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles)
+%------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 global civ1_exe Civ_exe sge%name of the executable for civ1 calculation
@@ -4646,58 +4729,88 @@
                 par.Dt='1' ;%case of 'displacement' mode
             end         
- 
-    textcmx={'##############   CMX file';...
-    ['FirstImage ' par.filename_ima_a];...
-    ['LastImage  ' par.filename_ima_b];...
-    'XX' ;...
-    ['Mask ' par.maskflag] ;...
-    ['MaskName ' par.maskname];...
-    ['ImageSize ' par.npx ' ' par.npy];...   %VERIFIER CAS GENERAL ?
-    ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
-    ['SearchBoxeSize ' par.isx ' ' par.isy];...
-    ['RO ' par.rho];...
-    ['GridSpacing ' par.dx ' ' par.dy];...
-    'XX 1.0';...
-    ['Dt_TO ' par.Dt ' ' par.T0];...
-    ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
-    'XX 1';...
-    ['ShiftXY ' par.shiftx ' '  par.shifty];...
-    ['Grid ' par.gridflag];...
-    ['GridName ' par.gridname] ;...
-    'XX 85';...
-    'XX 1.0';...
-    'XX 1.0';...
-    'Hart 1';...
-    'DecimalShift 0';...
-    'Deformation 0';...
-    'CorrelationMin 0';...
-    'IntensityMin 0';...
-    'SeuilImage n';...
-    'SeuilImageValues 0 4096';...
-    ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
-    'ImageUsedBefore null null'};
-
-            textout=char(textcmx);
-    %         timeL1=clock;
-            dlmwrite([filename '.cmx'],textout,'');
-    %             timeL2=clock;
-    %     timciv1=etime(timeL2,timeL1)
-          if sge  
-          cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
-          else
-              cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
-          end
-    if(isunix)
-    	[Rootbat,Filebat,extbat]=fileparts(namelog);
-    	ncName=fullfile(Rootbat,[ Filebat '.nc']);
-	    cmd_CIV1=char({cmd_CIV1 ; ['mv ' namelog  ' ' namelog '.civ1.log'];['chmod g+w ' ncName]});
-    else
-        cmd_CIV1=char({cmd_CIV1 ; ['copy /Y ' namelog ' ' namelog '.civ1.log']});
-    end
-
-%---------------------------------------------------------
-%CIV1  Unified
-%----------------------------------------------------------
+%  
+%     textcmx={'##############   CMX file';...
+%     ['FirstImage ' par.filename_ima_a];...
+%     ['LastImage  ' par.filename_ima_b];...
+%     'XX' ;...
+%     ['Mask ' par.maskflag] ;...
+%     ['MaskName ' par.maskname];...
+%     ['ImageSize ' par.npx ' ' par.npy];...   %VERIFIER CAS GENERAL ?
+%     ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
+%     ['SearchBoxeSize ' par.isx ' ' par.isy];...
+%     ['RO ' par.rho];...
+%     ['GridSpacing ' par.dx ' ' par.dy];...
+%     'XX 1.0';...
+%     ['Dt_TO ' par.Dt ' ' par.T0];...
+%     ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
+%     'XX 1';...
+%     ['ShiftXY ' par.shiftx ' '  par.shifty];...
+%     ['Grid ' par.gridflag];...
+%     ['GridName ' par.gridname] ;...
+%     'XX 85';...
+%     'XX 1.0';...
+%     'XX 1.0';...
+%     'Hart 1';...
+%     'DecimalShift 0';...
+%     'Deformation 0';...
+%     'CorrelationMin 0';...
+%     'IntensityMin 0';...
+%     'SeuilImage n';...
+%     'SeuilImageValues 0 4096';...
+%     ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
+%     'ImageUsedBefore null null'};
+% 
+%             textout=char(textcmx);
+
+   fid=fopen([filename '.cmx'],'w');
+fprintf(fid,['##############   CMX file' '\n' ]);
+ fprintf(fid,   ['FirstImage ' par.filename_ima_a '\n' ]);
+ fprintf(fid,   ['LastImage  ' par.filename_ima_b '\n' ]);
+  fprintf(fid,  ['XX' '\n' ]);
+  fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
+  fprintf(fid,  ['MaskName ' par.maskname '\n' ]);
+ fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
+ fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
+ fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
+ fprintf(fid,   ['RO ' par.rho '\n' ]);
+ fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
+ fprintf(fid,   ['XX 1.0' '\n' ]);
+ fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
+  fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
+  fprintf(fid,  ['XX 1' '\n' ]);
+ fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
+  fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
+ fprintf(fid,   ['GridName ' par.gridname '\n' ]);
+ fprintf(fid,   ['XX 85' '\n' ]);
+ fprintf(fid,   ['XX 1.0' '\n' ]);
+ fprintf(fid,   ['XX 1.0' '\n' ]);
+ fprintf(fid,   ['Hart 1' '\n' ]);
+ fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
+ fprintf(fid,   ['Deformation 0' '\n' ]);
+  fprintf(fid,  ['CorrelationMin 0' '\n' ]);
+ fprintf(fid,   ['IntensityMin 0' '\n' ]);
+  fprintf(fid,  ['SeuilImage n' '\n' ]);
+ fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
+ fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
+ fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
+fclose(fid);
+  
+if sge  
+    cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
+else
+    cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+end
+if(isunix)
+    [Rootbat,Filebat,extbat]=fileparts(namelog);
+    ncName=fullfile(Rootbat,[ Filebat '.nc']);
+    cmd_CIV1=[cmd_CIV1 '\n' 'mv ' namelog  ' ' namelog '.civ1.log' '\n' 'chmod g+w ' ncName];
+else
+    cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y ' namelog ' ' namelog '.civ1.log'];
+end
+
+%------------------------------------------------------------------------
+% --- CIV1  Unified
 function xml_civ1_parameters=BATCH_CIV1_Unified(filename,namelog,par)
+%------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 global civ1_exe Civ_exe%name of the executable for civ1 calculation
@@ -4734,9 +4847,9 @@
   
     xml_civ1_parameters=civ1;
-    
-%---------------------------------------------------------
-%CIV2  Unified
-%----------------------------------------------------------
+
+%------------------------------------------------------------------------
+% --- CIV2  Unified
 function civ2=BATCH_CIV2_Unified(filename,namelog,par)
+%------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 global civ2_exe Civ_exe%name of the executable for civ1 calculation
@@ -4787,8 +4900,8 @@
 civ2.convectFlow='n';
 
-%---------------------------------------------------------
-%CIV2  CIV2  CIV2 CIV2
-%----------------------------------------------------------
+%------------------------------------------------------------------------
+% --- CIV2  CIV2  CIV2 CIV2
 function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
+%------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 global civ2_exe sge%name of the executable for civ1 calculation
@@ -4796,45 +4909,48 @@
                 par.Dt='1' ;%case of 'displacement' mode
   end 
-textcmx={'##############   CMX file';...
-['FirstImage ' par.filename_ima_a];...
-['LastImage  ' par.filename_ima_b];...
-'XX' ;...
-['Mask ' par.maskflag];...
-['MaskName ' par.maskname];...
-['ImageSize ' par.npx ' ' par.npy];...   
-['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
-['SearchBoxeSize ' par.ibx ' ' par.iby];...
-['RO ' par.rho];...
-['GridSpacing ' par.dx ' ' par.dy];...
-'XX 1.0';...
-['Dt_TO ' par.Dt ' ' par.T0];...
-['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
-'XX 1';...
-['ShiftXY 0 0'];...
-['Grid ' par.gridflag];...
-['GridName ' par.gridname];...
-'XX 85';...
-'XX 1.0';...
-'XX 1.0';...
-'Hart 1';...
-['DecimalShift ' par.decimal];...
-['Deformation ' par.deformation];...
-'CorrelationMin 0';...
-'IntensityMin 0';...
-'SeuilImage n';...
-'SeuilImageValues 0 4096';...
-['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
-['ImageUsedBefore ' par.filename_nc1]};
-        textout=char(textcmx);
-        dlmwrite([filename_cmx '2'] ,textout,'');
-        if sge
-        cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
-        else
-          cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
-      end
-
-
+textcmx=['##############   CMX file'  '\n'...
+['FirstImage ' par.filename_ima_a]  '\n'...
+['LastImage  ' par.filename_ima_b]  '\n'...
+'XX'   '\n'...
+['Mask ' par.maskflag]  '\n'...
+['MaskName ' par.maskname]  '\n'...
+['ImageSize ' par.npx ' ' par.npy]  '\n'...   
+['CorrelationBoxesSize ' par.ibx ' ' par.iby]  '\n'...
+['SearchBoxeSize ' par.ibx ' ' par.iby]  '\n'...
+['RO ' par.rho]  '\n'...
+['GridSpacing ' par.dx ' ' par.dy]  '\n'...
+'XX 1.0'  '\n'...
+['Dt_TO ' par.Dt ' ' par.T0]  '\n'...
+['PixCmXY ' par.pxcmx ' ' par.pxcmy]  '\n'...
+'XX 1'  '\n'...
+['ShiftXY 0 0']  '\n'...
+['Grid ' par.gridflag]  '\n'...
+['GridName ' par.gridname]  '\n'...
+'XX 85'  '\n'...
+'XX 1.0'  '\n'...
+'XX 1.0'  '\n'...
+'Hart 1'  '\n'...
+['DecimalShift ' par.decimal]  '\n'...
+['Deformation ' par.deformation]  '\n'...
+'CorrelationMin 0'  '\n'...
+'IntensityMin 0'  '\n'...
+'SeuilImage n'  '\n'...
+'SeuilImageValues 0 4096'  '\n'...
+['ImageToUse ' par.term_a ' ' par.term_b]  '\n'... % VERIFIER ?
+['ImageUsedBefore ' par.filename_nc1]];
+textout=char(textcmx);
+fid=fopen([filename_cmx '2'],'w');
+fprintf(fid,textout); 
+fclose(fid)
+if sge
+    cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
+else
+    cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
+end
+
+%------------------------------------------------------------------------
 % --- Executes on button press in HELP.
 function HELP_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 path_to_uvmat=which ('uvmat');% check the path of uvmat
 pathelp=fileparts(path_to_uvmat);
@@ -4845,8 +4961,8 @@
 end
 
-
-%----------------------------------------------------------
+%------------------------------------------------------------------------
 %--read images and convert them to the uint16 format used for PIV
 function A=read_image(filename,nom_type,npx,npy,num);
+%------------------------------------------------------------------------
 %npx, npy are the dimensions needed for the raw SMD images
 %num is the view number needed for an avi movie
@@ -4870,44 +4986,46 @@
     A=uint16(A);
 end
-        
-%----------------------------------------------------------------
-%Executes on carriage return on the time interval dt
-%----------------------------------------------------------------
-function dt_Callback(hObject, eventdata, handles)
-%determine the set of times and possible intervals for CIV
-%                 answer=inputdlg('time interval between images?');
-                dt=(1/1000)*str2num(get(handles.dt,'String'));
-                nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
-                time=(dt*[0:nbfield-1])';
-%                 set(handles.incr_i,'UserData',dt);%store the time interval between successive images
-                set(handles.displ_filebase,'UserData',time); %store the set of times
-                for index=1:min(nbfield-1,200)
-                    displ_num(1,index)=1;
-                    displ_num(2,index)=1;
-                    displ_num(3,index)=-floor(index/2);
-                    displ_num(4,index)=ceil(index/2);
-                end
-set(handles.list_pair_civ1,'Value',1);
-set(handles.list_pair_civ1,'UserData',displ_num);
-set(handles.list_pair_civ2,'Value',1);
-%update the list of time intervals
-find_netcpair_civ1(hObject, eventdata, handles)
-find_netcpair_civ2(hObject, eventdata, handles)
-
-%-------------------------------------------------------
+
+% %----------------------------------------------------------------
+% %Executes on carriage return on the time interval dt
+% %----------------------------------------------------------------
+% function dt_Callback(hObject, eventdata, handles)
+% %determine the set of times and possible intervals for CIV
+% %                 answer=inputdlg('time interval between images?');
+%                 dt=(1/1000)*str2num(get(handles.dt,'String'));
+%                 nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
+%                 time=(dt*[0:nbfield-1])';
+% %                 set(handles.incr_i,'UserData',dt);%store the time interval between successive images
+%                 set(handles.displ_filebase,'UserData',time); %store the set of times
+%                 for index=1:min(nbfield-1,200)
+%                     displ_num(1,index)=1;
+%                     displ_num(2,index)=1;
+%                     displ_num(3,index)=-floor(index/2);
+%                     displ_num(4,index)=ceil(index/2);
+%                 end
+% set(handles.list_pair_civ1,'Value',1);
+% set(handles.list_pair_civ1,'UserData',displ_num);
+% set(handles.list_pair_civ2,'Value',1);
+% %update the list of time intervals
+% find_netcpair_civ1(hObject, eventdata, handles)
+% find_netcpair_civ2(hObject, eventdata, handles)
+
+%------------------------------------------------------------------------
 function ref_i_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 mode_list=get(handles.mode,'String');
 mode_value=get(handles.mode,'Value');
 mode=mode_list{mode_value};
-if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Di)') 
+%if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Di)') 
     find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
-end
-if isequal(mode,'series(Di)') | ...% we do patch2 only
+%end
+if isequal(mode,'series(Di)') || ...% we do patch2 only
    (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
     find_netcpair_civ2(hObject, eventdata, handles);
 end
 
-%----------------------------------------------------
+%------------------------------------------------------------------------
 function ref_j_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 mode_list=get(handles.mode,'String');
 mode_value=get(handles.mode,'Value');
@@ -4920,7 +5038,9 @@
     find_netcpair_civ2(hObject, eventdata, handles);
 end
-%----------------------------------------------------
+
+%------------------------------------------------------------------------
 % --- Executes on button press in compare.
 function compare_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 test=get(handles.compare,'Value');
 if test==2 || test==3    
@@ -4988,7 +5108,8 @@
 mode_Callback(hObject, eventdata, handles)
 
-%-----------------------------------------------------------
+%------------------------------------------------------------------------
 % --- Executes on button press in get_ref_fix1.
 function get_ref_fix1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 filebase=get(handles.displ_filebase,'String');
 [FileName, PathName, filterindex] = uigetfile( ...
@@ -5001,9 +5122,5 @@
 sizf=size(fileinput);
 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
-%[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
 [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
-%filebase=fullfile(RootPath,RootFile);
-% [Pth,FileN]=fileparts(filebasesub);
-% Pth=fileparts(Pth);
 ref.filebase=fullfile(Path,File);
 ref.num_a=stra2num(str_a);
@@ -5016,5 +5133,4 @@
     return
 end
-% [path,name]=fileparts(ref.filebase);
 set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
 set(handles.ref_fix1,'UserData',ref)
@@ -5030,14 +5146,4 @@
     menu_field{4}='filter2';
 end
-% [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
-% if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
-%          menu_field{2}='filter1';
-% end
-% if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
-%          menu_field{3}='civ2';
-% end
-% if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
-%          menu_field{4}='filter2';
-% end
 set(handles.field_ref1,'String',menu_field);
 set(handles.field_ref1,'Value',length(menu_field));
@@ -5045,8 +5151,9 @@
 set(handles.thresh_vel,'String','1');%default threshold
 set(handles.ref_fix1,'Enable','on')
- 
-%---------------------------------------------------------------
+
+%------------------------------------------------------------------------
 % --- Executes on button press in get_ref_fix2.
 function get_ref_fix2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 if isequal(get(handles.get_ref_fix2,'Value'),1)
     filebase=get(handles.displ_filebase,'String');
@@ -5059,8 +5166,5 @@
     sizf=size(fileinput);
     if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
-    %[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
     [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
-%     [Pth,FileN]=fileparts(filebasesub);
-%     Pth=fileparts(Pth);
     ref.filebase=fullfile(Path,File);
     ref.num_a=stra2num(str_a);
@@ -5073,9 +5177,7 @@
         return
     end
-%     [path,name]=fileparts(ref.filebase);
     set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
     set(handles.ref_fix2,'UserData',ref)    
     menu_field{1}='civ1';
-%     [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
     Data=nc2struct(fileinput,[]);
     if isfield(Data,'patch') & isequal(Data.patch,1)
@@ -5088,14 +5190,4 @@
         menu_field{4}='filter2';
     end
-
-%     if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
-%              menu_field{2}='filter1';
-%     end
-%     if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
-%              menu_field{3}='civ2';
-%     end
-%     if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
-%              menu_field{4}='filter2';
-%     end
     set(handles.field_ref2,'String',menu_field);
     set(handles.field_ref2,'Value',length(menu_field));
@@ -5109,44 +5201,29 @@
     set(handles.field_ref2,'Visible','off')
 end
-%-------------------------------------------------------
-
+
+%------------------------------------------------------------------------
 function ref_fix1_Callback(hObject, eventdata, handles)
-    set(handles.inf_sup1,'Value',1);
-    set(handles.field_ref1,'Value',1)
-    set(handles.field_ref1,'String',{' '})
-    set(handles.ref_fix1,'UserData',[]);
-    set(handles.ref_fix1,'String','');
-    set(handles.thresh_vel1,'String','0');
+%------------------------------------------------------------------------
+set(handles.inf_sup1,'Value',1);
+set(handles.field_ref1,'Value',1)
+set(handles.field_ref1,'String',{' '})
+set(handles.ref_fix1,'UserData',[]);
+set(handles.ref_fix1,'String','');
+set(handles.thresh_vel1,'String','0');
  
-
-%------------------------------------------------------
-
+%------------------------------------------------------------------------
 function ref_fix2_Callback(hObject, eventdata, handles)
-    set(handles.inf_sup2,'Value',1);
-    set(handles.field_ref2,'Value',1)
-    set(handles.field_ref2,'String',{' '})
-    set(handles.ref_fix2,'UserData',[]);
-    set(handles.ref_fix2,'String','');
-    set(handles.thresh_vel2,'String','0');
-
-%--------------------------------------------------------
-% --- Executes on selection change in inf_sup1.
-function inf_sup1_Callback(hObject, eventdata, handles)
-
-%--------------------------------------------------------------------------
-
-
-% --- Executes on selection change in field_ref.
-function field_ref_Callback(hObject, eventdata, handles)
-
-%-------------------------------------------------------------------------
-
-% --- Executes on selection change in field_ref2.
-function field_ref2_Callback(hObject, eventdata, handles)
-
-% -----------------------------------------------------------
+%------------------------------------------------------------------------
+set(handles.inf_sup2,'Value',1);
+set(handles.field_ref2,'Value',1)
+set(handles.field_ref2,'String',{' '})
+set(handles.ref_fix2,'UserData',[]);
+set(handles.ref_fix2,'String','');
+set(handles.thresh_vel2,'String','0');
+
+%------------------------------------------------------------------------
 % transform letters to numbers
-%--------------------------------------------
 function numres=stra2num(str)
+%------------------------------------------------------------------------
 numres=double(str)-96;
 if double(str) >= 48 & double(str) <= 57 % = 1 for numbers
@@ -5154,7 +5231,8 @@
 end
 
-
+%------------------------------------------------------------------------
 % --- Executes on button press in test_stereo1.
 function test_stereo1_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 if isequal(get(handles.test_stereo1,'Value'),0)
     set(handles.subdomain_patch1,'Visible','on')
@@ -5165,6 +5243,8 @@
 end
 
+%------------------------------------------------------------------------
 % --- Executes on button press in test_stereo2.
 function test_stereo2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 if isequal(get(handles.test_stereo2,'Value'),0)
     set(handles.subdomain_patch2,'Visible','on')
@@ -5175,6 +5255,8 @@
 end
 
+%------------------------------------------------------------------------
 % --- Executes on button press in ImaThreshold.
 function ImaThreshold_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 if isequal(get(handles.ImaThreshold,'Value'),1)
     set(handles.MinIma,'Visible','on')
@@ -5185,7 +5267,8 @@
 end
 
-
+%------------------------------------------------------------------------
 % --- Executes on button press in ImaThreshold2.
 function ImaThreshold2_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 if isequal(get(handles.ImaThreshold2,'Value'),1)
     set(handles.MinIma2,'Visible','on')
@@ -5196,53 +5279,2 @@
 end
 
-
-% --- Executes on button press in Experimental.
-function Experimental_Callback(hObject, eventdata, handles)
-
-
-
-function ext_ima_1_Callback(hObject, eventdata, handles)
-% hObject    handle to ext_ima_1 (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 ext_ima_1 as text
-%        str2double(get(hObject,'String')) returns contents of ext_ima_1 as a double
-
-
-% --- Executes during object creation, after setting all properties.
-function ext_ima_1_CreateFcn(hObject, eventdata, handles)
-% hObject    handle to ext_ima_1 (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
-
-
-
-function ext_ima_Callback(hObject, eventdata, handles)
-% hObject    handle to ext_ima (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 ext_ima as text
-%        str2double(get(hObject,'String')) returns contents of ext_ima as a double
-
-
-% --- Executes during object creation, after setting all properties.
-function ext_ima_CreateFcn(hObject, eventdata, handles)
-% hObject    handle to ext_ima (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
-
-
