1 | %'dir_scan': scan the structure of the directory tree (for browse_data.m) |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function [ListDevices,ListRecords,ListXml,List]=dir_scan(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in) |
---|
4 | % |
---|
5 | % |
---|
6 | % OUTPUT: |
---|
7 | % ListDevices: list of Devices |
---|
8 | % ListRecords: list of records |
---|
9 | % ListXml: list of xml file names |
---|
10 | % List: structure representing the tree structure |
---|
11 | % |
---|
12 | % INPUT: |
---|
13 | % CurrentPath: full name (including path) to the input campaign (or subcampaign), we assume that |
---|
14 | % data are organised as (sub)campaign/Experiment/Device/(Record/)/file .xml |
---|
15 | % ListExperiments: list of experiments to scan (cell of names) |
---|
16 | % ListDevices_in: list of devices to scan (cell of names) |
---|
17 | % ListRecords_in: list of records to scan (cell of names) |
---|
18 | |
---|
19 | %======================================================================= |
---|
20 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
21 | % http://www.legi.grenoble-inp.fr |
---|
22 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
23 | % |
---|
24 | % This file is part of the toolbox UVMAT. |
---|
25 | % |
---|
26 | % UVMAT is free software; you can redistribute it and/or modify |
---|
27 | % it under the terms of the GNU General Public License as published |
---|
28 | % by the Free Software Foundation; either version 2 of the license, |
---|
29 | % or (at your option) any later version. |
---|
30 | % |
---|
31 | % UVMAT is distributed in the hope that it will be useful, |
---|
32 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
33 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
34 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
35 | %======================================================================= |
---|
36 | |
---|
37 | function [ListDevices,ListRecords,ListXml,List]=dir_scan(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in) |
---|
38 | |
---|
39 | ListRecords={}; |
---|
40 | ListDevices={}; |
---|
41 | ListXml={}; |
---|
42 | irecord_tot=0; |
---|
43 | idevice_tot=0; |
---|
44 | ixml_tot=0; |
---|
45 | for iexp=1:length(ListExperiments) |
---|
46 | List.Experiment{iexp}.name=ListExperiments{iexp}; |
---|
47 | hdir=dir(fullfile(CurrentPath,ListExperiments{iexp})); |
---|
48 | idevice=0; |
---|
49 | for isub=1:length(hdir)% scan the sub-directories of the current experiment |
---|
50 | if hdir(isub).isdir |
---|
51 | name=hdir(isub).name;%name of the current device |
---|
52 | if ~isequal(name(1),'.')% subdirectory of the current experiment |
---|
53 | [testnew,testselect]=test_select(name,ListDevices,ListDevices_in); |
---|
54 | if testselect |
---|
55 | idevice=idevice+1; |
---|
56 | List.Experiment{iexp}.Device{idevice}.name=name; |
---|
57 | if testnew |
---|
58 | idevice_tot=idevice_tot+1; |
---|
59 | ListDevices{idevice_tot}=name; |
---|
60 | end |
---|
61 | CurrentDevice=fullfile(CurrentPath,ListExperiments{iexp},name); |
---|
62 | hsubxml=dir(fullfile(CurrentDevice,'*.xml'));%look at xml files in the subdirectory of the current device |
---|
63 | if isempty(hsubxml) % the subdirectory of the current device contains directories 'Record'' |
---|
64 | hsubdir=dir(fullfile(CurrentPath,ListExperiments{iexp},name));%list what is inside the directory 'Device' |
---|
65 | irecord=0; |
---|
66 | for isubsub=1:length(hsubdir)% subdirectories of the current device |
---|
67 | if hsubdir(isubsub).isdir |
---|
68 | RecordName=hsubdir(isubsub).name; |
---|
69 | if ~isequal(RecordName(1),'.') |
---|
70 | [testnew,testselect]=test_select(RecordName,ListRecords,ListRecords_in); |
---|
71 | if testselect |
---|
72 | if testnew |
---|
73 | irecord_tot=irecord_tot+1; |
---|
74 | ListRecords{irecord_tot}=RecordName; |
---|
75 | end |
---|
76 | irecord=irecord+1; |
---|
77 | List.Experiment{iexp}.Device{idevice}.Record{irecord}.name=RecordName; |
---|
78 | hsubsubxml=dir(fullfile(CurrentDevice,RecordName,'*.xml'));% |
---|
79 | for ixml=1:length(hsubsubxml) |
---|
80 | XmlName=hsubsubxml(ixml).name; |
---|
81 | List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}=XmlName; |
---|
82 | testnew=test_select(XmlName,ListXml,{}); |
---|
83 | if testnew |
---|
84 | ixml_tot=ixml_tot+1; |
---|
85 | ListXml{ixml_tot}=XmlName; |
---|
86 | end |
---|
87 | end |
---|
88 | end |
---|
89 | end |
---|
90 | end |
---|
91 | end |
---|
92 | else |
---|
93 | for ixml=1:length(hsubxml) |
---|
94 | XmlName=hsubxml(ixml).name; |
---|
95 | List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}=XmlName; |
---|
96 | testnew=test_select(XmlName,ListXml,{}); |
---|
97 | if testnew |
---|
98 | ixml_tot=ixml_tot+1; |
---|
99 | ListXml{ixml_tot}=XmlName; |
---|
100 | end |
---|
101 | end |
---|
102 | end |
---|
103 | end |
---|
104 | end |
---|
105 | end |
---|
106 | end |
---|
107 | end |
---|
108 | |
---|
109 | |
---|
110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
111 | % ListDevices: list of devices already scanned |
---|
112 | % ListDevices_in: list of input devices to scan |
---|
113 | function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in) |
---|
114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
115 | if ~isempty(ListDevices_in) |
---|
116 | testnew=0; |
---|
117 | testselect=0; |
---|
118 | for ilist=1:length(ListDevices_in) |
---|
119 | if isequal(name,ListDevices_in{ilist}) |
---|
120 | testnew=1; |
---|
121 | testselect=1; |
---|
122 | break |
---|
123 | end |
---|
124 | end |
---|
125 | else |
---|
126 | testnew=1; |
---|
127 | testselect=1; |
---|
128 | end |
---|
129 | if testnew |
---|
130 | for ilist=1:length(ListDevices) |
---|
131 | if isequal(name,ListDevices{ilist}) |
---|
132 | testnew=0; |
---|
133 | break |
---|
134 | end |
---|
135 | end |
---|
136 | end |
---|