61 #define MALLOC_54(x,t) (t *)malloc((x)*sizeof(t))
79 #include <Eigen/Dense>
92 using namespace FIFFLIB;
93 using namespace UTILSLIB;
94 using namespace Eigen;
101 : QDataStream(p_pIODevice)
103 this->setFloatingPointPrecision(QDataStream::SinglePrecision);
104 this->setByteOrder(QDataStream::BigEndian);
105 this->setVersion(QDataStream::Qt_5_0);
111 QIODevice::OpenMode mode)
112 : QDataStream(a, mode)
114 this->setFloatingPointPrecision(QDataStream::SinglePrecision);
115 this->setByteOrder(QDataStream::BigEndian);
116 this->setVersion(QDataStream::Qt_5_0);
123 QFile* t_pFile = qobject_cast<QFile*>(this->device());
126 p_sFileName = t_pFile->fileName();
128 p_sFileName = QString(
"TCPSocket");
172 return this->
write_int(FIFF_BLOCK_END,&kind,1,next);
179 fiff_int_t datasize = 0;
181 *
this << (qint32)FIFF_NOP;
182 *
this << (qint32)FIFFT_VOID;
183 *
this << (qint32)datasize;
184 *
this << (qint32)FIFFV_NEXT_NONE;
202 aspect_kinds.clear();
203 QList<FiffDirNode::SPtr>::ConstIterator ev;
208 for(ev = evoked_node.begin(); ev != evoked_node.end(); ++ev)
210 for(
k = 0;
k < (*ev)->nent(); ++
k)
212 kind = (*ev)->dir[
k]->kind;
213 pos = (*ev)->dir[
k]->pos;
217 comments.append(t_pTag->toString());
221 for(
k = 0;
k < my_aspect->nent(); ++
k)
223 kind = my_aspect->dir[
k]->kind;
224 pos = my_aspect->dir[
k]->pos;
228 aspect_kinds.append(*t_pTag->toInt());
233 if(comments.size() != aspect_kinds.size() || comments.size() == 0)
235 qWarning(
"Dataset names in FIF file could not be found.");
240 for(
k = 0;
k < aspect_kinds.size(); ++
k)
242 t += QString(
"%1 - \"%2\" (").arg(
k).arg(comments[
k]);
244 t += QString(
"FIFFV_ASPECT_AVERAGE)\n");
246 t += QString(
"FIFFV_ASPECT_STD_ERR)\n");
248 t += QString(
"unknown)\n");
264 if (!this->device()->
open(mode))
266 qCritical(
"Cannot open %s\n", t_sFileName.toUtf8().constData());
270 if(!check_beginning(t_pTag))
276 if (t_pTag->kind != FIFF_FILE_ID) {
277 qCritical(
"FIFF file should start with FIFF_FILE_ID!");
278 this->device()->close();
281 m_id = t_pTag->toFiffID();
284 if (t_pTag->kind != FIFF_DIR_POINTER) {
285 qWarning(
"Fiff::open: file does have a directory pointer");
286 this->device()->close();
293 qInfo(
"Creating tag directory for %s...", t_sFileName.toUtf8().constData());
295 qint32 dirpos = *t_pTag->toInt();
301 m_dir = this->make_dir(&ok);
303 qCritical (
"Could not create tag directory!");
308 if(!this->
read_tag(t_pTag, dirpos)) {
309 qCritical(
"Could not read the tag directory (file probably damaged)!");
312 m_dir = t_pTag->toDirEntry();
318 if (m_dir[m_dir.size()-2]->kind == FIFF_DIR) {
320 m_dir[m_dir.size()-1]->kind = -1;
321 m_dir[m_dir.size()-1]->type = -1;
322 m_dir[m_dir.size()-1]->size = -1;
323 m_dir[m_dir.size()-1]->pos = -1;
329 if((this->m_dirtree = this->
make_subtree(m_dir)) == NULL)
332 this->m_dirtree->parent.clear();
337 this->device()->seek(SEEK_SET);
345 if(this->device()->isOpen())
346 this->device()->close();
359 QList<FiffDirEntry::SPtr>
dir;
362 node->dir_tree = dentry;
365 node->type = FIFFB_ROOT;
367 if (dentry[current]->kind == FIFF_BLOCK_START) {
368 if (!this->
read_tag(t_pTag,dentry[current]->pos))
371 node->type = *t_pTag->toInt();
374 node->id = this->
id();
379 for (; current < dentry.size(); ++current) {
381 if (dentry[current]->kind == FIFF_BLOCK_START) {
384 QList<FiffDirEntry::SPtr> sub_dentry = dentry.mid(current);
387 child->parent = node;
388 node->children.append(child);
391 else if (dentry[current]->kind == FIFF_BLOCK_END) {
396 else if (dentry[current]->kind == -1)
398 else if (level == 0) {
404 if (((dentry[current]->kind == FIFF_PARENT_BLOCK_ID || dentry[current]->kind == FIFF_FILE_ID) && node->id.isEmpty()) || dentry[current]->kind == FIFF_BLOCK_ID) {
405 if (!this->
read_tag(t_pTag,dentry[current]->pos))
407 node->id = t_pTag->toFiffID();
423 QList<FiffDirNode::SPtr> node = p_Node->dir_tree_find(FIFFB_MNE_BAD_CHANNELS);
429 if(node[0]->find_tag(
this, FIFF_MNE_CH_NAME_LIST, t_pTag))
444 QList<FiffDirNode::SPtr> covs = p_Node->dir_tree_find(FIFFB_MNE_COV);
445 if (covs.size() == 0)
447 qWarning(
"No covariance matrices found");
455 bool success =
false;
456 fiff_int_t dim, nfree, nn;
458 bool diagmat =
false;
465 for(p = 0; p < covs.size(); ++p)
468 if (success && *tag->toInt() == cov_kind)
476 qWarning(
"Covariance matrix dimension not found.\n");
483 nfree = *tag->toInt();
485 if (current->find_tag(
this, FIFF_MNE_ROW_NAMES, tag))
488 if (names.size() != dim)
490 qWarning(
"Number of names does not match covariance matrix dimension\n");
498 qWarning(
"No covariance matrix data found\n");
506 if (tag->type == FIFFT_DOUBLE)
508 cov_diag = Map<VectorXd>(tag->toDouble(),dim);
510 else if (tag->type == FIFFT_FLOAT)
512 cov_diag = Map<VectorXf>(tag->toFloat(),dim).cast<
double>();
515 qCritical(
"Illegal data type for covariance matrix\n");
520 qInfo(
"\t%d x %d diagonal covariance (kind = %d) found.\n", dim, dim, cov_kind);
527 if (tag->type == FIFFT_DOUBLE)
529 vals = Map<VectorXd>(tag->toDouble(),nn);
531 else if (tag->type == FIFFT_FLOAT)
533 vals = Map<VectorXf>(tag->toFloat(),nn).cast<
double>();
537 qDebug() << tag->getInfo();
541 if(!MNEMath::issparse(vals))
546 cov = MatrixXd::Zero(dim,dim);
550 for(qint32 j = 0; j < dim; ++j)
552 for(qint32
k = 0;
k <= j; ++
k)
558 for(qint32 j = 0; j < dim; ++j)
559 for(qint32
k = j+1;
k < dim; ++
k)
563 qInfo(
"\t%d x %d full covariance (kind = %d) found.\n", dim, dim, cov_kind);
569 qDebug() <<
"ToDo: FiffStream::read_cov - this needs to be debugged.\n";
571 qInfo(
"\t%d x %d sparse covariance (kind = %d) found.\n", dim, dim, cov_kind);
608 if (current->find_tag(
this,
FIFF_MNE_COV_EIGENVALUES, tag1) && current->find_tag(
this, FIFF_MNE_COV_EIGENVECTORS, tag2))
610 eig = VectorXd(Map<VectorXd>(tag1->toDouble(),dim));
611 eigvec = tag2->toFloatMatrix().cast<
double>();
612 eigvec.transposeInPlace();
617 QList<FiffProj> projs = this->
read_proj(current);
627 p_covData.
kind = cov_kind;
628 p_covData.
diag = diagmat;
630 p_covData.
names = names;
632 if(cov_diag.size() > 0)
633 p_covData.
data = cov_diag;
634 else if(cov.size() > 0)
635 p_covData.
data = cov;
636 else if(cov_sparse.size() > 0)
637 p_covData.
data = cov_sparse;
639 p_covData.
projs = projs;
640 p_covData.
bads = bads;
641 p_covData.
nfree = nfree;
643 p_covData.
eigvec = eigvec;
650 qInfo(
"Did not find the desired covariance matrix\n");
658 QList<FiffCtfComp> compdata;
659 QList<FiffDirNode::SPtr> t_qListComps = p_Node->dir_tree_find(FIFFB_MNE_CTF_COMP_DATA);
661 qint32 i,
k, p, col, row;
662 fiff_int_t kind, pos;
664 for (
k = 0;
k < t_qListComps.size(); ++
k)
672 for(p = 0; p < node->nent(); ++p)
674 kind = node->dir[p]->kind;
675 pos = node->dir[p]->pos;
684 qWarning(
"Compensation type not found\n");
691 one.
ctfkind = *t_pTag->toInt();
698 else if (one.
ctfkind == 1194476114)
700 else if (one.
ctfkind == 1194541650)
702 else if (one.
ctfkind == 1194479433)
704 else if (one.
ctfkind == 1194544969)
709 for (p = 0; p < node->nent(); ++p)
711 kind = node->dir[p]->kind;
712 pos = node->dir[p]->pos;
723 calibrated = (bool)*t_pTag->toInt();
726 one.
rowcals = MatrixXd::Ones(1,mat->data.rows());
727 one.
colcals = MatrixXd::Ones(1,mat->data.cols());
736 QStringList ch_names;
737 for (p = 0; p < p_Chs.size(); ++p)
738 ch_names.append(p_Chs[p].ch_name);
741 MatrixXd col_cals(mat->data.cols(), 1);
743 for (col = 0; col < mat->data.cols(); ++col)
746 for (i = 0; i < ch_names.size(); ++i)
748 if (QString::compare(mat->col_names.at(col),ch_names.at(i)) == 0)
756 qWarning(
"Channel %s is not available in data",mat->col_names.at(col).toUtf8().constData());
761 qWarning(
"Ambiguous channel %s",mat->col_names.at(col).toUtf8().constData());
764 col_cals(col,0) = 1.0f/(p_Chs[p].range*p_Chs[p].cal);
769 MatrixXd row_cals(mat->data.rows(), 1);
771 for (row = 0; row < mat->data.rows(); ++row)
774 for (i = 0; i < ch_names.size(); ++i)
776 if (QString::compare(mat->row_names.at(row),ch_names.at(i)) == 0)
785 qWarning(
"Channel %s is not available in data",mat->row_names.at(row).toUtf8().constData());
790 qWarning(
"Ambiguous channel %s",mat->row_names.at(row).toUtf8().constData());
794 row_cals(row, 0) = p_Chs[p].range*p_Chs[p].cal;
796 mat->data = row_cals.asDiagonal()* mat->data *col_cals.asDiagonal();
801 compdata.append(one);
804 if (compdata.size() > 0)
805 qInfo(
"\tRead %lld compensation matrices\n",compdata.size());
814 p_digData.coord_frame = FIFFV_COORD_UNKNOWN;
815 fiff_int_t kind = -1;
820 QList<FiffDirNode::SPtr> t_qListDigData = p_Node->dir_tree_find(FIFFB_ISOTRAK);
823 if(t_qListDigData.isEmpty()) {
826 if(t_qListDigData.isEmpty()) {
827 printf(
"No Isotrak data found in %s", this->
streamName().toLatin1().data());
830 p_digData.coord_frame = FIFFV_COORD_MRI;
833 p_digData.coord_frame = FIFFV_COORD_HEAD;
837 for (
int k = 0;
k < t_qListDigData.first()->
nent(); ++
k) {
838 kind = t_qListDigData.first()->dir[
k]->kind;
839 pos = t_qListDigData.first()->dir[
k]->pos;
844 p_digData.points.append(t_pTag->toDigPoint());
848 p_digData.coord_frame = *t_pTag->toInt();
853 npoint = p_digData.points.size();
856 printf(
"No digitizer data in %s", this->
streamName().toLatin1().data());
860 for (
auto& dig : p_digData.points){
861 dig.coord_frame = p_digData.coord_frame;
866 p_digData.npoint = npoint;
868 for (
int k = 0;
k < p_digData.npoint;
k++) {
869 p_digData.active.append(TRUE);
870 p_digData.discard.append(FALSE);
880 p_InfoForward.
clear();
885 QList<FiffDirNode::SPtr> parent_meg = p_Node->dir_tree_find(FIFFB_MNE_PARENT_MEAS_FILE);
887 if (parent_meg.size() == 0)
889 qWarning(
"No parent MEG information found in operator\n");
895 QList<FiffChInfo> chs;
897 fiff_int_t kind = -1;
900 for (qint32
k = 0;
k < parent_meg[0]->nent(); ++
k)
902 kind = parent_meg[0]->dir[
k]->kind;
903 pos = parent_meg[0]->dir[
k]->pos;
907 chs.append( t_pTag->toChInfo() );
915 p_InfoForward.
chs = chs;
916 for (qint32 c = 0; c < p_InfoForward.
chs.size(); ++c)
917 p_InfoForward.
ch_names << p_InfoForward.
chs[c].ch_name;
919 p_InfoForward.
nchan = chs.size();
926 cand = t_pTag->toCoordTrans();
927 if(cand.
from == FIFFV_COORD_DEVICE && cand.
to == FIFFV_COORD_HEAD)
932 qWarning(
"MEG device/head coordinate transformation not found");
935 qWarning(
"MEG/head coordinate transformation not found.\n");
955 QList<FiffDirNode::SPtr> meas = p_Node->dir_tree_find(FIFFB_MEAS);
957 if (meas.size() == 0)
959 qWarning(
"Could not find measurement data\n");
963 QList<FiffDirNode::SPtr> meas_info = meas[0]->dir_tree_find(FIFFB_MEAS_INFO);
964 if (meas_info.count() == 0) {
965 qWarning(
"Could not find measurement info\n");
974 fiff_int_t nchan = -1;
976 float linefreq = -1.0f;
977 QList<FiffChInfo> chs;
978 float lowpass = -1.0f;
979 float highpass = -1.0f;
982 QString proj_name =
"";
983 QString xplotter_layout =
"";
985 QString utc_offset =
"";
986 fiff_int_t gantry_angle = -1;
988 QString experimenter =
"";
989 QString description =
"";
997 fiff_int_t meas_date[2];
1001 fiff_int_t kind = -1;
1002 fiff_int_t pos = -1;
1004 for (qint32
k = 0;
k < meas_info[0]->nent(); ++
k)
1006 kind = meas_info[0]->dir[
k]->kind;
1007 pos = meas_info[0]->dir[
k]->pos;
1012 nchan = *t_pTag->toInt();
1016 sfreq = *t_pTag->toFloat();
1020 linefreq = *t_pTag->toFloat();
1024 chs.append( t_pTag->toChInfo() );
1028 lowpass = *t_pTag->toFloat();
1032 highpass = *t_pTag->toFloat();
1036 meas_date[0] = t_pTag->toInt()[0];
1037 meas_date[1] = t_pTag->toInt()[1];
1042 cand = t_pTag->toCoordTrans();
1043 if(cand.
from == FIFFV_COORD_DEVICE && cand.
to == FIFFV_COORD_HEAD)
1050 proj_id = *t_pTag->toInt();
1054 proj_name = t_pTag->toString();
1058 xplotter_layout = t_pTag->toString();
1062 experimenter = t_pTag->toString();
1066 description = t_pTag->toString();
1070 gantry_angle = *t_pTag->toInt();
1074 utc_offset = t_pTag->toString();
1083 qWarning(
"Number of channels in not defined\n");
1088 qWarning(
"Sampling frequency is not defined\n");
1093 qWarning(
"Line frequency is not defined\n");
1095 if (chs.size() == 0)
1097 qWarning(
"Channel information not defined\n");
1100 if (chs.size() != nchan)
1102 qWarning(
"Incorrect number of channel definitions found\n");
1108 QList<FiffDirNode::SPtr> hpi_result = meas_info[0]->dir_tree_find(FIFFB_HPI_RESULT);
1109 if (hpi_result.size() == 1)
1111 for( qint32
k = 0;
k < hpi_result[0]->nent(); ++
k)
1113 kind = hpi_result[0]->dir[
k]->kind;
1114 pos = hpi_result[0]->dir[
k]->pos;
1118 cand = t_pTag->toCoordTrans();
1119 if (cand.
from == FIFFV_COORD_DEVICE && cand.
to == FIFFV_COORD_HEAD)
1130 QList<FiffDirNode::SPtr> isotrak = meas_info[0]->dir_tree_find(FIFFB_ISOTRAK);
1132 QList<FiffDigPoint> dig;
1133 fiff_int_t coord_frame = FIFFV_COORD_HEAD;
1137 if (isotrak.size() == 1)
1139 for (
k = 0;
k < isotrak[0]->nent(); ++
k)
1141 kind = isotrak[0]->dir[
k]->kind;
1142 pos = isotrak[0]->dir[
k]->pos;
1146 dig.append(t_pTag->toDigPoint());
1153 qDebug() <<
"NEEDS To BE DEBBUGED: FIFF_MNE_COORD_FRAME" << t_pTag->getType();
1154 coord_frame = *t_pTag->toInt();
1159 qDebug() <<
"NEEDS To BE DEBBUGED: FIFF_COORD_TRANS" << t_pTag->getType();
1160 dig_trans = t_pTag->toCoordTrans();
1165 for(
k = 0;
k < dig.size(); ++
k)
1166 dig[
k].coord_frame = coord_frame;
1169 if (dig_trans.
from != coord_frame && dig_trans.
to != coord_frame)
1175 QList<FiffDirNode::SPtr> acqpars = meas_info[0]->dir_tree_find(FIFFB_DACQ_PARS);
1178 if (acqpars.size() == 1)
1180 for(
k = 0;
k < acqpars[0]->nent(); ++
k)
1182 kind = acqpars[0]->dir[
k]->kind;
1183 pos = acqpars[0]->dir[
k]->pos;
1184 if (kind == FIFF_DACQ_PARS)
1187 acq_pars = t_pTag->toString();
1189 else if (kind == FIFF_DACQ_STIM)
1192 acq_stim = t_pTag->toString();
1199 QList<FiffProj> projs = this->
read_proj(meas_info[0]);
1203 QList<FiffCtfComp> comps = this->
read_ctf_comp(meas_info[0], chs);
1212 if (p_Node->id.version != -1)
1220 if (meas_info[0]->parent_id.version == -1)
1222 if (meas_info[0]->
id.version == -1)
1224 if (meas[0]->
id.version == -1)
1226 if (meas[0]->parent_id.version == -1)
1229 info.
meas_id = meas[0]->parent_id;
1235 info.
meas_id = meas_info[0]->id;
1238 info.
meas_id = meas_info[0]->parent_id;
1240 if (meas_date[0] == -1)
1255 if (highpass != -1.0f)
1260 if (lowpass != -1.0f)
1270 for (qint32 c = 0; c < info.
nchan; ++c)
1308 p_NodeInfo = meas[0];
1323 bool found_it =
false;
1324 if (node->type != FIFFB_MNE_NAMED_MATRIX)
1326 for (
int k = 0;
k < node->nchild(); ++
k)
1328 if (node->children[
k]->type == FIFFB_MNE_NAMED_MATRIX)
1330 if(node->children[
k]->has_tag(matkind))
1332 node = node->children[
k];
1340 qWarning(
"Fiff::read_named_matrix: Desired named matrix (kind = %d) not available\n",matkind);
1346 if (!node->has_tag(matkind))
1348 qWarning(
"Desired named matrix (kind = %d) not available",matkind);
1357 if(!node->find_tag(
this, matkind, t_pTag))
1359 qWarning(
"Matrix data missing.\n");
1365 mat.
data = t_pTag->toFloatMatrix().cast<
double>();
1366 mat.
data.transposeInPlace();
1372 if(node->find_tag(
this, FIFF_MNE_NROW, t_pTag))
1373 if (*t_pTag->toInt() != mat.
nrow)
1375 qWarning(
"Number of rows in matrix data and FIFF_MNE_NROW tag do not match");
1378 if(node->find_tag(
this, FIFF_MNE_NCOL, t_pTag))
1379 if (*t_pTag->toInt() != mat.
ncol)
1381 qWarning(
"Number of columns in matrix data and FIFF_MNE_NCOL tag do not match");
1386 if(node->find_tag(
this, FIFF_MNE_ROW_NAMES, t_pTag))
1387 row_names = t_pTag->toString();
1390 if(node->find_tag(
this, FIFF_MNE_COL_NAMES, t_pTag))
1391 col_names = t_pTag->toString();
1396 if (!row_names.isEmpty())
1399 if (!col_names.isEmpty())
1404 qWarning(
"FiffStream::read_named_matrix - Number of rows in matrix data and row names do not match\n");
1409 qWarning(
"FiffStream::read_named_matrix - Number of columns in matrix data and column names do not match\n");
1419 QList<FiffProj> projdata;
1423 QList<FiffDirNode::SPtr> t_qListNodes = p_Node->dir_tree_find(FIFFB_PROJ);
1424 if ( t_qListNodes.size() == 0 )
1428 t_qListNodes[0]->find_tag(
this,
FIFF_NCHAN, t_pTag);
1429 fiff_int_t global_nchan = 0;
1431 global_nchan = *t_pTag->toInt();
1434 QList<FiffDirNode::SPtr> t_qListItems = t_qListNodes[0]->dir_tree_find(FIFFB_PROJ_ITEM);
1435 for ( qint32 i = 0; i < t_qListItems.size(); ++i)
1441 t_pFiffDirTreeItem->find_tag(
this,
FIFF_NCHAN, t_pTag);
1443 nchan = *t_pTag->toInt();
1445 nchan = global_nchan;
1451 qDebug() <<
"read_proj: this has to be debugged";
1452 desc = t_pTag->toString();
1456 t_pFiffDirTreeItem->find_tag(
this,
FIFF_NAME, t_pTag);
1458 desc = t_pTag->toString();
1461 qWarning(
"Projection item description missing\n");
1476 t_pFiffDirTreeItem->find_tag(
this, FIFF_PROJ_ITEM_KIND, t_pTag);
1480 kind = *t_pTag->toInt();
1484 qWarning(
"Projection item kind missing");
1487 t_pFiffDirTreeItem->find_tag(
this, FIFF_PROJ_ITEM_NVEC, t_pTag);
1491 nvec = *t_pTag->toInt();
1495 qWarning(
"Number of projection vectors not specified\n");
1498 t_pFiffDirTreeItem->find_tag(
this, FIFF_PROJ_ITEM_CH_NAME_LIST, t_pTag);
1506 qWarning(
"Projection item channel list missing\n");
1509 t_pFiffDirTreeItem->find_tag(
this, FIFF_PROJ_ITEM_VECTORS, t_pTag);
1513 data = t_pTag->toFloatMatrix().cast<
double>();
1514 data.transposeInPlace();
1518 qWarning(
"Projection item data missing\n");
1524 active = *t_pTag->toInt();
1528 if (data.cols() != names.size())
1530 qWarning(
"Number of channel names does not match the size of data matrix\n");
1537 QStringList defaultList;
1538 FiffNamedMatrix t_fiffNamedMatrix(nvec, nchan, defaultList, names, data);
1540 FiffProj one(kind, active, desc, t_fiffNamedMatrix);
1542 projdata.append(one);
1545 if (projdata.size() > 0)
1547 printf(
"\tRead a total of %lld projection items:\n", projdata.size());
1548 for(qint32
k = 0;
k < projdata.size(); ++
k)
1550 printf(
"\t\t%s (%d x %d)",projdata[
k].desc.toUtf8().constData(), projdata[
k].data->nrow, projdata[
k].data->ncol);
1551 if (projdata[
k].active)
1552 printf(
" active\n");
1567 this->device()->seek(pos);
1576 if (p_pTag->size() > 0)
1578 this->readRawData(p_pTag->data(), p_pTag->size());
1582 if (p_pTag->next != FIFFV_NEXT_SEQ)
1583 this->device()->seek(p_pTag->next);
1592 fiff_long_t pos = this->device()->pos();
1604 *
this >> p_pTag->kind;
1605 *
this >> p_pTag->type;
1608 p_pTag->resize(size);
1609 *
this >> p_pTag->next;
1615 QTcpSocket* t_qTcpSocket = qobject_cast<QTcpSocket*>(this->device());
1618 this->skipRawData(p_pTag->size());
1622 if (p_pTag->next > 0)
1624 if(!this->device()->seek(p_pTag->next)) {
1629 else if (p_pTag->size() > 0 && p_pTag->next == FIFFV_NEXT_SEQ)
1631 if(!this->device()->seek(this->device()->pos()+p_pTag->size())) {
1645 while(this->device()->bytesAvailable() < 16)
1646 this->device()->waitForReadyRead(10);
1652 while(this->device()->bytesAvailable() < p_pTag->size())
1653 this->device()->waitForReadyRead(10);
1667 this->device()->seek(pos);
1675 *
this >> p_pTag->kind;
1676 *
this >> p_pTag->type;
1679 p_pTag->resize(size);
1680 *
this >> p_pTag->next;
1688 if (this->byteOrder() == QDataStream::LittleEndian){
1696 if (p_pTag->size() > 0)
1698 this->readRawData(p_pTag->data(), p_pTag->size());
1703 if (p_pTag->next != FIFFV_NEXT_SEQ)
1704 this->device()->seek(p_pTag->next);
1713 bool allow_maxshield,
1714 bool is_littleEndian)
1720 QString t_sFileName = t_pStream->streamName();
1722 if(is_littleEndian){
1724 t_pStream->setByteOrder(QDataStream::LittleEndian);
1727 qInfo(
"Opening raw data %s...\n",t_sFileName.toUtf8().constData());
1729 if(!t_pStream->open()){
1738 if(!t_pStream->read_meas_info(t_pStream->dirtree(), info, meas))
1744 QList<FiffDirNode::SPtr> raw = meas->dir_tree_find(FIFFB_RAW_DATA);
1745 if (raw.size() == 0)
1747 raw = meas->dir_tree_find(FIFFB_CONTINUOUS_DATA);
1754 qInfo(
"Maxshield data found\n");
1756 if (raw.size() == 0)
1758 qWarning(
"No raw data in %s\n", t_sFileName.toUtf8().constData());
1764 if (raw.size() == 0)
1766 qWarning(
"No raw data in %s\n", t_sFileName.toUtf8().constData());
1777 data.file = t_pStream;
1779 data.first_samp = 0;
1784 QList<FiffDirEntry::SPtr>
dir = raw[0]->dir;
1785 fiff_int_t
nent = raw[0]->nent();
1786 fiff_int_t nchan = info.
nchan;
1787 fiff_int_t first = 0;
1788 fiff_int_t first_samp = 0;
1789 fiff_int_t first_skip = 0;
1796 t_pStream->read_tag(t_pTag,
dir[first]->pos);
1797 first_samp = *t_pTag->toInt();
1808 t_pStream->read_tag(t_pTag,
dir[first]->pos);
1809 first_skip = *t_pTag->toInt();
1812 data.first_samp = first_samp;
1816 QList<FiffRawDir> rawdir;
1818 fiff_int_t nskip = 0;
1819 fiff_int_t ndir = 0;
1820 fiff_int_t nsamp = 0;
1821 for (qint32
k = first;
k <
nent; ++
k)
1826 t_pStream->read_tag(t_pTag, ent->pos);
1827 nskip = *t_pTag->toInt();
1836 case FIFFT_DAU_PACK16:
1837 nsamp = ent->size/(2*nchan);
1840 nsamp = ent->size/(2*nchan);
1843 nsamp = ent->size/(4*nchan);
1846 nsamp = ent->size/(4*nchan);
1849 qWarning(
"Cannot handle data buffers of type %d\n",ent->type);
1857 first_samp += nsamp*first_skip;
1858 data.first_samp = first_samp;
1867 t_RawDir.
first = first_samp;
1868 t_RawDir.
last = first_samp + nskip*nsamp - 1;
1869 t_RawDir.
nsamp = nskip*nsamp;
1870 rawdir.append(t_RawDir);
1871 first_samp = first_samp + nskip*nsamp;
1880 t_RawDir.
first = first_samp;
1881 t_RawDir.
last = first_samp + nsamp - 1;
1882 t_RawDir.
nsamp = nsamp;
1883 rawdir.append(t_RawDir);
1884 first_samp += nsamp;
1888 data.last_samp = first_samp - 1;
1892 RowVectorXd cals(data.info.nchan);
1894 for (qint32
k = 0;
k < data.info.nchan; ++
k)
1895 cals[
k] = data.info.chs[
k].range*data.info.chs[
k].cal;
1898 data.rawdir = rawdir;
1902 qInfo(
"\tRange : %d ... %d = %9.3f ... %9.3f secs",
1903 data.first_samp,data.last_samp,
1904 (
double)data.first_samp/data.info.sfreq,
1905 (
double)data.last_samp/data.info.sfreq);
1916 return p_sNameList.replace(
" ",
"").split(
":");
1923 return this->
write_int(FIFF_BLOCK_START,&kind);
1931 QString t_sFileName = p_pStream->streamName();
1933 if(!p_pStream->device()->open(QIODevice::WriteOnly))
1935 qWarning(
"Cannot write to %s\n", t_sFileName.toUtf8().constData());
1937 return p_pEmptyStream;
1943 p_pStream->write_id(FIFF_FILE_ID);
1944 int null_pointer = FIFFV_NEXT_NONE;
1945 p_pStream->write_int(FIFF_DIR_POINTER,&null_pointer);
1946 p_pStream->write_int(FIFF_FREE_LIST,&null_pointer);
1959 QString t_sFileName = t_pStream->streamName();
1964 if(!t_pStream->open(QIODevice::ReadWrite)) {
1965 qCritical(
"Cannot open %s\n", t_sFileName.toUtf8().constData());
1970 long dirpos,pointerpos;
1972 QFile *file = qobject_cast<QFile *>(t_pStream->device());
1978 pointerpos = t_pStream->dir()[t_pStream->nent()-2]->pos;
1979 if(!t_pStream->read_tag(t_pTag,pointerpos)){
1980 qCritical(
"Could not read last tag in the directory list!");
1984 if (t_pTag->next != FIFFV_NEXT_NONE) {
1985 t_pTag->next = FIFFV_NEXT_NONE;
1986 t_pStream->write_tag(t_pTag,pointerpos);
1991 pointerpos = t_pStream->dir()[1]->pos;
1992 if(!t_pStream->read_tag(t_pTag,pointerpos)){
1993 qCritical(
"Could not read directory pointer!");
2000 dirpos = *t_pTag->toInt();
2005 t_pStream->write_dir_pointer(-1, pointerpos);
2009 file->resize(dirpos);
2014 t_pStream->device()->seek(file->size());
2030 fiff_int_t data_type = 4;
2035 sel.resize(1,info.
nchan);
2040 QList<FiffChInfo> chs;
2042 for(
k = 0;
k < sel.cols(); ++
k)
2043 chs << info.
chs.at(sel(0,
k));
2045 fiff_int_t nchan = chs.size();
2051 t_pStream->start_block(FIFFB_MEAS);
2052 t_pStream->write_id(FIFF_BLOCK_ID);
2055 t_pStream->write_id(FIFF_PARENT_BLOCK_ID,info.
meas_id);
2061 t_pStream->start_block(FIFFB_MEAS_INFO);
2067 QList<fiff_int_t> blocks;
2069 bool have_hpi_result =
false;
2070 bool have_isotrak =
false;
2071 if (blocks.size() > 0 && !info.
filename.isEmpty())
2076 if(!t_pStream2->open()){
2077 qDebug() <<
"Failed to open file. Returning early";
2081 for(qint32
k = 0;
k < blocks.size(); ++
k)
2083 QList<FiffDirNode::SPtr> nodes = t_pStream2->dirtree()->dir_tree_find(blocks[
k]);
2085 if(blocks[
k] == FIFFB_HPI_RESULT && nodes.size() > 0)
2086 have_hpi_result =
true;
2088 if(blocks[
k] == FIFFB_ISOTRAK && nodes.size() > 0)
2089 have_isotrak =
true;
2101 t_pStream->start_block(FIFFB_DACQ_PARS);
2103 t_pStream->write_string(FIFF_DACQ_PARS, info.
acq_pars);
2106 t_pStream->write_string(FIFF_DACQ_STIM, info.
acq_stim);
2108 t_pStream->end_block(FIFFB_DACQ_PARS);
2115 if (!have_hpi_result)
2118 t_pStream->write_coord_trans(info.
dev_head_t);
2121 t_pStream->write_coord_trans(info.
ctf_head_t);
2126 if (info.
dig.size() > 0 && !have_isotrak)
2128 t_pStream->start_block(FIFFB_ISOTRAK);
2129 for (qint32
k = 0;
k < info.
dig.size(); ++
k)
2130 t_pStream->write_dig_point(info.
dig[
k]);
2132 t_pStream->end_block(FIFFB_ISOTRAK);
2139 t_pStream->write_proj(info.
projs);
2143 t_pStream->write_ctf_comp(info.
comps);
2147 if (info.
bads.size() > 0)
2149 t_pStream->start_block(FIFFB_MNE_BAD_CHANNELS);
2150 t_pStream->write_name_list(FIFF_MNE_CH_NAME_LIST,info.
bads);
2151 t_pStream->end_block(FIFFB_MNE_BAD_CHANNELS);
2173 cals = RowVectorXd(nchan);
2174 for(
k = 0;
k < nchan; ++
k)
2179 chs[
k].scanNo =
k+1;
2183 cals[
k] = chs[
k].cal;
2184 t_pStream->write_ch_info(chs[
k]);
2188 t_pStream->end_block(FIFFB_MEAS_INFO);
2192 t_pStream->start_block(FIFFB_RAW_DATA);
2205 this->device()->seek(pos);
2208 QFile* file = qobject_cast<QFile*> (this->device());
2210 this->device()->seek(file->size());
2212 pos = this->device()->pos();
2214 fiff_int_t datasize = p_pTag->size();
2216 *this << static_cast<qint32>(p_pTag->kind);
2217 *this << static_cast<qint32>(p_pTag->type);
2218 *this << static_cast<qint32>(datasize);
2219 *this << static_cast<qint32>(p_pTag->next);
2228 this->writeRawData(p_pTag->data(),datasize);
2238 fiff_long_t pos = this->device()->pos();
2259 fiff_int_t datasize= 4*13 + 4*7 + 16;
2262 *
this << (qint32)FIFFT_CH_INFO_STRUCT;
2263 *
this << (qint32)datasize;
2264 *
this << (qint32)FIFFV_NEXT_SEQ;
2269 *
this << (qint32)ch.
scanNo;
2270 *
this << (qint32)ch.
logNo;
2271 *
this << (qint32)ch.
kind;
2284 *
this << (qint32)ch.
unit;
2290 fiff_int_t len = ch.
ch_name.size();
2293 ch_name = ch.
ch_name.mid(0, 15);
2297 len = ch_name.size();
2299 this->writeRawData(ch_name.toUtf8().constData(),len);
2302 const char* chNull =
"";
2303 for(qint32 i = 0; i < 16-len; ++i)
2304 this->writeRawData(chNull,1);
2314 fiff_long_t pos = this->device()->pos();
2323 for(i = 0; i < 3; ++i)
2324 *
this << chpos.
r0[i];
2326 for(i = 0; i < 3; ++i)
2327 *
this << chpos.
ex[i];
2329 for(i = 0; i < 3; ++i)
2330 *
this << chpos.
ey[i];
2332 for(i = 0; i < 3; ++i)
2333 *
this << chpos.
ez[i];
2342 fiff_long_t pos = this->device()->pos();
2352 fiff_int_t datasize = 4*2*12 + 4*2;
2355 *
this << (qint32)FIFFT_COORD_TRANS_STRUCT;
2356 *
this << (qint32)datasize;
2357 *
this << (qint32)FIFFV_NEXT_SEQ;
2362 *
this << (qint32)trans.
from;
2363 *
this << (qint32)trans.
to;
2369 for (r = 0; r < 3; ++r)
2370 for (c = 0; c < 3; ++c)
2371 *
this << (
float)trans.
trans(r,c);
2372 for (r = 0; r < 3; ++r)
2373 *
this << (
float)trans.
trans(r,3);
2378 for (r = 0; r < 3; ++r)
2379 for (c = 0; c < 3; ++c)
2380 *
this << (
float)trans.
invtrans(r,c);
2381 for (r = 0; r < 3; ++r)
2382 *
this << (
float)trans.
invtrans(r,3);
2391 fiff_long_t pos = this->device()->pos();
2400 if (p_FiffCov.
nfree > 0)
2405 if(p_FiffCov.
names.size() > 0)
2419 qint32 dim = p_FiffCov.
dim;
2420 qint32 n = ((dim*dim) - dim)/2;
2424 for(qint32 i = 1; i < dim; ++i)
2425 for(qint32 j = 0; j < i; ++j)
2426 vals(count) = p_FiffCov.
data(i,j);
2434 if(p_FiffCov.
eig.size() > 0 && p_FiffCov.
eigvec.size() > 0)
2446 if(p_FiffCov.
bads.size() > 0)
2450 this->
end_block(FIFFB_MNE_BAD_CHANNELS);
2464 fiff_long_t pos = this->device()->pos();
2466 if (comps.size() <= 0)
2472 for(qint32
k = 0;
k < comps.size(); ++
k)
2486 if(comps[
k].save_calibrated) {
2487 comp.
data->data = (comp.
rowcals.asDiagonal()).inverse()* comp.
data->data * (comp.
colcals.asDiagonal()).inverse();
2491 this->
end_block(FIFFB_MNE_CTF_COMP_DATA);
2502 fiff_long_t pos = this->device()->pos();
2511 fiff_int_t datasize = 5*4;
2514 *
this << (qint32)FIFFT_DIG_POINT_STRUCT;
2515 *
this << (qint32)datasize;
2516 *
this << (qint32)FIFFV_NEXT_SEQ;
2521 *
this << (qint32)dig.
kind;
2522 *
this << (qint32)dig.
ident;
2523 for(qint32 i = 0; i < 3; ++i)
2537 this->device()->seek(pos);
2540 QFile* file = qobject_cast<QFile*> (this->device());
2542 this->device()->seek(file->size());
2544 pos = this->device()->pos();
2546 fiff_int_t datasize = 1 * 4;
2548 *
this << (qint32)FIFF_DIR_POINTER;
2549 *
this << (qint32)FIFFT_INT;
2550 *
this << (qint32)datasize;
2551 *
this << (qint32)next;
2576 this->device()->seek(pos);
2579 QFile* file = qobject_cast<QFile*> (this->device());
2581 this->device()->seek(file->size());
2584 pos = this->device()->pos();
2589 *
this << (qint32)FIFF_DIR;
2590 *
this << (qint32)FIFFT_DIR_ENTRY_STRUCT;
2591 *
this << (qint32)datasize;
2592 *
this << (qint32)FIFFV_NEXT_NONE;
2597 for(qint32 i = 0; i <
nent; ++i) {
2598 *
this << (qint32)
dir[i]->kind;
2599 *
this << (qint32)
dir[i]->type;
2600 *
this << (qint32)
dir[i]->size;
2601 *
this << (qint32)
dir[i]->pos;
2611 fiff_long_t pos = this->device()->pos();
2613 qint32 datasize = nel * 8;
2615 *
this << (qint32)kind;
2616 *
this << (qint32)FIFFT_DOUBLE;
2617 *
this << (qint32)datasize;
2618 *
this << (qint32)FIFFV_NEXT_SEQ;
2620 for(qint32 i = 0; i < nel; ++i)
2630 fiff_long_t pos = this->device()->pos();
2632 qint32 datasize = nel * 4;
2634 *
this << (qint32)kind;
2635 *
this << (qint32)FIFFT_FLOAT;
2636 *
this << (qint32)datasize;
2637 *
this << (qint32)FIFFV_NEXT_SEQ;
2639 for(qint32 i = 0; i < nel; ++i)
2649 fiff_long_t pos = this->device()->pos();
2651 qint32 numel = mat.rows() * mat.cols();
2653 fiff_int_t datasize = 4*numel + 4*3;
2655 *
this << (qint32)kind;
2656 *
this << (qint32)FIFFT_MATRIX_FLOAT;
2657 *
this << (qint32)datasize;
2658 *
this << (qint32)FIFFV_NEXT_SEQ;
2662 for(i = 0; i < mat.rows(); ++i)
2663 for(j = 0; j < mat.cols(); ++j)
2667 dims[0] = mat.cols();
2668 dims[1] = mat.rows();
2671 for(i = 0; i < 3; ++i)
2681 fiff_long_t pos = this->device()->pos();
2691 qint32 nnzm = mat.nonZeros();
2692 qint32 ncol = mat.cols();
2693 fiff_int_t datasize = 4*nnzm + 4*nnzm + 4*(ncol+1) + 4*4;
2697 typedef Eigen::Triplet<float> T;
2699 s.reserve(mat.nonZeros());
2700 for (
int k=0;
k < mat.outerSize(); ++
k)
2701 for (SparseMatrix<float>::InnerIterator it(mat,
k); it; ++it)
2702 s.push_back(T(it.row(), it.col(), it.value()));
2704 s = MNEMath::sortrows<float>(s, 1);
2707 std::vector<qint32> cols, starts;
2710 for(i = 0; i < s.size(); ++i)
2712 if((
signed) s[i].col() != v_old)
2715 cols.push_back(s[i].col());
2716 starts.push_back(i);
2720 *
this << (qint32)kind;
2721 *
this << (qint32)FIFFT_CCS_MATRIX_FLOAT;
2722 *
this << (qint32)datasize;
2723 *
this << (qint32)FIFFV_NEXT_SEQ;
2728 for(i = 0; i < s.size(); ++i)
2729 *
this << s[i].value();
2734 for(i = 0; i < s.size(); ++i)
2735 *
this << s[i].row();
2740 RowVectorXi ptrs = RowVectorXi::Ones(ncol+1);
2743 for(
k = 0;
k < cols.size(); ++
k)
2744 ptrs[cols[
k]] = starts[
k];
2749 for(
k = ncol;
k >= 1; --
k)
2751 ptrs[
k-1] = ptrs[
k];
2753 for(i = 0; i < (quint32)ptrs.size(); ++i)
2759 dims[0] = mat.nonZeros();
2760 dims[1] = mat.rows();
2761 dims[2] = mat.cols();
2764 for(i = 0; i < 4; ++i)
2774 fiff_long_t pos = this->device()->pos();
2784 qint32 nnzm = mat.nonZeros();
2785 qint32 nrow = mat.rows();
2786 fiff_int_t datasize = 4*nnzm + 4*nnzm + 4*(nrow+1) + 4*4;
2790 typedef Eigen::Triplet<float> T;
2792 s.reserve(mat.nonZeros());
2793 for (
int k=0;
k < mat.outerSize(); ++
k)
2794 for (SparseMatrix<float>::InnerIterator it(mat,
k); it; ++it)
2795 s.push_back(T(it.row(), it.col(), it.value()));
2797 s = MNEMath::sortrows<float>(s);
2800 std::vector<qint32> rows, starts;
2803 for(i = 0; i < s.size(); ++i)
2805 if((
signed) s[i].row() != v_old)
2808 rows.push_back(s[i].row());
2809 starts.push_back(i);
2816 *
this << (qint32)kind;
2817 *
this << (qint32)FIFFT_RCS_MATRIX_FLOAT;
2818 *
this << (qint32)datasize;
2819 *
this << (qint32)FIFFV_NEXT_SEQ;
2824 for(i = 0; i < s.size(); ++i)
2825 *
this << s[i].value();
2830 for(i = 0; i < s.size(); ++i)
2831 *
this << s[i].col();
2836 RowVectorXi ptrs = RowVectorXi::Ones(nrow+1);
2839 for(
k = 0;
k < rows.size(); ++
k)
2840 ptrs[rows[
k]] = starts[
k];
2846 for(
k = nrow;
k >= 1; --
k)
2848 ptrs[
k-1] = ptrs[
k];
2851 for(i = 0; i < (quint32)ptrs.size(); ++i)
2858 dims[0] = mat.nonZeros();
2859 dims[1] = mat.rows();
2860 dims[2] = mat.cols();
2863 for(i = 0; i < 4; ++i)
2873 fiff_long_t pos = this->device()->pos();
2886 fiff_int_t datasize = 5*4;
2888 *
this << (qint32)kind;
2889 *
this << (qint32)FIFFT_ID_STRUCT;
2890 *
this << (qint32)datasize;
2891 *
this << (qint32)FIFFV_NEXT_SEQ;
2897 data[1] = t_id.
machid[0];
2898 data[2] = t_id.
machid[1];
2902 for(qint32 i = 0; i < 5; ++i)
2912 fiff_long_t pos = this->device()->pos();
2931 QList<FiffChInfo> chs;
2932 for(
k = 0;
k < p_FiffInfoBase.
nchan; ++
k)
2933 chs << p_FiffInfoBase.
chs[
k];
2935 for(
k = 0;
k < p_FiffInfoBase.
nchan; ++
k)
2940 chs[
k].scanNo =
k+1;
2947 bool have_hpi_result =
false;
2952 if (!have_hpi_result)
2963 if (p_FiffInfoBase.
bads.size() > 0)
2967 this->
end_block(FIFFB_MNE_BAD_CHANNELS);
2970 this->
end_block(FIFFB_MNE_PARENT_MEAS_FILE);
2979 fiff_long_t pos = this->device()->pos();
2981 fiff_int_t datasize = nel * 4;
2983 *
this << (qint32)kind;
2984 *
this << (qint32)FIFFT_INT;
2985 *
this << (qint32)datasize;
2986 *
this << (qint32)next;
2988 for(qint32 i = 0; i < nel; ++i)
2998 fiff_long_t pos = this->device()->pos();
3003 qint32 numel = mat.rows() * mat.cols();
3005 fiff_int_t datasize = 4*numel + 4*3;
3007 *
this << (qint32)kind;
3008 *
this << (qint32)FIFFT_MATRIX_INT;
3009 *
this << (qint32)datasize;
3010 *
this << (qint32)FIFFV_NEXT_SEQ;
3014 for(i = 0; i < mat.rows(); ++i)
3015 for(j = 0; j < mat.cols(); ++j)
3019 dims[0] = mat.cols();
3020 dims[1] = mat.rows();
3023 for(i = 0; i < 3; ++i)
3033 QString all = data.join(
":");
3041 fiff_long_t pos = this->device()->pos();
3051 this->
end_block(FIFFB_MNE_NAMED_MATRIX);
3060 fiff_long_t pos = this->device()->pos();
3062 if (projs.size() <= 0)
3067 for(qint32
k = 0;
k < projs.size(); ++
k)
3071 this->
write_int(FIFF_PROJ_ITEM_KIND,&projs[
k].kind);
3072 if (projs[
k].kind == FIFFV_PROJ_ITEM_FIELD)
3074 float fValue = 0.0f;
3079 this->
write_int(FIFF_PROJ_ITEM_NVEC, &projs[
k].data->nrow);
3080 qint32 bValue = (qint32)projs[
k].active;
3082 this->
write_name_list(FIFF_PROJ_ITEM_CH_NAME_LIST, projs[
k].data->col_names);
3094 const RowVectorXd& cals)
3096 if (buf.rows() != cals.cols())
3098 qWarning(
"buffer and calibration sizes do not match\n");
3102 typedef Eigen::Triplet<double> T;
3103 std::vector<T> tripletList;
3104 tripletList.reserve(cals.cols());
3105 for(qint32 i = 0; i < cals.cols(); ++i)
3106 tripletList.push_back(T(i, i, 1.0/cals[i]));
3108 SparseMatrix<double> inv_calsMat(cals.cols(), cals.cols());
3109 inv_calsMat.setFromTriplets(tripletList.begin(), tripletList.end());
3111 MatrixXf tmp = (inv_calsMat*buf).cast<float>();
3119 const SparseMatrix<double>& mult)
3121 if (buf.rows() != mult.cols()) {
3122 qWarning(
"buffer and mult sizes do not match\n");
3126 SparseMatrix<double> inv_mult(mult.rows(), mult.cols());
3127 for (
int k=0;
k<inv_mult.outerSize(); ++
k)
3128 for (SparseMatrix<double>::InnerIterator it(mult,
k); it; ++it)
3129 inv_mult.coeffRef(it.row(),it.col()) = 1/it.value();
3131 MatrixXf tmp = (inv_mult*buf).cast<float>();
3140 MatrixXf tmp = buf.cast<
float>();
3148 const QString& data)
3150 fiff_long_t pos = this->device()->pos();
3152 fiff_int_t datasize = data.size();
3153 *
this << (qint32)kind;
3154 *
this << (qint32)FIFFT_STRING;
3155 *
this << (qint32)datasize;
3156 *
this << (qint32)FIFFV_NEXT_SEQ;
3158 this->writeRawData(data.toUtf8().constData(),datasize);
3167 fiff_int_t datasize = data.size();
3169 *
this << (qint32)FIFFT_VOID;
3170 *
this << 4+(qint32)datasize;
3171 *
this << (qint32)FIFFV_NEXT_SEQ;
3174 this->writeRawData(data.toUtf8().constData(),datasize);
3179 QList<FiffDirEntry::SPtr> FiffStream::make_dir(
bool *ok)
3182 QList<FiffDirEntry::SPtr>
dir;
3189 if(!this->device()->seek(SEEK_SET))
3195 if (t_pTag->kind == FIFF_DIR)
3201 t_pFiffDirEntry->kind = t_pTag->kind;
3202 t_pFiffDirEntry->type = t_pTag->type;
3203 t_pFiffDirEntry->size = t_pTag->size();
3204 t_pFiffDirEntry->pos = (fiff_long_t)pos;
3208 dir.append(t_pFiffDirEntry);
3209 if (t_pTag->next < 0)
3216 t_pFiffDirEntry->kind = -1;
3217 t_pFiffDirEntry->type = -1;
3218 t_pFiffDirEntry->size = -1;
3219 t_pFiffDirEntry->pos = -1;
3220 dir.append(t_pFiffDirEntry);
3232 if (p_pTag->kind != FIFF_FILE_ID)
3234 qWarning(
"Fiff::open: file does not start with a file id tag\n");
3238 if (p_pTag->type != FIFFT_ID_STRUCT)
3240 qWarning(
"Fiff::open: file does not start with a file id tag\n");
3243 if (p_pTag->size() != 20)
3245 qWarning(
"Fiff::open: file does not start with a file id tag\n");