10000 f2py - f90-style character array definition with character(len=n) fails · Issue #18684 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

f2py - f90-style character array definition with character(len=n) fails #18684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2sn opened this issue Mar 28, 2021 · 1 comment · Fixed by #19388
Closed

f2py - f90-style character array definition with character(len=n) fails #18684

2sn opened this issue Mar 28, 2021 · 1 comment · Fixed by #19388
Assignees

Comments

@2sn
Copy link
Contributor
2sn commented Mar 28, 2021

this is for f2py (version 1.20.2)

when use f90-style

character(len=n), dimension(m) :: variable

definition it fails (creates single byte string of length m (dim=(), dtype='|Sm')) whereas when I use F77-style length specification

character*n, dimension(m) :: variable

it correctly produces an array dim=(m,), dtype = '|Sn'.

I am hoping that crackfortran could be relatively(?) easily adjusted to add a regexp to also accept the f90-style character length specification? For context (see example below), I use a *.f code file (f77 format) for the code layout, but the same Fortran code should be allowable either way, whether using .f or .f90. (I have not tested whether this already works in an .f90 file.)

Or maybe I am just overlooking something?

Reproducing code example:

To give an real-world example, I have the snippets

integer(kind=int32), parameter :: ndtz  = 30
      character(len=8), dimension(ndtz) ::
     &     idtcsym
      common/charsave/
     &     idtcsym

and then after compilation

In [4]: k._kepler.charsave.idtcsym
Out[4]: array(b'dtr     dtt     dtd     dtq   ', dtype='|S30')

whereas

      character*8, dimension(ndtz) ::
     &     idtcsym
      common/charsave/
     &     idtcsym

as, as it should lines in the output of compilation

analyzevars: charselector={'len': '8'} unhandled.analyzevars: charselector={'len': '8'} unhandled.analyzevars: character array "character*8 idtcsym(30)" is considered as "character idtcsym(30,8)"; "intent(c)" is forced.

and resulting in

In [3]: k._kepler.charsave.idtcsym
Out[3]: 
array([b'dtr     ', b'dtt     ', b'dtd     ', b'dtq     ', b'dti     ',
       b'dtl     ', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'',
       b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b''],
      dtype='|S8')

as it should be.

Error message:

N/A

NumPy/Python version information:

In [1]: import sys, numpy; print(numpy.__version__, sys.version)
1.20.2 3.9.2 (default, Feb 20 2021, 13:24:34) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
@2sn
Copy link
Contributor Author
2sn commented Jun 3, 2021

I have some f90 codes I wrap with f2py and in these using character(len=n) does not seem to cause issues.

pearu added a commit to pearu/numpy that referenced this issue Jul 2, 2021
@pearu pearu self-assigned this Jul 3, 2021
pearu added a commit to pearu/numpy that referenced this issue Sep 1, 2021
pearu added a commit to pearu/numpy that referenced this issue Sep 6, 2021
TST: added test for issue numpy#18684

ENH: f2py opens files with correct encoding, fixes numpy#635

TST: added test for issue numpy#6308

TST: added test for issue numpy#4519

TST: added test for issue numpy#3425

ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook.

ENH: Add support for detecting utf-16 and utf-32 encodings.
melissawm pushed a commit to pearu/numpy that referenced this issue Apr 4, 2022
TST: added test for issue numpy#18684

ENH: f2py opens files with correct encoding, fixes numpy#635

TST: added test for issue numpy#6308

TST: added test for issue numpy#4519

TST: added test for issue numpy#3425

ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook.

ENH: Add support for detecting utf-16 and utf-32 encodings.
HaoZeke pushed a commit to pearu/numpy that referenced this issue Jun 5, 2022
TST: added test for issue numpy#18684

ENH: f2py opens files with correct encoding, fixes numpy#635

TST: added test for issue numpy#6308

TST: added test for issue numpy#4519

TST: added test for issue numpy#3425

ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook.

ENH: Add support for detecting utf-16 and utf-32 encodings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0