Today I realized something strange. See this simple program that writes a real array in a binary file:
program writeit implicit none integer, parameter :: n = 32 real, dimension(n) :: a integer :: iunit a(:) = 1. open(newunit=iunit,file='a.bin',status='replace',access='direct',recl=n*storage_size(1.)/8) write(iunit,rec=1) a(:) close(iunit) end program writeit
To my surprise, while in the gnu, cray and pgi compilers, the file size is, as expected = 32*4 = 128 bytes, with the intel compiler the corresponding file size is four times bigger: 512 bytes. It seems that the intel compiler (and perhaps others) assumes that recl is in units of 4 bytes (link below) unless the code is compiled with a specific flag. Shouldn’t the unit defining the record length be standardized? I’m sure there is a good reason for intel to choose this default value, but I do not see it. This has caused me a bit of trouble today.
The solution as most of you know is to use the inquire statement to fetch the record length of the real number, but if one is not careful this can also cause issues: for a long time I was using the inquire statement to fetch the size of a real in bytes, and now I realize why at that time I was also having an issue when using an intel compiler.
I thought this may be useful to some of you who may not be aware of this.