HDF5 string read errors

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:

  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

···

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov<mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center

Hello,

Memory type is not correct when you read array of the fixed size strings. Please take a look at this example
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/FORTRAN/H5T/h5ex_t_stringC_F03.f90

Elena

···

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Jul 7, 2015, at 10:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov<mailto:clay.blankenship@nasa.gov>> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:

  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov<mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

You can have a look at the program h5ex_t_string_F03.f90 from:

https://www.hdfgroup.org/HDF5/examples/api18-fortran.html

You should be able to remove the writing section of the example and just modify the reading part in order to read your dataset.

Scot

···

On Jul 7, 2015, at 2:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:
  
  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Elena is correct, take a look at h5ex_t_stringC_F03.f90 instead.

···

On Jul 7, 2015, at 3:06 PM, Scot Breitenfeld <brtnfld@hdfgroup.org> wrote:

You can have a look at the program h5ex_t_string_F03.f90 from:

https://www.hdfgroup.org/HDF5/examples/api18-fortran.html

You should be able to remove the writing section of the example and just modify the reading part in order to read your dataset.

Scot

On Jul 7, 2015, at 2:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

    DATASET "spacecraft_overpass_time_utc" {
        DATATYPE H5T_STRING {
              STRSIZE 24;
              STRPAD H5T_STR_NULLTERM;
              CSET H5T_CSET_ASCII;
              CTYPE H5T_C_S1;
           }

Here is my Fortran code:

use hdf5

integer :: istatus
integer(HID_T) :: fileid,dsetid,datatype
integer, parameter :: n_ease=267264
character*80 :: dsetname(12)
character(len=24), dimension(n_ease) :: tutc_ease
integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
integer(SIZE_T) :: mysize,sdim

dims(1)=n_ease

!Open fortran interface
call h5open_f(istatus)
call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
call h5tget_size_f(datatype,mysize,istatus) !mysize is good
call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
#000: H5Dio.c line 174 in H5Dread(): can't read data
   major: Dataset
   minor: Read failed
#001: H5Dio.c line 337 in H5D_read(): unable to set up type info
   major: Dataset
   minor: Unable to initialize object
#002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
   major: Dataset
   minor: Feature is unsupported
#003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
   major: Datatype
   minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

When I copy the code from Elena’s example, I get these compile errors:

readsmap.f90(161): error #6404: This name does not have a type, and must have an explicit type. [H5T_FORTRAN_S1]
  call h5tcopy_f(H5T_FORTRAN_S1, memtype,istatus)
-----------------^
readsmap.f90(167): error #6285: There is no matching specific subroutine for this generic subroutine call. [H5DREAD_F]
  call h5dread_f(dsetid,memtype,f_ptr,istatus,space)
-------^
compilation aborted for readsmap.f90 (code 1)

···

From: Elena Pourmal <epourmal@hdfgroup.org<mailto:epourmal@hdfgroup.org>>
Reply-To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Date: Tuesday, July 7, 2015 at 3:05 PM
To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Subject: Re: [Hdf-forum] HDF5 string read errors

Hello,

Memory type is not correct when you read array of the fixed size strings. Please take a look at this example
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/FORTRAN/H5T/h5ex_t_stringC_F03.f90

Elena
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Jul 7, 2015, at 10:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov<mailto:clay.blankenship@nasa.gov>> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:

  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov<mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

This is what I use:

      subroutine h5ltread_dataset_char_f(file_id,dset_name,data_out,dims,error)
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! High-level HDF5 FORTRAN API for reading a character array.
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      use HDF5
!
      implicit none
!
      integer(HID_T) :: file_id ! File identifier
      character(len=*), intent(IN) :: dset_name
      integer(HSIZE_T), dimension(*), intent(IN) :: dims ! size of the buffer
      character(len=*),dimension(*), intent(INOUT) :: data_out ! data buffer
      integer, intent(out) :: error ! Error flag
!
      integer(HID_T) :: dset_id ! Dataset identifier
      integer(HID_T) :: atype ! Datatype identifier
      integer(SIZE_T) :: size ! Datatype size
!
      call h5tcopy_f(H5T_NATIVE_CHARACTER,atype,error)
      size=len(data_out)
      call h5tset_size_f(atype,size,error)
!
      call h5dopen_f(file_id,dset_name,dset_id,error)
!
      call h5dread_f(dset_id,atype,data_out,dims,error,H5S_ALL_F,H5S_ALL_F,H5P_DEFAULT_F)
      !
      ! End access to the dataset and release resources used by it.
      !
      call h5dclose_f(dset_id,error)
!
      end subroutine h5ltread_dataset_char_f

···

On Jul 7, 2015, at 4:18 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov> wrote:

When I copy the code from Elena’s example, I get these compile errors:

readsmap.f90(161): error #6404: This name does not have a type, and must have an explicit type. [H5T_FORTRAN_S1]
  call h5tcopy_f(H5T_FORTRAN_S1, memtype,istatus)
-----------------^
readsmap.f90(167): error #6285: There is no matching specific subroutine for this generic subroutine call. [H5DREAD_F]
  call h5dread_f(dsetid,memtype,f_ptr,istatus,space)
-------^
compilation aborted for readsmap.f90 (code 1)

From: Elena Pourmal <epourmal@hdfgroup.org <mailto:epourmal@hdfgroup.org>>
Reply-To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org <mailto:hdf-forum@lists.hdfgroup.org>>
Date: Tuesday, July 7, 2015 at 3:05 PM
To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org <mailto:hdf-forum@lists.hdfgroup.org>>
Subject: Re: [Hdf-forum] HDF5 string read errors

Hello,

Memory type is not correct when you read array of the fixed size strings. Please take a look at this example
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/FORTRAN/H5T/h5ex_t_stringC_F03.f90

Elena
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org <http://hdfgroup.org/>
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Jul 7, 2015, at 10:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov <mailto:clay.blankenship@nasa.gov>> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:
  
  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov <mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org <mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Thanks Christian, that worked.

Clay

···

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov<mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center

From: Christian Oyarzun <christian.oyarzun@studsvik.com<mailto:christian.oyarzun@studsvik.com>>
Reply-To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Date: Tuesday, July 7, 2015 at 4:01 PM
To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Subject: Re: [Hdf-forum] HDF5 string read errors

This is what I use:

      subroutine h5ltread_dataset_char_f(file_id,dset_name,data_out,dims,error)
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! High-level HDF5 FORTRAN API for reading a character array.
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      use HDF5
!
      implicit none
!
      integer(HID_T) :: file_id ! File identifier
      character(len=*), intent(IN) :: dset_name
      integer(HSIZE_T), dimension(*), intent(IN) :: dims ! size of the buffer
      character(len=*),dimension(*), intent(INOUT) :: data_out ! data buffer
      integer, intent(out) :: error ! Error flag
!
      integer(HID_T) :: dset_id ! Dataset identifier
      integer(HID_T) :: atype ! Datatype identifier
      integer(SIZE_T) :: size ! Datatype size
!
      call h5tcopy_f(H5T_NATIVE_CHARACTER,atype,error)
      size=len(data_out)
      call h5tset_size_f(atype,size,error)
!
      call h5dopen_f(file_id,dset_name,dset_id,error)
!
      call h5dread_f(dset_id,atype,data_out,dims,error,H5S_ALL_F,H5S_ALL_F,H5P_DEFAULT_F)
      !
      ! End access to the dataset and release resources used by it.
      !
      call h5dclose_f(dset_id,error)
!
      end subroutine h5ltread_dataset_char_f

On Jul 7, 2015, at 4:18 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov<mailto:clay.blankenship@nasa.gov>> wrote:

When I copy the code from Elena’s example, I get these compile errors:

readsmap.f90(161): error #6404: This name does not have a type, and must have an explicit type. [H5T_FORTRAN_S1]
  call h5tcopy_f(H5T_FORTRAN_S1, memtype,istatus)
-----------------^
readsmap.f90(167): error #6285: There is no matching specific subroutine for this generic subroutine call. [H5DREAD_F]
  call h5dread_f(dsetid,memtype,f_ptr,istatus,space)
-------^
compilation aborted for readsmap.f90 (code 1)

From: Elena Pourmal <epourmal@hdfgroup.org<mailto:epourmal@hdfgroup.org>>
Reply-To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Date: Tuesday, July 7, 2015 at 3:05 PM
To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Subject: Re: [Hdf-forum] HDF5 string read errors

Hello,

Memory type is not correct when you read array of the fixed size strings. Please take a look at this example
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/FORTRAN/H5T/h5ex_t_stringC_F03.f90

Elena
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org<http://hdfgroup.org/>
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Jul 7, 2015, at 10:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov<mailto:clay.blankenship@nasa.gov>> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:

  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov<mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Apparently the library you are using was not built with Fortran2003 APIs enabled (—enable-fortran —enable-fortran2003 configure flags), but I see that the issue has been resolved.

Elena

···

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Jul 7, 2015, at 11:18 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov<mailto:clay.blankenship@nasa.gov>> wrote:

When I copy the code from Elena’s example, I get these compile errors:

readsmap.f90(161): error #6404: This name does not have a type, and must have an explicit type. [H5T_FORTRAN_S1]
  call h5tcopy_f(H5T_FORTRAN_S1, memtype,istatus)
-----------------^
readsmap.f90(167): error #6285: There is no matching specific subroutine for this generic subroutine call. [H5DREAD_F]
  call h5dread_f(dsetid,memtype,f_ptr,istatus,space)
-------^
compilation aborted for readsmap.f90 (code 1)

From: Elena Pourmal <epourmal@hdfgroup.org<mailto:epourmal@hdfgroup.org>>
Reply-To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Date: Tuesday, July 7, 2015 at 3:05 PM
To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>>
Subject: Re: [Hdf-forum] HDF5 string read errors

Hello,

Memory type is not correct when you read array of the fixed size strings. Please take a look at this example
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/FORTRAN/H5T/h5ex_t_stringC_F03.f90

Elena
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org<http://hdfgroup.org/>
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Jul 7, 2015, at 10:42 PM, Blankenship, Clay B. (MSFC-ZP12)[USRA] <clay.blankenship@nasa.gov<mailto:clay.blankenship@nasa.gov>> wrote:

Hi,
I am trying to read an HDF5 file using Fortran. I can read all the datasets I need except one which is a string. What am I doing wrong? I can’t find many examples of reading a fixed-length string array.

Thanks!

Here is the relevant output from h5dump:

     DATASET "spacecraft_overpass_time_utc" {
         DATATYPE H5T_STRING {
               STRSIZE 24;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }

Here is my Fortran code:

  use hdf5

  integer :: istatus
  integer(HID_T) :: fileid,dsetid,datatype
  integer, parameter :: n_ease=267264
  character*80 :: dsetname(12)
  character(len=24), dimension(n_ease) :: tutc_ease
  integer(HSIZE_T), dimension(1) :: dims,maxdims,newdims
  integer(SIZE_T) :: mysize,sdim

  dims(1)=n_ease

  !Open fortran interface
  call h5open_f(istatus)
  call h5fopen_f(fname,H5F_ACC_RDWR_F,fileid,istatus)
  dsetname(5)='Soil_Moisture_Retrieval_Data/spacecraft_overpass_time_utc'
  call h5dopen_f(fileid,dsetname(5),dsetid,istatus)
  call h5dget_type_f(dsetid,datatype,istatus) !datatype is not equal to H5T_STRING!
  call h5tget_size_f(datatype,mysize,istatus) !mysize is good
  call h5dread_f(dsetid,H5T_STRING,tutc_ease,dims,istatus) !errors here

The errors are:
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5Dio.c line 174 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: H5Dio.c line 337 in H5D_read(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: H5Dio.c line 836 in H5D_typeinfo_init(): unable to convert between src and dest datatype
    major: Dataset
    minor: Feature is unsupported
  #003: H5T.c line 4459 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

--
Clay Blankenship * USRA Research Scientist
clay.blankenship@nasa.gov<mailto:clay.b.blankenship@nasa.gov> * 256-961-7638
320 Sparkman Drive * Huntsville, AL 35805 USA
NASA-MSFC Short-Term Prediction Research and Transition (SPoRT) Center
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5