Re: using the same function for stdout and files



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.

.



Relevant Pages

  • Re: A Question about arrays file merging
    ... > I do have some programing experience-mostly working ... and in both cases load the output into an array? ... format you can use either language's I/O facilities [e.g. 'fopen', ... then I understand the portability concern. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)
  • VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)
  • Re: memory leak help!
    ... a loop from the main program. ... REPLACE THE NEW COMPLEX INTO ORIGINAL ARRAY x ... END OF SUBROUTINE SCEUA ... IMPLICIT NONE ...
    (comp.lang.fortran)