J
john
I have a simple module which performs basic operations on plot3d files
(below). I wrapped like:
f2py --fcompiler=gfortran -m plot3d -c prec.f90 plot3d.f90
That seems to work fine, but i get some unexpected results...
['imax', 'jmax', 'kmax', 'mg', 'prc', 'printall', 'readit', 'writeit',
'writeit2d']array(409)
"409" is correct, but "imax" is declared as an INTEGER in fortran and
now it's an array in python??? Any ideas?
# prec.f90
MODULE prec
IMPLICIT NONE
INTEGER, PARAMETER :: single = SELECTED_REAL_KIND(p=6,r=37)
INTEGER, PARAMETER :: double = SELECTED_REAL_KIND(p=15,r=200)
END MODULE prec
# plot3d.f90
MODULE PLOT3D
USE prec
IMPLICIT NONE
INTEGER, PARAMETER :: prc=single
REAL(prc), ALLOCATABLE, DIMENSION,:,:, :: x, y, z
INTEGER :: mg, imax, jmax, kmax
CONTAINS
!----------
SUBROUTINE READIT( fname, ftype, fmg )
! reads the plot3d, formatted, mg file in xyz
IMPLICIT NONE
CHARACTER(len=20), INTENT(IN) :: fname, ftype
LOGICAL :: fmg
INTEGER :: i, j, k, n, f=1
SELECT CASE (ftype)
CASE ('FORMATTED')
OPEN( UNIT=f, FILE=fname, STATUS='OLD', ACTION='READ',
FORM=ftype )
IF (fmg) READ(f,*) mg ! only read if multigrid
READ(f,*) imax, jmax, kmax
ALLOCATE( x(mg, imax, jmax, kmax) )
ALLOCATE( y(mg, imax, jmax, kmax) )
ALLOCATE( z(mg, imax, jmax, kmax) )
READ(f,*) ((((x(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((y(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((z(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg)
CASE ('UNFORMATTED')
OPEN( UNIT=f, FILE=fname, STATUS='OLD', ACTION='READ',
FORM=ftype )
IF (fmg) READ(f) mg ! only read if multigrid
READ(f) imax, jmax, kmax
ALLOCATE( x(mg, imax, jmax, kmax) )
ALLOCATE( y(mg, imax, jmax, kmax) )
ALLOCATE( z(mg, imax, jmax, kmax) )
READ(f) ((((x(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((y(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((z(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg)
CASE DEFAULT
WRITE(*,*) 'filetype not supported in <PLOT3D.READIT>'
STOP
END SELECT
CLOSE(f)
END SUBROUTINE READIT
END MODULE PLOT3D
(below). I wrapped like:
f2py --fcompiler=gfortran -m plot3d -c prec.f90 plot3d.f90
That seems to work fine, but i get some unexpected results...
['imax', 'jmax', 'kmax', 'mg', 'prc', 'printall', 'readit', 'writeit',
'writeit2d']array(409)
"409" is correct, but "imax" is declared as an INTEGER in fortran and
now it's an array in python??? Any ideas?
# prec.f90
MODULE prec
IMPLICIT NONE
INTEGER, PARAMETER :: single = SELECTED_REAL_KIND(p=6,r=37)
INTEGER, PARAMETER :: double = SELECTED_REAL_KIND(p=15,r=200)
END MODULE prec
# plot3d.f90
MODULE PLOT3D
USE prec
IMPLICIT NONE
INTEGER, PARAMETER :: prc=single
REAL(prc), ALLOCATABLE, DIMENSION,:,:, :: x, y, z
INTEGER :: mg, imax, jmax, kmax
CONTAINS
!----------
SUBROUTINE READIT( fname, ftype, fmg )
! reads the plot3d, formatted, mg file in xyz
IMPLICIT NONE
CHARACTER(len=20), INTENT(IN) :: fname, ftype
LOGICAL :: fmg
INTEGER :: i, j, k, n, f=1
SELECT CASE (ftype)
CASE ('FORMATTED')
OPEN( UNIT=f, FILE=fname, STATUS='OLD', ACTION='READ',
FORM=ftype )
IF (fmg) READ(f,*) mg ! only read if multigrid
READ(f,*) imax, jmax, kmax
ALLOCATE( x(mg, imax, jmax, kmax) )
ALLOCATE( y(mg, imax, jmax, kmax) )
ALLOCATE( z(mg, imax, jmax, kmax) )
READ(f,*) ((((x(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((y(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((z(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg)
CASE ('UNFORMATTED')
OPEN( UNIT=f, FILE=fname, STATUS='OLD', ACTION='READ',
FORM=ftype )
IF (fmg) READ(f) mg ! only read if multigrid
READ(f) imax, jmax, kmax
ALLOCATE( x(mg, imax, jmax, kmax) )
ALLOCATE( y(mg, imax, jmax, kmax) )
ALLOCATE( z(mg, imax, jmax, kmax) )
READ(f) ((((x(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((y(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg), &
((((z(n,
i,j,k),i=1,imax),j=1,jmax),k=1,kmax),n=1,mg)
CASE DEFAULT
WRITE(*,*) 'filetype not supported in <PLOT3D.READIT>'
STOP
END SELECT
CLOSE(f)
END SUBROUTINE READIT
END MODULE PLOT3D