ex_fiff_io
Example of the FiffIO interface class.
Build and run
cmake --build build/developer-dynamic --target ex_fiff_io
./out/Release/examples/ex_fiff_io
The default inputs come from the MNE sample dataset.
Used in the API reference
Source
src/examples/ex_fiff_io/main.cpp
//=============================================================================================================
/**
* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2012-2026 MNE-CPP Authors
*
* @file main.cpp
* @author Gabriel Motta <gabrielbenmotta@gmail.com>;
* Christoph Dinh <christoph.dinh@mne-cpp.org>;
* Lorenz Esch <lorenz.esch@tu-ilmenau.de>
* @since 0.1.0
* @date July, 2012
* @brief Example of the FiffIO interface class
*/
//=============================================================================================================
// INCLUDES
//=============================================================================================================
#include <iostream>
#include <vector>
#include <math.h>
#include <fiff/fiff.h>
#include <mne/mne.h>
#include <fiff/fiff_io.h>
//Eigen
#include <Eigen/Core>
#include <Eigen/SparseCore>
//=============================================================================================================
// QT INCLUDES
//=============================================================================================================
#include <QtCore/QCoreApplication>
//=============================================================================================================
// USED NAMESPACES
//=============================================================================================================
using namespace FIFFLIB;
using namespace MNELIB;
using namespace Eigen;
//=============================================================================================================
// MAIN
//=============================================================================================================
//=============================================================================================================
/**
* The function main marks the entry point of the program.
* By default, main has the storage class extern.
*
* @param[in] argc (argument count) is an integer that indicates how many arguments were entered on the command line when the program was started.
* @param[in] argv (argument vector) is an array of pointers to arrays of character objects. The array objects are null-terminated strings, representing the arguments that were entered on the command line when the program was started.
* @return the value that was set to exit() (which is 0 if exit() is called via quit()).
*/
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
//create list of fiff data to read
QList<QIODevice*> t_listSampleFilesIn;
t_listSampleFilesIn.append(new QFile(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif"));
// t_listSampleFilesIn.append(new QFile(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif"));
// t_listSampleFilesIn.append(new QFile(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis-ave.fif"));
// t_listSampleFilesIn.append(new QFile(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis-no-filter-ave.fif"));
// t_listSampleFilesIn.append(new QFile(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif"));
// t_listSampleFilesIn.append(new QFile(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis-cov.fif"));
FiffIO p_fiffIO(t_listSampleFilesIn);
std::cout << p_fiffIO << std::endl;
bool readSuccessful = false;
//Read raw data samples
MatrixXd data, times;
readSuccessful = p_fiffIO.m_qlistRaw[0]->read_raw_segment_times(data, times, 100, 102);
if (readSuccessful) {
//Write some raw data
QFile t_fileToWrite(QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_write/sample_out.fif");
p_fiffIO.write(t_fileToWrite, FIFFB_RAW_DATA, -1);
} else {
qDebug() << "Could not read raw segment.";
}
return a.exec();
}
//=============================================================================================================
// STATIC DEFINITIONS
//=============================================================================================================