[21] | 1 | %'ListDir': scan the structure of the directory tree (for dataview.m) |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function [ListDevices,ListRecords,ListXml,List]=ListDir(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 | function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in) |
---|
| 20 | |
---|
| 21 | ListRecords={}; |
---|
| 22 | ListDevices={}; |
---|
| 23 | ListXml={}; |
---|
| 24 | irecord_tot=0; |
---|
| 25 | idevice_tot=0; |
---|
| 26 | ixml_tot=0; |
---|
| 27 | for iexp=1:length(ListExperiments) |
---|
| 28 | List.Experiment{iexp}.name=ListExperiments{iexp}; |
---|
| 29 | hdir=dir(fullfile(CurrentPath,ListExperiments{iexp})); |
---|
| 30 | idevice=0; |
---|
| 31 | for isub=1:length(hdir)% scan the sub-directories of the current experiment |
---|
| 32 | if hdir(isub).isdir |
---|
| 33 | name=hdir(isub).name;%name of the current device |
---|
| 34 | if ~isequal(name(1),'.')% subdirectory of the current experiment |
---|
| 35 | [testnew,testselect]=test_select(name,ListDevices,ListDevices_in); |
---|
| 36 | if testselect |
---|
| 37 | idevice=idevice+1; |
---|
| 38 | List.Experiment{iexp}.Device{idevice}.name=name; |
---|
| 39 | if testnew |
---|
| 40 | idevice_tot=idevice_tot+1; |
---|
| 41 | ListDevices{idevice_tot}=name; |
---|
| 42 | end |
---|
| 43 | CurrentDevice=fullfile(CurrentPath,ListExperiments{iexp},name); |
---|
| 44 | hsubxml=dir(fullfile(CurrentDevice,'*.xml'));%look at xml files in the subdirectory of the current device |
---|
| 45 | if isempty(hsubxml) % the subdirectory of the current device contains directories 'Record'' |
---|
| 46 | hsubdir=dir(fullfile(CurrentPath,ListExperiments{iexp},name));%list what is inside the directory 'Device' |
---|
| 47 | irecord=0; |
---|
| 48 | for isubsub=1:length(hsubdir)% subdirectories of the current device |
---|
| 49 | if hsubdir(isubsub).isdir |
---|
| 50 | RecordName=hsubdir(isubsub).name; |
---|
| 51 | if ~isequal(RecordName(1),'.') |
---|
| 52 | [testnew,testselect]=test_select(RecordName,ListRecords,ListRecords_in); |
---|
| 53 | if testselect |
---|
| 54 | if testnew |
---|
| 55 | irecord_tot=irecord_tot+1; |
---|
| 56 | ListRecords{irecord_tot}=RecordName; |
---|
| 57 | end |
---|
| 58 | irecord=irecord+1; |
---|
| 59 | List.Experiment{iexp}.Device{idevice}.Record{irecord}.name=RecordName; |
---|
| 60 | hsubsubxml=dir(fullfile(CurrentDevice,RecordName,'*.xml'));% |
---|
| 61 | for ixml=1:length(hsubsubxml) |
---|
| 62 | XmlName=hsubsubxml(ixml).name; |
---|
| 63 | List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}=XmlName; |
---|
| 64 | testnew=test_select(XmlName,ListXml,{}); |
---|
| 65 | if testnew |
---|
| 66 | ixml_tot=ixml_tot+1; |
---|
| 67 | ListXml{ixml_tot}=XmlName; |
---|
| 68 | end |
---|
| 69 | end |
---|
| 70 | end |
---|
| 71 | end |
---|
| 72 | end |
---|
| 73 | end |
---|
| 74 | else |
---|
| 75 | for ixml=1:length(hsubxml) |
---|
| 76 | XmlName=hsubxml(ixml).name; |
---|
| 77 | List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}=XmlName; |
---|
| 78 | testnew=test_select(XmlName,ListXml,{}); |
---|
| 79 | if testnew |
---|
| 80 | ixml_tot=ixml_tot+1; |
---|
| 81 | ListXml{ixml_tot}=XmlName; |
---|
| 82 | end |
---|
| 83 | end |
---|
| 84 | end |
---|
| 85 | end |
---|
| 86 | end |
---|
| 87 | end |
---|
| 88 | end |
---|
| 89 | end |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 93 | % ListDevices: list of devices already scanned |
---|
| 94 | % ListDevices_in: list of input devices to scan |
---|
| 95 | function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in) |
---|
| 96 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 97 | if ~isempty(ListDevices_in) |
---|
| 98 | testnew=0; |
---|
| 99 | testselect=0; |
---|
| 100 | for ilist=1:length(ListDevices_in) |
---|
| 101 | if isequal(name,ListDevices_in{ilist}) |
---|
| 102 | testnew=1; |
---|
| 103 | testselect=1; |
---|
| 104 | break |
---|
| 105 | end |
---|
| 106 | end |
---|
| 107 | else |
---|
| 108 | testnew=1; |
---|
| 109 | testselect=1; |
---|
| 110 | end |
---|
| 111 | if testnew |
---|
| 112 | for ilist=1:length(ListDevices) |
---|
| 113 | if isequal(name,ListDevices{ilist}) |
---|
| 114 | testnew=0; |
---|
| 115 | break |
---|
| 116 | end |
---|
| 117 | end |
---|
| 118 | end |
---|