program read_spectral

use hdf5

implicit none

type sp
 real(4) :: wavelength
 real(4) :: intensity
 integer(kind=1) :: ionization
 CHARACTER(LEN=22) :: comment
end type sp


! This is the name of the data file we will read. 
character (len = *), parameter :: filename  = "spectral_lines_library.h5"
character (len = *), parameter :: dsetname1 = "He"

integer         , parameter        :: ms_dim0 = 81
integer(hsize_t), dimension(1)     :: ms_dims = (/ms_dim0/), ndims
type(sp), dimension(ms_dim0), target  :: wdata


integer(hid_t)  :: file_id, dspace_id, dset_id, memtype ! Handles
integer         :: hdferr, i
type(c_ptr)     :: f_ptr_ms

 call h5open_f(hdferr)

 ! open file
 call h5fopen_f(filename, H5F_ACC_RDONLY_F, file_id, hdferr)

 ! open dataset
 call h5dopen_f(file_id, dsetname1, dset_id, hdferr)






 ! get the datatype
 call h5dget_type_f(dset_id, memtype, hdferr)

 ! read the data
 f_ptr_ms = c_loc(wdata(1))
 call h5dread_f(dset_id, memtype, f_ptr_ms, hdferr)

 
 
 
 

 do i=1, ms_dim0
   print *, wdata(i)%wavelength, wdata(i)%intensity, wdata(i)%ionization, wdata(i)%comment
 end do
 
 
 
 
 
 
 
 
 
 
 
 
 

 ! close and release resources
 call h5dclose_f(dset_id, hdferr)
 call h5tclose_f(memtype, hdferr)
 call h5fclose_f(file_id, hdferr)

end program read_spectral
