Home/News

About Us

Products
  Locator
  Data Editor
  Source Estimator
  MR Viewer
  Image Processor
  Visualizer

Data Analysis Service

Downloads

FAQs

Formats

Jobs

Contact Us

Papers

Links

EMSE User Group

Search


 
File Formats - Inverse operator
Description
The inverse operator is simply a matrix of floating point numbers preceded by some prolog and header information.  The Prolog and header are ASCII, while the matrix itself consists of double precision (i.e. 8 bytes per number) floating point numbers, little-endian (Intel) IEEE 754-1985 64-bit format.  For EMSE v4.2 and below, minor revision 3 files were written and read.  EMSE v5.0 and above writes major revision 4 files, but can read both major revision 3 and 4.  In this document we will define major revision 3 and major revision 4 separately, though they are quite similar.

N.B. – Open as binary
In order to read or write these files properly, you must open them as binary, as shown in the example code at the end of this document.

Comments
Comment lines are not supported for this file type.

Major Revision 4

Prolog


Name

Format

Description

Magic number

%x

0x454D5345

Major revision

%d

4

Minor revision

%d

1

Type

%x

0x00000020

Table A-1

Header
The header consists of the entries shown in Table A-2 (in mandatory sequence):

Name

Format

Description

Mode

%x

bitmap set by program

state

%x

bitmap set by program

option

%x

bitmap set by program

Tangent space dimension

%d

First 16 bits: 1 or 3 dipoles per location

Last 16 bits used to define if cortical thinning was used (see example code)

[angle criterion]

%f

If (TangentSpaceDimension & 0x00400000), this field contains the angle criterion for cortical dipole thinning, else the field is omitted

[distance criterion]

%f

If (TangentSpaceDimension & 0x00400000), this field contains the distance criterion for cortical dipole thinning, else the field is omitted

checksum

%f

Defined by composite montage at create time

Rows, columns

%d %d

#rows, #columns in matrix

Table A-2

Data
The data in row-wise ordering, i.e. all the elements of a row are stored as successive 8-byte values before proceeding on to the next row.

Major Revision 3

Prolog


Name

Format

Description

Major revision

%d

3

Type

%x

0x00000020

Minor revision

%d

1

Table A-3

Header
The header consists of the entries shown in Table A-2 (in mandatory sequence):

Name

Format

Description

Tangent space dimension

%d

First 16 bits: 1 or 3 dipoles per location

Last 16 bits used to define if cortical thinning was used (see example code)

[angle criterion]

%f

If (TangentSpaceDimension & 0x00400000), this field contains the angle criterion for cortical dipole thinning, else the field is omitted

[distance criterion]

%f

If (TangentSpaceDimension & 0x00400000), this field contains the distance criterion for cortical dipole thinning, else the field is omitted

Rows, columns

%d %d

#rows, #columns in matrix

Table A-4

Data
The data in row-wise ordering, i.e. all the elements of a row are stored as successive 8-byte values before proceeding on to the next row.

C++ code example
This example was hacked out of the production code and reassembled.  It was never compiled and tested in the exact form that is presented here.  The example reads both major revision 3 and 4 files.

const unsigned long ulSSIMagicNumber = 0x454D5345;

void  

Read_InverseMatrix(const char *path)

{

       std::ifstream f_in;

       f_in.open(path, std::ios::in|std::ios::binary);      // Note binary

       if (!f_in)

       {

             throw exception("[Read_InverseMatrix] File open error.");

       }

      

       unsigned long ulMN;

       unsigned long ulMajorRev;

       f_in >> std::hex >> ulMN;

       if ( ulMN == ulSSIMagicNumber ){

             // in mr3, file starts with major rev ( == 3)

             // in mr4 file starts with magic number

             f_in >>  ulMajorRev;

       }

       else

       {

             ulMajorRev = ulMN;

       }

            

       switch( ulMajorRev )

       {

       case( 3 ):

             {

                    Read_InverseMatrix_mr3( f_in );

                    return;

             }

       case( 4 ) :

             {

                    Read_InverseMatrix_mr4( f_in );

                    return;

             }

       default:

            

             throw exception("[Read_InverseMatrix] Invalid file (bad major rev).");

       }

}      // end Read_InverseMatrix()

 

const unsigned long ulInverseMatrix = 0x00000020;

const unsigned long ssThin = 0x00400000;

 

void  

Read_InverseMatrix_mr3( std::ifstream &f_in )

{

       // read header

long   MyFileType;

float fAngleCrit, fDistanceCrit;

int iDimTangent;

       f_in >> std::hex >> MyFileType >> std::dec;

       if ( !(MyFileType&ulInverseMatrix) )

{

throw exception("[Read_InverseMatrix_mr3] Bad file type.");

}

       f_in >> iDimTangent;

       if (iDimTangent & ssThin){

             f_in >> fAngleCrit >> fDistanceCrit;

             iDimTangent &= ~ssThin;

       }

      

       // read data

long   newrow, newcol;

       f_in >> newrow >> newcol;

       char c[1];

       f_in.read(c, 1);    // skip over line feed

 

       double **mtx = new double*[ newrow ];

 

for (int i=0; i<newrow; i++ )

{

       mtx[i] = new double[ newcol ];

       f_in.read((char *)mtx[i], newcol*sizeof(double) );

       int iRet=f_in.rdstate();

       if (iRet) {

throw exception("[Read_InverseMatrix_mr3] Bad vector read.");

       }

}

       f_in.close();

       return;

}      // end Read_InverseMatrix_mr3()

 

void  

Read_InverseMatrix_mr4( std::ifstream &f_in )

{

       // read header

       unsigned long ulMinorRev;

       f_in >>  ulMinorRev;

       if ( ulMinorRev != 1 ){

             throw exception("[Read_InverseMatrix_mr4] Invalid file (bad minor rev).");

       }

            

       unsigned long ultype;

       f_in >>  ultype;

       if ( ultype != ulInverseMatrix ){

             throw exception("[Read_InverseMatrix_mr4] Invalid file (bad file type).");

       }

            

       unsigned long ulMode, ulState, ulOption;

int iDimTangent;

double dCheckSum;

       f_in >>  ulMode;

       f_in >>  ulState;

       f_in >>  ulOption;

       f_in >> std::dec;

       f_in >>  iDimTangent;

       f_in >>  dCheckSum;

 

       if (iDimTangent & ssThin){

             f_in >> fAngleCrit >> fDistanceCrit;

             iDimTangent &= ~ssThin;

       }

      

// read data

long   newrow, newcol;

       f_in >> newrow >> newcol;

       char c[1];

       f_in.read(c, 1);    // skip over line feed

 

       double **mtx = new double*[ newrow ];

 

for (int i=0; i<newrow; i++ )

{

       mtx[i] = new double[ newcol ];

       f_in.read((char *)mtx[i], newcol*sizeof(double) );

       int iRet=f_in.rdstate();

       if (iRet) {

throw exception("[Read_InverseMatrix_mr4] Bad vector read.");

       }

}

       f_in.close();

       return;

}      // end Read_InverseMatrix_mr4()

 

Return to File Formats page


 
  © 2007 by Source Signal Imaging Inc.