1

I have a complex array created and stored in hdf5 format as follows:

import numpy as np
import h5py

a = np.random.random((50,50))
b = np.random.random((50,50))
a = a+1j*b
with h5py.File('random.hdf5','w') as f:
    dset = f.create_dataset('vec',data=a,dtype='c16',compression="gzip",compression_opts=4)
f.close()

Now I am trying to read this file random.hdf5 via a Fortran routine.

Fortran has no native complex data types for hdf5. How do I go about reading this file?

(Also if it helps, I am using Intel fortran compiler)

  • hdf5 doesn't support complex data. How was this file written? Also while about netcdf https://stackoverflow.com/questions/57130311/using-parallel-netcdf-to-save-a-distributed-3d-complex-array might be of use – Ian Bush Jul 15 '20 at 07:48
  • By "How was this file written?", do you mean the hdf5 data file? I have given an example python code which generates a file (random.hdf5) in the format that my actual data files are in. My data files are already in hdf5 format. So I am not looking at netcdf at the moment. – Unpotating Potato Jul 15 '20 at 09:48
  • Sorry - misread your question on the writing part. The point about the netcdf link was to read complex numbers in netcdf you have to create a complex compound type as discussed, I don't know but this may be the way forward in hdf5 as well – Ian Bush Jul 15 '20 at 09:53
  • You can treat Fortran complex numbers as pairs of two real numbers. Using sequence association for procedure arguments or in equivalence and transfer. – Vladimir F Героям слава Jul 15 '20 at 12:00

0 Answers0