[SciPy-dev] Re: scipy / SGI MIPSpro compiler (part 3)
Pearu
pearu at scipy.org
Mon Aug 26 08:57:32 CDT 2002
On Mon, 26 Aug 2002, Steve M. Robbins wrote:
> > bash$ cc -version
> > MIPSpro Compilers: Version 7.30
> > bash$ f77 -version
> > MIPSpro Compilers: Version 7.30
> > bash$
>
> ditto, except scipy used GNU fortran:
>
> swmgr at wart{f77}g77 --version
> GNU Fortran (GCC 3.2) 3.2 20020814 (release)
Is there any reason why do you want use g77 and not the native f77?
Mixing compilers is like walking on a thin ice.
> However, there is an interesting note in the section on interoperating
> with C/C++
>
>
http://gcc.gnu.org/onlinedocs/gcc-3.2/g77/Interoperating-with-C-and-C--.html
>
> A simple and foolproof way to write g77-callable C
> routines--e.g. to interface with an existing library--is to write
> a file (named, for example, fred.f) of dummy Fortran skeletons
> comprising just the declaration of the routine(s) and dummy
> arguments plus END statements. Then run f2c on file fred.f to
> produce fred.c into which you can edit useful code, confident the
> calling sequence is correct, at least. (There are some errors
> otherwise commonly made in generating C interfaces with f2c
> conventions, such as not using doublereal as the return type of a
> REAL FUNCTION.)
I find the last note in parenthesis very interesting and may explain why
I don't get these errors while using f77.
> I ran "f2c -P" to find the C prototype, and it came back as
>
> extern E_f quibit_(real *x);
>
> Maybe that's a clue?
I think it is a good clue as E_f is defined in f2c.h as
typedef double doublereal;
typedef doublereal E_f;
Could you try out the following scripts:
#--------------- test.py
import f2py2e
import sys
f2py_opts = ' -Df_func=F_FUNC '+' '.join(sys.argv[1:])
f2py2e.compile('''
function t0(value)
real value
cf2py real*8 t0
real t0
cf2py fortranname F_FUNC(t0,T0)
cf2py intent(c) t0
cf2py callstatement t0_return_value = (float)(*f2py_func)(&value)
cf2py callprotoargument float*
t0 = value
end
''','t1',f2py_opts,source_fn='t1.f')
import t1
print t1.t0(9)
#---------------
and then
#------------- test2.py
import f2py2e
import sys
f2py_opts = ' -Df_func=F_FUNC '+' '.join(sys.argv[1:])
f2py2e.compile('''
function t0(value)
real value
real t0
cf2py fortranname F_FUNC(t0,T0)
cf2py intent(c) t0
cf2py callstatement t0_return_value = (*f2py_func)(&value)
cf2py callprotoargument float*
t0 = value
end
''','t2',f2py_opts,source_fn='t2.f')
import t2
print t2.t0(9)
#-------------
I hope that the first one prints `9' and the second one prints some
nonsense.
Pearu
More information about the Scipy-dev
mailing list