Search code examples
ioformattingfortran

What is the source of following fortran runtime error when I have used the correct WRITE DESCRIPTOR?


I was just making a program that reads values from a file that contains data and just uses it to calculate a simple function , then prints the output to another file.

I can't understand why it shows that it got character when I have used the F descriptor here.

program doppler_w_data

implicit none

real f
integer i,u,v,n

open(unit=1,file="inputfor_doppler.txt",status="old")
open(unit=2,file="outputfor_doppler.txt",status="old")

do i=1,5
read(1,1001) u,v,n

1001 format(4I5)

f = n*(330+u)/(330-v)

write(2,1002) "the req apparent freq is" ,f

1002 format(F9.4)

end do
endprogram doppler_w_data

The error is:

At line 18 of file doppler_w_data.f90 (unit = 2, file = 'outputfor_doppler.txt')
Fortran runtime error: Expected REAL for item 1 in formatted transfer, got CHARACTER
(F9.4)
 ^

Solution

  • You did not use the correct descriptor. The data for output is

      "the req apparent freq is"
    

    and that is CHARACTER.

    The descriptor is

      F9.4
    

    and that is for the REAL numerical datatype.

    Use the A descriptor for CHARACTER data.