Re: [f2py] Character Arrays FROM Common Block

Tim-DRS <[email protected]> Fri, 7 Sep 2012 11:45:38 -0500
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
--===============8107176209738077839==
Content-Transfer-Encoding: 7bit
Content-Type: multipart/alternative;
	boundary=Apple-Mail-D8A858E9-D721-4DC0-AC93-8B024C586E7C


--Apple-Mail-D8A858E9-D721-4DC0-AC93-8B024C586E7C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

I had to write my own parser.
Don't have it handy at the moment.
I didn't write generically enough to drop immediately into your code, but it=
 was flexible.

Tim

Sent from my iPod

On Sep 6, 2012, at 2:15 PM, Kevin Manross <[email protected]> wrote:

>=20
> Greetings!
>=20
> I have been enjoying learning to use f2py as a relative novice in both Pyt=
hon and FORTRAN.
>=20
> I have been working on wrapping the NOAA NCEP BUFRLIB library <http://www.=
nco.ncep.noaa.gov/sib/decoders/BUFRLIB/> to make the I/O more user friendly,=
 to take advantage of the many efficient packages available in Python, and t=
o translate the data into other data formats (such as netCDF).
>=20
> I have been successful in wrapping the library in order to use the subrout=
ines, but to have greater flexibility I need to access the common block data=
.  I can access it, and am trying to work through the FORTRAN column-order i=
ssues between the respective arrays.  The one area that I'm really stuck on i=
s trying to extract character arrays in proper order.
>=20
> I have an example of the issue I'm running into:
>=20
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D FORTRAN File =3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
>=20
> C     FILE: CHARTEST.F
>       SUBROUTINE FOO()
> C
> C     ABSTRACT: Test character arrays when using with F2PY. Problem is in=20=

> C               FORTRAN column-order, character arrays get all messed up.=20=

> C               Hope to learn a way around this
> C
> C     INPUTS:   None
> C     OUTPUTS:  STROUT - character array
> C
> C
>       COMMON /TEST/   STROUT(20)
>       CHARACTER*3   STROUT
>=20
>       STROUT(1) =3D 'ABC'
>       STROUT(2) =3D 'DEF'
>       STROUT(3) =3D 'GHI'
>       STROUT(4) =3D 'JKL'
>       STROUT(5) =3D 'MNO'
>       STROUT(6) =3D 'PQR'
>       STROUT(7) =3D 'STU'
>       STROUT(8) =3D 'VWX'
>       STROUT(9) =3D 'YZ'
>=20
>       END
>=20
>=20
>=20
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Python Script  =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
>=20
> #!/usr/bin/env python
>=20
> import chartest
>=20
> chartest.foo()
> print chartest.test.strout
>=20
>=20
>=20
>=20
> So while I need to get the array elements back out in the order that they a=
re entered (I.e., 'ABC') the output I get is:
>=20
> % ./test_chartest.py
> [['A' 'U' '']
>  ['B' 'V' '']
>  ['C' 'W' '']
>  ['D' 'X' '']
>  ['E' 'Y' '']
>  ['F' 'Z' '']
>  ['G' ' ' '']
>  ['H' '' '']
>  ['I' '' '']
>  ['J' '' '']
>  ['K' '' '']
>  ['L' '' '']
>  ['M' '' '']
>  ['N' '' '']
>  ['O' '' '']
>  ['P' '' '']
>  ['Q' '' '']
>  ['R' '' '']
>  ['S' '' '']
>  ['T' '' '']]
>=20
> I've been playing with Numpy's myriad of array manipulation, but with no s=
uccess thus far.
>=20
> Is there a "built-in" way around this reordering of character arrays, or w=
ill I need to create my own parser for this?
>=20
> Many thanks for any input!
>=20
> -kevin.
>=20
>=20
> --=20
> Kevin Manross
> NCAR/CISL/Data Support Section
> Phone: (303)-497-1218
> Email:[email protected]
> Web:http://dss.ucar.edu
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users

--Apple-Mail-D8A858E9-D721-4DC0-AC93-8B024C586E7C
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
	charset=utf-8

<html><head></head><body bgcolor="#FFFFFF"><div>I had to write my own parser.</div><div>Don't have it handy at the moment.</div><div>I didn't write generically enough to drop immediately into your code, but it was flexible.</div><div><br></div><div>Tim<br><br>Sent from my iPod</div><div><br>On Sep 6, 2012, at 2:15 PM, Kevin Manross &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite"><div>
  

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  
  
    <br>
    Greetings!<br>
    <br>
    I have been enjoying learning to use f2py as a relative novice in
    both Python and FORTRAN.<br>
    <br>
    I have been working on wrapping the NOAA NCEP BUFRLIB library
    <a class="moz-txt-link-rfc2396E" href="http://www.nco.ncep.noaa.gov/sib/decoders/BUFRLIB/">&lt;http://www.nco.ncep.noaa.gov/sib/decoders/BUFRLIB/&gt;</a> to make
    the I/O more user friendly, to take advantage of the many efficient
    packages available in Python, and to translate the data into other
    data formats (such as netCDF).<br>
    <br>
    I have been successful in wrapping the library in order to use the
    subroutines, but to have greater flexibility I need to access the
    common block data.&nbsp; I can access it, and am trying to work through
    the FORTRAN column-order issues between the respective arrays.&nbsp; The
    one area that I'm really stuck on is trying to extract character
    arrays in proper order.<br>
    <br>
    I have an example of the issue I'm running into:<br>
    <br>
    ============= FORTRAN File ===============<br>
    <br>
    C&nbsp;&nbsp;&nbsp;&nbsp; FILE: CHARTEST.F<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUBROUTINE FOO()<br>
    C<br>
    C&nbsp;&nbsp;&nbsp;&nbsp; ABSTRACT: Test character arrays when using with F2PY. Problem
    is in <br>
    C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORTRAN column-order, character arrays get all
    messed up. <br>
    C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hope to learn a way around this<br>
    C<br>
    C&nbsp;&nbsp;&nbsp;&nbsp; INPUTS:&nbsp;&nbsp; None<br>
    C&nbsp;&nbsp;&nbsp;&nbsp; OUTPUTS:&nbsp; STROUT - character array<br>
    C<br>
    C<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMON /TEST/&nbsp;&nbsp; STROUT(20)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CHARACTER*3&nbsp;&nbsp; STROUT<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(1) = 'ABC'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(2) = 'DEF'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(3) = 'GHI'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(4) = 'JKL'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(5) = 'MNO'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(6) = 'PQR'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(7) = 'STU'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(8) = 'VWX'<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STROUT(9) = 'YZ'<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END<br>
    <br>
    <br>
    <br>
    ========== Python Script&nbsp; =================<br>
    <br>
    #!/usr/bin/env python<br>
    <br>
    import chartest<br>
    <br>
    chartest.foo()<br>
    print chartest.test.strout<br>
    <br>
    <br>
    <br>
    <br>
    So while I need to get the array elements back out in the order that
    they are entered (I.e., 'ABC') the output I get is:<br>
    <br>
    % ./test_chartest.py<br>
    [['A' 'U' '']<br>
    &nbsp;['B' 'V' '']<br>
    &nbsp;['C' 'W' '']<br>
    &nbsp;['D' 'X' '']<br>
    &nbsp;['E' 'Y' '']<br>
    &nbsp;['F' 'Z' '']<br>
    &nbsp;['G' ' ' '']<br>
    &nbsp;['H' '' '']<br>
    &nbsp;['I' '' '']<br>
    &nbsp;['J' '' '']<br>
    &nbsp;['K' '' '']<br>
    &nbsp;['L' '' '']<br>
    &nbsp;['M' '' '']<br>
    &nbsp;['N' '' '']<br>
    &nbsp;['O' '' '']<br>
    &nbsp;['P' '' '']<br>
    &nbsp;['Q' '' '']<br>
    &nbsp;['R' '' '']<br>
    &nbsp;['S' '' '']<br>
    &nbsp;['T' '' '']]<br>
    <br>
    I've been playing with Numpy's myriad of array manipulation, but
    with no success thus far.<br>
    <br>
    Is there a "built-in" way around this reordering of character
    arrays, or will I need to create my own parser for this?<br>
    <br>
    Many thanks for any input!<br>
    <br>
    -kevin.<br>
    <br>
    <br>
    <div class="moz-signature">-- <br>
      Kevin Manross<br>
      NCAR/CISL/Data Support Section<br>
      Phone: (303)-497-1218<br>
      Email:<a href="mailto:[email protected]">[email protected]</a><br>
      Web:<a href="http://dss.ucar.edu">http://dss.ucar.edu</a><br>
    </div>
  

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>f2py-users mailing list</span><br><span><a href="mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</a></span><br><span><a href="http://cens.ioc.ee/mailman/listinfo/f2py-users">http://cens.ioc.ee/mailman/listinfo/f2py-users</a></span><br></div></blockquote></body></html>
--Apple-Mail-D8A858E9-D721-4DC0-AC93-8B024C586E7C--


--===============8107176209738077839==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users

--===============8107176209738077839==--