File handling
Table of Contents
1. Open file with default properties, serial version
C implementation
#include "H5hut.h"
int
main (
int argc,
char** argv
) {
h5_file_t f = H5OpenFile ("testfile.h5", H5_O_WRONLY, H5_PROP_DEFAULT);
H5CloseFile (f);
return 0;
}
Fortran90 implementation
include 'H5hut.f90'
program openclose
use H5hut
implicit none
include 'mpif.h'
integer*8 :: file_id, status
file_id = h5_openfile ("testfile.h5", H5_O_WRONLY, H5_PROP_DEFAULT)
status = h5_closefile (file_id);
end program openclose
2. Open file with default properties, parallel version
C implementation
#include "H5hut.h"
int
main (
int argc,
char** argv
) {
MPI_Init (&argc, &argv);
h5_file_t f = H5OpenFile ("testfile.h5", H5_O_WRONLY, H5_PROP_DEFAULT);
H5CloseFile (f);
MPI_Finalize ();
return 0;
}
Fortran90 implementation
[app-listing]] [source,Fortran] include 'H5hut.f90' program openclose use H5hut implicit none include 'mpif.h' integer :: ierr integer*8 :: file_id, status call mpi_init(ierr) file_id = h5_openfile ("testfile.h5", H5_O_WRONLY, H5_PROP_DEFAULT) status = h5_closefile (file_id); call mpi_finalize(ierr) end program openclose
3. Open file to use MPI independent I/O
C implementation
[app-listing]] [source,C] #include "H5hut.h" int main ( int argc, char** argv ) { MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; h5_prop_t prop = H5CreateFileProp (); H5SetPropFileMPIOIndependent (prop, &comm); h5_file_t f = H5OpenFile ("testfile.h5", H5_O_WRONLY, prop); H5CloseProp (prop); H5CloseFile (f); MPI_Finalize (); return 0; }
Fortran90 implementation
include 'H5hut.f90'
program openclose
use H5hut
implicit none
include 'mpif.h'
integer :: comm, rank, ierr
integer*8 :: file_id, status
integer*8 :: props
comm = MPI_COMM_WORLD
call mpi_init(ierr)
call mpi_comm_rank(comm, rank, ierr)
props = h5_createprop_file ()
status = h5_setprop_file_mpio_collective (props, comm)
file_id = h5_openfile ("testfile.h5", H5_O_WRONLY, props)
status = h5_closeprop (props)
status = h5_closefile (file_id);
call mpi_finalize(ierr)
end program openclose