-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurAscHeaderDataTable.m
76 lines (64 loc) · 2.82 KB
/
curAscHeaderDataTable.m
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
%% curAscHeaderDataTable.m
% This function retrieves the file header and the data table from WERA
% cur_asc total files.
% INPUT:
% ascFile: cell array of strings containing the WERA cur_asc total file.
% OUTPUT:
% cAHDT_err: error flag (0 = correct, 1 = error)
% header: cell array of strings containing the file header
% columnNames: cell array of strings containing the data table cloumn names
% dataTable: matrix containing the data table
% Author: Lorenzo Corgnati
% Date: October 5, 2018
% E-mail: [email protected]
%%
function [cAHDT_err, header, columnNames, dataTable] = curAscHeaderDataTable(ascFile)
disp(['[' datestr(now) '] - - ' 'curAscHeaderDataTable.m started.']);
cAHDT_err = 0;
warning('off', 'all');
try
% Read the file and look for the data table column names
% (they are the beginning of the data tabel, thus separating header and data table)
for line_idx=1:length(ascFile)
splitLine = regexp(ascFile{line_idx}, '[ \t]+', 'split');
if(length(splitLine)>1)
if((any(strcmp(splitLine,'IX'))) && (any(strcmp(splitLine,'IY'))) && (any(strcmp(splitLine,'U[m/s]'))) && (any(strcmp(splitLine,'V[m/s]'))) && (any(strcmp(splitLine,'Acc_U[m/s]'))) && (any(strcmp(splitLine,'Acc_V[m/s]'))))
endHeader = line_idx - 1;
% Delete empty lines before data
data_idx = line_idx + 1;
expressionNum = '([0-9]+)';
[startIndexNum,endIndexNum] = regexp(ascFile{data_idx},expressionNum);
while(isempty(startIndexNum))
data_idx = data_idx + 1;
[startIndexNum,endIndexNum] = regexp(ascFile{data_idx},expressionNum);
end
startDataTable = data_idx;
break;
end
end
end
% Retrieve header
header = ascFile(1:endHeader);
% Retrieve data table column names
splitColumnNames = regexp(ascFile(line_idx), '[ \t]+', 'split');
columnNames = splitColumnNames{1,1};
% Retrieve data table
dataTableCellArrayStr = ascFile(startDataTable:length(ascFile));
dataTable = NaN.*ones(length(dataTableCellArrayStr),length(columnNames));
for dT_idx=1:length(dataTableCellArrayStr)
[startIndexNum,endIndexNum] = regexp(dataTableCellArrayStr{dT_idx},expressionNum);
if(~isempty(startIndexNum))
splitRow = regexp(dataTableCellArrayStr{dT_idx}, '[ \t]+', 'split');
for sR_idx=1:length(splitRow)
dataTable(dT_idx,sR_idx) = str2double(splitRow{sR_idx});
end
end
end
catch err
disp(['[' datestr(now) '] - - ERROR in ' mfilename ' -> ' err.message]);
cAHDT_err = 1;
end
if(cAHDT_err==0)
disp(['[' datestr(now) '] - - ' 'curAscHeaderDataTable.m successfully executed.']);
end
return