Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hdf5] Incorrect handling of files in read-write mode #618

Open
galexv opened this issue Aug 5, 2019 · 0 comments
Open

[hdf5] Incorrect handling of files in read-write mode #618

galexv opened this issue Aug 5, 2019 · 0 comments
Assignees
Labels

Comments

@galexv
Copy link
Collaborator

galexv commented Aug 5, 2019

The following code produces a run-time error:

#include <alps/hdf5.hpp>
#include <iostream>

int main(int argc, char** argv)
{
    std::string filename("test.h5");
    const std::vector<int> data {1234,5678};

    alps::hdf5::archive ar(filename, "rw"); // Note (1)
    ar["/data"] << data;

    boolalpha(std::cout);
    // std::cout << "Data? " << ar.is_data("/data"); // Note (3)
    // std::cout << "\nScalar? " << ar.is_scalar("/data"); // Note (3)

    std::vector<int> rd_data;
    ar["/data"] >> rd_data; // Note(2)

    std::cout << "\nExpected data: " << data[0] << "," << data[1];
    std::cout << "\nActual data: " << rd_data[0] << "," << rd_data[1];

    return 0;
}

Notes:
(1) In current implementation, "r" and "rw" modes are equivalent ("r" is ignored).
(2) If the file did not exist when it was opened (e.g., on the first run of the program), the run is successful! Otherwise, this call fails throwing alps::hdf5::path_not_found.
(3) If any (or both) of these lines are uncommented, these calls are successful, but line (2) fails, no matter whether the file existed when it was opened.

Funny enough, a similar code that uses a scalar rather than a vector works correctly.

@galexv galexv added the bug label Aug 5, 2019
@galexv galexv self-assigned this Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant