-
Notifications
You must be signed in to change notification settings - Fork 13
/
SavePDF.m
134 lines (110 loc) · 4.97 KB
/
SavePDF.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
function run_count = SavePDF(h, MRS_struct, ii, jj, kk, vox, module, run_count)
% Gannet logo
axes('Position', [0.8825, 0.04, 0.125, 0.125], 'Units', 'normalized');
Gannet_logo = fullfile(fileparts(which('GannetLoad')), 'Gannet3_logo.png');
I = imread(Gannet_logo, 'BackgroundColor', 'none');
imshow(I);
axis off image;
% Gannet version
d.left = 0;
d.bottom = 0.02;
d.width = 1;
d.height = 0.02;
axes('Position', [d.left d.bottom d.width d.height], 'Units', 'normalized');
text(0.9925, 0, MRS_struct.version.Gannet, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 14, 'FontWeight', 'bold', 'HorizontalAlignment', 'right');
axis off;
% Gannet documentation
axes('Position', [d.left d.bottom d.width d.height], 'Units', 'normalized');
str = 'For complete documentation, please visit: https://markmikkelsen.github.io/Gannet-docs';
text(0.5, 0, str, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 11, 'HorizontalAlignment', 'center');
axis off square;
% Batch number and output time
d.bottom = 0.98;
axes('Position', [d.left d.bottom d.width d.height], 'Units', 'normalized');
text(0.0075, 0, ['Batch file: ' num2str(ii) ' of ' num2str(MRS_struct.p.numScans)], 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 11, 'HorizontalAlignment', 'left');
text(0.9925, 0, char(datetime('now','Format','dd-MMM-y HH:mm:ss')), 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 11, 'HorizontalAlignment', 'right');
axis off;
if any(strcmp(listfonts, 'Arial'))
set(findall(h, '-property', 'FontName'), 'FontName', 'Arial');
end
set(findall(h, '-property', 'XColor'), 'XColor', [0 0 0]);
set(findall(h, '-property', 'YColor'), 'YColor', [0 0 0]);
% If export_fig is installed, export PDF using it
if MRS_struct.p.append && ~isempty(fileparts(which('export_fig')))
scr_sz = get(0,'ScreenSize');
if ispc
px_sz = 96;
elseif ismac || isunix
px_sz = 72;
end
fig_w = 11*px_sz;
fig_h = 8.5*px_sz;
set(gcf, 'Units', 'Pixels', 'Position', [(scr_sz(3)-fig_w)/2, (scr_sz(4)-fig_h)/2, fig_w, fig_h]);
% Create output dir
if ~exist(fullfile(pwd, 'Gannet_output'), 'dir')
mkdir(fullfile(pwd, 'Gannet_output'));
end
pdf_name = fullfile(pwd, 'Gannet_output', [module '.pdf']);
if exist(pdf_name, 'file') && (ii + jj) == 2
run_count = 1;
pdf_name = fullfile(pwd, 'Gannet_output', [module num2str(run_count) '.pdf']);
while 1
if exist(pdf_name, 'file')
run_count = run_count + 1;
pdf_name = fullfile(pwd, 'Gannet_output', [module num2str(run_count) '.pdf']);
else
break
end
end
elseif (ii + jj) > 2 && run_count > 0
pdf_name = fullfile(pwd, 'Gannet_output', [module num2str(run_count) '.pdf']);
end
export_fig(pdf_name, '-pdf', '-painters', '-append', '-nocrop', '-nofontswap', '-silent', h);
else
if MRS_struct.p.append && isempty(fileparts(which('export_fig'))) && ii == 1
warning(['Could not find the function ''export_fig.m''. ', ...
'Cannot append PDFs. ', ...
'Please ensure that you have added the export_fig/ ', ...
'folder in the main Gannet folder to your MATLAB ', ...
'search path. PDFs will be saved separately.']);
end
set(h, 'PaperUnits', 'inches', 'PaperSize', [11 8.5], 'PaperPosition', [0 0 11 8.5]);
% Create output folder
if ~exist(fullfile(pwd, [module '_output']),'dir')
mkdir(fullfile(pwd, [module '_output']));
end
% For Philips .data
if strcmp(MRS_struct.p.vendor, 'Philips_data')
fullpath = MRS_struct.metabfile{1,ii};
fullpath = regexprep(fullpath, '.data', '_data');
fullpath = regexprep(fullpath, '\', '_');
fullpath = regexprep(fullpath, '/', '_');
end
if strcmp(MRS_struct.p.vendor, 'Siemens_rda')
[~, metabfile_nopath] = fileparts(MRS_struct.metabfile{1,ii*2-1});
else
[~, metabfile_nopath, ext] = fileparts(MRS_struct.metabfile{1,ii});
if strcmpi(ext, '.gz')
metabfile_nopath(end-3:end) = [];
end
end
module2 = lower(module);
module2(1:6) = [];
if strcmp(module2, 'fit') && MRS_struct.p.HERMES
module2 = [MRS_struct.p.target{jj} '_' module2];
end
if strcmp(MRS_struct.p.vendor, 'Philips_data')
if isfield(MRS_struct.p, 'trimmed_avgs')
pdf_name = fullfile(pwd, [module '_output'], [fullpath '_' vox{kk} '_' module2 '_' num2str(MRS_struct.p.Navg(ii)) '_avgs.pdf']);
else
pdf_name = fullfile(pwd, [module '_output'], [fullpath '_' vox{kk} '_' module2 '.pdf']);
end
else
if isfield(MRS_struct.p, 'trimmed_avgs')
pdf_name = fullfile(pwd, [module '_output'], [metabfile_nopath '_' vox{kk} '_' module2 '_' num2str(MRS_struct.p.Navg(ii)) '_avgs.pdf']);
else
pdf_name = fullfile(pwd, [module '_output'], [metabfile_nopath '_' vox{kk} '_' module2 '.pdf']);
end
end
saveas(h, pdf_name);
end