Redirect I/O to variable

Dear all,

I have some legacy Fortran code for which I’m writing a wrapper routine. The code allows to pass a unit number to which error messages will be written.
In the wrapper routine I need to capture these error messages in order to take appropriate action. If 0 is passed as unit number the code will write the error messages to screen (the unit number is changed from 0 to 6). This means I can’t use stderr (unit no 0) to capture the error messages.

So I’m looking for a way to redirect the I/O of a unit number to a variable or internal file. Is this possible?

cheers,
Maarten

So I’m looking for a way to redirect the I/O of a unit number to a variable or internal file. Is this possible?

I don’t think this is possible but maybe you could open a scratch file? When the unit is returned, rewind the file and then read back the messages.

  • Mat

Yes I think that’s the only solution then. Thanks.

cheers,
Maarten