0001 function [result] = vb_posfile_remake_megfile(pos_file, meg_file, new_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 if ~exist('pos_file', 'var'), pos_file = ''; end
0036 if ~exist('meg_file', 'var'), meg_file = ''; end
0037 if ~exist('new_file', 'var'), new_file = ''; end
0038 [pos_file, meg_file, new_file, result] = ...
0039 inner_check_arguments(pos_file, meg_file, new_file);
0040
0041 if result ~= 0
0042 return;
0043 end
0044
0045
0046
0047 cur_meg = load(meg_file);
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 meg_info = cur_meg.MEGinfo;
0058
0059
0060 meg_info = vb_info_add_posfile_info(meg_info, pos_file);
0061
0062 old_CoordType = cur_meg.CoordType;
0063
0064
0065 old_pick = cur_meg.pick;
0066 old_Qpick = cur_meg.Qpick;
0067
0068 [new_pick, new_Qpick, new_CoordType] = vb_meg_transform_coordinate( ...
0069 old_pick, old_Qpick, old_CoordType, pos_file);
0070
0071 cur_meg.pick = new_pick;
0072 cur_meg.Qpick = new_Qpick;
0073 cur_meg.CoordType = new_CoordType;
0074
0075
0076
0077 if (isfield(cur_meg, 'ref_pick') && ~isempty(cur_meg.ref_pick)) ...
0078 && (isfield(cur_meg, 'ref_Qpick') && ~isempty(cur_meg.ref_Qpick))
0079 old_ref_pick = cur_meg.ref_pick;
0080 old_ref_Qpick = cur_meg.ref_Qpick;
0081
0082 [new_ref_pick, new_ref_Qpick] = vb_meg_transform_coordinate( ...
0083 old_ref_pick, old_ref_Qpick, old_CoordType, pos_file);
0084
0085 cur_meg.ref_pick = new_ref_pick;
0086 cur_meg.ref_Qpick = new_ref_Qpick;
0087 end
0088
0089 cur_meg.PositionFile = pos_file;
0090 cur_meg.MEGinfo = meg_info;
0091
0092 vb_save_struct(new_file, cur_meg);
0093 return;
0094
0095
0096
0097
0098
0099
0100
0101 function [pos_file, meg_file, new_file, result] = ...
0102 inner_check_arguments(pos_file, meg_file, new_file)
0103
0104 func_ = mfilename;
0105 result = 0;
0106
0107 if isempty(pos_file)
0108 fprintf('(%s) pos_file is a required parameter\n', func_);
0109 result = 1;
0110 return;
0111 end
0112
0113 if exist(pos_file, 'file') ~= 2
0114 fprintf('(%s) cannot find pos_file : %s\n', func_, pos_file);
0115 result = 1;
0116 return;
0117 end
0118
0119 if isempty(meg_file)
0120 fprintf('(%s) meg_file is a required parameter\n', func_);
0121 result = 2;
0122 return;
0123 end
0124
0125 if exist(meg_file, 'file') ~= 2
0126 fprintf('(%s) cannot find meg_file : %s\n', func_, meg_file);
0127 result = 2;
0128 return;
0129 end
0130
0131 if isempty(new_file)
0132 new_file = meg_file;
0133 end
0134 return;
0135
0136
0137
0138
0139
0140