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

vb_posfile_remake_megfile

PURPOSE ^

remake MEG-MAT file by loading posfile

SYNOPSIS ^

function [result] = vb_posfile_remake_megfile(pos_file, meg_file, new_file)

DESCRIPTION ^

 remake MEG-MAT file by loading posfile
 [usage]
   [result] = vb_posfile_remake_megfile(pos_file, meg_file, new_file)
 [input]
   pos_file : <required> <<file>> POS-MAT file
   meg_file : <required> <<file>> MEG-MAT file
   new_file : <optional> new file name if you want [(update meg_file)]
 [output]
     result : result code
            :  0) no problem
            : >1) something wrong
            :      1) bad pos_file
            :      2) bad meg_file
 [note]
   the fields which will be updated are as follows:
     pick
     Qpick
     CoordType
     PositionFile
     MEGinfo.MRI_ID
     MEGinfo.Vcenter
     MEGinfo.Vradius
     MEGinfo.device_info
               .TransInfo

 [history]
   2009-08-05 (Sako) initial version
   2011-06-01 (Sako) supported standard data format

 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 [result] = vb_posfile_remake_megfile(pos_file, meg_file, new_file)
0002 % remake MEG-MAT file by loading posfile
0003 % [usage]
0004 %   [result] = vb_posfile_remake_megfile(pos_file, meg_file, new_file)
0005 % [input]
0006 %   pos_file : <required> <<file>> POS-MAT file
0007 %   meg_file : <required> <<file>> MEG-MAT file
0008 %   new_file : <optional> new file name if you want [(update meg_file)]
0009 % [output]
0010 %     result : result code
0011 %            :  0) no problem
0012 %            : >1) something wrong
0013 %            :      1) bad pos_file
0014 %            :      2) bad meg_file
0015 % [note]
0016 %   the fields which will be updated are as follows:
0017 %     pick
0018 %     Qpick
0019 %     CoordType
0020 %     PositionFile
0021 %     MEGinfo.MRI_ID
0022 %     MEGinfo.Vcenter
0023 %     MEGinfo.Vradius
0024 %     MEGinfo.device_info
0025 %               .TransInfo
0026 %
0027 % [history]
0028 %   2009-08-05 (Sako) initial version
0029 %   2011-06-01 (Sako) supported standard data format
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 % --- CHECK ARGUMENTS --- %
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 % --- MAIN PROCEDURE --------------------------------------------------------- %
0046 %
0047 cur_meg = load(meg_file);
0048 % cur_pos = load(pos_file);
0049 
0050 % --- cur_pos ------------------------------------------
0051 %            mri_key:
0052 %     spherical_info:
0053 %         trans_info:
0054 %         coord_type:
0055 %             header:
0056 
0057 meg_info = cur_meg.MEGinfo;
0058 
0059 % MRI_ID, Vcenter, Vradius, TransInfo
0060 meg_info = vb_info_add_posfile_info(meg_info, pos_file);
0061 
0062 old_CoordType = cur_meg.CoordType;
0063 
0064 % pick, Qpick, CoordType
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 % ref_pick, ref_Qpick
0076 % --- support standard format
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 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0096 
0097 % --- INNER FUNCTIONS -------------------------------------------------------- %
0098 %
0099 % --- inner_check_arguments()
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 % --- end of inner_check_arguments()
0137 %
0138 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0139 
0140 % --- END OF FILE --- %

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