Home > vbmeg > external > mne > mne_read_morph_map.m

mne_read_morph_map

PURPOSE ^

SYNOPSIS ^

function [leftmap,rightmap] = mne_read_morph_map(from,to,subjects_dir)

DESCRIPTION ^

 [leftmap,rightmap] = mne_read_morph_map(from,to,subjects_dir)

 Read the morphing map from subject 'from' to subject 'to'.
 If subjects_dir is not specified, the SUBJECTS_DIR environment
 variable is used

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [leftmap,rightmap] = mne_read_morph_map(from,to,subjects_dir)
0002 %
0003 % [leftmap,rightmap] = mne_read_morph_map(from,to,subjects_dir)
0004 %
0005 % Read the morphing map from subject 'from' to subject 'to'.
0006 % If subjects_dir is not specified, the SUBJECTS_DIR environment
0007 % variable is used
0008 %
0009 
0010 %
0011 %   Author : Matti Hamalainen, MGH Martinos Center
0012 %   License : BSD 3-clause
0013 %
0014 %
0015 %   Revision 1.1  2008/03/25 21:06:08  msh
0016 %   Added mne_read_morph_map function
0017 %
0018 %
0019 me='MNE:mne_read_morph_map';
0020 
0021 global FIFF;
0022 if isempty(FIFF)
0023     FIFF = fiff_define_constants();
0024 end
0025 
0026 if nargin < 3
0027     subjects_dir=getenv('SUBJECTS_DIR');
0028     if isempty(subjects_dir)
0029         error(me,'SUBJECTS_DIR not set');
0030     end
0031 end
0032 if nargin < 2
0033     error(me,'Not enough input arguments');
0034 end
0035 %
0036 %  Does the file exist
0037 %
0038 name = sprintf('%s/morph-maps/%s-%s-morph.fif',subjects_dir,from,to);
0039 if ~exist(name,'file')
0040     name = sprintf('%s/morph-maps/%s-%s-morph.fif',subjects_dir,to,from);
0041     if ~exist(name,'file')
0042         error(me,'The requested morph map does not exist');
0043     end
0044 end
0045 %
0046 %    Open it
0047 %
0048 [fid,tree] = fiff_open(name);
0049 %
0050 %   Locate all maps
0051 %
0052 maps = fiff_dir_tree_find(tree,FIFF.FIFFB_MNE_MORPH_MAP);
0053 if isempty(maps)
0054     fclose(fid);
0055     error(me,'Morphing map data not found');
0056 end
0057 %
0058 %   Find the correct ones
0059 %
0060 for k = 1:length(maps)
0061     tag = find_tag(maps(k),FIFF.FIFF_MNE_MORPH_MAP_FROM);
0062     if strcmp(tag.data,from)
0063         tag = find_tag(maps(k),FIFF.FIFF_MNE_MORPH_MAP_TO);
0064         if strcmp(tag.data,to)
0065             %
0066             %  Names match: which hemishere is this?
0067             %
0068             tag = find_tag(maps(k),FIFF.FIFF_MNE_HEMI);
0069             if tag.data == FIFF.FIFFV_MNE_SURF_LEFT_HEMI
0070                 tag     = find_tag(maps(k),FIFF.FIFF_MNE_MORPH_MAP);
0071                 leftmap = tag.data;
0072                 fprintf(1,'\tLeft-hemisphere map read.\n');
0073             elseif tag.data == FIFF.FIFFV_MNE_SURF_RIGHT_HEMI
0074                 tag      = find_tag(maps(k),FIFF.FIFF_MNE_MORPH_MAP);
0075                 rightmap = tag.data;
0076                 fprintf(1,'\tRight-hemisphere map read.\n');
0077             end
0078         end
0079     end
0080 end
0081 fclose(fid);
0082 if ~exist('leftmap')
0083     error(me,'Left hemisphere map not found in %s',name);
0084 end
0085 if ~exist('rightmap')
0086     error(me,'Left hemisphere map not found in %s',name);
0087 end
0088 
0089 return;
0090 
0091     function [tag] = find_tag(node,findkind)
0092         
0093         for p = 1:node.nent
0094             if node.dir(p).kind == findkind
0095                 tag = fiff_read_tag(fid,node.dir(p).pos);
0096                 return;
0097             end
0098         end
0099         tag = [];
0100         return;
0101     end
0102 
0103 end

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