Newer
Older
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
%%
% auxiliary script to write .mat containing empty IDS to separate .m files
% in ids_empty_folder
clear;
cd(fileparts(mfilename('fullpath')));
ids_struct_saved = '/home/sauter/matlab/gdat_develop/matlab/TCV_IMAS/ids_structures_20190312.mat';
target_folder = 'ids_empty';
ffolder = fullfile(fileparts(mfilename('fullpath')),target_folder);
assert(~~exist(ffolder,'dir'),'target folder does not exist')
load(ids_struct_saved);
fields = fieldnames(ids_structures);
%% write file with
okflag = writecell(fields,fullfile(ffolder,'ids_list'));
assert(okflag,'problem writing cell array');
assert(isequaln(fields,eval('ids_list'))); % check
%% write individual files per ids template
for ii=1:numel(fields)
myfield = fields{ii};
fieldval = ids_structures.(myfield);
%% write to .m
fname = sprintf('ids_empty_%s',myfield);
fpath = fullfile(ffolder,fname);
fprintf('writing %s\n',fpath);
okflag =writestruct(fieldval,fpath);
assert(okflag,'failed writing %s',fpath);
try
cd ids_empty
S_out = eval(fname);
assert(isequaln(fieldval,S_out),'fields not equal %s',myfield);
cd ..
catch ME
cd ..
rethrow(ME)
end
end