The 'program test_read_real_from_bytes' below works as free-standing code.
Essentially the same code in 'real_in4_w' below runs fine in /check /undef mode, but not otherwise. The Run-time Error is #67.
The code stops after ' write (iot,'( '' char bytes = ichar '' )' ) '. It correctly lists the four ichar values as four ichar bytes : 103 148 19 68
Any suggestions as to what I'm doing wrong?
PS The convoluted procedure of extracting the ichar values and then reforming the chars into rbyt was simply to get a handle on what the code was doing. I get the same error message if I bypass the ichar / char steps and try to read xval from the input dbyt values.
program test_read_real_from_bytes
character *4 dbyt, rbyt
integer*2 ich_dbyt (4)
real *4 xval, zval
iot = 7
open ( iot, file = 'test_read_real_from_bytes_out.txt' )
c Sample rate: 590.318787 Hz
ich_dbyt(1) = 103
ich_dbyt(2) = 148
ich_dbyt(3) = 19
ich_dbyt(4) = 68
write (iot,'(/ '' four ichar bytes : '', 4i10 )' )
1 ( ich_dbyt(ie), ie=1,4 )
do ie = 1, 4
dbyt(ie:ie) = char ( ich_dbyt(ie) )
end do
c write (iot,'( '' four char bytes : '', 4a )' ) c 1 ( dbyt(ie:ie), ie=1,4 )
do ie = 1, 4
rbyt(ie:ie) = dbyt(ie:ie)
end do
read ( rbyt, '(4a)' ) zval
write (iot,'( '' value : '', f10.6 )' ) zval
stop
end
four ichar bytes : 103 148 19 68 value : 590.318787
subroutine real_in4_w ( dbyt, zval )
character * ( * ) dbyt
integer*2 ich_dbyt (4)
character *4 rbyt
real *4 xval
iot = 6
do ie = 1, 4
ich_dbyt(ie) = ichar ( dbyt(ie:ie) )
end do
write (iot,'(/ '' four ichar bytes : '', 4i10 )' )
1 ( ich_dbyt(ie), ie=1,4 )
write (iot,'( '' char bytes = 0 '' )' )
do ie = 1, 4
rbyt(ie:ie) = char ( 0 )
end do
do ie = 1, 4
rbyt(ie:ie) = char ( ich_dbyt(ie) )
end do
write (iot,'( '' char bytes = ichar '' )' )
read ( rbyt, '(4a)' ) xval
write (iot,'( '' value : '', f10.6 )' ) xval
zval = xval
return
end