Re: [f2py] Wrapping MODFLOW 2005 source code using F2PY

Pearu Peterson <[email protected]> Mon, 22 Aug 2011 10:31:14 +0300
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Hi Alvin,

On 08/21/2011 02:05 PM, Alvin wrote:
> Dear all,
>
> Is there anyone who has wrapped MODFLOW 2005 source code using F2PY?
> The source code is available at the link below:
>
> http://water.usgs.gov/nrp/gwsoftware/modflow2005/mf2005v1_8_00.tar.Z
>
> I tried wrapping but the some files accept some give error messages.

The "problem" with MODFLOW is that its source files are in Fortran 90 
fixed format and the source files extension is .f. By default, for f2py
all .f files are assumed to be Fortran 77 source files.
So, to wrap MODFLOW with f2py, you need to teach f2py that the
source files are actually in Fortran 90 fix format.

One way to do it is to insert the following comment line

! -*- fix -*-

to the header of each .f file. You can write a script that copies all 
src/*.f files to, say, src2/ directory and at the same time inserts the 
comment lines above. And the apply f2py to src2/*.f.

In case Fortran codes use C functions, then you have to compile the
C files and provide .o files to `f2py -c` as additional arguments.

HTH,
Pearu