Index: trunk/src/series.m
===================================================================
--- trunk/src/series.m	(revision 711)
+++ trunk/src/series.m	(revision 714)
@@ -303,23 +303,36 @@
 %------------------------------------------------------------------------  
 function MenuBrowse_Callback(hObject, eventdata, handles)
-
 %% look for the previously opened file 'oldfile'
-oldfile=''; %default
-if get(handles.CheckAppend,'Value')
-    % case 'checkappend': new series appended to the input table
-    InputTable=get(handles.InputTable,'Data');
-    RootPathCell=InputTable(:,1);
-    SubDirCell=InputTable(:,3);
-    oldfile=''; %default
-    if ~(isempty(RootPathCell) || isequal(RootPathCell,{''}))%loads the previously stored file name and set it as default in the file_input box
-        oldfile=fullfile(RootPathCell{1},SubDirCell{1});
-    end
-else
-    % case refresh the input table by a new series
-    SeriesData=get(handles.series,'UserData');
-    if isfield(SeriesData,'RefFile')
-        oldfile=SeriesData.RefFile{1};
-    end
-end
+InputTable=get(handles.InputTable,'Data');
+oldfile=InputTable{1,1};
+if isempty(oldfile)
+    % use a file name stored in prefdir
+    dir_perso=prefdir;
+    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+    if exist(profil_perso,'file')
+        h=load (profil_perso);
+        if isfield(h,'RootPath') && ischar(h.RootPath)
+            oldfile=h.RootPath;
+        end
+    end
+end
+%% launch the browser
+fileinput=uigetfile_uvmat('pick a file to append in the input table',oldfile);
+if ~isempty(fileinput)
+      display_file_name(handles,fileinput,'one')
+end
+
+% --------------------------------------------------------------------
+function MenuBrowseAppend_Callback(hObject, eventdata, handles)
+
+%% look for the previously opened file 'oldfile'
+InputTable=get(handles.InputTable,'Data');
+RootPathCell=InputTable(:,1);
+if isempty(RootPathCell{1})% no input file in the table
+     MenuBrowse_Callback(hObject, eventdata, handles)%refresh the input table, not append
+     return
+end
+SubDirCell=InputTable(:,2);
+oldfile=fullfile(RootPathCell{1},SubDirCell{1});
 
 %% use a file name stored in prefdir
@@ -336,40 +349,4 @@
 fileinput=uigetfile_uvmat('pick a file to append in the input table',oldfile);
 if ~isempty(fileinput)
-%     if get(handles.CheckAppend,'Value')
-%         display_file_name(handles,fileinput,'append')
-%     else
-        display_file_name(handles,fileinput,'one')
-%     end
-end
-
-% --------------------------------------------------------------------
-function MenuBrowseAppend_Callback(hObject, eventdata, handles)
-
-%% look for the previously opened file 'oldfile'
-InputTable=get(handles.InputTable,'Data');
-RootPathCell=InputTable(:,1);
-if isempty(RootPathCell{1})% no input file in the table
-     MenuBrowse_Callback(hObject, eventdata, handles)%refresh the input table, not append
-     return
-end
-SubDirCell=InputTable(:,2);
-% oldfile=''; %default
-% if ~(isempty(RootPathCell) || isequal(RootPathCell,{''}))%loads the previously stored file name and set it as default in the file_input box
-    oldfile=fullfile(RootPathCell{1},SubDirCell{1});
-% end
-
-%% use a file name stored in prefdir
-dir_perso=prefdir;
-profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
-if exist(profil_perso,'file')
-    h=load (profil_perso);
-    if isfield(h,'RootPath') && ischar(h.RootPath)
-        oldfile=h.RootPath;
-    end
-end
-
-%% launch the browser
-fileinput=uigetfile_uvmat('pick a file to append in the input table',oldfile);
-if ~isempty(fileinput)
         display_file_name(handles,fileinput,'append')
 end
@@ -380,5 +357,15 @@
 function MenuFile_Callback(hObject, eventdata, handles)
 
-display_file_name(handles,get(hObject,'Label'),'one')
+errormsg=display_file_name(handles,get(hObject,'Label'),'one');
+if ~isempty(errormsg)
+    set(hObject,'Label','')
+    MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
+        {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
+    str_find=strcmp(get(hObject,'Label'),MenuFile);
+    MenuFile(str_find)=[];% suppress the input file to the list
+    for ifile=1:numel(MenuFile)
+        set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
+    end
+end
 
 %------------------------------------------------------------------------
@@ -546,9 +533,10 @@
     if ~exist(RootPath,'dir')
         i1_series=[];
-        RootPath=fileparts(RootPath); %will try the upped folder
-    else
+        RootPath=fileparts(RootPath); %will try the upper folder
+    else %scan the input folder
         [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=...
             find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
     end
+    % if no file is found, open a browser
     if isempty(i1_series)
         fileinput=uigetfile_uvmat(['wrong input at line ' num2str(iview) ':pick a new input file'],RootPath);
@@ -567,5 +555,5 @@
 %------------------------------------------------------------------------
 % --- Function called when a new file is opened, either by series_OpeningFcn or by the browser
-function display_file_name(handles,fileinput,iview)
+function errormsg=display_file_name(handles,fileinput,iview)
 %------------------------------------------------------------------------  
 %
@@ -576,8 +564,12 @@
 %       or 'one': refresh the list
 %         'append': add a new line to the input table
-
+set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH  button to yellow color (indicate activation)
+drawnow
+errormsg='';%default
 %% get the input root name, indices, file extension and nomenclature NomType
 if ~exist(fileinput,'file')
-    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
+    errormsg=['input file ' fileinput  ' does not exist'];
+    msgbox_uvmat('ERROR',errormsg)
+    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
     return
 end
@@ -590,14 +582,19 @@
 if isempty(RootFile)&&isempty(i1_series)
     errormsg='no input file in the series';
+    msgbox_uvmat('ERROR',errormsg)
+    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
     return
 end
 if strcmp(FileType,'txt')
     edit(fileinput)
+    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
     return
 elseif strcmp(FileType,'xml')
     editxml(fileinput)
+    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
      return
 elseif strcmp(FileType,'figure')
     open(fileinput)
+    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
      return
 end
@@ -670,4 +667,25 @@
 set(handles.num_ref_j,'String',num2str(ref_j)); 
 
+%% update first and last indices if they do not exist
+Param=read_GUI(handles.series);
+first_j=[];
+if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
+last_j=[];
+if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
+[i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,Param.IndexRange.PairString);
+FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
+    Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
+if ~exist(FirstFileName,'file')
+    set(handles.num_first_i,'String',num2str(ref_i))
+    set(handles.num_first_j,'String',num2str(ref_j))
+end
+[i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,Param.IndexRange.PairString);
+LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
+    Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
+if ~exist(LastFileName,'file')
+    set(handles.num_last_i,'String',num2str(ref_i))
+    set(handles.num_last_j,'String',num2str(ref_j))
+end
+
 %% update the list of recent files in the menubar and save it for future opening
 MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
@@ -699,4 +717,5 @@
 %% initiate input file series and refresh the current field view:     
 update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview);
+set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
 
 %------------------------------------------------------------------------
@@ -722,17 +741,7 @@
     diff_j_max=diff(ref_j);
     diff_i_max=diff(ref_i);
-    
-%     pair_max=squeeze(max(i1_series,[],1)); %max on pair index
-%     j_max=max(pair_max,[],1);
-%     MinIndex_i=find(j_max, 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)
-%     MaxIndex_i=find(j_max, 1, 'last' )-1;% max ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index) 
-%     diff_i_max=diff(j_max);
     if ~isempty(diff_i_max) && isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max)))
         set(handles.num_incr_i,'String',num2str(diff_i_max(1)))% detect an increment to dispaly by default
     end
-%     i_max=max(pair_max,[],2);
-%     MinIndex_j=min(find(i_max))-1;% min ref index j
-%     MaxIndex_j=max(find(i_max))-1;% max ref index j
-%     diff_j_max=diff(i_max);
     if isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max)))
         set(handles.num_incr_j,'String',num2str(diff_j_max(1)))
@@ -973,12 +982,5 @@
     ind_select=find(file_indices<=numel(j_max{iview}));
     LineData(ind_select)=j_max{iview}(file_select)~=0;
-%     LineData=zeros(1,range_index);
-%     x_index=find(j_max{iview}>0)-MinIndex_i;
-%     LineData(x_index)=1;
-%     if numel(x)>1
-%         LineData
-    %LineData=interp1(x,LineData,xI,'nearest');
     CData(ind_y,:)=ones(size(ind_y'))*LineData;
-%     end
 end
 CData=cat(3,zeros(size(CData)),CData,zeros(size(CData)));%make color images r=0,g,b=0
@@ -1088,43 +1090,30 @@
 %------------------------------------------------------------------------
 SeriesData=get(handles.series,'UserData');%
-ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
-ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
+PairString=get(handles.PairString,'Data');
+ref_i_1=str2num(get(handles.num_first_i,'String'));%first reference index
+ref_i_2=str2num(get(handles.num_last_i,'String'));%last reference index
+ref_j_1=[];ref_j_2=[];
+if strcmp(get(handles.num_first_j,'Visible'),'on')
+ref_j_1=str2num(get(handles.num_first_j,'String'));
+ref_j_2=str2num(get(handles.num_last_j,'String'));
+end
+[i1_1,i2_1,j1_1,j2_1] = get_file_index(ref_i_1,ref_j_1,PairString);
+[i1_2,i2_2,j1_2,j2_2] = get_file_index(ref_i_2,ref_j_2,PairString);
 TimeTable=get(handles.TimeTable,'Data');
-Pairs=get(handles.PairString,'Data');
+
+%Pairs=get(handles.PairString,'Data');
 for iview=1:size(TimeTable,1)
     if size(SeriesData.Time,1)<iview
         break
     end
-    i1=ref_i;
-    j1=ref_j;
-    i2=ref_i;
-    j2=ref_j;
-    % case of pairs
-    if ~isempty(Pairs{iview,1})
-        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
-        if isempty(r)
-            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
-        end
-        switch r.mode
-            case 'Di='  %  case 'series(Di)')
-                i1=ref_i-str2num(r.num1);
-                i2=ref_i+str2num(r.num2);
-            case 'Dj='  %  case 'series(Dj)'
-                j1=ref_j-str2num(r.num1);
-                j2=ref_j+str2num(r.num2);
-            case '-'  % case 'bursts'
-                j1=str2num(r.num1)*ones(size(ref_i));
-                j2=str2num(r.num2)*ones(size(ref_i));
-        end
-    end
     TimeTable{iview,2}=[];
     TimeTable{iview,3}=[];
-    if size(SeriesData.Time{iview},1)>=i2(2)+1&&size(SeriesData.Time{iview},2)>=j2(2)+1
-        if isempty(ref_j)
-            time_first=(SeriesData.Time{iview}(i1(1)+1)+SeriesData.Time{iview}(i2(1)+1))/2;
-            time_last=(SeriesData.Time{iview}(i1(2)+1)+SeriesData.Time{iview}(i2(2))+1)/2;
+    if size(SeriesData.Time{iview},1)>=i2_2+1 && (isempty(ref_j_1)||size(SeriesData.Time{iview},2)>=j2_2+1)
+        if isempty(ref_j_1)
+            time_first=(SeriesData.Time{iview}(i1_1+1,2)+SeriesData.Time{iview}(i2_1+1,2))/2;
+            time_last=(SeriesData.Time{iview}(i1_2+1,2)+SeriesData.Time{iview}(i2_2+1,2))/2;
         else
-            time_first=(SeriesData.Time{iview}(i1(1)+1,j1(1)+1)+SeriesData.Time{iview}(i2(1)+1,j2(1)+1))/2;
-            time_last=(SeriesData.Time{iview}(i1(2)+1,j1(2)+1)+SeriesData.Time{iview}(i2(2)+1,j2(2)+1))/2;
+            time_first=(SeriesData.Time{iview}(i1_1+1,j1_1+1)+SeriesData.Time{iview}(i2_1+1,j2_1+1))/2;
+            time_last=(SeriesData.Time{iview}(i1_2+1,j1_2+1)+SeriesData.Time{iview}(i2_2+1,j2_1+1))/2;
         end
         TimeTable{iview,2}=time_first; %TODO: take into account pairs
@@ -1137,6 +1126,6 @@
 MinIndex_i=min(get(handles.MinIndex_i,'Data'));
 MaxIndex_i=max(get(handles.MaxIndex_i,'Data'));
-pos_first=(ref_i(1)-MinIndex_i)/(MaxIndex_i-MinIndex_i+1);
-pos_last=(ref_i(2)-MinIndex_i+1)/(MaxIndex_i-MinIndex_i+1);
+pos_first=(ref_i_1-MinIndex_i)/(MaxIndex_i-MinIndex_i+1);
+pos_last=(ref_i_2-MinIndex_i+1)/(MaxIndex_i-MinIndex_i+1);
 Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height]
 Position_status=get(handles.FileStatus,'Position');
@@ -1145,32 +1134,4 @@
 set(handles.Waitbar,'Position',Position)
 update_waitbar(handles.Waitbar,0)
-
-% for iview=1:numel(SeriesData.i1_series)
-%     pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
-%     if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1)
-%         pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
-%     end
-%     pair_max{iview}=reshape(pair_max{iview},1,[]);
-%     index_min(iview)=find(pair_max{iview}>0, 1 );
-%     index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
-% end
-% [index_min,iview_min]=min(index_min);
-% [index_max,iview_max]=min(index_max);
-% if size(SeriesData.i1_series{iview_min},2)==1% movie
-%     index_first=ref_i(1);
-%     index_last=ref_i(2);
-% else
-%     index_first=(ref_i(1)-1)*(size(SeriesData.i1_series{iview_min},1))+ref_j(1)+1;
-%     index_last=(ref_i(2)-1)*(size(SeriesData.i1_series{iview_max},1))+ref_j(2)+1;
-% end
-% range=index_max-index_min+1;
-% coeff_min=(index_first-index_min)/range;
-% coeff_max=(index_last-index_min+1)/range;
-% Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height]
-% Position_status=get(handles.FileStatus,'Position');
-% Position(1)=coeff_min*Position_status(3)+Position_status(1);
-% Position(3)=Position_status(3)*(coeff_max-coeff_min);
-% set(handles.Waitbar,'Position',Position)
-% update_waitbar(handles.Waitbar,0)
 
 %------------------------------------------------------------------------
@@ -2028,5 +1989,5 @@
 %% Activate the Action fct
 Param=read_GUI_series(handles);% read the parameters from the GUI series
-ParamOut=h_fun(Param);
+ParamOut=h_fun(Param);%run the selected Action function to get the relevant input
 
 %% Put the first line of the selected Action fct as tooltip help
@@ -2041,5 +2002,5 @@
 SeriesData=get(handles.series,'UserData');
 iview_civ=[];nb_netcdf=0;
-if ~isempty(SeriesData)
+if ~isempty(SeriesData)&&isfield(SeriesData,'FileType')
     iview_civ=find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType));
     nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType)));
@@ -2117,5 +2078,5 @@
 InputFieldsVisible='off';%visibility of the frame Fields
 if isfield(ParamOut,'VelType')
-    if strcmp( ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
+    if strcmp( ParamOut.VelType,'on')||strcmp(ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
         if numel(iview_civ)>=1
             VelTypeVisible='on';
@@ -2138,5 +2099,5 @@
 FieldName_1Visible='off';  %hidden by default
 if isfield(ParamOut,'FieldName')
-    if strcmp( ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
+    if strcmp( ParamOut.FieldName,'on') || strcmp(ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
         if (numel(iview_civ)+nb_netcdf)>=1
             InputFieldsVisible='on';
@@ -2250,7 +2211,7 @@
 function ActionInput_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
-if get(handles.ActionInput,'Value')
-    ActionName_Callback(hObject, eventdata, handles)
-end
+% if get(handles.ActionInput,'Value')
+ActionName_Callback(hObject, eventdata, handles)
+% end
 
 %------------------------------------------------------------------------
@@ -2307,5 +2268,5 @@
                     set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
                     set(handles.NomType,'String','*')
-                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
+                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])% A VERIFIER !!!!!!
                     set(handles.FileIndex,'String','')
                     ParamIn.TimeVarName=GetFieldData.Time.TimeName;
@@ -2696,7 +2657,23 @@
 %------------------------------------------------------------------------
 function MenuImportConfig_Callback(hObject, eventdata, handles)
-
+% SeriesData=get(handles.series,'UserData');
+% if isfield(SeriesData,'RefFile')
+%     oldfile=SeriesData.RefFile{1};
+% end
+%% use a strating file name for browserr
 InputTable=get(handles.InputTable,'Data');
-filexml=uigetfile_uvmat('pick a xml parameter file',InputTable{1,1},'.xml');% get the xml file containing processing parameters
+oldfile=InputTable{1,1};
+if isempty(oldfile)
+    % use a file name stored in prefdir
+    dir_perso=prefdir;
+    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+    if exist(profil_perso,'file')
+        h=load (profil_perso);
+        if isfield(h,'RootPath') && ischar(h.RootPath)
+            oldfile=h.RootPath;
+        end
+    end
+end
+filexml=uigetfile_uvmat('pick a xml parameter file',oldfile,'.xml');% get the xml file containing processing parameters
 %proceed only if a file has been introduced by the browser
 if ~isempty(filexml)
@@ -2715,6 +2692,4 @@
     SeriesData=get(handles.series,'UserData');
     if isfield(Param,'ActionInput')%  introduce  parameters specific to an Action fct, for instance PIV parameters
-%         set(handles.ActionInput,'Visible','on')
-%         set(handles.ActionInput_title,'Visible','on')
         set(handles.ActionInput,'Visible','on')
         set(handles.ActionInput,'Value',0)
@@ -2737,7 +2712,5 @@
         set(handles.DeleteObject,'Visible','off')     
     end     
-%     set(handles.REFRESH,'Visible','on')
     set(handles.REFRESH,'BackgroundColor',[1 0 1]); %paint REFRESH button in magenta to indicate that it should be activated
-  %  REFRESH_Callback([],[],handles)% refresh data relative to the input files
 end
 
@@ -2802,5 +2775,10 @@
     OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
     OutputDir=fullfile(RootPath,OutputSubDir);
-    uigetfile_uvmat('status_display',OutputDir)
+    if exist(OutputDir,'dir')
+        uigetfile_uvmat('status_display',OutputDir)
+    else
+        msgbox_uvmat('ERROR','output folder not created yet: calculation did not start')
+        set(handles.status,'BackgroundColor',[0 1 0])
+    end
 else
     %% delete current display fig if selection is off
