0001 function vb_megfile_patch_posfile(megfile, posfile, outfile)
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('megfile', 'var'), megfile = ''; end
0025 if ~exist('posfile', 'var'), posfile = ''; end
0026 if ~exist('outfile', 'var'), outfile = ''; end
0027 [megfile, posfile, outfile] = inner_check_arguments(megfile, posfile, outfile);
0028
0029
0030
0031 func_ = mfilename;
0032
0033 meginfo = vb_megfile_load_meginfo(megfile);
0034 if isempty(meginfo)
0035 error('(%s) meginfo is empty', func_);
0036 end
0037
0038 meg = load(megfile);
0039 transinfo = vb_info_get_transinfo(meginfo);
0040
0041 if isempty(transinfo)
0042 [old_pick, old_Qpick] = vb_load_sensor(megfile, 'MEG', '', false);
0043
0044 [pick, Qpick] = vb_meg_transform_coordinate(old_pick, old_Qpick, '', posfile);
0045 [MEGinfo] = vb_info_add_posfile_info(meginfo, posfile);
0046
0047 meg.pick = pick;
0048 meg.Qpick = Qpick;
0049 meg.MEGinfo = MEGinfo;
0050 else
0051 fprintf('(%s) do nothing because there is MEGinfo.TransInfo\n', func_);
0052 return;
0053 end
0054
0055 if isempty(outfile)
0056 outfile = megfile;
0057 end
0058
0059 save_cmd = sprintf('save %s -struct meg', outfile);
0060 eval(save_cmd);
0061 return;
0062
0063
0064
0065
0066
0067
0068
0069 function [megfile, posfile, outfile] = ...
0070 inner_check_arguments(megfile, posfile, outfile)
0071 func_ = mfilename;
0072 if ~inner_is_valid_input_file(megfile)
0073 error('(%s) megfile is invalid', func_);
0074 end
0075 if ~inner_is_valid_input_file(posfile)
0076 error('(%s) megfile is invalid', func_);
0077 end
0078
0079 if isempty(outfile)
0080
0081 end
0082 return;
0083
0084
0085
0086
0087
0088 function result = inner_is_valid_input_file(cur_file)
0089
0090 if isempty(cur_file)
0091 result = false;
0092 return;
0093 end
0094
0095 if exist(cur_file, 'file') ~= 2
0096 result = false;
0097 return;
0098 end
0099
0100 result = true;
0101 return;
0102
0103
0104
0105
0106
0107