Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 465)
+++ trunk/src/civ.m	(revision 467)
@@ -24,5 +24,5 @@
 %TODO: search range
 
-% Last Modified by GUIDE v2.5 03-Jun-2012 22:16:42
+% Last Modified by GUIDE v2.5 21-Jun-2012 20:22:39
 % Begin initialization code - DO NOT EDIT
 gui_Singleton = 1;
@@ -77,7 +77,14 @@
     test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod
 end
+RUNVal=get(handles.RunMode,'Value');
 if test_batch==0
-    set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
-    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
+   if RUNVal>2
+       set(handles.RunMode,'Value',1)
+   end
+   set(handles.RunMode,'String',{'local';'background'})
+else
+    set(handles.RunMode,'String',{'local';'background';'cluster'})
+%     set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
+%     set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
 end
 if isfield(sparam.RunParam,'CivBin')
@@ -804,5 +811,6 @@
 set(handles.RUN, 'Enable','Off')
 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
-batch=0;
+batch=get(handles.RunMode,'Value');
+% batch=0;
 errormsg=launch_jobs(hObject, eventdata, handles,batch);
 set(handles.RUN, 'Enable','On')
@@ -817,24 +825,24 @@
     status_Callback(hObject, eventdata, handles)
 end
-
-%------------------------------------------------------------------------
-% --- Executes on button press in BATCH: remote processing
-function BATCH_Callback(hObject, eventdata, handles)
-% -----------------------------------------------------------------------
-set(handles.BATCH, 'Enable','Off')
-set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
-batch=1;
-errormsg=launch_jobs(hObject, eventdata, handles, batch);
-set(handles.BATCH, 'Enable','On')
-set(handles.BATCH,'BackgroundColor',[1 0 0])
-
-% display errors or start status callback to visualise results
-if ~isempty(errormsg)
-    display(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-elseif isfield(handles,'status')
-    set(handles.status,'Value',1);%suppress status display
-    status_Callback(hObject, eventdata, handles)
-end
+% 
+% %------------------------------------------------------------------------
+% % --- Executes on button press in BATCH: remote processing
+% function BATCH_Callback(hObject, eventdata, handles)
+% % -----------------------------------------------------------------------
+% set(handles.BATCH, 'Enable','Off')
+% set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
+% batch=1;
+% errormsg=launch_jobs(hObject, eventdata, handles, batch);
+% set(handles.BATCH, 'Enable','On')
+% set(handles.BATCH,'BackgroundColor',[1 0 0])
+% 
+% % display errors or start status callback to visualise results
+% if ~isempty(errormsg)
+%     display(errormsg)
+%     msgbox_uvmat('ERROR',errormsg)
+% elseif isfield(handles,'status')
+%     set(handles.status,'Value',1);%suppress status display
+%     status_Callback(hObject, eventdata, handles)
+% end
 
 %-------------------------------------------------------------------
@@ -1090,5 +1098,5 @@
 end
 test_interp=0; %eviter les variables test_ (LG)
-if batch
+if batch==3 %computation dispatched on a cluster
     if isfield(s,'BatchParam')
         Param.xml=s.BatchParam;
@@ -1114,5 +1122,5 @@
 
 %% check batch mode supported
-if batch
+if batch==3 %computation dispatched on a cluster
     switch batch_mode
         case 'sge'
@@ -1187,6 +1195,6 @@
 
 %% create subfolders for log, cmx, nml, xml, bat
-RootBat=fileparts(filecell.nc.civ1{1,1})
-dir_list={'0_BAT','0_CMX','0_XML','0_LOG',}
+RootBat=fileparts(filecell.nc.civ1{1,1});
+dir_list={'0_BAT','0_CMX','0_XML','0_LOG'};
 for k=1:length(dir_list)
     if ~exist(fullfile(RootBat,dir_list{k}),'dir')
@@ -1396,5 +1404,5 @@
 %% start calculation
 
-if batch  
+if batch ==3 
     switch batch_mode    
         case 'sge' %at the moment only psmn ENS Lyon uses it
@@ -1540,4 +1548,10 @@
                     return
                 end
+                
+                fprintf(fid,['#!/bin/bash \n' ...
+                 '/etc/sysprofile \n'...
+                'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n']);
+ 
+                
                 fprintf(fid,['addpath(''' path_civ ''');\n']);
                 for p=1:length(batch_file_list)
@@ -1550,6 +1564,9 @@
                     
                 end
+                fprintf(fid, 'exit \n END_MATLAB \n');
+
                 fclose(fid);
-                 eval(['run ' filename_superbat]);                     
+                 eval(['run ' filename_superbat]);                
+                 
             else
                 for p=1:length(batch_file_list)
@@ -4374,5 +4391,5 @@
 
 if isequal(Param.CivMode,'Matlab')
-    if batch
+    if batch>1
         cmd=['#!/bin/bash \n '...
             '#$ -cwd \n '...
@@ -4573,3 +4590,4 @@
 
 
-
+% --- Executes on selection change in RunMode.
+function RunMode_Callback(hObject, eventdata, handles)
