MNE-CPP  beta 1.0
fiff_tag.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "fiff_tag.h"
43 #include <utils/ioutils.h>
44 
45 
46 //*************************************************************************************************************
47 //=============================================================================================================
48 // QT INCLUDES
49 //=============================================================================================================
50 
51 #include <QTcpSocket>
52 
53 
54 //*************************************************************************************************************
55 //=============================================================================================================
56 // USED NAMESPACES
57 //=============================================================================================================
58 
59 using namespace UTILSLIB;
60 using namespace FIFFLIB;
61 
62 
63 //*************************************************************************************************************
64 //=============================================================================================================
65 // DEFINE MEMBER METHODS
66 //=============================================================================================================
67 
68 FiffTag::FiffTag()
69 : m_pComplexFloatData(NULL)
70 , m_pComplexDoubleData(NULL)
71 {
72 }
73 
74 
75 //*************************************************************************************************************
76 
77 FiffTag::FiffTag(const FiffTag* p_pFiffTag)
78 : QByteArray(p_pFiffTag->data(), p_pFiffTag->size())
79 , kind(p_pFiffTag->kind)
80 , type(p_pFiffTag->type)
81 , next(p_pFiffTag->next)
82 {
83  if(p_pFiffTag->m_pComplexFloatData)
84  this->toComplexFloat();
85  else
86  m_pComplexFloatData = NULL;
87 
88  if(p_pFiffTag->m_pComplexDoubleData)
89  this->toComplexDouble();
90  else
91  m_pComplexDoubleData = NULL;
92 }
93 
94 
95 //*************************************************************************************************************
96 
97 
99 {
100  if(this->m_pComplexFloatData)
101  delete this->m_pComplexFloatData;
102  if(this->m_pComplexDoubleData)
103  delete this->m_pComplexDoubleData;
104 }
105 
106 
107 //*************************************************************************************************************
108 
109 bool FiffTag::read_tag_data(FiffStream* p_pStream, FiffTag::SPtr& p_pTag, qint64 pos)
110 {
111  if(pos >= 0)
112  {
113  p_pStream->device()->seek(pos);
114  }
115 
116  if(!p_pTag)
117  return false;
118 
119  //
120  // Read data when available
121  //
122  if (p_pTag->size() > 0)
123  {
124  p_pStream->readRawData(p_pTag->data(), p_pTag->size());
125  FiffTag::convert_tag_data(p_pTag,FIFFV_BIG_ENDIAN,FIFFV_NATIVE_ENDIAN);
126  }
127 
128  if (p_pTag->next != FIFFV_NEXT_SEQ)
129  p_pStream->device()->seek(p_pTag->next);//fseek(fid,tag.next,'bof');
130 
131  return true;
132 }
133 
134 
135 //*************************************************************************************************************
136 
137 bool FiffTag::read_tag_info(FiffStream* p_pStream, FiffTag::SPtr &p_pTag, bool p_bDoSkip)
138 {
139  p_pTag = FiffTag::SPtr(new FiffTag());
140 
141  //Option 1
142 // t_DataStream.readRawData((char *)p_pTag, FIFFC_TAG_INFO_SIZE);
143 // p_pTag->kind = Fiff::swap_int(p_pTag->kind);
144 // p_pTag->type = Fiff::swap_int(p_pTag->type);
145 // p_pTag->size = Fiff::swap_int(p_pTag->size);
146 // p_pTag->next = Fiff::swap_int(p_pTag->next);
147 
148  //Option 2
149  *p_pStream >> p_pTag->kind;
150  *p_pStream >> p_pTag->type;
151  qint32 size;
152  *p_pStream >> size;
153  p_pTag->resize(size);
154  *p_pStream >> p_pTag->next;
155 
156 // qDebug() << "read_tag_info" << " Kind:" << p_pTag->kind << " Type:" << p_pTag->type << " Size:" << p_pTag->size() << " Next:" << p_pTag->next;
157 
158  if (p_bDoSkip)
159  {
160  QTcpSocket* t_qTcpSocket = qobject_cast<QTcpSocket*>(p_pStream->device());
161  if(t_qTcpSocket)
162  {
163  p_pStream->skipRawData(p_pTag->size());
164  }
165  else
166  {
167  if (p_pTag->next == FIFFV_NEXT_SEQ)
168  {
169  p_pStream->device()->seek(p_pStream->device()->pos()+p_pTag->size()); //fseek(fid,tag.size,'cof');
170  }
171  else if (p_pTag->next > 0)
172  {
173  p_pStream->device()->seek(p_pTag->next); //fseek(fid,tag.next,'bof');
174  }
175  }
176  }
177 
178  return true;
179 }
180 
181 
182 //*************************************************************************************************************
183 
185 {
186  while(p_pStream->device()->bytesAvailable() < 16)
187  p_pStream->device()->waitForReadyRead(10);
188 
189  if(!FiffTag::read_tag_info(p_pStream, p_pTag, false))
190  return false;
191 
192  while(p_pStream->device()->bytesAvailable() < p_pTag->size())
193  p_pStream->device()->waitForReadyRead(10);
194 
195  if(!FiffTag::read_tag_data(p_pStream, p_pTag))
196  return false;
197 
198  return true;
199 }
200 
201 
202 //*************************************************************************************************************
203 
204 bool FiffTag::read_tag(FiffStream* p_pStream, FiffTag::SPtr& p_pTag, qint64 pos)
205 {
206  if (pos >= 0)
207  {
208  p_pStream->device()->seek(pos);
209  }
210 
211  p_pTag = FiffTag::SPtr(new FiffTag());
212 
213  //
214  // Read fiff tag header from stream
215  //
216  *p_pStream >> p_pTag->kind;
217  *p_pStream >> p_pTag->type;
218  qint32 size;
219  *p_pStream >> size;
220  p_pTag->resize(size);
221  *p_pStream >> p_pTag->next;
222 
223 // qDebug() << "read_tag" << " Kind:" << p_pTag->kind << " Type:" << p_pTag->type << " Size:" << p_pTag->size() << " Next:" << p_pTag->next;
224 
225  //
226  // Read data when available
227  //
228  if (p_pTag->size() > 0)
229  {
230  p_pStream->readRawData(p_pTag->data(), p_pTag->size());
231  FiffTag::convert_tag_data(p_pTag,FIFFV_BIG_ENDIAN,FIFFV_NATIVE_ENDIAN);
232  }
233 
234  if (p_pTag->next != FIFFV_NEXT_SEQ)
235  p_pStream->device()->seek(p_pTag->next);//fseek(fid,tag.next,'bof');
236 
237  return true;
238 }
239 
240 
241 //*************************************************************************************************************
242 
243 fiff_int_t FiffTag::getMatrixCoding() const
244 {
245  return IS_MATRIX & this->type;
246 }
247 
248 
249 //*************************************************************************************************************
250 
251 bool FiffTag::isMatrix() const
252 {
253  if (this->getMatrixCoding() != 0)
254  return true;
255  else
256  return false;
257 }
258 
259 
260 //*************************************************************************************************************
261 
262 bool FiffTag::getMatrixDimensions(qint32& p_ndim, QVector<qint32>& p_Dims) const
263 {
264  p_Dims.clear();
265  if(!this->isMatrix() || this->data() == NULL)
266  {
267  p_ndim = 0;
268  return false;
269  }
270 
271  //
272  // Find dimensions and return to the beginning of tag data
273  //
274  qint32* t_pInt32 = (qint32*)this->data();
275 
276  p_ndim = t_pInt32[(this->size()-4)/4];
277 
278  if (fiff_type_matrix_coding(this->type) == FIFFTS_MC_DENSE)
279  for(int i = p_ndim+1; i > 1; --i)
280  p_Dims.append(t_pInt32[(this->size()-(i*4))/4]);
281  else if(fiff_type_matrix_coding(this->type) == FIFFTS_MC_CCS || fiff_type_matrix_coding(this->type) == FIFFTS_MC_RCS)
282  for(int i = p_ndim+2; i > 1; --i)
283  p_Dims.append(t_pInt32[(this->size()-(i*4))/4]);
284  else
285  {
286  printf("Error: Cannot handle other than dense or sparse matrices yet.\n");//ToDo Throw
287  return false;
288  }
289 
290  return true;
291 }
292 
293 
294 //*************************************************************************************************************
295 
296 fiff_int_t FiffTag::getType() const
297 {
298  if (this->isMatrix())
299  {
300  return DATA_TYPE & this->type;
301  }
302  else
303  {
304  return this->type;
305  }
306 }
307 
308 
309 //*************************************************************************************************************
310 
311 QString FiffTag::getInfo() const
312 {
313  QString t_qStringInfo;
314 
315  if (this->isMatrix())
316  {
317  switch(this->getType())
318  {
319  case FIFFT_INT:
320  t_qStringInfo = "Matrix of type FIFFT_INT";
321  break;
322  case FIFFT_JULIAN:
323  t_qStringInfo = "Matrix of type FIFFT_JULIAN";
324  break;
325  case FIFFT_FLOAT:
326  t_qStringInfo = "Matrix of type FIFFT_FLOAT";
327  break;
328  case FIFFT_DOUBLE:
329  t_qStringInfo = "Matrix of type FIFFT_DOUBLE";
330  break;
331  case FIFFT_COMPLEX_FLOAT:
332  t_qStringInfo = "Matrix of type FIFFT_COMPLEX_FLOAT";
333  break;
334  case FIFFT_COMPLEX_DOUBLE:
335  t_qStringInfo = "Matrix of type FIFFT_COMPLEX_DOUBLE";
336  break;
337  default:
338  t_qStringInfo = "Matrix of unknown type";
339  }
340  }
341  else
342  {
343  switch(this->getType())
344  {
345  //
346  // Simple types
347  //
348  case FIFFT_BYTE:
349  t_qStringInfo = "Simple type FIFFT_BYTE";
350  break;
351  case FIFFT_SHORT:
352  t_qStringInfo = "Simple type FIFFT_SHORT";
353  break;
354  case FIFFT_INT:
355  t_qStringInfo = "Simple type FIFFT_INT";
356  break;
357  case FIFFT_USHORT:
358  t_qStringInfo = "Simple type FIFFT_USHORT";
359  break;
360  case FIFFT_UINT:
361  t_qStringInfo = "Simple type FIFFT_UINT";
362  break;
363  case FIFFT_FLOAT:
364  t_qStringInfo = "Simple type FIFFT_FLOAT";
365  break;
366  case FIFFT_DOUBLE:
367  t_qStringInfo = "Simple type FIFFT_DOUBLE";
368  break;
369  case FIFFT_STRING:
370  t_qStringInfo = "Simple type FIFFT_STRING";
371  break;
372  case FIFFT_DAU_PACK16:
373  t_qStringInfo = "Simple type FIFFT_DAU_PACK16";
374  break;
375  case FIFFT_COMPLEX_FLOAT:
376  t_qStringInfo = "Simple type FIFFT_COMPLEX_FLOAT";
377  break;
378  case FIFFT_COMPLEX_DOUBLE:
379  t_qStringInfo = "Simple type FIFFT_COMPLEX_DOUBLE";
380  break;
381  //
382  // Structures
383  //
384  case FIFFT_ID_STRUCT:
385  t_qStringInfo = "Structure FIFFT_ID_STRUCT";
386  break;
387  case FIFFT_DIG_POINT_STRUCT:
388  t_qStringInfo = "Structure FIFFT_DIG_POINT_STRUCT";
389  break;
390  case FIFFT_COORD_TRANS_STRUCT:
391  t_qStringInfo = "Structure FIFFT_COORD_TRANS_STRUCT";
392  break;
393  case FIFFT_CH_INFO_STRUCT:
394  t_qStringInfo = "Structure FIFFT_CH_INFO_STRUCT";
395  break;
396  case FIFFT_OLD_PACK:
397  t_qStringInfo = "Structure FIFFT_OLD_PACK";
398  break;
399  case FIFFT_DIR_ENTRY_STRUCT:
400  t_qStringInfo = "Structure FIFFT_DIR_ENTRY_STRUCT";
401  break;
402  default:
403  t_qStringInfo = "Structure unknown";
404  }
405  }
406  return t_qStringInfo;
407 }
408 
409 
410 //*************************************************************************************************************
411 
412 /*---------------------------------------------------------------------------
413  *
414  * Motorola like Architectures
415  *
416  * Fif file bit and byte orderings are defined to be as in HP-UX.
417  *
418  *--------------------------------------------------------------------------*/
419 
420 //#ifdef BIG_ENDIAN_ARCH
421 
422 
423 //void FiffTag::fiff_convert_tag_info(FiffTag*& tag)
424 //{
425 // return;
426 //}
427 
428 //#endif
429 
430 //#ifdef INTEL_X86_ARCH
432 // */
433 
434 //void FiffTag::fiff_convert_tag_info(FiffTag*& tag)
435 
436 //{
437 // tag->kind = swap_int(tag->kind);
438 // tag->type = swap_int(tag->type);
439 // tag->size = swap_int(tag->size);
440 // tag->next = swap_int(tag->next);
441 // return;
442 //}
443 
444 //#endif /* INTEL_X86_ARCH */
445 
446 
447 //*************************************************************************************************************
448 
450 {
451  int k;
452  pos->coil_type = IOUtils::swap_int(pos->coil_type);
453  for (k = 0; k < 3; k++) {
454  IOUtils::swap_floatp(&pos->r0[k]);
455  IOUtils::swap_floatp(&pos->ex[k]);
456  IOUtils::swap_floatp(&pos->ey[k]);
457  IOUtils::swap_floatp(&pos->ez[k]);
458  }
459  return;
460 }
461 
462 
463 //*************************************************************************************************************
464 
466 /*
467  * Assumes that the input is in the non-native byte order and needs to be swapped to the other one
468  */
469 {
470  int ndim;
471  int k;
472  int *dimp,*data,kind,np,nz;
473  float *fdata;
474  double *ddata;
475  unsigned int tsize = tag->size();
476 
477  if (fiff_type_fundamental(tag->type) != FIFFTS_FS_MATRIX)
478  return;
479  if (tag->data() == NULL)
480  return;
481  if (tsize < sizeof(fiff_int_t))
482  return;
483 
484  dimp = ((fiff_int_t *)((tag->data())+tag->size()-sizeof(fiff_int_t)));
485  IOUtils::swap_intp(dimp);
486  ndim = *dimp;
487  if (fiff_type_matrix_coding(tag->type) == FIFFTS_MC_DENSE) {
488  if (tsize < (ndim+1)*sizeof(fiff_int_t))
489  return;
490  dimp = dimp - ndim;
491  for (k = 0, np = 1; k < ndim; k++) {
492  IOUtils::swap_intp(dimp+k);
493  np = np*dimp[k];
494  }
495  }
496  else {
497  if (tsize < (ndim+2)*sizeof(fiff_int_t))
498  return;
499  if (ndim > 2) /* Not quite sure what to do */
500  return;
501  dimp = dimp - ndim - 1;
502  for (k = 0; k < ndim+1; k++)
503  IOUtils::swap_intp(dimp+k);
504  nz = dimp[0];
505  if (fiff_type_matrix_coding(tag->type) == FIFFTS_MC_CCS)
506  np = nz + dimp[2] + 1; /* nz + n + 1 */
507  else if (fiff_type_matrix_coding(tag->type) == FIFFTS_MC_RCS)
508  np = nz + dimp[1] + 1; /* nz + m + 1 */
509  else
510  return; /* Don't know what to do */
511  /*
512  * Take care of the indices
513  */
514  for (data = (int *)(tag->data())+nz, k = 0; k < np; k++)
515  IOUtils::swap_intp(data+k);
516  np = nz;
517  }
518  /*
519  * Now convert data...
520  */
521  kind = fiff_type_base(tag->type);
522  if (kind == FIFFT_INT) {
523  for (data = (int *)(tag->data()), k = 0; k < np; k++)
524  IOUtils::swap_intp(data+k);
525  }
526  else if (kind == FIFFT_FLOAT) {
527  for (fdata = (float *)(tag->data()), k = 0; k < np; k++)
528  IOUtils::swap_floatp(fdata+k);
529  }
530  else if (kind == FIFFT_DOUBLE) {
531  for (ddata = (double *)(tag->data()), k = 0; k < np; k++)
532  IOUtils::swap_doublep(ddata+k);
533  }
534  return;
535 }
536 
537 
538 //*************************************************************************************************************
539 
541 /*
542  * Assumes that the input is in the NATIVE_ENDIAN byte order and needs to be swapped to the other one
543  */
544 {
545  int ndim;
546  int k;
547  int *dimp,*data,kind,np;
548  float *fdata;
549  double *ddata;
550  unsigned int tsize = tag->size();
551 
552  if (fiff_type_fundamental(tag->type) != FIFFTS_FS_MATRIX)
553  return;
554  if (tag->data() == NULL)
555  return;
556  if (tsize < sizeof(fiff_int_t))
557  return;
558 
559  dimp = ((fiff_int_t *)(((char *)tag->data())+tag->size()-sizeof(fiff_int_t)));
560  ndim = *dimp;
561  IOUtils::swap_intp(dimp);
562 
563  if (fiff_type_matrix_coding(tag->type) == FIFFTS_MC_DENSE) {
564  if (tsize < (ndim+1)*sizeof(fiff_int_t))
565  return;
566  dimp = dimp - ndim;
567  for (k = 0, np = 1; k < ndim; k++) {
568  np = np*dimp[k];
569  IOUtils::swap_intp(dimp+k);
570  }
571  }
572  else {
573  if (tsize < (ndim+2)*sizeof(fiff_int_t))
574  return;
575  if (ndim > 2) /* Not quite sure what to do */
576  return;
577  dimp = dimp - ndim - 1;
578  if (fiff_type_matrix_coding(tag->type) == FIFFTS_MC_CCS)
579  np = dimp[0] + dimp[2] + 1; /* nz + n + 1 */
580  else if (fiff_type_matrix_coding(tag->type) == FIFFTS_MC_RCS)
581  np = dimp[0] + dimp[1] + 1; /* nz + m + 1 */
582  else
583  return; /* Don't know what to do */
584  for (k = 0; k < ndim+1; k++)
585  IOUtils::swap_intp(dimp+k);
586  }
587  /*
588  * Now convert data...
589  */
590  kind = fiff_type_base(tag->type);
591  if (kind == FIFFT_INT) {
592  for (data = (int *)(tag->data()), k = 0; k < np; k++)
593  IOUtils::swap_intp(data+k);
594  }
595  else if (kind == FIFFT_FLOAT) {
596  for (fdata = (float *)(tag->data()), k = 0; k < np; k++)
597  IOUtils::swap_floatp(fdata+k);
598  }
599  else if (kind == FIFFT_DOUBLE) {
600  for (ddata = (double *)(tag->data()), k = 0; k < np; k++)
601  IOUtils::swap_doublep(ddata+k);
602  }
603  else if (kind == FIFFT_COMPLEX_FLOAT) {
604  for (fdata = (float *)(tag->data()), k = 0; k < 2*np; k++)
605  IOUtils::swap_floatp(fdata+k);
606  }
607  else if (kind == FIFFT_COMPLEX_DOUBLE) {
608  for (ddata = (double *)(tag->data()), k = 0; k < 2*np; k++)
609  IOUtils::swap_doublep(ddata+k);
610  }
611  return;
612 }
613 
614 
615 //*************************************************************************************************************
616 //ToDo remove this function by swapping -> define little endian big endian, QByteArray
617 void FiffTag::convert_tag_data(FiffTag::SPtr tag, int from_endian, int to_endian)
618 {
619  int np;
620  int k,r;//,c;
621  char *offset;
622  fiff_int_t *ithis;
623  fiff_short_t *sthis;
624  fiff_long_t *lthis;
625  float *fthis;
626  double *dthis;
627 // fiffDirEntry dethis;
628 // fiffId idthis;
629 // fiffChInfoRec* chthis;//FiffChInfo* chthis;//ToDo adapt parsing to the new class
630 // fiffChPos cpthis;
631 // fiffCoordTrans ctthis;
632 // fiffDigPoint dpthis;
633  fiffDataRef drthis;
634 
635  if (tag->data() == NULL || tag->size() == 0)
636  return;
637 
638  if (from_endian == FIFFV_NATIVE_ENDIAN)
639  from_endian = NATIVE_ENDIAN;
640  if (to_endian == FIFFV_NATIVE_ENDIAN)
641  to_endian = NATIVE_ENDIAN;
642 
643  if (from_endian == to_endian)
644  return;
645 
646  if (fiff_type_fundamental(tag->type) == FIFFTS_FS_MATRIX) {
647  if (from_endian == NATIVE_ENDIAN)
649  else
651  return;
652  }
653 
654  switch (tag->type) {
655 
656  case FIFFT_INT :
657  case FIFFT_JULIAN :
658  case FIFFT_UINT :
659  np = tag->size()/sizeof(fiff_int_t);
660  for (ithis = (fiff_int_t *)tag->data(), k = 0; k < np; k++, ithis++)
661  IOUtils::swap_intp(ithis);
662  break;
663 
664  case FIFFT_LONG :
665  case FIFFT_ULONG :
666  np = tag->size()/sizeof(fiff_long_t);
667  for (lthis = (fiff_long_t *)tag->data(), k = 0; k < np; k++, lthis++)
668  IOUtils::swap_longp(lthis);
669  break;
670 
671  case FIFFT_SHORT :
672  case FIFFT_DAU_PACK16 :
673  case FIFFT_USHORT :
674  np = tag->size()/sizeof(fiff_short_t);
675  for (sthis = (fiff_short_t *)tag->data(), k = 0; k < np; k++, sthis++)
676  *sthis = IOUtils::swap_short(*sthis);
677  break;
678 
679  case FIFFT_FLOAT :
680  case FIFFT_COMPLEX_FLOAT :
681  np = tag->size()/sizeof(fiff_float_t);
682  for (fthis = (fiff_float_t *)tag->data(), k = 0; k < np; k++, fthis++)
683  IOUtils::swap_floatp(fthis);
684  break;
685 
686  case FIFFT_DOUBLE :
687  case FIFFT_COMPLEX_DOUBLE :
688  np = tag->size()/sizeof(fiff_double_t);
689  for (dthis = (fiff_double_t *)tag->data(), k = 0; k < np; k++, dthis++)
690  IOUtils::swap_doublep(dthis);
691  break;
692 
693  case FIFFT_OLD_PACK :
694  fthis = (float *)tag->data();
695  /*
696  * Offset and scale...
697  */
698  IOUtils::swap_floatp(fthis+0);
699  IOUtils::swap_floatp(fthis+1);
700  sthis = (short *)(fthis+2);
701  np = (tag->size() - 2*sizeof(float))/sizeof(short);
702  for (k = 0; k < np; k++,sthis++)
703  *sthis = IOUtils::swap_short(*sthis);
704  break;
705 
706  case FIFFT_DIR_ENTRY_STRUCT :
707 // np = tag->size/sizeof(fiffDirEntryRec);
708 // for (dethis = (fiffDirEntry)tag->data->data(), k = 0; k < np; k++, dethis++) {
709 // dethis->kind = swap_int(dethis->kind);
710 // dethis->type = swap_int(dethis->type);
711 // dethis->size = swap_int(dethis->size);
712 // dethis->pos = swap_int(dethis->pos);
713 // }
714  np = tag->size()/FiffDirEntry::storageSize();
715  for (k = 0; k < np; k++) {
716  offset = (char*)tag->data() + k*FiffDirEntry::storageSize();
717  ithis = (fiff_int_t*) offset;
718  ithis[0] = IOUtils::swap_int(ithis[0]);//kind
719  ithis[1] = IOUtils::swap_int(ithis[1]);//type
720  ithis[2] = IOUtils::swap_int(ithis[2]);//size
721  ithis[3] = IOUtils::swap_int(ithis[3]);//pos
722  }
723  break;
724 
725  case FIFFT_ID_STRUCT :
726 // np = tag->size/sizeof(fiffIdRec);
727 // for (idthis = (fiffId)tag->data->data(), k = 0; k < np; k++, idthis++) {
728 // idthis->version = swap_int(idthis->version);
729 // idthis->machid[0] = swap_int(idthis->machid[0]);
730 // idthis->machid[1] = swap_int(idthis->machid[1]);
731 // idthis->time.secs = swap_int(idthis->time.secs);
732 // idthis->time.usecs = swap_int(idthis->time.usecs);
733 // }
734  np = tag->size()/FiffId::storageSize();
735  for (k = 0; k < np; k++) {
736  offset = (char*)tag->data() + k*FiffId::storageSize();
737  ithis = (fiff_int_t*) offset;
738  ithis[0] = IOUtils::swap_int(ithis[0]);//version
739  ithis[1] = IOUtils::swap_int(ithis[1]);//machid[0]
740  ithis[2] = IOUtils::swap_int(ithis[2]);//machid[1]
741  ithis[3] = IOUtils::swap_int(ithis[3]);//time.secs
742  ithis[4] = IOUtils::swap_int(ithis[4]);//time.usecs
743  }
744  break;
745 
746  case FIFFT_CH_INFO_STRUCT :
747 // np = tag->size/sizeof(fiffChInfoRec);
748 // for (chthis = (fiffChInfoRec*)tag->data->data(), k = 0; k < np; k++, chthis++) {
749 // chthis->scanNo = swap_int(chthis->scanNo);
750 // chthis->logNo = swap_int(chthis->logNo);
751 // chthis->kind = swap_int(chthis->kind);
752 // swap_floatp(&chthis->range);
753 // swap_floatp(&chthis->cal);
754 // chthis->unit = swap_int(chthis->unit);
755 // chthis->unit_mul = swap_int(chthis->unit_mul);
756 // convert_ch_pos(&(chthis->chpos));
757 // }
758 
759  np = tag->size()/FiffChInfo::storageSize();
760  for (k = 0; k < np; k++) {
761  offset = (char*)tag->data() + k*FiffChInfo::storageSize();
762  ithis = (fiff_int_t*) offset;
763  fthis = (float*) offset;
764 
765  ithis[0] = IOUtils::swap_int(ithis[0]); //scanno
766  ithis[1] = IOUtils::swap_int(ithis[1]); //logno
767  ithis[2] = IOUtils::swap_int(ithis[2]); //kind
768  IOUtils::swap_floatp(&fthis[3]); //range
769  IOUtils::swap_floatp(&fthis[4]); //cal
770  ithis[5] = IOUtils::swap_int(ithis[5]); //coil_type
771  for (r = 0; r < 12; ++r)
772  IOUtils::swap_floatp(&fthis[6+r]); //loc
773  ithis[18] = IOUtils::swap_int(ithis[18]);//unit
774  ithis[19] = IOUtils::swap_int(ithis[19]);//unit_mul
775  }
776 
777  break;
778 
779  case FIFFT_CH_POS_STRUCT :
780 // np = tag->size/sizeof(fiffChPosRec);
781 // for (cpthis = (fiffChPos)tag->data->data(), k = 0; k < np; k++, cpthis++)
782 // convert_ch_pos(cpthis);
783 
784  np = tag->size()/FiffChPos::storageSize();
785  for (k = 0; k < np; ++k)
786  {
787  offset = (char*)tag->data() + k*FiffChPos::storageSize();
788  ithis = (fiff_int_t*) offset;
789  fthis = (float*) offset;
790 
791  ithis[0] = IOUtils::swap_int(ithis[0]); //coil_type
792  for (r = 0; r < 12; r++)
793  IOUtils::swap_floatp(&fthis[1+r]); //r0, ex, ey, ez
794  }
795 
796  break;
797 
798  case FIFFT_DIG_POINT_STRUCT :
799 // np = tag->size/sizeof(fiffDigPointRec);
800 // for (dpthis = (fiffDigPoint)tag->data->data(), k = 0; k < np; k++, dpthis++) {
801 // dpthis->kind = swap_int(dpthis->kind);
802 // dpthis->ident = swap_int(dpthis->ident);
803 // for (r = 0; r < 3; r++)
804 // swap_floatp(&dpthis->r[r]);
805 // }
806 
807  np = tag->size()/FiffDigPoint::storageSize();
808 
809  for (k = 0; k < np; k++) {
810  offset = tag->data() + k*FiffDigPoint::storageSize();
811  ithis = (fiff_int_t*) offset;
812  fthis = (float*) offset;
813 
814  ithis[0] = IOUtils::swap_int(ithis[0]);//kind
815  ithis[1] = IOUtils::swap_int(ithis[1]);//ident
816 
817  for (r = 0; r < 3; ++r)
818  IOUtils::swap_floatp(&fthis[2+r]); //r
819  }
820  break;
821 
822  case FIFFT_COORD_TRANS_STRUCT :
823 // np = tag->size/sizeof(fiffCoordTransRec);
824 // for (ctthis = (fiffCoordTrans)tag->data->data(), k = 0; k < np; k++, ctthis++) {
825 // ctthis->from = swap_int(ctthis->from);
826 // ctthis->to = swap_int(ctthis->to);
827 // for (r = 0; r < 3; r++) {
828 // swap_floatp(&ctthis->move[r]);
829 // swap_floatp(&ctthis->invmove[r]);
830 // for (c = 0; c < 3; c++) {
831 // swap_floatp(&ctthis->rot[r][c]);
832 // swap_floatp(&ctthis->invrot[r][c]);
833 // }
834 // }
835 // }
836 
837  np = tag->size()/FiffCoordTrans::storageSize();
838 
839  for( k = 0; k < np; ++k)
840  {
841  offset = tag->data() + k*FiffCoordTrans::storageSize();
842  ithis = (fiff_int_t*)offset;
843  fthis = (float*)offset;
844 
845  ithis[0] = IOUtils::swap_int(ithis[0]);
846  ithis[1] = IOUtils::swap_int(ithis[1]);
847 
848  for (r = 0; r < 24; ++r)
849  IOUtils::swap_floatp(&fthis[2+r]);
850  }
851  break;
852 
853  case FIFFT_DATA_REF_STRUCT :
854  np = tag->size()/sizeof(fiffDataRefRec);
855  for (drthis = (fiffDataRef)tag->data(), k = 0; k < np; k++, drthis++) {
856  drthis->type = IOUtils::swap_int(drthis->type);
857  drthis->endian = IOUtils::swap_int(drthis->endian);
858  drthis->size = IOUtils::swap_long(drthis->size);
859  drthis->offset = IOUtils::swap_long(drthis->offset);
860  }
861  break;
862 
863  default :
864  break;
865  }
866  return;
867 }
868 
869 //*************************************************************************************************************
870 //fiff_type_spec
871 
872 fiff_int_t FiffTag::fiff_type_fundamental(fiff_int_t type)
873 {
874  return type & FIFFTS_FS_MASK;
875 }
876 
877 
878 //*************************************************************************************************************
879 
880 fiff_int_t FiffTag::fiff_type_base(fiff_int_t type)
881 {
882  return type & FIFFTS_BASE_MASK;
883 }
884 
885 
886 //*************************************************************************************************************
887 
888 fiff_int_t FiffTag::fiff_type_matrix_coding(fiff_int_t type)
889 {
890  return type & FIFFTS_MC_MASK;
891 }
std::complex< float > * toComplexFloat()
Definition: fiff_tag.h:705
static fiff_int_t fiff_type_matrix_coding(fiff_int_t type)
Definition: fiff_tag.cpp:888
fiff_float_t ey[3]
Definition: fiff_ch_pos.h:114
static bool read_tag_data(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, qint64 pos=-1)
Definition: fiff_tag.cpp:109
static bool read_tag_info(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, bool p_bDoSkip=true)
Definition: fiff_tag.cpp:137
fiff_int_t getMatrixCoding() const
Definition: fiff_tag.cpp:243
fiff_float_t r0[3]
Definition: fiff_ch_pos.h:112
static qint32 storageSize()
Definition: fiff_id.h:155
static void convert_matrix_to_file_data(FiffTag::SPtr tag)
Definition: fiff_tag.cpp:540
QSharedPointer< FiffTag > SPtr
Definition: fiff_tag.h:166
fiff_int_t getType() const
Definition: fiff_tag.cpp:296
static bool read_tag(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, qint64 pos=-1)
Definition: fiff_tag.cpp:204
fiff_int_t kind
Definition: fiff_tag.h:576
static fiff_int_t fiff_type_fundamental(fiff_int_t type)
Definition: fiff_tag.cpp:872
static void convert_tag_data(FiffTag::SPtr tag, int from_endian, int to_endian)
Definition: fiff_tag.cpp:617
static qint32 storageSize()
static qint32 storageSize()
bool getMatrixDimensions(qint32 &p_ndim, QVector< qint32 > &p_Dims) const
Definition: fiff_tag.cpp:262
fiff_float_t ex[3]
Definition: fiff_ch_pos.h:113
static void convert_matrix_from_file_data(FiffTag::SPtr tag)
Definition: fiff_tag.cpp:465
fiff_float_t ez[3]
Definition: fiff_ch_pos.h:115
static qint32 storageSize()
Definition: fiff_ch_pos.h:136
fiff_int_t coil_type
Definition: fiff_ch_pos.h:111
static qint32 storageSize()
Definition: fiff_ch_info.h:168
static qint32 storageSize()
QString getInfo() const
Definition: fiff_tag.cpp:311
bool isMatrix() const
Definition: fiff_tag.cpp:251
Definition: fiff.h:98
static void convert_ch_pos(FiffChPos *pos)
Definition: fiff_tag.cpp:449
static bool read_rt_tag(FiffStream *p_pStream, FiffTag::SPtr &p_pTag)
Definition: fiff_tag.cpp:184
Coil position.
Definition: fiff_ch_pos.h:76
FIFF data tag.
Definition: fiff_tag.h:163
static fiff_int_t fiff_type_base(fiff_int_t type)
Definition: fiff_tag.cpp:880
FiffTag class declaration, which provides fiff tag I/O and processing methods.
std::complex< double > * toComplexDouble()
Definition: fiff_tag.h:722
fiff_int_t type
Definition: fiff_tag.h:578
FIFF File I/O routines.
Definition: fiff_stream.h:129
IOUtils class declaration.