Index: trunk/src/browse_data.m
===================================================================
--- trunk/src/browse_data.m	(revision 837)
+++ trunk/src/browse_data.m	(revision 856)
@@ -24,5 +24,5 @@
 function varargout = browse_data(varargin)
 
-% Last Modified by GUIDE v2.5 11-Mar-2014 22:09:37
+% Last Modified by GUIDE v2.5 24-Jan-2015 16:55:04
 
 % Begin initialization code - DO NOT EDIT
@@ -47,5 +47,5 @@
 %------------------------------------------------------------------------
 % --- Executes just before browse_data is made visible.
-function browse_data_OpeningFcn(hObject, eventdata, handles, Campaign,EnableMirror)
+function browse_data_OpeningFcn(hObject, eventdata, handles, DataSeries,EnableMirror)
 %------------------------------------------------------------------------
 
@@ -80,35 +80,44 @@
     set(handles.mirror_txt,'Visible','off')
 end
-if exist('Campaign','var')
-    [tild,CampaignName]=fileparts(Campaign);
-    RootXml=fullfile(Campaign,[CampaignName '.xml']);
-    s=[];
-    if exist(RootXml,'file') 
-        [s,Heading]=xml2struct(RootXml);%read the xml file
-        if isfield(s,'SourceDir')
-            set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
-            set(handles.MirrorDir,'Visible','on');%  mirror dir display
-            set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
-            set(handles.CreateMirror,'String','update_mirror')
-        end
-    end
-    if isempty(s) %a source dir has been opened
-        set(handles.SourceDir,'String',Campaign);
-        set(handles.MirrorDir,'Visible','off');% no mirror dir display
-        set(handles.CreateMirror,'String','create_mirror')
-    end
-    errormsg=scan_campaign(handles,Campaign);
-    if ~isempty(errormsg)
-        msgbox_uvmat('ERROR',errormsg)
-        return
-    end
-    set(handles.OK,'Visible','on')
-    set(handles.Cancel,'Visible','on')
-    set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal
-    set(hObject,'Visible','on')
-    drawnow
-    % UIWAIT makes GUI wait for user response (see UIRESUME)
-    uiwait(handles.browse_data);
-end
+
+%% initialize the GUI
+if ~(exist('DataSeries','var') && exist(DataSeries,'dir'))
+    DataSeries=pwd;% current dir is the starting data series by default
+end
+[Experiment,DataSeries,Ext]=fileparts(DataSeries);
+DataSeries=[DataSeries Ext];
+[Campaign,Experiment,Ext]=fileparts(Experiment);
+Experiment=[Experiment Ext];
+[tild,CampaignName]=fileparts(Campaign);
+RootXml=fullfile(Campaign,[CampaignName '.xml']);
+s=[];
+if exist(RootXml,'file')
+    [s,Heading]=xml2struct(RootXml);%read the xml file
+    if isfield(s,'SourceDir')
+        set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
+        set(handles.MirrorDir,'Visible','on');%  mirror dir display
+        set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
+        set(handles.CreateMirror,'String','update_mirror')
+    end
+end
+if isempty(s) %a source dir has been opened
+    set(handles.SourceDir,'String',Campaign);
+    set(handles.MirrorDir,'Visible','off');% no mirror dir display
+    set(handles.CreateMirror,'String','create_mirror')
+end
+errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries);
+if ~isempty(errormsg)
+    msgbox_uvmat('ERROR',errormsg)
+    return
+end
+set(handles.OK,'Visible','on')
+set(handles.Cancel,'Visible','on')
+
+set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal
+set(hObject,'Visible','on')
+drawnow
+% UIWAIT makes GUI wait for user response (see UIRESUME)
+uiwait(handles.browse_data);
+
 
 
@@ -190,13 +199,9 @@
 set(handles.SourceDir,'BackgroundColor',[1 1 1])
 
-
-%------------------------------------------------------------------------
-function errormsg=scan_campaign(handles,Campaign)
-%------------------------------------------------------------------------
-%set(handles.SourceDir,'BackgroundColor',[1 1 0])
-%drawnow
-%SourceDir=get(handles.SourceDir,'String');
-%MirrorDir=get(handles.MirrorDir,'String');
-% ExpName={''};
+%------------------------------------------------------------------------
+% List the experiments in a campaign, filling the menu ListExperiments
+%------------------------------------------------------------------------
+function errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries)
+%------------------------------------------------------------------------
 errormsg='';
 if exist(Campaign,'dir')
@@ -213,12 +218,20 @@
     check_keep=cellfun('isempty', cell_remove);
     ListFiles=sort((ListFiles(check_keep))');
+    index=find(strcmp(['+/' Experiment],ListFiles));
+    if isempty(index), index=0; end
     set(handles.ListExperiments,'String',[{'*'};ListFiles])
-    set(handles.ListExperiments,'Value',1)
+    set(handles.ListExperiments,'Value',index+1)% initialise the menu selection with the folder defined by the input
     ListExperiments_Callback([],[], handles)
+    ListDevices=get(handles.ListDevices,'String');
+    index=find(strcmp(['+/' DataSeries],ListDevices));
+    if isempty(index)
+        index=find(strcmp(['~/' DataSeries],ListDevices));
+    end
+    if ~isempty(index)
+          set(handles.ListDevices,'Value',index)
+    end
 else
     msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory'])
 end
-%set(handles.SourceDir,'BackgroundColor',[1 1 1])
-
 
 %------------------------------------------------------------------------
@@ -668,4 +681,9 @@
 
 
-% --- Executes during object deletion, before destroying properties.
-function browse_data_DeleteFcn(hObject, eventdata, handles)
+% --- Executes on button press in Browse.
+function Browse_Callback(hObject, eventdata, handles)
+ListDevices=get(handles.ListDevices,'String');
+Device=ListDevices{get(handles.ListDevices,'Value')};
+DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
+uiresume(handles.browse_data);
+browse_data(DataSeries)
