Error while reading a hyperslab of a hdf5 file with compound datatype


I need to write a module where I create a file with an extendible dataset, write data into it and read the last row of a 2D dataset in a hdf5 file which is of a compound datatype. I am successfull in creating and writing the dataset into the file, but when I try to read the last row by selecting the hyperslab, it throws errors as shown below

HDF5-DIAG: Error detected in HDF5 (1.10.5) thread 0:
  #000: H5Dio.c line 199 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 487 in H5D__read(): src and dest dataspaces have different number of elements selected
    major: Invalid arguments to routine
    minor: Bad value
HDF5-DIAG: Error detected in HDF5 (1.10.5) thread 0:
  #000: H5T.c line 1754 in H5Tclose(): not a datatype
    major: Invalid arguments to routine
    minor: Inappropriate type

I am using the same memory type id that I use to create the datatype while writing. That is still throwing datatype errors and also dataspace errors. I am uploading the testprogram I am using. But the code snippet for the read routine is as follows

 ! now reading the file
    write(*,*) ' into reading'
    call h5fopen_f('swarms.h5', H5F_ACC_RDONLY_F, this% id, this% error)
    !call check_error(this% error, 'error opening the file swarms.h5')
    call h5gopen_f(this% id, 'swarms', this%swarms, this% error)
    ! open dataset, dataspace and get data dimensions
    write(*,*) 'opening dataset'
    call h5dopen_f (this%swarms, 'swarm list', this%dset_id, this%error)
    CALL h5dget_space_f(this%dset_id, this%dspace_id, error)
    call h5sget_simple_extent_dims_f(this%dspace_id, dims, maxdims, this%error)
    !create hyperslab to read
    offset(1:rank-1) = 0
    offset(rank) = dims(rank) - 1 
    counts(1:rank-1) = shape(read_swrm)
    counts(rank) = 1
    write(*,*) 'selecting hyperslab to read'
    write(*,*) 'dims:', dims, 'offset', offset, 'counts', counts
    call h5sselect_hyperslab_f(this%dspace_id, H5S_SELECT_SET_F, offset, counts, this%error)
    write(*,*) 'in reading line'
    ! read using defined hyperslab
    f_ptr = C_LOC(read_swrm(1))
    call h5dread_f(this%dset_id, file%memtype, f_ptr, this%error, this%dspace_id)

Here file%memtype is the memtype id for the compound datatype I use to create. I would grateful if you can let me know if I am doing anything incorrect.

And How would one read a compund datatype in fortran when the memtype has not been established before? In all the examples I saw in the hdf5 examples, they read after writing but how do you read a compound datatype that is already exisiting.

Makefile (270 Bytes)
objects.f90 (754 Bytes)
testprogram.f90 (5.8 KB)