  !>
  !> write real 1d dataset to hdf5 file
  !>
  subroutine hdf5_usg_write_group_data_r1d(group_id,dataname,nsize,nsize_gbl,offset,dataset)

    use gen, only : hdf5_compress_level


    implicit none

    !c passed variables
    integer(HID_T), intent(in) :: group_id ! File identifier
    character(*), intent(in) :: dataname   ! Dataset name
    integer, intent(in) :: nsize           ! Size of local Dataset
    integer, intent(in) :: nsize_gbl       ! Size of global Dataset
    integer, intent(in) :: offset          ! Offset of local dataset
    real*8, allocatable :: dataset(:)      ! Dataset

    !c local variables
    integer :: hdf5_ierr                   ! HDF5 error code
    integer :: hdf5_ndim                   ! h5gopen_fNumber of dimensions used in the dataspace
    integer(HSIZE_T) :: hdf5_dsize(3)      ! Array with current dimension sizes
    integer(HSIZE_T) :: hdf5_offset(3)     ! Offset of start of hyperslab
    integer(HSIZE_T) :: hdf5_count(3)      ! Number of blocks to select from dataspace
    integer(HSIZE_T) :: hdf5_stride(3)     ! Array of how many elements to move in each direction
    integer(HSIZE_T) :: hdf5_block(3)      ! Size of the element block
    integer(HSIZE_T) :: hdf5_gdsize(3)     ! Array with current dimension global sizes
    integer(HSIZE_T) :: hdf5_goffset(3)    ! Offset of start of hyperslab
    integer(HSIZE_T) :: hdf5_csize(3)      ! Ayyay conaining sizes of chunk dimensions
    integer(HID_T) :: dset_id              ! Dataset identifier
    integer(HID_T) :: chunk_id             ! Chunk identifier
    integer(HID_T) :: filespace            ! Dataspace identifier in file
    integer(HID_T) :: memspace             ! Memoryspace identifier in file
    integer(HID_T) :: xlist_id             ! Property list identifier

    ! Uncomment these variables to use SZIP compression
    !integer :: szip_options_mask
    !integer :: szip_pixels_per_block

    !c create the data space for the domain datset
    hdf5_ndim = 1
    hdf5_dsize(1) = nsize
    hdf5_offset(1) = 0
    hdf5_count(1) = nsize
    hdf5_stride(1) = 1
    hdf5_block(1) = 1
    hdf5_gdsize(1) = nsize_gbl
    hdf5_goffset(1) = offset

    !hdf5_csize(1) = 1
    hdf5_csize(1) = min(nsize_gbl,1024)   !1024 intege*4 is 4096(4K) which matches most file block size on file systems

    !c make sure the group has already been created before opening it

    !c create local memory space and hyperslab
    call h5screate_simple_f(hdf5_ndim, hdf5_dsize, memspace,           &
                            hdf5_ierr)
    if (nsize <= 0) then
      call h5sselect_none_f(memspace,hdf5_ierr)
    end if
    call h5sselect_hyperslab_f(memspace, H5S_SELECT_SET_F,             &
                               hdf5_offset, hdf5_count, hdf5_ierr,     &
                               hdf5_stride, hdf5_block)

    !c create the global file space and hyperslab
    call h5screate_simple_f(hdf5_ndim,hdf5_gdsize,filespace,           &
                            hdf5_ierr)
    if (nsize <= 0) then
      call h5sselect_none_f(filespace,hdf5_ierr)
    end if
    call h5sselect_hyperslab_f(filespace, H5S_SELECT_SET_F,            &
                               hdf5_goffset, hdf5_count, hdf5_ierr,    &
                               hdf5_stride, hdf5_block)

    !c create a data chunking property
    call h5pcreate_f(H5P_DATASET_CREATE_F, chunk_id, hdf5_ierr)
    call h5pset_chunk_f(chunk_id, hdf5_ndim, hdf5_csize, hdf5_ierr)

    !c create compressed data, dataset must be chunked for compression
    !c the following cause crash in hdf5 library, check when new
    !c hdf5 version is available

    ! Set ZLIB / DEFLATE Compression using compression level 6.
    ! To use SZIP Compression comment out these lines.
    if (hdf5_compress_level > 0 .and. hdf5_compress_level < 10) then
      call h5pset_deflate_f(chunk_id, hdf5_compress_level, hdf5_ierr)
    end if

    ! Uncomment these lines to set SZIP Compression
    !szip_options_mask = H5_SZIP_NN_OM_F
    !szip_pixels_per_block = 16
    !call H5Pset_szip_f(chunk_id, szip_options_mask,                    &
    !                  szip_pixels_per_block, hdf5_ierr)

    !c create the dataset id
    call h5dcreate_f(group_id, dataname, H5T_NATIVE_DOUBLE,            &
                     filespace, dset_id, hdf5_ierr,                    &
                     dcpl_id=chunk_id)

    !c create a data transfer property
    call h5pcreate_f(H5P_DATASET_XFER_F, xlist_id, hdf5_ierr)
    call h5pset_dxpl_mpio_f(xlist_id, H5FD_MPIO_COLLECTIVE_F,          &
                            hdf5_ierr)

    !c write the dataset collectively
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    !!!! CODE CRASHES HERE IF SOME PROCESSORS HAVE NO DATA TO WRITE!!!!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    call h5dwrite_f(dset_id, H5T_NATIVE_DOUBLE, dataset, hdf5_dsize,   &
                    hdf5_ierr, file_space_id=filespace,                &
                    mem_space_id=memspace, xfer_prp = xlist_id)

    call h5dclose_f(dset_id, hdf5_ierr)

    !c close resources
    call h5sclose_f(filespace, hdf5_ierr)
    call h5sclose_f(memspace, hdf5_ierr)
    call h5pclose_f(chunk_id, hdf5_ierr)
    call h5pclose_f(xlist_id, hdf5_ierr)

  end subroutine hdf5_usg_write_group_data_r1d