-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbst_get.m
4056 lines (3826 loc) · 190 KB
/
bst_get.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 [argout1, argout2, argout3, argout4, argout5] = bst_get( varargin )
% BST_GET: Get a Brainstorm structure.
% This function is used to abstract the way that these structures are stored.
%
% USAGE :
% ====== DIRECTORIES ==================================================================
% - bst_get('UserDir') : User home directory
% - bst_get('BrainstormHomeDir') : Application directory of brainstorm
% - bst_get('BrainstormUserDir') : User home directory for brainstorm (<home>/.brainstorm/)
% - bst_get('BrainstormTmpDir') : User brainstorm temporary directory (Default: <home>/.brainstorm/tmp/)
% - bst_get('BrainstormTmpDir', isForcedDefault) : User DEFAULT brainstorm temporary directory (<home>/.brainstorm/tmp/)
% - bst_get('BrainstormDocDir') : Doc folder folder of the Brainstorm distribution (may vary in compiled versions)
% - bst_get('BrainstormDefaultsDir') : Defaults folder folder of the Brainstorm distribution (may vary in compiled versions)
% - bst_get('UserReportsDir') : User reports directory (<home>/.brainstorm/reports/)
% - bst_get('UserMexDir') : User temporary directory (<home>/.brainstorm/mex/)
% - bst_get('UserProcessDir') : User custom processes directory (<home>/.brainstorm/process/)
% - bst_get('UserDefaultsDir') : User defaults directory (<home>/.brainstorm/defaults/)
% - bst_get('BrainstormDbFile') : User brainstorm.mat file (<home>/.brainstorm/brainstorm.mat)
% - bst_get('BrainstormDbDir') : User database directory (contains all the brainstorm protocols)
% - bst_get('DirDefaultSubject') : Directory name of the default subject
% - bst_get('DirDefaultStudy') : Directory name of the default study for each subject
% - bst_get('DirAnalysisInter') : Directory name of the inter-subject analysis study
% - bst_get('DirAnalysisIntra') : Directory name of the intra-subject analysis study (for each subject)
% - bst_get('AnatomyDefaults') : Get the contents of directory bstDir/defaults/anatomy
% - bst_get('MniAtlasDefaults') : Get the contents of directory bstDir/defaults/mniatlas
% - bst_get('EegDefaults') : Get the contents of directory bstDir/defaults/eeg
% - bst_get('LastUsedDirs') : Structure with all the last used directories (last used)
% - bst_get('OsType', isMatlab=1) : Get a string that describes the operating system (if isMatlab=1 return the Matlab/JVM platform, else return the real host system)
% - bst_get('FileFilters', DataType) : Get the list of import filters for a specific data type
% - bst_get('FieldTripDir') : Full path to a local installation of FieldTrip
% - bst_get('SpmDir') : Full path to a local installation of SPM
% - bst_get('BrainSuiteDir') : Full path to a local installation of BrainSuite
% - bst_get('SpmTpmAtlas') : Full path to the SPM atlas TPM.nii
% - bst_get('PythonExe') : Path to the python executable
%
% ====== PROTOCOLS ====================================================================
% - bst_get('iProtocol') : Indice of current protocol
% - bst_get('Protocol', ProtocolName): Return the indice of the protocol ProtocolName, or [] if it doesn't exist
% - bst_get('ProtocolInfo') : Definition structure for current protocol
% - bst_get('ProtocolSubjects') : Subjects list for current protocol
% - bst_get('ProtocolStudies') : Studies list for current protocol
% - bst_get('isProtocolLoaded') : 1 if the protocol has been loaded, 0 else
% - bst_get('isProtocolModified') : 1 if the protocol has been modified, 0 else
%
% ====== STUDIES ======================================================================
% - bst_get('Study', StudyFileName) : Get one study in current protocol with its file name
% - bst_get('Study', iStudies) : Get one or more studies
% - bst_get('Study') : Get current study in current protocol
% - bst_get('StudyCount') : Get number of studies in the current protocol
% - bst_get('StudyWithSubject', SubjectFile) : Find studies associated with a given subject file (WITHOUT the system studies ('intra_subject', 'default_study'))
% - bst_get('StudyWithSubject', ..., 'intra_subject') : Find studies ... INCLUDING 'intra_subject' study
% - bst_get('StudyWithSubject', ..., 'default_study') : Find studies ... INCLUDING 'default_study' study
% - bst_get('StudyWithCondition', ConditionPath) : Find studies for a given condition path
% - bst_get('ChannelStudiesWithSubject', iSubjects) : Get all the studies where there should be a channel file for a list of subjects
% - bst_get('AnalysisIntraStudy', iSubject) : Get the default analysis study for target subject
% - bst_get('AnalysisInterStudy') : Get the default analysis study for inter-subject analysis
% - bst_get('DefaultStudy', iSubject) : Get the default study for target subject (by subject indice)
% - bst_get('DefaultStudy') : Get the global default study (common to all subjects)
% - bst_get('DefaultStudy', SubjectFile) : Get the default study for target subject (by filename)
% - bst_get('ChannelFile', ChannelFile) : Find a channel file in current protocol
% - bst_get('ChannelFileForStudy', StudyFile/DataFile) : Find a channel file in current protocol
% - bst_get('ChannelForStudy', iStudies) : Return current Channel struct for target study
% - bst_get('ChannelModalities', ChannelFile) : Return displayable modalities for a Channel file
% - bst_get('ChannelModalities', DataFile) : Return displayable modalities for a Data/Results/Timefreq... file
% - bst_get('ChannelDevice', ChannelFile) : Return acquisistion device for a channel file
% - bst_get('TimefreqDisplayModalities', TfFile) : Get displayable modalities for a TF file based on recordings
% - bst_get('HeadModelForStudy', iStudy) : Return current HeadModel struct for target study
% - bst_get('HeadModelFile', HeadModelFile) : Find a HeadModel file in current protocol
% - bst_get('HeadModelFile', HeadModelFile, iStudies): Find a HeadModel file in current protocol
% - bst_get('NoiseCovFile', NoiseCovFile) : Find a noise covariance file file in current protocol
% - bst_get('NoiseCovFile', NoiseCovFile, iStudies) : Find a noise covariance file in current protocol
% - bst_get('NoiseCovFile', DataCovFile) : Find a data covariance file file in current protocol
% - bst_get('NoiseCovFile', DataCovFile, iStudies) : Find a data covariance file file in current protocol
% - bst_get('DataFile', DataFile) : Find a DataFile in current protocol
% - bst_get('DataFile', DataFile, iStudies) : Find a DataFile in current protocol
% - bst_get('DataForDataList', iStudy, DataListName) : Find all the DataFiles grouped by a data list
% - bst_get('DataForStudy', iStudy) : Find all the Data files that are dependent on the channel/headmodel of a given study
% - bst_get('DataForStudies', iStudies)
% - bst_get('DataForChannelFile', ChannelFile) : Find all the DataFiles that use the given ChannelFile
% - bst_get('ResultsFile', ResultsFile) : Find a ResultsFile in current protocol
% - bst_get('ResultsFile', ResultsFile, iStudies) : Find a ResultsFile in input studies
% - bst_get('ResultsForDataFile', DataFile, iStudies): Find all results computed based on DataFile
% - bst_get('StatFile', StatFile) : Find a StatFile in current protocol
% - bst_get('StatFile', StatFile, iStudies) : Find a StatFile in input studies
% - bst_get('StatForDataFile', DataFile, iStudies)
% - bst_get('StatForDataFile', DataFile)
% - bst_get('TimefreqFile', TimefreqFile)
% - bst_get('TimefreqFile', TimefreqFile, iStudies)
% - bst_get('TimefreqForFile', FileName, iStudies) : Find all timefreq files computed based on target file
% - bst_get('TimefreqForKernel', KernelFile)
% - bst_get('DipolesFile', DipolesFile)
% - bst_get('DipolesFile', DipolesFile, iStudies)
% - bst_get('DipolesForFile', FileName, iStudies) : Find all dipoles files computed based on target file
% - bst_get('DipolesForKernel', KernelFile)
% - bst_get('MatrixFile', MatrixFile)
% - bst_get('MatrixFile', MatrixFile, iStudies)
% - bst_get('MatrixForMatrixList', iStudy, MatrixListName)
% - bst_get('AnyFile', AnyFile)
% - bst_get('AnyFile', AnyFile, iStudies)
% - bst_get('RelatedDataFile', FileName)
% - bst_get('RelatedDataFile', FileName, iStudies)
% - bst_get('GetFilenames')
%
% ====== SUBJECTS ======================================================================
% - bst_get('Subject', SubjectFileName, isRaw) : Find a subject in current protocol with its file name
% - bst_get('Subject', SubjectName, isRaw) : Find a subject in current protocol with its name
% - bst_get('Subject', iSubject) : Get a subject (normal or default if iSubject==0)
% - bst_get('Subject') : Get current subject in current protocol
% - bst_get('SubjectCount') : Get number of studies in the current protocol
% - bst_get('NormalizedSubjectName') : Name of the subject with a normalized anatomy
% - bst_get('NormalizedSubject') : Get groupd analysis subject for the current protocol
% - bst_get('ConditionsForSubject', SubjectFile) : Find all conditions for a given subject
% - bst_get('SurfaceFile', SurfaceFile) : Find a surface in current protocol
% - bst_get('SurfaceFileByType', iSubject, SurfaceType) : Find surfaces with given type for subject #i (default only)
% - bst_get('SurfaceFileByType', SubjectFile, SurfaceType) : Find surfaces with given type for subject SubjectFile (default only)
% - bst_get('SurfaceFileByType', SurfaceName, SurfaceType) : Find surfaces with given type for subject that also has surface SurfaceName (default only)
% - bst_get('SurfaceFileByType', MriName, SurfaceType) : Find surfaces with given type for subject that also has MRI MriName (default only)
% - bst_get('SurfaceFileByType', ..., ..., isDefaultOnly) : If 0, return all the surfaces of the given type, instead of only the default surface
% - bst_get('MriFile', MriFile) : Find a MRI in current protocol
%
% ====== GUI =================================================================
% - bst_get('BstControls') : Return main Brainstorm GUI structure
% - bst_get('BstFrame') : Return main Brainstorm JFrame
% - bst_get('isGUI') : Return 1 if the Brainstorm interface is displayed
% - bst_get('GuiLevel') : Return GUI level: -1=server, 0=nogui, 1=normal, 2=autopilot
% - bst_get('ScreenDef') : Get screens configuration
% - bst_get('DecorationSize') : Get dimensions of the windows decorations
% - bst_get('Layout') : Configuration of the main Brainstorm window
% - bst_get('Layout', prop) : Get one property in the layout properties
% - bst_get('PanelContainer') : Display list of registered panel containers
% - bst_get('PanelContainer', ContainerName) : Get a panel container handle
% - bst_get('Panel') : Display list of registered panels
% - bst_get('Panel', PanelName) : Find a panel with its name
% - bst_get('PanelControls', PanelName) : Get the controls of a panel
% - bst_get('Clipboard') : Nodes that were copied from the interface
% - bst_get('FigFont') : Standard font size displayed in the figures
% - bst_get('Font') : Create a Java font, scaled for the operating system
%
% ====== CONFIGURATION =================================================================
% - bst_get('Version') : Brainstorm version
% - bst_get('MatlabVersion') : Matlab version (version number * 100, eg. 801)
% - bst_get('MatlabReleaseName') : Matlab version (release name, eg. "R2014a")
% - bst_get('JavaVersion') : Java version
% - bst_get('isJavacomponent') : Returns 1 if javacomponent is available (Matlab < 2019b), 0 otherwise
% - bst_get('SystemMemory') : Amount of memory available, in Mb
% - bst_get('ByteOrder') : {'l','b'} - Byte order used to read and save binary files
% - bst_get('TSDisplayMode') : {'butterfly','column'}
% - bst_get('ElectrodeConfig', Modality) : Structure describing the current display values for SEEG/ECOG/EEG contacts
% - bst_get('AutoUpdates') : {0,1} - If 1, check automatically for updates at startup
% - bst_get('ForceMatCompression') : {0,1} - If 1, always save mat-files using the v7 format instead of v6
% - bst_get('IgnoreMemoryWarnings') : {0,1} - If 1, do not display memory warnings at the Brainstorm startup
% - bst_get('ExpertMode') : {0,1} - If 1, show advanced options that regular user do not see
% - bst_get('DisplayGFP') : {0,1} - If 1, the GFP is displayed on all the time series figures
% - bst_get('DownsampleTimeSeries') : {0,1,...} - If > 0, downsample dense time series for faster display
% - bst_get('DisableOpenGL') : {0,1,2} - If 1, do not use OpenGL renderer; if 2, use software OpenGL
% - bst_get('InterfaceScaling') : {100,125,150,...} - Scales the Brainstorm GUI by a fixed factor
% - bst_get('GraphicsSmoothing') : {0,1} - If 1, uses the graphics smoothing (Matlab >= 2014b)
% - bst_get('SystemCopy') : {0,1} - If 1, uses the system calls mv/cp instead of movefile/copyfile (Linux only)
% - bst_get('JOGLVersion') : {0,1,2}, Detect the current version of JOGL available in Matlab
% - bst_get('DefaultFormats') : Default formats for importing/exporting data, channels, ... (last used)
% - bst_get('BFSProperties') : Conductivities and thicknesses for 3-shell spherical forward model
% - bst_get('ImportDataOptions') : Import options for recordings
% - bst_get('ImportEegRawOptions') : Importation options for RAW EEG format
% - bst_get('BugReportOptions') : Bug reporter options
% - bst_get('DefaultSurfaceDisplay') : Default display options for surfaces (smooth, data threshold, sulci map)
% - bst_get('MagneticExtrapOptions') : Structure with the options for magnetic field extrapolation
% - bst_get('DefaultFreqBands')
% - bst_get('TimefreqOptions_morlet')
% - bst_get('TimefreqOptions_fft')
% - bst_get('TimefreqOptions_psd')
% - bst_get('TimefreqOptions_hilbert')
% - bst_get('OpenMEEGOptions')
% - bst_get('DuneuroOptions')
% - bst_get('GridOptions_headmodel')
% - bst_get('GridOptions_dipfit')
% - bst_get('UniformizeTimeSeriesScales') : {0,1} - If 1, the Y-axis of all the time series figures have the scale
% - bst_get('FlipYAxis') : {0,1} - If 1, the recordings are displayed with the negative values UP
% - bst_get('AutoScaleY') : {0,1} - If 1, the axis limits are updated when the figure is updated
% - bst_get('ShowXGrid') : {0,1} - If 1, show the XGrid in the time series figures
% - bst_get('ShowYGrid') : {0,1} - If 1, show the YGrid in the time series figures
% - bst_get('ShowZeroLines') : {0,1} - If 1, show the Y=0 lines in the columns view
% - bst_get('ShowEventsMode') : {'dot','line','none'}
% - bst_get('Resolution') : [resX,resY] fixed resolutions for X and Y axes
% - bst_get('FixedScaleY', Modality) : Struct with the scales to impose on the recordings for the selected modality
% - bst_get('XScale', XScale) : {'log', 'linear'}
% - bst_get('YScale', YScale) : {'log', 'linear'}
% - bst_get('UseSigProcToolbox') : Use Matlab's Signal Processing Toolbox when available
% - bst_get('RawViewerOptions', sFile) : Display options for RAW recordings, adapt for specific file
% - bst_get('RawViewerOptions') : Display options for RAW recordings
% - bst_get('TopoLayoutOptions') : Display options for 2DLayout display
% - bst_get('StatThreshOptions') : Options for online statistical thresholding
% - bst_get('ContactSheetOptions') : Display options for contact sheets
% - bst_get('ProcessOptions') : Options related with the data processing
% - bst_get('CustomColormaps') : Gets the list of user defined colormaps
% - bst_get('MriOptions') : Configuration for MRI display
% - bst_get('DigitizeOptions') : Digitizer options
% - bst_get('ReadOnly') : Read only interface
% - bst_get('NodelistOptions') : Structure with the options for file selection in the Process1 and Process2 panels
% - bst_get('ResizeFunction') : Get the appropriate resize function
% - bst_get('groot') : Get the root graphic object
% - bst_get('JFrame', hFig) : Get the underlying java frame for a Matlab figure
% - bst_get('LastPsdDisplayFunction') : Display option of measure for spectrum (log, power, magnitude, etc.)
% - bst_get('PlotlyCredentials') : Get the credentials and URL to connect to plot.ly server
% - bst_get('MffJarFile') : Get the path to the MFF JAR file and whether it exists
% - bst_get('ExportBidsOptions') : Additional metadata for BIDS export
%
% SEE ALSO bst_set
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
%
% Copyright (c)2000-2020 University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2008-2021
% Martin Cousineau, 2017
%% ==== PARSE INPUTS ====
global GlobalData;
if ((nargin >= 1) && ischar(varargin{1}))
contextName = varargin{1};
else
return
end
% Initialize returned variable
argout1 = [];
argout2 = [];
argout3 = [];
argout4 = [];
argout5 = [];
% Get required context structure
switch contextName
%% ==== SUBFUNCTIONS =====
case 'findFileInStudies'
[argout1, argout2, argout3] = findFileInStudies(varargin{2:end});
%% ==== BRAINSTORM CONFIGURATION ====
case 'Version'
argout1 = GlobalData.Program.Version;
case 'MatlabVersion'
if ~exist('version','builtin')
Version = 601;
else
% Get version number
str_vers = version();
vers = sscanf(str_vers, '%d.%d%*s');
if isempty(vers) || any(~isnumeric(vers)) || any(isnan(vers))
vers = 0;
end
Version = 100 * vers(1) + vers(2);
% Get release name
ipar = [find(str_vers == '('), find(str_vers == ')')];
end
argout1 = Version;
case 'MatlabReleaseName'
if ~exist('version','builtin')
Release = 'Matlab6';
else
% Get version number
str_vers = version();
% Get release name
ipar = [find(str_vers == '('), find(str_vers == ')')];
Release = str_vers(ipar(1)+1:ipar(2)-1);
end
argout1 = Release;
case 'JavaVersion'
strver = char(java.lang.System.getProperty('java.version'));
iDot = find(strver == '.');
if (length(iDot) < 2)
argout1 = str2num(strver);
else
argout1 = str2num(strver(1:iDot(2)-1));
end
case 'isJavacomponent'
% After Matlab 2019b, javacomponent() and JavaFrame property have been deprecated
argout1 = (bst_get('MatlabVersion') <= 906);
case 'SystemMemory'
maxvar = [];
totalmem = [];
if ispc && (bst_get('MatlabVersion') >= 706)
try
% Get memory info
usermem = memory();
maxvar = round(usermem.MaxPossibleArrayBytes / 1024 / 1024);
totalmem = round(usermem.MemAvailableAllArrays / 1024 / 1024);
catch
% Whatever...
end
end
argout1 = maxvar;
argout2 = totalmem;
case 'BrainstormHomeDir'
argout1 = GlobalData.Program.BrainstormHomeDir;
case 'BrainstormDbDir'
argout1 = GlobalData.DataBase.BrainstormDbDir;
case 'UserDir'
try
if ispc
userDir = getenv('USERPROFILE');
else
userDir = char(java.lang.System.getProperty('user.home'));
end
catch
userDir = '';
end
if isempty(userDir)
userDir = bst_get('BrainstormHomeDir');
end
argout1 = userDir;
case 'BrainstormUserDir'
bstUserDir = bst_fullfile(bst_get('UserDir'), '.brainstorm');
if ~isdir(bstUserDir)
res = mkdir(bstUserDir);
if ~res
error(['Cannot create Brainstorm user directory: "' bstUserDir '".']);
end
end
argout1 = bstUserDir;
case 'BrainstormTmpDir'
tmpDir = '';
isForcedDefault = ((nargin >= 2) && varargin{2});
% Default folder: userdir/tmp
defDir = bst_fullfile(bst_get('BrainstormUserDir'), 'tmp');
% If temporary directory is set in the preferences
if ~isForcedDefault && isfield(GlobalData, 'Preferences') && isfield(GlobalData.Preferences, 'BrainstormTmpDir')
tmpDir = GlobalData.Preferences.BrainstormTmpDir;
end
% Else: use directory userdir/tmp
if isempty(tmpDir)
tmpDir = defDir;
end
% Create directory if it does not exist yet
if ~isdir(tmpDir)
res = mkdir(tmpDir);
if ~res && ~strcmp(tmpDir, defDir)
disp(['BST> Cannot create Brainstorm temporary directory: "' tmpDir '".']);
disp(['BST> Using default directory instead: "' defDir '".']);
% Create temporary folder
tmpDir = defDir;
if ~isdir(tmpDir)
res = mkdir(tmpDir);
else
res = 1;
end
end
% Error: cannot create any temporary folder
if ~res
error(['Cannot create Brainstorm temporary directory: "' tmpDir '".']);
end
end
argout1 = tmpDir;
case 'BrainstormDocDir'
docDir = bst_fullfile(GlobalData.Program.BrainstormHomeDir, 'doc');
if ~exist(docDir, 'file')
% Matlab compiler >= 2018b stores 'doc' under 'bst_javabuil'
docDir = bst_fullfile(GlobalData.Program.BrainstormHomeDir, 'bst_javabuil', 'doc');
if ~exist(docDir, 'file')
docDir = '';
disp('BST> Could not find "doc" folder.');
disp(['BST> BrainstormHomeDir = ' GlobalData.Program.BrainstormHomeDir]);
end
end
argout1 = docDir;
case 'BrainstormDefaultsDir'
defaultsDir = bst_fullfile(GlobalData.Program.BrainstormHomeDir, 'defaults');
if ~exist(defaultsDir, 'file')
% Matlab compiler >= 2018b stores 'defaults' under 'bst_javabuil'
defaultsDir = bst_fullfile(GlobalData.Program.BrainstormHomeDir, 'bst_javabuil', 'defaults');
if ~exist(defaultsDir, 'file')
defaultsDir = '';
disp('BST> Could not find "defaults" folder.');
disp(['BST> BrainstormHomeDir = ' GlobalData.Program.BrainstormHomeDir]);
end
end
argout1 = defaultsDir;
case 'UserReportsDir'
reportDir = bst_fullfile(bst_get('BrainstormUserDir'), 'reports');
if ~isdir(reportDir)
res = mkdir(reportDir);
if ~res
error(['Cannot create user reports directory: "' reportDir '".']);
end
end
argout1 = reportDir;
case 'UserMexDir'
mexDir = bst_fullfile(bst_get('BrainstormUserDir'), 'mex');
if ~isdir(mexDir)
res = mkdir(mexDir);
if ~res
error(['Cannot create Brainstorm mex-files directory: "' mexDir '".']);
end
end
argout1 = mexDir;
case 'UserProcessDir'
processDir = bst_fullfile(bst_get('BrainstormUserDir'), 'process');
if ~isdir(processDir)
res = mkdir(processDir);
if ~res
error(['Cannot create Brainstorm custom processes directory: "' processDir '".']);
end
end
argout1 = processDir;
case 'UserDefaultsDir'
defDir = bst_fullfile(bst_get('BrainstormUserDir'), 'defaults');
defDirAnat = bst_fullfile(defDir, 'anatomy');
defDirEeg = bst_fullfile(defDir, 'eeg');
if ~isdir(defDir)
res = mkdir(defDir);
if ~res
error(['Cannot create user templates directory: "' defDir '".']);
end
end
if ~isdir(defDirAnat)
res = mkdir(defDirAnat);
if ~res
error(['Cannot create user templates directory: "' defDirAnat '".']);
end
end
if ~isdir(defDirEeg)
res = mkdir(defDirEeg);
if ~res
error(['Cannot create user templates directory: "' defDirEeg '".']);
end
end
argout1 = defDir;
case 'BrainstormDbFile'
argout1 = bst_fullfile(bst_get('BrainstormUserDir'), 'brainstorm.mat');
%% ==== PROTOCOL ====
case 'iProtocol'
if isempty(GlobalData.DataBase.iProtocol)
argout1 = 0;
else
argout1 = GlobalData.DataBase.iProtocol;
end
case 'Protocol'
if ~isempty(GlobalData.DataBase.ProtocolInfo)
argout1 = find(strcmpi({GlobalData.DataBase.ProtocolInfo.Comment}, varargin{2}));
else
argout1 = [];
end
case {'ProtocolInfo', 'ProtocolSubjects', 'ProtocolStudies', 'isProtocolLoaded', 'isProtocolModified'}
argout2 = GlobalData.DataBase.iProtocol;
% No protocol: return empty matrix
if isempty(argout2) || ~isnumeric(argout2) || argout2 == 0
return;
end
% Check index integrity
if ((argout2 <= 0) || (argout2 > length(GlobalData.DataBase.ProtocolInfo))), warning('Brainstorm:InvalidIndex', 'Invalid index'), return, end
% Get requested protocol structure
argout1 = GlobalData.DataBase.(contextName)(argout2);
%% ==== STUDY ====
% Usage: [sStudy, iStudy] = bst_get('Study', StudyFileName)
% [sStudy, iStudy] = bst_get('Study')
% [sStudy, iStudy] = bst_get('Study', iStudies)
case 'Study'
if isempty(GlobalData.DataBase.iProtocol) || (GlobalData.DataBase.iProtocol == 0)
return;
end
% Get list of current protocols
ProtocolInfo = GlobalData.DataBase.ProtocolInfo(GlobalData.DataBase.iProtocol);
ProtocolStudies = GlobalData.DataBase.ProtocolStudies(GlobalData.DataBase.iProtocol);
% Get list of current protocol studies
if isempty(ProtocolStudies) || isempty(ProtocolInfo)
return;
end
% ===== PARSE INPUTS =====
if (nargin < 2)
% Call: bst_get('Study');
iStudies = ProtocolInfo.iStudy;
StudyFileName = [];
elseif (isnumeric(varargin{2}))
iStudies = varargin{2};
StudyFileName = [];
elseif (ischar(varargin{2}))
iStudies = [];
StudyFileName = strrep(varargin{2}, ProtocolInfo.STUDIES, '');
end
% Indices
iAnalysisStudy = -2; % CANNOT USE -1 => DISABLES SEARCH FUNCTIONS
iDefaultStudy = -3;
% Indices > 0: normal studies indiced in ProtocolStudies.Study array
% ===== GET STUDY BY INDEX =====
% Call: bst_get('Study', iStudies);
if ~isempty(iStudies)
argout1 = repmat(ProtocolStudies.DefaultStudy, 0);
% Get analysis study
iTargetAnalysis = find(iStudies == iAnalysisStudy);
if ~isempty(iTargetAnalysis)
argout1(iTargetAnalysis) = repmat(ProtocolStudies.AnalysisStudy, size(iTargetAnalysis));
argout2(iTargetAnalysis) = repmat(iAnalysisStudy, size(iTargetAnalysis));
end
% Get default study
iTargetDefault = find(iStudies == iDefaultStudy);
if ~isempty(iTargetDefault)
argout1(iTargetDefault) = repmat(ProtocolStudies.DefaultStudy, size(iTargetDefault));
argout2(iTargetDefault) = repmat(iDefaultStudy, size(iTargetDefault));
end
% Get normal studies
iTargetNormal = find((iStudies >= 1) & (iStudies <= length(ProtocolStudies.Study)));
if ~isempty(iTargetNormal)
argout1(iTargetNormal) = ProtocolStudies.Study(iStudies(iTargetNormal));
argout2(iTargetNormal) = iStudies(iTargetNormal);
end
% Error
if isempty(argout1)
GlobalData.DataBase.ProtocolInfo(GlobalData.DataBase.iProtocol).iStudy = [];
end
% ===== GET STUDY BY FILENAME =====
% Call: bst_get('Study', StudyFileName);
elseif ~isempty(StudyFileName)
% NORMAL STUDY
iStudy = find(file_compare({ProtocolStudies.Study.FileName}, StudyFileName), 1);
% If a study is found : return it
if ~isempty(iStudy)
argout1 = ProtocolStudies.Study(iStudy);
argout2 = iStudy;
% DEFAULT STUDY
elseif ~isempty(ProtocolStudies.DefaultStudy) && file_compare({ProtocolStudies.DefaultStudy.FileName}, StudyFileName)
argout1 = ProtocolStudies.DefaultStudy;
argout2 = iDefaultStudy;
% ANALYSIS STUDY
elseif ~isempty(ProtocolStudies.AnalysisStudy) && file_compare({ProtocolStudies.AnalysisStudy.FileName}, StudyFileName)
argout1 = ProtocolStudies.AnalysisStudy;
argout2 = iAnalysisStudy;
end
else
return
end
%% ==== STUDY WITH SUBJECT FILE ====
% Usage : [sStudies, iStudies] = bst_get('StudyWithSubject', SubjectFile) : WITHOUT the system studies ('intra_subject', 'default_study')
% [sStudies, iStudies] = bst_get(..., 'intra_subject', 'default_study') : WITH the system studies: 'intra_subject' | 'default_study'
case 'StudyWithSubject'
% Parse inputs
if (nargin < 2) || ~ischar(varargin{2})
error('Invalid call to bst_get()');
end
if (nargin > 2)
IntraStudies = any(strcmpi(varargin(3:end), 'intra_subject'));
DefaultStudies = any(strcmpi(varargin(3:end), 'default_study'));
else
IntraStudies = 0;
DefaultStudies = 0;
end
SubjectFile = {varargin{2}};
if isempty(GlobalData.DataBase.iProtocol) || (GlobalData.DataBase.iProtocol == 0)
return;
end
% Get list of current protocol description
ProtocolInfo = GlobalData.DataBase.ProtocolInfo(GlobalData.DataBase.iProtocol);
ProtocolStudies = GlobalData.DataBase.ProtocolStudies(GlobalData.DataBase.iProtocol);
if isempty(ProtocolStudies) || isempty(ProtocolInfo)
return;
end
% Get default subject
sDefaultSubject = bst_get('Subject', 0);
% If SubjectFile is the default subject filename
if ~isempty(sDefaultSubject) && ~isempty(sDefaultSubject.FileName) && file_compare( SubjectFile{1}, sDefaultSubject.FileName)
% Get all the subjects files that use default anatomy
ProtocolSubjects = GlobalData.DataBase.ProtocolSubjects(GlobalData.DataBase.iProtocol);
iSubjectUseDefaultAnat = find([ProtocolSubjects.Subject.UseDefaultAnat]);
if isempty(iSubjectUseDefaultAnat)
return
end
SubjectFile = {ProtocolSubjects.Subject(iSubjectUseDefaultAnat).FileName};
% Also updates inter-subject node
isInterSubject = 1;
else
isInterSubject = 0;
end
% Search all the current protocol's studies
iStudies = [];
for i=1:length(SubjectFile)
iStudies = [iStudies, find(file_compare({ProtocolStudies.Study.BrainStormSubject}, SubjectFile{i}))];
end
% Return results
if ~isempty(iStudies)
% Remove "analysis_intra" and "default_study" studies from list
if ~IntraStudies
iStudies(strcmpi({ProtocolStudies.Study(iStudies).Name}, bst_get('DirAnalysisIntra'))) = [];
end
if ~DefaultStudies
iStudies(strcmpi({ProtocolStudies.Study(iStudies).Name}, bst_get('DirDefaultStudy'))) = [];
end
% Return studies
argout1 = ProtocolStudies.Study(iStudies);
argout2 = iStudies;
else
argout1 = repmat(db_template('Study'), 0);
argout2 = [];
end
% Add inter-subject node, if needed
if isInterSubject
[sInterStudy, iInterStudy] = bst_get('AnalysisInterStudy');
argout1 = [argout1, sInterStudy];
argout2 = [argout2, iInterStudy];
end
%% ==== STUDY WITH CONDITION PATH ====
% USAGE: [sStudies, iStudies] = bst_get('StudyWithCondition', ConditionPath)
%
% INPUT: ConditionPath
% - 'SubjectName/conditionName' : Target condition for the specified subject
% - 'SubjectName/@intra' : Intra-subject condition for the subject
% - 'SubjectName/@default_study' : Default condition for the subject (where the subject's shared files are stored)
% - '*/conditionName' : Target condition for all the subjects
% - '@inter' : Inter-subject condition
% - '@default_study' : Protocol's default condition (where the protocol's shared files are stored)
case 'StudyWithCondition'
% Parse inputs
if (nargin ~= 2) || ~ischar(varargin{2})
error('Invalid call to bst_get()');
end
ConditionPath = varargin{2};
% Get list of current protocol description
ProtocolInfo = GlobalData.DataBase.ProtocolInfo(GlobalData.DataBase.iProtocol);
ProtocolStudies = GlobalData.DataBase.ProtocolStudies(GlobalData.DataBase.iProtocol);
if isempty(ProtocolStudies) || isempty(ProtocolInfo)
return;
end
% ConditionPath = @inter
if strcmpi(ConditionPath, '@inter')
iStudy = -2;
argout2 = iStudy;
argout1 = bst_get('Study', iStudy);
% ConditionPath = @default_study
elseif strcmpi(ConditionPath, '@default_study')
iStudy = -3;
argout2 = iStudy;
argout1 = bst_get('Study', iStudy);
% ConditionPath = SubjectName/ConditionName
else
% Get subject and condition names
condSplit = str_split(ConditionPath);
if (length(condSplit) ~= 2)
error('Invalid condition path.');
end
SubjectName = condSplit{1};
ConditionName = condSplit{2};
% If first element is '*', search for condition in all the studies
if (SubjectName(1) == '*')
iStudies = 1:length(ProtocolStudies.Study);
% Else : search for condition only in studies that are linked to the subject specified in the ConditionPath
else
% Get subject
sSubject = bst_get('Subject', SubjectName, 1);
if isempty(sSubject)
return;
end
iStudies = find(file_compare({ProtocolStudies.Study.BrainStormSubject}, sSubject.FileName));
end
% Nothing to search
if isempty(iStudies)
return
end
% Search all the current protocol's studies
iStudies = iStudies(cellfun(@(c)isequal(ConditionName, c), [ProtocolStudies.Study(iStudies).Condition]));
% Return results
if ~isempty(iStudies)
% Remove "analysis_intra" and "default_study" studies from list
if ~strcmpi(ConditionName, '@intra')
iStudies(strcmpi({ProtocolStudies.Study(iStudies).Condition}, bst_get('DirAnalysisIntra'))) = [];
end
if ~strcmpi(ConditionName, '@default_study')
iStudies(strcmpi({ProtocolStudies.Study(iStudies).Condition}, bst_get('DirDefaultStudy'))) = [];
end
% Sort by subject
if (length(iStudies) > 1)
SubjNameList = cell(1,length(iStudies));
% For each study, get subject name
for i = 1:length(iStudies)
sSubject = bst_get('Subject', ProtocolStudies.Study(iStudies(i)).BrainStormSubject);
SubjNameList{i} = sSubject.Name;
end
% Sort subjects names
[sortSubjList, iSort] = sort(SubjNameList);
% Apply same sorting to studies
iStudies = iStudies(iSort);
end
% Return studies
argout1 = ProtocolStudies.Study(iStudies);
argout2 = iStudies;
else
argout1 = repmat(db_template('Study'), 0);
argout2 = [];
end
end
%% ==== CHANNEL STUDIES WITH SUBJECT ====
% Usage: iStudies = bst_get('ChannelStudiesWithSubject', iSubjects, 'NoIntra')
case 'ChannelStudiesWithSubject'
% Parse inputs
if (nargin >= 2) && isnumeric(varargin{2})
iSubjects = varargin{2};
else
error('Invalid call to bst_get()');
end
if (nargin == 3) && strcmpi(varargin{3}, 'NoIntra')
NoIntra = 1;
else
NoIntra = 0;
end
% Process all subjects
iStudies = [];
for i=1:length(iSubjects)
iSubject = iSubjects(i);
sSubject = bst_get('Subject', iSubject, 1);
% No subject: error
if isempty(sSubject)
continue
% If subject uses default channel file
elseif (sSubject.UseDefaultChannel ~= 0)
% Get default study for this subject
[tmp___, iStudiesNew] = bst_get('DefaultStudy', iSubject);
iStudies = [iStudies, iStudiesNew];
% Else: get all the studies belonging to this subject
else
if NoIntra
[tmp___, iStudiesNew] = bst_get('StudyWithSubject', sSubject.FileName);
else
[tmp___, iStudiesNew] = bst_get('StudyWithSubject', sSubject.FileName, 'intra_subject');
end
iStudies = [iStudies, iStudiesNew];
end
end
argout1 = iStudies;
%% ==== STUDIES COUNT ====
% Usage: [nbStudies] = bst_get('StudyCount')
case 'StudyCount'
% Nothing
if isempty(GlobalData.DataBase.iProtocol) || (GlobalData.DataBase.iProtocol == 0)
argout1 = 0;
return;
end
% Get list of current protocol studies
ProtocolStudies = GlobalData.DataBase.ProtocolStudies(GlobalData.DataBase.iProtocol);
argout1 = length(ProtocolStudies.Study);
%% ==== SUBJECTS COUNT ====
% Usage: [nbSubjects] = bst_get('SubjectCount')
case 'SubjectCount'
if isempty(GlobalData.DataBase.iProtocol) || (GlobalData.DataBase.iProtocol == 0)
argout1 = 0;
return;
end
% Get list of current protocol studies
ProtocolSubjects = GlobalData.DataBase.ProtocolSubjects(GlobalData.DataBase.iProtocol);
argout1 = length(ProtocolSubjects.Subject);
%% ==== NORMALIZED SUBJECT ====
case 'NormalizedSubject'
% Get normalized subject name
normSubjName = 'Group_analysis';
% Try to get normalized subject
[sNormSubj, iNormSubj] = bst_get('Subject', normSubjName, 0);
% If normalized subject does not exist: create it
if isempty(sNormSubj)
% Always use default anatomy
UseDefaultAnat = 1;
% If all the subjects use a global channel file: Use global default as well
if ~isempty(GlobalData.DataBase.ProtocolSubjects(GlobalData.DataBase.iProtocol).Subject) && ...
all([GlobalData.DataBase.ProtocolSubjects(GlobalData.DataBase.iProtocol).Subject.UseDefaultChannel] == 2)
UseDefaultChannel = 2;
else
UseDefaultChannel = 1;
end
% Create subject
[sNormSubj, iNormSubj] = db_add_subject(normSubjName, [], UseDefaultAnat, UseDefaultChannel);
% Get full subject structure
[sNormSubj, iNormSubj] = bst_get('Subject', normSubjName, 0);
end
argout1 = sNormSubj;
argout2 = iNormSubj;
%% ==== ANALYSIS STUDY (INTRA) ====
% Usage: [sAnalStudy, iAnalStudy] = bst_get('AnalysisIntraStudy', iSubject)
case 'AnalysisIntraStudy'
% Parse inputs
if (nargin == 2) && isnumeric(varargin{2})
iSubject = varargin{2};
else
error('Invalid call to bst_get()');
end
% Get subject
sSubject = bst_get('Subject', iSubject, 1);
% Get studies related to subject
[sSubjStudies, iSubjStudies] = bst_get('StudyWithSubject', sSubject.FileName, 'intra_subject');
% Look for the 'AnalysisIntra' study
iFound = find(cellfun(@(c)ismember(bst_get('DirAnalysisIntra'), c), {sSubjStudies.Condition}));
iAnalStudy = iSubjStudies(iFound);
sAnalStudy = sSubjStudies(iFound);
% Return found structure
argout1 = sAnalStudy;
argout2 = iAnalStudy;
%% ==== ANALYSIS STUDY (INTER) ====
% Usage: [sAnalStudyInter, iAnalStudyInter] = bst_get('AnalysisInterStudy')
case 'AnalysisInterStudy'
iAnalStudyInter = -2;
[argout1, argout2] = bst_get('Study', iAnalStudyInter);
%% ==== DEFAULT STUDY ====
% Usage: [sDefaulStudy, iDefaultStudy] = bst_get('DefaultStudy', iSubject)
% [sDefaulStudy, iDefaultStudy] = bst_get('DefaultStudy') : iSubject=0
% [sDefaulStudy, iDefaultStudy] = bst_get('DefaultStudy', SubjectFile)
case 'DefaultStudy'
if isempty(GlobalData.DataBase.iProtocol) || (GlobalData.DataBase.iProtocol == 0)
return;
end
% Parse inputs
if (nargin == 1)
iSubject = 0;
elseif (nargin == 2) && isnumeric(varargin{2})
iSubject = varargin{2};
elseif (nargin == 2) && ischar(varargin{2})
SubjectFile = varargin{2};
% Get subject attached to study
[sSubject, iSubject] = bst_get('Subject', SubjectFile, 1);
if isempty(sSubject) || ~sSubject.UseDefaultChannel
return;
end
else
error('Invalid call to bst_get()');
end
% === DEFAULT SUBJECT ===
% => Return global default study
if (iSubject == 0)
% Get protocol's studies
ProtocolStudies = GlobalData.DataBase.ProtocolStudies(GlobalData.DataBase.iProtocol);
% Return Global default study
argout1 = ProtocolStudies.DefaultStudy;
argout2 = -3;
% === NORMAL SUBJECT ===
else
% Get subject
sSubject = bst_get('Subject', iSubject, 1);
% === GLOBAL DEFAULT STUDY ===
if sSubject.UseDefaultChannel == 2
% Get protocol's studies
ProtocolStudies = GlobalData.DataBase.ProtocolStudies(GlobalData.DataBase.iProtocol);
% Return Global default study
argout1 = ProtocolStudies.DefaultStudy;
argout2 = -3;
% === SUBJECT'S DEFAULT STUDY ===
elseif sSubject.UseDefaultChannel == 1
% Get studies related to subject
[sSubjStudies, iSubjStudies] = bst_get('StudyWithSubject', sSubject.FileName, 'default_study');
% Look for the 'DefaultStudy' study
iFound = find(cellfun(@(c)ismember(bst_get('DirDefaultStudy'), c), {sSubjStudies.Condition}));
iDefaultStudy = iSubjStudies(iFound);
sDefaultStudy = sSubjStudies(iFound);
% Return found structure
argout1 = sDefaultStudy;
argout2 = iDefaultStudy;
end
end
%% ==== SUBJECT ====
% Usage : [sSubject, iSubject] = bst_get('Subject', iSubject, isRaw)
% [sSubject, iSubject] = bst_get('Subject', SubjectFileName, isRaw);
% [sSubject, iSubject] = bst_get('Subject', SubjectName, isRaw);
% [sSubject, iSubject] = bst_get('Subject');
% If isRaw is set: force to return the real brainstormsubject description
% (ignoring wether it uses protocol's default anatomy or not)
case 'Subject'
if isempty(GlobalData.DataBase.iProtocol) || (GlobalData.DataBase.iProtocol == 0)
return;
end
% Get list of current protocol subjects
ProtocolSubjects = GlobalData.DataBase.ProtocolSubjects(GlobalData.DataBase.iProtocol);
sSubject = [];
SubjectName = [];
SubjectFileName = [];
% ISRAW parameter
if (nargin < 3)
isRaw = 0;
else
isRaw = varargin{3};
end
% Call: bst_get('subject', iSubject, isRaw);
if (nargin >= 2) && isnumeric(varargin{2})
iSubject = varargin{2};
if (iSubject > length(ProtocolSubjects.Subject))
error('Invalid subject indice.');
end
% If required subject is default subject (iSubject = 0)
if (iSubject == 0)
% Default subject available
if ~isempty(ProtocolSubjects.DefaultSubject)
sSubject = ProtocolSubjects.DefaultSubject;
% Default subject not available
else
return
end
% Normal subject
else
sSubject = ProtocolSubjects.Subject(iSubject);
end
% Call: bst_get('subject', SubjectFileName, isRaw);
% Call: bst_get('subject', SubjectName, isRaw);
elseif (nargin >= 2) && isempty(varargin{2})
% If study name is empty: use DefaultSubject
SubjectFileName = ProtocolSubjects.DefaultSubject.FileName;
elseif (nargin >= 2) && (ischar(varargin{2}))
[fName, fBase, fExt] = bst_fileparts(varargin{2});
% Argument is a Matlab .mat filename
if strcmpi(fExt, '.mat')
SubjectFileName = varargin{2};
% Else : assume argument is a directory
else
SubjectName = file_standardize(varargin{2});
end
% Call: bst_get('subject'); => looking for current subject
elseif (nargin < 2)
% Get current subject filename in current study
sStudy = bst_get('Study');
if isempty(sStudy)
return
end
SubjectFileName = sStudy.BrainStormSubject;
% If study's subject is not defined, get DefaultSubject
if isempty(SubjectFileName) && ~isempty(ProtocolSubjects.DefaultSubject)
SubjectFileName = ProtocolSubjects.DefaultSubject.FileName;
end
else
error('Invalid call to bst_get()');
end
% If Subject is defined by its filename/name
if isempty(sSubject)
% Look in Default Subject
if ~isempty(ProtocolSubjects.DefaultSubject) && (file_compare(ProtocolSubjects.DefaultSubject.FileName, SubjectFileName) ...
|| strcmpi(ProtocolSubjects.DefaultSubject.Name, SubjectName))
sSubject = ProtocolSubjects.DefaultSubject;
iSubject = 0;
% If not found : find target subject file name in normal subjects
elseif ~isempty(SubjectFileName)
iSubject = find(file_compare({ProtocolSubjects.Subject.FileName}, SubjectFileName), 1);
sSubject = ProtocolSubjects.Subject(iSubject);
elseif ~isempty(SubjectName)
iSubject = find(file_compare({ProtocolSubjects.Subject.Name}, SubjectName), 1);
sSubject = ProtocolSubjects.Subject(iSubject);
else
error('Subject name not specified.');
end
end
% Return found subject
if ~isempty(iSubject) && ~isempty(sSubject)