Index: trunk/src/series.m
===================================================================
--- trunk/src/series.m	(revision 664)
+++ trunk/src/series.m	(revision 667)
@@ -75,5 +75,4 @@
 RescaleFactor=min((ScreenSize(3)-80)/Width,(ScreenSize(4)-80)/Height);
 if RescaleFactor>1
-    %RescaleFactor=RescaleFactor/2+1/2; %reduce the rescale factor to provide an increased margin for a big screen
     RescaleFactor=min(RescaleFactor,1);
 end
@@ -89,4 +88,5 @@
 set(handles.MinIndex_i,'ColumnEditable',false)
 set(handles.MinIndex_i,'ColumnName',{'i min'})
+set(handles.MinIndex_i,'Data',[])% initiate Data to double (not cell)
 
 % settings of table MinIndex_j
@@ -94,4 +94,5 @@
 set(handles.MinIndex_j,'ColumnEditable',false)
 set(handles.MinIndex_j,'ColumnName',{'j min'})
+set(handles.MinIndex_j,'Data',[])% initiate Data to double (not cell)
 
 % settings of table MaxIndex_i
@@ -99,4 +100,5 @@
 set(handles.MaxIndex_i,'ColumnEditable',false)
 set(handles.MaxIndex_i,'ColumnName',{'i max'})
+set(handles.MaxIndex_i,'Data',[])% initiate Data to double (not cell)
 
 % settings of table MaxIndex_j
@@ -104,7 +106,14 @@
 set(handles.MaxIndex_j,'ColumnEditable',false)
 set(handles.MaxIndex_j,'ColumnName',{'j max'})
+set(handles.MaxIndex_j,'Data',[])% initiate Data to double (not cell)
 
 % settings of table PairString
 set(handles.PairString,'ColumnName',{'pairs'})
+set(handles.PairString,'ColumnEditable',false)
+set(handles.PairString,'ColumnFormat',{'char'})
+set(handles.PairString,'Data',{''})
+
+% settings of table MaskTable
+set(handles.MaskTable,'ColumnName',{'mask name'})
 set(handles.PairString,'ColumnEditable',false)
 set(handles.PairString,'ColumnFormat',{'char'})
@@ -154,4 +163,5 @@
         for ifile=1:min(length(h.MenuFile),5)
             set(handles.(['MenuFile_' num2str(ifile)]),'Label',h.MenuFile{ifile});
+            set(handles.(['MenuFile_' num2str(ifile+5)]),'Label',h.MenuFile{ifile});
         end
     end
@@ -306,9 +316,41 @@
 fileinput=uigetfile_uvmat('pick a file to append in the input table',oldfile);
 if ~isempty(fileinput)
-    if get(handles.CheckAppend,'Value')
+%     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')
-    else
-        display_file_name(handles,fileinput,'one')
-    end
 end
 
@@ -318,9 +360,16 @@
 function MenuFile_Callback(hObject, eventdata, handles)
 
-fileinput=get(hObject,'Label');
-if get(handles.CheckAppend,'Value')
-    display_file_name(handles,fileinput,'append')
+display_file_name(handles,get(hObject,'Label'),'one')
+
+%------------------------------------------------------------------------
+% --- fct activated by selecting a previous file under the menu Open/append
+%------------------------------------------------------------------------
+function MenuFile_append_Callback(hObject, eventdata, handles)
+
+InputTable=get(handles.InputTable,'Data');
+if isempty(InputTable{1,1})% no input file in the table
+    display_file_name(handles,get(hObject,'Label'),'one') %refresh the input table, not append
 else
-    display_file_name(handles,fileinput,'one')
+    display_file_name(handles,get(hObject,'Label'),'append')% append the selected file to the current list of InputTable
 end
 
@@ -424,5 +473,5 @@
 %------------------------------------------------------------------------
 set(handles.REFRESH,'Visible','on')
-set(handles.REFRESH_title,'Visible','on')
+% set(handles.REFRESH_title,'Visible','on')
 iview=eventdata.Indices(1);
 view_set=get(handles.REFRESH,'UserData');
@@ -489,5 +538,5 @@
 % iview: line index in the input table
 %       or 'one': refresh the list
-%       'checkappend': add a new line to the list
+%         'append': add a new line to the input table
 
 %% get the input root name, indices, file extension and nomenclature NomType
@@ -581,5 +630,4 @@
 ref_j=floor((j1+j2)/2);% reference image number corresponding to the file
 set(handles.num_ref_j,'String',num2str(ref_j)); 
-% set(handles.num_ref_j,'UserData',[j1 j2]);%store the indices for future opening
 
 %% update the list of recent files in the menubar and save it for future opening
@@ -629,18 +677,8 @@
     ref_i=squeeze(max(i1_series(1,:,:),[],2));% select ref_j index for each ref_i
     ref_j=squeeze(max(j1_series(1,:,:),[],3));% select ref_i index for each ref_j
-%     [ref_j,ref_i]=find(squeeze(i1_series(1,:,:)));
-%     [ref_j,ref_i]=find(squeeze(i1_series(1,:,:)))
      MinIndex_i=min(find(ref_i))-1;
      MaxIndex_i=max(find(ref_i))-1;
-%         MinIndex_j=min(ref_j)-1;
      MaxIndex_j=max(find(ref_j))-1;
-%     MinIndex_j=min(find(j1_series_j))-1;
-%     MaxIndex_j=max(find(j1_series_j))-1;
-%     MaxIndex_i=max(i1_series_i)-1;
-%     MinIndex_j=min(i1_series_j)-1;
-%     MaxIndex_j=max(i1_series_j)-1;
-%     MaxIndex_i=max(ref_i)-1;
      MinIndex_j=min(find(ref_j))-1;
-%     MaxIndex_j=max(ref_j)-1;
     diff_j_max=diff(ref_j);
     diff_i_max=diff(ref_i);
@@ -668,16 +706,16 @@
     MinIndex_j=0;
 end
-MinIndex_i_cell=get(handles.MinIndex_i,'Data');%retrieve the min indices in the table MinIndex
-MinIndex_j_cell=get(handles.MinIndex_j,'Data');%retrieve the min indices in the table MinIndex
-MaxIndex_i_cell=get(handles.MaxIndex_i,'Data');%retrieve the min indices in the table MinIndex
-MaxIndex_j_cell=get(handles.MaxIndex_j,'Data');%retrieve the min indices in the table MinIndex
-MinIndex_i_cell(iview,1)=MinIndex_i;
-MinIndex_j_cell(iview,1)=MinIndex_j;
-MaxIndex_i_cell(iview,1)=MaxIndex_i;
-MaxIndex_j_cell(iview,1)=MaxIndex_j;
-set(handles.MinIndex_i,'Data',MinIndex_i_cell)%display the min indices in the table MinIndex
-set(handles.MinIndex_j,'Data',MinIndex_j_cell)%display the max indices in the table MaxIndex
-set(handles.MaxIndex_i,'Data',MaxIndex_i_cell)%display the min indices in the table MinIndex
-set(handles.MaxIndex_j,'Data',MaxIndex_j_cell)%display the max indices in the table MaxIndex
+MinIndex_i_table=get(handles.MinIndex_i,'Data');%retrieve the min indices in the table MinIndex
+MinIndex_j_table=get(handles.MinIndex_j,'Data');%retrieve the min indices in the table MinIndex
+MaxIndex_i_table=get(handles.MaxIndex_i,'Data');%retrieve the min indices in the table MinIndex
+MaxIndex_j_table=get(handles.MaxIndex_j,'Data');%retrieve the min indices in the table MinIndex
+MinIndex_i_table(iview,1)=MinIndex_i;
+MinIndex_j_table(iview,1)=MinIndex_j;
+MaxIndex_i_table(iview,1)=MaxIndex_i;
+MaxIndex_j_table(iview,1)=MaxIndex_j;
+set(handles.MinIndex_i,'Data',MinIndex_i_table)%display the min indices in the table MinIndex
+set(handles.MinIndex_j,'Data',MinIndex_j_table)%display the max indices in the table MaxIndex
+set(handles.MaxIndex_i,'Data',MaxIndex_i_table)%display the min indices in the table MinIndex
+set(handles.MaxIndex_j,'Data',MaxIndex_j_table)%display the max indices in the table MaxIndex
 
 %% adjust the first and last indices for the selected series, only if requested by the bounds
@@ -787,8 +825,6 @@
 %% read timing and total frame number from the current file (movie files) if not already set by the xml file (prioritary)
 InputTable=get(handles.InputTable,'Data');
-% FileBase=fullfile(InputTable{iview,1},InputTable{iview,3});
 
 % case of movies
-% if strcmp(InputTable{iview,4},'*')
 if isempty(Time)
     if ~isempty(VideoObject)
@@ -801,17 +837,4 @@
         end
         TimeSource='video';
-        % set(han:dles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
-        %     ColorType='truecolor';
-%     elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image
-%         if ~isempty(InputTable{iview,2})
-%             imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}]));
-%         else
-%             imainfo=imfinfo([FileBase InputTable{iview,5}]);
-%         end
-%         %     ColorType=imainfo.ColorType;%='truecolor' for color images
-% %         if length(imainfo) >1 %case of image with multiple frames
-% %             nbfield=length(imainfo);
-% %             nbfield_j=1;
-% %         end
     end
 end
@@ -820,12 +843,4 @@
 if ~isempty(Time)
     TimeTable=get(handles.TimeTable,'Data');
-    %     first_i=str2num(get(handles.num_first_i,'String'));
-    %     last_i=str2num(get(handles.num_last_i,'String'));
-    %     first_j=str2num(get(handles.num_first_j,'String'));
-    %     last_j=str2num(get(handles.num_last_j,'String'));
-    %     MinIndex_i=get(handles.MinIndex_i,'Data');
-    %     MinIndex_j=get(handles.MinIndex_j,'Data');
-    %     MaxIndex_i=get(handles.MaxIndex_i,'Data');
-    %     MaxIndex_j=get(handles.MaxIndex_j,'Data');
     TimeTable{iview,1}=Time(MinIndex_i+1,MinIndex_j+1);
     if size(Time)>=[first_i+1 first_j+1]
@@ -840,5 +855,4 @@
     set(handles.TimeTable,'Data',TimeTable)
 end
-   
 
 %% update the series info in 'UserData'
@@ -1986,19 +2000,18 @@
 %% Detect the types of input files
 SeriesData=get(handles.series,'UserData');
-nb_civ=0;nb_netcdf=0;
+iview_civ=[];nb_netcdf=0;
 if ~isempty(SeriesData)
-    nb_civ=numel(find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType)));
+    iview_civ=find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType));
     nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType)));
 end
-if nb_civ>=1
-    menu=set_veltype_display(SeriesData.FileInfo{1}.CivStage,SeriesData.FileType{1});
+%menu={''};
+if numel(iview_civ)>=1
+    menu=set_veltype_display(SeriesData.FileInfo{iview_civ(1)}.CivStage,SeriesData.FileType{iview_civ(1)});
     set(handles.VelType,'String',[{'*'};menu])
-    if nb_civ>=2
-        menu=set_veltype_display(SeriesData.FileInfo{2}.CivStage,SeriesData.FileType{2});
+    if numel(iview_civ)>=2
+        menu=set_veltype_display(SeriesData.FileInfo{iview_civ(2)}.CivStage,SeriesData.FileType{iview_civ(2)});
         set(handles.VelType_1,'String',[{'*'};menu])
     end
-end
-        
-    
+end       
 
 %% Check whether alphabetical sorting of input Subdir is alowed by the Action fct  (for multiples series entries)
@@ -2065,5 +2078,5 @@
 if isfield(ParamOut,'VelType')
     if strcmp( ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
-        if nb_civ>=1
+        if numel(iview_civ)>=1
             VelTypeVisible='on';
             InputFieldsVisible='on';
@@ -2071,5 +2084,5 @@
     end
     if strcmp( ParamOut.VelType,'two')
-        if nb_civ>=2
+        if numel(iview_civ)>=2
             VelType_1Visible='on';
         end
@@ -2086,5 +2099,5 @@
 if isfield(ParamOut,'FieldName')
     if strcmp( ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
-        if (nb_civ+nb_netcdf)>=1
+        if (numel(iview_civ)+nb_netcdf)>=1
             InputFieldsVisible='on';
             FieldNameVisible='on';
@@ -2092,5 +2105,5 @@
     end
     if strcmp( ParamOut.FieldName,'two')
-        if (nb_civ+nb_netcdf)>=1
+        if (numel(iview_civ)+nb_netcdf)>=1
             FieldName_1Visible='on';
         end
@@ -2360,12 +2373,13 @@
                 defaultname={''};
             end
-            [FileName, PathName] = uigetfile( ...
-                {'*.xml;*.mat', ' (*.xml,*.mat)';
-                '*.xml',  '.xml files '; ...
-                '*.mat',  '.mat matlab files '}, ...
-                'Pick an xml object file (or use uvmat to create it)',defaultname);
-            fileinput=[PathName FileName];%complete file name
-            sizf=size(fileinput);
-            if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
+            fileinput=uigetfile_uvmat('pick a xml object file (or use uvmat to create it)',defaultname,'.xml');
+%             [FileName, PathName] = uigetfile( ...
+%                 {'*.xml;*.mat', ' (*.xml,*.mat)';
+%                 '*.xml',  '.xml files '; ...
+%                 '*.mat',  '.mat matlab files '}, ...
+%                 'Pick an xml object file (or use uvmat to create it)',defaultname);
+%             fileinput=[PathName FileName];%complete file name
+%             sizf=size(fileinput);
+            if isempty(fileinput),return;end
             %read the file
             data=xml2struct(fileinput);
@@ -2404,15 +2418,19 @@
 function ViewObject_Callback(hObject, eventdata, handles)
 
-if get(handles.ViewObject,'Value')
-    set(handles.EditObject,'Value',0)
+% if get(handles.ViewObject,'Value')
+   % set(handles.EditObject,'Value',0)
 	UserData=get(handles.series,'UserData');
+    hset_object=findobj(allchild(0),'Tag','set_object');
+    if ~isempty(hset_object)
+        delete(hset_object)% refresh set_object if already opened
+    end
     hset_object=set_object(UserData.ProjObject);
     set(hset_object,'Name','view_object_series')
-else
-    hset_object=findobj(allchild(0),'Tag','set_object');
-    if ~isempty(hset_object)
-        delete(hset_object)
-    end 
-end
+% else
+%     hset_object=findobj(allchild(0),'Tag','set_object');
+%     if ~isempty(hset_object)
+%         delete(hset_object)
+%     end 
+% end
 
 %------------------------------------------------------------------------
@@ -2428,7 +2446,7 @@
     set(get(hset_object,'Children'),'Enable','on')
 else
-    hset_object=findobj(allchild(0),'Tag','set_object');
+    hset_object=findobj(allchild(0),'Tag','set_object'); 
     if ~isempty(hset_object)
-        delete(hset_object)
+        set(get(hset_object,'Children'),'Enable','off')
     end 
 end
@@ -2439,5 +2457,5 @@
 function DeleteObject_Callback(hObject, eventdata, handles)
 
-if get(handles.DeleteObject,'Value')
+% if get(handles.DeleteObject,'Value')
 	SeriesData=get(handles.series,'UserData');
     SeriesData.ProjObject=[];
@@ -2445,38 +2463,87 @@
     set(handles.ProjObject,'String','')
     set(handles.CheckObject,'Value',0)
+    set(handles.ViewObject,'Visible','off')
+    set(handles.EditObject,'Visible','off')
+    hset_object=findobj(allchild(0),'Tag','set_object');
+    if ~isempty(hset_object)
+        delete(hset_object)
+    end
     set(handles.DeleteObject,'Visible','off')
-    set(handles.ViewObject,'Visible','off')
-    set(handles.DeleteObject,'Value',0)
-end
-
-%--------------------------------------------------------------
+%     set(handles.DeleteObject,'Value',0)
+% end
+
+%------------------------------------------------------------------------
+% --- Executed when CheckMask is activated
+%------------------------------------------------------------------------
 function CheckMask_Callback(hObject, eventdata, handles)
+
 if get(handles.CheckMask,'Value')
+    MaskData=get(handles.MaskTable,'Data');
     InputTable=get(handles.InputTable,'Data');
-    for iview=1:size(InputTable,1)
+    nbview=size(InputTable,1);
+    %     MaskTable=cell(nbview,1);
+    for iview=1:nbview
         RootPath=InputTable{iview,1};
-        SubDir=InputTable{iview,2};
-        MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
-        MaskName=fullfile(RootPath,[MaskSubDir '.mask'],'mask_1.png');
-        if ~exist(MaskName,'file')
-            msgbox_uvmat('WARNING',['mask file '  MaskName ' not found'])
-            return
-        end
-    end
-end
-%--------------------------------------------------------------
+        if ~isempty(RootPath)
+            if isempty(MaskData{iview})
+                SubDir=InputTable{iview,2};
+                MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
+                MaskName=fullfile(RootPath,[MaskSubDir '.mask'],'mask_1.png');
+                if ~exist(MaskName,'file')
+                    MaskName=uigetfile_uvmat('select a mask file:',RootPath,'image');
+                end
+                MaskTable{iview,1}=MaskName ;
+                ListMask{iview,1}=num2str(iview);
+            end
+        end
+    end
+    nbview=size(MaskTable,1);
+    set(handles.MaskTable,'Data',MaskTable)
+    %     set(handles.MaskTable,'ColumnFormat',{MaskTable'})
+    set(handles.MaskTable,'Visible','on')
+    set(handles.MaskBrowse,'Visible','on')
+    set(handles.ListMask,'Visible','on')
+    set(handles.ListMask,'String',ListMask)
+    set(handles.ListMask,'Value',numel(ListMask))
+else
+    set(handles.MaskTable,'Visible','off')
+    set(handles.MaskBrowse,'Visible','off')
+    set(handles.ListMask,'Visible','off')
+end
+
+%------------------------------------------------------------------------
+% --- Executes on button press in MaskBrowse.
+%------------------------------------------------------------------------
+function MaskBrowse_Callback(hObject, eventdata, handles)
+InputTable=get(handles.InputTable,'Data');
+iview=get(handles.ListMask,'Value');
+%     MaskTable=cell(nbview,1);
+
+RootPath=InputTable{iview,1};
+%         if ~isempty(RootPath)
+%         SubDir=InputTable{iview,2};
+%         MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
+%         MaskName=fullfile(RootPath,[MaskSubDir '.mask'],'mask_1.png');
+%         if ~exist(MaskName,'file')
+MaskName=uigetfile_uvmat('select a mask file:',RootPath,'image');
+%         end
+if ~isempty(MaskName)
+    MaskTable=get(handles.MaskTable,'Data');
+MaskTable{iview,1}=MaskName ;
+%         end
+set(handles.MaskTable,'Data',MaskTable)
+end
+   % set(handles.MaskTable,'ColumnFormat',{MaskTable'})
+
+%------------------------------------------------------------------------
+% --- Executes when selected cell(s) is changed in MaskTable.
+%------------------------------------------------------------------------
+function MaskTable_CellSelectionCallback(hObject, eventdata, handles)
+
+if numel(eventdata.Indices)>=1
+set(handles.ListMask,'Value',eventdata.Indices(1))
+end
 
 %-------------------------------------------------------------------
-%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
-function ncbrowser_uvmat(hObject, eventdata)
-%-------------------------------------------------------------------
-     bla=get(gcbo,'String');
-     ind=get(gcbo,'Value');
-     filename=cell2mat(bla(ind));
-      blank=find(filename==' ');
-      filename=filename(1:blank-1);
-     get_field(filename)
-
-% ------------------------------------------------------------------
 function MenuHelp_Callback(hObject, eventdata, handles)
 %-------------------------------------------------------------------
@@ -2624,4 +2691,10 @@
 set(handles.PairString,'Unit','normalized')
 set(handles.PairString,'ColumnWidth',{Pos(3)-5})
+
+%% MaskTable
+set(handles.MaskTable,'Unit','pixel')
+Pos=get(handles.MaskTable,'Position');
+set(handles.MaskTable,'Unit','normalized')
+set(handles.MaskTable,'ColumnWidth',{Pos(3)-5})
 
 %------------------------------------------------------------------------
