0001 function [ mat ] = fiff_read_named_matrix(fid,node,matkind)
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 global FIFF;
0031 if isempty(FIFF)
0032 FIFF = fiff_define_constants();
0033 end
0034
0035 me='MNE:fiff_read_named_matrix';
0036
0037 if nargin ~= 3
0038 error(me,'Incorrect number of arguments');
0039 end
0040
0041
0042
0043 found_it=false;
0044 if node.block ~= FIFF.FIFFB_MNE_NAMED_MATRIX
0045 for k = 1:node.nchild
0046 if node.children(k).block == FIFF.FIFFB_MNE_NAMED_MATRIX
0047 if has_tag(node.children(k),matkind)
0048 node = node.children(k);
0049 found_it = true;
0050 break;
0051 end
0052 end
0053 end
0054 if ~found_it
0055 error(me,'Desired named matrix (kind = %d) not available',matkind);
0056 end
0057 else
0058 if ~has_tag(node,matkind)
0059 error(me,'Desired named matrix (kind = %d) not available',matkind);
0060 end
0061 end
0062
0063
0064
0065 tag = find_tag(node,matkind);
0066 if isempty(tag)
0067 error(me,'Matrix data missing');
0068 else
0069 data = tag.data;
0070 end
0071 nrow = size(data,1);
0072 ncol = size(data,2);
0073 tag = find_tag(node,FIFF.FIFF_MNE_NROW);
0074 if ~isempty(tag)
0075 if tag.data ~= nrow
0076 error(me,'Number of rows in matrix data and FIFF_MNE_NROW tag do not match');
0077 end
0078 end
0079 tag = find_tag(node,FIFF.FIFF_MNE_NCOL);
0080 if ~isempty(tag)
0081 if tag.data ~= ncol
0082 error(me,'Number of columns in matrix data and FIFF_MNE_NCOL tag do not match');
0083 end
0084 end
0085 tag = find_tag(node,FIFF.FIFF_MNE_ROW_NAMES);
0086 if ~isempty(tag)
0087 row_names = tag.data;
0088 end
0089 tag = find_tag(node,FIFF.FIFF_MNE_COL_NAMES);
0090 if ~isempty(tag)
0091 col_names = tag.data;
0092 end
0093
0094
0095
0096 mat.nrow = nrow;
0097 mat.ncol = ncol;
0098 if exist('row_names','var')
0099 mat.row_names = fiff_split_name_list(row_names);
0100 else
0101 mat.row_names = [];
0102 end
0103 if exist('col_names','var')
0104 mat.col_names = fiff_split_name_list(col_names);
0105 else
0106 mat.col_names = [];
0107 end
0108 mat.data = data;
0109
0110 return;
0111
0112
0113 function [tag] = find_tag(node,findkind)
0114
0115 for p = 1:node.nent
0116 if node.dir(p).kind == findkind
0117 tag = fiff_read_tag(fid,node.dir(p).pos);
0118 return;
0119 end
0120 end
0121 tag = [];
0122 return;
0123 end
0124
0125 function [has] = has_tag(this,findkind)
0126
0127 for p = 1:this.nent
0128 if this.dir(p).kind == findkind
0129 has = true;
0130 return;
0131 end
0132 end
0133 has = false;
0134 return;
0135
0136 end
0137
0138 end