pgfortran is apparently storing multi-dimensional arrays of user defined types in row-major order instead of column-major order. Is this a bug or is there something I’m missing in the Fortran spec that allows this? Below is my test code and output. The results are the same with Community Edition 2017 and 2018.
$ cat out_test.f03
program out_test
implicit none
integer :: i
type MyRec
real :: pos
real :: neg
end type MyRec
type(MyRec) :: pn1(6), pn2(2, 3)
do i = 1, 6
pn1(i)%pos = i
pn1(i)%neg = -i
enddo
pn2 = reshape(pn1, [2, 3])
open(10, file = “out_test.dat”, &
action = ‘write’, form = ‘unformatted’, access = ‘stream’, &
status = ‘replace’)
write(10) pn2
close(10)
end program out_test
$ cat in_test.f03
program in_test
implicit none
integer :: i
type MyRec
real :: pos
real :: neg
end type MyRec
type(MyRec) :: pn1(6)
open(10, file = “out_test.dat”, &
action = ‘read’, form = ‘unformatted’, access = ‘stream’, &
status = ‘old’)
read(10) pn1
close(10)
do i = 1, 6
print *, pn1(i)
enddo
end program in_test
$ pgfortran -o out_test out_test.f03
$ pgfortran -o in_test in_test.f03
$ ./out_test
$ ./in_test
1.000000 -1.000000
3.000000 -3.000000
5.000000 -5.000000
2.000000 -2.000000
4.000000 -4.000000
6.000000 -6.000000