! Hei Hei
!
! please see the following lines
!
program tektip
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! check derived type structure for binary io
! compile -> ifort tektip.f90 -o xtektip
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
integer (kind = 2) :: aone,atwo
integer (kind = 4) :: athree,afour,afive
real (kind = 4) :: asix
integer (kind = 2) :: bone,btwo
integer (kind = 4) :: bthree,bfour,bfive
real (kind = 4) :: bsix
! type construct
type teststruct
integer (kind = 2) :: cone
integer (kind = 2) :: ctwo
integer (kind = 4) :: cthree
integer (kind = 4) :: cfour
integer (kind = 4) :: cfive
real (kind = 4) :: csix
end type teststruct
!
type(teststruct) :: bintest
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! initial values
aone = 2
atwo = 4
athree = 1024
afour = 161257
afive = 752161
asix = 12.3456
!
open(convert = 'BIG_ENDIAN', unit = 10, file = 'test.bin', form = 'binary')
! write testdata
write(10)aone,atwo,athree,afour,afive,asix
write(10)aone,atwo,athree,afour,afive,asix
write(10)aone,atwo,athree,afour,afive,asix
write(10)aone,atwo,athree,afour,afive,asix
close(10)
!
open(convert = 'BIG_ENDIAN', unit = 11, file = 'test.bin', form = 'binary')
! read testdata
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
close(11)
!
open(convert = 'BIG_ENDIAN', unit = 12, file = 'test.bin', form = 'binary')
! read testdata
read(12)bintest
print*,bintest
read(12)bintest
print*,bintest
read(12)bintest
print*,bintest
read(12)bintest
print*,bintest
close(12)
end program tektip
!
! this is the what I get on my screen
!
! 2 4 1024 161257 752161 12.34560
! 2 4 1024 161257 752161 12.34560
! 2 4 1024 161257 752161 12.34560
! 2 4 1024 161257 752161 12.34560
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
!
! Why is the output not the same? I stumbled over this in an other
! program and wrote these lines just for demonstration. I really
! would like to use derived type structures as the real data files I
! want to read have various repeating integer headers and no fixed
! length data records with real numbers. I tried the same without
! convert = 'BIG_ENDIAN' and it works fine but the data I have
! to read is big endian.
! I am using the intel fortran compiler 11.1 on a linux machine and
! I hope one of you can help me. Thanks in advance.
!
! Hilsen, from Norway
!
! please see the following lines
!
program tektip
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! check derived type structure for binary io
! compile -> ifort tektip.f90 -o xtektip
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
integer (kind = 2) :: aone,atwo
integer (kind = 4) :: athree,afour,afive
real (kind = 4) :: asix
integer (kind = 2) :: bone,btwo
integer (kind = 4) :: bthree,bfour,bfive
real (kind = 4) :: bsix
! type construct
type teststruct
integer (kind = 2) :: cone
integer (kind = 2) :: ctwo
integer (kind = 4) :: cthree
integer (kind = 4) :: cfour
integer (kind = 4) :: cfive
real (kind = 4) :: csix
end type teststruct
!
type(teststruct) :: bintest
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! initial values
aone = 2
atwo = 4
athree = 1024
afour = 161257
afive = 752161
asix = 12.3456
!
open(convert = 'BIG_ENDIAN', unit = 10, file = 'test.bin', form = 'binary')
! write testdata
write(10)aone,atwo,athree,afour,afive,asix
write(10)aone,atwo,athree,afour,afive,asix
write(10)aone,atwo,athree,afour,afive,asix
write(10)aone,atwo,athree,afour,afive,asix
close(10)
!
open(convert = 'BIG_ENDIAN', unit = 11, file = 'test.bin', form = 'binary')
! read testdata
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
read(11)bone,btwo,bthree,bfour,bfive,bsix
print*,bone,btwo,bthree,bfour,bfive,bsix
close(11)
!
open(convert = 'BIG_ENDIAN', unit = 12, file = 'test.bin', form = 'binary')
! read testdata
read(12)bintest
print*,bintest
read(12)bintest
print*,bintest
read(12)bintest
print*,bintest
read(12)bintest
print*,bintest
close(12)
end program tektip
!
! this is the what I get on my screen
!
! 2 4 1024 161257 752161 12.34560
! 2 4 1024 161257 752161 12.34560
! 2 4 1024 161257 752161 12.34560
! 2 4 1024 161257 752161 12.34560
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
! 512 1024 262144 -378207744 561646336 -1.3658832E-26
!
! Why is the output not the same? I stumbled over this in an other
! program and wrote these lines just for demonstration. I really
! would like to use derived type structures as the real data files I
! want to read have various repeating integer headers and no fixed
! length data records with real numbers. I tried the same without
! convert = 'BIG_ENDIAN' and it works fine but the data I have
! to read is big endian.
! I am using the intel fortran compiler 11.1 on a linux machine and
! I hope one of you can help me. Thanks in advance.
!
! Hilsen, from Norway