0001 function vb_posfile_maker(facefile, old_data_dir, mode)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
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
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
0055 sph_info = vb_facefile_get_spherical_info(facefile);
0056
0057
0058 mri_key = vb_facefile_get_mri_key(facefile);
0059
0060
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
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
0076
0077 def_coord = vb_define_coordinate;
0078 for k=1:Nfile
0079 if mode == 1
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
0094
0095
0096
0097
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
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
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