-
Notifications
You must be signed in to change notification settings - Fork 1
/
spm.m
1415 lines (1232 loc) · 52.8 KB
/
spm.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout=spm(varargin)
% SPM: Statistical Parametric Mapping (startup function)
%_______________________________________________________________________
% ___ ____ __ __
% / __)( _ \( \/ )
% \__ \ )___/ ) ( Statistical Parametric Mapping
% (___/(__) (_/\/\_) SPM - http://www.fil.ion.ucl.ac.uk/spm
%_______________________________________________________________________
%
% SPM (Statistical Parametric Mapping) is a package for the analysis
% functional brain mapping experiments. It is the in-house package of
% the Wellcome Department of Cognitive Neurology, and is available to
% the scientific community as copyright freeware under the terms of the
% GNU General Public Licence.
%
% Theoretical, computational and other details of the package are
% available in SPM's "Help" facility. This can be launched from the
% main SPM Menu window using the "Help" button, or directly from the
% command line using the command `spm_help`.
%
% Details of this release are availiable via the "About SPM" help topic
% (file spm.man), accessible from the SPM splash screen. (Or type
% `spm_help spm.man` in the MatLab command window)
%
% This spm function initialises the default parameters, and displays a
% splash screen with buttons leading to the PET(SPECT) & fMRI
% modalities Alternatively, `spm('pet')` and `spm('fmri')`
% (equivalently `spm pet` and `spm mri`) lead directly to the respective
% modality interfaces.
%
% Once the modality is chosen, (and it can be toggled mid-session) the
% SPM user interface is displayed. This provides a constant visual
% environment in which data analysis is implemented. The layout has
% been designed to be simple and at the same time show all the
% facilities that are available. The interface consists of three
% windows: A menu window with pushbuttons for the SPM routines (each
% button has a 'CallBack' string which launches the appropriate
% function/script); A blank panel used for interaction with the user;
% And a graphics figure with various editing and print facilities (see
% spm_figure.m). (These windows are 'Tag'ged 'Menu', 'Interactive', and
% 'Graphics' respectively, and should be referred to by their tags
% rather than their figure numbers.)
%
% Further interaction with the user is (mainly) via questioning in the
% 'Interactive' window (managed by spm_input), and file selection
% (managed by spm_get). See the help on spm_input.m and spm_get.m for
% details on using these functions.
%
% If a "message of the day" file named spm_motd.man exists in the SPM
% directory (alongside spm.m) then it is displayed in the Graphics
% window on startup.
%
% Arguments to this routine (spm.m) lead to various setup facilities,
% mainly of use to SPM power users and programmers. See programmers
% FORMAT & help in the main body of spm.m
%
%_______________________________________________________________________
% SPM is developed by members and collaborators of the
% Wellcome Department of Cognitive Neurology
%-SCCS ID and authorship of this program...
%-----------------------------------------------------------------------
% @(#)spm.m 2.67 Andrew Holmes 01/03/14
%=======================================================================
% - FORMAT specifications for embedded CallBack functions
%=======================================================================
%( This is a multi function function, the first argument is an action )
%( string, specifying the particular action function to take. Recall )
%( MatLab's command-function duality: `spm Welcome` is equivalent to )
%( `spm('Welcome')`. )
%
% FORMAT spm
% Defaults to spm('Welcome')
%
% FORMAT spm('Welcome')
% Clears command window, deletes all figures, prints welcome banner and
% splash screen, sets window defaults.
%
% FORMAT spm('AsciiWelcome')
% Prints ASCII welcome banner in MatLab command window.
%
% FORMAT spm('PET') spm('FMRI')
% Closes all windows and draws new Menu, Interactive, and Graphics
% windows for an SPM session. The buttons in the Menu window launch the
% main analysis routines.
%
% FORMAT Fmenu = spm('CreateMenuWin',Vis)
% Creates SPM menu window, 'Tag'ged 'Menu'
% F - handle of figure created
% Vis - Visibility, 'on' or 'off'
%
% Finter = FORMAT spm('CreateIntWin',Vis)
% Creates an SPM Interactive window, 'Tag'ged 'Interactive'
% F - handle of figure created
% Vis - Visibility, 'on' or 'off'
%
% FORMAT spm('ChMod',Modality)
% Changes modality of SPM: Currently SPM supports PET & MRI modalities,
% each of which have a slightly different Menu window and different
% defaults. This function switches to the specified modality, setting
% defaults and displaying the relevant buttons.
%
% FORMAT spm('defaults',Modality)
% Sets default global variables for the specified modality.
%
% FORMAT [Modality,ModNum]=spm('CheckModality',Modality)
% Checks the specified modality against those supported, returns
% upper(Modality) and the Modality number, it's position in the list of
% supported Modalities.
%
% FORMAT WS=spm('WinScale')
% Returns ratios of current display dimensions to that of a 1152 x 900
% Sun display. WS=[Xratio,Yratio,Xratio,Yratio]. Used for scaling other
% GUI elements.
% (Function duplicated in spm_figure.m, repeated to reduce inter-dependencies.)
%
% FORMAT [FS,sf] = spm('FontSize',FS)
% FORMAT [FS,sf] = spm('FontSizes',FS)
% Returns fontsizes FS scaled for the current display.
% FORMAT sf = spm('FontScale')
% Returns font scaling factor
% FS - (vector of) Font sizes to scale [default [1:36]]
% sf - font scaling factor (FS(out) = floor(FS(in)*sf)
%
% Rect = spm('WinSize',Win,raw)
% Returns sizes and positions for SPM windows.
% Win - 'Menu', 'Interactive', 'Graphics', or '0'
% - Window whose position is required. Only first character is
% examined. '0' returns size of root workspace.
% raw - If specified, then positions are for a 1152 x 900 Sun display.
% Otherwise the positions are scaled for the current display.
%
% FORMAT SPMdir=spm('Dir',Mfile)
% Returns the directory containing the version of spm in use,
% identified as the first in MATLABPATH containing the Mfile spm (this
% file) (or Mfile if specified).
%
% FORMAT [v,c]=spm('Ver',Mfile,ReDo,Cache,Con)
% Returns the current version (v) & copyright notice, extracted from
% the top line of the Contents.m file in the directory containing the
% currently used file Mfile (defaults on omission or empty to 'spm').
% %-The version and copyright information are saved in a global
% variable called [upper(spm_str_manip(Mfile,'rt')),'_VER'], as a
% structure with fields 'v' and 'c'. This enables repeat use without
% recomputation.
%-If Con [default (missing or empty) 1] is false, then the version
% information is extracted from Mfile itself, rather than the
% Contents.m file in the same directory. When using a Contents.m file,
% the first line is read. For other files, the second line (the H1 help
% line) is used. This is for consistency with MatLab's ver and help
% commands respectively. (This functionality enables toolboxes to be
% identified by a function rather than a Contents.m file, allowing
% installation in a directory which already has a Contents.m file.)
%-If Cache [default (missing or empty) 1] is true, then the version and
% copyright information cached in the global variable
% [upper(Mfile),'_VER'], as a structure with fields 'v' and 'c'. This
% enables repeat use without recomputation.
%-If ReDo [default (missing or empty) 0] is true, then the version and
% copyright information are recomputed (regardless of any stored global
% data).
%
% FORMAT xTB = spm('TBs')
% Identifies installed SPM toolboxes: SPM toolboxes are defined as the
% contents of sub-directories of fullfile(spm('Dir'),'toolbox') - the
% SPM toolbox installation directory. For SPM to pick a toolbox up,
% there must be a single mfile in the directory whose name ends with
% the toolbox directory name. (I.e. A toolbox called "test" would be in
% the "test" subdirectory of spm('Dir'), with a single file named
% *test.m.) This M-file is regarded as the launch file for the
% toolbox.
% xTB - structure array containing toolbox definitions
% xTB.name - name of toolbox (taken as toolbox directory name)
% xTB.prog - launch program for toolbox
% xTB.dir - toolbox directory
%
% FORMAT spm('TBlaunch',xTB,i)
% Launch a toolbox, prepending TBdir to path if necessary
% xTB - toolbox definition structure (i.e. from spm('TBs')
% xTB.name - name of toolbox
% xTB.prog - name of program to launch toolbox
% xTB.dir - toolbox directory (prepended to path if not on path)
%
% FORMAT [c,cName] = spm('Colour')
% Returns the RGB triple and a description for the current en-vogue SPM
% colour, the background colour for the Menu and Help windows.
%
% FORMAT [v1,v2,...] = spm('GetGlobal',name1,name2,...)
% Returns values of global variables (without declaring them global)
% name1, name2,... - name strings of desired globals
% a1, a2,... - corresponding values of global variables with given names
% ([] is returned as value if global variable doesn't exist)
%
% FORMAT CmdLine = spm('CmdLine',CmdLine)
% Command line SPM usage?
% CmdLine (input) - CmdLine preference
% [defaults (missing or empty) to global ]
% [CMDLINE, if it exists, or 0 (GUI) otherwise. ]
% CmdLine (output) - true if global CmdLine if true,
% or if on a terminal with no support for graphics windows.
%
% FORMAT v = spm('MLver')
% Returns MatLab version, truncated to major & minor revision numbers
%
% FORMAT spm('SetCmdWinLabel',WinStripe,IconLabel)
% Sets the names on the headers and icons of Sun command tools.
% WinStripe defaults to a summary line identifying the user, host and
% MatLab version; IconLabel to 'MatLab'.
%
% FORMAT spm('PopUpCB',h)
% Callback handler for PopUp UI menus with multiple callbacks as cellstr UserData
%
% FORMAT str = spm('GetUser',fmt)
% Returns current users login name, extracted from the hosting environment
% fmt - format string: If USER is defined then sprintf(fmt,USER) is returned
%
% FORMAT spm('Beep')
% plays the keyboard beep!
%
% FORMAT spm('time')
% Returns the current time and date as hh:mm dd/mm/yyyy
%
% FORMAT spm('Pointer',Pointer)
% Changes pointer on all SPM (HandleVisible) windows to type Pointer
% Pointer defaults to 'Arrow'. Robust to absence of windows
%
% FORMAT h = spm('alert',Message,Title,CmdLine,wait)
% FORMAT h = spm('alert"',Message,Title,CmdLine,wait)
% FORMAT h = spm('alert*',Message,Title,CmdLine,wait)
% FORMAT h = spm('alert!',Message,Title,CmdLine,wait)
% Displays an alert, either in a GUI msgbox, or as text in the command window.
% ( 'alert"' uses the 'help' msgbox icon, 'alert*' the )
% ( 'error' icon, 'alert!' the 'warn' icon )
% Message - string (or cellstr) containing message to print
% Title - title string for alert
% CmdLine - CmdLine preference [default spm('CmdLine')]
% - If CmdLine is complex, then a CmdLine alert is always used,
% possibly in addition to a msgbox (the latter according
% to spm('CmdLine').)
% - If in batch mode (non-empty global BCH), then uses CmdLine alert
% wait - if true, waits until user dismisses GUI / confirms text alert
% [default 0] (if doing both GUI & text, waits on GUI alert)
% - If in batch mode (non-empty global BCH), doesn't wait
% h - handle of msgbox created, empty if CmdLine used
%
% FORMAT SPMid = spm('FnBanner', Fn,FnV)
% Prints a function start banner, for version FnV of function Fn, & datestamps
% FORMAT SPMid = spm('SFnBanner',Fn,FnV)
% Prints a sub-function start banner
% FORMAT SPMid = spm('SSFnBanner',Fn,FnV)
% Prints a sub-sub-function start banner
% Fn - Function name (string)
% FnV - Function version (string)
% SPMid - ID string: [SPMver: Fn (FnV)]
%
% FORMAT [Finter,Fgraph,CmdLine] = spm('FnUIsetup',Iname,bGX,CmdLine)
% Robust UIsetup procedure for functions:
% Returns handles of 'Interactive' and 'Graphics' figures.
% Creates 'Interactive' figure if ~CmdLine, creates 'Graphics' figure if bGX.
% Iname - Name for 'Interactive' window
% bGX - Need a Graphics window? [default 1]
% CmdLine - CommandLine usage? [default spm('CmdLine')]
% Finter - handle of 'Interactive' figure
% Fgraph - handle of 'Graphics' figure
% CmdLine - CommandLine usage?
%
% FORMAT F = spm('FigName',Iname,F,CmdLine)
% Set name of figure F to "SPMver (User): Iname" if ~CmdLine
% Robust to absence of figure.
% Iname - Name for figure
% F (input) - Handle (or 'Tag') of figure to name [default 'Interactive']
% CmdLine - CommandLine usage? [default spm('CmdLine')]
% F (output) - Handle of figure named
%
% FORMAT spm('GUI_FileDelete')
% CallBack for GUI for file deletion, using spm_get and confirmation dialogs
%
% FORMAT Fs = spm('Show')
% Opens all SPM figure windows (with HandleVisibility) using `figure`.
% Maintains current figure.
% Fs - vector containing all HandleVisible figures (i.e. get(0,'Children'))
%
% FORMAT spm('Clear',Finter, Fgraph)
% Clears and resets SPM-GUI, clears and timestamps MatLab command window
% Finter - handle or 'Tag' of 'Interactive' figure [default 'Interactive']
% Fgraph - handle or 'Tag' of 'Graphics' figure [default 'Graphics']
%
% FORMAT spm('Help',varargin)
% Merely a gateway to spm_help(varargin) - so you can type "spm help"
%
%_______________________________________________________________________
%-Parameters
%-----------------------------------------------------------------------
Modalities = str2mat('PET','FMRI');
%-Format arguments
%-----------------------------------------------------------------------
if nargin == 0, Action='Welcome'; else, Action = varargin{1}; end
%=======================================================================
switch lower(Action), case 'welcome' %-Welcome splash screen
%=======================================================================
%-Open startup window, set window defaults
%-----------------------------------------------------------------------
S = get(0,'ScreenSize');
if all(S==1), error('Can''t open any graphics windows...'), end
[SPMver,SPMc] = spm('Ver','',1);
PF = spm_platform('fonts');
F = figure('IntegerHandle','off',...
'Name',sprintf('%s%s',spm('ver'),spm('GetUser',' (%s)')),...
'NumberTitle','off',...
'Tag','Welcome',...
'Position',[S(3)/2-300,S(4)/2-140,500,280],...
'Resize','off',...
'Pointer','Watch',...
'Color',[1 1 1]*.8,...
'MenuBar','none',...
'DefaultUicontrolFontName',PF.helvetica,...
'HandleVisibility','off',...
'Visible','off');
%-Text
%-----------------------------------------------------------------------
hA = axes('Parent',F,'Position',[0 0 100/500 280/280],'Visible','Off');
text(0.5,0.5,'SPM',...
'Parent',hA,...
'FontName',PF.times,'FontSize',96,...
'FontAngle','Italic','FontWeight','Bold',...
'Rotation',90,...
'VerticalAlignment','Middle','HorizontalAlignment','Center',...
'Color',[1 1 1]*.6);
uicontrol(F,'Style','Text','Position',[110 245 390 030],...
'String','Statistical Parametric Mapping',...
'FontName',PF.times,'FontSize',18,'FontAngle','Italic',...
'FontWeight','Bold',...
'ForegroundColor',[1 1 1]*.6,'BackgroundColor',[1 1 1]*.8);
uicontrol(F,'Style','Frame','Position',[110 130 380 115]);
uicontrol(F,'Style','Frame','Position',[110 015 380 087]);
uicontrol(F,'Style','Text','String',SPMver,...
'ToolTipString','by the FIL methods group',...
'Position',[112 200 376 030],...
'FontName',PF.times,'FontSize',18,'FontWeight','Bold',...
'ForegroundColor','b')
uicontrol(F,'Style','Text','Position',[112 175 376 020],...
'String','developed by members and collaborators of',...
'ToolTipString','',...
'FontName',PF.times,'FontSize',10,'FontAngle','Italic')
uicontrol(F,'Style','Text','Position',[112 160 376 020],...
'String','The Wellcome Department of Cognitive Neurology',...
'ToolTipString','',...
'FontName',PF.times,'FontSize',12,'FontWeight','Bold')
uicontrol(F,'Style','Text', 'Position',[112 140 376 020],...
'String','Institute of Neurology, University College London',...
'ToolTipString','',...
'FontName',PF.times,'FontSize',12)
uicontrol(F,'Style','Text','String',SPMc,'ToolTipString',SPMc,...
'ForegroundColor',[1 1 1]*.6,'BackgroundColor',[1 1 1]*.8,...
'FontName',PF.times,'FontSize',10,...
'HorizontalAlignment','center',...
'Position',[110 003 380 010])
%-Objects with Callbacks - PET, fMRI, About SPM, SPMweb
%-----------------------------------------------------------------------
set(F,'DefaultUicontrolFontSize',12,'DefaultUicontrolInterruptible','on')
uicontrol(F,'String','PET and SPECT',...
'ToolTipString',...
'launch SPM-GUI in PET/SPECT modality (or type "spm pet" in MatLab)',...
'Position',[140 061 150 030],...
'CallBack','delete(gcbf),clear all,spm(''PET'')',...
'ForegroundColor',[0 1 1])
uicontrol(F,'String','fMRI time-series',...
'ToolTipString',...
'launch SPM-GUI in fMRI modality (or type "spm fmri" in MatLab)',...
'Position',[310 061 150 030],...
'CallBack','delete(gcbf),clear all,spm(''FMRI'')',...
'ForegroundColor',[0 1 1])
uicontrol(F,'String','About SPM',...
'ToolTipString','launch SPMhelp browser - about SPM',...
'Position',[140 025 100 030],...
'CallBack','spm_help(''spm.man'')',...
'ForegroundColor','g')
uicontrol(F,'String','SPMweb',...
'FontWeight','Bold','FontName',PF.courier,...
'ToolTipString',...
'launch web browser - http://www.fil.ion.ucl.ac.uk/spm',...
'Position',[250 025 100 030],...
'CallBack',['set(gcbf,''Pointer'',''Watch''),',...
'web(''http://www.fil.ion.ucl.ac.uk/spm'');',...
'set(gcbf,''Pointer'',''Arrow'')'],...
'ForegroundColor','k')
uicontrol(F,'String','Quit',...
'ToolTipString','close this splash screen',...
'Position',[360 025 100 030],...
'CallBack','delete(gcbf)',...
'Interruptible','off',...
'ForegroundColor','r')
set(F,'Pointer','Arrow','Visible','on')
%=======================================================================
case 'asciiwelcome' %-ASCII SPM banner welcome
%=======================================================================
disp( ' ___ ____ __ __ ')
disp( '/ __)( _ \( \/ ) ')
disp( '\__ \ )___/ ) ( Statistical Parametric Mapping ')
disp(['(___/(__) (_/\/\_) ',spm('Ver'),' - http://www.fil.ion.ucl.ac.uk/spm'])
fprintf('\n')
%=======================================================================
case {'pet','fmri'} %-Initialise SPM in PET or fMRI modality
%=======================================================================
% spm(Modality)
%-Turn on warning messages for debugging
warning always, warning backtrace
%-Initialisation and workspace canonicalisation
%-----------------------------------------------------------------------
clc, spm('SetCmdWinLabel')
spm('AsciiWelcome'), fprintf('\n\nInitialising SPM')
Modality = upper(Action); fprintf('.')
delete(get(0,'Children')), fprintf('.')
%-Draw SPM windows
%-----------------------------------------------------------------------
Fmenu = spm('CreateMenuWin','off'); fprintf('.')
Finter = spm('CreateIntWin','off'); fprintf('.')
spm_figure('WaterMark',Finter,spm('Ver'),'',45), fprintf('.')
Fgraph = spm_figure('Create','Graphics','Graphics','off'); fprintf('.')
Fmotd = fullfile(spm('Dir'),'spm_motd.man');
if exist(Fmotd), spm_help('!Disp',Fmotd,'',Fgraph,spm('Ver')); end
fprintf('.')
%-Load startup global defaults
%-----------------------------------------------------------------------
spm_defaults, fprintf('.')
%-Setup for current modality
%-----------------------------------------------------------------------
spm('ChMod',Modality), fprintf('.')
%-Reveal windows
%-----------------------------------------------------------------------
set([Fmenu,Finter,Fgraph],'Visible','on')
fprintf('done\n\n')
%-Print present working directory
%-----------------------------------------------------------------------
fprintf('SPM present working directory:\n\t%s\n',pwd)
%=======================================================================
case 'createmenuwin' %-Draw SPM menu window
%=======================================================================
% Fmenu = spm('CreateMenuWin',Vis)
if nargin<2, Vis='on'; else, Vis=varargin{2}; end
%-Close any existing 'Menu' 'Tag'ged windows
delete(spm_figure('FindWin','Menu'))
%-Get size and scalings and create Menu window
%-----------------------------------------------------------------------
WS = spm('WinScale'); %-Window scaling factors
FS = spm('FontSizes'); %-Scaled font sizes
PF = spm_platform('fonts'); %-Font names (for this platform)
Rect = spm('WinSize','Menu','raw').*WS; %-Menu window rectangle
[SPMver,SPMc] = spm('Ver','',1,1);
Fmenu = figure('IntegerHandle','off',...
'Name',sprintf('%s%s',spm('ver'),spm('GetUser',' (%s)')),...
'NumberTitle','off',...
'Tag','Menu',...
'Position',Rect,...
'Resize','off',...
'Color',[1 1 1]*.8,...
'UserData',struct('SPMver',SPMver,'SPMc',SPMc),...
'MenuBar','none',...
'DefaultTextFontName',PF.helvetica,...
'DefaultTextFontSize',FS(12),...
'DefaultUicontrolFontName',PF.helvetica,...
'DefaultUicontrolFontSize',FS(12),...
'DefaultUicontrolInterruptible','on',...
'Renderer','zbuffer',...
'Visible','off');
%-Frames and text
%-----------------------------------------------------------------------
uicontrol(Fmenu,'Style','Frame','BackgroundColor',spm('Colour'),...
'Position',[010 145 380 295].*WS)
uicontrol(Fmenu,'Style','Frame',...
'Position',[020 320 360 110].*WS)
uicontrol(Fmenu,'Style','Text','String','spatial pre-processing',...
'Position',[025 405 350 020].*WS,...
'ForegroundColor','w','FontName',PF.times,'FontAngle','Italic')
uicontrol(Fmenu,'Style','Frame',...
'Position',[020 155 360 155].*WS)
uicontrol(Fmenu,'Style','Text',...
'String','model specification & parameter estimation',...
'Position',[025 285 350 020].*WS,...
'ForegroundColor','w','FontName',PF.times,'FontAngle','Italic')
uicontrol(Fmenu,'Style','Text','String','statistical inference',...
'Position',[025 195 350 020].*WS,...
'ForegroundColor','w','FontName',PF.times,'FontAngle','Italic')
uicontrol(Fmenu,'Style','Text',...
'String','SPM for PET/SPECT',...
'ToolTipString','modality & defaults set for PET/SPECT',...
'ForegroundColor',[1 1 1]*.6,'BackgroundColor',[1 1 1]*.8,...
'FontName',PF.times,'FontAngle','Italic','FontWeight','Bold',...
'HorizontalAlignment','center',...
'Position',[020 122 360 020].*WS,...
'Tag','PET','Visible','off')
uicontrol(Fmenu,'Style','Text',...
'String','SPM for functional MRI',...
'ToolTipString','modality & defaults set for fMRI',...
'ForegroundColor',[1 1 1]*.6,'BackgroundColor',[1 1 1]*.8,...
'FontName',PF.times,'FontAngle','Italic','FontWeight','Bold',...
'HorizontalAlignment','center',...
'Position',[020 122 360 020].*WS,...
'Tag','FMRI','Visible','off')
uicontrol(Fmenu,'Style','Frame','BackgroundColor',spm('Colour'),...
'Position',[010 010 380 112].*WS);
uicontrol(Fmenu,'Style','Text','String',SPMc,'ToolTipString',SPMc,...
'ForegroundColor',[1 1 1]*.6,'BackgroundColor',[1 1 1]*.8,...
'FontName',PF.times,'FontSize',FS(10),...
'HorizontalAlignment','center',...
'Position',[020 002 360 008].*WS)
%-Objects with Callbacks - main spm_*_ui.m routines
%=======================================================================
%-Spatial
%-----------------------------------------------------------------------
uicontrol(Fmenu,'String','Realign', 'Position',[040 370 080 030].*WS,...
'ToolTipString','realignment',...
'CallBack','spm_realign_ui;')
uicontrol(Fmenu,'String','Normalize', 'Position',[150 350 100 030].*WS,...
'ToolTipString','spatial normalisation',...
'CallBack','spm_sn3d;', 'Tag','PET', 'Visible','off');
uicontrol(Fmenu,'String','Normalize', 'Position',[150 330 100 030].*WS,...
'ToolTipString','spatial normalisation',...
'CallBack','spm_sn3d;', 'Tag', 'FMRI', 'Visible','off');
uicontrol(Fmenu,'String','Slice timing', 'Position',[150 370 100 030].*WS,...
'ToolTipString','correct slice acquisition times',...
'CallBack','spm_slice_timing;', 'Tag', 'FMRI', 'Visible','off');
uicontrol(Fmenu,'String','Smooth', 'Position',[280 370 080 030].*WS,...
'ToolTipString','spatial smoothing with Gaussian kernel',...
'CallBack','spm_smooth_ui;');
uicontrol(Fmenu,'String','Coregister', 'Position',[040 330 080 030].*WS,...
'ToolTipString','co-register images from disparate modalities',...
'CallBack','spm_coreg_ui;');
uicontrol(Fmenu,'String','Segment', 'Position',[280 330 080 030].*WS,...
'ToolTipString','segment',...
'CallBack','spm_segment;');
%-Statistical
%-----------------------------------------------------------------------
uicontrol(Fmenu,'String','PET/SPECT models','Position',[035 255 160 030].*WS,...
'ToolTipString','general linear model setup for PET/SPECT',...
'CallBack','spm_spm_ui(''cfg'',spm_spm_ui(''DesDefs_PET''))',...
'Visible','off', 'Tag','PET', 'Enable','on')
uicontrol(Fmenu,'String','fMRI models', 'Position',[035 255 160 030].*WS,...
'ToolTipString',['general linear model setup & stats for serially ',...
'correlated fMRI time series'],...
'CallBack','[X,Sess] = spm_fmri_spm_ui;',...
'Visible','off', 'Tag','FMRI')
uicontrol(Fmenu,'String','Basic models','Position',[205 255 160 030].*WS,...
'ToolTipString','basic stats models for independent data',...
'CallBack','spm_spm_ui(''cfg'',spm_spm_ui(''DesDefs_Stats''))')
uicontrol(Fmenu,'String','Explore design','Position',[035 220 160 030].*WS,...
'ToolTipString','review a previously specified model',...
'CallBack','spm pointer watch, spm_DesRep; spm pointer arrow')
str = [...
'if exist(fullfile(''.'',''SPM.mat''),''file'')==2 & ',...
'spm_input({''Current directory contains existing SPMstats files:'',',...
''' SPMstats results files (inc. SPM.mat)'',',...
'[''(pwd = '',pwd,'')''],'' '',',...
'''Continuing will overwrite existing results!''},1,''bd'',',...
'''stop|continue'',[1,0],1), tmp=0; else, tmp=1; end, ',...
'if tmp, ',...
'tmp = load(spm_get(1,''SPMcfg.mat'',''Select SPMcfg.mat...'')); ',...
'if isfield(tmp,''Sess'') & ~isempty(tmp.Sess), ',...
'Sess=tmp.Sess; xsDes=tmp.xsDes;',... % because spm_spm uses inputname
'spm_spm(tmp.VY,tmp.xX,tmp.xM,tmp.F_iX0,Sess,xsDes), ',...
'elseif isfield(tmp,''xC''), ',...
'xC=tmp.xC; xsDes=tmp.xsDes;',... % because spm_spm uses inputname
'spm_spm(tmp.VY,tmp.xX,tmp.xM,tmp.F_iX0,xC,xsDes), ',...
'end, ',...
'end'];
uicontrol(Fmenu,'String','Estimate','Position',[205 220 160 030].*WS,...
'ToolTipString','estimate a previously specified model',...
'CallBack',str)
uicontrol(Fmenu,'String','Results', 'Position',[035 165 330 030].*WS,...
'ToolTipString','compute & interrogate SPM''s etc.',...
'CallBack','[hReg,SPM,VOL,xX,xCon,xSDM] = spm_results_ui;')
%-Utility buttons (first line)
%-----------------------------------------------------------------------
uicontrol(Fmenu,'String','Display', 'Position',[020 088 082 024].*WS,...
'ToolTipString','orthogonal sections',...
'FontSize',FS(9), 'CallBack','spm_image')
uicontrol(Fmenu,'String','Check Reg', 'Position',[112 088 083 024].*WS,...
'ToolTipString','check image registration',...
'FontSize',FS(9), 'CallBack','spm_check_registration;')
uicontrol(Fmenu,'Style','PopUp',...
'String','Render...|Display|Xtract Brain',...
'Position',[205 088 083 024].*WS,...
'ToolTipString','rendering utilities...',...
'FontSize',FS(9), 'CallBack','spm(''PopUpCB'',gcbo)',...
'UserData',{ 'spm_render;',...
'spm_xbrain;' })
uicontrol(Fmenu,'Style','PopUp','String',Modalities,...
'ToolTipString','change modality PET<->fMRI',...
'Tag','Modality', 'Position',[298 088 082 024].*WS,...
'CallBack',[...
'if isempty(get(gco,''UserData'')) | ',...
'get(gco,''Value'')~=get(gco,''UserData''),',...
'spm(''ChMod'',get(gco,''Value'')),',...
'end'],...
'Interruptible','off')
%-Utility buttons (second line)
%-----------------------------------------------------------------------
%-Toolbox pulldown
xTB = spm('TBs');
if isempty(xTB)
uicontrol(Fmenu,'String','Toolboxes...','Position',[020 054 082 024].*WS,...
'ToolTipString','Additional Toolboxes',...
'FontSize',FS(9), 'CallBack','','Enable','off')
else
uicontrol(Fmenu,'Style','PopUp','String',{'Toolboxes...',xTB.name},...
'ToolTipString','Additional Toolboxes',...
'Position',[020 054 082 024].*WS,...
'FontSize',FS(9),'CallBack',...
['spm(''TBlaunch'',get(gcbo,''UserData''),get(gcbo,''Value'')-1), ',...
'set(gcbo,''Value'',1)'],...
'UserData', xTB)
end
uicontrol(Fmenu,'Style','PopUp',...
'String','Means...|Mean|adjMean|adjMean/fMRI',...
'Position',[112 054 083 024].*WS,...
'ToolTipString','image averaging utilities...',...
'FontSize',FS(9), 'CallBack','spm(''PopUpCB'',gcbo)',...
'UserData',{ 'spm_mean_ui;',...
'spm_adjmean_ui;',...
'spm_adjmean_fmri_ui;' })
uicontrol(Fmenu,'String','ImCalc', 'Position',[205 054 083 024].*WS,...
'ToolTipString','image calculator',...
'FontSize',FS(9), 'CallBack','spm_imcalc_ui;')
uicontrol(Fmenu,'String','HDR edit', 'Position',[298 054 082 024].*WS,...
'ToolTipString','header editor',...
'FontSize',FS(9), 'CallBack','spm_header_edit;')
%-Utility buttons (third line)
%-----------------------------------------------------------------------
uicontrol(Fmenu,'String','Help', 'Position',[020 020 082 024].*WS,...
'ToolTipString','launch SPMhelp browser',...
'CallBack','spm_help;',...
'ForeGroundColor','g')
uicontrol(Fmenu,'Style','PopUp',...
'String','Utils...|CD|PWD|delete files|Show SPM|Run mFile|SPMweb',...
'ToolTipString','misc SPM utilities',...
'Position',[112 020 083 024].*WS,...
'FontSize',FS(9), 'CallBack','spm(''PopUpCB'',gcbo)',...
'UserData',{ [...
'spm(''FnBanner'',''CD'');',...
'cd(spm_get(-1,''*'',''Select new working directory'',pwd)),',...
'spm(''alert"'',',...
'{''New working directory:'',['' '',pwd]},',...
'''CD'',sqrt(-1));'],...
['spm(''alert"'',',...
'{''Present working directory:'',['' '',pwd]},',...
'''PWD'',0);'],...
'spm(''GUI_FileDelete'')',...
'spm(''Show'');',...
'run(spm_get(1,''*.m'',''Select mFile to run''))',...
'web(''http://www.fil.ion.ucl.ac.uk/spm'')' } )
uicontrol(Fmenu,'String','Defaults', 'Position',[205 020 083 024].*WS,...
'ToolTipString','adjust default SPM behaviour for this session',...
'FontSize',FS(9), 'CallBack','spm_defaults_edit;')
uicontrol(Fmenu,'String','Quit', 'Position',[298 020 082 024].*WS,...
'ToolTipString','exit SPM',...
'ForeGroundColor','r', 'Interruptible','off',...
'CallBack','spm(''Quit''), clear all')
%-----------------------------------------------------------------------
set(Fmenu,'CloseRequestFcn','spm(''Quit'')')
set(Fmenu,'Visible',Vis)
varargout = {Fmenu};
%=======================================================================
case 'createintwin' %-Create SPM interactive window
%=======================================================================
% Finter = spm('CreateIntWin',Vis)
if nargin<2, Vis='on'; else, Vis=varargin{2}; end
%-Close any existing 'Interactive' 'Tag'ged windows
delete(spm_figure('FindWin','Interactive'))
FS = spm('FontSizes'); %-Scaled font sizes
PF = spm_platform('fonts'); %-Font names (for this platform)
Rect = spm('WinSize','Interactive'); %-Interactive window rectangle
%-Create SPM Interactive window
Finter = figure('IntegerHandle','off',...
'Tag','Interactive',...
'Name','','NumberTitle','off',...
'Position',Rect,...
'Resize','off',...
'Color',[1 1 1]*.7,...
'MenuBar','none',...
'DefaultTextFontName',PF.helvetica,...
'DefaultTextFontSize',FS(10),...
'DefaultAxesFontName',PF.helvetica,...
'DefaultUicontrolBackgroundColor',[1 1 1]*.7,...
'DefaultUicontrolFontName',PF.helvetica,...
'DefaultUicontrolFontSize',FS(10),...
'DefaultUicontrolInterruptible','on',...
'Renderer', 'zbuffer',...
'Visible',Vis);
varargout = {Finter};
%=======================================================================
case 'chmod' %-Change SPM modality PET<->fMRI
%=======================================================================
% spm('ChMod',Modality)
%-Sort out arguments
%-----------------------------------------------------------------------
if nargin<2, Modality = ''; else, Modality = varargin{2}; end
[Modality,ModNum] = spm('CheckModality',Modality);
if strcmp(Modality,'PET'), OModality = 'FMRI'; else, OModality='PET'; end
%-Sort out global defaults
%-----------------------------------------------------------------------
spm('defaults',Modality)
%-Sort out visability of appropriate controls on Menu window
%-----------------------------------------------------------------------
Fmenu = spm_figure('FindWin','Menu');
if isempty(Fmenu), error('SPM Menu window not found'), end
set(findobj(Fmenu,'Tag',OModality),'Visible','off')
set(findobj(Fmenu,'Tag', Modality),'Visible','on')
set(findobj(Fmenu,'Tag','Modality'),'Value',ModNum,'UserData',ModNum)
%=======================================================================
case 'defaults' %-Set SPM defaults (as global variables)
%=======================================================================
% spm('defaults',Modality)
%-Sort out arguments
%-----------------------------------------------------------------------
if nargin<2, Modality=''; else, Modality=varargin{2}; end
Modality = spm('CheckModality',Modality);
%-Set MODALITY
%-----------------------------------------------------------------------
% clear global
global MODALITY
MODALITY = Modality;
%-Set global defaults (global variables)
%-----------------------------------------------------------------------
global SWD TWD DESCRIP
SWD = spm('Dir'); % SPM directory
TWD = spm_platform('tempdir'); % Temp directory
%-Get global modality defaults
%-----------------------------------------------------------------------
global PET_UFp PET_DIM PET_VOX PET_TYPE PET_SCALE PET_OFFSET PET_ORIGIN PET_DESCRIP
global fMRI_UFp fMRI_DIM fMRI_VOX fMRI_TYPE fMRI_SCALE fMRI_OFFSET fMRI_ORIGIN fMRI_DESCRIP
%-Load startup defaults (if not already done so)
%-----------------------------------------------------------------------
if isempty(PET_DIM), spm_defaults, end
%-Set Modality specific default (global variables)
%-----------------------------------------------------------------------
global UFp DIM VOX SCALE TYPE OFFSET ORIGIN
if strcmp(Modality,'PET')
DIM = PET_DIM; % Dimensions [x y z]
VOX = PET_VOX; % Voxel size [x y z]
SCALE = PET_SCALE; % Scaling coeficient
TYPE = PET_TYPE; % Data type
OFFSET = PET_OFFSET; % Offset in bytes
ORIGIN = PET_ORIGIN; % Origin in voxels
UFp = PET_UFp; % Upper tail F-prob
elseif strcmp(Modality,'FMRI')
DIM = fMRI_DIM; % Dimensions {x y z]
VOX = fMRI_VOX; % Voxel size {x y z]
SCALE = fMRI_SCALE; % Scaling coeficient
TYPE = fMRI_TYPE; % Data type
OFFSET = fMRI_OFFSET; % Offset in bytes
ORIGIN = fMRI_ORIGIN; % Origin in voxels
UFp = fMRI_UFp; % Upper tail F-prob
elseif strcmp(Modality,'UNKNOWN')
else
error('Illegal Modality')
end
%=======================================================================
case 'quit' %-Quit SPM and clean up
%=======================================================================
% spm('Quit')
%-----------------------------------------------------------------------
delete(get(0,'Children'))
clc
fprintf('Bye...\n\n')
%=======================================================================
case 'checkmodality' %-Check & canonicalise modality string
%=======================================================================
% [Modality,ModNum] = spm('CheckModality',Modality)
%-----------------------------------------------------------------------
if nargin<2, Modality=''; else, Modality=upper(varargin{2}); end
if isempty(Modality)
global MODALITY
if ~isempty(MODALITY); Modality = MODALITY;
else, Modality = 'UNKNOWN'; end
end
if isstr(Modality)
ModNum = find(all(Modalities(:,1:length(Modality))'==...
Modality'*ones(1,size(Modalities,1))));
else
if ~any(Modality==[1:size(Modalities,1)])
Modality = 'ERROR';
ModNum = [];
else
ModNum = Modality;
Modality = deblank(Modalities(ModNum,:));
end
end
if isempty(ModNum), error('Unknown Modality'), end
varargout = {upper(Modality),ModNum};
%=======================================================================
case {'winscale','getwinscale'} %-Window scale factors (to fit display)
%=======================================================================
% WS = spm('WinScale')
if strcmp(lower(Action),'getwinscale')
warning('spm(''GetWinScale'' GrandFathered, use ''WinScale''')
end
S0 = get(0,'ScreenSize');
if all(S0==1), error('Can''t open any graphics windows...'), end
varargout = {[S0(3)/1152 S0(4)/900 S0(3)/1152 S0(4)/900]};
%=======================================================================
case {'fontsize','fontsizes','fontscale'} %-Font scaling
%=======================================================================
% [FS,sf] = spm('FontSize',FS)
% [FS,sf] = spm('FontSizes',FS)
% sf = spm('FontScale')
if nargin<3, c=0; else, c=1; end
if nargin<2, FS=[1:36]; else, FS=varargin{2}; end
sf = 1 + 0.85*(min(spm('WinScale'))-1);
if strcmp(lower(Action),'fontscale')
varargout = {sf};
else
varargout = {floor(FS*sf),sf};
end
%=======================================================================
case 'winsize' %-Standard SPM window locations and sizes
%=======================================================================
% Rect = spm('WinSize',Win,raw)
if nargin<3, raw=0; else, raw=1; end
if nargin<2, Win=''; else, Win=varargin{2}; end
Rect = [ [108 429 400 445];...
[108 008 400 395];...
[515 008 600 865] ];
WS = spm('WinScale');
if isempty(Win)
WS = ones(3,1)*WS;
elseif upper(Win(1))=='M'
%-Menu window
Rect = Rect(1,:);
elseif upper(Win(1))=='I'
%-Interactive window
Rect = Rect(2,:);
elseif upper(Win(1))=='G'
%-Graphics window
Rect = Rect(3,:);
elseif Win(1)=='0'
%-Root workspace
Rect = get(0,'ScreenSize');
else
error('Unknown Win type');
end
if ~raw, Rect = Rect.*WS; end
varargout = {Rect};
%=======================================================================
case 'dir' %-Identify specific (SPM) directory
%=======================================================================
% spm('Dir',Mfile)
%-----------------------------------------------------------------------
if nargin<2, Mfile='spm'; else, Mfile=varargin{2}; end
SPMdir = which(Mfile);
if isempty(SPMdir) %-Not found or full pathname given
if exist(Mfile,'file')==2 %-Full pathname
SPMdir = Mfile;
else
error(['Can''t find ',Mfile,' on MATLABPATH']);
end
end
varargout = {spm_str_manip(SPMdir,'H')};
%=======================================================================
case 'ver' %-SPM version
%=======================================================================
% SPMver = spm('Ver',Mfile,ReDo,Cache,Con)
if nargin<5, Con=[]; else, Con=varargin{5}; end
if isempty(Con), Con=1; end
if nargin<4, Cache=[]; else, Cache=varargin{4}; end
if isempty(Cache), Cache=1; end
if nargin<3, ReDo=[]; else, ReDo=varargin{3}; end
if isempty(ReDo), ReDo=0; end
if nargin<2, Mfile=''; else, Mfile=varargin{2}; end
if isempty(Mfile), Mfile='spm'; end
xVname = [upper(spm_str_manip(Mfile,'rt')),'_VER'];
%-See if version info exists in global variable
%-----------------------------------------------------------------------
xV = spm('GetGlobal',xVname);
if ~ReDo & ~isempty(xV)
if isstruct(xV) & isfield(xV,'v') & isfield(xV,'c')
varargout = {xV.v,xV.c};
return
end
end
%-Work version out from file
%-----------------------------------------------------------------------
if Con
Vfile = fullfile(spm('Dir',Mfile),'Contents.m');
skip = 0; %-Don't skip first line
else
Vfile = which(Mfile);