Home > vbmeg > functions > gui > current_gui_dir > current_gui.m

current_gui

PURPOSE ^

This function is for using current gui.

SYNOPSIS ^

function varargout = current_gui(varargin)

DESCRIPTION ^

 This function is for using current gui.
 Usage :
    key : 'set_parm', 'get_parm'

      current_gui(fig, 'set_parm', <current_parm>)
        current_parm will be set to launched gui.

      current_gui(fig, 'get_parm')
        make current_parm structure from launched gui
        and returns current_parm.

 inner functions:
   set_parm_gui
   get_parm_gui
   exec
   vb_index_to_time
   vb_time_to_index
   subsmpl_index_to_index
   index_to_subsmpl_index
   data_len_to_time_len
   time_len_to_data_len
   callback
   set_result_file
   read_time_parameters
   change_save_mode
   select_time_window_time_course
   reload_gui_area_file
 Related functions:
   vb_job_current
   job_plot_meg

 --- History
 ??-??-?? Ryosuke Hayashi
 2009-04-02 Taku Yoshioka
  Parameter name changed within this code for readability
  (just replacing 'resultfile' to bayesfile)

 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 = current_gui(varargin)
0002 % This function is for using current gui.
0003 % Usage :
0004 %    key : 'set_parm', 'get_parm'
0005 %
0006 %      current_gui(fig, 'set_parm', <current_parm>)
0007 %        current_parm will be set to launched gui.
0008 %
0009 %      current_gui(fig, 'get_parm')
0010 %        make current_parm structure from launched gui
0011 %        and returns current_parm.
0012 %
0013 % inner functions:
0014 %   set_parm_gui
0015 %   get_parm_gui
0016 %   exec
0017 %   vb_index_to_time
0018 %   vb_time_to_index
0019 %   subsmpl_index_to_index
0020 %   index_to_subsmpl_index
0021 %   data_len_to_time_len
0022 %   time_len_to_data_len
0023 %   callback
0024 %   set_result_file
0025 %   read_time_parameters
0026 %   change_save_mode
0027 %   select_time_window_time_course
0028 %   reload_gui_area_file
0029 % Related functions:
0030 %   vb_job_current
0031 %   job_plot_meg
0032 %
0033 % --- History
0034 % ??-??-?? Ryosuke Hayashi
0035 % 2009-04-02 Taku Yoshioka
0036 %  Parameter name changed within this code for readability
0037 %  (just replacing 'resultfile' to bayesfile)
0038 %
0039 % Copyright (C) 2011, ATR All Rights Reserved.
0040 % License : New BSD License(see VBMEG_LICENSE.txt)
0041 
0042 %if nargin == 0
0043 %    key = 'init';
0044 %else
0045 %    key = varargin{1};
0046 %end
0047 %
0048 %if ~strcmp(key, 'init')
0049 %    h = get(0, 'CurrentFigure');
0050 %    data = figure_load_data(h);
0051 %end
0052 fig = varargin{1};
0053 key = varargin{2};
0054 data = guidata(fig);
0055 
0056 switch(key)
0057     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0058     % --- public
0059     % These interfaces are able to use from external function.
0060     %
0061     case 'set_parm'
0062         current_parm = varargin{3};
0063         data = set_parm_gui(data, current_parm);
0064         data.current_parm = current_parm;
0065     case 'get_parm'
0066         varargout{1} = data.current_parm(data);
0067     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0068     % --- protected
0069     % These interfaces are for current_gui.
0070     % Don't use from external function.
0071     %
0072     case 'callback'
0073         hObj = varargin{3};
0074         data = callback(data.H, hObj, data);
0075         if ~ishandle(fig), return; end
0076         current_parm = get_parm_gui(data);
0077         guidata(fig, data);
0078         current_gui(fig, 'merge_parm', current_parm);
0079     case 'merge_parm'
0080         merge_parm = varargin{3};
0081         parm_names = fieldnames(merge_parm);
0082         for k=1:length(parm_names)
0083             data.current_parm.(parm_names{k}) = merge_parm.(parm_names{k});
0084         end
0085 end
0086 
0087 % Save application data to the figure.
0088 guidata(fig, data);
0089 
0090 function [data] = set_parm_gui(data, current_parm)
0091 % Set parameters to GUI function.
0092 % [IN]
0093 %            data : application data
0094 %    current_parm : current parameter structure.
0095 % [OUT]
0096 %    data : some updated application data
0097 
0098     H = data.H;
0099 
0100     % Set default
0101     if isempty(current_parm) || ~exist('current_parm', 'var')
0102         current_parm = vb_set_current_parm;
0103     end
0104 
0105     % result file
0106     if isfield(current_parm, 'bayesfile') && ~isempty(current_parm.bayesfile)
0107         proj_root = get(H.proj_root_edit, 'String');
0108         if isfield(current_parm, 'megfile')
0109             megfile = current_parm.megfile;
0110         else
0111             megfile = [];
0112         end
0113         [err, t_parm] = set_result_file(H, proj_root, current_parm.bayesfile, megfile);
0114         if ~err, data.time_parm = t_parm; end
0115     end
0116 
0117     % current file
0118     if isfield(current_parm, 'currfile') && ~isempty(current_parm.currfile)
0119         [path_name, file_name, ext] = fileparts(current_parm.currfile);
0120         set(H.save_directory_edit, 'String', path_name);
0121         set(H.current_file_edit, 'String', current_parm.currfile);
0122         update_output_filename(H);
0123     end
0124 
0125     % trial average
0126     if isfield(current_parm, 'trial_average') && ~isempty(current_parm.trial_average)
0127         if current_parm.trial_average == ON
0128             change_trial_average(H, ON);
0129         else
0130             change_trial_average(H, OFF);
0131         end
0132     end
0133 
0134     % tsubsmpl
0135     if isfield(current_parm, 'tsubsmpl') && ~isempty(current_parm.tsubsmpl)
0136         tsubsmpl = current_parm.tsubsmpl;
0137         twin_msec = []; % [from, to] by msec
0138         twin_meg  = []; % [from, to] by sample
0139         step_time = data_len_to_time_len(...
0140                          tsubsmpl(2) - tsubsmpl(1), ...
0141                          data.time_parm); % sample
0142         Nsample = length(tsubsmpl);
0143         % Convert sample number to msec.
0144         [twin_meg(1), err, err_msg] = ...
0145             subsmpl_index_to_index(tsubsmpl(1), data.time_parm);
0146         [twin_msec(1), err, err_msg] = ...
0147             vb_index_to_time(twin_meg(1), data.time_parm);
0148         [twin_meg(2), err, err_msg] = ...
0149             subsmpl_index_to_index(tsubsmpl(Nsample), data.time_parm);
0150         [twin_msec(2), err, err_msg] = ...
0151             vb_index_to_time(twin_meg(2), data.time_parm);
0152         % set time to gui
0153         set(H.time_window_from_edit, 'String', sprintf('%.2f', twin_msec(1)));
0154         set(H.time_window_to_edit, 'String', sprintf('%.2f', twin_msec(2)));
0155         set(H.time_step_edit, 'String', sprintf('%.2f', step_time));
0156     end
0157 
0158     % jactdir
0159     if isfield(current_parm, 'jactdir') && ~isempty(current_parm.jactdir)
0160         if ~isempty(current_parm.jactdir)
0161             set(H.jact_directory_edit, 'String', current_parm.jactdir);
0162             change_save_mode(H, SAVE_MODE_MULTIPLE);
0163         end
0164     end
0165 
0166     % area_file, area_key
0167     if isfield(current_parm, 'areafile') && ~isempty(current_parm.areafile)
0168         if isfield(current_parm, 'area_key')
0169             reload_gui_area_file(H, current_parm.areafile, current_parm.area_key);
0170         else
0171             reload_gui_area_file(H, current_parm.areafile);
0172         end
0173     end
0174 
0175     % flag
0176     current_parm.flag = 0;
0177 
0178     update_exec_button_state(H);
0179 
0180 % end of set_parm_gui()
0181 
0182 function current_parm = get_parm_gui(data)
0183 % Get parameters function from GUI.
0184 % [IN]
0185 %    data : application data
0186 % [OUT]
0187 %    current_parm : current parameter structure.
0188 
0189     H = data.H;
0190     
0191     current_parm = struct;
0192 
0193     % result file
0194     current_parm.bayesfile = get(H.result_file_edit, 'String');
0195 
0196     % MEG/EEG file
0197     meg_file = get(H.meg_file_edit, 'String');
0198     if ~isempty(meg_file)
0199         current_parm.megfile = meg_file;
0200     end
0201     
0202     % current file
0203     current_file = get(H.current_file_edit, 'String');
0204     current_parm.currfile = current_file;
0205 
0206     % trial average
0207     if get(H.trial_average_on_button, 'Value') == 1
0208         current_parm.trial_average = ON;
0209     else
0210         current_parm.trial_average = OFF;
0211     end
0212 
0213     % tsubsmpl
0214     twin_subsmple = [];
0215     twin_meg  = [];
0216     step_size_str = get(H.time_step_edit, 'String');
0217     twin_from_str = get(H.time_window_from_edit, 'String');
0218     twin_to_str   = get(H.time_window_to_edit, 'String');
0219 
0220     if ~isempty(data.time_parm)
0221         % Step size by sampling length
0222         step_size = time_len_to_data_len(...
0223                         str2double(step_size_str),...
0224                         data.time_parm);
0225         % msec-->index-->subsmpl_index
0226         [twin_meg(1), err, err_msg] = ...
0227             vb_time_to_index(str2double(twin_from_str), data.time_parm);
0228         [twin_meg(2), err, err_msg] = ...
0229             vb_time_to_index(str2double(twin_to_str), data.time_parm);
0230         [twin_subsmple(1), err, err_msg] = ...
0231             index_to_subsmpl_index(twin_meg(1), data.time_parm);
0232         [twin_subsmple(2), err, err_msg] = ...
0233             index_to_subsmpl_index(twin_meg(2), data.time_parm);
0234     
0235         current_parm.tsubsmpl = [twin_subsmple(1):step_size:twin_subsmple(2)];
0236     end
0237 
0238     % jactdir
0239     if get(H.save_file_multiple_button, 'Value') == 1
0240         current_parm.jactdir = get(H.jact_directory_edit, 'String');
0241         if isempty(current_parm.jactdir)
0242             current_parm.jactdir = '.';
0243         end
0244     end
0245 
0246     % area_file, area_key
0247     current_parm.areafile = get(H.area_file_edit, 'String');
0248     area_keys = get(H.area_key_listbox, 'String');
0249     if ischar(area_keys)
0250         current_parm.area_key = area_keys;
0251     else
0252         current_parm.area_key = area_keys{get(H.area_key_listbox, 'Value')};
0253     end
0254 
0255     % flag
0256     current_parm.flag = 0;
0257 
0258 
0259 % end of get_parm_gui()
0260 
0261 function [err] = exec(H, data)
0262 % This function execute vb_job_current() by using gui parameters.
0263 % [IN]
0264 %    H : all handles of components
0265 % [OUT]
0266 %   err : true or false
0267 
0268     err = false;
0269 
0270     proj_root = get(H.proj_root_edit, 'String');
0271     current_parm = get_parm_gui(data);
0272 
0273     str = get(H.exec_push, 'String');
0274     set(H.exec_push, 'String', 'Processing...');
0275     drawnow;
0276     % Execute current estimation
0277     vb_job_current(proj_root, current_parm);
0278     set(H.exec_push, 'String', 'Exec');
0279 
0280 % end of exec()
0281 
0282 function [data] = callback(H, hObj, data)
0283 % GUI event processing function.
0284 % This function is called when user pushes, editing, any action.
0285 % [IN]
0286 %       H : gui component handles.
0287 %    hObj : action component
0288 %    data : application data
0289 % [OUT]
0290 %    data : some updated application data
0291 
0292     global vbmeg_inst;
0293     define = vbmeg_inst.const;
0294 
0295     switch(hObj)
0296         case H.proj_root_push
0297             dir_name = dir_dialog(get(H.proj_root_edit, 'String'));
0298             if dir_name ~= 0
0299                 set(H.proj_root_edit, 'String', dir_name);
0300             end
0301         case H.result_file_push
0302             proj_root = get(H.proj_root_edit, 'String');
0303             [dirname, fnames, cancelled] = pa_prjfile_select(proj_root, ...
0304                                                              {define.BAYES_EXTENSION}, ...
0305                                                              'Select current variance file');
0306             if ~cancelled
0307                 result_file = [dirname, filesep, fnames{1}]; % relative from proj_root
0308                 [err, time_parm] = set_result_file(H, proj_root, result_file);
0309                 if ~err
0310                     data.time_parm = time_parm;
0311                 end
0312                 % make output current filename from bayes.mat
0313                 [p_, f_, e_] = vb_get_file_parts(result_file);
0314                 ix = find(f_ == '.');
0315                 if ~isempty(ix)
0316                     set(H.current_file_edit, 'String', ...
0317                                              [f_(1:ix(1)-1), define.CURRENT_EXTENSION]);
0318                 end
0319                 update_output_filename(H);
0320             end
0321         case H.meg_file_push
0322             proj_root = get(H.proj_root_edit, 'String');
0323             [dir fname] = pa_prjfile_select(proj_root, ...
0324                 {define.MEG2_EXTENSION, define.EEG_EXTENSION}, ...
0325                 'Select MEG/EEG file');
0326             if ~isempty(dir)
0327                 meg_file = [dir, filesep, fname{1}];
0328                 set(H.meg_file_edit, 'String', meg_file);
0329                 result_file = get(H.result_file_edit, 'String');
0330                 [err, time_parm] = set_result_file(H, proj_root, result_file, meg_file);
0331                 if ~err
0332                     data.time_parm = time_parm;
0333                 end
0334             end
0335         case {H.trial_average_on_button, H.trial_average_off_button}
0336             if hObj == H.trial_average_on_button
0337                 if get(H.save_file_multiple_button, 'Value')
0338                     change_trial_average(H, OFF);
0339                     uiwait(...
0340                         msgbox(['Set Current file format = "single file" '...
0341                                 'before changing trial average ON.'],...
0342                                 'message', 'modal'));
0343                 else
0344                     change_trial_average(H, ON);
0345                 end
0346             else
0347                 change_trial_average(H, OFF);
0348             end
0349         case {H.time_window_from_edit, H.time_window_to_edit}
0350             time_value = str2double(get(hObj, 'String'));
0351             time_index = vb_time_to_index(time_value, data.time_parm);
0352             time_value = vb_index_to_time(time_index, data.time_parm);
0353             set(hObj, 'String', sprintf('%.2f', time_value));
0354         case H.select_time_window_push
0355             time_parm = data.time_parm;
0356             if isempty(time_parm)
0357                 errordlg('first, set result file.', 'error');
0358             else
0359                 select_time_window_time_course(H, time_parm);
0360             end
0361         case H.time_step_edit
0362             [time_len] = str2double(get(hObj, 'String'));
0363             if time_len <= 0
0364                 errordlg('Time step should be positive value.', 'error');
0365                 return;
0366             else
0367                 % Convert inputted time length to multiple number of
0368                 % minimum unit of time length.
0369                 [data_len] = time_len_to_data_len(time_len, data.time_parm);
0370                 [time_len] = data_len_to_time_len(data_len, data.time_parm);
0371                 set(hObj, 'String', sprintf('%.2f', time_len));
0372             end
0373         case H.area_file_push
0374             proj_root = get(H.proj_root_edit, 'String');
0375             [dirname, fnames, cancelled] = pa_prjfile_select(...
0376                                                     proj_root, ...
0377                                                     {define.AREA_EXTENSION}, ...
0378                                                     'Select cortical area file');
0379             if ~cancelled
0380                 area_file = [dirname '/' fnames{1}];
0381                 reload_gui_area_file(H, area_file);
0382             end
0383         case H.area_file_reset_push
0384             set(H.area_file_edit, 'String', []);
0385             set(H.area_key_listbox, 'String', []);
0386             set(H.area_key_listbox, 'Value', 1);
0387         case {H.save_file_single_button, H.save_file_multiple_button}
0388             if hObj == H.save_file_single_button
0389                 % single file
0390                 change_save_mode(H, SAVE_MODE_SINGLE);
0391             else
0392                 % multiple files
0393                 if get(H.trial_average_on_button, 'Value')
0394                     change_save_mode(H, SAVE_MODE_SINGLE);
0395                     uiwait(...
0396                         msgbox(['Set trial average = "OFF" ' ...
0397                                 'before changing Current file format to Multiple files.'] ,...
0398                                 'message', 'modal'));
0399                 else
0400                     change_save_mode(H, SAVE_MODE_MULTIPLE);
0401                 end
0402             end
0403         case H.save_directory_push
0404             proj_root = get(H.proj_root_edit, 'String');
0405             [dirname, cancelled] = pa_prjdir_select(proj_root);
0406             if ~cancelled
0407                 set(H.save_directory_edit, 'String', dirname);
0408                 update_output_filename(H);
0409             end
0410         case H.exec_push
0411             err = exec(H, data);
0412         case H.advanced_parameter_push
0413             this = data.H.figure;
0414             if ishandle(data.adv_fig)
0415                 figure(data.adv_fig);
0416             else
0417                 data.adv_fig = current_gui_advanced_new(this, data.current_parm);
0418             end
0419         %%%%%%%%
0420         % Menu
0421         case {H.figure, H.menu_close}
0422              current_gui_delete(data.H.figure);
0423              return;
0424         case H.menu_current_timecourse_estimation
0425             url = vb_users_manual_url('Current timecourse estimation');
0426             vb_browser_show(url);
0427     end
0428 
0429     update_exec_button_state(H);
0430 
0431 % end of callback()
0432 
0433 function update_exec_button_state(H)
0434 % This function check status of gui and change exec button status.
0435 % [IN]
0436 %    H : handles of GUI
0437     button_state = 'off';
0438     if ~isempty(get(H.result_file_edit, 'String')) & ...
0439        ~isempty(get(H.time_window_from_edit, 'String')) & ...
0440        ~isempty(get(H.time_window_to_edit, 'String')) & ...
0441        ~isempty(get(H.time_step_edit, 'String')) & ...
0442        ~isempty(get(H.save_directory_edit, 'String')) & ...
0443        ~isempty(get(H.current_file_edit, 'String'))
0444 
0445        button_state = 'on';
0446 %        % Save file single
0447 %        if get(H.save_file_single_button, 'Value')
0448 %            button_state = 'on';
0449 %        else
0450 %        % Save file multiple
0451 %            if ~isempty(get(H.jact_directory_edit, 'String'))
0452 %                button_state = 'on';
0453 %            end
0454 %        end
0455    end
0456 
0457    set(H.exec_push, 'Enable', button_state);
0458 
0459 % end of update_exec_button_state()
0460 
0461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0462 % subsmpl_index, index, time Conversion
0463 %
0464 % bayes_parm.twin_meg  is meg_data index( = index)
0465 % current_parm.tsubsmpl is bayes_parm.twin_meg index ( = subsmpl_index)
0466 
0467 function [time, err, err_msg] = vb_index_to_time(index, time_parm)
0468 % Convert meg_data index to meg_data time.
0469 % [IN]
0470 %        index : meg_data index number.
0471 %    time_parm : time parameter.
0472 % [OUT]
0473 %        time : time corresponds to sampling data index.
0474 %         err : true or false
0475 %     err_msg : error reason
0476 % [exception]
0477 %     inputted index cannot be processed.
0478 %     check function usage.
0479 
0480     time = [];
0481     err = false;
0482     err_msg = [];
0483 
0484     if isempty(time_parm)
0485         err = true;
0486         err_msg = 'result file is not specified.';
0487         return;
0488     end
0489 
0490     if ~( (time_parm.twin_meg(1) <= index) &&  (index <= time_parm.twin_meg(2)) )
0491         error('vb_index_to_time : inputted index is out of range.');
0492     end
0493 
0494     time = (index - time_parm.pretrigger - 1) * (1000/time_parm.sample_freq);
0495 
0496 % end of vb_index_to_time()
0497 
0498 function [index, err, err_msg] = vb_time_to_index(time, time_parm)
0499 % Convert meg_data time to meg_data index.
0500 % [IN]
0501 %         time : meg_data time.
0502 %    time_parm : time parameter.
0503 % [OUT]
0504 %      index : meg_data index number
0505 %        err : true or false
0506 %    err_msg : error reason
0507 %
0508 
0509     index = [];
0510     err = false;
0511     err_msg = [];
0512 
0513     if isempty(time_parm)
0514         err = true;
0515         err_msg = 'result file is not specified.';
0516         return;
0517     end
0518 
0519     index = round(time * (time_parm.sample_freq/1000) + time_parm.pretrigger + 1);
0520 
0521     % out of range is checked and collect(set min or max).
0522     if index < time_parm.twin_meg(1), index = time_parm.twin_meg(1); end;
0523     if time_parm.twin_meg(2) < index, index = time_parm.twin_meg(2); end;
0524 
0525 % end of vb_time_to_index()
0526 
0527 function [data_len, err, err_msg] = time_len_to_data_len(time_len, time_parm)
0528 % Convert time length to sampling length.
0529 % [IN]
0530 %     time_len : time length.
0531 %    time_parm : time parameter.
0532 % [OUT]
0533 %    data_len : data length(sample)
0534 %         err : true or false
0535 %     err_msg : error reason
0536 
0537     data_len = [];
0538     err = false;
0539     err_msg = [];
0540 
0541     if time_len <= 0;
0542         err = true; 
0543         err_msg = 'Time length should be positive value.';
0544         return;
0545     end
0546     if isempty(time_parm)
0547         err = true;
0548         err_msg = 'result file is not specified.';
0549         return;
0550     end
0551 
0552     data_len = ceil(time_len * (time_parm.sample_freq/1000));
0553     twin_meg = time_parm.twin_meg;
0554 
0555 % end of time_len_to_data_len()
0556 
0557 function [time_len, err, err_msg] = data_len_to_time_len(data_len, time_parm)
0558 % Convert sampling number to time length.
0559 % [IN]
0560 %     data_len : sampling number.
0561 %    time_parm : time parameter.
0562 % [OUT]
0563 %    time_len : time length
0564 %         err : true or false
0565 %     err_msg : error reason
0566 % [exception]
0567 %     inputted data_len cannot be processed.
0568 %     check function usage.
0569 
0570     time_len = [];
0571     err = false;
0572     err_msg = [];
0573 
0574     data_len_int = double(int64(data_len));
0575     if( data_len <=0 || (data_len - data_len_int) > 0 )
0576         error('data_len_to_time_len : data_len should be positive integer.');
0577     end
0578     if isempty(time_parm)
0579         err = true;
0580         err_msg = 'result file is not specified.';
0581         return;
0582     end
0583 
0584     data_len = ceil(data_len);
0585     time_len = data_len * (1000/time_parm.sample_freq);
0586 
0587 % end of data_len_to_time_len()
0588 
0589 function [subsmpl_index, err, err_msg] = index_to_subsmpl_index(index, time_parm)
0590 % Convert meg_data index to tsubsmpl index
0591 % [IN]
0592 %        index : meg_data index number.
0593 %    time_parm : time parameter.
0594 % [OUT]
0595 %    subsmpl_index : current_parm.tsubsmpl index.
0596 %              err : true or false
0597 %          err_msg : error reason
0598 % [exception]
0599 %     inputted index cannot be processed.
0600 %     check function usage.
0601 
0602     subsmpl_index = [];
0603     err = false;
0604     err_msg = [];
0605 
0606     index_int = double(int64(index));
0607     if( index <= 0 || (index_int - index) > 0 )
0608         error('index_to_subsmpl_index : index should be positive integer.');
0609     end
0610     if isempty(time_parm)
0611         err = true;
0612         err_msg = 'result file is not specified.';
0613         return;
0614     end
0615 
0616     if ~( (time_parm.twin_meg(1) <= index) &&  (index <= time_parm.twin_meg(2)) )
0617         error('index_to_subsmpl_index : inputted index is out of range.');
0618     end
0619     subsmpl_index = index - time_parm.twin_meg(1) + 1;
0620 
0621 % end of index_to_subsmpl_index()
0622 
0623 function [index, err, err_msg] = subsmpl_index_to_index(subsmpl_index, time_parm);
0624 % Convert curret_parm.tsubsmpl index to meg_data index
0625 % [IN]
0626 %    subsmpl_index : current_parm.tsubsmpl index.
0627 %        time_parm : time parameter.
0628 % [OUT]
0629 %      index : meg_data index number.
0630 %        err : true or false
0631 %    err_msg : error reason
0632 % [exception]
0633 %     inputted subsmpl_index cannot be processed.
0634 %     check function usage.
0635 
0636     index = [];
0637     err = false;
0638     err_msg = [];
0639 
0640     subsmpl_int = double(int64(subsmpl_index));
0641     if( subsmpl_index <= 0 || (subsmpl_index - subsmpl_int) > 0 )
0642         error('subsmpl_index_to_index : subsmple_index should be positive integer.');
0643     end
0644     if isempty(time_parm)
0645         err = true;
0646         err_msg = 'result file is not specified.';
0647         return;
0648     end
0649 
0650     index = ceil(subsmpl_index) + time_parm.twin_meg(1) - 1;
0651     if ~( (time_parm.twin_meg(1) <= index) &&  (index <= time_parm.twin_meg(2)) )
0652         error('subsmpl_index_to_index : inputted subsmpl_index is out of range.');
0653     end
0654 
0655 % end of subsmpl_index_to_index()
0656 
0657 function [err, time_parm] = set_result_file(H, proj_root, result_file, meg_file)
0658 % This function read result file and initialize gui of timewindow part.
0659 % [IN]
0660 %              H : gui component handles
0661 %      proj_root : project root directory
0662 %    result_file : result_file(relative path from proj_root)
0663 %       meg_file : external meg file(optional:relative path from prj_root)
0664 %
0665 % [OUT]
0666 %          err : true(file read failed.) or false
0667 %    time_parm : time parameter
0668 
0669     err = false;
0670 
0671     % Read time parameter from result file
0672     if ~exist('meg_file', 'var')
0673         meg_file = [];
0674     end
0675     [time_parm, err, err_msg] = read_time_parameters(proj_root, result_file, meg_file);
0676     if err
0677         errordlg(['result file read error occured -- detail :' err_msg], 'error');
0678     else
0679         %
0680         %--- Initialize gui of timewindow part.
0681         %
0682 
0683         % result file name
0684         set(H.result_file_edit, 'String', result_file);
0685 
0686         % time window
0687         [time] = vb_index_to_time(time_parm.twin_meg(1), time_parm);
0688         set(H.time_window_from_edit, 'String', sprintf('%.2f', time)); 
0689         [time] = vb_index_to_time(time_parm.twin_meg(2), time_parm);
0690         set(H.time_window_to_edit, 'String', sprintf('%.2f', time));
0691 
0692         % time step
0693         [time_len] = data_len_to_time_len(1, time_parm); % 1 sample step
0694         set(H.time_step_edit, 'String', num2str(time_len-0.001));
0695         
0696         % meg_file
0697         set(H.meg_file_edit, 'String', time_parm.meg_file);
0698         set(H.meg_file_edit, 'Enable', 'on');
0699         set(H.meg_file_push, 'Enable', 'on');
0700     end
0701 
0702 % end of set_result_file()
0703 
0704 function [time_parm, err, err_msg] = read_time_parameters(proj_root, result_file, meg_file)
0705 % This function read result file and meg_file and make 'time_parm' structure.
0706 % [IN]
0707 %       proj_root : project root directory
0708 %     result_file : result file name(relative path from proj_root)
0709 %        meg_file : external meg file input(relative path from proj_root)
0710 % [OUT]
0711 %      time_parm : time parameters
0712 %            err : true(failed to read file) or false.
0713 %        err_msg : error reason string.
0714 %
0715 
0716     time_parm = [];
0717     err = false;
0718     err_msg = [];
0719     if ~exist('meg_file', 'var')
0720         meg_file = [];
0721     end
0722 
0723     % load bayes_parm
0724     result_file = [proj_root, '/', result_file]; % absolute path
0725     
0726     if ~exist(result_file, 'file'), 
0727         err = true;
0728         err_msg = 'result file does not exist.';
0729         return;
0730     end;
0731     load(result_file, 'bayes_parm');
0732 
0733     % load Meg data time parameter.
0734     if isempty(meg_file)
0735         meg_file = bayes_parm.megfile{1};
0736     end
0737 
0738 
0739     meg_file_abs = [proj_root, '/', meg_file];    % absolute path
0740     if ~exist(meg_file_abs, 'file')
0741         err = true;
0742         err_msg = 'megfile does not exist.';
0743         return;
0744     end
0745     [MEGinfo] = vb_load_meg_info(meg_file_abs);
0746 
0747     % make time parameter
0748     time_parm = struct;
0749     time_parm.meg_file    = meg_file;
0750     time_parm.pretrigger  = vb_meginfo_get_pre_trigger(MEGinfo);
0751     time_parm.sample_freq = vb_meginfo_get_sampling_frequency(MEGinfo);
0752     time_parm.Nsample     = vb_meginfo_get_sample_number(MEGinfo);
0753     time_parm.twin_meg    = bayes_parm.twin_meg;
0754 
0755 % end of read_time_parameters()
0756 
0757 function change_save_mode(H, mode)
0758 % This function changes save file mode on gui.
0759 % [IN]
0760 %       H : component handles of gui
0761 %    mode : SAVE_MODE_SINGLE or SAVE_MODE_MULTIPLE
0762 
0763     switch(mode)
0764         case SAVE_MODE_SINGLE
0765             set(H.save_file_single_button, 'Value', 1);
0766             set(H.save_file_multiple_button, 'Value', 0);
0767             set(H.jact_directory_text, 'Visible', 'off');
0768             set(H.jact_directory_text2, 'Visible', 'off');
0769             set(H.jact_directory_edit, 'Visible', 'off');
0770         case SAVE_MODE_MULTIPLE
0771             set(H.save_file_single_button, 'Value', 0);
0772             set(H.save_file_multiple_button, 'Value', 1);
0773             % 20091008 rhayashi visible on
0774             set(H.jact_directory_text, 'Visible', 'on');
0775             set(H.jact_directory_text2, 'Visible', 'on');
0776             set(H.jact_directory_edit, 'Visible', 'on');
0777     end
0778 
0779 % end of change_save_mode()
0780 
0781 function update_output_filename(H)
0782 % This function update output filenames(current file, jact directory).
0783 % [IN]
0784 %       H : component handles of gui.
0785 
0786     save_dir = get(H.save_directory_edit, 'String');
0787 
0788     current_file_edit = get(H.current_file_edit, 'String');
0789     jact_dir_edit = get(H.jact_directory_edit, 'String');
0790 
0791 %    [path_name, current_file, ext_cur] = fileparts(current_file_edit);
0792 %    [path_name, jact_dir] = fileparts(jact_dir_edit);
0793     [path_name, current_file, ext_cur] = vb_get_file_parts(current_file_edit);
0794     [path_name, jact_dir] = vb_get_file_parts(jact_dir_edit);
0795 
0796     set(H.current_file_edit, 'String', [save_dir, filesep, current_file, ext_cur]);
0797 %    set(H.jact_directory_edit, 'String', [save_dir]);
0798 
0799 % end of update_output_filename()
0800 
0801 function change_trial_average(H, mode)
0802 % This function changes trial average mode on gui.
0803 % [IN]
0804 %       H : component handles of gui.
0805 %    mode : ON or OFF
0806 
0807     switch(mode)
0808         case ON
0809             set(H.trial_average_on_button, 'Value', 1);
0810             set(H.trial_average_off_button, 'Value', 0);
0811         case OFF
0812             set(H.trial_average_on_button, 'Value', 0);
0813             set(H.trial_average_off_button, 'Value', 1);
0814     end
0815 
0816 % end of change_trial_average()
0817 
0818 function select_time_window_time_course(H, time_parm)
0819 % This function launch job_plot_meg and set selected time window to gui.
0820 % [IN]
0821 %            H : component handles
0822 %    time_parm :
0823     %
0824     % --- Time window setting in current_gui.
0825     %
0826     twin_ini = [];
0827     [twin_ini(1)] = vb_time_to_index(...
0828                     str2double(get(H.time_window_from_edit, 'String')), time_parm);
0829     [twin_ini(2)] = vb_time_to_index(...
0830                     str2double(get(H.time_window_to_edit, 'String')), time_parm);
0831     %
0832     %  --- launch time window selection gui
0833     %
0834 
0835     % hide current_gui figure handle not to be painted from
0836     % job_plot_meg.
0837     gui_cancelled = true;
0838     set(H.figure, 'HandleVisibility', 'off'); 
0839     try
0840         proj_root = get(H.proj_root_edit, 'String');
0841         meg_file  = [proj_root, '/', time_parm.meg_file];
0842         [twin_meg, gui_cancelled] = ...
0843             job_plot_meg(meg_file, ...          % meg file
0844                         2, ...                  % intaraction mode
0845                         time_parm.twin_meg, ... % selectable range
0846                         twin_ini);              % initial selected range
0847     catch
0848         [last_msg, last_id] = lasterr;
0849         errordlg(last_msg, 'error');
0850     end
0851     set(H.figure, 'HandleVisibility', 'on');
0852     % set time window from job_plot_meg selection
0853     if ~gui_cancelled
0854         [time] = vb_index_to_time(twin_meg(1), time_parm);
0855         set(H.time_window_from_edit, 'String', sprintf('%.2f', time));
0856         [time] = vb_index_to_time(twin_meg(2), time_parm);
0857         set(H.time_window_to_edit, 'String', sprintf('%.2f', time));
0858     end
0859 
0860 % end of select_time_window_time_course()
0861 
0862 function reload_gui_area_file(H, area_file, area_key)
0863 % This function sets area_file data to gui.
0864 % [IN]
0865 %            H : gui component handles.
0866 %    area_file : area file(relative path)
0867 %  --- optional
0868 %     area_key : area_key string.
0869 %                If area_keys match this string, set focus.
0870 
0871     % set gui to area filename
0872     set(H.area_file_edit, 'String', area_file);
0873 
0874     % get area keys
0875     keys = {};
0876     proj_root = get(H.proj_root_edit, 'String');
0877     area_file = [proj_root '/' area_file];
0878 
0879     if exist(area_file, 'file') ~= 2
0880         return;
0881     end
0882 
0883     load(area_file, 'Area');
0884     for n = 1 : length(Area)
0885         keys{n} = Area{n}.key;
0886     end
0887 
0888     % search focus line when area_key is specified.
0889     if exist('area_key', 'var')
0890         focus_line = strmatch(area_key, keys, 'exact');
0891         if isempty(focus_line), focus_line = 1; end;
0892     else
0893         focus_line = 1;
0894     end
0895 
0896     % set area keys to the popup
0897     set(H.area_key_listbox, 'String', keys);
0898     set(H.area_key_listbox, 'Value', focus_line);
0899 
0900 % end of reload_gui_area_file()
0901 
0902 %
0903 %  --- Define constants
0904 %
0905 function v = DEFAULT_CURRENT_FNAME
0906     v = 'current.curr.mat';
0907 function v = SAVE_MODE_SINGLE
0908     v = 1;
0909 function v = SAVE_MODE_MULTIPLE
0910     v = 2;
0911 function v = OVERLAPPED_MODE
0912     v = 1;
0913 function v = CONCATENATE_MODE
0914     v = 2;
0915 function v = APPLICATION_NAME
0916     v = 'Current estimation';

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005