https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96018
--- Comment #5 from anlauf at gcc dot gnu.org --- (In reply to martin.schlipf from comment #4) > Finally, I reproduced it with gfortran 9.3.0 + hdf 1.12.0 and gfortran 10.0 > + hdf 1.10.4. With older versions of gfortran 7.3.0 it does not appear. Workarounds: - compile with -O0, not sure why this makes a difference - or replace in write_real_array_nd: real, intent(in) :: array(*) by real :: array(*) I'd recommend to additionally replace in write_complex_array_3d ierr = write_real_array_4d(locid, dataset_name, ptr) by ierr = write_real_array_4d(locid, dataset_name, & reshape (transfer(array,[1.0]),[2, shape(array)])) The latter is IMO much cleaner Fortran. There might by a bug in gfortran with the way you use c_f_pointer and assumed-size, which generates wrong code for argument packing, or there is a bug elsewhere which may corrupt data subtly.