コード例 #1
0
Compartment_Report_HDF5_File_Reader::Compartment_Report_HDF5_File_Reader
(const Report_Specification & specs) :
    _path(uri_to_filename(specs.data_source())),
    _report_name(specs.label()),
    _sequence_start_frame(0),
    _frame_counter(0),
    _frame_skip(1.0),
    _current_framestamp(UNDEFINED_FRAME_NUMBER)
{
    namespace fs = boost::filesystem;

    static Report_Specialization_Register<
               Compartment_Report_HDF5_File_Reader,
               float
           > register_float_buffer;

    // Finding a suitable cell name from which has a h5 inside the search path.
    bool h5_file_found = false;
    if (!fs::is_directory(_path))
    {
        throw_exception(
            IO_Error("Compartment_Report_HDF5_File_Reader: data source "
                     "is not a directory: " + specs.data_source()),
            FATAL_LEVEL, __FILE__, __LINE__);
    }
    fs::directory_iterator entry(_path), end_entry;
    Cell_GID cell_GID = UNDEFINED_CELL_GID;
    while (cell_GID == UNDEFINED_CELL_GID && entry != end_entry)
    {
        fs::path filename = entry->path();
        std::string cell_name = fs::basename(filename);
        char * endptr;
        if (fs::is_regular(entry->status()) &&
            fs::extension(filename) == ".h5" &&
            // Checking if name matches a[0-9]+ pattern and storing the GID
            cell_name.size() > 1 && cell_name[0] == 'a' &&
            (cell_GID = strtol(&cell_name[1], &endptr, 10)) > 0 &&
            *endptr == '\0')
            h5_file_found = true;
        ++entry;
    }
    if (cell_GID == UNDEFINED_CELL_GID)
    {
        throw_exception(
            Bad_Data("Compartment_Report_HDF5_File_Reader: source path "
                     "doesn't contain any valid .h5 file" + 
                     specs.data_source()), FATAL_LEVEL, __FILE__, __LINE__);
    }
    
    // Not catching any exception here
    H5ID file, dataset;
    open_data_set(cell_GID, "data", file, dataset);
    float start_time, end_time, delta_time;
    if (// Trying to read attributes
        !read_attribute("tstart", dataset, start_time) ||
        !read_attribute("tstop", dataset, end_time) ||
        !read_attribute("Dt", dataset, delta_time) ||
        // And checking them
        start_time != specs.start_time() ||
        end_time != specs.end_time() ||
        delta_time != specs.timestep())
    {
/*!
    \todo Exception commented because the forward_skip is not taken into
    account in the HDF5. SL - 24.07.08
        throw_exception(
            Bad_Data("Compartment_Report_HDF5_File_Reader: inconsistent"
                     " report metadata found for '" + specs.label() +
                     "' in path " + specs.data_source()), 
            FATAL_LEVEL, __FILE__, __LINE__);
*/
    }
}