[f2py] intent(c) forced
Tim McGreevy <[email protected]> Sun, 25 Sep 2011 17:41:19 -0500
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <CAFYj8p3q7-ELJCBZw6FKXcDFsJNB2dSEmE5qzXag_xENkGTsOw@mail.gmail.com> |
Hello,
I am attempting to use F2PY to wrap Fortran code.
I am generally successful. However, I have the following problem. Any help
would be appreciated.
I have attempted to solve on my own, and used online search tools for
examples to solve. I have been unsuccessful. I was under the impression
that numpy handles everything in the background, and I need not worry about
c vs fortran contiguous. I am doing something wrong, but what?
The issue is with the f2py compiler forcing intent(c) on character
variables. I am using numpy 1.3.0, python 2.6.5, intel fortran compiler
11.0, linxu (Ubuntu 10.04), 64 bit.
*Fortran Code: saved file as Test1.f90*
Subroutine foo(var1)
CHAR*30 var1(5,4)
!f2py intent(out) var1
code to create var1(5,4)...
do i=1,5
do j=1,4
var1(i,j)=....
end do !j
end do !i
return
end subroutine
*Compiling:*
f2py -c --fcompiler=intelem -m Test1 Test1.f90
--> forces intent(c) for var1
analyzevars: character array "character*30 x(5,4)" is considered as
"character x(5,4,30)"; "intent(c)" is forced.
*This forcing of 'intnet(c)' requires that I create var1 differently (as
var2 in example below) as follows in Fortran code:*
CHAR*30 var2(4,5)
do i=1,5
do j=1,4
var2(j,i)=....
end do !j
end do !i
*With var2 version, I can then access content of var2 in Python via the
following:*
>> var2[0,#,:] --> gives me array of 30 dtype S1 characters pertaining to
the #th C continguous data, meaning
var2[0,0,:] (Python) <==> Fortran:: var1(1,1)==var2(1,1)
var2[0,1,:] (Python) <==> Fortran:: var1(1,2)==var2(2,1)
...
var2[0,6,:] (Python) <==> Fortran:: var1(2,1)==var2(1,2)
*Questions:*
1. Can I avoid the forcing intent(c), and not have to modify my Fortran
code? Luckly, in my existing code, I have the source and can modify. In
the example above var1 / var2 are output variables. However, this requires
modifications of every character type variable and possible coding, e.g. use
of do loop variables to modify/use variable such as var2(j,i) vs var1(i,j).
2. I have been unsuccessful at the use of transpose; perhaps I have made a
simple error. Recommendations?
3. I interpret, but have not tested, that other variables that are 'input'
variables will cause greater confusion and additional effort on my part. I
am sure that this was not the intent of developers, and I am missing
something very basic and key. At first I thought that I would have to use
arr.as_row_major_storage or arr.as_column_major_storage. But they don't
exist anymore, a clue that the issue has been addressed with a better
solution. I have failed to locate the solution.
Obviously, I prefer a solution where I need not modify my existing Fortran
code at all (only the wrapper functions).
Thanks very much.
Tim
[email protected]
_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users