-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistFromXML.m
More file actions
81 lines (74 loc) · 2.47 KB
/
Copy pathlistFromXML.m
File metadata and controls
81 lines (74 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function [DataFiles,metaData] = listFromXML(XMLdir,update)
% Usage: [DataFiles,metaData] = listFromXML(XMLdir,update);
%
% Generates a list of data files names (runs), and the
% corresponding metadata from list of xml files in XMLdir
% If the second argument is present, also updates the metaData.
if nargin > 1
update = 1;
else
update = 0;
end
F = findfiles('xml',XMLdir);
nFiles = length(F);
% For all of them, read the metaData
metaData = {};
xml_file = {};
updated = [];
for k = 1:nFiles
[pathstr,id] = fileparts(char(F(k)));
disp(['Reading XML file ' id '.xml']);
xml_file{k} = F(k);
Pref.Str2Num = 'never';
Pref.ReadAttr = 0;
metaData{k} = xml_read(char(xml_file{k}),Pref);
if update
metaData{k} = cleanMetaData(metaData{k});
metaData{k} = updateMetaData(metaData{k});
end
end
DataFiles = cell(nFiles,1);
Months = {'Jan','Feb','Mar','Apr','May','Jun','Jul',...
'Aug','Sep','Oct','Nov','Dec'};
for k = 1:nFiles
temp = metaData{k}.startDate;
Ind = find(temp == '-');
Ind = [0 Ind length(temp)];
year = temp(Ind(1)+1:Ind(2)-1);
mo = Months{str2num(temp(Ind(2)+1:Ind(3)-1))};
day = temp(Ind(3)+1:Ind(4));
startDate = [day '-' mo '-' year];
start = [ startDate ' ' metaData{k}.startTime ]
temp = metaData{k}.endDate;
Ind = find(temp == '-');
Ind = [0 Ind length(temp)];metaData{k}.runID
year = temp(Ind(1)+1:Ind(2)-1)
if strcmp(year,'yyyy')
disp(['Please correct start time for ' metaData{k}.runID]);
end
mo = Months{str2num(temp(Ind(2)+1:Ind(3)-1))};
day = temp(Ind(3)+1:Ind(4));
endDate = [day '-' mo '-' year];
lastdata = [ endDate ' ' metaData{k}.endTime ]
% construct scale factors for plotting ... if information
% is available in metaData!
if isfield(metaData{k},'ConversionFactors')
scaleFactors = str2num(metaData{k}.ConversionFactors);
if isfield(metaData{k},'Gain')
scaleFactors = scaleFactors./str2num(metaData{k}.Gain);
end
if isfield(metaData{k},'DipoleLength')
scaleFactors = scaleFactors./str2num(metaData{k}.DipoleLength);
end
else
scaleFactors = [];
end
DataFiles{k} = struct('Name',metaData{k}.runID, ...
'fileName',char(xml_file{k}), ...
'lat',metaData{k}.lat, ...
'lon',metaData{k}.lon, ...
'elev',metaData{k}.elev, ...
'scaleFactors',scaleFactors,...
'start',start,'end',lastdata,...
'metaData',metaData{k});
end