-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsafe_create_hw_library.m
63 lines (47 loc) · 1.75 KB
/
safe_create_hw_library.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
function fn_l = safe_create_hw_library(fn_l, fn_lib)
% function fn_l = safe_create_hw_library(fn_l, fn_lib)
%
% fn_l is cell array with absolute paths to .asc files that contain
% information on SAFE model.
if nargin < 1
% This funciton searches for all .asc files in a folder, to include all
% unique files in a list. Note that the hardware specification files
% are not shared via GitHub. Note that the function
% 'find_files_under_folder' is not shared as part of this repo.
% However, you can find it here:
% https://se.mathworks.com/matlabcentral/fileexchange/1378-files-under-folders-fuf
dir_safe_hw = path_hw_safe;
fn_l = find_files_under_folder([dir_safe_hw filesep '*.asc'], 1, 'detail');
end
if nargin < 2
fn_lib = safe_hw_lib_fn();
end
sha_l = {};
name_l = {};
var_l = [];
mod_l = {};
for i = 1:numel(fn_l)
% Decide on the interpreter version/mode and create a structure that
% has all necessary hardware PNS parameters.
mode = safe_asc_fn_to_mode(fn_l{i});
for j = 1:numel(mode)
hw = safe_hw_from_asc(fn_l{i}, 0, mode(j));
% If the file is incomplete, do not add it to the library
if ~safe_hw_check(hw, 1)
warning(['Skipping ' fn_l{i}])
continue
end
sha = safe_hw_to_sha(hw);
% Check if identical SHA exists
if ~any(strcmp(sha_l,sha))
if any(strcmp(name_l,hw.name))
warning(['Doublet name with different specification exists! (' hw.name ')'])
end
sha_l {end+1} = sha;
name_l{end+1} = hw.name;
var_l (end+1) = sum(strcmp(name_l,hw.name));
mod_l {end+1} = hw.model;
end
end
end
save(fn_lib, 'sha_l', 'name_l', 'var_l', 'mod_l');