a b/functions/adminfunc/pop_editoptions.m
1
% POP_EDITOPTIONS - Edit memory-saving EEGLAB options. These are stored in 
2
%                     a file 'eeg_options.m'. With no argument, pop up a window 
3
%                     to allow the user to set/unset these options. Store
4
%                     user choices in a new 'eeg_options.m' file in the 
5
%                     working directory.
6
%
7
% Usage: >> pop_editoptions;
8
%        >> pop_editoptions( 'key1', value1, 'key2', value2, ...);
9
%
10
% Graphic interface inputs:
11
%   "If set, keep at most one dataset in memory ..." - [checkbox] If set, EEGLAB will only retain the current
12
%                   dataset in memory. All other datasets will be automatically
13
%                   read and written to disk. All EEGLAB functionalities are preserved
14
%                   even for dataset stored on disk. 
15
%   "If set, write data in same file as dataset ..." - [checkbox] Set -> dataset data (EEG.data) are 
16
%                   saved in the EEG structure in the standard Matlab dataset (.set) file. 
17
%                   Unset -> The EEG.data are saved as a transposed stream of 32-bit 
18
%                   floats in a separate binary file. As of Matlab 4.51, the order 
19
%                   of the data in the binary file is as in the transpose of EEG.data 
20
%                   (i.e., as in EEG.data', frames by channels). This allows quick 
21
%                   reading of single channels from the data, e.g. when comparing 
22
%                   channels across datasets. The stored files have the extension 
23
%                   .dat instead of the pre-4.51, non-transposed .fdt. Both file types 
24
%                   are read by the dataset load function. Command line equivalent is
25
%                   option_savematlab.
26
%   "Precompute ICA activations" - [checkbox] If set, all the ICA activation
27
%                   time courses are precomputed (this requires more RAM). 
28
%                   Command line equivalent: option_computeica.
29
%   "If set, remember old folder when reading dataset" - [checkbox] this option
30
%                   is convenient if the file you are working on are not in the 
31
%                   current folder.
32
%
33
% Commandline keywords:
34
%   'option_computeica' - [0|1] If 1, compute the ICA component activitations and
35
%                   store them in a new variable. If 0, compute ICA activations
36
%                   only when needed (& only partially, if possible) and do not
37
%                   store the results).
38
%   NOTE: Turn OFF the options above when working with very large datasets or on 
39
%                   computers with limited memory.
40
%   'option_savematlab' - [0|1] If 1, datasets are saved as single Matlab .set files. 
41
%                   If 0, dataset data are saved in separate 32-bit binary float 
42
%                   .dat files.  See the corresponding GUI option above for details. 
43
% Outputs:
44
%   In the output workspace, variables 'option_computeica', 
45
%   and 'option_savematlab'  are updated, and a new 'eeg_options.m' file may be
46
%   written to the working directory. The copy of 'eeg_options.m' placed in your 
47
%   working directory overwrites system defaults whenever EEGLAB operates in this
48
%   directory (assuming your working directory is in your MATLABPATH - see PATH).
49
%   To adjust these options system-wide, edit the master "eeg_options.m" file in the
50
%   EEGLAB directory hierarchy.
51
%
52
% Author: Arnaud Delorme, SCCN / INC / UCSD, March 2002
53
%
54
% See also: EEG_OPTIONS, EEG_READOPTIONS
55
56
% Copyright (C) Arnaud Delorme, CNL / Salk Institute, 09 March 2002, arno@salk.edu
57
%
58
% This file is part of EEGLAB, see http://www.eeglab.org
59
% for the documentation and details.
60
%
61
% Redistribution and use in source and binary forms, with or without
62
% modification, are permitted provided that the following conditions are met:
63
%
64
% 1. Redistributions of source code must retain the above copyright notice,
65
% this list of conditions and the following disclaimer.
66
%
67
% 2. Redistributions in binary form must reproduce the above copyright notice,
68
% this list of conditions and the following disclaimer in the documentation
69
% and/or other materials provided with the distribution.
70
%
71
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
72
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
75
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
77
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
78
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
79
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
80
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
81
% THE POSSIBILITY OF SUCH DAMAGE.
82
83
function com = pop_editoptions(varargin)
84
85
com = '';
86
argsoutput = {};
87
88
datasets_in_memory = 0;
89
if nargin > 0
90
    if ~ischar(varargin{1})
91
        datasets_in_memory = varargin{1};
92
        varargin = {};
93
    end
94
end
95
96
% parse the eeg_options file
97
% ----------------------------
98
eeglab_options;
99
if isdeployed || (exist('ismcc') && ismcc)
100
    filename = which('eeg_options.txt');
101
    eegoptionbackup = which('eeg_optionsbackup.txt');
102
else
103
    % folder for eeg_options file (also update the eeglab_options)
104
    if ~isempty(EEGOPTION_PATH)
105
         homefolder = EEGOPTION_PATH;
106
    elseif ispc
107
         if ~exist('evalc'), eval('evalc = @(x)(eval(x));'); end
108
         homefolder = deblank(evalc('!echo %USERPROFILE%'));
109
    else homefolder = '~';
110
    end
111
    filename = fullfile(homefolder, 'eeg_options.m');
112
    eegoptionbackup = which('eeg_optionsbackup.m');
113
end
114
115
fid = fopen( filename, 'r+'); % existing file
116
storelocal = 0;
117
if  fid == -1
118
    filepath = homefolder;
119
    filename = 'eeg_options.m';
120
    fid = fopen( fullfile(filepath, filename), 'w'); % new file possible?
121
    if fid == -1
122
        error([ 'Cannot write into HOME folder: ' homefolder 10 'You may specify another folder for the eeg_option.m' 10 'file by editing the icadefs.m file' ]);
123
    end
124
    fclose(fid);
125
    delete(fullfile(filepath, filename));
126
127
    % read variables values and description
128
    % --------------------------------------
129
    [ header, opt ] = eeg_readoptions( eegoptionbackup ); 
130
else 
131
    [filepath, filename, ext] = fileparts(filename);
132
    filename  = [ filename ext ];
133
    fprintf('Using option file in directory %s\n', filepath);
134
    
135
    % read variables values and description
136
    % --------------------------------------
137
    [ header, opt ] = eeg_readoptions( eegoptionbackup ); 
138
    [ header, opt ] = eeg_readoptions( fid, opt  ); % use opt from above as default
139
end
140
141
optionsToShow = {
142
    'option_storedisk' ...
143
    'option_savetwofiles'  ...
144
    'option_parallel'  ...
145
    'option_computeica'  ...
146
    'option_rememberfolder' ...
147
    'option_allmenus'  ...
148
    'option_checkversion' ...
149
    'option_showadvanced' ...
150
    'option_boundary99' ...
151
    'option_cachesize' };
152
153
% remove advanced options if necessary
154
if isempty(varargin)
155
    if ~option_showadvanced
156
        % remove options 
157
        for iOpt = length(opt):-1:1
158
            if ~isempty(opt(iOpt).varname) && ~ismember(opt(iOpt).varname, optionsToShow)
159
                opt(iOpt) = [];
160
            end
161
        end
162
        % remove header not serving any option
163
        for iOpt = length(opt)-1:-1:1
164
            if isempty(opt(iOpt).varname) && isempty(opt(iOpt+1).varname)
165
                opt(iOpt) = [];
166
            end
167
        end
168
    end
169
end
170
171
if nargin < 2
172
    geometry = { [6 1] };
173
    tmpfile = fullfile(filepath, filename);
174
    
175
    cb_file = [ '[filename, filepath] = uiputfile(''eeg_options.txt'', ''Pick a folder to save option file'');' ...
176
                'if filename(1) ~= 0,' ...
177
                '   filepath = fullfile(filepath, ''eeg_options.m'');' ...
178
                '   set(gcf, ''userdata'', filepath);' ...
179
                '   if length(filepath) > 100,' ...
180
                '        filepath =  [ ''...'' filepath(end-100:end) ];' ...
181
                '   end;' ...
182
                '   set(findobj(gcf, ''tag'', ''filename''), ''string'', filepath);' ...
183
                'end;' ...
184
                'clear filepath;' ];
185
            
186
    uilist = { ...
187
         { 'Style', 'text', 'string', '', 'fontweight', 'bold'  }, ...
188
         { 'Style', 'text', 'string', 'Set/Unset', 'fontweight', 'bold'   } };
189
190
    % add all fields to graphic interface
191
    % -----------------------------------
192
    for index = 1:length(opt)
193
        % format the description to fit a help box
194
        % ----------------------------------------
195
        descrip = { 'string', opt(index).description }; % strmultiline(description{ index }, 80, 10) };
196
           
197
        % create the gui for this variable
198
        % --------------------------------
199
        if strcmpi(opt(index).varname, 'option_storedisk') && datasets_in_memory
200
            cb_nomodif = [ 'set(gcbo, ''value'', ~get(gcbo, ''value''));' ...
201
                           'warndlg2(strvcat(''This option may only be modified when at most one dataset is stored in memory.''));' ];
202
            
203
        elseif strcmpi(opt(index).varname, 'option_memmapdata')
204
            cb_nomodif = [ 'if get(gcbo, ''value''), warndlg2(strvcat(''Matlab memory is beta, use at your own risk'')); end;' ];
205
        elseif strcmpi(opt(index).varname, 'option_boundary99')
206
            cb_nomodif = [ 'warndlg2(strvcat(''This function is for ERPLAB compatility. If you do not have numerical events,'', ''it will have no effect. If you have numerical events, type -99 will be used as boundary'', ''event type throughout EEGLAB. If you use this option to process some datasets and then'', ''unset it, EEGLAB will no longer detect type -99 boundaries, so be careful!'' ));' ];
207
        elseif strcmpi(opt(index).varname, 'option_donotusetoolboxes')
208
            cb_nomodif = [ 'if get(gcbo, ''value''), warndlg2([''You have selected the option to disable'' 10 ''Matlab toolboxes. Use with caution.'' 10 ''Matlab toolboxes will be removed from'' 10 ''your path. Unlicking this option later will not'' 10 ''add back the toolboxes. You will need'' 10 ''to add them back manually. If you are unsure'' 10 ''if you want to disable Matlab toolboxes'' 10 ''deselect the option now.'' ]); end;' ];
209
        else
210
            cb_nomodif = '';
211
        end
212
        
213
        if ~isempty(opt(index).value)
214
            if opt(index).value <= 1
215
                uilist   = { uilist{:}, { 'Style', 'text', descrip{:}, 'horizontalalignment', 'left' }, ...
216
                             { 'Style', 'checkbox', 'string', '    ', 'value', opt(index).value 'callback' cb_nomodif } { } }; 
217
                geometry = { geometry{:} [4 0.3 0.1] };
218
            else
219
                uilist   = { uilist{:}, { 'Style', 'text', descrip{:}, 'horizontalalignment', 'left' }, ...
220
                             { 'Style', 'edit', 'string', num2str(opt(index).value), 'callback' cb_nomodif } { } }; 
221
                geometry = { geometry{:} [3 0.5 0.1] };
222
            end
223
        else
224
            uilist   = { uilist{:}, { 'Style', 'text', descrip{:}, 'fontweight' 'bold', 'horizontalalignment', 'left' }, { } { } }; 
225
            geometry = { geometry{:} [4 0.3 0.1] };
226
        end
227
    end
228
229
    % change option file
230
    uilist = { uilist{:} {} ...
231
                 { 'Style', 'text', 'string', 'Edit the EEGOPTION_PATH variable of functions/sigprocfunc/icadefs.m to change where the option file is saved' } };
232
    geometry = { geometry{:} [1] [1] };
233
    [results, userdat ] = inputgui( geometry, uilist, 'pophelp(''pop_editoptions'');', 'Memory options - pop_editoptions()', ...
234
                        [], 'normal');
235
    if isempty(results), return; end
236
   
237
    % decode inputs
238
    % -------------
239
    args = {};
240
    count = 1;
241
    for index = 1:length(opt)
242
        if ~isempty(opt(index).varname)
243
            args = {  args{:}, opt(index).varname, results{count} }; 
244
            count = count+1;
245
        end
246
    end
247
else 
248
    % no interactive inputs
249
    % ---------------------
250
    args = varargin;
251
end
252
253
% change default folder option
254
% ----------------------------
255
W_MAIN = findobj('tag', 'EEGLAB');
256
if ~isempty(W_MAIN)
257
    tmpuserdata    = get(W_MAIN, 'userdata');
258
    tmpuserdata{3} = filepath;
259
    set(W_MAIN, 'userdata', tmpuserdata);
260
end
261
262
% decode inputs
263
% -------------
264
for index = 1:2:length(args)
265
    ind = strmatch(args{index}, { opt.varname }, 'exact');
266
    if isempty(ind)
267
        if strcmpi(args{index}, 'option_savematlab')
268
            disp('pop_editoptions: option_savematlab is obsolete, use option_savetwofiles instead');
269
            ind = strmatch('option_savetwofiles', { opt.varname }, 'exact');
270
        else
271
            error(['Variable name ''' args{index} ''' is invalid']);
272
        end
273
    end
274
    
275
    % case for 'option_cachesize'
276
    if strcmpi(args{index}, 'option_cachesize') && ischar(args{index+1})
277
        args{index+1}  = str2num(args{index+1});
278
    end
279
    
280
    % overwrite only if different
281
    if args{index+1} ~= opt(ind).value 
282
        opt(ind).value    = args{index+1};
283
        argsoutput{end+1} = args{index};   % for history
284
        argsoutput{end+1} = args{index+1}; % for history
285
    end  
286
end
287
288
% write to eeg_options file
289
% -------------------------
290
fid = fopen( fullfile(filepath, filename), 'w');
291
addpath(filepath);
292
if fid == -1
293
    error('File writing error, check writing permission');
294
end
295
fprintf(fid, '%s\n', header);
296
for index = 1:length(opt)
297
    if isempty(opt(index).varname)
298
        fprintf( fid, '%% %s\n', opt(index).description);
299
    else
300
        fprintf( fid, '%s = %d ; %% %s\n', opt(index).varname, opt(index).value, opt(index).description);
301
    end
302
end
303
fclose(fid);    
304
% clear it from the MATLAB function cache
305
clear(fullfile(filepath,filename));
306
307
% generate the output text command
308
% --------------------------------
309
if ~isempty(argsoutput)
310
    com = 'pop_editoptions(';
311
    for index = 1:2:length(argsoutput)
312
        com = sprintf( '%s ''%s'', %d,', com, argsoutput{index}, argsoutput{index+1});
313
    end
314
    com = [com(1:end-1) ');'];
315
else
316
    disp('pop_editoptions: Options were not modified');
317
end
318
wtmp = warning;
319
warning off;
320
clear functions
321
warning(wtmp);
322
323
% ---------------------------
324
function  chopedtext = choptext( tmptext )
325
    chopedtext = '';
326
    while length(tmptext) > 30
327
          blanks = findstr( tmptext, ' ');
328
          [tmp, I] = min( abs(blanks - 30) );
329
          chopedtext = [ chopedtext ''' 10 ''' tmptext(1:blanks(I)) ];
330
          tmptext  = tmptext(blanks(I)+1:end);
331
    end    
332
    chopedtext = [ chopedtext ''' 10 ''' tmptext];
333
    chopedtext = chopedtext(7:end);
334
return;
335
336
function num = popask( text )
337
     ButtonName=questdlg2( text, ...
338
            'Confirmation', 'Cancel', 'Yes','Yes');
339
     switch lower(ButtonName)
340
          case 'cancel', num = 0;
341
          case 'yes',    num = 1;
342
     end