-
Notifications
You must be signed in to change notification settings - Fork 7
/
swe.m
257 lines (195 loc) · 6.66 KB
/
swe.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
function varargout = swe(varargin)
% This function initializes the SwE toolbox and checks the installation.
% =========================================================================
% FORMAT swe, swe(), swe('startup') - starts the SwE toolbox.
% FORMAT swe('ASCIIwelcome') - display the startup message.
% FORMAT swe('Colour') - returns the interface colour.
% -------------------------------------------------------------------------
% Inputs:
% - str - 'ASCIIwelcome' for startup message or 'startup' for toolbox
% =========================================================================
% Written by Bryan Guillaume
% Version Info: $Format:%ci$ $Format:%h$
versionNo = '2.2.2';
try
Modality = spm_get_defaults('modality');
catch
spm('defaults','FMRI'); % Starting w/out SPM
end
if nargin == 0
Action = 'StartUp';
else
Action = varargin{1};
end
switch lower(Action)
%==================================================================
case 'startup' % Startup the toolbox
%==================================================================
% check installation of toolbox and of SPM8/SPM12
ok = check_installation;
if ~ok
beep
fprintf('INSTALLATION PROBLEM!');
return
end
% Welcome message
swe('ASCIIwelcome');
% Add pathes for SPM functions
addpath(fullfile(spm('Dir'),'matlabbatch'))
if strncmpi(spm('ver'),'spm12',5)
addpath(fullfile(spm('Dir'),'compat'))
end
% Add path to SwE toolbox.
addpath(fileparts(mfilename('fullpath')));
% launch the main GUI
swe_ui_main;
% print present working directory
fprintf('SwE present working directory:\n\t%s\n',pwd)
%==================================================================
case 'asciiwelcome' %-ASCII swe banner welcome
%==================================================================
tmp = strrep(versionNo,'.rc2','');
tmp = strrep(tmp,'.rc','');
a = generateAscii(['SwE v' tmp]);
fprintf('%s \n', a{1}, a{2}, a{3}, a{4});
fprintf('swe v%s \n', versionNo);
case 'colour'
varargout = {[0.8 0.8 1.0], 'Diluted Blackcurrent Purple'};
case 'ver'
varargout{1}=versionNo;
%==================================================================
otherwise %-Unknown action string
%==================================================================
error('Unknown action string');
end
return
end
%=======================================================================
% SUBFUNCTIONS
%=======================================================================
%=======================================================================
function ok = check_installation
% function to check installation state of toolbox,
% particullarly the SPM path setup
ok=1;
if exist('spm.m','file')
if ~strcmpi(spm('ver'),'spm8')&& ~strncmpi(spm('ver'),'spm12',5)
beep
fprintf('\nERROR:\n')
fprintf('\tSPM8 or SPM12 should be installed on your computer, and\n')
fprintf('\tbe available on MATLABPATH!\n\n')
ok = 0;
end
else
beep
fprintf('\nERROR:\n')
fprintf('\tSPM8 or SPM12 should be installed on your computer, and\n')
fprintf ('\tbe available on MATLABPATH!\n\n')
ok = 0;
end
return
end
% The following functions are for generating the ascii welcome message for
% SwE.
% -------------------------------------------------------------------------
% This method converts character 'char' to it's equivalent 4-line ascii
% art. New characters can be added by creating new cases in the below
% switch.
function aChar = char2ascii(char)
switch char
case '0'
aChar = {' ___ ',...
'| |',...
'| | |',...
'|___|'};
case '1'
aChar = {' _ ',...
'/_|',...
' ||',...
' ||'};
case '2'
aChar = {' ___ ',...
'(__ \',...
'/ __/',...
'\___)'};
case '3'
aChar = {' ___ ',...
'(__ )',...
' (_ \',...
'(___/'};
case '4'
aChar = {' __ ',...
' /. |',...
'(_ _)',...
' (_) '};
case '5'
aChar = {' ___ ',...
'| __)',...
'|__ \',...
'(___/'};
case '6'
aChar = {' _ ',...
' / ) ',...
'/ _ \',...
'\___/'};
case '7'
aChar = {' ___ ',...
'(__ )',...
' / / ',...
'(_/ '};
case '8'
aChar = {' ___ ',...
'| _ |',...
'| _ |',...
'|___| '};
case '9'
aChar = {' ___ ',...
'/ _ \',...
'\_ /',...
' (_/ '};
case '.'
aChar = {' ',...
' ',...
' _ ',...
'|_|'};
case 'S'
aChar = {' ___ ',...
'/ __)',...
'\__ \',...
'(___/'};
case 'w'
aChar = {' ',...
'_ _',...
'\\/\//',...
' \/\/ '};
case 'E'
aChar = {' ___ ',...
'| __)',...
'| __)',...
'|___)'};
case ' '
aChar = {' ',...
' ',...
' ',...
' '};
case 'v'
aChar = {' ',...
'_ _ ',...
'\\// ',...
' \/ '};
end
end
% This function takes two cell arrays containing ascii art in the form
% {line1, line2, line3,...} and concatenates them horizontally.
function c = concatAscii(a,b)
c = arrayfun(@(i) [a{i} b{i}], 1:length(b),'UniformOutput',false);
end
% This function takes in a string as input and recursively generates the
% ASCII art representation of said string.
function ascii = generateAscii(str)
if length(str)~=1
ascii = concatAscii(generateAscii(str(1:(end-1))), generateAscii(str(end)));
else
ascii = char2ascii(str);
end
end