Fortran print called from C prog. goes to file fort.6 . Why?
Mike Hummell
mike at lll-lcc.aRpA
Sat Mar 12 12:39:26 AEST 1988
Mike Lipsie gave us the solution to our problem (thru. email). Many thanks!
Here is his response (solution), followed by an example showing it works.
=========================================================================
From: pyramid!mikel at Sun.COM (Mike Lipsie)
In article <1540 at lll-lcc.aRpA> [Mike Hummell] writes:
>When we call a fortran subroutine from a C program, the fortran print
>statement ends up in file "fort.6" instead of on the terminal, whereas
>the same fortran print stmt. will go to the terminal when called from a
>Fortran program and compiled/loaded with F77. How can we get the fortran
>print to go to the terminal (called from the C program). The example is:
> [ example deleted ]
>REMARK: The output, " fortran subroutine ", is in file "fort.6" .
>QUESTION: Why doesn't it come out to the standard output device (terminal?)
Whenever any Fortran program starts up (not just Pyramid) there is some
initialization code that is executed before the user code. In particular
the I/O routines and tables are set up. If you were to write (or print)
to unit 99, it would go into fort.99, so it looks like unit 6 was not
initialized to point to the terminal.
The easiest way around the problem is to have a Fortran main that consists
*only* of a call to the c main (although you might want to do other things
too). Then the Fortran initialization would occur (btw, all the c
initialization would happen, Fortran is a superset).
This is a general problem. The only Pyramid specific thing is that the
c initialization would occur.
Good luck.
Mike Lipsie {allegra,cmcl2,decwrl,hplabs,ut-sally,utzoo}!pyramid!mikel
Pyramid Technology Corp, Mountain View, CA +1 415 965 7200 ext. 4980
=========================================================================
Now, here's example showing that Mike Lipsie's solution works:
>>type fmainf.f
program fmain
call cmain
stop
end
>>type prog1.c
cmain_() /* test calling fortran subroutine from C program */
/* Note that we appended an UNDERLINE after "cmain"
since it's called by a fortran program" */
{
printf("begin c program\n");
sub1_(); /* Need to add "_" after fortran subroutine name */
printf("end c program\n");
}
>>type sub1.f
subroutine sub1
print 1000
1000 format(' fortran subroutine ')
return
end
>>f77 -c sub1.f
>>cc -c prog1.c
>>f77 fmain.f prog1.o sub1.o
>>a.out
begin c program
fortran subroutine
end c program
--------------------------------------------------------------------------
"Si Vis Pacem, Para Bellum" -- Vegetius
--------------------------------------------------------------------------
ARPA: mike at lll-lcc.llnl.gov (mike at lll-lcc.arpa)
UUCP: { ihnp4,sun,lll-crg,rutgers }!lll-lcc!mike
U.S. MAIL: LLNL ; P.O. Box 808 , L-363 ; Livermore, CA. 94550
--------------------------------------------------------------------------
More information about the Comp.sys.pyramid
mailing list