mecej4
08-29-2010, 11:36 PM
Here are two short programs which contain the kind of recursive I/O statements that are allowed by the 2003 standard but not by the Fortran-95 standard. With both examples, the program runs correctly without the -chk option, but the runtime gives a misleading error when -chk is used.
Prog-1:
program tst
character(len=10) :: today='10/27/2005'
write(*,*)' Number of days = ',days(today)
stop
contains
integer function days(date1)
character(len=10) :: date1
integer :: mm,dd,yyyy
read(date1,'(I2,1x,I2,1x,I4)')mm,dd,yyyy
days=NINT(yyyy*365.25+mm*30.44+dd)
return
end function days
end program tst
The error message from this program:
Invalid decimal character ü was detected (unit=internal).
(the relative position causing an error in a record = 0ee s )
10/27/200
jwe0911i-u A work area cannot be reserved because of insufficient area
Prog-2:
program tst
write(*,*)' Today : ',today(8,25,2010)
stop
contains
character(len=10) function today(mm,dd,yyyy)
integer :: mm,dd,yyyy
write(today,'(I2,"|",I2,"|",I4)')mm,dd,yyyy
return
end function today
end program tst
The error message from this program:
jwe0019i-u The program was terminated abnormally with Exception Code EXCEPTION_ACCESS_VIOLATION
error summary (Fortran)
error number error level error count
jwe0019i u 1
total error count = 1
Prog-1:
program tst
character(len=10) :: today='10/27/2005'
write(*,*)' Number of days = ',days(today)
stop
contains
integer function days(date1)
character(len=10) :: date1
integer :: mm,dd,yyyy
read(date1,'(I2,1x,I2,1x,I4)')mm,dd,yyyy
days=NINT(yyyy*365.25+mm*30.44+dd)
return
end function days
end program tst
The error message from this program:
Invalid decimal character ü was detected (unit=internal).
(the relative position causing an error in a record = 0ee s )
10/27/200
jwe0911i-u A work area cannot be reserved because of insufficient area
Prog-2:
program tst
write(*,*)' Today : ',today(8,25,2010)
stop
contains
character(len=10) function today(mm,dd,yyyy)
integer :: mm,dd,yyyy
write(today,'(I2,"|",I2,"|",I4)')mm,dd,yyyy
return
end function today
end program tst
The error message from this program:
jwe0019i-u The program was terminated abnormally with Exception Code EXCEPTION_ACCESS_VIOLATION
error summary (Fortran)
error number error level error count
jwe0019i u 1
total error count = 1