The test program given below contains four errors: format edit descriptors that are mismatched for the corresponding variables in the I/O list. Absoft Fortran catches only one of the four errors. Are there any obscure compiler options that can be specified to help catch such errors?
program mismatch
implicit none
integer i, ios
real r
character(2) :: iline = '1.', jline='12'
character(132) :: msg
!
print '(/,A,/)','Test-1'
read(iline,'(F2.1)',iostat=ios,iomsg=msg)i !reading real number into integer variable using F format
if(ios /= 0)then
print *,'ios = ',ios,' for READ 1, msg: ',trim(msg)
else
print *,'Value of i: ',i
endif
write(*,'(ES10.3,4x,I10)',iostat=ios,iomsg=msg)i,i !printing integer using ES format
if(ios /= 0)print *,'ios = ',ios,' for WRITE 1, msg: ',trim(msg)
print '(/,A,/)','Test-2'
read(jline,'(I3)',iostat=ios,iomsg=msg)r !reading integer data into real variable using I format
if(ios /= 0)print *,'ios = ',ios,' for READ 2, msg: ',trim(msg)
write(*,'(ES10.3,4x,I10)',iostat=ios,iomsg=msg)r,r !printing real using I format
if(ios /= 0)print *,'ios = ',ios,' for WRITE 2, msg: ',trim(msg)
end program
The output from the same program when it is compiled and run using Gfortran:
Test-1
ios = 5006 for READ 1, msg: Expected REAL for item 1 in formatted transfer, got INTEGER
(F2.1)
^
ios = 5006 for WRITE 1, msg: Expected REAL for item 1 in formatted transfer, got INTEGER
(ES10.3,4x,I10)
^
Test-2
ios = 5006 for READ 2, msg: Expected INTEGER for item 1 in formatted transfer, got REAL
(I3)
^
1.401E-45 ios = 5006 for WRITE 2, msg: Expected INTEGER for item 2 in formatted transfer, got REAL
(ES10.3,4x,I10)
^
/code]