Re: using the same function for stdout and files
- From: beliavsky@xxxxxxx
- Date: 19 Jun 2006 05:34:23 -0700
Kamaraju Kusumanchi wrote:
Using Debian, Sid + gfortran/fort/absoft f90 (if that matters).
I have a subroutine as follows
subroutine print_array(unit_no, array)
which basically prints the array in a specific format and sends the
output to the file opened on unit_no.
Is it possible to use this function in a clever way so that the same
output is printed on stdout (just like when we specify write(*,FMT)
instead of write(unit_no, FMT)?
I am looking for a solution which is portable across different
compilers. It is ok if the solution is not portable across different
operating systems. But it would be nice if that is the case as well.
Dan Nagle's Fortran Portability Project
http://users.erols.com/dnagle/port.html addresses this, in particular
with the constants input_unit, output_unit and error_unit mentioned at
http://users.erols.com/dnagle/stdtype.html . Fortran 2003 has an
intrinsic module ISO_FORTRAN_ENV defining the same constants .
G95 implements this and for the program
program xiso
use ISO_FORTRAN_ENV
print*,input_unit,output_unit,error_unit
end program xiso
gives
5 6 0
On Windows XP the mingw gfortran version 4.2.0 20060531 cannot compile
the code.
.
- References:
- using the same function for stdout and files
- From: Kamaraju Kusumanchi
- using the same function for stdout and files
- Prev by Date: Re: heap allocation of arrays
- Next by Date: Re: heap allocation of arrays
- Previous by thread: Re: using the same function for stdout and files
- Next by thread: heap allocation of arrays
- Index(es):
Relevant Pages
|