76 : QDataStream(p_pIODevice)
78 this->setFloatingPointPrecision(QDataStream::SinglePrecision);
79 this->setByteOrder(QDataStream::BigEndian);
80 this->setVersion(QDataStream::Qt_5_0);
87 : QDataStream(a, mode)
89 this->setFloatingPointPrecision(QDataStream::SinglePrecision);
90 this->setByteOrder(QDataStream::BigEndian);
91 this->setVersion(QDataStream::Qt_5_0);
122 fiff_int_t datasize = 0;
124 *
this << (qint32)FIFF_NOP;
125 *
this << (qint32)FIFFT_VOID;
126 *
this << (qint32)datasize;
127 *
this << (qint32)FIFFV_NEXT_NONE;
138 this->device()->close();
147 aspect_kinds.clear();
148 QList<FiffDirTree>::ConstIterator ev;
153 for(ev = evoked_node.begin(); ev != evoked_node.end(); ++ev)
155 for(k = 0; k < ev->nent; ++k)
157 kind = ev->dir[k].kind;
158 pos = ev->dir[k].pos;
159 if (kind == FIFF_COMMENT)
162 comments.append(t_pTag->toString());
166 for(k = 0; k < my_aspect.
nent; ++k)
168 kind = my_aspect.
dir[k].kind;
169 pos = my_aspect.
dir[k].pos;
170 if (kind == FIFF_ASPECT_KIND)
173 aspect_kinds.append(*t_pTag->toInt());
178 if(comments.size() != aspect_kinds.size() || comments.size() == 0)
180 qWarning(
"Dataset names in FIF file could not be found.");
185 for(k = 0; k < aspect_kinds.size(); ++k)
187 t += QString(
"%1 - \"%2\" (").arg(k).arg(comments[k]);
189 t += QString(
"FIFFV_ASPECT_AVERAGE)\n");
191 t += QString(
"FIFFV_ASPECT_STD_ERR)\n");
193 t += QString(
"unknown)\n");
206 if (!this->device()->
open(QIODevice::ReadOnly))
208 printf(
"Cannot open %s\n", t_sFileName.toUtf8().constData());
215 if (t_pTag->kind != FIFF_FILE_ID)
217 printf(
"Fiff::open: file does not start with a file id tag");
221 if (t_pTag->type != FIFFT_ID_STRUCT)
223 printf(
"Fiff::open: file does not start with a file id tag");
226 if (t_pTag->size() != 20)
228 printf(
"Fiff::open: file does not start with a file id tag");
234 if (t_pTag->kind != FIFF_DIR_POINTER)
236 printf(
"Fiff::open: file does have a directory pointer");
243 printf(
"\nCreating tag directory for %s...", t_sFileName.toUtf8().constData());
246 qint32 dirpos = *t_pTag->toInt();
250 p_Dir = t_pTag->toDirEntry();
255 this->device()->seek(0);
257 while (t_pTag->next >= 0)
259 t_fiffDirEntry.
pos = this->device()->pos();
262 t_fiffDirEntry.
kind = t_pTag->kind;
263 t_fiffDirEntry.
type = t_pTag->type;
264 t_fiffDirEntry.
size = t_pTag->size();
265 p_Dir.append(t_fiffDirEntry);
279 this->device()->seek(0);
288 QList<FiffDirTree> node = p_Node.
dir_tree_find(FIFFB_MNE_BAD_CHANNELS);
294 if(node[0].find_tag(
this, FIFF_MNE_CH_NAME_LIST, t_pTag))
310 QList<FiffDirTree> covs = p_Node.
dir_tree_find(FIFFB_MNE_COV);
311 if (covs.size() == 0)
313 printf(
"No covariance matrices found");
321 bool success =
false;
322 fiff_int_t dim, nfree, nn;
324 bool diagmat =
false;
331 for(p = 0; p < covs.size(); ++p)
334 if (success && *tag->toInt() == cov_kind)
342 printf(
"Covariance matrix dimension not found.\n");
349 nfree = *tag->toInt();
351 if (current->
find_tag(
this, FIFF_MNE_ROW_NAMES, tag))
354 if (names.size() != dim)
356 printf(
"Number of names does not match covariance matrix dimension\n");
364 printf(
"No covariance matrix data found\n");
372 if (tag->type == FIFFT_DOUBLE)
374 cov_diag = Map<VectorXd>(tag->toDouble(),dim);
376 else if (tag->type == FIFFT_FLOAT)
378 cov_diag = Map<VectorXf>(tag->toFloat(),dim).cast<double>();
381 printf(
"Illegal data type for covariance matrix\n");
386 printf(
"\t%d x %d diagonal covariance (kind = %d) found.\n", dim, dim, cov_kind);
393 if (tag->type == FIFFT_DOUBLE)
395 vals = Map<VectorXd>(tag->toDouble(),nn);
397 else if (tag->type == FIFFT_FLOAT)
399 vals = Map<VectorXf>(tag->toFloat(),nn).cast<double>();
403 qDebug() << tag->getInfo();
407 if(!MNEMath::issparse(vals))
412 cov = MatrixXd::Zero(dim,dim);
416 for(qint32 j = 0; j < dim; ++j)
418 for(qint32 k = 0; k <= j; ++k)
424 for(qint32 j = 0; j < dim; ++j)
425 for(qint32 k = j+1; k < dim; ++k)
429 printf(
"\t%d x %d full covariance (kind = %d) found.\n", dim, dim, cov_kind);
435 qDebug() <<
"ToDo: FiffStream::read_cov - this needs to be debugged.\n";
437 printf(
"\t%d x %d sparse covariance (kind = %d) found.\n", dim, dim, cov_kind);
476 eig = VectorXd(Map<VectorXd>(tag1->toDouble(),dim));
477 eigvec = tag2->toFloatMatrix().cast<
double>();
478 eigvec.transposeInPlace();
483 QList<FiffProj> projs = this->
read_proj(*current);
493 p_covData.
kind = cov_kind;
494 p_covData.
diag = diagmat;
496 p_covData.
names = names;
498 if(cov_diag.size() > 0)
499 p_covData.
data = cov_diag;
500 else if(cov.size() > 0)
501 p_covData.
data = cov;
502 else if(cov_sparse.size() > 0)
503 p_covData.
data = cov_sparse;
505 p_covData.
projs = projs;
506 p_covData.
bads = bads;
507 p_covData.
nfree = nfree;
509 p_covData.
eigvec = eigvec;
516 printf(
"Did not find the desired covariance matrix\n");
525 QList<FiffCtfComp> compdata;
526 QList<FiffDirTree> t_qListComps = p_Node.
dir_tree_find(FIFFB_MNE_CTF_COMP_DATA);
528 qint32 i, k, p, col, row;
529 fiff_int_t kind, pos;
531 for (k = 0; k < t_qListComps.size(); ++k)
539 for(p = 0; p < node->
nent; ++p)
541 kind = node->
dir.at(p).kind;
542 pos = node->
dir.at(p).pos;
551 printf(
"Compensation type not found\n");
558 one.
ctfkind = *t_pTag->toInt();
565 else if (one.
ctfkind == 1194476114)
567 else if (one.
ctfkind == 1194541650)
572 for (p = 0; p < node->
nent; ++p)
574 kind = node->
dir.at(p).kind;
575 pos = node->
dir.at(p).pos;
586 calibrated = (bool)*t_pTag->toInt();
589 one.
rowcals = MatrixXd::Ones(1,mat->data.rows());
590 one.
colcals = MatrixXd::Ones(1,mat->data.cols());
599 QStringList ch_names;
600 for (p = 0; p < p_Chs.size(); ++p)
601 ch_names.append(p_Chs[p].ch_name);
604 MatrixXd col_cals(mat->data.cols(), 1);
606 for (col = 0; col < mat->data.cols(); ++col)
609 for (i = 0; i < ch_names.size(); ++i)
611 if (QString::compare(mat->col_names.at(col),ch_names.at(i)) == 0)
619 printf(
"Channel %s is not available in data",mat->col_names.at(col).toUtf8().constData());
624 printf(
"Ambiguous channel %s",mat->col_names.at(col).toUtf8().constData());
627 col_cals(col,0) = 1.0f/(p_Chs[p].range*p_Chs[p].cal);
632 MatrixXd row_cals(mat->data.rows(), 1);
634 for (row = 0; row < mat->data.rows(); ++row)
637 for (i = 0; i < ch_names.size(); ++i)
639 if (QString::compare(mat->row_names.at(row),ch_names.at(i)) == 0)
648 printf(
"Channel %s is not available in data",mat->row_names.at(row).toUtf8().constData());
653 printf(
"Ambiguous channel %s",mat->row_names.at(row).toUtf8().constData());
657 row_cals(row, 0) = p_Chs[p].range*p_Chs[p].cal;
659 mat->data = row_cals.asDiagonal()* mat->data *col_cals.asDiagonal();
664 compdata.append(one);
667 if (compdata.size() > 0)
668 printf(
"\tRead %d compensation matrices\n",compdata.size());
678 p_InfoForward.
clear();
683 QList<FiffDirTree> parent_meg = p_Node.
dir_tree_find(FIFFB_MNE_PARENT_MEAS_FILE);
685 if (parent_meg.size() == 0)
687 printf(
"No parent MEG information found in operator\n");
693 QList<FiffChInfo> chs;
695 fiff_int_t kind = -1;
698 for (qint32 k = 0; k < parent_meg[0].nent; ++k)
700 kind = parent_meg[0].dir[k].kind;
701 pos = parent_meg[0].dir[k].pos;
702 if (kind == FIFF_CH_INFO)
705 chs.append( t_pTag->toChInfo() );
713 p_InfoForward.
chs = chs;
714 for (qint32 c = 0; c < p_InfoForward.
chs.size(); ++c)
715 p_InfoForward.
ch_names << p_InfoForward.
chs[c].ch_name;
717 p_InfoForward.
nchan = chs.size();
722 if(parent_meg[0].find_tag(
this, FIFF_COORD_TRANS, t_pTag))
724 cand = t_pTag->toCoordTrans();
725 if(cand.
from == FIFFV_COORD_DEVICE && cand.
to == FIFFV_COORD_HEAD)
730 printf(
"MEG device/head coordinate transformation not found");
733 printf(
"MEG/head coordinate transformation not found.\n");
756 if (meas.size() == 0)
758 printf(
"Could not find measurement data\n");
762 QList<FiffDirTree> meas_info = meas[0].dir_tree_find(FIFFB_MEAS_INFO);
763 if (meas_info.count() == 0)
765 printf(
"Could not find measurement info\n");
774 fiff_int_t nchan = -1;
776 QList<FiffChInfo> chs;
777 float lowpass = -1.0f;
778 float highpass = -1.0f;
786 fiff_int_t meas_date[2];
790 fiff_int_t kind = -1;
793 for (qint32 k = 0; k < meas_info[0].nent; ++k)
795 kind = meas_info[0].dir[k].kind;
796 pos = meas_info[0].dir[k].pos;
801 nchan = *t_pTag->toInt();
805 sfreq = *t_pTag->toFloat();
809 chs.append( t_pTag->toChInfo() );
813 lowpass = *t_pTag->toFloat();
817 highpass = *t_pTag->toFloat();
821 meas_date[0] = t_pTag->toInt()[0];
822 meas_date[1] = t_pTag->toInt()[1];
824 case FIFF_COORD_TRANS:
827 cand = t_pTag->toCoordTrans();
828 if(cand.
from == FIFFV_COORD_DEVICE && cand.
to == FIFFV_COORD_HEAD)
840 printf(
"Number of channels in not defined\n");
845 printf(
"Sampling frequency is not defined\n");
850 printf(
"Channel information not defined\n");
853 if (chs.size() != nchan)
855 printf(
"Incorrect number of channel definitions found\n");
861 QList<FiffDirTree> hpi_result = meas_info[0].dir_tree_find(FIFFB_HPI_RESULT);
862 if (hpi_result.size() == 1)
864 for( qint32 k = 0; k < hpi_result[0].nent; ++k)
866 kind = hpi_result[0].dir[k].kind;
867 pos = hpi_result[0].dir[k].pos;
868 if (kind == FIFF_COORD_TRANS)
871 cand = t_pTag->toCoordTrans();
872 if (cand.
from == FIFFV_COORD_DEVICE && cand.
to == FIFFV_COORD_HEAD)
883 QList<FiffDirTree> isotrak = meas_info[0].dir_tree_find(FIFFB_ISOTRAK);
885 QList<FiffDigPoint> dig;
886 fiff_int_t coord_frame = FIFFV_COORD_HEAD;
890 if (isotrak.size() == 1)
892 for (k = 0; k < isotrak[0].nent; ++k)
894 kind = isotrak[0].dir[k].kind;
895 pos = isotrak[0].dir[k].pos;
896 if (kind == FIFF_DIG_POINT)
899 dig.append(t_pTag->toDigPoint());
906 qDebug() <<
"NEEDS To BE DEBBUGED: FIFF_MNE_COORD_FRAME" << t_pTag->getType();
907 coord_frame = *t_pTag->toInt();
909 else if (kind == FIFF_COORD_TRANS)
912 qDebug() <<
"NEEDS To BE DEBBUGED: FIFF_COORD_TRANS" << t_pTag->getType();
913 dig_trans = t_pTag->toCoordTrans();
918 for(k = 0; k < dig.size(); ++k)
919 dig[k].coord_frame = coord_frame;
922 if (dig_trans.
from != coord_frame && dig_trans.
to != coord_frame)
928 QList<FiffDirTree> acqpars = meas_info[0].dir_tree_find(FIFFB_DACQ_PARS);
931 if (acqpars.size() == 1)
933 for( k = 0; k < acqpars[0].nent; ++k)
935 kind = acqpars[0].dir.at(k).kind;
936 pos = acqpars[0].dir.at(k).pos;
937 if (kind == FIFF_DACQ_PARS)
940 acq_pars = t_pTag->toString();
942 else if (kind == FIFF_DACQ_STIM)
945 acq_stim = t_pTag->toString();
952 QList<FiffProj> projs = this->
read_proj(meas_info[0]);
956 QList<FiffCtfComp> comps = this->
read_ctf_comp(meas_info[0], chs);
973 if (meas_info[0].parent_id.version == -1)
975 if (meas_info[0].
id.version == -1)
977 if (meas[0].
id.version == -1)
979 if (meas[0].parent_id.version == -1)
982 info.
meas_id = meas[0].parent_id;
988 info.
meas_id = meas_info[0].id;
991 info.
meas_id = meas_info[0].parent_id;
993 if (meas_date[0] == -1)
1006 if (highpass != -1.0f)
1011 if (lowpass != -1.0f)
1021 for (qint32 c = 0; c < info.
nchan; ++c)
1051 p_NodeInfo = meas[0];
1067 bool found_it =
false;
1068 if (node.
block != FIFFB_MNE_NAMED_MATRIX)
1070 for (
int k = 0; k < node.
nchild; ++k)
1072 if (node.
children[k].block == FIFFB_MNE_NAMED_MATRIX)
1074 if(node.
children[k].has_tag(matkind))
1084 printf(
"Fiff::read_named_matrix: Desired named matrix (kind = %d) not available\n",matkind);
1092 printf(
"Desired named matrix (kind = %d) not available",matkind);
1101 if(!node.
find_tag(
this, matkind, t_pTag))
1103 printf(
"Matrix data missing.\n");
1109 mat.
data = t_pTag->toFloatMatrix().cast<
double>();
1110 mat.
data.transposeInPlace();
1116 if(node.
find_tag(
this, FIFF_MNE_NROW, t_pTag))
1117 if (*t_pTag->toInt() != mat.
nrow)
1119 printf(
"Number of rows in matrix data and FIFF_MNE_NROW tag do not match");
1122 if(node.
find_tag(
this, FIFF_MNE_NCOL, t_pTag))
1123 if (*t_pTag->toInt() != mat.
ncol)
1125 printf(
"Number of columns in matrix data and FIFF_MNE_NCOL tag do not match");
1130 if(node.
find_tag(
this, FIFF_MNE_ROW_NAMES, t_pTag))
1131 row_names = t_pTag->toString();
1134 if(node.
find_tag(
this, FIFF_MNE_COL_NAMES, t_pTag))
1135 col_names = t_pTag->toString();
1140 if (!row_names.isEmpty())
1143 if (!col_names.isEmpty())
1154 QList<FiffProj> projdata;
1158 QList<FiffDirTree> t_qListNodes = p_Node.
dir_tree_find(FIFFB_PROJ);
1159 if ( t_qListNodes.size() == 0 )
1164 t_qListNodes[0].find_tag(
this, FIFF_NCHAN, t_pTag);
1165 fiff_int_t global_nchan = 0;
1167 global_nchan = *t_pTag->toInt();
1171 QList<FiffDirTree> t_qListItems = t_qListNodes[0].dir_tree_find(FIFFB_PROJ_ITEM);
1172 for ( qint32 i = 0; i < t_qListItems.size(); ++i)
1177 FiffDirTree* t_pFiffDirTreeItem = &t_qListItems[i];
1178 t_pFiffDirTreeItem->
find_tag(
this, FIFF_NCHAN, t_pTag);
1180 nchan = *t_pTag->toInt();
1182 nchan = global_nchan;
1184 t_pFiffDirTreeItem->
find_tag(
this, FIFF_DESCRIPTION, t_pTag);
1188 qDebug() <<
"read_proj: this has to be debugged";
1189 desc = t_pTag->toString();
1193 t_pFiffDirTreeItem->
find_tag(
this, FIFF_NAME, t_pTag);
1195 desc = t_pTag->toString();
1198 printf(
"Projection item description missing\n");
1213 t_pFiffDirTreeItem->
find_tag(
this, FIFF_PROJ_ITEM_KIND, t_pTag);
1217 kind = *t_pTag->toInt();
1221 printf(
"Projection item kind missing");
1224 t_pFiffDirTreeItem->
find_tag(
this, FIFF_PROJ_ITEM_NVEC, t_pTag);
1228 nvec = *t_pTag->toInt();
1232 printf(
"Number of projection vectors not specified\n");
1235 t_pFiffDirTreeItem->
find_tag(
this, FIFF_PROJ_ITEM_CH_NAME_LIST, t_pTag);
1243 printf(
"Projection item channel list missing\n");
1246 t_pFiffDirTreeItem->
find_tag(
this, FIFF_PROJ_ITEM_VECTORS, t_pTag);
1250 data = t_pTag->toFloatMatrix().cast<
double>();
1251 data.transposeInPlace();
1255 printf(
"Projection item data missing\n");
1261 active = *t_pTag->toInt();
1265 if (data.cols() != names.size())
1267 printf(
"Number of channel names does not match the size of data matrix\n");
1276 QStringList defaultList;
1277 FiffNamedMatrix t_fiffNamedMatrix(nvec, nchan, defaultList, names, data);
1279 FiffProj one(kind, active, desc, t_fiffNamedMatrix);
1281 projdata.append(one);
1284 if (projdata.size() > 0)
1286 printf(
"\tRead a total of %d projection items:\n", projdata.size());
1287 for(qint32 k = 0; k < projdata.size(); ++k)
1289 printf(
"\t\t%s (%d x %d)",projdata[k].desc.toUtf8().constData(), projdata[k].data->nrow, projdata[k].data->ncol);
1290 if (projdata[k].active)
1291 printf(
" active\n");
1308 QString t_sFileName = p_pStream->streamName();
1310 printf(
"Opening raw data %s...\n",t_sFileName.toUtf8().constData());
1313 QList<FiffDirEntry> t_Dir;
1315 if(!p_pStream->open(t_Tree, t_Dir))
1323 if(!p_pStream->read_meas_info(t_Tree, info, meas))
1329 QList<FiffDirTree> raw = meas.
dir_tree_find(FIFFB_RAW_DATA);
1330 if (raw.size() == 0)
1339 if (raw.size() == 0)
1341 printf(
"No raw data in %s\n", t_sFileName.toUtf8().constData());
1347 if (raw.size() == 0)
1349 printf(
"No raw data in %s\n", t_sFileName.toUtf8().constData());
1360 data.
file = p_pStream;
1368 QList<FiffDirEntry> dir = raw[0].dir;
1369 fiff_int_t nent = raw[0].nent;
1370 fiff_int_t nchan = info.
nchan;
1371 fiff_int_t first = 0;
1372 fiff_int_t first_samp = 0;
1373 fiff_int_t first_skip = 0;
1378 if (dir[first].kind == FIFF_FIRST_SAMPLE)
1381 first_samp = *t_pTag->toInt();
1394 first_skip = *t_pTag->toInt();
1401 QList<FiffRawDir> rawdir;
1403 fiff_int_t nskip = 0;
1404 fiff_int_t ndir = 0;
1405 fiff_int_t nsamp = 0;
1406 for (qint32 k = first; k < nent; ++k)
1412 nskip = *t_pTag->toInt();
1421 case FIFFT_DAU_PACK16:
1422 nsamp = ent.
size/(2*nchan);
1425 nsamp = ent.
size/(2*nchan);
1428 nsamp = ent.
size/(4*nchan);
1431 nsamp = ent.
size/(4*nchan);
1434 printf(
"Cannot handle data buffers of type %d\n",ent.
type);
1442 first_samp += nsamp*first_skip;
1452 t_RawDir.
first = first_samp;
1453 t_RawDir.
last = first_samp + nskip*nsamp - 1;
1454 t_RawDir.
nsamp = nskip*nsamp;
1455 rawdir.append(t_RawDir);
1456 first_samp = first_samp + nskip*nsamp;
1465 t_RawDir.
first = first_samp;
1466 t_RawDir.
last = first_samp + nsamp - 1;
1467 t_RawDir.
nsamp = nsamp;
1468 rawdir.append(t_RawDir);
1469 first_samp += nsamp;
1479 for (qint32 k = 0; k < data.
info.
nchan; ++k)
1487 printf(
"\tRange : %d ... %d = %9.3f ... %9.3f secs\n",
1492 data.
file->device()->close();
1502 return p_sNameList.split(
":");
1509 this->
write_int(FIFF_BLOCK_START,&kind);
1518 QString t_sFileName = p_pStream->streamName();
1520 if(!p_pStream->device()->open(QIODevice::WriteOnly))
1522 printf(
"Cannot write to %s\n", t_sFileName.toUtf8().constData());
1524 return p_pEmptyStream;
1530 p_pStream->write_id(FIFF_FILE_ID);
1532 p_pStream->write_int(FIFF_DIR_POINTER,&data);
1533 p_pStream->write_int(FIFF_FREE_LIST,&data);
1548 fiff_int_t data_type = 4;
1553 sel.resize(1,info.
nchan);
1554 for (k = 0; k < info.
nchan; ++k)
1558 QList<FiffChInfo> chs;
1560 for(k = 0; k < sel.cols(); ++k)
1561 chs << info.
chs.at(sel(0,k));
1563 fiff_int_t nchan = chs.size();
1569 t_pStream->start_block(FIFFB_MEAS);
1570 t_pStream->write_id(FIFF_BLOCK_ID);
1573 t_pStream->write_id(FIFF_PARENT_BLOCK_ID,info.
meas_id);
1579 t_pStream->start_block(FIFFB_MEAS_INFO);
1583 QList<fiff_int_t> blocks;
1584 blocks << FIFFB_SUBJECT << FIFFB_HPI_MEAS << FIFFB_HPI_RESULT << FIFFB_ISOTRAK << FIFFB_PROCESSING_HISTORY;
1585 bool have_hpi_result =
false;
1586 bool have_isotrak =
false;
1587 if (blocks.size() > 0 && !info.
filename.isEmpty())
1593 QList<FiffDirEntry> t_Dir;
1594 t_pStream2->open(t_Tree, t_Dir);
1596 for(qint32 k = 0; k < blocks.size(); ++k)
1600 if(blocks[k] == FIFFB_HPI_RESULT && nodes.size() > 0)
1601 have_hpi_result =
true;
1603 if(blocks[k] == FIFFB_ISOTRAK && nodes.size() > 0)
1604 have_isotrak =
true;
1614 t_pStream->start_block(FIFFB_DACQ_PARS);
1616 t_pStream->write_string(FIFF_DACQ_PARS, info.
acq_pars);
1619 t_pStream->write_string(FIFF_DACQ_STIM, info.
acq_stim);
1621 t_pStream->end_block(FIFFB_DACQ_PARS);
1626 if (!have_hpi_result)
1629 t_pStream->write_coord_trans(info.
dev_head_t);
1632 t_pStream->write_coord_trans(info.
ctf_head_t);
1637 if (info.
dig.size() > 0 && !have_isotrak)
1639 t_pStream->start_block(FIFFB_ISOTRAK);
1640 for (qint32 k = 0; k < info.
dig.size(); ++k)
1641 t_pStream->write_dig_point(info.
dig[k]);
1643 t_pStream->end_block(FIFFB_ISOTRAK);
1648 t_pStream->write_proj(info.
projs);
1652 t_pStream->write_ctf_comp(info.
comps);
1656 if (info.
bads.size() > 0)
1658 t_pStream->start_block(FIFFB_MNE_BAD_CHANNELS);
1659 t_pStream->write_name_list(FIFF_MNE_CH_NAME_LIST,info.
bads);
1660 t_pStream->end_block(FIFFB_MNE_BAD_CHANNELS);
1665 t_pStream->write_float(FIFF_SFREQ,&info.
sfreq);
1666 t_pStream->write_float(FIFF_HIGHPASS,&info.
highpass);
1667 t_pStream->write_float(FIFF_LOWPASS,&info.
lowpass);
1668 t_pStream->write_int(FIFF_NCHAN,&nchan);
1669 t_pStream->write_int(FIFF_DATA_PACK,&data_type);
1671 t_pStream->write_int(FIFF_MEAS_DATE,info.
meas_date, 2);
1675 cals = RowVectorXd(nchan);
1677 for(k = 0; k < nchan; ++k)
1682 chs[k].scanno = k+1;
1684 cals[k] = chs[k].cal;
1685 t_pStream->write_ch_info(&chs[k]);
1689 t_pStream->end_block(FIFFB_MEAS_INFO);
1693 t_pStream->start_block(FIFFB_RAW_DATA);
1703 QFile* t_pFile = qobject_cast<QFile*>(this->device());
1704 QString p_sFileName;
1706 p_sFileName = t_pFile->fileName();
1708 p_sFileName = QString(
"TCPSocket");
1738 fiff_int_t datasize= 4*13 + 4*7 + 16;
1740 *
this << (qint32)FIFF_CH_INFO;
1741 *
this << (qint32)FIFFT_CH_INFO_STRUCT;
1742 *
this << (qint32)datasize;
1743 *
this << (qint32)FIFFV_NEXT_SEQ;
1748 *
this << (qint32)ch->
scanno;
1749 *
this << (qint32)ch->
logno;
1750 *
this << (qint32)ch->
kind;
1760 for(i = 0; i < 12; ++i)
1761 *
this << ch->
loc(i,0);
1766 *
this << (qint32)ch->
unit;
1772 fiff_int_t len = ch->
ch_name.size();
1775 ch_name = ch->
ch_name.mid(0, 15);
1779 len = ch_name.size();
1781 this->writeRawData(ch_name.toUtf8().constData(),len);
1785 const char* chNull =
"";
1786 for(i = 0; i < 16-len; ++i)
1787 this->writeRawData(chNull,1);
1804 fiff_int_t datasize = 4*2*12 + 4*2;
1806 *
this << (qint32)FIFF_COORD_TRANS;
1807 *
this << (qint32)FIFFT_COORD_TRANS_STRUCT;
1808 *
this << (qint32)datasize;
1809 *
this << (qint32)FIFFV_NEXT_SEQ;
1814 *
this << (qint32)trans.
from;
1815 *
this << (qint32)trans.
to;
1821 for (r = 0; r < 3; ++r)
1822 for (c = 0; c < 3; ++c)
1823 *
this << (
float)trans.
trans(r,c);
1824 for (r = 0; r < 3; ++r)
1825 *
this << (
float)trans.
trans(r,3);
1830 for (r = 0; r < 3; ++r)
1831 for (c = 0; c < 3; ++c)
1832 *
this << (
float)trans.
invtrans(r,c);
1833 for (r = 0; r < 3; ++r)
1834 *
this << (
float)trans.
invtrans(r,3);
1849 if (p_FiffCov.
nfree > 0)
1854 if(p_FiffCov.
names.size() > 0)
1868 qint32 dim = p_FiffCov.
dim;
1869 qint32 n = ((dim*dim) - dim)/2;
1873 for(qint32 i = 1; i < dim; ++i)
1874 for(qint32 j = 0; j < i; ++j)
1875 vals(count) = p_FiffCov.
data(i,j);
1883 if(p_FiffCov.
eig.size() > 0 && p_FiffCov.
eigvec.size() > 0)
1895 if(p_FiffCov.
bads.size() > 0)
1899 this->
end_block(FIFFB_MNE_BAD_CHANNELS);
1912 if (comps.size() <= 0)
1918 for(qint32 k = 0; k < comps.size(); ++k)
1931 comp.
data->data = (comp.
rowcals.diagonal()).inverse()* comp.
data->data * (comp.
colcals.diagonal()).inverse();
1933 this->
end_block(FIFFB_MNE_CTF_COMP_DATA);
1952 fiff_int_t datasize = 5*4;
1954 *
this << (qint32)FIFF_DIG_POINT;
1955 *
this << (qint32)FIFFT_DIG_POINT_STRUCT;
1956 *
this << (qint32)datasize;
1957 *
this << (qint32)FIFFV_NEXT_SEQ;
1962 *
this << (qint32)dig.
kind;
1963 *
this << (qint32)dig.
ident;
1964 for(qint32 i = 0; i < 3; ++i)
1973 qint32 datasize = nel * 8;
1975 *
this << (qint32)kind;
1976 *
this << (qint32)FIFFT_DOUBLE;
1977 *
this << (qint32)datasize;
1978 *
this << (qint32)FIFFV_NEXT_SEQ;
1982 for(qint32 i = 0; i < nel; ++i)
1991 qint32 datasize = nel * 4;
1993 *
this << (qint32)kind;
1994 *
this << (qint32)FIFFT_FLOAT;
1995 *
this << (qint32)datasize;
1996 *
this << (qint32)FIFFV_NEXT_SEQ;
2000 for(qint32 i = 0; i < nel; ++i)
2009 qint32 FIFFT_MATRIX = 1 << 30;
2010 qint32 FIFFT_MATRIX_FLOAT = FIFFT_FLOAT | FIFFT_MATRIX;
2012 qint32 numel = mat.rows() * mat.cols();
2014 fiff_int_t datasize = 4*numel + 4*3;
2016 *
this << (qint32)kind;
2017 *
this << (qint32)FIFFT_MATRIX_FLOAT;
2018 *
this << (qint32)datasize;
2019 *
this << (qint32)FIFFV_NEXT_SEQ;
2022 for(i = 0; i < numel; ++i)
2023 *
this << mat.data()[i];
2026 dims[0] = mat.cols();
2027 dims[1] = mat.rows();
2030 for(i = 0; i < 3; ++i)
2039 qint32 FIFFT_MATRIX = 16400 << 16;
2040 qint32 FIFFT_MATRIX_FLOAT_CCS = FIFFT_FLOAT | FIFFT_MATRIX;
2050 qint32 nnzm = mat.nonZeros();
2051 qint32 ncol = mat.cols();
2052 fiff_int_t datasize = 4*nnzm + 4*nnzm + 4*(ncol+1) + 4*4;
2056 typedef Eigen::Triplet<float> T;
2058 s.reserve(mat.nonZeros());
2059 for (
int k=0; k < mat.outerSize(); ++k)
2060 for (SparseMatrix<float>::InnerIterator it(mat,k); it; ++it)
2061 s.push_back(T(it.row(), it.col(), it.value()));
2063 s = MNEMath::sortrows<float>(s, 1);
2066 std::vector<qint32> cols, starts;
2069 for(i = 0; i < s.size(); ++i)
2071 if((
signed) s[i].col() != v_old)
2074 cols.push_back(s[i].col());
2075 starts.push_back(i);
2079 *
this << (qint32)kind;
2080 *
this << (qint32)FIFFT_MATRIX_FLOAT_CCS;
2081 *
this << (qint32)datasize;
2082 *
this << (qint32)FIFFV_NEXT_SEQ;
2087 for(i = 0; i < s.size(); ++i)
2088 *
this << s[i].value();
2093 for(i = 0; i < s.size(); ++i)
2094 *
this << s[i].row();
2099 RowVectorXi ptrs = RowVectorXi::Ones(ncol+1);
2102 for(k = 0; k < cols.size(); ++k)
2103 ptrs[cols[k]] = starts[k];
2108 for(k = ncol; k >= 1; --k)
2110 ptrs[k-1] = ptrs[k];
2112 for(i = 0; i < (quint32)ptrs.size(); ++i)
2118 dims[0] = mat.nonZeros();
2119 dims[1] = mat.rows();
2120 dims[2] = mat.cols();
2123 for(i = 0; i < 4; ++i)
2132 qint32 FIFFT_MATRIX = 16416 << 16;
2133 qint32 FIFFT_MATRIX_FLOAT_RCS = FIFFT_FLOAT | FIFFT_MATRIX;
2143 qint32 nnzm = mat.nonZeros();
2144 qint32 nrow = mat.rows();
2145 fiff_int_t datasize = 4*nnzm + 4*nnzm + 4*(nrow+1) + 4*4;
2149 typedef Eigen::Triplet<float> T;
2151 s.reserve(mat.nonZeros());
2152 for (
int k=0; k < mat.outerSize(); ++k)
2153 for (SparseMatrix<float>::InnerIterator it(mat,k); it; ++it)
2154 s.push_back(T(it.row(), it.col(), it.value()));
2156 s = MNEMath::sortrows<float>(s);
2159 std::vector<qint32> rows, starts;
2162 for(i = 0; i < s.size(); ++i)
2164 if((
signed) s[i].row() != v_old)
2167 rows.push_back(s[i].row());
2168 starts.push_back(i);
2172 *
this << (qint32)kind;
2173 *
this << (qint32)FIFFT_MATRIX_FLOAT_RCS;
2174 *
this << (qint32)datasize;
2175 *
this << (qint32)FIFFV_NEXT_SEQ;
2180 for(i = 0; i < s.size(); ++i)
2181 *
this << s[i].value();
2186 for(i = 0; i < s.size(); ++i)
2187 *
this << s[i].col();
2192 RowVectorXi ptrs = RowVectorXi::Ones(nrow+1);
2195 for(k = 0; k < rows.size(); ++k)
2196 ptrs[rows[k]] = starts[k];
2202 for(k = nrow; k >= 1; --k)
2204 ptrs[k-1] = ptrs[k];
2207 for(i = 0; i < (quint32)ptrs.size(); ++i)
2214 dims[0] = mat.nonZeros();
2215 dims[1] = mat.rows();
2216 dims[2] = mat.cols();
2219 for(i = 0; i < 4; ++i)
2232 srand ( time(NULL) );
2233 double rand_1 = (double)(rand() % 100);rand_1 /= 100;
2234 double rand_2 = (double)(rand() % 100);rand_2 /= 100;
2237 seconds = time (NULL);
2241 t_id.
machid[0] = 65536*rand_1;
2242 t_id.
machid[1] = 65536*rand_2;
2249 fiff_int_t datasize = 5*4;
2251 *
this << (qint32)kind;
2252 *
this << (qint32)FIFFT_ID_STRUCT;
2253 *
this << (qint32)datasize;
2254 *
this << (qint32)FIFFV_NEXT_SEQ;
2260 data[1] = t_id.
machid[0];
2261 data[2] = t_id.
machid[1];
2265 for(qint32 i = 0; i < 5; ++i)
2291 QList<FiffChInfo> chs;
2292 for(k = 0; k < p_FiffInfoBase.
nchan; ++k)
2293 chs << p_FiffInfoBase.
chs[k];
2295 for(k = 0; k < p_FiffInfoBase.
nchan; ++k)
2300 chs[k].scanno = k+1;
2308 bool have_hpi_result =
false;
2313 if (!have_hpi_result)
2324 if (p_FiffInfoBase.
bads.size() > 0)
2328 this->
end_block(FIFFB_MNE_BAD_CHANNELS);
2331 this->
end_block(FIFFB_MNE_PARENT_MEAS_FILE);
2339 fiff_int_t datasize = nel * 4;
2341 *
this << (qint32)kind;
2342 *
this << (qint32)FIFFT_INT;
2343 *
this << (qint32)datasize;
2344 *
this << (qint32)FIFFV_NEXT_SEQ;
2346 for(qint32 i = 0; i < nel; ++i)
2355 qint32 FIFFT_MATRIX = 1 << 30;
2356 qint32 FIFFT_MATRIX_INT = FIFFT_INT | FIFFT_MATRIX;
2358 qint32 numel = mat.rows() * mat.cols();
2360 fiff_int_t datasize = 4*numel + 4*3;
2362 *
this << (qint32)kind;
2363 *
this << (qint32)FIFFT_MATRIX_INT;
2364 *
this << (qint32)datasize;
2365 *
this << (qint32)FIFFV_NEXT_SEQ;
2368 for(i = 0; i < numel; ++i)
2369 *
this << mat.data()[i];
2372 dims[0] = mat.cols();
2373 dims[1] = mat.rows();
2376 for(i = 0; i < 3; ++i)
2385 QString all = data.join(
":");
2402 this->
end_block(FIFFB_MNE_NAMED_MATRIX);
2410 if (projs.size() <= 0)
2415 for(qint32 k = 0; k < projs.size(); ++k)
2419 this->
write_int(FIFF_PROJ_ITEM_KIND,&projs[k].kind);
2420 if (projs[k].kind == FIFFV_PROJ_ITEM_FIELD)
2422 float fValue = 0.0f;
2426 this->
write_int(FIFF_NCHAN, &projs[k].data->ncol);
2427 this->
write_int(FIFF_PROJ_ITEM_NVEC, &projs[k].data->nrow);
2428 qint32 bValue = (qint32)projs[k].active;
2430 this->
write_name_list(FIFF_PROJ_ITEM_CH_NAME_LIST, projs[k].data->col_names);
2442 if (buf.rows() != cals.cols())
2444 printf(
"buffer and calibration sizes do not match\n");
2448 typedef Eigen::Triplet<double> T;
2449 std::vector<T> tripletList;
2450 tripletList.reserve(cals.cols());
2451 for(qint32 i = 0; i < cals.cols(); ++i)
2452 tripletList.push_back(T(i, i, 1.0/cals[i]));
2454 SparseMatrix<double> inv_calsMat(cals.cols(), cals.cols());
2455 inv_calsMat.setFromTriplets(tripletList.begin(), tripletList.end());
2457 MatrixXf tmp = (inv_calsMat*buf).cast<float>();
2467 if (buf.rows() != mult.cols()) {
2468 printf(
"buffer and mult sizes do not match\n");
2472 SparseMatrix<double> inv_mult(mult.rows(), mult.cols());
2473 for (
int k=0; k<inv_mult.outerSize(); ++k)
2474 for (SparseMatrix<double>::InnerIterator it(mult,k); it; ++it)
2475 inv_mult.coeffRef(it.row(),it.col()) = 1/it.value();
2477 MatrixXf tmp = (inv_mult*buf).cast<float>();
2487 MatrixXf tmp = buf.cast<
float>();
2497 fiff_int_t datasize = data.size();
2498 *
this << (qint32)kind;
2499 *
this << (qint32)FIFFT_STRING;
2500 *
this << (qint32)datasize;
2501 *
this << (qint32)FIFFV_NEXT_SEQ;
2503 this->writeRawData(data.toUtf8().constData(),datasize);
2511 fiff_int_t datasize = data.size();
2513 *
this << (qint32)FIFFT_VOID;
2514 *
this << 4+(qint32)datasize;
2515 *
this << (qint32)FIFFV_NEXT_SEQ;
2518 this->writeRawData(data.toUtf8().constData(),datasize);
void write_int_matrix(fiff_int_t kind, const MatrixXi &mat)
#define FIFF_MNE_CTF_COMP_KIND
void write_string(fiff_int_t kind, const QString &data)
static bool copy_tree(QSharedPointer< FiffStream > p_pStreamIn, FiffId &in_id, QList< FiffDirTree > &p_Nodes, QSharedPointer< FiffStream > p_pStreamOut)
QList< FiffCtfComp > comps
FIFF measurement file information.
QList< FiffDirTree > children
bool write_raw_buffer(const MatrixXd &buf, const RowVectorXd &cals)
static bool read_tag_info(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, bool p_bDoSkip=true)
void write_cov(const FiffCov &p_FiffCov)
bool find_tag(FiffStream *p_pStream, fiff_int_t findkind, QSharedPointer< FiffTag > &p_pTag) const
QList< FiffCtfComp > read_ctf_comp(const FiffDirTree &p_Node, const QList< FiffChInfo > &p_Chs)
static FiffStream::SPtr start_file(QIODevice &p_IODevice)
Directory entry description.
QStringList read_bad_channels(const FiffDirTree &p_Node)
static QStringList split_name_list(QString p_sNameList)
QList< FiffDirTree > dir_tree_find(fiff_int_t p_kind) const
Digitization point description.
void write_named_matrix(fiff_int_t kind, const FiffNamedMatrix &mat)
QList< FiffProj > read_proj(const FiffDirTree &p_Node)
QSharedDataPointer< FiffNamedMatrix > SDPtr
FiffDirTree class declaration, which provides fiff dir tree processing methods.
Universially unique identifier.
static qint32 make_dir_tree(FiffStream *p_pStream, QList< FiffDirEntry > &p_Dir, FiffDirTree &p_Tree, qint32 start=0)
QSharedPointer< FiffTag > SPtr
FiffCoordTrans ctf_head_t
#define FIFF_MNE_COV_NFREE
void write_rt_command(fiff_int_t command, const QString &data)
#define FIFF_MNE_COV_DIAG
void write_float_sparse_ccs(fiff_int_t kind, const SparseMatrix< float > &mat)
static bool read_tag(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, qint64 pos=-1)
#define FIFF_MNE_CTF_COMP_CALIBRATED
bool open(FiffDirTree &p_Tree, QList< FiffDirEntry > &p_Dir)
#define FIFF_MNE_CTF_COMP_DATA
#define FIFF_MNE_COV_EIGENVALUES
void write_dig_point(const FiffDigPoint &dig)
QList< FiffRawDir > rawdir
#define FIFF_MNE_PROJ_ITEM_ACTIVE
QSharedPointer< FiffStream > SPtr
FiffStream(QIODevice *p_pIODevice)
FIFF raw measurement data.
bool read_named_matrix(const FiffDirTree &p_Node, fiff_int_t matkind, FiffNamedMatrix &mat)
#define FIFF_MNE_FILE_NAME
void write_float(fiff_int_t kind, const float *data, fiff_int_t nel=1)
FiffInfo class declaration.
FiffInfoBase class declaration.
static bool setup_read_raw(QIODevice &p_IODevice, FiffRawData &data, bool allow_maxshield=false)
Matrix< float, 4, 4, DontAlign > invtrans
void write_int(fiff_int_t kind, const fiff_int_t *data, fiff_int_t nel=1)
void start_block(fiff_int_t kind)
bool get_evoked_entries(const QList< FiffDirTree > &evoked_node, QStringList &comments, QList< fiff_int_t > &aspect_kinds, QString &t)
void write_info_base(const FiffInfoBase &p_FiffInfoBase)
FiffCtfComp class declaration.
FiffNamedMatrix::SDPtr data
void write_double(fiff_int_t kind, const double *data, fiff_int_t nel=1)
FiffStream class declaration.
void write_ctf_comp(const QList< FiffCtfComp > &comps)
Directory tree structure.
#define FIFFV_ASPECT_AVERAGE
bool has_tag(fiff_int_t findkind)
QList< FiffDirEntry > dir
void write_ch_info(FiffChInfo *ch)
#define FIFF_MNE_RT_COMMAND
#define FIFF_MNE_COORD_FRAME
FiffCoordTrans dev_head_t
void write_proj(const QList< FiffProj > &projs)
void write_coord_trans(const FiffCoordTrans &trans)
#define FIFFV_ASPECT_STD_ERR
void write_float_matrix(fiff_int_t kind, const MatrixXf &mat)
QList< FiffDigPoint > dig
Coordinate transformation description.
void write_id(fiff_int_t kind, const FiffId &id=defaultFiffId)
void finish_writing_raw()
CTF software compensation data.
FiffRawData class declaration.
FiffTag class declaration, which provides fiff tag I/O and processing methods.
MNEMath class declaration.
#define FIFFV_MNE_COORD_CTF_HEAD
void write_name_list(fiff_int_t kind, const QStringList &data)
bool read_cov(const FiffDirTree &p_Node, fiff_int_t cov_kind, FiffCov &p_covData)
void write_float_sparse_rcs(fiff_int_t kind, const SparseMatrix< float > &mat)
bool read_meas_info_base(const FiffDirTree &p_Node, FiffInfoBase &p_InfoForward)
void end_block(fiff_int_t kind)
Matrix< double, 12, 1, DontAlign > loc
static FiffStream::SPtr start_writing_raw(QIODevice &p_IODevice, const FiffInfo &info, RowVectorXd &cals, MatrixXi sel=defaultMatrixXi)
Matrix< float, 4, 4, DontAlign > trans
bool read_meas_info(const FiffDirTree &p_Node, FiffInfo &p_Info, FiffDirTree &p_NodeInfo)
#define FIFF_MNE_COV_KIND
FiffCov class declaration.