fortrandev-null

Portable output to null stream in Fortran


I'd like to implement a verbosity level flag in a Fortran program in the following way. The code would use statements

write (level1, *) 'This will be shown always'
write (level2, *) 'This will be shown sometimes'

and the streams level1, level2 and higher would either be equal to output_unit or correspond to /dev/null (on Unix), depending on the value of the verbosity flag provided by the user.

However, /dev/null is not platform independent. I could try to detect Windows manually and work with NUL there, but I don't want to write platform-specific code. Is there a platform-independent way of writing to an output sink with write in Fortran?


Solution

  • I've made my earlier comment into an answer so we can tick this question off ...

    Fortran doesn't provide a platform independent way to send output into the void. If I wanted the facility I might write a little platform-dependent code, and wrap it into a module so I never had to look at it again.