Index: trunk/src/series.m
===================================================================
--- trunk/src/series.m	(revision 1095)
+++ trunk/src/series.m	(revision 1096)
@@ -627,5 +627,5 @@
     empty_line(iline)= isempty(cell2mat(InputTable(iline,1:3)));
 end
-if ~isempty(find(empty_line));
+if ~isempty(find(empty_line,1))
     InputTable(empty_line,:)=[]; % remove empty lines
     set(handles.InputTable,'Data',InputTable)
@@ -743,10 +743,4 @@
 
 %% enable other menus and uicontrols
-% set(handles.MenuOpenCampaign,'Enable','on')
-% set(handles.MenuCampaign_1,'Enable','on')
-% set(handles.MenuCampaign_2,'Enable','on')
-% set(handles.MenuCampaign_3,'Enable','on')
-% set(handles.MenuCampaign_4,'Enable','on')
-% set(handles.MenuCampaign_5,'Enable','on')
 set(handles.RUN, 'Enable','On')
 set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red 
@@ -758,11 +752,10 @@
 InputTable=get(handles.InputTable,'Data');
 SeriesData=get(handles.series,'UserData');
+
 if strcmp(iview,'append') % display the input data as a new line in the table
     iview=size(InputTable,1)+1; % the next line in InputTable becomes the current line
-%     InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
 elseif strcmp(iview,'one') % refresh the list of  input  file series
     iview=1; % the first line in InputTable becomes the current line
     InputTable={'','','','',''};
-%     InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
     set(handles.TimeTable,'Data',[{''},{[]},{[]},{[]},{[]}])
     set(handles.MinIndex_i,'Data',[])
@@ -860,4 +853,27 @@
 SeriesData.Ref_j1=j1;
 SeriesData.Ref_j2=j2;
+
+%% define the path for the output files 
+[InputPath,Device,DeviceExt]=fileparts(InputTable{1,1});
+[InputPath,Experiment,ExperimentExt]=fileparts(InputPath);
+[~,InputPath,InputPathExt]=fileparts(InputPath);
+set(handles.Device,'String',[Device DeviceExt])
+set(handles.Experiment,'String',[Experiment ExperimentExt])
+if ~isempty(regexp(InputTable{1,1},'(^http://)|(^https://)'))
+    set(handles.OutputPathBrowse,'Value',1)% an output folder needs to be specified for OpenDAP data
+end
+
+%update the output path if needed
+if ~(isfield(SeriesData,'InputPath') && strcmp(SeriesData.InputPath,InputPath))
+    if get(handles.OutputPathBrowse,'Value')==1  % fix the output path in manual mode
+        OutputPathOld=get(handles.OutputPath,'String');
+        OutputPath=uigetdir(OutputPathOld,'pick a root folder for output data');
+        set(handles.OutputPath,'String',OutputPath)
+    else %reproduce the input path for output
+        set(handles.OutputPath,'String',InputPath)
+    end
+    SeriesData.InputPath=InputPath;
+end
+
 set(handles.series,'UserData',SeriesData)
 
@@ -1029,16 +1045,4 @@
         end
     end
-   
-%     if isfield(XmlData,'GeometryCalib')
-%         check_calib=1;
-%         if isfield(XmlData.GeometryCalib,'SliceCoord')
-%             siz=size(XmlData.GeometryCalib.SliceCoord);
-%             if ~isempty(NbSlice)&& ~isequal(size(1),NbSlice)
-%                 msgbox_uvmat('WARNING','inconsistent numbers of Z indices between motor and calibration');
-%             else
-%                 NbSlice=siz(1);
-%             end
-%         end
-%     end
 end
 if ~isempty(NbSlice)
@@ -1050,5 +1054,5 @@
 if ~isempty(VideoObject)% case of movies
     imainfo=get(VideoObject);
-    if isempty(j1_series); % frame index along i
+    if isempty(j1_series) % frame index along i
         Time=zeros(imainfo.NumberOfFrames+1,2);
         Time(:,2)=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)';
@@ -1069,5 +1073,5 @@
         TimeLast=Time(last_i+1,last_j+1);
     end
-    if size(Time)>=[MaxIndex_i+1 MaxIndex_j+1];
+    if size(Time)>=[MaxIndex_i+1 MaxIndex_j+1]
         TimeMax=Time(MaxIndex_i+1,MaxIndex_j+1);
     end
@@ -1134,6 +1138,6 @@
     j_max{iline}=max(pair_max,[],1); % max on j index
     if ~isempty(j_max{iline})
-    MaxIndex_i(iline)=max(find(j_max{iline}))-1; % max ref index i
-    MinIndex_i(iline)=min(find(j_max{iline}))-1; % min ref index i
+    MaxIndex_i(iline)=find(j_max{iline}, 1, 'last' )-1; % max ref index i
+    MinIndex_i(iline)=find(j_max{iline}, 1 )-1; % min ref index i
     end
 end
@@ -1149,5 +1153,5 @@
     LineData=zeros(size(file_indices));
     file_select=file_indices(file_indices<=numel(j_max{iline}));
-    ind_select=find(file_indices<=numel(j_max{iline}));
+    ind_select=file_indices<=numel(j_max{iline});
     LineData(ind_select)=j_max{iline}(file_select)~=0;
     CData(ind_y,:)=ones(size(ind_y'))*LineData;
@@ -1198,4 +1202,5 @@
 
 %------------------------------------------------------------------------
+%fill the menu of possible pairs as input
 function displ_pair=update_listpair(i1_series,i2_series,j1_series,j2_series,mode,time,TimeUnit,ref_i,ref_j,TimeName,InputTable,FileInfo)
 %------------------------------------------------------------------------
@@ -1212,7 +1217,7 @@
         max_diff=max(diff_i(diff_i>0));
         for ipair=min_diff:max_diff
-            if numel(diff_i(diff_i==ipair))>0
+            if ~isempty(find(diff_i==ipair,1))% if the considered difference exists as input
                 pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
-                if ~isempty(time)
+                if size(time,1)>=ref_i+ceil(ipair/2)
                     if ref_i<=floor(ipair/2)
                         ref_i=floor(ipair/2)+1; % shift ref_i to get the first pair
@@ -2137,5 +2142,9 @@
             [status,result]=system(oar_command)% execute system command and show the result (ID number of the launched job) on the Matlab command window
             filename_oarcommand=fullfile(DIR_CLUSTER,'0_cluster_command'); % keep track of the command in file '0-OAR/0_cluster_command'
-            fid=fopen(filename_oarcommand,'w');
+            [fid,errormsg]=fopen(filename_oarcommand,'w');
+            if ~isempty(errormsg)
+                msgbox_uvmat('ERROR',['cannot create ' filename_oarcommand ': ' errormsg])
+                return
+            end
             fprintf(fid,oar_command); % store the command
             fprintf(fid,result); % store the result (job ID number)
@@ -2723,11 +2732,4 @@
 set(handles.Experiment,'Visible','on')
 set(handles.Experiment_title,'Visible','on')
-OutputPathOld=get(handles.OutputPath,'String')
-if isempty(OutputPathOld)
-    if ~isempty(regexp(InputTable{1,1},'(^http://)|(^https://)'))
-        OutputPath=uigetdir(pwd,'pick a root folder for output data');
-    end
-    set(handles.OutputPath,'String',OutputPath)
-end
 set(handles.Experiment_title,'Visible','on')
 set(handles.OutputPath,'Visible','on')
@@ -2777,5 +2779,5 @@
 set(handles.OutputDirExt,'Visible',OutputDirVisible)
 set(handles.OutputSubDir,'Visible',OutputDirVisible)
-set(handles.OutputDir_title,'Visible',OutputDirVisible)
+% set(handles.OutputDir_title,'Visible',OutputDirVisible)
 SeriesData.ActionName=ActionName; % record ActionName for next use
 
@@ -3951,31 +3953,20 @@
 
 function OutputPath_Callback(hObject, eventdata, handles)
-% hObject    handle to OutputPath (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 OutputPath as text
-%        str2double(get(hObject,'String')) returns contents of OutputPath as a doubl
-
 
 
 function Experiment_Callback(hObject, eventdata, handles)
-% hObject    handle to Experiment (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 Experiment as text
-%        str2double(get(hObject,'String')) returns contents of Experiment as a double
 
 
 function Device_Callback(hObject, eventdata, handles)
-% hObject    handle to Device (see GCBO)
-% eventdata  reserved - to be defined in a future version of MATLAB
-% handles    structure with handles and user data (see GUIDATA)
-
 
 
 % --- Executes on button press in OutputPathBrowse.
 function OutputPathBrowse_Callback(hObject, eventdata, handles)
+CheckValue=get(handles.OutputPathBrowse,'Value');
+if CheckValue
 OutputPath=uigetdir(get(handles.OutputPath,'String'));
 set(handles.OutputPath,'String',OutputPath)
+else
+    InputTable=get(handles.InputTable,'Data');
+    set(handles.OutputPath,'String',InputTable{1,1})
+end
