Reputation: 41
I would like to write data into hdf5 file in fortran in an appended way, but I can't hold the data in a large memory array.
when writing using ascii I can do something like:
program example1
implicit none
integer :: nu, i
open(filename="someFile.txt", newunit=nu)
do i = 1, 10
write(nu, *) i
end do
close(nu)
end program example1
and what I would get is a file holding all of the integer numbers from 1 to 10 but without declaring a size 10 one dimensional array.
How can I write a hdf5 file in fortran that does exactly that, i.e holding the numbers in the same file under the same dataset name but without holding an array that holds these numbers?
Upvotes: 2
Views: 480
Reputation: 912
You need to create an extendible dataset and then populate it with the help of an hyperslab or point selection (otherwise, previously written data will be overwritten). Using HDFql, your use-case can be solved as follows in Fortran:
PROGRAM Example
USE HDFql
CHARACTER :: variable_number
INTEGER :: state
INTEGER :: i
state = hdfql_execute("CREATE AND USE FILE test.h5")
state = hdfql_execute("CREATE DATASET dset AS INT(0 TO UNLIMITED)")
WRITE(variable_number, "(I0)") hdfql_variable_register(i)
DO i = 1, 10
state = hdfql_execute("ALTER DIMENSION dset TO +1")
state = hdfql_execute("INSERT INTO dset[-1] VALUES FROM MEMORY " // variable_number)
END DO
state = hdfql_variable_unregister(i)
state = hdfql_execute("CLOSE FILE")
END PROGRAM
Upvotes: 3