-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup_hyscorean.m
261 lines (230 loc) · 10.5 KB
/
setup_hyscorean.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
%==========================================================================
% Hyscorean Installer
%==========================================================================
% This script installs Hyscorean for MATLAB. The installer takes care of
% setting up all necessary files, variables and preferences required for
% the program. It also checks for required MATLAB toolboxes and external
% programs that may be required.
% The user has to accept the terms and conditions of the GNU General Public
% License 3.0 in order for the program to be installed.
%
% The program can be executed normally as a MATLAB script by either
% pressing the Run button or the F5 key.
%==========================================================================
%
% Copyright (C) 2019 Luis Fabregas, Hyscorean 2019
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License 3.0 as published by
% the Free Software Foundation.
%==========================================================================
function setup_hyscorean
%Clear workspace
clc, clearvars
%Just check that (re)-installation is done in the right folder
try
InstallationPath = fileparts(which('setup_hyscorean'));
CurrentPath = pwd;
if ~strcmp(CurrentPath,InstallationPath)
cd(InstallationPath)
end
catch
end
%Initiallize variable
fullyInstalled = true;
%Get OS system information
MATLAB_version = version;
OS = computer;
allFilesOK = true;
JavaVersion = version('-java');
fprintf('===========================================================================\n')
fprintf('Hyscorean: HYSCORE processing and analysis software (c)2018 ETH Zurich \n')
fprintf('Version 1.0 \n')
fprintf('===========================================================================\n')
fprintf('Installation info \n')
fprintf(' Path: %s \n',InstallationPath)
fprintf(' MATLAB Version: %s \n',MATLAB_version)
fprintf(' OS: %s \n',OS)
fprintf(' Java Version: %s \n',JavaVersion)
fprintf('===========================================================================\n')
fprintf('Verfying Hyscorean directory contents... ')
if allFilesOK
fprintf('no missing files \n')
end
%==========================================================================
% License agreement
%==========================================================================
%If license has been accepted, do not ask again
if ~ispref('hyscorean','LGPL_license')
%Construct GUI with license agreement
FigureHandle = figure('NumberTitle','off','Name','Hyscorean: License Agreement','menu','none','WindowStyle','modal','toolbar','none','units','normalized','Position',[0.25 0.15 0.31 0.75]);
PanelHandel = uipanel(FigureHandle,'Units','normalized','position',[0.02 0.05 0.96 0.86],'title','License');
ListBoxHandle = uicontrol(PanelHandel,'style','listbox','Units','normalized','position',[0 0 1 1],'FontSize',9);
%Add accept and decline buttons
uicontrol(FigureHandle,'style','pushbutton','Units','normalized','position',[0.25 0.005 0.2 0.04],'FontSize',9,'String','Agree','Callback',@AgreeCallback);
uicontrol(FigureHandle,'style','pushbutton','Units','normalized','position',[0.56 0.005 0.2 0.04],'FontSize',9,'String','Disagree','Callback',@DisagreeCallback);
%Add the GNU LGPL logo
AxisHandle = axes(FigureHandle,'Units','normalized','position',[0.02 0.92 0.35 0.075]);
[matlabImage,~,Alpha] = imread(fullfile(InstallationPath,'bin','licenseLogo.png'));
image(matlabImage,'AlphaData',Alpha)
axis(AxisHandle,'off')
%Open license file
FileID = fopen(fullfile(InstallationPath,'LICENSE'));
%Copy license text into UI list box
LineIndicator = 1;
while true
TextLine = fgetl(FileID);
if ~ischar(TextLine)
break
end
strings{LineIndicator}=TextLine;
LineIndicator = LineIndicator + 1;
end
fclose(FileID);
set(ListBoxHandle,'string',strings);
set(ListBoxHandle,'Value',1);
set(ListBoxHandle,'Selected','on');
%Wait for user response
waitfor(FigureHandle)
%Set Hyscorean preference accordingly. If not agreed abort installation
if ispref('hyscorean','LGPL_license')
if getpref('hyscorean','LGPL_license')
fprintf('Hyscorean GNU LGPL 3.0 license accepted \n')
else
fprintf('Hyscorean GNU LGPL 3.0 license needs to be accepted. Aborting installation... \n')
return
end
else
fprintf('Hyscorean GNU LGPL 3.0 license needs to be accepted. Aborting installation... \n')
return
end
end
%==========================================================================
% Hyscorean default paths
%==========================================================================
%Inform user
fprintf('Setting Hyscorean paths... ')
%Get MATLAB search paths
MatlabPaths = path;
OldPaths = textscan(MatlabPaths,'%s','Delimiter',';');
OldPaths = OldPaths{1}(:)';
AddPaths = {pwd,[pwd filesep 'bin'],[pwd filesep 'bin' filesep 'export_fig']};
PathsAlreadyAdded = strfind(horzcat(OldPaths),AddPaths{1});
%Check if Hyscorean paths have been already added
if isempty([PathsAlreadyAdded{:}])
NewPaths = horzcat(AddPaths,OldPaths(1:end));
%If not then add them
if ~isequal(NewPaths,OldPaths)
PathToAdd = sprintf('%s;', NewPaths{:} );
PathToAdd = PathToAdd(1:end-1);
path(PathToAdd);
end
%Save the MATLAB search paths
savepath
end
fprintf('done. \n')
fprintf('===========================================================================\n')
%==========================================================================
% Hyscorean preferences
%==========================================================================
%Inform user
fprintf('Setting Hyscorean preferences... \n')
%Get MATLAB default path
SavePath = userpath;
%Check if preferences have been already defined to keep user preferences
if ~ispref('hyscorean','savepath')
setpref('hyscorean','savepath',SavePath)
fprintf(' Save path: %s \n',SavePath)
else
fprintf(' Save path: %s \n',getpref('hyscorean','savepath'))
end
%Graphical settings
if ~ispref('hyscorean','graphicalsettings')
GraphicalSettings = struct('LineWidth',1,'Levels',40,'PlotType',1,'Colormap',1,'ColormapName','parula','Real',0,'Imaginary',0,'Absolute',1);
setpref('hyscorean','graphicalsettings',GraphicalSettings)
fprintf(' Graphical settings: defaults \n')
else
fprintf(' Graphical settings: user-defined \n')
end
%EasySpin default spin system definition
SystemInputString(1,:) = '%---------------------------------------------';
SystemInputString(2,:) = '% EasySpin Input ';
SystemInputString(3,:) = '%---------------------------------------------';
SystemInputString(4,:) = ' ';
SystemInputString(5,:) = '%Spin System definition ';
SystemInputString(6,:) = '%---------------------------------------------';
SystemInputString(8,:) = 'Sys.Nucs = ''14N,15N,1H''; ';
SystemInputString(9,:) = 'Sys.A = [9 0 0; 7.6 0 0 ; 7.6 8.7 7.0]; ';
SystemInputString(10,:) = 'Sys.Q = [0.8 0.8 0.8; 0 0 0; 0 0 0]; ';
SystemInputString(11,:) = ' ';
SystemInputString(12,:) = '%Fit variables definition ';
SystemInputString(13,:) = '%---------------------------------------------';
SystemInputString(14,:) = 'Vary.A = [2 4 6; 5 4 9; 2 2 2]; ';
setpref('hyscorean','defaultsystemEasyspin',SystemInputString)
if ~ispref('hyscorean','defaultsystemEasyspin')
fprintf(' Easyspin input system: default \n')
else
fprintf(' Easyspin input system: reset to default \n')
end
%==========================================================================
% MATLAB toolbox licenses
%==========================================================================
%Look for required toolboxes licenses
fprintf('===========================================================================\n')
fprintf('Checking required MATLAB toolboxes... \n')
%Report generator
LicenseCheckout = license('test','matlab_report_gen');
if LicenseCheckout
VersionInfo = ver('rptgen');
fprintf(' MATLAB Report Generator (installed) v%s %s %s \n',VersionInfo.Version,VersionInfo.Release,VersionInfo.Date)
setpref('hyscorean','reportlicense',true)
else
fprintf(' MATLAB Report Generator (not found) \n')
fprintf(' (Hyscorean is able to work without this functionality) \n')
setpref('hyscorean','reportlicense',false)
fullyInstalled = false;
end
fprintf('===========================================================================\n')
%==========================================================================
% Easyspin installation checkout
%==========================================================================
%Check if easyspin is installed and added to path
fprintf('Easyspin installation \n')
try
warning('off','all')
easyspin
warning('on','all')
setpref('hyscorean','easyspin_installed',true)
catch
fprintf('Easyspin not found or not installed. Make sure its path is added \n')
fprintf('to the MATLAB default search path and run this installation again.\n')
fprintf('Otherwise the fitting module of Hyscorean will be unavailable. \n')
setpref('hyscorean','easyspin_installed',false)
fullyInstalled = false;
end
%==========================================================================
% Finish & Return
%==========================================================================
fprintf('============================================================================\n')
fprintf('INSTALLATION FINISHED \n')
if fullyInstalled
fprintf(' - Hyscorean was successfully and fully installed and all functionalities are operational.\n')
else
fprintf(' - Hyscorean was successfully but incompletely installed.\n')
end
fprintf(' - MATLAB preferences may be changed later in the GUI \n')
fprintf('============================================================================\n')
%Remove all installer variables from workspace
clearvars
end
%==========================================================================
%Callbacks for License Agreement GUI
%==========================================================================
function AgreeCallback(Object, ~)
setpref('hyscorean','LGPL_license',true)
close(Object.Parent)
end
function DisagreeCallback(Object, ~)
setpref('hyscorean','LGPL_license',false)
close(Object.Parent)
end