Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 1095)
+++ /trunk/src/proj_field.m	(revision 1096)
@@ -1074,5 +1074,5 @@
 end
 
-%% initiate Matlab  structure for physical field
+%% initiate Matlab  structure for physical fieldopen
 [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
 if ~isempty(errormsg)
@@ -1204,4 +1204,6 @@
     ProjData.VarAttribute{1}.Role='coord_y';
     ProjData.VarAttribute{2}.Role='coord_x';
+    YAttribute=[];
+    XAttribute=[];
     if ~isempty(icell_grid)
             YAttribute=FieldData.VarAttribute{CellInfo{icell_grid}.CoordIndex(NbDim-1)};
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
Index: /trunk/src/series/civ_series.m
===================================================================
--- /trunk/src/series/civ_series.m	(revision 1095)
+++ /trunk/src/series/civ_series.m	(revision 1096)
@@ -331,5 +331,5 @@
     end
     if CheckInputFile
-        OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+        OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
         if iview_A==0 % no nc file has been entered
             ncfile=fullfile_uvmat(OutputPath,Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},...
Index: /trunk/src/series/merge_proj.m
===================================================================
--- /trunk/src/series/merge_proj.m	(revision 1095)
+++ /trunk/src/series/merge_proj.m	(revision 1096)
@@ -83,6 +83,4 @@
     if ~exist(FirstFileName,'file')
         msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
-    elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject')
-        msgbox_uvmat('WARNING','You may need a projection object of type plane for merge_proj')
     end
     return
@@ -252,5 +250,5 @@
     CheckOverwrite=Param.CheckOverwrite;
 end
-OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
 
 for index=1:NbField
Index: /trunk/src/series/sliding_average.m
===================================================================
--- /trunk/src/series/sliding_average.m	(revision 1095)
+++ /trunk/src/series/sliding_average.m	(revision 1096)
@@ -185,9 +185,25 @@
 
 %% initialisation
-T=24.4; %main wave period
-t0=3; % time for motion start (torus at its maximum x)
+char_index=regexp(SubDir{1},'waves_L1_');
+switch(SubDir{1}(char_index+9))
+    case '1'
+        amplitude=2.5 %oscillation amplitude
+        T=24.46;
+        t0=3 ;% dt=0.5 s, torus at its max x at the beginning of motion, i0=7
+    case '2'
+        amplitude=5 %oscillation amplitude
+        T=24.47;
+        t0=8.5; % dt=1/3 s -> image index of starting motion = 26, % torus at its max x at the beginning of motion
+    case '3'
+        amplitude=10 %oscillation amplitude
+        T=24.45;
+        t0=6.5-T/2;% dt=0.25, torus at its minimum x at the beginning of motion
+    case '4'  
+        amplitude=15 %oscillation amplitude
+        T=24.48;
+        t0=3.4;     %dt=0.2 -> i0=18 image index of starting motion, % torus at its max x at the beginning of motion
+end
 NbPeriod=2; %number of periods for the sliding average
 omega=2*pi/T;
-amplitude=2.5; %oscillation amplitude
 Lscale=15;%diameter of the torus, length scale for normalisation
 Uscale=amplitude*omega;
@@ -214,5 +230,5 @@
 NpTime=round(NbPeriod*T/dt+1);
 
-OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
 RootFileOut=RootFile{1};
 NomTypeOut='_1';
Index: /trunk/src/struct2nc.m
===================================================================
--- /trunk/src/struct2nc.m	(revision 1095)
+++ /trunk/src/struct2nc.m	(revision 1096)
@@ -42,4 +42,9 @@
     return
 end
+FilePath=fileparts(flname);
+if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
+    errormsg=['directory ' FilePath ' needs to be created'];
+    return
+end
 if ~exist('Data','var')
      errormsg='no data  input for the netcdf file';
@@ -47,29 +52,19 @@
 end 
 
-
 %% check the validity of the input field structure
 if ~ (exist('action','var') && strcmp(action,'keep_open'))
-[errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(Data);
-if ~isempty(errormsg)
-    errormsg=['error in struct2nc:invalid input structure_' errormsg];
-    return
-end
+    [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(Data);
+    if ~isempty(errormsg)
+        errormsg=['error in struct2nc:invalid input structure_' errormsg];
+        return
+    end
 end
 ListVarName=Data.ListVarName;
 
 %% create the netcdf file with name flname in format NETCDF4
-% if ischar(flname)
-    FilePath=fileparts(flname);
-    if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
-        errormsg=['directory ' FilePath ' needs to be created'];
-        return
-    end
-    cmode = netcdf.getConstant('NETCDF4');
-    cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
-    cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
-    nc = netcdf.create(flname, cmode);
-% else
-%     nc=flname;
-% end
+cmode = netcdf.getConstant('NETCDF4');
+cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
+cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
+nc = netcdf.create(flname, cmode);
 
 %% write global constants
