45 #include <mne/c/mne_types.h>
58 using namespace Eigen;
59 using namespace FIFFLIB;
60 using namespace MNELIB;
61 using namespace INVERSELIB;
79 #if defined(_WIN32) || defined(_WIN64)
80 #define snprintf _snprintf
81 #define vsnprintf _vsnprintf
82 #define strcasecmp _stricmp
83 #define strncasecmp _strnicmp
86 #define MIN(a,b) ((a) < (b) ? (a) : (b))
87 #define MAX(a,b) ((a) > (b) ? (a) : (b))
89 #define MALLOC_9(x,t) (t *)malloc((x)*sizeof(t))
90 #define REALLOC_9(x,y,t) (t *)((x == NULL) ? malloc((y)*sizeof(t)) : realloc((x),(y)*sizeof(t)))
92 #define FREE_9(x) if ((char *)(x) != NULL) free((char *)(x))
94 #define ALLOC_CMATRIX_9(x,y) mne_cmatrix_9((x),(y))
96 #define FREE_CMATRIX_9(m) mne_free_cmatrix_9((m))
98 void fromFloatEigenMatrix_9(
const Eigen::MatrixXf& from_mat,
float **& to_mat,
const int m,
const int n)
100 for (
int i = 0; i < m; ++i)
101 for (
int j = 0; j < n; ++j)
102 to_mat[i][j] = from_mat(i,j);
105 void fromFloatEigenMatrix_9(
const Eigen::MatrixXf& from_mat,
float **& to_mat)
107 fromFloatEigenMatrix_9(from_mat, to_mat, from_mat.rows(), from_mat.cols());
110 void mne_free_cmatrix_9 (
float **m)
118 static void matrix_error_9(
int kind,
int nr,
int nc)
122 printf(
"Failed to allocate memory pointers for a %d x %d matrix\n",nr,nc);
124 printf(
"Failed to allocate memory for a %d x %d matrix\n",nr,nc);
126 printf(
"Allocation error for a %d x %d matrix\n",nr,nc);
127 if (
sizeof(
void *) == 4) {
128 printf(
"This is probably because you seem to be using a computer with 32-bit architecture.\n");
129 printf(
"Please consider moving to a 64-bit platform.");
131 printf(
"Cannot continue. Sorry.\n");
135 float **mne_cmatrix_9(
int nr,
int nc)
142 m = MALLOC_9(nr,
float *);
143 if (!m) matrix_error_9(1,nr,nc);
144 whole = MALLOC_9(nr*nc,
float);
145 if (!whole) matrix_error_9(2,nr,nc);
169 void mne_free_ring_buffer_9(
void *thisp)
178 for (
k = 0;
k < this_buf->nbuf;
k++)
179 FREE_9(this_buf->bufs[
k]->data);
180 FREE_9(this_buf->bufs);
202 for (
k = 0;
k < list->nevent;
k++)
203 mne_free_event_9(list->events[
k]);
204 FREE_9(list->events);
216 mat->rowlist.clear();
217 mat->collist.clear();
233 FREE_9(s->pick_deriv);
236 s->chspick_nospace.clear();
242 void mne_string_to_name_list_9(
const QString& s, QStringList& listp,
int &nlistp)
249 if (!s.isEmpty() && s.size() > 0) {
254 nlistp = list.size();
258 QString mne_name_list_to_string_9(
const QStringList& list)
263 int nlist = list.size();
265 if (nlist == 0 || list.isEmpty())
268 for (
int k = 0;
k < nlist-1;
k++) {
272 res += list[nlist-1];
276 QString mne_channel_names_to_string_9(
const QList<FIFFLIB::FiffChInfo>& chs,
286 for (
int k = 0;
k < nch;
k++)
287 names.append(chs[
k].ch_name);
288 res = mne_name_list_to_string_9(names);
292 void mne_channel_names_to_name_list_9(
const QList<FIFFLIB::FiffChInfo>& chs,
298 QString s = mne_channel_names_to_string_9(chs,nch);
300 mne_string_to_name_list_9(s,listp,nlistp);
314 while (tmp_node->type != FIFFB_MEAS) {
315 if (tmp_node->parent == NULL)
317 tmp_node = tmp_node->parent;
331 while (tmp_node->type != FIFFB_MEAS) {
332 if (tmp_node->parent == NULL)
334 tmp_node = tmp_node->parent;
336 for (
k = 0;
k < tmp_node->nchild();
k++)
337 if (tmp_node->children[
k]->type == FIFFB_MEAS_INFO)
338 return (tmp_node->children[
k]);
353 while (tmp_node->type != FIFFB_EVOKED) {
354 if (tmp_node->parent == NULL)
356 tmp_node = tmp_node->parent;
367 QList<FiffDirEntry::SPtr> ent = start->dir;
368 for (
k = 0;
k < start->nent();
k++)
370 if (stream->read_tag(t_pTag,ent[
k]->pos)) {
371 return t_pTag->toString();
374 return QString(
"No comment");
379 QString& namep,
int *typep)
384 QList<FiffDirEntry::SPtr> ent = start->dir;
385 QString res =
"unknown";
388 for (
k = 0;
k < start->nent();
k++)
390 if (stream->read_tag(t_pTag,ent[
k]->pos)) {
391 type = *t_pTag->toInt();
400 res =
"single trace";
405 case FIFFV_ASPECT_SUBAVERAGE :
409 res =
"alt. average";
412 res =
"power density spectrum";
415 res =
"dipole amplitudes";
433 fiff_int_t kind, pos;
436 if (!(meas_info = find_meas_info_9(node))) {
439 for (
k = 0;
k < meas_info->nent();
k++) {
440 kind = meas_info->dir[
k]->kind;
441 pos = meas_info->dir[
k]->pos;
444 if (stream->read_tag(t_pTag,pos)) {
446 time_t time = meas_date->
secs;
449 ltime = localtime(&time);
450 res = MALLOC_9(MAXDATE,
char);
451 (void)strftime(res,MAXDATE,
"%x %X",ltime);
467 QList<FIFFLIB::FiffChInfo>& chp,
475 QList<FIFFLIB::FiffChInfo> ch;
480 QList<FiffDirNode::SPtr> hpi;
483 fiff_int_t kind, pos;
491 if (!(meas = find_meas_9(node))) {
492 printf (
"Meas. block not found!");
495 if (!(meas_info = find_meas_info_9(node))) {
496 printf (
"Meas. info not found!");
502 if (!meas->id.isEmpty()) {
504 (*id)->version = meas->id.version;
505 (*id)->machid[0] = meas->id.machid[0];
506 (*id)->machid[1] = meas->id.machid[1];
507 (*id)->time = meas->id.time;
514 for (
k = 0;
k < meas_info->nent();
k++) {
515 kind = meas_info->dir[
k]->kind;
516 pos = meas_info->dir[
k]->pos;
520 if (!stream->read_tag(t_pTag,pos))
522 *nchan = *t_pTag->toInt();
524 for (j = 0; j < *nchan; j++) {
528 to_find = to_find + *nchan - 1;
532 if (!stream->read_tag(t_pTag,pos))
534 *sfreq = *t_pTag->toFloat();
539 if (!stream->read_tag(t_pTag,pos))
544 **meas_date = *(
fiffTime)t_pTag->data();
548 if (!stream->read_tag(t_pTag,pos))
550 *lowpass = *t_pTag->toFloat();
555 if (!stream->read_tag(t_pTag,pos))
557 *highpass = *t_pTag->toFloat();
563 if (!stream->read_tag(t_pTag,pos))
566 this_ch = t_pTag->toChInfo();
568 qCritical (
"FIFF_CH_INFO : scan # out of range!");
572 ch[this_ch.
scanNo-1] = this_ch;
577 if (!stream->read_tag(t_pTag,pos))
581 t = FiffCoordTransOld::read_helper( t_pTag );
585 if (t->
from == FIFFV_COORD_DEVICE && t->
to == FIFFV_COORD_HEAD) {
596 hpi = meas_info->dir_tree_find(FIFFB_HPI_RESULT);
598 if (hpi.size() > 0 && *trans == NULL)
599 for (
k = 0;
k < hpi[0]->nent();
k++)
601 if (!stream->read_tag(t_pTag,hpi[0]->dir[
k]->pos))
603 t = FiffCoordTransOld::read_helper( t_pTag );
608 if (t->
from == FIFFV_COORD_DEVICE && t->
to == FIFFV_COORD_HEAD) {
614 *lowpass = *sfreq/2.0;
622 printf (
"Not all essential tags were found!");
643 fiff_int_t kind_1, pos;
648 while (node != NULL) {
649 for (
k = 0;
k < node->nent();
k++)
651 kind_1 = node->dir[
k]->kind;
652 pos = node->dir[
k]->pos;
653 if (kind_1 == kind) {
655 if (!stream->read_tag(t_pTag,pos)) {
659 fiff_byte_t* tmp = MALLOC_9(t_pTag->size(),fiff_byte_t);
660 fiff_byte_t* tmp_current = (fiff_byte_t *)t_pTag->data();
662 for(
int k = 0;
k < t_pTag->size(); ++
k )
663 tmp[
k] = tmp_current[
k];
670 if (node == high_node)
702 fiff_int_t kind, pos;
711 if (find_between (stream,tmp_node,tmp_node->parent,
FIFF_NAVE,&tempb) == FIFF_FAIL)
714 nave = *(
int *)tempb;
716 if (find_between (stream,tmp_node,tmp_node->parent,
720 sfreq = *(
float *)tempb;
723 if (find_between (stream,tmp_node,tmp_node->parent,
727 akind = *(
int *)tempb;
734 tmp_node = tmp_node->parent;
737 for (
k = 0;
k < tmp_node->dir_tree.size();
k++) {
738 kind = tmp_node->dir_tree[
k]->kind;
739 pos = tmp_node->dir_tree[
k]->pos;
743 if (!stream->read_tag(t_pTag,pos))
745 first = *t_pTag->toInt(); to_find--;
749 if (!stream->read_tag(t_pTag,pos))
751 last = *t_pTag->toInt(); to_find--;
755 if (!stream->read_tag(t_pTag,pos))
757 my_nsamp = *t_pTag->toInt(); to_find--;
761 if (!stream->read_tag(t_pTag,pos))
763 my_tmin = *t_pTag->toFloat(); to_find--;
766 if (!stream->read_tag(t_pTag,pos))
768 qDebug() <<
"TODO: check whether artefs contains the right stuff -> use MatrixXi instead";
769 artefs = t_pTag->toInt();
770 nartef = t_pTag->size()/(3*
sizeof(int));
775 printf (
"Not all essential tags were found!");
778 if (first != -1 && last != -1) {
779 nsamp = (last)-(first)+1;
780 tmin = (first)/(sfreq);
782 else if (my_tmin != -1 && my_nsamp != -1) {
787 printf(
"Not enough data for time scale definition!");
800 QList<FiffChInfo>& chp)
806 QList<FiffChInfo> new_ch;
807 int new_nchan = *nchan;
810 fiff_int_t kind, pos;
814 if (!(evoked_node = find_evoked(node))) {
820 if(evoked_node->find_tag(stream,
FIFF_NCHAN, t_pTag))
821 new_nchan = *t_pTag->toInt();
825 for (
k = 0;
k < evoked_node->nent();
k++) {
826 kind = evoked_node->dir[
k]->kind;
827 pos = evoked_node->dir[
k]->pos;
829 if (new_ch.isEmpty()) {
831 for (
int i = 0; i < to_find; i++) {
835 if (!stream->read_tag(t_pTag,pos))
838 this_ch = t_pTag->toChInfo();
839 if (this_ch.
scanNo <= 0 || this_ch.
scanNo > new_nchan) {
840 printf (
"FIFF_CH_INFO : scan # out of range!");
844 new_ch[this_ch.
scanNo-1] = this_ch;
849 printf(
"All channels were not specified "
850 "at the FIFFB_EVOKED level.");
857 if (res == FIFF_OK) {
859 if (!new_ch.isEmpty()) {
867 static void unpack_data(
double offset,
874 for (
k = 0;
k < nsamp;
k++)
875 orig[
k] = scale * packed[
k] + offset;
881 int nchan,
int nsamp)
886 fiff_int_t kind, pos;
890 float **epochs = NULL;
894 for (
k = 0, ch = 0;
k < node->nent() && ch < nchan;
k++) {
895 kind = node->dir[
k]->kind;
896 pos = node->dir[
k]->pos;
898 if (!stream->read_tag(t_pTag,pos))
900 if (t_pTag->type & FIFFT_MATRIX) {
901 if ((t_pTag->type & ~FIFFT_MATRIX) != FIFFT_FLOAT) {
902 printf(
"Epochs in matrix should be floats!");
907 QVector<qint32> dims;
908 t_pTag->getMatrixDimensions(ndim, dims);
911 printf(
"Data matrix dimension should be two!");
914 if (dims[0] != nsamp) {
915 printf(
"Incorrect number of samples in data matrix!");
918 if (dims[1] != nchan) {
919 printf(
"Incorrect number of channels in data matrix!");
922 MatrixXf tmp_epochs = t_pTag->toFloatMatrix().transpose();
923 epochs = ALLOC_CMATRIX_9(tmp_epochs.rows(),tmp_epochs.cols());
924 fromFloatEigenMatrix_9(tmp_epochs, epochs);
930 epochs = ALLOC_CMATRIX_9(nchan,nsamp);
931 if (t_pTag->type == FIFFT_OLD_PACK) {
932 offset = ((
float *)t_pTag->data())[0];
933 scale = ((
float *)t_pTag->data())[1];
934 packed = (
short *)(((
float *)t_pTag->data())+2);
935 unpack_data(offset,scale,packed,nsamp,epochs[ch++]);
937 else if (t_pTag->type == FIFFT_FLOAT)
938 memcpy(epochs[ch++],t_pTag->data(),nsamp*
sizeof(
float));
940 printf (
"Unknown data packing type!");
941 FREE_CMATRIX_9(epochs);
950 printf (
"All epochs were not found!");
956 FREE_CMATRIX_9(epochs);
962 QList<FiffDirNode::SPtr>& nodesp,
964 QStringList* commentsp)
969 QList<FiffDirNode::SPtr> evoked;
970 QList<FiffDirNode::SPtr> meas;
971 QList<FiffDirNode::SPtr> nodes;
972 int evoked_count,count;
973 QString part,type,meas_date;
974 QStringList comments;
983 meas = stream->dirtree()->dir_tree_find(FIFFB_MEAS);
987 for (count = 0,p = 0; p < meas.size(); p++) {
988 evoked = meas[p]->dir_tree_find(FIFFB_EVOKED);
992 for (evoked_count = 0, j = 0; j < evoked.size(); j++) {
993 for (
k = 0;
k < evoked[j]->nchild();
k++) {
994 if (evoked[j]->children[
k]->type == FIFFB_ASPECT) {
1002 types = REALLOC_9(types,count+evoked_count+1,
int);
1006 for (j = 0; j < evoked.size(); j++)
1007 for (
k = 0;
k < evoked[j]->nchild();
k++)
1008 if (evoked[j]->children[
k]->type == FIFFB_ASPECT) {
1009 meas_date = get_meas_date(stream,evoked[j]);
1010 part = get_comment(stream,evoked[j]);
1011 get_aspect_name_type(stream,evoked[j]->children[
k],type,types+count);
1012 if (!meas_date.isEmpty()) {
1013 comments.append(QString(
"%1>%2>%3").arg(meas_date).arg(part).arg(type));
1016 comments.append(QString(
"%1>%2").arg(part).arg(type));
1018 nodes.append(evoked[j]->children[
k]);
1026 *commentsp = comments;
1028 *aspect_typesp = NULL;
1036 *commentsp = comments;
1040 *aspect_typesp = types;
1047 QList<FiffDirNode::SPtr> mne_find_evoked (
FiffStream::SPtr& stream, QStringList* commentsp)
1050 QList<FiffDirNode::SPtr> evoked;
1051 mne_find_evoked_types_comments(stream,evoked,NULL,commentsp);
1055 static void remove_artefacts (
float *resp,
1068 for (
k = 0;
k < nartef;
k++) {
1069 if (artefs[3*
k] == FIFFV_ARTEF_NONE || artefs[3*
k] == FIFFV_ARTEF_KEEP)
1071 remove_jump = (artefs[3*
k] == FIFFV_ARTEF_NOJUMP);
1075 start = artefs[3*
k+1];
1076 end = artefs[3*
k+2];
1077 start = MAX(0,MIN(start,nsamp));
1078 end = MAX(0,MIN(end,nsamp));
1084 a = resp[end] - resp[start];
1085 for (j = 0; j <=start; j++)
1086 resp[j] = resp[j] + a;
1087 for (j = start+1 ; j < end; j++)
1088 resp[j] = resp[end];
1091 a = (resp[end]-resp[start])/(end-start);
1092 b = (resp[start]*end - resp[end]*start)/(end-start);
1093 for (j = start+1 ; j < end; j++)
1101 int mne_read_evoked(
const QString& name,
1107 QList<FiffChInfo>& chsp,
1127 QList<FiffDirNode::SPtr> evoked;
1130 QStringList comments;
1133 QList<FiffChInfo> chs;
1136 float **epochs = NULL;
1143 float highpass = 0.0;
1152 printf (
"Evoked response selector must be positive!");
1162 evoked = mne_find_evoked(stream,(commentp == NULL) ? NULL : &comments);
1163 if (!evoked.size()) {
1164 printf (
"No evoked response data available here");
1168 nset = evoked.size();
1171 start = evoked[setno];
1174 printf (
"Too few evoked response data sets (how come?)");
1180 if (get_meas_info (stream,
1197 if (get_evoked_essentials(stream,start,sfreq,
1198 tmin,nsamp,nave,aspect_kind,
1199 artefs,nartef) == -1)
1204 if (get_evoked_optional(stream,
1212 if ((epochs = get_epochs(stream,start,nchan,nsamp)) == NULL)
1217 for (
k = 0;
k < nartef;
k++) {
1218 qDebug() <<
"TODO: Artefact Vectors do not contain the right stuff!";
1219 artefs[2*
k+1] = artefs[2*
k+1] - sfreq*tmin;
1220 artefs[2*
k+2] = artefs[2*
k+2] - sfreq*tmin;
1222 for (
k = 0;
k < nchan;
k++) {
1224 for (j = 0; j < nsamp; j++)
1225 epoch[j] = chs[
k].cal*epoch[j];
1226 remove_artefacts(epoch,nsamp,artefs,nartef);
1236 *epochsp = epochs; epochs = NULL;
1241 *commentp = comments[setno];
1242 comments[setno] =
"";
1245 *highpassp = highpass;
1247 *lowpassp = lowpass;
1255 *aspect_kindp = aspect_kind;
1261 *meas_datep = meas_date;
1274 FREE_CMATRIX_9(epochs);
1284 char *mne_format_file_id (
fiffId id)
1292 secs =
id->time.secs;
1293 ltime = localtime(&secs);
1294 (void)strftime(buf,MAXBUF,
"%c",ltime);
1300 int mne_read_meg_comp_eeg_ch_info_9(
const QString& name,
1301 QList<FiffChInfo>& megp,
1303 QList<FiffChInfo>& meg_compp,
1305 QList<FiffChInfo>& eegp,
1317 QList<FiffChInfo> chs;
1319 QList<FiffChInfo> meg;
1321 QList<FiffChInfo> meg_comp;
1323 QList<FiffChInfo> eeg;
1326 QList<FiffDirNode::SPtr> nodes;
1331 fiff_int_t kind, pos;
1337 nodes = stream->dirtree()->dir_tree_find(FIFFB_MNE_PARENT_MEAS_FILE);
1339 if (nodes.size() == 0) {
1340 nodes = stream->dirtree()->dir_tree_find(FIFFB_MEAS_INFO);
1341 if (nodes.size() == 0) {
1342 qCritical (
"Could not find the channel information.");
1348 for (
k = 0;
k < info->nent();
k++) {
1349 kind = info->dir[
k]->kind;
1350 pos = info->dir[
k]->pos;
1353 if (!stream->read_tag(t_pTag,pos))
1355 nchan = *t_pTag->toInt();
1357 for (j = 0; j < nchan; j++) {
1364 case FIFF_PARENT_BLOCK_ID :
1365 if(!stream->read_tag(t_pTag, pos))
1368 *
id = *(
fiffId)t_pTag->data();
1372 if(!stream->read_tag(t_pTag, pos))
1375 t = FiffCoordTransOld::read_helper( t_pTag );
1376 if (t->
from != FIFFV_COORD_DEVICE || t->
to != FIFFV_COORD_HEAD)
1381 if(!stream->read_tag(t_pTag, pos))
1384 this_ch = t_pTag->toChInfo();
1386 printf (
"FIFF_CH_INFO : scan # out of range %d (%d)!",this_ch.
scanNo,nchan);
1390 chs[this_ch.
scanNo-1] = this_ch;
1396 qCritical(
"Some of the channel information was missing.");
1399 if (t == NULL && meg_head_t != NULL) {
1403 if ((t = FiffCoordTransOld::mne_read_meas_transform(name)) == NULL) {
1404 qCritical(
"MEG -> head coordinate transformation not found.");
1411 for (
k = 0;
k < nchan;
k++) {
1412 if (chs[
k].kind == FIFFV_MEG_CH) {
1416 meg_comp.append(chs[
k]);
1418 }
else if (chs[
k].kind == FIFFV_EEG_CH) {
1431 meg_compp = meg_comp;
1433 *nmeg_compp = nmeg_comp;
1445 if (meg_head_t == NULL) {
1467 QList<FiffDirNode::SPtr> temp;
1473 if (pNode->isEmpty())
1474 node = stream->dirtree();
1478 temp = node->dir_tree_find(FIFFB_MNE_BAD_CHANNELS);
1479 if (temp.size() > 0) {
1482 bad->find_tag(stream, FIFF_MNE_CH_NAME_LIST, t_pTag);
1484 names = t_pTag->toString();
1485 mne_string_to_name_list_9(names,list,nlist);
1493 int mne_read_bad_channel_list_9(
const QString& name, QStringList& listp,
int& nlistp)
1504 res = mne_read_bad_channel_list_from_node_9(stream,stream->dirtree(),listp,nlistp);
1515 MneMeasData::MneMeasData()
1534 meas_date.
usecs = 0;
1556 for (
k = 0;
k < nset;
k++)
1561 mne_ch_selection_free_9(chsel);
1571 float sfreq,tmin,tmax;
1579 sfreq = 1.0/ this->current->tstep;
1580 tmin = this->current->tmin;
1581 tmax = this->current->tmin + ( this->current->np-1)/sfreq;
1585 else if (bmin > tmax)
1586 b1 = this->current->np;
1588 for (b1 = 0; b1/sfreq + tmin < bmin; b1++)
1592 else if (b1 > this->current->np)
1593 b1 = this->current->np;
1597 else if (bmax > tmax)
1598 b2 = this->current->np;
1600 for (b2 = this->current->np; b2/sfreq + tmin > bmax; b2--)
1604 else if (b2 > this->current->np)
1605 b2 = this->current->np;
1607 data = this->current->data;
1609 for (c = 0; c < this->nchan; c++) {
1610 for (s = b1, ave = 0.0; s < b2; s++)
1613 this->current->baselines[c] += ave;
1614 for (s = 0; s < this->current->np; s++)
1615 data[s][c] = data[s][c] - ave;
1617 qDebug() <<
"TODO: Check comments content";
1618 printf(
"\t%s : using baseline %7.1f ... %7.1f ms\n",
1619 this->current->comment.toUtf8().constData() ? this->current->comment.toUtf8().constData() :
"unknown",
1620 1000*(tmin+b1/sfreq),
1621 1000*(tmin+b2/sfreq));
1628 MneMeasData *MneMeasData::mne_read_meas_data_add(
const QString &name,
1632 const QStringList& namesp,
1642 QList<FiffChInfo> chs;
1643 int nchan_file,nsamp;
1644 float dtmin,dtmax,sfreq;
1646 float **data = NULL;
1647 float lowpass,highpass;
1653 QString stim14_name;
1667 float *source,tmin,tmax;
1673 stim14_name = getenv(MNE_ENV_TRIGGER_CH);
1674 if (stim14_name.isEmpty() || stim14_name.size() == 0)
1675 stim14_name = MNE_DEFAULT_TRIGGER_CH;
1678 mne_channel_names_to_name_list_9(add_to->chs,add_to->nchan,names,nchan);
1681 names = op->eigen_fields->collist;
1685 names = fwd->collist;
1692 if (names.isEmpty())
1698 if (mne_read_evoked(name,set-1,
1712 &meas_date) == FAIL)
1716 printf(
"\tMeasurement file id: %s\n",mne_format_file_id(
id));
1720 printf(
"\tWarning: data set consistency check is still in the works.\n");
1727 sel = MALLOC_9(nchan,
int);
1728 for (
k = 0;
k < nchan;
k++)
1730 for (c = 0; c < nchan_file; c++) {
1731 for (
k = 0;
k < nchan;
k++) {
1732 if (sel[
k] == -1 && QString::compare(chs[c].ch_name,names[
k]) == 0) {
1737 if (QString::compare(stim14_name,chs[c].ch_name) == 0) {
1741 for (
k = 0;
k < nchan;
k++)
1743 printf(
"All channels needed were not in the MEG/EEG data file "
1744 "(first missing: %s).",names[
k].toUtf8().constData());
1749 sel = MALLOC_9(nchan_file,
int);
1750 for (c = 0, nchan = 0; c < nchan_file; c++) {
1751 if (chs[c].kind == FIFFV_MEG_CH || chs[c].kind == FIFFV_EEG_CH) {
1755 if (QString::compare(stim14_name,chs[c].ch_name) == 0) {
1766 dtmax = dtmin + (np-1)/sfreq;
1772 printf(
"\tData time range: %8.1f ... %8.1f ms\n",1000*tmin,1000*tmax);
1778 new_data->filename = name;
1779 new_data->meas_id = id;
id = NULL;
1784 new_data->meas_date = *meas_date;
1786 if (new_data->meas_id)
1787 new_data->meas_date = new_data->meas_id->
time;
1789 new_data->meas_date.
secs = 0;
1790 new_data->meas_date.
usecs = 0;
1793 new_data->lowpass = lowpass;
1794 new_data->highpass = highpass;
1795 new_data->nchan = nchan;
1796 new_data->sfreq = sfreq;
1799 new_data->meg_head_t = t;
1801 printf(
"\tUsing MEG <-> head transform from the present data set\n");
1803 if (op != NULL && op->mri_head_t != NULL) {
1804 if (!new_data->mri_head_t)
1806 *(new_data->mri_head_t) = *(op->mri_head_t);
1807 printf(
"\tPicked MRI <-> head transform from the inverse operator\n");
1812 for (
k = 0;
k < nchan;
k++) {
1814 new_data->chs[
k] = chs[sel[
k]];
1818 new_data->fwd = fwd;
1820 new_data->proj = MneProjOp::mne_dup_proj_op(op->proj);
1822 new_data->proj = MneProjOp::mne_read_proj_op(name);
1823 if (new_data->proj && new_data->proj->nitems > 0) {
1824 printf(
"\tLoaded projection from %s:\n",name.toUtf8().data());
1825 MneProjOp::mne_proj_op_report(stderr,
"\t\t",new_data->proj);
1827 new_data->comp = MneCTFCompDataSet::mne_read_ctf_comp_data(name);
1828 if (new_data->comp == NULL)
1830 if (new_data->comp->ncomp > 0)
1831 printf(
"\tRead %d compensation data sets from %s\n",new_data->comp->ncomp,name.toUtf8().data());
1839 new_data->bad = MALLOC_9(new_data->nchan,
int);
1840 for (
k = 0;
k < new_data->nchan;
k++)
1841 new_data->bad[
k] = FALSE;
1843 if (mne_read_bad_channel_list_9(name,new_data->badlist,new_data->nbad) == OK) {
1844 for (b = 0; b < new_data->nbad; b++) {
1845 for (
k = 0;
k < new_data->nchan;
k++) {
1846 if (QString::compare(new_data->chs[
k].ch_name,new_data->badlist[b],Qt::CaseInsensitive) == 0) {
1847 new_data->bad[
k] = TRUE;
1852 printf(
"\t%d bad channels read from %s%s",new_data->nbad,name.toUtf8().data(),new_data->nbad > 0 ?
":\n" :
"\n");
1853 if (new_data->nbad > 0) {
1855 for (
k = 0;
k < new_data->nbad;
k++)
1856 printf(
"%s%c",new_data->badlist[
k].toUtf8().constData(),k < new_data->nbad-1 ?
' ' :
'\n');
1865 dataset->tmin = tmin;
1866 dataset->tstep = 1.0/sfreq;
1867 dataset->first = n1;
1869 dataset->nave = nave;
1870 dataset->kind = aspect_kind;
1871 dataset->data = ALLOC_CMATRIX_9(np,nchan);
1872 dataset->comment = comment; comment.clear();
1873 dataset->baselines = MALLOC_9(nchan,
float);
1877 for (
k = 0;
k < nchan;
k++) {
1878 source = data[sel[
k]];
1882 for (p = 0; p < np; p++)
1883 dataset->data[p][
k] = source[p+n1];
1884 dataset->baselines[
k] = 0.0;
1890 dataset->stim14 = MALLOC_9(np,
float);
1891 source = data[stim14];
1892 for (p = 0; p < np; p++)
1893 dataset->stim14[p] = source[p+n1]/chs[stim14].cal;
1895 new_data->sets.append(dataset); dataset = NULL;
1898 new_data->current = new_data->sets[0];
1900 printf(
"\t%s dataset %s from %s\n",
1901 add_to ?
"Added" :
"Loaded",
1902 new_data->sets[new_data->nset-1]->comment.toUtf8().constData() ? new_data->sets[new_data->nset-1]->comment.toUtf8().constData() :
"unknown",name.toUtf8().data());
1907 FREE_CMATRIX_9(data);
1910 if (res == NULL && !add_to)
1920 MneMeasData *MneMeasData::mne_read_meas_data(
const QString &name,
1924 const QStringList& namesp,
1928 return mne_read_meas_data_add(name,set,op,fwd,namesp,nnamesp,NULL);