rload_1d_array_from_hdf5 Subroutine

private subroutine rload_1d_array_from_hdf5(h5file_id, dset, rdata, attr)

Arguments

Type IntentOptional AttributesName
integer(kind=HID_T), intent(in) :: h5file_id
character(len=MAX_STRING_LENGTH), intent(in) :: dset
real(kind=rp), intent(inout), DIMENSION(:), ALLOCATABLE:: rdata
character(len=MAX_STRING_LENGTH), intent(out), optional DIMENSION(:), ALLOCATABLE:: attr

Contents


Source Code

  subroutine rload_1d_array_from_hdf5(h5file_id,dset,rdata,attr)
    INTEGER(HID_T), INTENT(IN) 				:: h5file_id
    CHARACTER(MAX_STRING_LENGTH), INTENT(IN)		:: dset
    REAL(rp), DIMENSION(:), ALLOCATABLE, INTENT(INOUT) 	:: rdata
    REAL, DIMENSION(:), ALLOCATABLE 			:: raw_data
    CHARACTER(MAX_STRING_LENGTH), OPTIONAL, DIMENSION(:), ALLOCATABLE, INTENT(OUT) 	:: attr
    CHARACTER(MAX_STRING_LENGTH) 			:: aname
    INTEGER(HID_T) 					:: dset_id
    INTEGER(HID_T) 					:: dspace_id
    INTEGER(HID_T) 					:: aspace_id
    INTEGER(HID_T) 					:: attr_id
    INTEGER(HID_T) 					:: atype_id
    INTEGER(HSIZE_T), DIMENSION(1) 			:: dims
    INTEGER(HSIZE_T), DIMENSION(1) 			:: adims
    INTEGER 						:: h5error

    dims = (/ shape(rdata) /)

    ALLOCATE( raw_data(dims(1)) )

    ! * * * Read data from file * * *

    call h5dopen_f(h5file_id, TRIM(dset), dset_id, h5error)
    if (h5error .EQ. -1) then
       write(6,'("KORC ERROR: Something went wrong in: rload_from_hdf5 --> h5dopen_f")')
    end if

    call h5dread_f(dset_id, H5T_NATIVE_REAL, raw_data, dims, h5error)
    if (h5error .EQ. -1) then
       write(6,'("KORC ERROR: Something went wrong in: rload_from_hdf5 --> h5dread_f")')
    end if
    rdata = REAL(raw_data,rp)

    call h5dclose_f(dset_id, h5error)
    if (h5error .EQ. -1) then
       write(6,'("KORC ERROR: Something went wrong in: rload_from_hdf5 --> h5dclose_f")')
    end if

    DEALLOCATE( raw_data )

    if (PRESENT(attr)) then
       ! * * * Read data attribute(s) from file * * *
    end if

    ! * * * Read data from file * * *
  end subroutine rload_1d_array_from_hdf5