File: HDFFile.cpp

package info (click to toggle)
pbseqlib 5.3.5%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,020 kB
  • sloc: cpp: 77,250; python: 331; sh: 103; makefile: 41
file content (46 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <hdf/HDFFile.hpp>

using namespace H5;

HDFFile::HDFFile() {}

//
//  Open a file.  By default, if the file already exists, open it in
//  read/write mode.  The only other flag that is allowed is
//  H5F_ACC_TRUNC, which will truncate the file to zero size.
//
void HDFFile::Open(std::string fileName, unsigned int flags, const FileAccPropList& fileAccPropList)
{

    assert(flags == H5F_ACC_RDWR || flags == H5F_ACC_TRUNC || flags == H5F_ACC_RDONLY);
    std::ifstream testIn(fileName.c_str());
    bool fileExists = static_cast<bool>(testIn);
    bool flagsIsNotTrunc = flags != H5F_ACC_TRUNC;

    if (fileExists and H5File::isHdf5(fileName.c_str()) and flagsIsNotTrunc) {
        try {
            hdfFile.openFile(fileName.c_str(), flags, fileAccPropList);
        } catch (const FileIException& e) {
            std::cout << "Error opening file " << fileName << std::endl;
            std::exit(EXIT_FAILURE);
        }
    } else {
        try {
            //
            // Open a new file with TRUNC permissions, always read/write.
            //
            FileCreatPropList filePropList;
            filePropList.setUserblock(512);
            hdfFile = H5File(fileName.c_str(), H5F_ACC_TRUNC, filePropList);
        } catch (const FileIException& fileException) {
            std::cout << "Error creating file " << fileName << std::endl;
            std::exit(EXIT_FAILURE);
        }
    }
    if (rootGroup.Initialize(hdfFile, "/") != 1) {
        std::cout << "Error initializing the root group for file " << fileName << std::endl;
        std::exit(EXIT_FAILURE);
    }
}

void HDFFile::Close() { hdfFile.close(); }