Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 133)
+++ /trunk/src/civ.m	(revision 134)
@@ -1849,7 +1849,6 @@
 time=get(handles.RootName,'UserData'); %get the set of times
 civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
-super_cmd='#!/bin/bash \n';
-super_cmd=[super_cmd '#$ -cwd \n'];
-super_cmd=[super_cmd 'hostname && date \n'];
+super_cmd=[];
+
 for ifile=1:nbfield
     for j=1:nbslice
@@ -2096,5 +2095,6 @@
             %endTESTgrid
             i_cmd=i_cmd+1;
-            cmd_CIV2=CIV2_CMD(filename_cmx,namelog,par_civ2,sparam);
+            filename_cmx(1:end-4)
+            cmd_CIV2=CIV2_CMD(filename_cmx(1:end-4),namelog,par_civ2,sparam);
             if isequal(civAll,0)
                 if(isunix)
@@ -2233,20 +2233,33 @@
             %% to lauch the jobs locally :
             if(isunix)
-        %       cmd_str=['!. ' filename_bat ' &'];
-                cmd_str=['!. ' filename_bat];
+              cmd_str=['!. ' filename_bat ' &'];
+%                 cmd_str=['!. ' filename_bat];
                 display(cmd_str)
-         %       super_cmd=[super_cmd filename_bat]
      %            cmd_str=['!at -qb now -f ' filename_bat ' &']; %ou at -qb now -f bad idea...
             else %case of Windows
                cmd_str=['!' filename_bat ' &'];
             end
-            eval(cmd_str);
-            display(cmd_str);
-        end
-    end
-end
+               super_cmd=[super_cmd '. ' filename_bat '\n']
+%             eval(cmd_str);
+%             display(cmd_str);
+        end
+    end
+end
+
+           
+% filename_superbat(end-2:end)='bat';
+%         fid=fopen(filename_bat,'w');
+%         fprintf(fid,cmd);
+%         fclose(fid);
+
 if ~batch%TODO: a revoir, cas 'run as background task'
-    eval(['!.' super_cmd])
-end
+    eval(['!. ' filename_superbat ' &'])
+    [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
+    filename_superbat=fullfile(Rootbat,['toto.bat']);
+    fid=fopen(filename_superbat,'w');
+    fprintf(fid,super_cmd');
+    fclose(fid);
+end
+
 
 %save interface state
@@ -2272,4 +2285,6 @@
 end
 saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
+
+
 
 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]=...
@@ -2446,5 +2461,5 @@
 if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
 if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
-currentdir=pwd;%store the current working directory
+currentdir=pwd%store the current working directory
 [Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
 if ~exist(Path_ima,'dir')
@@ -2453,7 +2468,4 @@
     return
 end
-cd(Path_ima);%move to the directory of the images: needed to create the result dir by 'mkdir'
-dircur=pwd; %current working directory
-m2='';
 [xx,message]=fileattrib(Path_ima);
 if ~isempty(message) && ~isequal(message.UserWrite,1)
@@ -2493,21 +2505,23 @@
             end
         end
+  
         %create the new subdir_civ1
         if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
+            cd(Path_ima);          
             [xx,msg1]=mkdir(subdir_civ1_new);
+
             if ~strcmp(msg1,'')
                 msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
-                cd(currentdir)
                 filecell={};
                 return
-            else
+            else          
                 [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
                 if ~strcmp(msg2,'')
-                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg2])%error message for directory creation
-                    cd(currentdir)
+                    msgbox_uvmat('ERROR',['pb of permission for  ' subdir_civ1_new ': ' msg2])%error message for directory creation
                     filecell={};
                     return
                 end
             end
+            cd(currentdir);
         end
         if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
@@ -2538,6 +2552,8 @@
 %             subdir_civ1=subdir_civ1_new;
             %create the new subdir_civ1
-            if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
+            if exist(fullfile(Path_ima,subdir_civ1_new),'dir')
+                   cd(Path_ima);          
                 [xx,msg1]=mkdir(subdir_civ1_new);
+                            cd(currentdir);
                 if ~strcmpl(msg1,'')
                     msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
@@ -4182,5 +4198,5 @@
 %------------------------------------------------------------------------
 % --- CIV2  CIV2  CIV2 CIV2
-function cmd_CIV2=CIV2_CMD(filename_cmx,namelog,par,sparam)
+function cmd_CIV2=CIV2_CMD(filename,namelog,par,sparam)
 %------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
@@ -4226,5 +4242,5 @@
 par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
 par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');% bug : .png appears two times ?
-fid=fopen([filename_cmx '2'],'w');
+fid=fopen([filename '.cmx2'],'w');
 fprintf(fid,['##############   CMX file' '\n' ]);
 fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
@@ -4259,6 +4275,17 @@
 fclose(fid);
 
-cmd_CIV2=[sparam.Civ2Bin ' -f ' filename_cmx ]; % redirect standard output to the log file
+cmd_CIV2=[sparam.Civ2Bin ' -f ' filename  '.cmx >' filename '.log' ]; % redirect standard output to the log file
 cmd_CIV2=regexprep(cmd_CIV2,'\\','\\\\');
+namelog=regexprep(namelog,'\\','\\\\');
+
+if(isunix)
+    [Rootbat,Filebat,extbat]=fileparts(namelog);
+    ncName=fullfile(Rootbat,[ Filebat '.nc']);
+    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' namelog  ' ' regexprep(namelog,'\.log','') '.civ2.log' '\n' 'chmod g+w ' ncName];
+else
+    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y ' namelog ' ' regexprep(namelog,'\.log','') '.civ2.log'];
+end
+
+
 
 %------------------------------------------------------------------------
