write_step_attribsf.f90 2.47 KB
Newer Older
1
  !
gsell's avatar
gsell committed
2
  !  Copyright (c) 2006-2015, The Regents of the University of California,
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_step_attribs
    use H5hut
    implicit none

gsell's avatar
gsell committed
15 16 17 18
#if defined(PARALLEL_IO)
    include 'mpif.h'
#endif
    
19 20 21 22 23 24 25 26 27
    integer*8, parameter :: verbosity_level =          1
    character (len=*), parameter :: FNAME =            "example_step_attribs.h5"

    character (len=*), parameter :: ATTR_STRING =      "StepAttrString"
    character (len=*), parameter :: ATTR_I4 =          "StepAttrInt32"
    character (len=*), parameter :: ATTR_I8 =          "StepAttrInt64"
    character (len=*), parameter :: ATTR_R4 =          "StepAttrFloat32"
    character (len=*), parameter :: ATTR_R8 =          "StepAttrFloat64"

gsell's avatar
gsell committed
28
    character (len=*),parameter :: string_value =      "This is a string attribute bound to this step."
29 30 31 32 33 34 35 36

    integer*4, parameter, dimension(*) :: i4_value =   (/0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144/)
    integer*8, parameter, dimension(*) :: i8_value =   (/42, 43, 44, 45/)
    real*4, parameter, dimension(*) ::    r4_value =   (/2.71828/)
    real*8, parameter, dimension(*) ::    r8_value =   (/3.141592653589793238462643383279502884197169/)

    integer*8 :: file_id, status

gsell's avatar
gsell committed
37 38
#if defined(PARALLEL_IO)
    integer :: ierr
39
    call mpi_init(ierr)
gsell's avatar
gsell committed
40 41
#endif
    
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    ! abort program on any H5hut error
    call h5_abort_on_error()

    call h5_set_verbosity_level (verbosity_level)

    !  MPI_COMM_WORLD is used, if file is opened with default properties
    file_id = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)

    ! open step 1
    status = h5_setstep (file_id, int8(1))

    ! write attributes
    status = h5_writestepattrib_string (file_id, ATTR_STRING, string_value)
    status = h5_writestepattrib_i4     (file_id, ATTR_I4,     i4_value, int8(size(i4_value, 1)))
    status = h5_writestepattrib_i8     (file_id, ATTR_I8,     i8_value, int8(size(i8_value, 1)))
    status = h5_writestepattrib_r4     (file_id, ATTR_R4,     r4_value, int8(size(r4_value, 1)))
    status = h5_writestepattrib_r8     (file_id, ATTR_R8,     r8_value, int8(size(r8_value, 1)))

    ! cleanup
    status = h5_closefile (file_id)

gsell's avatar
gsell committed
63 64 65
#if defined(PARALLEL_IO)
    call mpi_finalize(ierr)
#endif
66
  end program write_step_attribs