Home > vbmeg > functions > device > acqdata > vb_posfile_maker.m

vb_posfile_maker

PURPOSE ^

Make POS-MAT file from old positioning files(.digit.mat, megpos.mat).

SYNOPSIS ^

function vb_posfile_maker(facefile, old_data_dir, mode)

DESCRIPTION ^

 Make POS-MAT file from old positioning files(.digit.mat, megpos.mat).
 [usage]
    vb_posfile_maker(<facefile>, <old_data_dir> [,mode])
 [input]
       facefile : FACE-MAT file(to get spherical model).
   old_data_dir : MEG : directory including old positioning(.megpos.mat) files.
                  EEG : directory including old positioning(.digit.mat) files.
           mode : [optional] making mode [1] | 2
                   :  1) MEG (MEGPOS-MAT to POS-MAT)
                   :  2) EEG (DIGIT-MAT  to POS-MAT)
 [output]
    none
 [note]
    old_data_dir/original.megpos.mat ==> old_data_dir/original.pos.mat
    old_data_dir/original.digit.mat  ==> old_data_dir/original.pos.mat

 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:

SOURCE CODE ^

0001 function  vb_posfile_maker(facefile, old_data_dir, mode)
0002 % Make POS-MAT file from old positioning files(.digit.mat, megpos.mat).
0003 % [usage]
0004 %    vb_posfile_maker(<facefile>, <old_data_dir> [,mode])
0005 % [input]
0006 %       facefile : FACE-MAT file(to get spherical model).
0007 %   old_data_dir : MEG : directory including old positioning(.megpos.mat) files.
0008 %                  EEG : directory including old positioning(.digit.mat) files.
0009 %           mode : [optional] making mode [1] | 2
0010 %                   :  1) MEG (MEGPOS-MAT to POS-MAT)
0011 %                   :  2) EEG (DIGIT-MAT  to POS-MAT)
0012 % [output]
0013 %    none
0014 % [note]
0015 %    old_data_dir/original.megpos.mat ==> old_data_dir/original.pos.mat
0016 %    old_data_dir/original.digit.mat  ==> old_data_dir/original.pos.mat
0017 %
0018 % Copyright (C) 2011, ATR All Rights Reserved.
0019 % License : New BSD License(see VBMEG_LICENSE.txt)
0020 
0021 %
0022 % --- Previous check
0023 %
0024 if ~exist('facefile', 'var') || exist(facefile, 'file') ~= 2
0025     error('facefile is a required parameter.');
0026 end
0027 if ~exist('old_data_dir', 'var') || ~isdir(old_data_dir)
0028     error('old_data_dir is a required parameter.');
0029 end
0030 
0031 %
0032 % --- Main Procedure
0033 %
0034 if ~exist('mode', 'var')
0035    mode = 1;
0036 end
0037 
0038 if mode == 1
0039     file_ext = '.megpos.mat';
0040 elseif mode == 2
0041     file_ext = '.digit.mat';
0042 else
0043     error('Check mode.');
0044 end
0045 
0046 % find target files
0047 d = dir([old_data_dir, '/', '*', file_ext]);
0048 file_list = {d.name};
0049 Nfile = length(file_list);
0050 if Nfile == 0
0051     error([file_ext, ' not found.']);
0052 end
0053 
0054 % face file(spherical_head and mri_key)
0055 sph_info = vb_facefile_get_spherical_info(facefile);
0056 
0057 % Make 'mri_key'
0058 mri_key = vb_facefile_get_mri_key(facefile);
0059 
0060 % Make 'spherical_head'
0061 if ~isempty(sph_info.Center) && ~isempty(sph_info.Radius)
0062     spherical_info = struct;
0063     spherical_info.Vcenter = sph_info.Center;
0064     spherical_info.Vradius = sph_info.Radius;
0065     spherical_info.coord_type = sph_info.CoordType;
0066 end
0067 
0068 % ----- header
0069 header.base_file_name = '';
0070 header.meg_marker_id = 1;
0071 header.file_type = 'POS-MAT';
0072 header.version   = 1.0;
0073 
0074 %
0075 % --- Convert old files to new files.
0076 %
0077 def_coord = vb_define_coordinate;
0078 for k=1:Nfile
0079     if mode == 1 % MEG
0080         input_file = [old_data_dir, '/', file_list{k}];
0081         clear trans_mat;
0082         load(input_file, 'trans_mat');
0083         trans_info.trans_mri = trans_mat.meg_to_mri;
0084         trans_info.coord_type_before = 'Unknown';
0085         trans_info.coord_type_after  = def_coord.COORDINATE_SPM_RIGHT_M;
0086         coord_type = 'Unknown';
0087         pos = [];
0088         name = [];
0089     else
0090         input_file = [old_data_dir, '/', file_list{k}];
0091         clear eeg_sensor digitizer;
0092         load(input_file, 'eeg_sensor', 'digitizer');
0093         % .coord_type
0094         % .pos
0095         % .name
0096         % .mri
0097         % .coord_type_mri
0098         trans_info.trans_mri = digitizer.trans_mri;
0099         trans_info.coord_type_before = eeg_sensor.coord_type;
0100         trans_info.coord_type_after  = eeg_sensor.coord_type_mri;
0101         coord_type = eeg_sensor.coord_type_mri;
0102         pos = eeg_sensor.mri;
0103         name = eeg_sensor.name;
0104     end
0105 
0106     % make filename(old.megpos(digit).mat ==> old.pos.mat)
0107     ix = findstr(input_file, file_ext);
0108     if isempty(ix), error('file name is invalid.'); end
0109     pos_file_name = [input_file(1:ix-1), '.pos.mat'];
0110 
0111     % --- make file
0112     var_list = {'mri_key', 'coord_type', 'pos', 'name', 'spherical_info', ...
0113       'trans_info', 'header'};
0114     for m=1:length(var_list)
0115         if exist(var_list{m}, 'var')
0116             vb_save(pos_file_name, var_list{m});
0117         end
0118     end
0119 end
0120 
0121 % ---  END OF FILE --- %

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