Home > functions > gui > bayes_parm_editor_dir > basic_parm > bayes_parm_basic_gui.m

bayes_parm_basic_gui

PURPOSE ^

Process event abouts bayes parameter basic gui.

SYNOPSIS ^

function varargout = bayes_parm_basic_gui(fig, command, varargin)

DESCRIPTION ^

 Process event abouts bayes parameter basic gui.
 [IN]
         fig : figure handle of bayes basic parameter gui.
     command : event type
    varargin :
 [OUT]
    varargout :


 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = bayes_parm_basic_gui(fig, command, varargin)
0002 % Process event abouts bayes parameter basic gui.
0003 % [IN]
0004 %         fig : figure handle of bayes basic parameter gui.
0005 %     command : event type
0006 %    varargin :
0007 % [OUT]
0008 %    varargout :
0009 %
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 %
0015 % --- Previous check
0016 %
0017 if ~exist('fig', 'var') || isempty(fig) || ~ishandle(fig)
0018     error('invalid figure handle is specified.');
0019 end
0020 
0021 %
0022 % --- Main Procedure
0023 %
0024 
0025 % load data(@see bayes_parm_basic_init)
0026 data = guidata(fig);
0027 H = data.H;
0028 
0029 switch(command)
0030     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0031     % GUI initialize/exit/update functions
0032     %
0033     case 'is_exist'
0034         if isfield(H, 'fig')
0035             varargout{1} = true;
0036         else
0037             varargout{1} = false;
0038         end
0039     case 'figure_pull_up_to_top'
0040         figure(H.fig);
0041     case 'gui_update'
0042         bayes_parm = varargin{1};
0043         data = set_gui_parms(data, bayes_parm);
0044     case 'get_project_root'
0045         project_root = get(H.project_root_edit, 'String');
0046         varargout{1} = project_root;
0047     case 'set_project_root'
0048         set(H.project_root_edit, 'String', varargin{1});
0049 
0050     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0051     % GUI component handles getter functions
0052     %
0053     case 'get_gui_handles'
0054         varargout{1} = H;
0055 
0056     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0057     % GUI component's call back functions
0058     case 'call_back'
0059         hObj = varargin{1};
0060         data = callback(data, hObj);
0061         % gui parameters collection
0062         bayes_parm = get_gui_parms(data);
0063         % send parameters to main function
0064         bayes_parm_editor(data.main_obj, 'merge_bayes_parm', bayes_parm);
0065 end
0066 
0067 function data = set_gui_parms(data, bayes_parm)
0068 % This function set parameters to the GUI.
0069 % see : get_gui_parms
0070 % [IN]
0071 %          data : application data (@see bayes_parm_basic_init)
0072 %    bayes_parm : initialize parameters.
0073 % [OUT]
0074 %    H : structure of all object handles
0075 
0076     H = data.H;
0077 
0078     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0079     % files
0080     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0081     if isfield(bayes_parm, 'proj_dir') && isempty(get(H.project_root_edit, 'String'))
0082         set(H.project_root_edit, 'String', bayes_parm.proj_dir);
0083     end
0084     data = set_gui_meg_file(data, bayes_parm.megfile);
0085     set_gui_basis_file(H, bayes_parm.basisfile);
0086     set(H.brain_file_edit, 'String', bayes_parm.brainfile);
0087 %    [output_dir, filename, ext] = fileparts(bayes_parm.bayesfile);
0088     [output_dir, filename, ext] = vb_get_file_parts(bayes_parm.bayesfile);
0089     set(H.result_file_outputdir_edit, 'String', output_dir);
0090     set(H.result_filename_edit, 'String', [filename, ext]);
0091     set_gui_act_file(H, bayes_parm.actfile);
0092     set_gui_area_file(H, bayes_parm.areafile);
0093     
0094     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0095     % keys
0096     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0097     area_keys = get(H.area_key_listbox, 'String');
0098     if isempty(area_keys)
0099         set(H.area_key_listbox, 'String', bayes_parm.area_key);
0100         area_keys = bayes_parm.area_key;
0101     end
0102     idx = strmatch(bayes_parm.area_key, area_keys, 'exact');
0103     if ~isempty(idx)
0104         set(H.area_key_listbox, 'Value', idx);
0105     else
0106         set(H.area_key_listbox, 'Value', 1);
0107     end
0108 
0109     act_keys = get(H.act_key_listbox, 'String');
0110     if isempty(act_keys)
0111         set(H.act_key_listbox, 'String', bayes_parm.act_key);
0112         act_keys = bayes_parm.act_key;
0113     end
0114     idx = [];
0115     % convert char to cell
0116     if ischar(bayes_parm.act_key)
0117         bayes_parm.act_key = cellstr(bayes_parm.act_key);
0118     end
0119     for k=1:length(bayes_parm.act_key)
0120         idx = [idx; strmatch(bayes_parm.act_key{k}, act_keys, 'exact')];
0121     end
0122     if ~isempty(idx)
0123         set(H.act_key_listbox, 'Value', idx);
0124     else
0125         set(H.area_key_listbox, 'Value', 1);
0126     end
0127 
0128     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0129     % Time parameters
0130     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0131     %Whole time window
0132     if length(bayes_parm.twin_meg) == 2
0133         wtime_from_index = bayes_parm.twin_meg(1);
0134         wtime_to_index = bayes_parm.twin_meg(2);
0135     
0136         wtime_from_msec = bayes_parm_editor(data.main_obj, ...
0137                                             'index_to_time',...
0138                                             wtime_from_index,...
0139                                             'meg');
0140         wtime_to_msec = bayes_parm_editor(data.main_obj, ...
0141                                             'index_to_time',...
0142                                             wtime_to_index,...
0143                                             'meg');
0144         set(H.whole_time_window_from_edit,...
0145             'String', sprintf('%.2f', wtime_from_msec));
0146         set(H.whole_time_window_to_edit,...
0147             'String', sprintf('%.2f', wtime_to_msec));
0148     end
0149     %
0150     % --- Window parameters
0151     %
0152     set(H.time_shift_start_pos_edit, 'String', '');
0153     set(H.time_shift_end_pos_edit, 'String', '');
0154     set(H.time_shift_window_size_edit, 'String', '');
0155     set(H.time_shift_shift_length_edit, 'String', '');
0156 
0157     if (length(bayes_parm.Tperiod) == 1) &&...
0158        (length(bayes_parm.Tnext) == 1)
0159         change_time_shift_mode(H, 'equally');
0160         %Time shift equally
0161         window_size = bayes_parm_editor(data.main_obj, ...
0162                                         'data_len_to_time_len',...
0163                                         bayes_parm.Tperiod,...
0164                                         'meg');%msec
0165         shift_len = bayes_parm_editor(data.main_obj, ...
0166                                         'data_len_to_time_len',...
0167                                         bayes_parm.Tnext,...
0168                                         'meg');%msec
0169         set(H.time_shift_window_size_edit,...
0170             'String', sprintf('%.2f', window_size));
0171         set(H.time_shift_shift_length_edit,...
0172             'String', sprintf('%.2f', shift_len));
0173     elseif (length(bayes_parm.Tperiod) ~= 0) &&...
0174             (length(bayes_parm.Tnext) ~= 0)
0175         %Manual settings
0176         change_time_shift_mode(H, 'manual');
0177         start_idx = bayes_parm.Tnext + bayes_parm.twin_meg(1) -1;
0178         start_pos = bayes_parm_editor(data.main_obj, ...
0179                                       'index_to_time',...
0180                                       start_idx,...
0181                                       'meg');
0182         end_idx = bayes_parm.Tnext + bayes_parm.Tperiod + ...
0183                   bayes_parm.twin_meg(1)-2;
0184         end_pos = bayes_parm_editor(data.main_obj, ...
0185                                     'index_to_time',...
0186                                     end_idx,...
0187                                     'meg');
0188         spos_comma_text = bayes_parm_gui_util('comma_text', start_pos);
0189         epos_comma_text = bayes_parm_gui_util('comma_text', end_pos);
0190         set(H.time_shift_start_pos_edit, 'String', spos_comma_text);
0191         set(H.time_shift_end_pos_edit, 'String', epos_comma_text);
0192     else
0193         change_time_shift_mode(H, 'equally');
0194         set(H.time_shift_window_size_edit, 'String', '');
0195         set(H.time_shift_shift_length_edit,'String', '');
0196         set(H.time_shift_start_pos_edit, 'String', '');
0197         set(H.time_shift_end_pos_edit, 'String', '');
0198     end
0199     
0200     
0201     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0202     % Estimation Model Parameters
0203     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0204     %Estimation model
0205 
0206     if IsTreatableEstimationModel(bayes_parm) == true
0207         %
0208         % -- Forward Model
0209         %
0210         set_forward_model(H, bayes_parm.forward_model, true);
0211 
0212         %
0213         % -- Noise estimation model
0214         %
0215         model = bayes_parm.noise_estimation_model;
0216 %        if(model == 1)||(model == 2)
0217 %            value = model;     % listbox line number
0218 %        elseif(model == 3)||(model == 4)||(model == 5)
0219 %            value = model - 2; % listbox line number
0220 %        else
0221 %            disp('bayes_parm_editor:set_gui_parms estimation_model error');
0222 %        end
0223 
0224         set(H.noise_estimation_model_popup, 'Value', model);
0225         set_estimation_GUI_properties(H);
0226 
0227         %
0228         % -- update_sx
0229         %
0230         %Covariance
0231         set(H.obsn_cov_popup, 'Value', bayes_parm.noise_model);
0232 
0233         %Update
0234         if bayes_parm.update_sx == ON
0235             update_state = 1;    
0236         else
0237             update_state = 0;    
0238         end
0239         set(H.update_sx_checkbox, 'Value', update_state);
0240 
0241         %
0242         % -- update_v
0243         %
0244 
0245         %Update
0246         if bayes_parm.update_v == ON
0247             update_state = 1;
0248         else
0249             update_state = 0;
0250         end
0251         set(H.update_v_checkbox, 'Value', update_state);
0252 
0253     else
0254         error_str = sprintf(['Cannot read Estimation Model Parameters.\n', ...
0255                             '(The combination not to be able to treat was specified.)\n', ...
0256                             'Default Estimation Model parameters are set.']);
0257         errordlg(error_str, 'notice');
0258 
0259         % Default estimation parameters are set by this.
0260         set_forward_model(H, STR_FORWARD_MODEL_FOCAL, true);
0261     end
0262 
0263     %Sensor noise file and Noise Time window
0264     %set(H.sensor_noise_file_listbox, 'String', bayes_parm.megnoisefile);
0265     set(H.sensor_noise_file_listbox,'String',bayes_parm.megfile_baseline);
0266     data = set_noise_file_time_window(data, bayes_parm);
0267 
0268     % comment
0269     if isfield(bayes_parm, 'comment')
0270         set(H.comment_edit, 'String', bayes_parm.comment);
0271     end
0272     
0273     % Smoothness filter radius
0274     set(H.Rfilt_edit, 'String', sprintf('%.2f', bayes_parm.Rfilt(1)*1e3));
0275 
0276     % Reduce ratio
0277     set(H.reduce_edit, 'String', sprintf('%.2f', bayes_parm.reduce(1)));
0278     
0279     % Magnification parameter (a0_act)
0280     set(H.magnification_edit, 'String', num2str(bayes_parm.a0_act));
0281     
0282     % Confidence parameter (Ta0_act,Ta0)
0283     set(H.confidence_edit', 'String', num2str(bayes_parm.Ta0_act)); 
0284     
0285 function bayes_parm = get_gui_parms(data)
0286 % This function get basic bayes parameters from GUI.
0287 % see : set_gui_parms
0288 % [IN]
0289 %    data : application data (@see bayes_parm_basic_init)
0290 % [OUT]
0291 %    bayes_parm : bayes basic parameters.
0292 
0293     H = data.H;
0294     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0295     % files
0296     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0297 %    bayes_parm.proj_dir = get(H.project_root_edit, 'String');
0298 
0299     bayes_parm.megfile = get(H.meg_file_listbox, 'String');
0300     bayes_parm.basisfile = get(H.basis_file_listbox, 'String');
0301     bayes_parm.brainfile = get(H.brain_file_edit, 'String');
0302     bayes_parm.bayesfile = [get(H.result_file_outputdir_edit, 'String'),...
0303                             filesep,...
0304                             get(H.result_filename_edit, 'String')];
0305     bayes_parm.actfile = get(H.act_file_edit, 'String');
0306     bayes_parm.areafile = get(H.area_file_edit, 'String');
0307 
0308     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0309     % keys
0310     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0311     area_keys = get(H.area_key_listbox, 'String');
0312     if ischar(area_keys)
0313         bayes_parm.area_key = area_keys;
0314     else
0315         bayes_parm.area_key = area_keys{get(H.area_key_listbox, 'Value')};
0316     end
0317     act_keys = get(H.act_key_listbox, 'String');
0318     % bayes_parm.act_key is cell strings
0319     if ischar(act_keys)
0320         bayes_parm.act_key = {act_keys};
0321     else
0322         bayes_parm.act_key = act_keys(get(H.act_key_listbox, 'Value'));
0323     end
0324 
0325     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0326     % Time parameters
0327     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0328     %Duration settings
0329     Tperiod = [];
0330     Tnext = [];
0331     twin_meg = [];
0332     try
0333     if get(H.time_shift_equally_radiobutton, 'Value')
0334         %
0335         % --- Time shift Equally
0336         %
0337         
0338         % get parameters from gui
0339         wtime_from_msec = str2double(...
0340                             get(H.whole_time_window_from_edit, 'String'));
0341         wtime_to_msec = str2double(get(H.whole_time_window_to_edit, 'String'));
0342     
0343         % convert vbmeg data format
0344         wtime_from_index = bayes_parm_editor(data.main_obj, ...
0345                                              'time_to_index',...
0346                                              wtime_from_msec, 'meg');
0347         wtime_to_index   = bayes_parm_editor(data.main_obj, ...
0348                                              'time_to_index',...
0349                                              wtime_to_msec, 'meg');
0350 
0351         twin_meg = [wtime_from_index, wtime_to_index];
0352         
0353         window_size = str2double(...
0354                             get(H.time_shift_window_size_edit, 'String'));
0355         time_shift_len = str2double(...
0356                             get(H.time_shift_shift_length_edit, 'String'));
0357 
0358         Tperiod = bayes_parm_editor(data.main_obj, ...
0359                                     'time_len_to_data_len',...
0360                                     window_size, 'meg');
0361         Tnext = bayes_parm_editor(data.main_obj, ...
0362                                   'time_len_to_data_len',...
0363                                   time_shift_len, 'meg');
0364     else
0365         %
0366         % --- Time shift manual settings
0367         %
0368         
0369         % get time lists from gui
0370         command = ['[' get(H.time_shift_start_pos_edit, 'String') ']']; 
0371         start_pos = eval(command);
0372         command = ['[' get(H.time_shift_end_pos_edit, 'String') ']']; 
0373         end_pos = eval(command);
0374         [start_idx, err] = bayes_parm_editor(data.main_obj, ...
0375                                              'time_to_index',...
0376                                              start_pos, 'meg');
0377         if err, return, end;
0378         [end_idx, err] = bayes_parm_editor(data.main_obj, ...
0379                                            'time_to_index',...
0380                                            end_pos, 'meg');
0381         if err, return, end;
0382         
0383         % make parameters.
0384         twin_meg = [min(start_idx), max(end_idx)];
0385         Tperiod = end_idx - start_idx + 1;
0386         Tnext   = [start_idx - twin_meg(1) + 1];
0387         if length(Tnext) == 1
0388             Tnext = Tperiod;
0389         end
0390     end
0391     catch
0392     end
0393 
0394     bayes_parm.twin_meg = twin_meg;
0395     bayes_parm.Tnext = Tnext;
0396     bayes_parm.Tperiod = Tperiod;
0397 
0398     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0399     % Estimation Model Parameters
0400     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0401     %Estimation model
0402     bayes_parm.forward_model = get_forward_model(H);
0403     bayes_parm.noise_estimation_model = get_noise_estimation_model(H);
0404 
0405     %Sensor noise file
0406     if get(H.specified_checkbox, 'Value')
0407         num_files = length(bayes_parm.megfile);
0408         meg_file = get(H.sensor_noise_file_edit, 'String');
0409         % copy sensor noise file(num_files)
0410         %bayes_parm.megnoisefile = repmat(cellstr(meg_file), num_files, 1);
0411         bayes_parm.megfile_baseline = repmat(cellstr(meg_file), num_files, 1);
0412     else
0413         %bayes_parm.megnoisefile = get(H.sensor_noise_file_listbox, 'String');
0414         bayes_parm.megfile_baseline = get(H.sensor_noise_file_listbox,'String');
0415     end
0416 
0417     %%%%%%%%%%%%%%%%%%%%%%%%%
0418     % Observation noise
0419     %%%%%%%%%%%%%%%%%%%%%%%%%
0420     %Covariance
0421     bayes_parm.noise_model = get(H.obsn_cov_popup, 'Value');
0422 
0423     %Time window
0424     twin_from_msec = str2double(get(H.obsn_time_window_from_edit, 'String'));
0425     twin_to_msec = str2double(get(H.obsn_time_window_to_edit, 'String'));
0426     twin_from_index = bayes_parm_editor(data.main_obj, ...
0427                                         'time_to_index',...
0428                                         twin_from_msec, 'meg');
0429     twin_to_index = bayes_parm_editor(data.main_obj, ...
0430                                       'time_to_index',...
0431                                       twin_to_msec, 'meg');
0432     bayes_parm.twin_noise = [twin_from_index twin_to_index];
0433 
0434     %Update
0435     update_state = get(H.update_sx_checkbox, 'Value');
0436     if update_state
0437         bayes_parm.update_sx = ON;
0438     else
0439         bayes_parm.update_sx = OFF;
0440     end
0441 
0442     %%%%%%%%%%%%%%%%%%%%%%%%%
0443     % Baseline activity
0444     %%%%%%%%%%%%%%%%%%%%%%%%%
0445 
0446     %Time window
0447     %twin_from_msec = str2double(get(H.pcv_time_window_from_edit, 'String'));
0448     %twin_to_msec = str2double(get(H.pcv_time_window_to_edit, 'String'));
0449     % Time window is the same that of the observation noise
0450     twin_from_msec = str2double(get(H.obsn_time_window_from_edit, 'String'));
0451     twin_to_msec = str2double(get(H.obsn_time_window_to_edit, 'String'));
0452     twin_from_index = bayes_parm_editor(data.main_obj, ...
0453                                         'time_to_index',...
0454                                         twin_from_msec, 'meg');
0455     twin_to_index = bayes_parm_editor(data.main_obj, ...
0456                                       'time_to_index',...
0457                                       twin_to_msec, 'meg');
0458     %bayes_parm.twin_global = [twin_from_index twin_to_index];
0459     bayes_parm.twin_baseline = [twin_from_index twin_to_index];
0460 
0461     %Update
0462     update_state = get(H.update_v_checkbox, 'Value');
0463     if update_state
0464         bayes_parm.update_v = ON;
0465     else
0466         bayes_parm.update_v = OFF;
0467     end
0468 
0469     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0470     % flag_baseline, flag_noise_set
0471     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0472     bayes_parm.flag_baseline  = str2double(get(H.flag_baseline_edit, 'String'));
0473     bayes_parm.flag_noise_set = str2double(get(H.flag_noise_set_edit, 'String'));
0474     
0475     % comment
0476     bayes_parm.comment = get(H.comment_edit, 'String');
0477     
0478     % Smoothness filter radius
0479     bayes_parm.Rfilt = str2num(get(H.Rfilt_edit, 'String'))*1e-3; 
0480 
0481     % Reduce ratio
0482     bayes_parm.reduce = str2num(get(H.reduce_edit, 'String'));
0483     
0484     % Magnification parameter (a0_act)
0485     bayes_parm.a0_act = str2num(get(H.magnification_edit, 'String'));
0486     
0487     % Confidence parameter (Ta0_act, Ta0)
0488     bayes_parm.Ta0 = str2num(get(H.confidence_edit, 'String'));
0489     bayes_parm.Ta0_act = str2num(get(H.confidence_edit, 'String'));
0490 
0491 function data = callback(data, hObj)
0492 % This function processes an GUI action.
0493 % we can detect the action which object is changed by hObj.
0494 %
0495 % [IN]
0496 %    data : application data (@see bayes_parm_basic_init)
0497 %    hObj : event component handle
0498 % [OUT]
0499 %    data : some updated application data
0500 %
0501 global vbmeg_inst;
0502 define = vbmeg_inst.const;
0503 
0504 H = data.H;
0505 
0506 switch(hObj)
0507     case H.project_root_push
0508         dirname = dir_dialog(get(H.project_root_edit, 'String'));
0509         if dirname ~= 0
0510             set(H.project_root_edit, 'String', dirname);
0511         end
0512     case H.brain_file_push
0513         project_root = get(H.project_root_edit, 'String');
0514         [dirname fname selected] = bayes_parm_gui_util(...
0515                                             'filedlg_relative',...
0516                                             {define.BRAIN_EXTENSION},...
0517                                             0, project_root, ...
0518                                             'Select cortical model file');
0519         if selected
0520             set(H.brain_file_edit, 'String', [dirname filesep fname{1}]);
0521         end
0522     case H.basis_file_add_push
0523         project_root = get(H.project_root_edit, 'String');
0524         [dirname fname selected] = bayes_parm_gui_util(...
0525                                             'filedlg_relative',...
0526                                             {define.BASIS_EXTENSION},...
0527                                             0, project_root, ...
0528                                             'Select leadfield file');
0529         if selected
0530             num = length(fname);
0531             add_files = {};
0532             for n=1:num
0533                 add_files = ...
0534                     [add_files; cellstr([dirname filesep fname{n}])];
0535             end
0536             filenames = get(H.basis_file_listbox, 'String');
0537             set_gui_basis_file(H, [filenames; add_files]);
0538         end
0539     case H.basis_file_remove_push
0540         idx = get(H.basis_file_listbox, 'Value');
0541         filenames = get(H.basis_file_listbox, 'String');
0542         if ~isempty(filenames)
0543             filenames(idx) = [];
0544             list_focus = idx(1)-1;
0545             if idx(1)-1 == 0
0546                 list_focus = 1;
0547             end
0548             set(H.basis_file_listbox, 'Value', list_focus);
0549             set_gui_basis_file(H, filenames);
0550         end
0551     case H.meg_file_add_push
0552         project_root = get(H.project_root_edit, 'String');
0553         [dirname fnames selected] = bayes_parm_gui_util(...
0554                                         'filedlg_relative',...
0555                                         {define.MEG2_EXTENSION, ...
0556                                          define.EEG_EXTENSION},...
0557                                         0, project_root, ...
0558                                         'Select MEG/EEG data');
0559         if selected
0560             num = length(fnames);
0561             add_files = {};
0562             for n=1:num
0563                 add_files = ...
0564                     [add_files; cellstr([dirname filesep fnames{n}])];
0565             end
0566             filenames = get(H.meg_file_listbox, 'String');
0567             data = set_gui_meg_file(data, [filenames; add_files]);
0568         end
0569     case H.meg_file_remove_push
0570         idx = get(H.meg_file_listbox, 'Value');
0571         filenames = get(H.meg_file_listbox, 'String');
0572         
0573         if ~isempty(filenames)
0574             filenames(idx) = [];   % remove selected filenames
0575             list_focus = idx(1)-1;
0576             if idx(1)-1 == 0
0577                 list_focus = 1;
0578             end
0579             % update list focus.
0580             set(H.meg_file_listbox, 'Value', list_focus);
0581             data = set_gui_meg_file(data, filenames);
0582         end
0583     case H.result_file_outputdir_push
0584         project_root = get(H.project_root_edit, 'String');
0585         dirname = dir_dialog(get(H.project_root_edit, 'String'), false);
0586         if (dirname ~= 0) & (~isempty(project_root))
0587             path_relative = vb_relativepath(dirname, project_root);
0588             path_relative = path_relative(1:length(path_relative)-1);
0589             set(H.result_file_outputdir_edit, 'String', path_relative);
0590         end
0591     case H.result_filename_edit
0592         result_file = get(hObj, 'String');
0593 %        [path_name, fname, ext] = fileparts(result_file);
0594         [path_name, fname, ext] = vb_get_file_parts(result_file);
0595         if isempty(ext)
0596             ext = define.BAYES_EXTENSION;
0597         end
0598         set(hObj, 'String', [fname ext]);
0599     case H.area_file_push
0600         project_root = get(H.project_root_edit, 'String');
0601         [dirname fname selected] = bayes_parm_gui_util(...
0602                                         'filedlg_relative',...
0603                                         {define.AREA_EXTENSION},...
0604                                         0, project_root, ...
0605                                         'Select cortical area file');
0606         if selected
0607             area_file = [dirname filesep fname{1}];
0608             data = reload_gui_area_file(data, area_file);
0609         end
0610     case H.act_file_push
0611         project_root = get(H.project_root_edit, 'String');
0612         [dirname fname selected] = bayes_parm_gui_util(...
0613                                         'filedlg_relative',...
0614                                         {define.FMRI_EXTENSION},...
0615                                         0, project_root, ...
0616                                         'Select cortical activity file');
0617         if selected
0618             act_file = [dirname filesep fname{1}];
0619             set_gui_act_file(H, act_file);
0620         end
0621     case { H.whole_time_window_from_edit, H.whole_time_window_to_edit }
0622         time = str2double(get(hObj, 'String'));
0623         [match_time, err] = time_match_sample_point(data, time, 'meg');
0624         if err == 1
0625             errordlg('select meg file.', 'error');
0626             set(hObj, 'String', '');
0627         elseif err == 2
0628             errordlg('Illigal input.', 'error');
0629             set(hObj, 'String', '');
0630         else
0631             set(hObj, 'String', sprintf('%.2f', match_time));
0632         end
0633     case H.time_shift_manual_radiobutton
0634         change_time_shift_mode(H, 'manual');
0635     case H.time_shift_equally_radiobutton
0636         change_time_shift_mode(H, 'equally');
0637     case {H.time_shift_window_size_edit, H.time_shift_shift_length_edit}
0638         time_len = str2double(get(hObj, 'String'));
0639         if time_len < 0
0640             errordlg('The value should be positive value.', 'Error');
0641             set(hObj, 'String', '');
0642         else
0643             [ceil_time_len, err] = ceil_time_length(data, time_len, 'meg');
0644             if err == 1
0645                 errordlg('select meg file.', 'error');
0646             elseif err == 2
0647                 errordlg('Illigal input.', 'error');
0648             else
0649                 set(hObj, 'String', sprintf('%.2f', ceil_time_len));
0650             end
0651         end
0652     case { H.time_shift_start_pos_edit, H.time_shift_end_pos_edit }
0653         %start positions, end positions check
0654         command = ['[' get(hObj, 'String') ']']; 
0655         try
0656             pos = eval(command);
0657             [match_time, err] = time_match_sample_point(data, pos, 'meg');
0658         catch
0659             errordlg('positions are invalid.', 'error');
0660             return;
0661         end
0662         match_time = sort(match_time);
0663         pos_text = bayes_parm_gui_util('comma_text', match_time);
0664         set(hObj, 'String', pos_text);
0665     case H.duration_check_push
0666         % Display durations
0667         [start_pos, end_pos, err] = get_interval(H);
0668         if err
0669             return;
0670         end
0671         time_window_string = [num2str(start_pos, '%-8.2f'),...
0672                             repmat(' - ', length(start_pos), 1),...
0673                             num2str(end_pos, '%-8.2f')];
0674         % set to listbox
0675         set(H.duration_listbox, 'String', time_window_string);
0676         % set listbox line
0677         set(H.duration_listbox, 'Value', 1);
0678     case H.noise_estimation_model_popup
0679         set_estimation_GUI_properties(H);
0680         %case H.forward_model_popup
0681         %forward_model = get_forward_model(H);
0682         %H = set_forward_model(H, forward_model);
0683     case H.specified_checkbox
0684         if get(hObj, 'Value')
0685             data = change_sensor_noise_file_selection_mode(data, ON);
0686         else
0687             data = change_sensor_noise_file_selection_mode(data, OFF);
0688         end
0689     case H.sensor_noise_file_edit
0690         data = set_noise_file_time_window(data);
0691     case H.sensor_noise_file_push
0692         project_root = get(H.project_root_edit, 'String');
0693         [dirname fname selected] = bayes_parm_gui_util('filedlg_relative',...
0694                                                         {define.MEG2_EXTENSION},...
0695                                                         0,...
0696                                                         project_root);
0697         if selected
0698             set(H.sensor_noise_file_edit, 'String', [dirname filesep fname{1}]);
0699             data = set_noise_file_time_window(data);
0700         end
0701     case {H.obsn_time_window_from_edit, ...
0702           H.obsn_time_window_to_edit} %, ...
0703           %H.pcv_time_window_from_edit, ...
0704           %H.pcv_time_window_to_edit}
0705         value = str2double(get(hObj, 'String'));
0706         [match_time, err] = time_match_sample_point(data, value, 'noise');
0707         if err == 1
0708             errordlg('select meg file.', 'error');% current(v0.50) GUI,
0709             set(hObj, 'String', '');              % Sensor noise file = Meg noise file
0710         elseif err == 2
0711             errordlg('Illigal input.', 'error');
0712             set(hObj, 'String', '');
0713         else
0714             set(hObj, 'String', sprintf('%.2f', match_time));
0715         end
0716     case H.advanced_parm_push
0717         bayes_parm_editor_init_advanced_gui(data.main_obj);
0718     case H.save_push
0719         % gui parameters collection
0720         bayes_parm = get_gui_parms(data);
0721         % send parameters to main function
0722         bayes_parm_editor(data.main_obj, 'merge_bayes_parm', bayes_parm);
0723         % send save message to main function
0724         bayes_parm_editor(data.main_obj, 'save_bayes_parm');
0725     case H.load_push
0726         % send load message to main function
0727         bayes_parm_editor(data.main_obj, 'load_bayes_parm');
0728     case H.exec_push
0729         push_button_caption = get(H.exec_push, 'String');
0730         set(H.exec_push, 'String', 'Processing...');
0731         pause(0.01); % for update button string
0732         
0733         % gui parameters collection
0734         bayes_parm = get_gui_parms(data);
0735         % send parameters to main function
0736         bayes_parm_editor(data.main_obj, 'merge_bayes_parm', bayes_parm);
0737         % send execution message to main function
0738         bayes_parm_editor(data.main_obj, 'exec_estimation');
0739         
0740         set(H.exec_push, 'String', 'Exec');
0741     otherwise
0742 end
0743 
0744 function [start_pos, end_pos, err] = get_interval(H,data)
0745 % This function gets small window start points and end points.
0746 % [IN]
0747 %      H : GUI component handle.
0748 % [OUT]
0749 %      start_pos : time window start positions
0750 %      end_pos   : time window end positions
0751 %      err       : return true when time window is invalid.
0752 
0753     start_pos = [];
0754     end_pos = [];
0755     err = false;
0756     
0757     meg_info = data.meg_info;
0758 
0759     if get(H.time_shift_manual_radiobutton, 'Value')
0760         % manual Shift
0761         command = ['[' get(H.time_shift_start_pos_edit, 'String') ']']; 
0762         start_pos = eval(command);
0763         start_pos = start_pos(:);
0764         command = ['[' get(H.time_shift_end_pos_edit, 'String') ']']; 
0765         end_pos = eval(command);
0766         end_pos = end_pos(:);
0767 
0768         if length(start_pos) ~= length(end_pos)
0769             errordlg('Check Start positions and End positions.', 'Error');
0770             err = true;
0771         end
0772     else
0773         % equally Shift
0774         window_size = str2double(...
0775                             get(H.time_shift_window_size_edit, 'String'));
0776         shift_length = str2double(...
0777                             get(H.time_shift_shift_length_edit, 'String'));
0778         begin = str2double( ...
0779                             get(H.whole_time_window_from_edit, 'String'));
0780         last  = str2double(...
0781                             get(H.whole_time_window_to_edit, 'String'));
0782         
0783         index = vb_time_to_index([begin last],meg_info);
0784         Tsample = index(2)-index(1)+1;
0785         Tperiod = vb_time_to_numsamp(window_size,sample_freq);
0786         Tnext = vb_time_to_numsamp(shift_length,sample_freq);
0787         Twindow = vb_calc_timewindow(Tsample,Tperiod,Tnext);
0788         
0789         start_pos = Twindow(:,1);
0790         end_pos = Twindow(:,2);
0791         start_pos = vb_index_to_time(start_pos,meg_info);
0792         end_pos = vb_index_to_time(end_pos,meg_info);
0793         
0794         % small window start, end positions
0795         %w_start_pos = begin;
0796         %w_end_pos = 0;
0797 
0798         %n = 1;
0799         %st = clock;
0800         %while( (w_end_pos <= last) && (w_start_pos < last) )
0801         %    loop_out = false;
0802         %    w_end_pos = w_start_pos + window_size;
0803         %    if w_end_pos >= last
0804         %        w_end_pos = last;
0805         %        loop_out = true;
0806         %%    end
0807         %
0808         %    % add small window start_pos, end_pos
0809         %    start_pos = [start_pos; w_start_pos];
0810         %    end_pos = [end_pos; w_end_pos];
0811         %
0812         %    w_start_pos = w_start_pos + shift_length;
0813         %    n = n + 1;
0814         %    if loop_out || etime(clock, st) >= 3
0815         %        break;
0816         %    end
0817         %end
0818     end
0819 
0820 function data = set_noise_file_time_window(data, bayes_parm)
0821 % This function loads sensor noise file and sets time window.
0822 % [IN]
0823 %    data : application data(@see bayes_parm_basic_gui_init)
0824 % [OUT]
0825 %    data : some updated application data
0826 
0827     H = data.H;
0828 
0829     project_root = get(H.project_root_edit, 'String');
0830     noise_file = [];
0831     
0832     if get(H.specified_checkbox, 'Value') % specified sensor noise file
0833         noise_file = get(H.sensor_noise_file_edit, 'String');
0834     else
0835         filenames = get(H.sensor_noise_file_listbox, 'String'); % same with meg_file
0836         if length(filenames)
0837             noise_file = filenames{1}; % meg_file{1}
0838         end
0839     end
0840     
0841     % store sensor_noise_file data to the data cabinet.
0842     filename = [];
0843     if ~isempty(noise_file)
0844         filename = [project_root filesep noise_file];
0845     end
0846     set_sensor_noise_file_info(data, filename);
0847 
0848     
0849     % get sensor noise info
0850     meg_info = bayes_parm_editor(data.main_obj, 'get_sensor_noise_file_info');
0851     if isempty(meg_info)
0852         return;
0853     end
0854 
0855     pretrigger = vb_meginfo_get_pre_trigger(meg_info);
0856     % convert index to the msec
0857     if exist('bayes_parm', 'var') && ...
0858        isfield(bayes_parm, 'twin_noise') && ...
0859          size(bayes_parm.twin_noise, 2) == 2
0860 
0861         time_window_noise_from    = bayes_parm.twin_noise(1);
0862         time_window_noise_to      = bayes_parm.twin_noise(2);
0863     else
0864         time_window_noise_from    = 1;
0865         time_window_noise_to      = pretrigger;
0866     end
0867     if exist('bayes_parm', 'var') && ...
0868        isfield(bayes_parm, 'twin_baseline') && ...
0869          size(bayes_parm.twin_baseline, 2) == 2
0870         time_window_global_from   = bayes_parm.twin_baseline(1);
0871         time_window_global_to     = bayes_parm.twin_baseline(2);
0872     else
0873         time_window_global_from   = 1;
0874         time_window_global_to     = pretrigger;
0875     end
0876 
0877     [noise_from, err] = bayes_parm_editor(data.main_obj, ...
0878                                           'index_to_time', ...
0879                                           time_window_noise_from, ...
0880                                           'noise');
0881     [noise_to, err]   = bayes_parm_editor(data.main_obj, ...
0882                                           'index_to_time', ...
0883                                           time_window_noise_to, ...
0884                                           'noise');
0885     noise_from_str = sprintf('%.2f', noise_from);
0886     noise_to_str = sprintf('%.2f', noise_to);
0887 
0888     [global_from, err] = bayes_parm_editor(data.main_obj, ...
0889                                            'index_to_time', ...
0890                                            time_window_global_from, ...
0891                                            'noise');
0892     [global_to, err]   = bayes_parm_editor(data.main_obj, ...
0893                                            'index_to_time', ...
0894                                            time_window_global_to, ...
0895                                            'noise');
0896     global_from_str = sprintf('%.2f', global_from);
0897     global_to_str = sprintf('%.2f', global_to);
0898     
0899     % Observation noise time window
0900     set(H.obsn_time_window_from_edit, 'String', noise_from_str);
0901     set(H.obsn_time_window_to_edit, 'String', noise_to_str);
0902 
0903     % Prior current variance time window
0904     %set(H.pcv_time_window_from_edit, 'String', global_from_str);
0905     %set(H.pcv_time_window_to_edit, 'String', global_to_str);
0906 
0907 function data = change_sensor_noise_file_selection_mode(data, mode)
0908 % This function changes GUI properties of Sensor noise file selection.
0909 % [IN]
0910 %    data : application data(@see bayes_parm_basic_init)
0911 %    mode : ON(specified one file) or OFF
0912 % [OUT]
0913 %    data : some updated application data.
0914 
0915     H = data.H;
0916     switch(mode)
0917         case ON
0918             set(H.sensor_noise_file_edit, 'Visible', 'on');
0919             set(H.sensor_noise_file_push, 'Visible', 'on');
0920             set(H.sensor_noise_file_listbox, 'Visible', 'off');
0921             data = set_noise_file_time_window(data);
0922         case OFF
0923             set(H.sensor_noise_file_edit, 'Visible', 'off');
0924             set(H.sensor_noise_file_push, 'Visible', 'off');
0925             set(H.sensor_noise_file_listbox, 'Visible', 'on');
0926             data = set_noise_file_time_window(data);
0927     end
0928 
0929 function change_time_shift_mode(H, mode)
0930 % This function changes GUI properties of Time shift.
0931 % [IN]
0932 %       H : GUI component handle.
0933 %    mode : 0-manual 1- equally shift
0934 % [OUT]
0935 %    none
0936     switch(mode)
0937         case 'manual'
0938             set(H.time_shift_equally_radiobutton, 'Value', 0);
0939             set(H.time_shift_manual_radiobutton, 'Value', 1);
0940             % start_pos, end_pos gui visible
0941             set(H.time_shift_start_pos_label, 'Visible', 'on');
0942             set(H.time_shift_end_pos_label, 'Visible', 'on');
0943             set(H.time_shift_start_pos_edit, 'Visible', 'on');
0944             set(H.time_shift_end_pos_edit, 'Visible', 'on');
0945             % equally setting gui invisible
0946             set(H.time_shift_window_size_label, 'Visible', 'off');
0947             set(H.time_shift_shift_length_label, 'Visible', 'off');
0948             set(H.time_shift_window_size_edit, 'Visible', 'off');
0949             set(H.time_shift_shift_length_edit, 'Visible', 'off');
0950             % time range makes enable off
0951             set(H.analysis_time_range_text, 'Visible', 'off');
0952             set(H.whole_time_window_from_edit, 'Visible', 'off');
0953             set(H.whole_time_window_to_edit,   'Visible', 'off');
0954             set(H.whole_time_window_minus_text, 'Visible', 'off');
0955         otherwise
0956             set(H.time_shift_manual_radiobutton, 'Value', 0);
0957             set(H.time_shift_equally_radiobutton, 'Value', 1);
0958             % start_pos, end_pos gui invisible
0959             set(H.time_shift_start_pos_label, 'Visible', 'off');
0960             set(H.time_shift_end_pos_label, 'Visible', 'off');
0961             set(H.time_shift_start_pos_edit, 'Visible', 'off');
0962             set(H.time_shift_end_pos_edit, 'Visible', 'off');
0963             % equally setting gui visible
0964             set(H.time_shift_window_size_label, 'Visible', 'on');
0965             set(H.time_shift_shift_length_label, 'Visible', 'on');
0966             set(H.time_shift_window_size_edit, 'Visible', 'on');
0967             set(H.time_shift_shift_length_edit, 'Visible', 'on');
0968             % time range makes enable on
0969             set(H.analysis_time_range_text, 'Visible', 'on');
0970             set(H.whole_time_window_from_edit, 'Visible', 'on');
0971             set(H.whole_time_window_to_edit,   'Visible', 'on');
0972             set(H.whole_time_window_minus_text, 'Visible', 'on');
0973     end
0974 
0975 function H = change_forward_model(H, forward_model)
0976 % Don't call this function.
0977 % If you change forward model, you should call through set_forward_model().
0978 % This function changes forward model on GUI.
0979 %
0980 % [IN]
0981 %    H : GUI component handle.
0982 %    forward_model : 'focal' or 'focal+global'
0983 % [OUT]
0984 %    H : GUI component handle.
0985 
0986     %forward_models = get(H.forward_model_popup, 'String');
0987     %idx = strmatch(forward_model, forward_models, 'exact');
0988     %set(H.forward_model_popup, 'Value', idx);
0989     forward_model = STR_FORWARD_MODEL_FOCAL;
0990 
0991     switch(forward_model)
0992         case STR_FORWARD_MODEL_FOCAL
0993             models = { STR_COVARIANCE_NOISE,...
0994                        STR_COVARIANCE_NOISE_NO_UPDATE };
0995             value = 1;
0996         case STR_FORWARD_MODEL_FOCAL_GLOBAL
0997             models = { STR_COVARIANCE_NOISE,...
0998                        STR_COVARIANCE_NOISE_NO_UPDATE,...
0999                        STR_ISOTROPIC_NOISE,...
1000                        STR_ISOTROPIC_NOISE_NO_GLOBAL_UPDATE,...
1001                        STR_ISOTROPIC_NOISE_NO_UPDATE };
1002             value = 1;
1003     end
1004 
1005     set(H.noise_estimation_model_popup, 'String', models);
1006     set(H.noise_estimation_model_popup, 'Value', value);
1007 
1008     set_estimation_GUI_properties(H);
1009 
1010 function set_estimation_GUI_properties(H)
1011 % This function changes GUI properties of 'Estimation Model Parameters'
1012 %  by Estimation model.
1013 % [IN]
1014 %   H : GUI component handle.
1015 % [OUT]
1016 %   none
1017 
1018     %models = get(H.forward_model_popup, 'String');
1019     %ix     = get(H.forward_model_popup, 'Value');
1020     forward_model= STR_FORWARD_MODEL_FOCAL; %models{ix};
1021 
1022     estimation_models = get(H.noise_estimation_model_popup, 'String');
1023     ix                = get(H.noise_estimation_model_popup, 'Value');
1024     estimation_model  = estimation_models{ix};
1025 
1026     switch(forward_model)
1027     case STR_FORWARD_MODEL_FOCAL
1028         switch(estimation_model)
1029         case STR_COVARIANCE_NOISE
1030             set(H.update_sx_checkbox, 'Value', 1);
1031             set(H.update_v_checkbox, 'Value', 0);
1032             set(H.obsn_cov_popup, 'Value', 3); % noise model = 3
1033             set(H.flag_baseline_edit, 'String', '0');
1034             set(H.flag_noise_set_edit, 'String', '0');
1035         case STR_COVARIANCE_NOISE_NO_UPDATE
1036             set(H.update_sx_checkbox, 'Value', 0);
1037             set(H.update_v_checkbox, 'Value', 0);
1038             set(H.obsn_cov_popup, 'Value', 3); % noise model = 3
1039             set(H.flag_baseline_edit, 'String', '0');
1040             set(H.flag_noise_set_edit, 'String', '0');
1041         end
1042     case STR_FORWARD_MODEL_FOCAL_GLOBAL
1043         switch(estimation_model)
1044         case STR_COVARIANCE_NOISE
1045             set(H.update_sx_checkbox, 'Value', 1);
1046             set(H.update_v_checkbox, 'Value', 0);
1047             set(H.obsn_cov_popup, 'Value', 3); % noise model = 3
1048             set(H.flag_baseline_edit, 'String', '0');
1049             set(H.flag_noise_set_edit, 'String', '0');
1050         case STR_COVARIANCE_NOISE_NO_UPDATE
1051             set(H.update_sx_checkbox, 'Value', 0);
1052             set(H.update_v_checkbox, 'Value', 0);
1053             set(H.obsn_cov_popup, 'Value', 3); % noise model = 3
1054             set(H.flag_baseline_edit, 'String', '0');
1055             set(H.flag_noise_set_edit, 'String', '0');
1056         case STR_ISOTROPIC_NOISE
1057             set(H.update_sx_checkbox, 'Value', 1);
1058             set(H.update_v_checkbox, 'Value', 1);
1059             set(H.obsn_cov_popup, 'Value', 1); % noise model = 1
1060             set(H.flag_baseline_edit, 'String', '0');
1061             set(H.flag_noise_set_edit, 'String', '1');
1062         case STR_ISOTROPIC_NOISE_NO_GLOBAL_UPDATE
1063             set(H.update_sx_checkbox, 'Value', 1);
1064             set(H.update_v_checkbox, 'Value', 0);
1065             set(H.obsn_cov_popup, 'Value', 1); % noise model = 1
1066             set(H.flag_baseline_edit, 'String', '0');
1067             set(H.flag_noise_set_edit, 'String', '1');
1068         case STR_ISOTROPIC_NOISE_NO_UPDATE
1069             set(H.update_sx_checkbox, 'Value', 0);
1070             set(H.update_v_checkbox, 'Value', 0);
1071             set(H.obsn_cov_popup, 'Value', 1); % noise model = 1
1072             set(H.flag_baseline_edit, 'String', '0');
1073             set(H.flag_noise_set_edit, 'String', '1');
1074         end
1075     end
1076 
1077 function data = set_gui_meg_file(data, filenames)
1078 % This function adds filenames to the meg file listbox.
1079 % note : meg file is used as sensor noise file by default.
1080 %        This function sets the sensor noise file when the file is not
1081 %        specifield.
1082 % [IN]
1083 %    data : application data(@see bayes_parm_basic_init)
1084 %    filenames : meg files(relative path from project_root)
1085 % [OUT]
1086 %    data : some updated application data
1087 
1088     H = data.H;
1089 
1090     set(H.meg_file_listbox, 'String', filenames);
1091 
1092     % store megfile info to the data cabinet.
1093     if length(filenames)
1094         %
1095         % --- File is inputted
1096         %
1097         project_root = get(H.project_root_edit, 'String');
1098         filename = [project_root filesep filenames{1}];
1099         err = set_meg_file_info(data, filename);
1100         if err, return; end
1101         meg_info = get_meg_file_info(data);
1102         [time_window_from, err] = bayes_parm_editor(data.main_obj, ...
1103                                                     'index_to_time', ...
1104                                                     1, 'meg');
1105         [time_window_to, err]   = bayes_parm_editor(data.main_obj, ...
1106                                                     'index_to_time', ...
1107                                                     meg_info.Nsample, 'meg');
1108         
1109         time_window_from_str = sprintf('%.2f', time_window_from);
1110         time_window_to_str = sprintf('%.2f', time_window_to);
1111 
1112         % analysis time range (default analysis window covers all the data secsions.)
1113         wsize_msec = bayes_parm_editor(data.main_obj, ...
1114                                        'data_len_to_time_len', ...
1115                                        meg_info.Nsample, 'meg');
1116         wsize_msec = sprintf('%.2f', wsize_msec);
1117     else
1118         %
1119         % --- File not specified
1120         %
1121         % for clean up GUI
1122         err = set_meg_file_info(data, '');
1123         time_window_from_str = [];
1124         time_window_to_str = [];
1125         wsize_msec = [];
1126     end
1127 
1128     % time window range for display
1129     set(H.whole_time_range_from_edit, 'String', time_window_from_str);
1130     set(H.whole_time_range_to_edit, 'String', time_window_to_str);
1131 
1132     % Analysis time range
1133     set(H.whole_time_window_from_edit, 'String', time_window_from_str);
1134     set(H.whole_time_window_to_edit, 'String', time_window_to_str);
1135 
1136     % Window size, Shift length
1137     set(H.time_shift_window_size_edit, 'String', wsize_msec);
1138     set(H.time_shift_shift_length_edit, 'String', wsize_msec);
1139     
1140     set(H.sensor_noise_file_listbox, 'String', filenames);
1141     set_noise_file_time_window(data);
1142 
1143 function set_gui_basis_file(H, basis_files)
1144 % This function adds filenames to the basis file listbox.
1145 % [IN]
1146 %              H : component handles.
1147 %    basis_files : basis filename list(relative path from project_root)
1148 % [OUT]
1149 %    none
1150 
1151     set(H.basis_file_listbox, 'String', basis_files);
1152 
1153 function set_gui_act_file(H, act_file)
1154 % This function loads actkeys and set it to the actkey listbox.
1155 % [IN]
1156 %            H : component handles.
1157 %     act_file : actfile(relative path from project_root)
1158 % [OUT]
1159 %    H : component handles.
1160 
1161     % set filename
1162     set(H.act_file_edit, 'String', act_file);
1163     
1164     keys = [];
1165     if ~isempty(act_file)
1166         % get act keys
1167         project_root = get(H.project_root_edit, 'String');
1168         load([project_root filesep act_file], 'Act');
1169         for n = 1 : length(Act)
1170             keys{n} = Act{n}.key;
1171         end
1172     end
1173     
1174     % set act keys to the listbox
1175     set(H.act_key_listbox, 'String', keys);
1176 
1177 function set_gui_area_file(H, area_file)
1178 % This function load areakeys and set it to the areakey popup.
1179 % see :  reload_gui_area_file
1180 % [IN]
1181 %            H : component handles.
1182 %    area_file : areafile(relative path from project_root)
1183 % [OUT]
1184 %    none
1185 
1186     % set filename
1187     set(H.area_file_edit, 'String', area_file);
1188 
1189     keys = [];
1190     if ~isempty(area_file)
1191         % get area keys
1192         keys = {};
1193         project_root = get(H.project_root_edit, 'String');
1194         load([project_root filesep area_file], 'Area');
1195         for n = 1 : length(Area)
1196             keys{n} = Area{n}.key;
1197         end
1198     end
1199     
1200     % set area keys to the popup
1201     set(H.area_key_listbox, 'String', keys);
1202     set(H.area_key_listbox, 'Value', 1);
1203 
1204 function data = reload_gui_area_file(data, area_file)
1205 % This function load areakeys and set it to the areakey popup.
1206 % note:  this function changes the advanced parameter(area_key_global).
1207 % see :  set_gui_area_file
1208 % [IN]
1209 %         data : application data (@see bayes_parm_basic_init)
1210 %    area_file : areafile(relative path from project_root)
1211 % [OUT]
1212 %    data : some updated application data
1213 
1214     H = data.H;
1215 
1216     % set filename
1217     set(H.area_file_edit, 'String', area_file);
1218 
1219     % get area keys
1220     keys = {};
1221     project_root = get(H.project_root_edit, 'String');
1222     load([project_root filesep area_file], 'Area');
1223     for n = 1 : length(Area)
1224         keys{n} = Area{n}.key;
1225     end
1226 
1227     % set area keys to the popup
1228     set(H.area_key_listbox, 'String', keys);
1229     set(H.area_key_listbox, 'Value', 1);
1230     
1231     % advanced parameter(area_key_global) will be keys{1}.
1232     bayes_parm.area_key_global = keys{1};
1233     bayes_parm_editor(data.main_obj, 'merge_bayes_parm', bayes_parm);
1234     
1235 function [match_time, err] = time_match_sample_point(data, time, file_type)
1236 % This function returns time on the nearest sample point at the
1237 % specified time. The value is rounded up.
1238 % (ex. There are sample points : 1.0, 2.0 ,...
1239 %      specifield time: 1.0<x<=2.0
1240 %      match_time is 2.0)
1241 %
1242 % [IN]
1243 %         data : application data (@see bayes_parm_basic_init)
1244 %         time : user input time data
1245 %    file_type : calculate time by 'meg'(megfile) or 'noise'(sensor_noise file)
1246 % [OUT]
1247 %    match_time : user input time data matched with sample data.
1248 %           err : 1 or 2 (1:file does not specified, 2:user input error)
1249 
1250     % nearest index with specified time.
1251     match_time = [];
1252     err = false;
1253     
1254     [index, err] = bayes_parm_editor(data.main_obj, ...
1255                                      'time_to_index', ...
1256                                      time, file_type);
1257     if err, return; end
1258     [match_time, err] = bayes_parm_editor(data.main_obj, ...
1259                                           'index_to_time', ...
1260                                           index, file_type);
1261     if err, return; end
1262     
1263 function [ceil_time_len, err] = ceil_time_length(data, time_len, file_type)
1264 % This function rounds up the specified time length to the multiple
1265 % of the sample length .
1266 %
1267 % [IN]
1268 %         data : application data (@see bayes_parm_basic_init)
1269 %    time_len  : time length(msec)
1270 %    file_type : calculate time_len by 'meg'(megfile)
1271 %                                   or 'noise'(sensor_noise file)
1272 % [OUT]
1273 %    ceil_time_len : rounded up time length
1274 %              err : 1 or 2 (1:file does not specified, 2:user input error)
1275 
1276     ceil_time_len = [];
1277     err = false;
1278 
1279     [data_len, err] = bayes_parm_editor(data.main_obj, ...
1280                                         'time_len_to_data_len',...
1281                                         time_len, ...
1282                                         file_type);
1283 
1284     % Calculate analysis time window size(sample)
1285     analysis_time_from_msec = ...
1286         str2double(get(data.H.whole_time_window_from_edit, 'String'));
1287     analysis_time_to_msec = ...
1288         str2double(get(data.H.whole_time_window_to_edit, 'String'));
1289 
1290     [analysis_time_from_sample, err] = bayes_parm_editor(data.main_obj, ...
1291                                             'time_len_to_data_len', ...
1292                                             analysis_time_from_msec, ...
1293                                             file_type);
1294 
1295     if err, return; end
1296     [analysis_time_to_sample, err] = bayes_parm_editor(data.main_obj, ...
1297                                             'time_len_to_data_len', ...
1298                                             analysis_time_to_msec, ...
1299                                             file_type);
1300     analysis_time_sample = ...
1301         analysis_time_to_sample - analysis_time_from_sample + 1;
1302 
1303     % Convert inputted time(msec) to sample number.
1304     [time_sample, err] = bayes_parm_editor(data.main_obj, ...
1305                                             'time_len_to_data_len', ...
1306                                             time_len, ...
1307                                             file_type);
1308 
1309     if time_sample > analysis_time_sample
1310         time_sample = analysis_time_sample;
1311     end
1312     [ceil_time_len, err] = bayes_parm_editor(data.main_obj, ...
1313                                         'data_len_to_time_len', ...
1314                                         time_sample, ...
1315                                         file_type);
1316     if err, return;end;
1317 
1318 function [meg_info, err] = get_meg_file_info(data)
1319 % get megfile info from bayes_parm_editor object
1320 % [IN]
1321 %    data : application data (@see bayes_parm_basic_init)
1322 % [OUT]
1323 %    meg_info : megfile information.
1324 %    err      : true(megfile data is not set.) or false
1325 
1326     err = false;
1327     meg_info = bayes_parm_editor(data.main_obj, 'get_megfile_info');
1328     if isempty(meg_info)
1329         errordlg('select meg file.', 'Error');
1330         err = true;
1331     end
1332 
1333 function [err] = set_meg_file_info(data, meg_file)
1334 % set megfile info to bayes_parm_editor main object.
1335 % [IN]
1336 %        data : application data (@see bayes_parm_basic_init);
1337 %    meg_file : meg file name.
1338 % [OUT]
1339 %    err : true(meg_file is invalid.) or false
1340 
1341     err = false;
1342     try
1343         bayes_parm_editor(data.main_obj, 'set_megfile_info', meg_file);
1344     catch
1345         err = true;
1346         errordlg('file read error occured.', 'Error');
1347     end
1348 
1349 function [s_noise_file_info, err] = get_sensor_noise_file_info(data)
1350 % get sensor noise file info from bayes_parm_editor main object.
1351 % [IN]
1352 %    data : application data (@see bayes_parm_basic_init);
1353 % [OUT]
1354 %    s_noise_info : sensor noise file information.
1355 %             err : true(sensor noise file data is not set.) or false
1356 
1357    err = false;
1358    s_noise_file_info = bayes_parm_editor(data.main_obj, ...
1359                                          'get_sensor_noise_file_info');
1360    if isempty(s_noise_file_info)
1361        errordlg('select meg file.', 'Error'); % current(v0.50) GUI,
1362                                               % Sensor noise file = Meg noise file
1363        err = true;
1364    end
1365 
1366 function [err] = set_sensor_noise_file_info(data, s_noise_file)
1367 % This function sets the sensor noise file info to the data cabinet.
1368 % see : get_sensor_noise_file_info
1369 %     : bayes_parm_basic_gui('set_sensor_noise_file_info')
1370 % [IN]
1371 %            data : application data (@see bayes_parm_basic_init)
1372 %    s_noise_file : sensor noise file name.
1373 % [OUT]
1374 %     err : true(sensor noise file is invalid.) or false
1375 
1376     err = false;
1377     try
1378         bayes_parm_editor(data.main_obj, ...
1379                           'set_sensor_noise_file_info', s_noise_file);
1380     catch
1381         err = true;
1382         errordlg('file read error occured.', 'Error');
1383     end
1384 
1385 function [forward_model] = get_forward_model(H)
1386 % This function returns forward model parameter
1387 % [IN]
1388 %    H : handles of components
1389 % [OUT]
1390 %    forward_model : forward model parameter
1391 %
1392 
1393     %models = get(H.forward_model_popup, 'String');
1394     %forward_model = models{get(H.forward_model_popup, 'Value')};
1395     forward_model = STR_FORWARD_MODEL_FOCAL;
1396 
1397 function H = set_forward_model(H, forward_model, force_update)
1398 % This function sets GUI forward model.
1399 % [IN]
1400 %    H : handles of components
1401 %    forward_model : to be set foward_model
1402 %    force_update : all parameters should updates forcelly,
1403 %                   specify this value true.
1404 % [OUT]
1405 %    H : handles of components
1406 
1407     if ~exist('force_update', 'var')
1408         force_update = false;
1409     end
1410 
1411     % forward model change.
1412     % update timing:
1413     %   1.force_update flag is true.
1414     %   2.If current_model is different from forward_model.
1415     %
1416     current_model = get_forward_model(H);
1417     if ((force_update == true) || ~(strcmp(current_model, forward_model)))
1418         % all parameters change
1419         change_forward_model(H, forward_model);
1420     end
1421 
1422 function [estimation_model_number] = get_noise_estimation_model(H)
1423 % This function returns estimation_model number.
1424 % [IN]
1425 %    H : handles of components
1426 % [OUT]
1427 %    estimation_model_number : defined estimation model number
1428 %
1429 
1430     models = get(H.noise_estimation_model_popup, 'String');
1431     noise_estimation_model = models{get(H.noise_estimation_model_popup, 'Value')};
1432 
1433     switch(noise_estimation_model)
1434         case STR_COVARIANCE_NOISE
1435             estimation_model_number = 1;
1436         case STR_COVARIANCE_NOISE_NO_UPDATE
1437             estimation_model_number = 2;
1438         case STR_ISOTROPIC_NOISE
1439             estimation_model_number = 3;
1440         case STR_ISOTROPIC_NOISE_NO_GLOBAL_UPDATE
1441             estimation_model_number = 4;
1442         case STR_ISOTROPIC_NOISE_NO_UPDATE
1443             estimation_model_number = 5;
1444     end
1445 
1446 function [treatable] = IsTreatableEstimationModel(bayes_parm)
1447 % This function checks estimation model parameters section of bayes_parm.
1448 % GUI has a restriction about combination between foward model and
1449 % noise estimation model.
1450 %
1451 % [IN]
1452 %    bayes_parm : check target
1453 % [OUT]
1454 %    treatable  : true or false. (true means treatable.)
1455 
1456     treatable = false;
1457 
1458     switch(bayes_parm.forward_model)
1459     case STR_FORWARD_MODEL_FOCAL
1460         switch(bayes_parm.noise_estimation_model)
1461         case 1   % COVARIANCE_NOISE
1462             if (bayes_parm.update_sx == ON) && ...
1463                (bayes_parm.update_v  == OFF) && ...
1464                (bayes_parm.noise_model == 3) && ...
1465                (bayes_parm.flag_baseline == 0) && ...
1466                (bayes_parm.flag_noise_set == 0)
1467                
1468                treatable = true;
1469             end
1470         case 2   % COVARIANCE_NOISE_NO_UPDATE
1471             if (bayes_parm.update_sx == OFF) && ...
1472                (bayes_parm.update_v  == OFF) && ...
1473                (bayes_parm.noise_model == 3) && ...
1474                (bayes_parm.flag_baseline == 0) && ...
1475                (bayes_parm.flag_noise_set == 0)
1476                
1477                treatable = true;
1478             end
1479         end
1480     case STR_FORWARD_MODEL_FOCAL_GLOBAL
1481         switch(bayes_parm.noise_estimation_model)
1482         case 1   % COVARIANCE_NOISE
1483             if (bayes_parm.update_sx == ON) && ...
1484                (bayes_parm.update_v  == OFF) && ...
1485                (bayes_parm.noise_model == 3) && ...
1486                (bayes_parm.flag_baseline == 0) && ...
1487                (bayes_parm.flag_noise_set == 0)
1488                
1489                treatable = true;
1490             end
1491         case 2   % COVARIANCE_NOISE_NO_UPDATE
1492             if (bayes_parm.update_sx == OFF) && ...
1493                (bayes_parm.update_v  == OFF) && ...
1494                (bayes_parm.noise_model == 3) && ...
1495                (bayes_parm.flag_baseline == 0) && ...
1496                (bayes_parm.flag_noise_set == 0)
1497                
1498                treatable = true;
1499             end
1500         case 3   % ISOTROPIC_NOISE
1501             if (bayes_parm.update_sx == ON) && ...
1502                (bayes_parm.update_v  == ON) && ...
1503                (bayes_parm.noise_model == 1) && ...
1504                (bayes_parm.flag_baseline == 0) && ...
1505                (bayes_parm.flag_noise_set == 1)
1506                
1507                treatable = true;
1508             end
1509         case 4   % ISOTROPIC_NOISE_NO_GLOBAL_UPDATE
1510             if (bayes_parm.update_sx == ON) && ...
1511                (bayes_parm.update_v  == OFF) && ...
1512                (bayes_parm.noise_model == 1) && ...
1513                (bayes_parm.flag_baseline == 0) && ...
1514                (bayes_parm.flag_noise_set == 1)
1515                
1516                treatable = true;
1517             end
1518         case 5   % ISOTROPIC_NOISE_NO_UPDATE
1519             if (bayes_parm.update_sx == OFF) && ...
1520                (bayes_parm.update_v  == OFF) && ...
1521                (bayes_parm.noise_model == 1) && ...
1522                (bayes_parm.flag_baseline == 0) && ...
1523                (bayes_parm.flag_noise_set == 1)
1524                
1525                treatable = true;
1526             end
1527         end
1528     end
1529 
1530 
1531 %%%%%%%%%%%%%%%%%%%%%%%
1532 % Define constants
1533 %
1534 
1535 %
1536 % -- forward model strings (This string should be set to global.)
1537 %
1538 function [v] = STR_FORWARD_MODEL_FOCAL
1539     v = 'focal';
1540 function [v] = STR_FORWARD_MODEL_FOCAL_GLOBAL
1541     v = 'focal+global';
1542 
1543 %
1544 % -- Noise model estimation strings
1545 %
1546 function [v] = STR_COVARIANCE_NOISE
1547     v = 'COVARIANCE NOISE';
1548 function [v] = STR_COVARIANCE_NOISE_NO_UPDATE
1549     v = 'COVARIANCE NOISE(NO UPDATE)';
1550 function [v] = STR_ISOTROPIC_NOISE
1551     v = 'ISOTROPIC NOISE';
1552 function [v] = STR_ISOTROPIC_NOISE_NO_GLOBAL_UPDATE
1553     v = 'ISOTROPIC NOISE(NO GLOBAL UPDATE)';
1554 function [v] = STR_ISOTROPIC_NOISE_NO_UPDATE
1555     v = 'ISOTROPIC NOISE(NO UPDATE)';
1556

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005