Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 468)
+++ trunk/src/civ.m	(revision 469)
@@ -24,5 +24,5 @@
 %TODO: search range
 
-% Last Modified by GUIDE v2.5 21-Jun-2012 20:22:39
+% Last Modified by GUIDE v2.5 21-Jun-2012 23:37:47
 % Begin initialization code - DO NOT EDIT
 gui_Singleton = 1;
@@ -302,6 +302,6 @@
 set(handles.RUN, 'Enable','On')
 set(handles.RUN,'BackgroundColor',[1 0 0])%set RUN button to red color
-set(handles.BATCH,'Enable','On')
-set(handles.BATCH,'BackgroundColor',[1 0 0])%set BATCH button to red color
+% set(handles.BATCH,'Enable','On')
+% set(handles.BATCH,'BackgroundColor',[1 0 0])%set BATCH button to red color
 if isfield(handles,'status')
     set(handles.status,'Value',0);       %suppress the 'status' display
@@ -339,5 +339,5 @@
     % settings for  new civ data,
     if strcmp(Data.Conventions,'uvmat/civdata')% case of new civ data,
-        set(handles.ListProgram,'Value',2) %select civ/Matlab by default
+        set(handles.Program,'Value',2) %select civ/Matlab by default
         ListProgram_Callback([],[], handles)
         if ~isempty(Data.CivStage)%test for civ files
@@ -355,5 +355,5 @@
         % settings for civx data,
     elseif ~isempty(Data.absolut_time_T0')% case of  civx data,
-        set(handles.ListProgram,'Value',1) %select Cix by default
+        set(handles.Program,'Value',1) %select Cix by default
         ListProgram_Callback([],[], handles)
         if ~isempty(Data.fix2)
@@ -388,5 +388,5 @@
 end
 
-%no corresponding image found, select manually with the browser
+%% no corresponding image found, select manually with the browser
 ImaExt=ExtInput;
 if ~isempty(NomTypeNc)
@@ -400,8 +400,10 @@
             '*.*',  'All Files (*.*)'};
         [FileName, PathName] = uigetfile( menu, 'Pick an input image file',fileparts(fileparts(fileinput)));
-        imageinput=[PathName FileName];%complete file name
-     
+        fileinput=[PathName FileName];%complete file name
+        if ~exist(fileinput,'file')
+            return %abandon of the browser is cancelled
+        end
     end    
-    fileinput=imageinput;
+    %fileinput=imageinput;
 end
 
@@ -410,6 +412,5 @@
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-[RootPath,SubdirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName ImaExt]);
-
+[RootPath,SubdirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName ImaExt]);
 switch FileType
     case {'image','multimage','video','mmreader'}
@@ -448,20 +449,24 @@
 
 %% look for an image documentation file
-ext_imadoc='';%default
-SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
-filexml=fullfile(RootPath,[SubDirBase '.xml']);% new convention: xml above the image dir
-if ~exist(filexml,'file')
-    filexml=fullfile(RootPath,SubDir,[RootFile '.xml']);%old convention: xml within the image directroy
-end
-RootName=fullfile(RootPath,RootFile);
-if exist(filexml,'file')
-    ext_imadoc='.xml';
-elseif exist(fullfile(RootPath,SubDir,[RootFile '.civ']),'file')
-    ext_imadoc='.civ';
-    fileciv=fullfile(RootPath,SubDir,[RootFile '.civ']);
-elseif exist([RootName '.avi'],'file')
-    ext_imadoc='.avi';
-elseif exist([RootName '.AVI'],'file')
-    ext_imadoc='.AVI';
+XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt);
+% SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
+% filexml=fullfile(RootPath,[SubDirBase '.xml']);% new convention: xml above the image dir
+% if ~exist(filexml,'file')
+%     filexml=fullfile(RootPath,SubDir,[RootFile '.xml']);%old convention: xml within the image directroy
+%     if ~exist(filexml,'file')
+%         filexml=fullfile(RootPath,SubDir,[RootFile '.civ']);%very old convention: .civ file
+%         if ~exist(filexml,'file')
+%             filexml='';
+%         end
+%     end
+% end
+if isempty(XmlFileName)
+    if (strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
+        ext_imadoc=ImaExt;% the timing from the video movie is used
+    else
+        ext_imadoc='';
+    end
+else
+    [tild,tild,ext_imadoc]=fileparts(XmlFileName);
 end
 set(handles.ImaDoc,'String',ext_imadoc)% display the extension name for the image documentation file used
@@ -472,72 +477,50 @@
 CoordUnit='';%default
 pxcm_search=1;
-if ~isempty(ext_imadoc)
+if ~isempty(XmlFileName)
     set(handles.ImaDoc,'BackgroundColor',[1 1 0]) % set edit box to yellow cloro to indicate that the file reading is beginning
     drawnow
-    switch ext_imadoc
-        case '.xml'
-            [XmlData,warntext]=imadoc2struct(filexml);
-            ext_ima_read=[];
-            nom_type_read=[];
-            if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
-                %[PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
-                [~,tild,tild,tild,tild,tild,tild,tild,nom_type_read]=fileparts_uvmat(XmlData.Heading.ImageName);
-                fullname=fullfile(fileparts(RootName),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
-                if ~exist(fullname,'file')
-                    msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
-                end
-            end
-            if isfield(XmlData,'Time') && ~isempty(XmlData.Time)
-                time=XmlData.Time;
-                %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
-                if isequal(MaxIndex_i,1) && ~isequal(MaxIndex_j,1)% .Time is a line vector
-                    if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D','once'))
-                        time=time';
-                        MaxIndex_i=MaxIndex_j;
-                        MaxIndex_j=1;
-                    end
-                end
-            end
-            if isfield(XmlData,'TimeUnit')
-                TimeUnit=XmlData.TimeUnit;
-            end
-            
-            if isfield(XmlData,'GeometryCalib')
-                tsai=XmlData.GeometryCalib;
-                if isfield(tsai,'fx_fy')
-                    pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
-                end
-                if isfield(tsai,'CoordUnit')
-                    CoordUnit=tsai.CoordUnit;
-                end
-            end
-        case '.civ'% OBSOLETE: case of .civ image documentation file
-            [error,time,TimeUnit,mode,npx,npy]=read_imatext(fileciv);
-            if error==2, msgbox_uvmat('WARNING',['no file ' fileciv]);
-            elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
-            end
-            nom_type_ima='001a';
-    end
-    if isempty(time) && (strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
-        nom_type_ima='*';
-        %ImaExt=ext_imadoc;
-        set(handles.ListPairMode,'Value',1);
-        set(handles.ListPairMode,'String',{'series(Di)'})
-        dt=0.04;%default
-        hhh=which('videoreader');
-        if strcmp(FileType,'mmreader')%use old video function of matlab
-            imainfo=aviinfo(fileinput);%read infos on the avi movie TO REPLACE mmreader
-            dt=1/imainfo.FramesPerSecond;%time interval between successive frames
-            MaxIndex_i=imainfo.NumFrames;%number of frames
-        else %use video function videoreader of matlab
-            imainfo=get(videoreader(fileinput));%read infos on the avi movie
-            dt=1/imainfo.FrameRate;%time interval between successive frames
-            MaxIndex_i=imainfo.NumberOfFrames;%number of frames
-        end       
-        time=(dt*(0:MaxIndex_i-1))';%list of image times
-        TimeUnit='s';
-        set(handles.ImaDoc,'BackgroundColor',[1 1 1])% set display box back to whiter
-    end
-end
+    [XmlData,warntext]=imadoc2struct(XmlFileName);
+    nom_type_read=[];
+    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
+        [~,tild,tild,tild,tild,tild,tild,tild,nom_type_read]=fileparts_uvmat(XmlData.Heading.ImageName);
+        fullname=fullfile(fileparts(RootName),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
+        if ~exist(fullname,'file')
+            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
+        end
+    end
+    if isfield(XmlData,'Time') && ~isempty(XmlData.Time)
+        time=XmlData.Time;
+        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
+        if isequal(MaxIndex_i,1) && ~isequal(MaxIndex_j,1)% .Time is a line vector
+            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D','once'))
+                time=time';
+                MaxIndex_i=MaxIndex_j;
+                MaxIndex_j=1;
+            end
+        end
+    end
+    if isfield(XmlData,'TimeUnit')
+        TimeUnit=XmlData.TimeUnit;
+    end
+    if isfield(XmlData,'GeometryCalib')
+        tsai=XmlData.GeometryCalib;
+        if isfield(tsai,'fx_fy')
+            pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
+        end
+        if isfield(tsai,'CoordUnit')
+            CoordUnit=tsai.CoordUnit;
+        end
+    end
+end
+if isempty(time) && (strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
+    set(handles.ListPairMode,'Value',1);
+    set(handles.ListPairMode,'String',{'series(Di)'})
+    dt=1/get(MovieObject,'FrameRate');%time interval between successive frames
+    MaxIndex_i=get(MovieObject,'NumberOfFrames');
+    time=(dt*(0:MaxIndex_i-1))';%list of image times
+    TimeUnit='s';
+    set(handles.ImaDoc,'BackgroundColor',[1 1 1])% set display box back to whiter
+end
+
 %% timing display
 %show the reference image edit box if relevant (not needed for movies or in the absence of time information
@@ -547,7 +530,4 @@
     time=[zeros(size(time,1),1) time]; %insert a vertical line of zeros (to deal with zero file indices)
     time=[zeros(1,size(time,2)); time]; %insert a horizontal line of zeros
-    set(handles.ImaDoc,'UserData',time); %store the matrix of times
-    set(handles.dt_unit,'String',['dt in m' TimeUnit]);
-    set(handles.TimeUnit,'String',TimeUnit);
 else
     set(handles.ImaDoc,'String',''); %xml file not used for timing
@@ -801,7 +781,7 @@
 set(handles.RUN, 'Enable','Off')
 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
-batch=get(handles.RunMode,'Value');
+%batch=get(handles.RunMode,'Value');
 % batch=0;
-errormsg=launch_jobs(hObject, eventdata, handles,batch);
+errormsg=launch_jobs(hObject, eventdata, handles);
 set(handles.RUN, 'Enable','On')
 set(handles.RUN,'BackgroundColor',[1 0 0])
@@ -1021,5 +1001,5 @@
 %------------------------------------------------------------------------
 % --- Main lauch command, called by RUN and BATCH
-function errormsg=launch_jobs(hObject, eventdata, handles, batch)
+function errormsg=launch_jobs(hObject, eventdata, handles)
 %------------------------------------------------------------------------
 errormsg='';%default
@@ -1087,6 +1067,6 @@
     return
 end
-test_interp=0; %eviter les variables test_ (LG)
-if batch==3 %computation dispatched on a cluster
+% test_interp=0; %eviter les variables test_ (LG)
+if strcmp(Param.RunMode,'cluster') %computation dispatched on a cluster
     if isfield(s,'BatchParam')
         Param.xml=s.BatchParam;
@@ -1112,5 +1092,5 @@
 
 %% check batch mode supported
-if batch==3 %computation dispatched on a cluster
+if strcmp(Param.RunMode,'cluster') %computation dispatched on a cluster 
     switch batch_mode
         case 'sge'
@@ -1127,13 +1107,13 @@
 
 %% check if the binaries exist
-ListProgram=get(handles.ListProgram,'String');
-Param.CivMode=ListProgram{get(handles.ListProgram,'Value')};
+% ListProgram=get(handles.Program,'String');
+% Param.CivMode=ListProgram{get(handles.Program,'Value')};
 binary_list={};
-switch Param.CivMode
+switch Param.Program
     case 'CivX'
         binary_list={'Civ1Bin','Civ2Bin','PatchBin','FixBin'};
     case 'CivAll'% desactivated option
         binary_list={'Civ'};
-    case 'Matlab'
+    case 'civ_matlab.sh'% compiled version of civ_matlab 
         if batch
             binary_list={'CivmBin'};
@@ -1194,18 +1174,17 @@
 
     
-%% PARTIE A VERIFIER
-%output netcdf file (without extention) Joel what does this mean ?
+%% get information on input images or movies
 nbfield=numel(i1_civ1);
 nbslice=numel(j1_civ1);
-if ~strcmp(Param.CivMode,'CivX')
+% if strcmp(Param.Program,'civ_matlab')
     if Param.CheckCiv1
-        [Param.Civ1.FileTypeA,FileInfo,Param.Civ1.ImageA]=get_file_type(filecell.ima1.civ1{1});
-        [Param.Civ1.FileTypeB,FileInfo,Param.Civ1.ImageB]=get_file_type(filecell.ima2.civ1{1});
+        [Param.Civ1.FileTypeA,ImageInfoA_civ1,Param.Civ1.ImageA]=get_file_type(filecell.ima1.civ1{1});
+        [Param.Civ1.FileTypeB,ImageInfoB_civ1,Param.Civ1.ImageB]=get_file_type(filecell.ima2.civ1{1});
     end
     if Param.CheckCiv2
-        [Param.Civ2.FileTypeA,FileInfo,Param.Civ2.ImageA]=get_file_type(filecell.ima1.civ2{1});
-        [Param.Civ2.FileTypeB,FileInfo,Param.Civ2.ImageB]=get_file_type(filecell.ima2.civ2{1});
-    end
-end
+        [Param.Civ2.FileTypeA,FileInfoA_civ2,Param.Civ2.ImageA]=get_file_type(filecell.ima1.civ2{1});
+        [Param.Civ2.FileTypeB,FileInfoB_civ2,Param.Civ2.ImageB]=get_file_type(filecell.ima2.civ2{1});
+    end
+% end
 
 %% MAIN LOOP
@@ -1217,5 +1196,4 @@
 for ifile=1:nbfield
     for j=1:nbslice
-
             
         % define output file name
@@ -1236,27 +1214,13 @@
             end
             Param.Civ1.Time=((time(i2_civ1(ifile)+1,j2_civ1(j)+1)+time(i1_civ1(ifile)+1,j1_civ1(j)+1))/2);
-            if strcmp(Param.CivMode,'CivX')
+            if strcmp(Param.Program,'CivX')
                 Param.Civ1.term_a=num2stra(j1_civ1(j),nom_type_nc);%UTILITE?
                 Param.Civ1.term_b=num2stra(j2_civ1(j),nom_type_nc);%
             end
-            if isfield(Param.Civ1,'FileTypeA')&&(strcmp(Param.Civ1.FileTypeA,'video')|| strcmp(Param.Civ1.FileTypeA,'mmreader'))
-                %   ImageInfo=get(VideoReader(fullfile(Param.RootPath,[Param.RootFile Param.ImaExt])));
-                ImageInfo=get(Param.Civ1.ImageA);
-                %                 elseif strcmp(Param.Civ1.FileTypeA,'mmreader')
-                %                     ImageInfo=get(mmreader(fullfile(Param.RootPath,[Param.RootFile Param.ImaExt])));
-                Param.Civ1.ImageBitDepth=ImageInfo.BitsPerPixel/3;
-                if batch
-                    Param.Civ1.ImageA=filecell.ima1.civ1{ifile,j};%file name must be used for batch instead of video object
-                    Param.Civ1.ImageB=filecell.ima2.civ1{ifile,j};
-                end
-            else
-                Param.Civ1.ImageA=filecell.ima1.civ1{ifile,j};
-                Param.Civ1.ImageB=filecell.ima2.civ1{ifile,j};
-               % form=imformats(regexprep(get(handles.ImaExt,'String'),'^.',''));%look for image formats
-                ImageInfo=imfinfo(filecell.ima1.civ1{1,1});%read the first image to get the size
-                Param.Civ1.ImageBitDepth=ImageInfo.BitDepth;
-            end
-            Param.Civ1.ImageWidth=ImageInfo.Width;
-            Param.Civ1.ImageHeight=ImageInfo.Height;
+            Param.Civ1.ImageA=filecell.ima1.civ1{ifile,j};
+            Param.Civ1.ImageB=filecell.ima2.civ1{ifile,j};
+            Param.Civ1.ImageBitDepth=FileInfoA_civ1.BitDepth;
+            Param.Civ1.ImageWidth=FileInfoA_civ1.Width;
+            Param.Civ1.ImageHeight=FileInfoA_civ1.Height;
             Param.Civ1.FrameIndexA=i1_civ1(ifile);
             Param.Civ1.FrameIndexB=i2_civ1(ifile);
@@ -1278,5 +1242,4 @@
                         i1_grid=mod(i1_civ1(ifile)-1,nbslice_grid)+1;
                         Param.Civ1.Grid=[filecell.filebase '_' fullfile_uvmat('','',Param.Civ1.Grid,'.grid','_1',i1_grid)];
-                        %                         Param.Civ1.Grid=[filecell.filebase '_' name_generator(Param.Civ1.Grid,i1_grid,1,'.grid','_i')];
                         if ~exist(Param.Civ1.GridName,'file')
                             errormsg='grid file absent for civ1';
@@ -1293,22 +1256,6 @@
         
         if Param.CheckCiv2==1
-            if isfield(Param.Civ2,'FileTypeA') &&(strcmp(Param.Civ2.FileTypeA,'video')|| strcmp(Param.Civ2.FileTypeA,'mmreader'))
-                %   ImageInfo=get(VideoReader(fullfile(Param.RootPath,[Param.RootFile Param.ImaExt])));
-                ImageInfo=get(Param.Civ2.ImageA);
-                %                 elseif strcmp(Param.Civ1.FileTypeA,'mmreader')
-                %                     ImageInfo=get(mmreader(fullfile(Param.RootPath,[Param.RootFile Param.ImaExt])));
-                Param.Civ2.ImageBitDepth=ImageInfo.BitsPerPixel/3;
-                if batch
-                    Param.Civ2.ImageA=filecell.ima1.civ2{ifile,j};%file name must be used for batch instead of video object
-                    Param.Civ2.ImageB=filecell.ima2.civ2{ifile,j};
-                end
-            else
-                Param.Civ2.ImageA=filecell.ima1.civ2{ifile,j};
-                Param.Civ2.ImageB=filecell.ima2.civ2{ifile,j};
-                form=imformats(regexprep(get(handles.ImaExt,'String'),'^.',''));%look for image formats
-                ImageInfo=imfinfo(filecell.ima1.civ2{1,1});%read the first image to get the size
-                Param.Civ2.ImageBitDepth=ImageInfo.BitDepth;
-            end
-            
+            Param.Civ2.ImageA=filecell.ima1.civ2{ifile,j};
+            Param.Civ2.ImageB=filecell.ima2.civ2{ifile,j};          
             if ~checkframe %&& size(time,1)>=i2_civ2(ifile) && size(time,2)>=j2_civ2(j)
                 Param.Civ2.Dt=time(i2_civ2(ifile)+1,j2_civ2(j)+1)-time(i1_civ2(ifile)+1,j1_civ2(j)+1);
@@ -1317,5 +1264,5 @@
             end
             Param.Civ2.Time=(time(i2_civ2(ifile)+1,j2_civ2(j)+1)+time(i1_civ2(ifile)+1,j1_civ2(j)+1))/2;
-            if strcmp(Param.CivMode,'CivX')
+            if strcmp(Param.Program,'CivX')
                 Param.Civ2.term_a=num2stra(j1_civ2(j),nom_type_nc);
                 Param.Civ2.term_b=num2stra(j2_civ2(j),nom_type_nc);
@@ -1346,29 +1293,19 @@
                 end
             end
-            form=imformats(regexprep(get(handles.ImaExt,'String'),'^.',''));%look for image formats
-            if isempty(form)
-                % ImageInfo=get(VideoReader(fullfile());
-                Param.Civ2.ImageBitDepth=ImageInfo.BitsPerPixel/3;
-            else
-                ImageInfo=imfinfo(filecell.ima1.civ2{1,1});%read the first image to get the size
-                Param.Civ2.ImageBitDepth=ImageInfo.BitDepth;
-            end
-            Param.Civ2.ImageWidth=ImageInfo.Width;
-            Param.Civ2.ImageHeight=ImageInfo.Height;
+
+            Param.Civ2.ImageBitDepth=FileInfoA_civ2.BitDepth;
+            Param.Civ2.ImageWidth=FileInfoA_civ2.Width;
+            Param.Civ2.ImageHeight=FileInfoA_civ2.Height;
             Param.Civ2.FrameIndexA=i1_civ2(ifile);
-            Param.Civ2.FrameIndexB=i2_civ2(ifile);
-            
-        end
-        
-        
+            Param.Civ2.FrameIndexB=i2_civ2(ifile);           
+        end
+       
         % write the command and eventually the cmx, xml or nml files
-        cmd=write_cmd(Param,batch);
+        cmd=write_cmd(Param);
         write_param(Param);
-        
-
-        
+              
         % create the file used in run or batch
-        switch Param.CivMode
-            case 'Matlab'
+        switch Param.Program
+            case {'civ_matlab','civ_matlab.sh'}
                 filename_bat=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_BAT$2$3.m');
             case {'CivX','CivAll'}
@@ -1393,6 +1330,7 @@
 
 %% start calculation
-
-if batch ==3 
+%computation on cluster
+%if batch ==3
+ if  strcmp(Param.RunMode,'cluster') 
     switch batch_mode    
         case 'sge' %at the moment only psmn ENS Lyon uses it
@@ -1526,10 +1464,10 @@
             end
     end
-else
-    switch Param.CivMode
-        case 'Matlab'
-            
-            background=1;
-            if background
+ else %computation on local computer 
+    switch Param.Program
+        case {'civ_matlab','civ_matlab.sh'}
+%             
+%             background=1;
+            if strcmp(Param.RunMode,'background')
                 filename_superbat=fullfile(RootBat,'job_list.m');
                 fid=fopen(filename_superbat,'w');
@@ -1689,6 +1627,6 @@
 filecell=[];%default
 errormsg='';
-ListProgram=get(handles.ListProgram,'String');
-CivMode=ListProgram{get(handles.ListProgram,'Value')};%Program to use , CivX or Matlab
+ListProgram=get(handles.Program,'String');
+CivMode=ListProgram{get(handles.Program,'Value')};%Program to use , CivX or Matlab
 
 %% get the root name and check dir
@@ -3891,8 +3829,8 @@
 set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
 
-% --- Executes on selection change in ListProgram.
-function ListProgram_Callback(hObject, eventdata, handles)
-ListProgram=get(handles.ListProgram,'String');
-Program=ListProgram{get(handles.ListProgram,'value')};
+% --- Executes on selection change in Program.
+function Program_Callback(hObject, eventdata, handles)
+ListProgram=get(handles.Program,'String');
+Program=ListProgram{get(handles.Program,'value')};
 switch Program
     case 'CivX'
@@ -3911,5 +3849,5 @@
         set(handles.CheckDeformation,'Value',1)
         set(handles.CheckDecimal,'Value',1)
-    case 'Matlab'
+    case {'civ_matlab','civ_matlab.sh'}
         set(handles.num_MaxDiff,'Visible','on')
         set(handles.num_MaxVel,'Visible','on')
@@ -3987,5 +3925,5 @@
 %changes : filename_cmx -> filename ( no extension )
 errormsg='';
-switch Param.CivMode
+switch Param.Program
     case 'CivX'
         if Param.CheckCiv1
@@ -4129,5 +4067,5 @@
             fclose(fid);
         end
-    case 'Matlab'
+    case {'civ_matlab','civ_matlab.sh'}
         filename=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_XML$2$3.xml');
         save(struct2xml(Param),filename);
@@ -4135,10 +4073,10 @@
 
 
-function cmd=write_cmd(Param,batch)
+function cmd=write_cmd(Param)
 
 % initiate system command
 cmd=[];
 
-switch Param.CivMode
+switch Param.Program
     case 'CivX'
         if isunix % check: necessaire aussi en RUN?
@@ -4160,5 +4098,5 @@
 
 if Param.CheckCiv1
-    switch Param.CivMode
+    switch Param.Program
         case 'CivX'
             if(isunix) %unix (or Mac) system
@@ -4189,5 +4127,5 @@
 
 if Param.CheckFix1
-    switch Param.CivMode
+    switch Param.Program
         case 'CivX'
             cmd=[cmd...
@@ -4216,5 +4154,5 @@
 %CheckPatch1
 if Param.CheckPatch1
-    switch Param.CivMode
+    switch Param.Program
         case 'CivX'
             cmd=[cmd...
@@ -4267,5 +4205,5 @@
 
 if Param.CheckCiv2
-    switch Param.CivMode
+    switch Param.Program
         case 'CivX'
             if(isunix)
@@ -4297,5 +4235,5 @@
 % CheckFix2
 if Param.CheckFix2==1
-    switch Param.CivMode
+    switch Param.Program
         case 'CivX'
             cmd=[cmd...
@@ -4324,5 +4262,5 @@
 if Param.CheckPatch2==1
     
-    switch Param.CivMode
+    switch Param.Program
         
         case 'CivX'
@@ -4375,11 +4313,11 @@
 end
 
-if isequal(Param.CivMode,'CivAll')
+if isequal(Param.Program,'CivAll')
     save(CivAllxml,[Param.OutputFile '.xml']);
     cmd=[cmd sparam.CivBin ' -f ' Param.OutputFile '.xml '  CivAllCmd ' >' Param.OutputFile '.log' '\n'];
 end
 
-if isequal(Param.CivMode,'Matlab')
-    if batch>1
+if isequal(Param.Program,'civ_matlab')
+    if strcmp(Param.RunMode,'cluster')||strcmp(Param.RunMode,'background')
         cmd=['#!/bin/bash \n '...
             '#$ -cwd \n '...
@@ -4402,5 +4340,5 @@
    
 
-if isequal(Param.CivMode,'MatlabCompile')
+if isequal(Param.Program,'civ_matlab.sh')
         cmd=['#!/bin/bash \n '...
             '#$ -cwd \n '...
@@ -4411,5 +4349,5 @@
 
 
-if isequal(Param.CivMode,'MatlabNonCompile')
+if isequal(Param.Program,'MatlabNonCompile')
 %         cmd=[regexprep(which(civ_matlab),'.m$','')...
 %             '(' regexprep(filename,'(\w+)/(\w+$)','$1/0_XML$2.xml,')...
