Skip to content

Commit

Permalink
Added new example showing how to copy datasets between files
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Jun 17, 2021
1 parent 763daa9 commit 79ddb1b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/example-07d-copy-dset-file2file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <h5pp/h5pp.h>

int main() {
size_t logLevel = 2; // Set log level (default is 2: "info")

// Initialize two files
h5pp::File fileA("exampledir/example-07d-copy-dset-file2file-A.h5", h5pp::FilePermission::REPLACE, logLevel);
h5pp::File fileB("exampledir/example-07d-copy-dset-file2file-B.h5", h5pp::FilePermission::REPLACE, logLevel);

// Write a dummy dataset to fileA
fileA.writeDataset("Data on file A", "data/in/fileB/datasetA");
// Write a dummy dataset to fileB
fileB.writeDataset("Data on file B", "data/in/fileB/datasetB");


// Copy the dataset to fileB
fileA.copyLinkToFile("data/in/fileB/datasetA",fileB.getFilePath(), "data/from/fileA/datasetA");

// Alternatively, copy a dataset on fileB to fileA
fileA.copyLinkFromFile("data/from/fileB/datasetB", fileB.getFilePath(), "data/in/fileB/datasetB");

return 0;
}

0 comments on commit 79ddb1b

Please sign in to comment.