write_core_vfdf.f90 1.81 KB
Newer Older
gsell's avatar
gsell committed
1
!
gsell's avatar
gsell committed
2
!  Copyright (c) 2006-2015, The Regents of the University of California,
gsell's avatar
gsell committed
3 4 5 6 7 8 9 10 11 12 13 14
!  through Lawrence Berkeley National Laboratory (subject to receipt of any
!  required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
!  Institut (Switzerland).  All rights reserved.!
!
!  License: see file COPYING in top level of source distribution.
!
include 'H5hut.f90'

program write_core_vfd
  use H5hut
  implicit none

gsell's avatar
gsell committed
15 16 17 18
#if defined(PARALLEL_IO)
  include 'mpif.h'
#endif
  
gsell's avatar
gsell committed
19 20
  ! name of output file
  character (len=*), parameter :: fname = "example_core_vfd.h5"
gsell's avatar
gsell committed
21

gsell's avatar
gsell committed
22 23 24 25 26 27
  ! H5hut verbosity level
  integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT

  ! number of particles we are going to write per core
  integer*4, parameter :: num_particles = 32

gsell's avatar
gsell committed
28
  integer   :: comm_rank = 0
gsell's avatar
gsell committed
29 30 31
  integer*8 :: file, h5_ierror
  integer*8 :: prop
  integer*4 :: i
gsell's avatar
gsell committed
32 33
  integer*4, allocatable :: data(:)

gsell's avatar
gsell committed
34
  ! initialize MPI & H5hut
gsell's avatar
gsell committed
35 36
#if defined(PARALLEL_IO)
  integer   :: comm, mpi_ierror
gsell's avatar
gsell committed
37
  comm = MPI_COMM_WORLD
gsell's avatar
gsell committed
38 39
  call mpi_init (mpi_ierror)
  call mpi_comm_rank (comm, comm_rank, mpi_ierror)
gsell's avatar
gsell committed
40 41
#endif
  
gsell's avatar
gsell committed
42
  call h5_abort_on_error ()
gsell's avatar
gsell committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  call h5_set_verbosity_level (h5_verbosity)

  ! open file and create first step
  prop = h5_createprop_file ()
  h5_ierror = h5_setprop_file_corevfd (prop);
  file = h5_openfile (fname, H5_O_WRONLY, prop)
  h5_ierror = h5_setstep(file, 1_8)

  ! set number of particles this process is going to write
  h5_ierror = h5pt_setnpoints (file, int8 (num_particles))

  ! create fake data
  allocate (data (num_particles))
  do i = 1, num_particles
     data (i) = (i-1) + comm_rank * num_particles
  end do
gsell's avatar
gsell committed
59

gsell's avatar
gsell committed
60 61
  ! write the data
  h5_ierror = h5pt_writedata_i4 (file, "data", data);
gsell's avatar
gsell committed
62 63 64

  ! cleanup
  deallocate (data)
gsell's avatar
gsell committed
65
  h5_ierror = h5_closefile (file)
gsell's avatar
gsell committed
66

gsell's avatar
gsell committed
67 68 69 70
#if defined(PARALLEL_IO)
  call mpi_finalize (mpi_ierror)
#endif
  
gsell's avatar
gsell committed
71
end program write_core_vfd