f90wrap icon indicating copy to clipboard operation
f90wrap copied to clipboard

array of string

Open pogam opened this issue 4 years ago • 1 comments
trafficstars

I am using f90wrap v0.2.3 I have a problem passing array of string from fortan to python in the string example f90wrap/examples/string I changed func_return_string to

    function func_return_string() result(stringout)
        CHARACTER(51),dimension(10):: stringout
        stringout(1) = 'yy-_-::this is a string with ASCII, / and 123...::-_-'
        print*,stringout(1)
        stringout(2) = 'eerde'
        print*,stringout(2)
    end function func_return_string

in the python code when printing the outstring I got

array([b'y', b'y', b'-', b'_', b'-', b':', b':', b't', b'h', b'i'], dtype='|S1')

each element of the array is getting one letter of the first string.

pogam avatar Jan 22 '21 18:01 pogam

I'm afraid there's nothing simple to be done about this - this is what the Fortran representation of the string looks like. You can convert to a Python string with ''.join(outstring) or similar.

jameskermode avatar Feb 02 '21 09:02 jameskermode