I have a problem trying to WRITE the result of a function that returns a string. Whenever I try to WRITE the result, I get an error: “PGFIO-F-235/formatted write/internal file/edit descriptor does not match item.” However, if I try PRINT, the result is displayed correctly.
PROGRAM test CHARACTER(LEN=4) :: mambo !function INTEGER :: x x = 1 WRITE(*, '(A)') mambo (x) END PROGRAM test FUNCTION mambo (x) RESULT (string) CHARACTER(LEN=4) :: string INTEGER :: x WRITE(string, "(I4.4)") x RETURN END FUNCTION mambo
Since x = 1, I would expect the program to print out ‘0001’. Instead, I get:
inferno  ./a.out PGFIO-F-235/formatted write/internal file/edit descriptor does not match item
If I replace “WRITE(*, ‘(A)’) mambo (x)” with “PRINT *, mambo(x)” … it works as expected.
Any idea what is going on?