92: QDataStream(p_pIODevice)
94 this->setFloatingPointPrecision(QDataStream::SinglePrecision);
95 this->setByteOrder(QDataStream::BigEndian);
96 this->setVersion(QDataStream::Qt_5_0);
102 QIODevice::OpenMode mode)
103: QDataStream(a, mode)
105 this->setFloatingPointPrecision(QDataStream::SinglePrecision);
106 this->setByteOrder(QDataStream::BigEndian);
107 this->setVersion(QDataStream::Qt_5_0);
114 QFile* t_pFile = qobject_cast<QFile*>(this->device());
117 p_sFileName = t_pFile->fileName();
119 p_sFileName = QString(
"TCPSocket");
174 *
this << (qint32)datasize;
193 aspect_kinds.clear();
194 QList<FiffDirNode::SPtr>::ConstIterator ev;
199 for(ev = evoked_node.begin(); ev != evoked_node.end(); ++ev)
201 for(k = 0; k < (*ev)->nent(); ++k)
203 kind = (*ev)->dir[k]->kind;
204 pos = (*ev)->dir[k]->pos;
208 comments.append(t_pTag->toString());
212 for(k = 0; k < my_aspect->nent(); ++k)
214 kind = my_aspect->dir[k]->kind;
215 pos = my_aspect->dir[k]->pos;
219 aspect_kinds.append(*t_pTag->toInt());
224 if(comments.size() != aspect_kinds.size() || comments.size() == 0)
226 qWarning(
"Dataset names in FIF file could not be found.");
231 for(k = 0; k < aspect_kinds.size(); ++k)
233 t += QString(
"%1 - \"%2\" (").arg(k).arg(comments[k]);
235 t += QString(
"FIFFV_ASPECT_AVERAGE)\n");
237 t += QString(
"FIFFV_ASPECT_STD_ERR)\n");
239 t += QString(
"unknown)\n");
255 if (!this->device()->
open(mode))
257 qCritical(
"Cannot open %s\n", t_sFileName.toUtf8().constData());
261 if(!check_beginning(t_pTag))
268 qCritical(
"FIFF file should start with FIFF_FILE_ID!");
269 this->device()->close();
272 m_id = t_pTag->toFiffID();
276 qWarning(
"Fiff::open: file does have a directory pointer");
277 this->device()->close();
284 qInfo(
"Creating tag directory for %s...", t_sFileName.toUtf8().constData());
286 qint32 dirpos = *t_pTag->toInt();
292 m_dir = this->make_dir(&ok);
294 qCritical (
"Could not create tag directory!");
299 if(!this->
read_tag(t_pTag, dirpos)) {
300 qCritical(
"Could not read the tag directory (file probably damaged)!");
303 m_dir = t_pTag->toDirEntry();
309 if (m_dir[m_dir.size()-2]->kind ==
FIFF_DIR) {
311 m_dir[m_dir.size()-1]->kind = -1;
312 m_dir[m_dir.size()-1]->type = -1;
313 m_dir[m_dir.size()-1]->size = -1;
314 m_dir[m_dir.size()-1]->pos = -1;
320 if((this->m_dirtree = this->
make_subtree(m_dir)) ==
nullptr)
323 this->m_dirtree->parent.clear();
328 this->device()->seek(SEEK_SET);
336 if(this->device()->isOpen())
337 this->device()->close();
350 QList<FiffDirEntry::SPtr>
dir;
353 node->dir_tree = dentry;
359 if (!this->
read_tag(t_pTag,dentry[current]->pos))
362 node->type = *t_pTag->toInt();
365 node->id = this->
id();
370 for (; current < dentry.size(); ++current) {
375 QList<FiffDirEntry::SPtr> sub_dentry = dentry.mid(current);
378 child->parent = node;
379 node->children.append(child);
387 else if (dentry[current]->kind == -1)
389 else if (level == 0) {
396 if (!this->
read_tag(t_pTag,dentry[current]->pos))
398 node->id = t_pTag->toFiffID();
435 QList<FiffDirNode::SPtr> covs = p_Node->dir_tree_find(
FIFFB_MNE_COV);
436 if (covs.size() == 0)
438 qWarning(
"No covariance matrices found");
446 bool success =
false;
449 bool diagmat =
false;
456 for(p = 0; p < covs.size(); ++p)
459 if (success && *tag->toInt() == cov_kind)
467 qWarning(
"Covariance matrix dimension not found.\n");
474 nfree = *tag->toInt();
479 if (names.size() != dim)
481 qWarning(
"Number of names does not match covariance matrix dimension\n");
489 qWarning(
"No covariance matrix data found\n");
499 cov_diag = Map<VectorXd>(tag->toDouble(),dim);
503 cov_diag = Map<VectorXf>(tag->toFloat(),dim).cast<
double>();
506 qCritical(
"Illegal data type for covariance matrix\n");
511 qInfo(
"\t%d x %d diagonal covariance (kind = %d) found.\n", dim, dim, cov_kind);
520 vals = Map<VectorXd>(tag->toDouble(),nn);
524 vals = Map<VectorXf>(tag->toFloat(),nn).cast<
double>();
528 qDebug() << tag->getInfo();
537 cov = MatrixXd::Zero(dim,dim);
541 for(qint32 j = 0; j < dim; ++j)
543 for(qint32 k = 0; k <= j; ++k)
549 for(qint32 j = 0; j < dim; ++j)
550 for(qint32 k = j+1; k < dim; ++k)
554 qInfo(
"\t%d x %d full covariance (kind = %d) found.\n", dim, dim, cov_kind);
560 qDebug() <<
"ToDo: FiffStream::read_cov - this needs to be debugged.\n";
562 qInfo(
"\t%d x %d sparse covariance (kind = %d) found.\n", dim, dim, cov_kind);
601 eig = VectorXd(Map<VectorXd>(tag1->toDouble(),dim));
602 eigvec = tag2->toFloatMatrix().cast<
double>();
603 eigvec.transposeInPlace();
608 QList<FiffProj> projs = this->
read_proj(current);
618 p_covData.
kind = cov_kind;
619 p_covData.
diag = diagmat;
621 p_covData.
names = names;
623 if(cov_diag.size() > 0)
624 p_covData.
data = cov_diag;
625 else if(cov.size() > 0)
626 p_covData.
data = cov;
627 else if(cov_sparse.size() > 0)
628 p_covData.
data = cov_sparse;
630 p_covData.
projs = projs;
631 p_covData.
bads = bads;
632 p_covData.
nfree = nfree;
634 p_covData.
eigvec = eigvec;
641 qInfo(
"Did not find the desired covariance matrix\n");
649 QList<FiffCtfComp> compdata;
652 qint32 i, k, p, col, row;
655 for (k = 0; k < t_qListComps.size(); ++k)
663 for(p = 0; p < node->nent(); ++p)
665 kind = node->dir[p]->kind;
666 pos = node->dir[p]->pos;
675 qWarning(
"Compensation type not found\n");
682 one.
ctfkind = *t_pTag->toInt();
689 else if (one.
ctfkind == 1194476114)
691 else if (one.
ctfkind == 1194541650)
693 else if (one.
ctfkind == 1194479433)
695 else if (one.
ctfkind == 1194544969)
700 for (p = 0; p < node->nent(); ++p)
702 kind = node->dir[p]->kind;
703 pos = node->dir[p]->pos;
714 calibrated = (bool)*t_pTag->toInt();
717 one.
rowcals = MatrixXd::Ones(1,mat->data.rows());
718 one.
colcals = MatrixXd::Ones(1,mat->data.cols());
727 QStringList ch_names;
728 for (p = 0; p < p_Chs.size(); ++p)
729 ch_names.append(p_Chs[p].ch_name);
732 MatrixXd col_cals(mat->data.cols(), 1);
734 for (col = 0; col < mat->data.cols(); ++col)
737 for (i = 0; i < ch_names.size(); ++i)
739 if (QString::compare(mat->col_names.at(col),ch_names.at(i)) == 0)
747 qWarning(
"Channel %s is not available in data",mat->col_names.at(col).toUtf8().constData());
752 qWarning(
"Ambiguous channel %s",mat->col_names.at(col).toUtf8().constData());
755 col_cals(col,0) = 1.0f/(p_Chs[p].range*p_Chs[p].cal);
760 MatrixXd row_cals(mat->data.rows(), 1);
762 for (row = 0; row < mat->data.rows(); ++row)
765 for (i = 0; i < ch_names.size(); ++i)
767 if (QString::compare(mat->row_names.at(row),ch_names.at(i)) == 0)
776 qWarning(
"Channel %s is not available in data",mat->row_names.at(row).toUtf8().constData());
781 qWarning(
"Ambiguous channel %s",mat->row_names.at(row).toUtf8().constData());
785 row_cals(row, 0) = p_Chs[p].range*p_Chs[p].cal;
787 mat->data = row_cals.asDiagonal()* mat->data *col_cals.asDiagonal();
792 compdata.append(one);
795 if (compdata.size() > 0)
796 qInfo(
"\tRead %lld compensation matrices\n",compdata.size());
811 QList<FiffDirNode::SPtr> t_qListDigData = p_Node->dir_tree_find(
FIFFB_ISOTRAK);
814 if(t_qListDigData.isEmpty()) {
817 if(t_qListDigData.isEmpty()) {
818 printf(
"No Isotrak data found in %s", this->
streamName().toLatin1().data());
828 for (
int k = 0; k < t_qListDigData.first()->
nent(); ++k) {
829 kind = t_qListDigData.first()->dir[k]->kind;
830 pos = t_qListDigData.first()->dir[k]->pos;
835 p_digData.
points.append(t_pTag->toDigPoint());
844 npoint = p_digData.
points.size();
847 printf(
"No digitizer data in %s", this->
streamName().toLatin1().data());
851 for (
auto& dig : p_digData.
points){
857 p_digData.
npoint = npoint;
859 for (
int k = 0; k < p_digData.
npoint; k++) {
860 p_digData.
active.append(1);
871 p_InfoForward.
clear();
878 if (parent_meg.size() == 0)
880 qWarning(
"No parent MEG information found in operator\n");
886 QList<FiffChInfo> chs;
891 for (qint32 k = 0; k < parent_meg[0]->nent(); ++k)
893 kind = parent_meg[0]->dir[k]->kind;
894 pos = parent_meg[0]->dir[k]->pos;
898 chs.append( t_pTag->toChInfo() );
906 p_InfoForward.
chs = chs;
907 for (qint32 c = 0; c < p_InfoForward.
chs.size(); ++c)
908 p_InfoForward.
ch_names << p_InfoForward.
chs[c].ch_name;
910 p_InfoForward.
nchan = chs.size();
917 cand = t_pTag->toCoordTrans();
923 qWarning(
"MEG device/head coordinate transformation not found");
926 qWarning(
"MEG/head coordinate transformation not found.\n");
946 QList<FiffDirNode::SPtr> meas = p_Node->dir_tree_find(
FIFFB_MEAS);
948 if (meas.size() == 0)
950 qWarning(
"Could not find measurement data\n");
954 QList<FiffDirNode::SPtr> meas_info = meas[0]->dir_tree_find(
FIFFB_MEAS_INFO);
955 if (meas_info.count() == 0) {
956 qWarning(
"Could not find measurement info\n");
967 float linefreq = -1.0f;
968 QList<FiffChInfo> chs;
969 float lowpass = -1.0f;
970 float highpass = -1.0f;
973 QString proj_name =
"";
974 QString xplotter_layout =
"";
976 QString utc_offset =
"";
979 QString experimenter =
"";
980 QString description =
"";
995 for (qint32 k = 0; k < meas_info[0]->nent(); ++k)
997 kind = meas_info[0]->dir[k]->kind;
998 pos = meas_info[0]->dir[k]->pos;
1003 nchan = *t_pTag->toInt();
1007 sfreq = *t_pTag->toFloat();
1011 linefreq = *t_pTag->toFloat();
1015 chs.append( t_pTag->toChInfo() );
1019 lowpass = *t_pTag->toFloat();
1023 highpass = *t_pTag->toFloat();
1027 meas_date[0] = t_pTag->toInt()[0];
1028 meas_date[1] = t_pTag->toInt()[1];
1033 cand = t_pTag->toCoordTrans();
1041 proj_id = *t_pTag->toInt();
1045 proj_name = t_pTag->toString();
1049 xplotter_layout = t_pTag->toString();
1053 experimenter = t_pTag->toString();
1057 description = t_pTag->toString();
1061 gantry_angle = *t_pTag->toInt();
1065 utc_offset = t_pTag->toString();
1074 qWarning(
"Number of channels in not defined\n");
1079 qWarning(
"Sampling frequency is not defined\n");
1084 qWarning(
"Line frequency is not defined\n");
1086 if (chs.size() == 0)
1088 qWarning(
"Channel information not defined\n");
1091 if (chs.size() != nchan)
1093 qWarning(
"Incorrect number of channel definitions found\n");
1099 QList<FiffDirNode::SPtr> hpi_result = meas_info[0]->dir_tree_find(
FIFFB_HPI_RESULT);
1100 if (hpi_result.size() == 1)
1102 for( qint32 k = 0; k < hpi_result[0]->nent(); ++k)
1104 kind = hpi_result[0]->dir[k]->kind;
1105 pos = hpi_result[0]->dir[k]->pos;
1109 cand = t_pTag->toCoordTrans();
1121 QList<FiffDirNode::SPtr> isotrak = meas_info[0]->dir_tree_find(
FIFFB_ISOTRAK);
1123 QList<FiffDigPoint> dig;
1128 if (isotrak.size() == 1)
1130 for (k = 0; k < isotrak[0]->nent(); ++k)
1132 kind = isotrak[0]->dir[k]->kind;
1133 pos = isotrak[0]->dir[k]->pos;
1137 dig.append(t_pTag->toDigPoint());
1144 qDebug() <<
"NEEDS To BE DEBBUGED: FIFF_MNE_COORD_FRAME" << t_pTag->getType();
1145 coord_frame = *t_pTag->toInt();
1150 qDebug() <<
"NEEDS To BE DEBBUGED: FIFF_COORD_TRANS" << t_pTag->getType();
1151 dig_trans = t_pTag->toCoordTrans();
1156 for(k = 0; k < dig.size(); ++k)
1157 dig[k].coord_frame = coord_frame;
1160 if (dig_trans.
from != coord_frame && dig_trans.
to != coord_frame)
1166 QList<FiffDirNode::SPtr> acqpars = meas_info[0]->dir_tree_find(
FIFFB_DACQ_PARS);
1169 if (acqpars.size() == 1)
1171 for( k = 0; k < acqpars[0]->nent(); ++k)
1173 kind = acqpars[0]->dir[k]->kind;
1174 pos = acqpars[0]->dir[k]->pos;
1178 acq_pars = t_pTag->toString();
1183 acq_stim = t_pTag->toString();
1190 QList<FiffProj> projs = this->
read_proj(meas_info[0]);
1194 QList<FiffCtfComp> comps = this->
read_ctf_comp(meas_info[0], chs);
1203 if (p_Node->id.version != -1)
1211 if (meas_info[0]->parent_id.version == -1)
1213 if (meas_info[0]->
id.version == -1)
1215 if (meas[0]->
id.version == -1)
1217 if (meas[0]->parent_id.version == -1)
1220 info.
meas_id = meas[0]->parent_id;
1226 info.
meas_id = meas_info[0]->id;
1229 info.
meas_id = meas_info[0]->parent_id;
1231 if (meas_date[0] == -1)
1246 if (highpass != -1.0f)
1251 if (lowpass != -1.0f)
1261 for (qint32 c = 0; c < info.
nchan; ++c)
1299 p_NodeInfo = meas[0];
1314 bool found_it =
false;
1317 for (
int k = 0; k < node->nchild(); ++k)
1321 if(node->children[k]->has_tag(matkind))
1323 node = node->children[k];
1331 qWarning(
"Fiff::read_named_matrix: Desired named matrix (kind = %d) not available\n",matkind);
1337 if (!node->has_tag(matkind))
1339 qWarning(
"Desired named matrix (kind = %d) not available",matkind);
1348 if(!node->find_tag(
this, matkind, t_pTag))
1350 qWarning(
"Matrix data missing.\n");
1356 mat.
data = t_pTag->toFloatMatrix().cast<
double>();
1357 mat.
data.transposeInPlace();
1364 if (*t_pTag->toInt() != mat.
nrow)
1366 qWarning(
"Number of rows in matrix data and FIFF_MNE_NROW tag do not match");
1370 if (*t_pTag->toInt() != mat.
ncol)
1372 qWarning(
"Number of columns in matrix data and FIFF_MNE_NCOL tag do not match");
1378 row_names = t_pTag->toString();
1382 col_names = t_pTag->toString();
1387 if (!row_names.isEmpty())
1390 if (!col_names.isEmpty())
1395 qWarning(
"FiffStream::read_named_matrix - Number of rows in matrix data and row names do not match\n");
1400 qWarning(
"FiffStream::read_named_matrix - Number of columns in matrix data and column names do not match\n");
1410 QList<FiffProj> projdata;
1414 QList<FiffDirNode::SPtr> t_qListNodes = p_Node->dir_tree_find(
FIFFB_PROJ);
1415 if ( t_qListNodes.size() == 0 )
1419 t_qListNodes[0]->find_tag(
this,
FIFF_NCHAN, t_pTag);
1422 global_nchan = *t_pTag->toInt();
1425 QList<FiffDirNode::SPtr> t_qListItems = t_qListNodes[0]->dir_tree_find(
FIFFB_PROJ_ITEM);
1426 for ( qint32 i = 0; i < t_qListItems.size(); ++i)
1432 t_pFiffDirTreeItem->find_tag(
this,
FIFF_NCHAN, t_pTag);
1434 nchan = *t_pTag->toInt();
1436 nchan = global_nchan;
1442 qDebug() <<
"read_proj: this has to be debugged";
1443 desc = t_pTag->toString();
1447 t_pFiffDirTreeItem->find_tag(
this,
FIFF_NAME, t_pTag);
1449 desc = t_pTag->toString();
1452 qWarning(
"Projection item description missing\n");
1471 kind = *t_pTag->toInt();
1475 qWarning(
"Projection item kind missing");
1482 nvec = *t_pTag->toInt();
1486 qWarning(
"Number of projection vectors not specified\n");
1497 qWarning(
"Projection item channel list missing\n");
1504 data = t_pTag->toFloatMatrix().cast<
double>();
1505 data.transposeInPlace();
1509 qWarning(
"Projection item data missing\n");
1515 active = *t_pTag->toInt();
1519 if (data.cols() != names.size())
1521 qWarning(
"Number of channel names does not match the size of data matrix\n");
1528 QStringList defaultList;
1529 FiffNamedMatrix t_fiffNamedMatrix(nvec, nchan, defaultList, names, data);
1531 FiffProj one(kind, active, desc, t_fiffNamedMatrix);
1533 projdata.append(one);
1536 if (projdata.size() > 0)
1538 printf(
"\tRead a total of %lld projection items:\n", projdata.size());
1539 for(qint32 k = 0; k < projdata.size(); ++k)
1541 printf(
"\t\t%s (%d x %d)",projdata[k].desc.toUtf8().constData(), projdata[k].data->nrow, projdata[k].data->ncol);
1542 if (projdata[k].active)
1543 printf(
" active\n");
1558 this->device()->seek(pos);
1567 if (p_pTag->size() > 0)
1569 this->readRawData(p_pTag->data(), p_pTag->size());
1574 this->device()->seek(p_pTag->next);
1595 *
this >> p_pTag->kind;
1596 *
this >> p_pTag->type;
1599 p_pTag->resize(size);
1600 *
this >> p_pTag->next;
1606 QTcpSocket* t_qTcpSocket = qobject_cast<QTcpSocket*>(this->device());
1609 this->skipRawData(p_pTag->size());
1613 if (p_pTag->next > 0)
1615 if(!this->device()->seek(p_pTag->next)) {
1622 if(!this->device()->seek(this->device()->pos()+p_pTag->size())) {
1636 while(this->device()->bytesAvailable() < 16)
1637 this->device()->waitForReadyRead(10);
1643 while(this->device()->bytesAvailable() < p_pTag->size())
1644 this->device()->waitForReadyRead(10);
1658 this->device()->seek(pos);
1666 *
this >> p_pTag->kind;
1667 *
this >> p_pTag->type;
1670 p_pTag->resize(size);
1671 *
this >> p_pTag->next;
1679 if (this->byteOrder() == QDataStream::LittleEndian){
1687 if (p_pTag->size() > 0)
1689 this->readRawData(p_pTag->data(), p_pTag->size());
1696 this->device()->seek(p_pTag->next);
1705 bool allow_maxshield,
1706 bool is_littleEndian)
1712 QString t_sFileName = t_pStream->streamName();
1714 if(is_littleEndian){
1716 t_pStream->setByteOrder(QDataStream::LittleEndian);
1719 qInfo(
"Opening raw data %s...\n",t_sFileName.toUtf8().constData());
1721 if(!t_pStream->open()){
1730 if(!t_pStream->read_meas_info(t_pStream->dirtree(), info, meas))
1736 QList<FiffDirNode::SPtr> raw = meas->dir_tree_find(
FIFFB_RAW_DATA);
1737 if (raw.size() == 0)
1746 qInfo(
"Maxshield data found\n");
1748 if (raw.size() == 0)
1750 qWarning(
"No raw data in %s\n", t_sFileName.toUtf8().constData());
1756 if (raw.size() == 0)
1758 qWarning(
"No raw data in %s\n", t_sFileName.toUtf8().constData());
1769 data.
file = t_pStream;
1776 QList<FiffDirEntry::SPtr>
dir = raw[0]->dir;
1788 t_pStream->read_tag(t_pTag,
dir[first]->pos);
1789 first_samp = *t_pTag->toInt();
1800 t_pStream->read_tag(t_pTag,
dir[first]->pos);
1801 first_skip = *t_pTag->toInt();
1808 QList<FiffRawDir> rawdir;
1813 for (qint32 k = first; k <
nent; ++k)
1818 t_pStream->read_tag(t_pTag, ent->pos);
1819 nskip = *t_pTag->toInt();
1829 nsamp = ent->size/(2*nchan);
1832 nsamp = ent->size/(2*nchan);
1835 nsamp = ent->size/(4*nchan);
1838 nsamp = ent->size/(4*nchan);
1841 qWarning(
"Cannot handle data buffers of type %d\n",ent->type);
1849 first_samp += nsamp*first_skip;
1859 t_RawDir.
first = first_samp;
1860 t_RawDir.
last = first_samp + nskip*nsamp - 1;
1861 t_RawDir.
nsamp = nskip*nsamp;
1862 rawdir.append(t_RawDir);
1863 first_samp = first_samp + nskip*nsamp;
1872 t_RawDir.
first = first_samp;
1873 t_RawDir.
last = first_samp + nsamp - 1;
1874 t_RawDir.
nsamp = nsamp;
1875 rawdir.append(t_RawDir);
1876 first_samp += nsamp;
1886 for (qint32 k = 0; k < data.
info.
nchan; ++k)
1894 qInfo(
"\tRange : %d ... %d = %9.3f ... %9.3f secs",
1908 return p_sNameList.replace(
" ",
"").split(
":");
1923 QString t_sFileName = p_pStream->streamName();
1925 if(!p_pStream->device()->open(QIODevice::WriteOnly))
1927 qWarning(
"Cannot write to %s\n", t_sFileName.toUtf8().constData());
1929 return p_pEmptyStream;
1951 QString t_sFileName = t_pStream->streamName();
1956 if(!t_pStream->open(QIODevice::ReadWrite)) {
1957 qCritical(
"Cannot open %s\n", t_sFileName.toUtf8().constData());
1962 long dirpos,pointerpos;
1964 QFile *file = qobject_cast<QFile *>(t_pStream->device());
1966 if (file !=
nullptr) {
1970 pointerpos = t_pStream->dir()[t_pStream->nent()-2]->pos;
1971 if(!t_pStream->read_tag(t_pTag,pointerpos)){
1972 qCritical(
"Could not read last tag in the directory list!");
1978 t_pStream->write_tag(t_pTag,pointerpos);
1983 pointerpos = t_pStream->dir()[1]->pos;
1984 if(!t_pStream->read_tag(t_pTag,pointerpos)){
1985 qCritical(
"Could not read directory pointer!");
1992 dirpos = *t_pTag->toInt();
1997 t_pStream->write_dir_pointer(-1, pointerpos);
2001 file->resize(dirpos);
2006 t_pStream->device()->seek(file->size());
2027 sel.resize(1,info.
nchan);
2028 for (k = 0; k < info.
nchan; ++k)
2032 QList<FiffChInfo> chs;
2034 for(k = 0; k < sel.cols(); ++k)
2035 chs << info.
chs.at(sel(0,k));
2059 QList<fiff_int_t> blocks;
2061 bool have_hpi_result =
false;
2062 bool have_isotrak =
false;
2063 if (blocks.size() > 0 && !info.
filename.isEmpty())
2068 if(!t_pStream2->open()){
2069 qDebug() <<
"Failed to open file. Returning early";
2073 for(qint32 k = 0; k < blocks.size(); ++k)
2075 QList<FiffDirNode::SPtr> nodes = t_pStream2->dirtree()->dir_tree_find(blocks[k]);
2078 have_hpi_result =
true;
2081 have_isotrak =
true;
2107 if (!have_hpi_result)
2110 t_pStream->write_coord_trans(info.
dev_head_t);
2113 t_pStream->write_coord_trans(info.
ctf_head_t);
2118 if (info.
dig.size() > 0 && !have_isotrak)
2121 for (qint32 k = 0; k < info.
dig.size(); ++k)
2122 t_pStream->write_dig_point(info.
dig[k]);
2131 t_pStream->write_proj(info.
projs);
2135 t_pStream->write_ctf_comp(info.
comps);
2139 if (info.
bads.size() > 0)
2165 cals = RowVectorXd(nchan);
2166 for(k = 0; k < nchan; ++k)
2171 chs[k].scanNo = k+1;
2175 cals[k] = chs[k].cal;
2176 t_pStream->write_ch_info(chs[k]);
2197 this->device()->seek(pos);
2200 QFile* file = qobject_cast<QFile*> (this->device());
2202 this->device()->seek(file->size());
2204 pos = this->device()->pos();
2208 *this << static_cast<qint32>(p_pTag->kind);
2209 *this << static_cast<qint32>(p_pTag->type);
2210 *this << static_cast<qint32>(datasize);
2211 *this << static_cast<qint32>(p_pTag->next);
2220 this->writeRawData(p_pTag->data(),datasize);
2255 *
this << (qint32)datasize;
2261 *
this << (qint32)ch.
scanNo;
2262 *
this << (qint32)ch.
logNo;
2263 *
this << (qint32)ch.
kind;
2276 *
this << (qint32)ch.
unit;
2285 ch_name = ch.
ch_name.mid(0, 15);
2289 len = ch_name.size();
2291 this->writeRawData(ch_name.toUtf8().constData(),len);
2294 const char* chNull =
"";
2295 for(qint32 i = 0; i < 16-len; ++i)
2296 this->writeRawData(chNull,1);
2315 for(i = 0; i < 3; ++i)
2316 *
this << chpos.
r0[i];
2318 for(i = 0; i < 3; ++i)
2319 *
this << chpos.
ex[i];
2321 for(i = 0; i < 3; ++i)
2322 *
this << chpos.
ey[i];
2324 for(i = 0; i < 3; ++i)
2325 *
this << chpos.
ez[i];
2348 *
this << (qint32)datasize;
2354 *
this << (qint32)trans.
from;
2355 *
this << (qint32)trans.
to;
2361 for (r = 0; r < 3; ++r)
2362 for (c = 0; c < 3; ++c)
2363 *
this << (
float)trans.
trans(r,c);
2364 for (r = 0; r < 3; ++r)
2365 *
this << (
float)trans.
trans(r,3);
2370 for (r = 0; r < 3; ++r)
2371 for (c = 0; c < 3; ++c)
2372 *
this << (
float)trans.
invtrans(r,c);
2373 for (r = 0; r < 3; ++r)
2374 *
this << (
float)trans.
invtrans(r,3);
2392 if (p_FiffCov.
nfree > 0)
2397 if(p_FiffCov.
names.size() > 0)
2411 qint32 dim = p_FiffCov.
dim;
2412 qint32 n = ((dim*dim) - dim)/2;
2416 for(qint32 i = 1; i < dim; ++i)
2417 for(qint32 j = 0; j < i; ++j)
2418 vals(count) = p_FiffCov.
data(i,j);
2426 if(p_FiffCov.
eig.size() > 0 && p_FiffCov.
eigvec.size() > 0)
2438 if(p_FiffCov.
bads.size() > 0)
2458 if (comps.size() <= 0)
2464 for(qint32 k = 0; k < comps.size(); ++k)
2478 if(comps[k].save_calibrated) {
2479 comp.
data->data = (comp.
rowcals.asDiagonal()).inverse()* comp.
data->data * (comp.
colcals.asDiagonal()).inverse();
2507 *
this << (qint32)datasize;
2513 *
this << (qint32)dig.
kind;
2514 *
this << (qint32)dig.
ident;
2515 for(qint32 i = 0; i < 3; ++i)
2529 this->device()->seek(pos);
2532 QFile* file = qobject_cast<QFile*> (this->device());
2534 this->device()->seek(file->size());
2536 pos = this->device()->pos();
2542 *
this << (qint32)datasize;
2543 *
this << (qint32)next;
2568 this->device()->seek(pos);
2571 QFile* file = qobject_cast<QFile*> (this->device());
2573 this->device()->seek(file->size());
2576 pos = this->device()->pos();
2583 *
this << (qint32)datasize;
2589 for(qint32 i = 0; i <
nent; ++i) {
2590 *
this << (qint32)
dir[i]->kind;
2591 *
this << (qint32)
dir[i]->type;
2592 *
this << (qint32)
dir[i]->size;
2593 *
this << (qint32)
dir[i]->pos;
2605 qint32 datasize = nel * 8;
2607 *
this << (qint32)kind;
2609 *
this << (qint32)datasize;
2612 for(qint32 i = 0; i < nel; ++i)
2624 qint32 datasize = nel * 4;
2626 *
this << (qint32)kind;
2628 *
this << (qint32)datasize;
2631 for(qint32 i = 0; i < nel; ++i)
2643 qint32 numel = mat.rows() * mat.cols();
2647 *
this << (qint32)kind;
2649 *
this << (qint32)datasize;
2654 for(i = 0; i < mat.rows(); ++i)
2655 for(j = 0; j < mat.cols(); ++j)
2659 dims[0] = mat.cols();
2660 dims[1] = mat.rows();
2663 for(i = 0; i < 3; ++i)
2683 qint32 nnzm = mat.nonZeros();
2684 qint32 ncol = mat.cols();
2685 fiff_int_t datasize = 4*nnzm + 4*nnzm + 4*(ncol+1) + 4*4;
2689 typedef Eigen::Triplet<float> T;
2691 s.reserve(mat.nonZeros());
2692 for (
int k=0; k < mat.outerSize(); ++k)
2693 for (SparseMatrix<float>::InnerIterator it(mat,k); it; ++it)
2694 s.push_back(T(it.row(), it.col(), it.value()));
2699 std::vector<qint32> cols, starts;
2702 for(i = 0; i < s.size(); ++i)
2704 if((
signed) s[i].col() != v_old)
2707 cols.push_back(s[i].col());
2708 starts.push_back(i);
2712 *
this << (qint32)kind;
2714 *
this << (qint32)datasize;
2720 for(i = 0; i < s.size(); ++i)
2721 *
this << s[i].value();
2726 for(i = 0; i < s.size(); ++i)
2727 *
this << s[i].row();
2732 RowVectorXi ptrs = RowVectorXi::Ones(ncol+1);
2735 for(k = 0; k < cols.size(); ++k)
2736 ptrs[cols[k]] = starts[k];
2741 for(k = ncol; k >= 1; --k)
2743 ptrs[k-1] = ptrs[k];
2745 for(i = 0; i < (quint32)ptrs.size(); ++i)
2751 dims[0] = mat.nonZeros();
2752 dims[1] = mat.rows();
2753 dims[2] = mat.cols();
2756 for(i = 0; i < 4; ++i)
2776 qint32 nnzm = mat.nonZeros();
2777 qint32 nrow = mat.rows();
2778 fiff_int_t datasize = 4*nnzm + 4*nnzm + 4*(nrow+1) + 4*4;
2782 typedef Eigen::Triplet<float> T;
2784 s.reserve(mat.nonZeros());
2785 for (
int k=0; k < mat.outerSize(); ++k)
2786 for (SparseMatrix<float>::InnerIterator it(mat,k); it; ++it)
2787 s.push_back(T(it.row(), it.col(), it.value()));
2792 std::vector<qint32> rows, starts;
2795 for(i = 0; i < s.size(); ++i)
2797 if((
signed) s[i].row() != v_old)
2800 rows.push_back(s[i].row());
2801 starts.push_back(i);
2808 *
this << (qint32)kind;
2810 *
this << (qint32)datasize;
2816 for(i = 0; i < s.size(); ++i)
2817 *
this << s[i].value();
2822 for(i = 0; i < s.size(); ++i)
2823 *
this << s[i].col();
2828 RowVectorXi ptrs = RowVectorXi::Ones(nrow+1);
2831 for(k = 0; k < rows.size(); ++k)
2832 ptrs[rows[k]] = starts[k];
2838 for(k = nrow; k >= 1; --k)
2840 ptrs[k-1] = ptrs[k];
2843 for(i = 0; i < (quint32)ptrs.size(); ++i)
2850 dims[0] = mat.nonZeros();
2851 dims[1] = mat.rows();
2852 dims[2] = mat.cols();
2855 for(i = 0; i < 4; ++i)
2880 *
this << (qint32)kind;
2882 *
this << (qint32)datasize;
2889 data[1] = t_id.
machid[0];
2890 data[2] = t_id.
machid[1];
2894 for(qint32 i = 0; i < 5; ++i)
2923 QList<FiffChInfo> chs;
2924 for(k = 0; k < p_FiffInfoBase.
nchan; ++k)
2925 chs << p_FiffInfoBase.
chs[k];
2927 for(k = 0; k < p_FiffInfoBase.
nchan; ++k)
2932 chs[k].scanNo = k+1;
2939 bool have_hpi_result =
false;
2944 if (!have_hpi_result)
2955 if (p_FiffInfoBase.
bads.size() > 0)
2975 *
this << (qint32)kind;
2977 *
this << (qint32)datasize;
2978 *
this << (qint32)next;
2980 for(qint32 i = 0; i < nel; ++i)
2995 qint32 numel = mat.rows() * mat.cols();
2999 *
this << (qint32)kind;
3001 *
this << (qint32)datasize;
3006 for(i = 0; i < mat.rows(); ++i)
3007 for(j = 0; j < mat.cols(); ++j)
3011 dims[0] = mat.cols();
3012 dims[1] = mat.rows();
3015 for(i = 0; i < 3; ++i)
3025 QString all = data.join(
":");
3054 if (projs.size() <= 0)
3059 for(qint32 k = 0; k < projs.size(); ++k)
3066 float fValue = 0.0f;
3072 qint32 bValue = (qint32)projs[k].active;
3089 if (p_FiffEvokedSet.
evoked.isEmpty())
3100 for (
int j = 0; j < p_FiffEvokedSet.
evoked.size(); ++j) {
3113 int nave = evoked.
nave;
3116 int first = evoked.
first;
3119 int last = evoked.
last;
3122 Eigen::MatrixXf floatData = evoked.
data.cast<
float>();
3123 for (
int ch = 0; ch < floatData.rows(); ++ch) {
3125 static_cast<int>(floatData.cols()));
3141 const RowVectorXd& cals)
3143 if (buf.rows() != cals.cols())
3145 qWarning(
"buffer and calibration sizes do not match\n");
3149 typedef Eigen::Triplet<double> T;
3150 std::vector<T> tripletList;
3151 tripletList.reserve(cals.cols());
3152 for(qint32 i = 0; i < cals.cols(); ++i)
3153 tripletList.push_back(T(i, i, 1.0/cals[i]));
3155 SparseMatrix<double> inv_calsMat(cals.cols(), cals.cols());
3156 inv_calsMat.setFromTriplets(tripletList.begin(), tripletList.end());
3158 MatrixXf tmp = (inv_calsMat*buf).cast<float>();
3166 const SparseMatrix<double>& mult)
3168 if (buf.rows() != mult.cols()) {
3169 qWarning(
"buffer and mult sizes do not match\n");
3173 SparseMatrix<double> inv_mult(mult.rows(), mult.cols());
3174 for (
int k=0; k<inv_mult.outerSize(); ++k)
3175 for (SparseMatrix<double>::InnerIterator it(mult,k); it; ++it)
3176 inv_mult.coeffRef(it.row(),it.col()) = 1/it.value();
3178 MatrixXf tmp = (inv_mult*buf).cast<float>();
3187 MatrixXf tmp = buf.cast<
float>();
3195 const QString& data)
3200 *
this << (qint32)kind;
3202 *
this << (qint32)datasize;
3205 this->writeRawData(data.toUtf8().constData(),datasize);
3217 *
this << 4+(qint32)datasize;
3221 this->writeRawData(data.toUtf8().constData(),datasize);
3226QList<FiffDirEntry::SPtr> FiffStream::make_dir(
bool *ok)
3229 QList<FiffDirEntry::SPtr>
dir;
3236 if(!this->device()->seek(SEEK_SET))
3248 t_pFiffDirEntry->kind = t_pTag->kind;
3249 t_pFiffDirEntry->type = t_pTag->type;
3250 t_pFiffDirEntry->size = t_pTag->size();
3255 dir.append(t_pFiffDirEntry);
3256 if (t_pTag->next < 0)
3263 t_pFiffDirEntry->kind = -1;
3264 t_pFiffDirEntry->type = -1;
3265 t_pFiffDirEntry->size = -1;
3266 t_pFiffDirEntry->pos = -1;
3267 dir.append(t_pFiffDirEntry);
3281 qWarning(
"Fiff::open: file does not start with a file id tag\n");
3287 qWarning(
"Fiff::open: file does not start with a file id tag\n");
3290 if (p_pTag->size() != 20)
3292 qWarning(
"Fiff::open: file does not start with a file id tag\n");
FiffChPos class declaration.
FiffTag class declaration, which provides fiff tag I/O and processing methods.
FiffInfo class declaration.
#define FIFF_MNE_COV_KIND
#define FIFF_MNE_COORD_FRAME
#define FIFF_MNE_CTF_COMP_KIND
#define FIFFV_COORD_DEVICE
#define FIFF_MNE_COV_DIAG
#define FIFFB_MNE_CTF_COMP_DATA
#define FIFF_MNE_CTF_COMP_CALIBRATED
#define FIFF_MNE_ROW_NAMES
#define FIFF_MNE_COV_EIGENVALUES
#define FIFF_MNE_PROJ_ITEM_ACTIVE
#define FIFFV_MNE_COORD_CTF_HEAD
#define FIFF_MNE_COL_NAMES
#define FIFF_MNE_RT_COMMAND
#define FIFF_MNE_CTF_COMP_DATA
#define FIFF_MNE_CH_NAME_LIST
#define FIFFB_MNE_CTF_COMP
#define FIFF_MNE_COV_NFREE
#define FIFFB_MNE_PARENT_MEAS_FILE
#define FIFF_MNE_COV_EIGENVECTORS
#define FIFFV_COORD_UNKNOWN
#define FIFFB_MNE_BAD_CHANNELS
#define FIFFB_MNE_NAMED_MATRIX
#define FIFF_MNE_FILE_NAME
FiffStream class declaration.
FiffDigitizerData class declaration.
FiffInfoBase class declaration.
FiffRawData class declaration.
FiffDirNode class declaration, which provides fiff dir tree processing methods.
FiffCtfComp class declaration.
FiffChInfo class declaration.
FiffId class declaration.
FiffCov class declaration.
FiffEvokedSet class declaration.
#define FIFF_GANTRY_ANGLE
#define FIFF_PARENT_BLOCK_ID
#define FIFFV_PROJ_ITEM_FIELD
#define FIFF_XPLOTTER_LAYOUT
#define FIFFB_PROCESSING_HISTORY
#define FIFFT_MATRIX_FLOAT
#define FIFFT_CH_INFO_STRUCT
#define FIFF_EXPERIMENTER
#define FIFFT_RCS_MATRIX_FLOAT
#define FIFFT_CCS_MATRIX_FLOAT
#define FIFF_FIRST_SAMPLE
#define FIFFV_ASPECT_AVERAGE
#define FIFFB_SMSH_RAW_DATA
#define FIFF_PROJ_ITEM_TIME
#define FIFFV_LITTLE_ENDIAN
#define FIFFB_PROCESSED_DATA
#define FIFFV_ASPECT_STD_ERR
#define FIFF_PROJ_ITEM_VECTORS
#define FIFF_PROJ_ITEM_KIND
#define FIFFB_HPI_SUBSYSTEM
#define FIFFB_CONTINUOUS_DATA
#define FIFFV_NATIVE_ENDIAN
#define FIFF_PROJ_ITEM_CH_NAME_LIST
#define FIFFT_DIR_ENTRY_STRUCT
#define FIFFT_COORD_TRANS_STRUCT
#define FIFFT_DIG_POINT_STRUCT
#define FIFF_PROJ_ITEM_NVEC
FiffCoordTrans class declaration.
FiffDigPoint class declaration.
IOUtils class declaration.
MNEMath class declaration.
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Measurement channel position and coil type.
Coordinate transformation description.
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > trans
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > invtrans
CTF software compensation data.
FiffNamedMatrix::SDPtr data
Digitization point description.
Digitization points container and description.
QList< FIFFLIB::FiffDigPoint > points
Directory entry description.
QSharedPointer< FiffDirEntry > SPtr
Directory node structure.
QSharedPointer< FiffDirNode > SPtr
static bool copy_tree(QSharedPointer< FiffStream > &p_pStreamIn, const FiffId &in_id, const QList< QSharedPointer< FiffDirNode > > &p_Nodes, QSharedPointer< FiffStream > &p_pStreamOut)
QList< FiffEvoked > evoked
Universally unique identifier.
static FiffId new_file_id()
FIFF measurement file information.
QList< FiffCtfComp > comps
QList< FiffDigPoint > dig
FiffCoordTrans ctf_head_t
FiffCoordTrans dev_head_t
QSharedDataPointer< FiffNamedMatrix > SDPtr
FIFF raw measurement data.
QList< FiffRawDir > rawdir
fiff_long_t write_tag(const QSharedPointer< FiffTag > &p_pTag, fiff_long_t pos=-1)
bool write_raw_buffer(const Eigen::MatrixXd &buf, const Eigen::RowVectorXd &cals)
fiff_long_t write_cov(const FiffCov &p_FiffCov)
bool read_cov(const FiffDirNode::SPtr &p_Node, fiff_int_t cov_kind, FiffCov &p_covData)
fiff_long_t write_dir_entries(const QList< FiffDirEntry::SPtr > &dir, fiff_long_t pos=-1)
fiff_long_t start_block(fiff_int_t kind)
fiff_long_t write_float_matrix(fiff_int_t kind, const Eigen::MatrixXf &mat)
fiff_long_t write_proj(const QList< FiffProj > &projs)
bool read_tag(QSharedPointer< FiffTag > &p_pTag, fiff_long_t pos=-1)
fiff_long_t write_int_matrix(fiff_int_t kind, const Eigen::MatrixXi &mat)
bool read_meas_info_base(const FiffDirNode::SPtr &p_Node, FiffInfoBase &p_InfoForward)
fiff_long_t write_dig_point(const FiffDigPoint &dig)
fiff_long_t write_int(fiff_int_t kind, const fiff_int_t *data, fiff_int_t nel=1, fiff_int_t next=FIFFV_NEXT_SEQ)
static bool setup_read_raw(QIODevice &p_IODevice, FiffRawData &data, bool allow_maxshield=true, bool is_littleEndian=false)
QList< FiffCtfComp > read_ctf_comp(const FiffDirNode::SPtr &p_Node, const QList< FiffChInfo > &p_Chs)
fiff_long_t write_float(fiff_int_t kind, const float *data, fiff_int_t nel=1)
fiff_long_t write_id(fiff_int_t kind, const FiffId &id=FiffId::getDefault())
fiff_long_t write_float_sparse_rcs(fiff_int_t kind, const Eigen::SparseMatrix< float > &mat)
fiff_long_t write_ch_pos(const FiffChPos &chpos)
void write_rt_command(fiff_int_t command, const QString &data)
fiff_long_t write_coord_trans(const FiffCoordTrans &trans)
bool get_evoked_entries(const QList< FiffDirNode::SPtr > &evoked_node, QStringList &comments, QList< fiff_int_t > &aspect_kinds, QString &t)
bool read_tag_data(QSharedPointer< FiffTag > &p_pTag, fiff_long_t pos=-1)
fiff_long_t write_name_list(fiff_int_t kind, const QStringList &data)
bool read_meas_info(const FiffDirNode::SPtr &p_Node, FiffInfo &p_Info, FiffDirNode::SPtr &p_NodeInfo)
bool open(QIODevice::OpenModeFlag mode=QIODevice::ReadOnly)
fiff_long_t read_tag_info(QSharedPointer< FiffTag > &p_pTag, bool p_bDoSkip=true)
fiff_long_t write_named_matrix(fiff_int_t kind, const FiffNamedMatrix &mat)
bool read_rt_tag(QSharedPointer< FiffTag > &p_pTag)
FiffStream(QIODevice *p_pIODevice)
static QStringList split_name_list(QString p_sNameList)
fiff_long_t write_string(fiff_int_t kind, const QString &data)
QStringList read_bad_channels(const FiffDirNode::SPtr &p_Node)
fiff_long_t write_evoked_set(const FiffEvokedSet &p_FiffEvokedSet)
const FiffDirNode::SPtr & dirtree() const
bool read_digitizer_data(const FiffDirNode::SPtr &p_Node, FiffDigitizerData &p_digData)
static FiffStream::SPtr start_writing_raw(QIODevice &p_IODevice, const FiffInfo &info, Eigen::RowVectorXd &cals, Eigen::MatrixXi sel=defaultMatrixXi, bool bResetRange=true)
fiff_long_t write_dir_pointer(fiff_int_t dirpos, fiff_long_t pos=-1, fiff_int_t next=FIFFV_NEXT_SEQ)
static FiffStream::SPtr start_file(QIODevice &p_IODevice)
fiff_long_t write_info_base(const FiffInfoBase &p_FiffInfoBase)
fiff_long_t end_block(fiff_int_t kind, fiff_int_t next=FIFFV_NEXT_SEQ)
fiff_long_t write_float_sparse_ccs(fiff_int_t kind, const Eigen::SparseMatrix< float > &mat)
fiff_long_t write_ch_info(const FiffChInfo &ch)
fiff_long_t write_ctf_comp(const QList< FiffCtfComp > &comps)
fiff_long_t write_double(fiff_int_t kind, const double *data, fiff_int_t nel=1)
QList< FiffProj > read_proj(const FiffDirNode::SPtr &p_Node)
static FiffStream::SPtr open_update(QIODevice &p_IODevice)
FiffDirNode::SPtr make_subtree(QList< FiffDirEntry::SPtr > &dentry)
bool read_named_matrix(const FiffDirNode::SPtr &p_Node, fiff_int_t matkind, FiffNamedMatrix &mat)
void finish_writing_raw()
QSharedPointer< FiffStream > SPtr
QList< FiffDirEntry::SPtr > & dir()
QSharedPointer< FiffTag > SPtr
static void convert_tag_data(FiffTag::SPtr tag, int from_endian, int to_endian)
static bool issparse(Eigen::VectorXd &v)
static std::vector< Eigen::Triplet< T > > sortrows(const std::vector< Eigen::Triplet< T > > &A, qint32 column=0)