Ignore:
Timestamp:
Jul 9, 2019, 10:10:18 AM (5 years ago)
Author:
sommeria
Message:

replicate updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/browse_data.m

    r1064 r1068  
    1 %'browse_data': function for scanning directories in a campaign
     1
     2%'browse_data': function for scanning directories in a campaign
    23%------------------------------------------------------------------------
    34% function varargout = series(varargin)
     
    2425function varargout = browse_data(varargin)
    2526
    26 % Last Modified by GUIDE v2.5 17-Apr-2019 18:15:24
     27% Last Modified by GUIDE v2.5 08-Jul-2019 23:32:39
    2728
    2829% Begin initialization code - DO NOT EDIT
    2930gui_Singleton = 1;
    3031gui_State = struct('gui_Name',       mfilename, ...
    31                    'gui_Singleton',  gui_Singleton, ...
    32                    'gui_OpeningFcn', @browse_data_OpeningFcn, ...
    33                    'gui_OutputFcn',  @browse_data_OutputFcn, ...
    34                    'gui_LayoutFcn',  [] , ...
    35                    'gui_Callback',   []);
    36 if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))             
     32    'gui_Singleton',  gui_Singleton, ...
     33    'gui_OpeningFcn', @browse_data_OpeningFcn, ...
     34    'gui_OutputFcn',  @browse_data_OutputFcn, ...
     35    'gui_LayoutFcn',  [] , ...
     36    'gui_Callback',   []);
     37if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
    3738    gui_State.gui_Callback = str2func(varargin{1});
    3839end
     
    7475set(hObject, 'Position', FigPos);
    7576set(hObject, 'Units', OldUnits);
    76 if exist('MultiDevices','var') && strcmp(MultiDevices,'on')
    77     set(handles.DataSeries,'Max',2)
    78 else
    79     set(handles.DataSeries,'Max',1)
    80 end
     77% if exist('MultiDevices','var') && strcmp(MultiDevices,'on')
     78%     set(handles.DataSeries,'Max',2)
     79% else
     80%     set(handles.DataSeries,'Max',1)
     81% end
    8182if exist('EnableMirror','var') && strcmp(EnableMirror,'on')
    8283    set(handles.CreateMirror,'Visible','on')
     
    9192    InputDir=pwd;% current dir is the starting data series by default
    9293end
    93 % [Experiment,DataSeries,Ext]=fileparts(DataSeries);
    94 % DataSeries=[DataSeries Ext];
    95 % [Campaign,Experiment,Ext]=fileparts(Experiment);
    96 % Experiment=[Experiment Ext];
     94
    9795[ExpWithPath,DataSeries]=fileparts(InputDir);
    98 [Campaign,Experiment,Ext]=fileparts(ExpWithPath);
    99 [tild,CampaignName]=fileparts(Campaign);
    100 RootXml=fullfile(Campaign,[CampaignName '.xml']);
     96[Experiment,Device,Ext]=fileparts(ExpWithPath);
     97Device=[Device Ext];
     98[SourceDir,Experiment,Ext]=fileparts(Experiment);
     99Experiment=[Experiment Ext];
     100% [tild,CampaignName]=fileparts(Campaign);
     101% RootXml=fullfile(Campaign,[CampaignName '.xml']);
    101102s=[];
    102 if exist(RootXml,'file')
    103     [s,Heading]=xml2struct(RootXml);%read the xml file
    104     if isfield(s,'SourceDir')
    105         set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
    106         set(handles.MirrorDir,'Visible','on');%  mirror dir display
    107         set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
    108         set(handles.CreateMirror,'String','update_mirror')
    109     end
    110 end
     103% if exist(RootXml,'file')
     104%     [s,Heading]=xml2struct(RootXml);%read the xml file
     105%     if isfield(s,'SourceDir')
     106%         set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
     107%         set(handles.MirrorDir,'Visible','on');%  mirror dir display
     108%         set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
     109%         set(handles.CreateMirror,'String','update_mirror')
     110%     end
     111% end
    111112if isempty(s) %a source dir has been opened
    112     set(handles.SourceDir,'String',Campaign);
     113    set(handles.SourceDir,'String',SourceDir);
    113114    set(handles.MirrorDir,'Visible','off');% no mirror dir display
    114115    set(handles.CreateMirror,'String','create_mirror')
    115116end
    116 errormsg=scan_campaign(handles,Campaign,Experiment,ExpWithPath);
     117set(handles.DataSeries,'String',{['+/' DataSeries]});
     118set(handles.ListDevices,'String',{['+/' Device]});
     119errormsg=scan_campaign(handles,SourceDir,['+/' Experiment]);
    117120if ~isempty(errormsg)
    118121    msgbox_uvmat('ERROR',errormsg)
    119122    return
    120123end
    121 % set(handles.OK,'Visible','on')
    122 % set(handles.Cancel,'Visible','on')
    123 
    124 %set(handles.browse_data,'WindowStyle','modal')% Make the GUI
    125 %modal%%%%%%%%%%%%%%%%%%%%%%%
     124
    126125set(hObject,'Visible','on')
    127 drawnow
    128 % UIWAIT makes GUI wait for user response (see UIRESUME)%%%%%%%%%%%%%%%%TO
    129 % CHECK
    130 %uiwait(handles.browse_data);
    131 
    132 
    133 
     126drawnow     
     127       
    134128%------------------------------------------------------------------------
    135129% --- Outputs from this function are returned to the command line.
     
    149143[SourcePath,ProjectName]=fileparts(SourceDir);
    150144if strcmp(get(handles.MirrorDir,'Visible'),'on')
    151     MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder
     145MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder
    152146else% create the mirror folder if it does not exist
    153     MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir');
    154     if isempty(MirrorRoot)
    155         return
    156     elseif strcmp(MirrorRoot,SourcePath)
    157         msgbox_uvmat('ERROR','The mirror folder must be different from the source')
    158         return
    159     else
    160         MirrorDir=fullfile(MirrorRoot,ProjectName);
    161     end
    162     if exist(MirrorDir,'dir')
    163         msgbox_uvmat('ERROR',['The folder ' MirrorDir ' chosen as new mirror campaign already exists'])
    164         return
    165     else
    166         [s,errormsg]=mkdir(MirrorDir)% create the mirror dir
    167         if s~=1
    168             msgbox_uvmat('ERROR',['error in creating ' MirrorDir ': ' errormsg])
    169             return
    170         end
    171     end
    172     MirrorDoc.SourceDir=SourceDir;
    173     t=struct2xml(MirrorDoc);
    174     set(t,1,'name','DataTree');
    175     save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder
    176     set(handles.MirrorDir,'String',MirrorDir)
    177     set(handles.MirrorDir,'Visible','on')
    178     set(handles.CreateMirror,'String','update_mirror')
     147MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir');
     148if isempty(MirrorRoot)
     149return
     150elseif strcmp(MirrorRoot,SourcePath)
     151msgbox_uvmat('ERROR','The mirror folder must be different from the source')
     152return
     153else
     154MirrorDir=fullfile(MirrorRoot,ProjectName);
     155end
     156if exist(MirrorDir,'dir')
     157msgbox_uvmat('ERROR',['The folder ' MirrorDir ' chosen as new mirror campaign already exists'])
     158return
     159else
     160[s,errormsg]=mkdir(MirrorDir)% create the mirror dir
     161if s~=1
     162msgbox_uvmat('ERROR',['error in creating ' MirrorDir ': ' errormsg])
     163return
     164end
     165end
     166MirrorDoc.SourceDir=SourceDir;
     167t=struct2xml(MirrorDoc);
     168set(t,1,'name','DataTree');
     169save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder
     170set(handles.MirrorDir,'String',MirrorDir)
     171set(handles.MirrorDir,'Visible','on')
     172set(handles.CreateMirror,'String','update_mirror')
    179173end
    180174ExpName={''};
     
    182176%% update the mirror from the source dir
    183177if exist(SourceDir,'dir')
    184     hdir=dir(SourceDir); %list files and dirs
    185     idir=0;
    186     for ilist=1:length(hdir)
    187         if hdir(ilist).isdir% scan all subfolders
    188             dirname=hdir(ilist).name;%
    189             if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')%skip subfolder beginning by '0'
    190                 idir=idir+1;
    191                 mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror
    192                 if ~exist(mirror,'dir')
    193                    mkdir(mirror)% create the mirror folder if it does not exist
    194                 end
    195                 ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder
    196             end
    197             % look for the list of 'devices'
    198         else
    199             %warning for isolated files
    200         end
    201     end
    202     set(handles.ListExperiments,'String',[{'*'};ExpName'])
    203     set(handles.ListExperiments,'Value',1)
    204      update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir)
    205    % ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment
    206 else
    207     msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory'])
     178hdir=dir(SourceDir); %list files and dirs
     179idir=0;
     180for ilist=1:length(hdir)
     181if hdir(ilist).isdir% scan all subfolders
     182dirname=hdir(ilist).name;%
     183if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')%skip subfolder beginning by '0'
     184idir=idir+1;
     185mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror
     186if ~exist(mirror,'dir')
     187mkdir(mirror)% create the mirror folder if it does not exist
     188end
     189ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder
     190end
     191% look for the list of 'devices'
     192else
     193%warning for isolated files
     194end
     195end
     196set(handles.ListExperiments,'String',[{'*'};ExpName'])
     197set(handles.ListExperiments,'Value',1)
     198update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir)
     199% ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment
     200else
     201msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory'])
    208202end
    209203set(handles.SourceDir,'BackgroundColor',[1 1 1])
     
    212206% List the experiments in a campaign, filling the menu ListExperiments
    213207%------------------------------------------------------------------------
    214 function errormsg=scan_campaign(handles,Campaign,Experiment,DataInput)
     208function errormsg=scan_campaign(handles,SourceDir,Experiment)
    215209%------------------------------------------------------------------------
    216210errormsg='';
    217 if ~isempty(regexp(Campaign,'^http'))|| exist(Campaign,'dir')
    218     ListStruct=dir_uvmat(Campaign); %list files and dirs
     211if ~isempty(regexp(SourceDir,'^http'))|| exist(SourceDir,'dir')
     212    ListStruct=dir_uvmat(SourceDir); %list files and dirs, extende to OpenDAP case
    219213    if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders
    220         errormsg=[Campaign ' contains too many items (>1000) to be a Project folder'];
     214        errormsg=[SourceDir ' contains too many items (>1000) to be a Project folder'];
    221215        return
    222216    end
     217    [ListFiles,index]=list_dir_1(SourceDir,Experiment);
     218    set(handles.ListExperiments,'String',ListFiles)
     219    set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input
     220    ListExperiments_Callback([],[], handles)
     221else
     222    msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory'])
     223end
     224
     225%------------------------------------------------------------------------
     226% --- Executes on selection change in ListExperiments.
     227%------------------------------------------------------------------------
     228function ListExperiments_Callback(hObject, eventdata, handles)
     229
     230if strcmp(get(handles.MirrorDir,'Visible'),'on')
     231    SourceDir=get(handles.MirrorDir,'String');
     232else
     233    SourceDir=get(handles.SourceDir,'String');
     234end
     235ListExperiments=get(handles.ListExperiments,'String');
     236list_val=get(handles.ListExperiments,'Value');
     237ListExperiments=ListExperiments(list_val);%choose the selected experiments
     238ListDevices=get(handles.ListDevices,'String');% list of devices
     239list_val=get(handles.ListDevices,'Value');% currently selected devices
     240Device='';
     241if numel(ListDevices)>=list_val
     242Device=ListDevices(list_val);%choose selected devices
     243end
     244[ListFiles,indices]=list_dir_2(SourceDir,ListExperiments,Device);
     245set(handles.ListDevices,'String',ListFiles)
     246set(handles.ListDevices,'Value',indices)% initialise the menu selection with the folder defined by the input
     247ListDevices_Callback([],[], handles)
     248
     249%------------------------------------------------------------------------
     250% --- Executes on selection change in ListExperiments.
     251%------------------------------------------------------------------------
     252function ListDevices_Callback(hObject, eventdata, handles)
     253
     254ListDevices=get(handles.ListDevices,'String');% list of devices
     255list_val=get(handles.ListDevices,'Value');% currently selected devices
     256ListDevices=ListDevices(list_val);%choose selected devices
     257if strcmp(get(handles.MirrorDir,'Visible'),'on')
     258    SourceDir=get(handles.MirrorDir,'String');
     259else
     260    SourceDir=get(handles.SourceDir,'String');
     261end
     262ListExperiments=get(handles.ListExperiments,'String');
     263list_val=get(handles.ListExperiments,'Value');
     264ListExperiments=ListExperiments(list_val);%choose the selected experiments
     265
     266DataSeries=get(handles.DataSeries,'String');
     267list_val=get(handles.DataSeries,'Value');
     268if numel(DataSeries)>=list_val
     269    DataSeries=DataSeries(list_val);
     270else
     271    DataSeries=[];
     272end
     273[ListFiles,indices]=list_dir_3(SourceDir,ListExperiments,ListDevices,DataSeries);
     274set(handles.DataSeries,'String',ListFiles)
     275set(handles.DataSeries,'Value',indices)% initialise the menu selection with the folder defined by the input
     276
     277%------------------------------------------------------------------------
     278% --- List the DataSeries when a set of experiments is selected
     279%------------------------------------------------------------------------
     280% function list_dataseries(handles,ListExperiments,MirrorPath)
     281%
     282% DataSeries={};
     283% for iexp=1:numel(ListExperiments)
     284% if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
     285% ListExperiments{iexp}(1)=[];%remove the first char '+' used to mark folders
     286% ListStruct=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
     287% ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
     288% ListFiles=ListCells(1,:);%list of dir and file  names
     289% cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
     290% cell_remove_tild=regexp(ListFiles,'~$');% detect tild the end of file nqme (do not list)
     291% check_keep=cellfun('isempty', cell_remove) & cellfun('isempty', cell_remove_tild);
     292% check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     293% for ilist=1:numel(ListFiles)
     294%     if check_keep(ilist)% loop on eligible DataSeries folders
     295%         mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});%source folder
     296%         if ~exist(mirror,'file') && ~exist(mirror,'dir')% if the name is a broken link
     297%             delete(mirror)% delete broken link
     298%         else %update the list of dataSeries
     299%             [tild,msg]=fileattrib(mirror);
     300%             if check_dir(ilist)
     301%                 ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
     302%             end
     303%             if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
     304%                 DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list
     305%             end
     306%         end
     307%     end
     308% end
     309% end
     310% end
     311% if get(handles.CheckDevices,'Value')
     312% set(handles.ListDevices,'Value',1)
     313% set(handles.ListDevices,'String',sort(DataSeries))
     314% CheckDevices_Callback([],[], handles)
     315% else
     316% set(handles.DataSeries,'Value',1)
     317% set(handles.DataSeries,'String',sort(DataSeries))
     318% end
     319
     320%------------------------------------------------------------------------
     321% Provide a list to display
     322%------------------------------------------------------------------------
     323function [ListFiles,indices]=list_dir_1(SourceDir,ListSub)
     324
     325    ListStruct=dir_uvmat(SourceDir); %list files and dirs, extende to OpenDAP case
    223326    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
    224     ListFiles=ListCells(1,:);%list of dir and file  names
     327    ListFiles=ListCells(1,:);
    225328    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
    226329    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
     
    228331    check_keep=cellfun('isempty', cell_remove);
    229332    ListFiles=sort((ListFiles(check_keep))');
    230     index=find(strcmp(['+/' Experiment],ListFiles));
    231     if isempty(index), index=1; end
    232     set(handles.ListExperiments,'String',ListFiles)
    233     set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input
    234     ListExperiments_Callback([],[], handles)
    235     DataSeries=get(handles.DataSeries,'String');
    236     index=find(strcmp(['+/' DataInput],DataSeries));
    237     if isempty(index)
    238         index=find(strcmp(['~/' DataInput],DataSeries));
     333
     334if ischar(ListSub)
     335    indices=find(strcmp(ListSub,ListFiles));
     336else
     337    indices=[];
     338    for ilist=1:numel(ListSub)
     339        index=find(strcmp(ListSub{ilist},ListFiles));
     340        indices=[indices index];
    239341    end
    240     if ~isempty(index)
    241           set(handles.DataSeries,'Value',index)
     342end
     343if isempty(indices), indices=1; end
     344
     345%------------------------------------------------------------------------
     346% Provide a list to display
     347%------------------------------------------------------------------------
     348function [ListFilesTot,indices]=list_dir_2(SourceDir,ListDir,ListSub)
     349ListFilesTot={};
     350for ilist=1:numel(ListDir)
     351    if ~isempty(regexp(ListDir{ilist},'^\+/'))
     352    ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
     353    ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist})); %list files and dirs, extende to OpenDAP case
     354    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     355    ListFiles=ListCells(1,:);
     356    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     357    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
     358    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
     359    check_keep=cellfun('isempty', cell_remove);
     360    ListFilesTot=[ListFilesTot;(ListFiles(check_keep))'];
    242361    end
    243 else
    244     msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory'])
    245 end
    246 
    247 %------------------------------------------------------------------------
    248 % --- Executes on selection change in ListExperiments.
    249 %------------------------------------------------------------------------
    250  function ListExperiments_Callback(hObject, eventdata, handles)
    251 
    252 if strcmp(get(handles.MirrorDir,'Visible'),'on')
    253     MirrorPath=get(handles.MirrorDir,'String');
    254 else
    255     MirrorPath=get(handles.SourceDir,'String');
    256 end
    257 ListExperiments=get(handles.ListExperiments,'String');
    258 list_val=get(handles.ListExperiments,'Value');
    259 ListExperiments=ListExperiments(list_val);%choose selected experiments
    260 list_dataseries(handles,ListExperiments,MirrorPath)
    261 
    262 %------------------------------------------------------------------------
    263 % --- List the DataSeries when a set of experiments is selected
    264 %------------------------------------------------------------------------
    265  function list_dataseries(handles,ListExperiments,MirrorPath)
    266 
    267 DataSeries={};
    268 for iexp=1:numel(ListExperiments)
    269     if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
    270         ListExperiments{iexp}(1)=[];%remove the first char '+' used to mark folders
    271         ListStruct=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
    272         ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
    273         ListFiles=ListCells(1,:);%list of dir and file  names
    274         cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
    275         cell_remove_tild=regexp(ListFiles,'~$');% detect tild the end of file nqme (do not list)
    276         check_keep=cellfun('isempty', cell_remove) & cellfun('isempty', cell_remove_tild);
    277         check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
    278         for ilist=1:numel(ListFiles)
    279             if check_keep(ilist)% loop on eligible DataSeries folders
    280                 mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});%source folder
    281                 if ~exist(mirror,'file') && ~exist(mirror,'dir')% if the name is a broken link
    282                     delete(mirror)% delete broken link
    283                 else %update the list of dataSeries
    284                     [tild,msg]=fileattrib(mirror);
    285 %                     msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name
    286 %                     if ~strcmp(msg.Name,mirror)% if it is a link
    287 %                         ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list
    288 %                     end
    289                     if check_dir(ilist)
    290                         ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
    291                     end
    292                     if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
    293                         DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list
    294                     end                   
    295                 end
     362end
     363ListFilesTot=unique(ListFilesTot);
     364if ischar(ListSub)
     365    indices=find(strcmp(ListSub,ListFilesTot));
     366else
     367    indices=[];
     368    for ilist=1:numel(ListSub)
     369        index=find(strcmp(ListSub{ilist},ListFilesTot));
     370        indices=[indices index];
     371    end
     372end
     373if isempty(indices), indices=1; end
     374
     375
     376%------------------------------------------------------------------------
     377% Provide a list to display
     378%------------------------------------------------------------------------
     379function [ListFilesTot,indices]=list_dir_3(SourceDir,ListDir,ListSub,ListSubSub)
     380ListFilesTot={};
     381for ilist=1:numel(ListDir)
     382    if ~isempty(regexp(ListDir{ilist},'^\+/'))
     383        ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
     384        for isub=1:numel(ListSub)
     385            if ~isempty(regexp(ListSub{isub},'^\+/'))
     386                ListSub{isub}=regexprep(ListSub{isub},'^\+/','');
     387                ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist},ListSub{isub})); %list files and dirs, extende to OpenDAP case
     388                ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     389                ListFiles=ListCells(1,:);
     390                check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     391                ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
     392                cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
     393                check_keep=cellfun('isempty', cell_remove);
     394                ListFilesTot=[ListFilesTot;(ListFiles(check_keep))'];
    296395            end
    297396        end
    298397    end
    299398end
    300 if get(handles.CheckDevices,'Value')
    301     set(handles.ListDevices,'Value',1)
    302 set(handles.ListDevices,'String',sort(DataSeries))
    303 CheckDevices_Callback([],[], handles)
    304 else
    305 set(handles.DataSeries,'Value',1)
    306 set(handles.DataSeries,'String',sort(DataSeries))
    307 end
     399ListFilesTot=unique(ListFilesTot);
     400if ischar(ListSubSub)
     401    indices=find(strcmp(ListSubSub,ListFilesTot));
     402else
     403    indices=[];
     404    for ilist=1:numel(ListSubSub)
     405        index=find(strcmp(ListSubSub{ilist},ListFilesTot));
     406        indices=[indices index];
     407    end
     408end
     409if isempty(indices), indices=1; end
     410
    308411
    309412%------------------------------------------------------------------------
    310413% --- Executes when the mirror is created or updated
    311414%------------------------------------------------------------------------
    312  function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
     415function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
    313416
    314417DataSeries={};
     
    344447                                if strcmp(answer,'Yes')
    345448                                    delete(mirror);
    346                                     system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder                                 
     449                                    system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
    347450                                end
    348451                            end
    349452                        end
    350453                    else% create mirror to the data series if needed
    351                         system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder                     
     454                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
    352455                    end
    353456                    if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
     
    367470% --- Executes on button press in CampaignDoc.
    368471function CampaignDoc_Callback(hObject, eventdata, handles)
    369 %------------------------------------------------------------------------   
     472%------------------------------------------------------------------------
    370473answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file');
    371474if ~isequal(answer{1},'OK')
     
    397500    ExpName=List.Experiment{iexp}.name;
    398501    t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
    399    
     502
    400503    if isfield(List.Experiment{iexp},'Device')
    401504        for idevice=1:length(List.Experiment{iexp}.Device)
    402505            [t,uid_device]=add(t,uid_exp,'element','Device');
    403506            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
    404             t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
     507            t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);
    405508            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    406509                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
     
    413516                        [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
    414517                        t = attributes(t,'add',uid_xml,'source','file');
    415                         [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                   
     518                        [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});
    416519                    end
    417520                end
    418              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
     521            elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    419522                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    420523                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
     
    447550
    448551
    449 %------------------------------------------------------------------------
    450 % --- Executes on button press in OK.
    451 %------------------------------------------------------------------------
    452 function OK_Callback(hObject, eventdata, handles)
    453 
    454 if strcmp(get(handles.MirrorDir,'Visible'),'on')
    455     Campaign=get(handles.MirrorDir,'String');
    456 else
    457     Campaign=get(handles.SourceDir,'String');
    458 end
    459 handles.output=[];
    460 handles.output.Campaign=Campaign;
    461 Experiment=get(handles.ListExperiments,'String');
    462 IndicesExp=get(handles.ListExperiments,'Value');
    463 if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected
    464     Experiment=Experiment(IndicesExp);% use the selection of the list of experiments
    465 end
    466 Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
    467 Device=get(handles.DataSeries,'String');
    468 Value=get(handles.DataSeries,'Value');
    469 Device=Device(Value);
    470 Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir
    471 Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
    472 handles.output.Experiment=Experiment;
    473 handles.output.DataSeries=Device;
    474 guidata(hObject, handles);% Update handles structure
    475 uiresume(handles.browse_data);
    476 drawnow
     552% %------------------------------------------------------------------------
     553% % --- Executes on button press in OK.
     554% %------------------------------------------------------------------------
     555% function OK_Callback(hObject, eventdata, handles)
     556%
     557% if strcmp(get(handles.MirrorDir,'Visible'),'on')
     558%     Campaign=get(handles.MirrorDir,'String');
     559% else
     560%     Campaign=get(handles.SourceDir,'String');
     561% end
     562% handles.output=[];
     563% handles.output.Campaign=Campaign;
     564% Experiment=get(handles.ListExperiments,'String');
     565% IndicesExp=get(handles.ListExperiments,'Value');
     566% if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected
     567%     Experiment=Experiment(IndicesExp);% use the selection of the list of experiments
     568% end
     569% Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
     570% Device=get(handles.DataSeries,'String');
     571% Value=get(handles.DataSeries,'Value');
     572% Device=Device(Value);
     573% Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir
     574% Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
     575% handles.output.Experiment=Experiment;
     576% handles.output.DataSeries=Device;
     577% guidata(hObject, handles);% Update handles structure
     578% uiresume(handles.browse_data);
     579% drawnow
    477580
    478581%------------------------------------------------------------------------
     
    491594%------------------------------------------------------------------------
    492595function closefcn(gcbo, eventdata)
    493 % if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
    494 %     % The GUI is still in UIWAIT, us UIRESUME
    495 %     handles.output = get(hObject,'String');
    496 %     guidata(hObject, handles); % Update handles structure
    497 %     uiresume(handles.browse_data);
    498 % else
    499 %     % The GUI is no longer waiting, just close it
    500 %     delete(handles.browse_data);
    501 % end
     596
    502597hseries=findobj(allchild(0),'Tag','series');
    503598if ~isempty(hseries)
     
    511606end
    512607
    513 %------------------------------------------------------------------------
    514 % --- Executes on key press over figure1 with no controls selected.
    515 %------------------------------------------------------------------------
    516 function browse_data_KeyPressFcn(hObject, eventdata, handles)
     608% %------------------------------------------------------------------------
     609% % --- Executes on key press over figure1 with no controls selected.
     610% %------------------------------------------------------------------------
     611% function browse_data_KeyPressFcn(hObject, eventdata, handles)
    517612   
    518 % Check for "enter" or "escape"
    519 if isequal(get(hObject,'CurrentKey'),'escape')
    520     % User said no by hitting escape
    521     handles.output = 'Cancel';
    522    
    523     % Update handles structure
    524     guidata(hObject, handles);
    525    
    526     uiresume(handles.browse_data);
    527 end
    528 if isequal(get(hObject,'CurrentKey'),'return')
    529     uiresume(handles.browse_data);
    530 end
     613% % Check for "enter" or "escape"
     614% if isequal(get(hObject,'CurrentKey'),'escape')
     615%     % User said no by hitting escape
     616%     handles.output = 'Cancel';
     617%    
     618%     % Update handles structure
     619%     guidata(hObject, handles);
     620%    
     621%     uiresume(handles.browse_data);
     622% end
     623% if isequal(get(hObject,'CurrentKey'),'return')
     624%     uiresume(handles.browse_data);
     625% end
    531626
    532627
    533628% --- Executes on button press in Up.
    534 function Up_Callback(hObject, eventdata, handles)
    535 SourceDir=get(handles.SourceDir,'String');
    536 browse_data(SourceDir)
    537 
    538 
    539 % --- Executes on button press in Down.
    540629function Down_Callback(hObject, eventdata, handles)
    541630SourceDir=get(handles.SourceDir,'String');
    542631ListExperiments=get(handles.ListExperiments,'String');
    543632list_val=get(handles.ListExperiments,'Value');
    544 SourceFolder=regexprep(ListExperiments{list_val(1)},'+','');
    545 set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder))
     633if ischar(ListExperiments)
     634    Exp=ListExperiments;
     635else
     636    Exp=ListExperiments{list_val(1)};
     637end
     638Exp=regexprep(Exp,'^\+/','');
     639SourceDirNew=fullfile(SourceDir,Exp);
     640set(handles.SourceDir,'String',SourceDirNew);% New SourceDir
     641ListDevices=get(handles.ListDevices,'String');
     642DeviceIndices=get(handles.ListDevices,'Value');
     643set(handles.ListExperiments,'String',ListDevices);%replace Experiments by Devices
     644set(handles.ListExperiments,'Value',DeviceIndices);%replace Experiments by Devices
    546645DataSeries=get(handles.DataSeries,'String');
    547 ValueDevice=get(handles.DataSeries,'Value');
    548 set(handles.ListExperiments,'String',DataSeries)
    549 set(handles.ListExperiments,'Value',ValueDevice)
    550 ListExperiments_Callback(hObject, [], handles)
    551 
    552 
    553 % --- Executes on selection change in DataSeries.
    554 function DataSeries_Callback(hObject, eventdata, handles)
    555 
    556 
    557 % --- Executes on button press in CheckDevices.
    558 function CheckDevices_Callback(hObject, eventdata, handles)
    559 if get(handles.CheckDevices,'Value')
    560     set(handles.ListDevices,'Visible','on')
    561     ListDevices=get(handles.DataSeries,'String');
    562     Index=get(handles.DataSeries,'Value');
    563     set(handles.ListDevices,'String',ListDevices)
    564     set(handles.ListDevices,'Value',Index)
    565     set(handles.DataSeries,'Value',1)
    566     if strcmp(get(handles.MirrorDir,'Visible'),'on')
    567     MirrorPath=get(handles.MirrorDir,'String');
    568     else
    569     MirrorPath=get(handles.SourceDir,'String');
    570     end
    571     IndexExperiment=get(handles.ListExperiments,'Value');
    572     ListExperiment=get(handles.ListExperiments,'String');
    573     Experiment=ListExperiment{get(handles.ListExperiments,'Value')};
    574     Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
    575     Experiment=regexprep(Experiment,'^~','');% remove the ~ used to mark symbolic link
    576     Device=regexprep(ListDevices{Index},'^\+/','');% remove the +/ used to mark dir
    577     Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
    578     DataSeries=dir(fullfile(MirrorPath,Experiment,Device));
    579     DataSeriesCell=struct2cell(DataSeries);
    580     set(handles.DataSeries,'String',DataSeriesCell(1,:)')
    581 else
    582     ListDevices=get(handles.ListDevices,'String');
    583     Index=get(handles.ListDevices,'Value');
    584     set(handles.ListDevices,'Visible','off')
    585     set(handles.DataSeries,'String',ListDevices)
    586     set(handles.DataSeries,'Value',Index)
    587 end
     646list_val=get(handles.DataSeries,'Value');
     647set(handles.ListDevices,'String',DataSeries);%replace Devices by DataSeries
     648set(handles.ListDevices,'Value',list_val);%replace Devices by DataSeries
     649
     650[ListFiles,indices]=list_dir_3(SourceDirNew,ListDevices(DeviceIndices),DataSeries(list_val),[]);
     651set(handles.DataSeries,'String',ListFiles)
     652set(handles.DataSeries,'Value',indices)% initialise the menu selection with the folder defined by the input
     653
     654
     655% --- Executes on button press in Down.
     656function Up_Callback(hObject, eventdata, handles)
     657SourceDir=get(handles.SourceDir,'String');
     658[SourceDir,Exp]=fileparts(SourceDir);
     659set(handles.SourceDir,'String',SourceDir)
     660
     661% set(handles.ListExperiments,'Value',indices)
     662%[ListFiles,indices]=list_dir_1(SourceDir,Exp);
     663% set(handles.ListExperiments,'String',ListFiles)
     664% set(handles.ListExperiments,'Value',indices)
     665ListDevices=get(handles.ListDevices,'String');
     666DeviceIndices=get(handles.ListDevices,'Value');
     667set(handles.DataSeries,'String',ListDevices);
     668set(handles.DataSeries,'Value',DeviceIndices);
     669
     670ListExperiments=get(handles.ListExperiments,'String');
     671ExpIndices=get(handles.ListExperiments,'Value');
     672set(handles.ListDevices,'String',ListExperiments);
     673set(handles.ListDevices,'Value',ExpIndices);
     674
     675set(handles.ListExperiments,'String',{['+/' Exp]})
     676set(handles.ListExperiments,'Value',1)
     677
     678% ListExperiments=get(handles.ListExperiments,'String');
     679% list_val=get(handles.ListExperiments,'Value');
     680% SourceFolder=regexprep(ListExperiments{list_val(1)},'+','');
     681% set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder))
     682% DataSeries=get(handles.DataSeries,'String');
     683% ValueDevice=get(handles.DataSeries,'Value');
     684% set(handles.ListExperiments,'String',DataSeries)
     685% set(handles.ListExperiments,'Value',ValueDevice)
     686% ListExperiments_Callback(hObject, [], handles)
     687
     688
     689% % --- Executes on selection change in DataSeries.
     690% function DataSeries_Callback(hObject, eventdata, handles)
     691% SourceDir=get(handles.SourceDir,'String');
     692% ListData=get(handles.DataSeries,'String');
     693% Folder=ListData{get(handles.DataSeries,'Value')};
     694% if ~isempty(regexp(Folder,'^\+/'))% if a folder is selected
     695%     Folder=regexprep(Folder,'\+/','');
     696%     ListExperiments=get(handles.ListExperiments,'String');
     697%     list_val=get(handles.ListExperiments,'Value');
     698%     for iexp=1:numel(list_val)
     699%         ExpName=regexprep(ListExperiments{list_val(iexp)},'\+/','');
     700%         FullName=fullfile(SourceDir,ExpName,Folder);
     701%         dd=dir(FullName);
     702%         check_sub=1;
     703%         for idir=1:numel(dd)
     704%             ListData{ilist}=dd(ilist).name;
     705%             if dd(ilist).isdir && ~strcmp(dd(ilist).name,'.')&& ~strcmp(dd(ilist).name,'..')&& isempty(regexp(dd(ilist).name,'^_LOG'))...
     706%                     && isempty(regexp(dd(ilist).name,'^_LOG'))&& isempty(regexp(dd(ilist).name,'^_XML'))
     707%                check_sub=1;
     708%                ListData{ilist}=['+/' dd(ilist).name];
     709%             end
     710%         end
     711%         if check_sub
     712%         set(handles.ListDevices,'String',ListData);
     713%                 set(handles.ListDevices,'Visible','on');
     714%                 set(handles.DataSeries,'String',ListData)
     715%                 break
     716%         end
     717%     end
     718% end
     719
     720% % --- Executes on button press in CheckDevices.
     721% function CheckDevices_Callback(hObject, eventdata, handles)
     722% if get(handles.CheckDevices,'Value')
     723%     set(handles.ListDevices,'Visible','on')
     724%     ListDevices=get(handles.DataSeries,'String');
     725%     Index=get(handles.DataSeries,'Value');
     726%     set(handles.ListDevices,'String',ListDevices)
     727%     set(handles.ListDevices,'Value',Index)
     728%     set(handles.DataSeries,'Value',1)
     729%     if strcmp(get(handles.MirrorDir,'Visible'),'on')
     730%     MirrorPath=get(handles.MirrorDir,'String');
     731%     else
     732%     MirrorPath=get(handles.SourceDir,'String');
     733%     end
     734%     IndexExperiment=get(handles.ListExperiments,'Value');
     735%     ListExperiment=get(handles.ListExperiments,'String');
     736%     Experiment=ListExperiment{get(handles.ListExperiments,'Value')};
     737%     Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
     738%     Experiment=regexprep(Experiment,'^~','');% remove the ~ used to mark symbolic link
     739%     Device=regexprep(ListDevices{Index},'^\+/','');% remove the +/ used to mark dir
     740%     Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
     741%     DataSeries=dir(fullfile(MirrorPath,Experiment,Device));
     742%     DataSeriesCell=struct2cell(DataSeries);
     743%     set(handles.DataSeries,'String',DataSeriesCell(1,:)')
     744% else
     745%     ListDevices=get(handles.ListDevices,'String');
     746%     Index=get(handles.ListDevices,'Value');
     747%     set(handles.ListDevices,'Visible','off')
     748%     set(handles.DataSeries,'String',ListDevices)
     749%     set(handles.DataSeries,'Value',Index)
     750% end
Note: See TracChangeset for help on using the changeset viewer.