void Compartment_Report_HDF5_File_Reader::open_data_set
(Cell_GID cell_ID, const char * dataset_name, H5ID & file, H5ID & dataset) const
{
    // Opening file for current cell
    std::string cell_name = "a" + boost::lexical_cast<std::string>(cell_ID);
    Filename filename = _path / (cell_name + ".h5");

    file.reset(H5Fopen(filename.string().c_str(), H5F_ACC_RDONLY, H5P_DEFAULT),
               H5Fclose);
    if (!file)
    {
        throw_exception(
            File_Open_Error("Compartment_Report_HDF5_File_Reader: error "
                            "opening file:" + filename.string()),
            FATAL_LEVEL, __FILE__, __LINE__);
    }

    // Opening the dataset
    std::string dataset_full_name = 
        "/" + cell_name + "/" + (_report_name + "/") + dataset_name;
    H5E_BEGIN_TRY
        dataset.reset(H5Dopen(file, dataset_full_name.c_str()), H5Dclose);
    H5E_END_TRY;
    if (!dataset)
    {
        throw_exception(
            File_Parse_Error("Compartment_Report_HDF5_File_Reader: "
                             "Dataset " + dataset_full_name + " not found "
                             "in file: " + filename.string()),
            FATAL_LEVEL, __FILE__, __LINE__);
    }
}
void Mesh_Binary_File_Writer::write_mesh(
    const Filename        & file,
    Mesh                  & mesh
)
{
    std::ofstream datastream((char*)file.string().c_str(), std::ios::binary);

    if (!datastream)
    {
        throw_exception(
            IO_Error("Mesh_Binary_File_Writer: cannot create "
                     "binary file: " + file.string()),
            WARNING_LEVEL, __FILE__, __LINE__);
    }
    
    // write header infos for the current mesh
    Vertex_Index vertex_count = mesh.vertex_count();
    Triangle_Index triangle_count = mesh.triangle_count();
    Triangle_Index triangle_strip_length = mesh.triangle_strip_length();
    datastream.write((char*)&vertex_count, sizeof(Vertex_Index));
    datastream.write((char*)&triangle_count, sizeof(Triangle_Index));
    datastream.write((char*)&triangle_strip_length, sizeof(Triangle_Index));
    
    // write the vertices data
    datastream.write((char*)mesh.vertices().pointer(),
                     vertex_count * 3 * sizeof(Micron));
    datastream.write((char*)mesh.vertex_sections().pointer(),
                     vertex_count * sizeof(Section_ID));
    datastream.write((char*)mesh.vertex_relative_distances().pointer(), 
                     vertex_count * sizeof(float));
    
    // write the triangles data
    datastream.write((char*)mesh.triangles().pointer(), 
                     triangle_count * 3 * sizeof(Vertex_Index));
    datastream.write((char*)mesh.triangle_strip().pointer(), 
                     triangle_strip_length * sizeof(Vertex_Index));
}
void Compartment_Voltage_Voxel_Average::open(Filename mapping_filename,
                                             bool portable_format)
{
    std::ifstream file(mapping_filename.string().c_str());
	
	if (file.is_open() == false)
	{
		std::cerr << "Volume compartment mapping file could not be opened (" 
			<< mapping_filename << ")" << std::endl;
		throw std::runtime_error( std::string("Volume compartment mapping file"
			" could not be opened (") 
			+ mapping_filename.string() + ")");
	}

    if (portable_format)
    {
        boost::archive::text_iarchive ia(file);
	    std::cout << "Volume Compartment Mapping: reading from portable text"
            "file (" << mapping_filename.string()  << ")" << std::endl;
        ia >> * this;
	    std::cout << "Volume Compartment Mapping: in memory" << std::endl;
    }
    else
    {