internal Fortran reading operation fails to return non-zero status if
one attempts to read a real*8 from a string which is does not contain
a valid number, and therefore the reading operation must fail.
This may have some implication for ROMS, ever more for plotting package
(since it uses string-to-number conversions) and other codes. Please take
a look at this test program and see whether you have similar experiences.
Code: Select all
program reading_error
implicit none
real(kind=8) value
character(len=16) string
integer ierr
string='1.6'
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
string='-3.1415926D-3'
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
string='123456789012346'
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
string='1.D+02'
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
string='4D+03' !<-- "semi-legal" (no decimal point),
read(string,*,iostat=ierr) value ! but actually read OK
write(*,*) string, value, ierr
string='2E4' !<-- "semi-legal", but actually read OK
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
!??
!?? The following two cases should cause reading error, because
!?? the content of the string is not a number, so as the outcome
!?? ierr should be different from 0, while the number should not
!?? be read (hence variable "value" retains its previous value;
!?? this program compliled using GNU gfortran compiler, the
!?? outcome is, indeed a non-zero ierr, and "value" retains its
!?? value from above.
!??
!?? If complied using Intel "ifort" (versions/package IDs tested:
!?? l_fc_c_9.1.040, l_fc_p_10.1.011, and l_cprof_p_11.0.081) the
!?? outcome is value becomes -1.0000, and ierr becomes 0.
!??
!?? This behavior occurs both if using 64- (x86_64) and 32-bit
!?? (i686) compiler and operating system
!??
string='test.nc' !<-- SHOULD CAUSE iostat ERROR
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
string='test_0000.nn' !<-- SHOULD CAUSE iostat ERROR
read(string,*,iostat=ierr) value
write(*,*) string, value, ierr
stop
end