Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Some questions, maybe naive ones

Received: by 10.42.25.147 with SMTP id a19mr3191283icc.20.1348812565239;
        Thu, 27 Sep 2012 23:09:25 -0700 (PDT)
X-BeenThere: cython-users@googlegroups.com
Received: by 10.50.157.164 with SMTP id wn4ls405967igb.0.canary; Thu, 27 Sep
 2012 23:09:23 -0700 (PDT)
Received: by 10.50.216.193 with SMTP id os1mr541020igc.4.1348812563962;
        Thu, 27 Sep 2012 23:09:23 -0700 (PDT)
Received: by 10.50.57.13 with SMTP id e13msigq;
        Thu, 27 Sep 2012 21:39:30 -0700 (PDT)
Received: by 10.68.238.201 with SMTP id vm9mr1931002pbc.6.1348807170288;
        Thu, 27 Sep 2012 21:39:30 -0700 (PDT)
Date: Thu, 27 Sep 2012 21:39:29 -0700 (PDT)
From: JBT <jianbao....@gmail.com>
To: cython-users@googlegroups.com
Message-Id: <e68fcb7f-075f-4bfb-acab-c7d1b704ee92@googlegroups.com>
Subject: Some questions, maybe naive ones
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_275_2355490.1348807169772"

------=_Part_275_2355490.1348807169772
Content-Type: multipart/alternative; 
	boundary="----=_Part_276_28048796.1348807169772"

------=_Part_276_28048796.1348807169772
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi,

I am new to cython. I am currently trying to make a python wrapper to use 
NASA CDF library. This is currently for practicing purposes, but hopefully 
it will eventually work out and turn into something useful.

Anyway, for now I am trying to translate the following c codes to cython 
codes.
------------------------ below is from cdf.h 
------------------------------------------------
typedef void *CDFid;
typedef long CDFstatus;

static double *TT2000NULL = 0;

#define HOST_ENCODING           8L
#define ROW_MAJOR       1L
#define SINGLE_FILE     1L


----------------------------- below is from an example, say, example.c 
-----------------------
CDFid       test_id;                    /* CDF identifier (handle). */
CDFstatus   status;                     /* Status returned from CDF 
library. */
static char CDFname[] = {"test1"};      /* File name of the CDF. */
long        numDims = 2;                /* Number of dimensions. */
static long dimSizes[2] = {100,200};    /* Dimension sizes. */
long        encoding = HOST_ENCODING;   /* Data encoding. */
long        majority = ROW_MAJOR;       /* Variable data majority. */
long        form = SINGLE_FILE;         /* Format of CDF. */


Below is my translation.
------------------------------ below is from nasacdf.pxd 
----------------------------
cdef extern from "cdf34_1-dist/include/cdf.h":
    ctypedef void *CDFid;
    ctypedef long CDFstatus;
    static double *TT2000NULL = 0;
    enum:
        HOST_ENCODING = 8;
        ROW_MAJOR     = 1;
        SINGLE_FILE   = 1;

-------------------------------below is from test.pyx 
------------------------------
cimport nasacdf

def hello():
    cdef CDFid       test_id
    cdef CDFstatus   status
 #  cdef char        CDFname[] = {"test1"}
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
    cdef long        majority = ROW_MAJOR
    cdef long        form = SINGLE_FILE

    print CDFname

----------------------------- below is my setup.py ---------------------
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

cdfdist = 'cdf34_1-dist/'
modules = Extension("cdf",
    sources = ['test.pyx'],
    libraries = [cdfdist + 'lib/libcdf.a'],
    extra_compile_args = ['-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE64_SOURCE',
                         '-D_LARGEFILE_SOURCE'])

setup(name = 'pyNASACDF',
      version = '0.1.0',
      cmdclass = {'build_ext':build_ext},
      ext_modules = [modules]
     )

---------------------------------------- end of code 
--------------------------------------
 I modified the CDFname declaration and commented out dimSizes declaration 
because the compiler issued errors on them. After I run:
python setup.py build_ext --inplace
I got errors. I attached the error message below. Can anyone tell me what 
is wrong with my translation, please? Thank you very much. 

>$ python setup.py build_ext --inplace
running build_ext
cythoning test.pyx to test.c

Error compiling Cython file:
------------------------------------------------------------
...
# File: nasacdf.pxd

cdef extern from "cdf34_1-dist/include/cdf.h":
    ctypedef void *CDFid;
                       ^
------------------------------------------------------------

nasacdf.pxd:4:24: Syntax error in ctypedef statement

Error compiling Cython file:
------------------------------------------------------------
...
# File test.pyx

cimport nasacdf

def hello():
    cdef CDFid       test_id
        ^
------------------------------------------------------------

test.pyx:6:9: 'CDFid' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...

cimport nasacdf

def hello():
    cdef CDFid       test_id
    cdef CDFstatus   status
        ^
------------------------------------------------------------

test.pyx:7:9: 'CDFstatus' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    cdef CDFstatus   status
 #  cdef char        CDFname[] = {"test1"}
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
                                            ^
------------------------------------------------------------

test.pyx:12:45: undeclared name not builtin: HOST_ENCODING

Error compiling Cython file:
------------------------------------------------------------
...
 #  cdef char        CDFname[] = {"test1"}
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
    cdef long        majority = ROW_MAJOR
                                        ^
------------------------------------------------------------

test.pyx:13:41: undeclared name not builtin: ROW_MAJOR

Error compiling Cython file:
------------------------------------------------------------
...
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
    cdef long        majority = ROW_MAJOR
    cdef long        form = SINGLE_FILE
                                      ^
------------------------------------------------------------

test.pyx:14:39: undeclared name not builtin: SINGLE_FILE
building 'cdf' extension
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common 
-fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX 
-DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall 
-Wstrict-prototypes -DENABLE_DTRACE -pipe -arch i386 -arch x86_64 
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 
-c test.c -o build/temp.macosx-10.8-intel-2.7/test.o -D_FILE_OFFSET_BITS=64 
-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE
clang: warning: argument unused during compilation: '-mno-fused-madd'
test.c:1:2: error: Do not use this file, it is the result of a failed 
Cython compilation.
#error Do not use this file, it is the result of a failed Cython 
compilation.
 ^
1 error generated.
error: command 'clang' failed with exit status 1



------=_Part_276_28048796.1348807169772
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,<div><br></div><div>I am new to cython. I am currently trying to make a =
python wrapper to use NASA CDF library. This is currently for practicing pu=
rposes, but hopefully it will eventually work out and turn into something u=
seful.</div><div><br></div><div>Anyway, for now I am trying to translate th=
e following c codes to cython codes.</div><div>------------------------ bel=
ow is from cdf.h ------------------------------------------------</div><div=
><div>typedef void *CDFid;</div><div>typedef long CDFstatus;</div><div><br>=
</div><div>static double *TT2000NULL =3D 0;</div><div><br></div><div>#defin=
e HOST_ENCODING &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8L</div><div>#define ROW=
_MAJOR &nbsp; &nbsp; &nbsp; 1L</div><div>#define SINGLE_FILE &nbsp; &nbsp; =
1L</div></div><div><br></div><div><br></div><div>--------------------------=
--- below is from an example, say, example.c -----------------------</div><=
div><div>CDFid &nbsp; &nbsp; &nbsp; test_id; &nbsp; &nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* CDF identifier (handle). */</div>=
<div>CDFstatus &nbsp; status; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; /* Status returned from CDF library. */</div><div>=
static char CDFname[] =3D {"test1"}; &nbsp; &nbsp; &nbsp;/* File name of th=
e CDF. */</div><div>long &nbsp; &nbsp; &nbsp; &nbsp;numDims =3D 2; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Number of dimensions. */<=
/div><div>static long dimSizes[2] =3D {100,200}; &nbsp; &nbsp;/* Dimension =
sizes. */</div><div>long &nbsp; &nbsp; &nbsp; &nbsp;encoding =3D HOST_ENCOD=
ING; &nbsp; /* Data encoding. */</div><div>long &nbsp; &nbsp; &nbsp; &nbsp;=
majority =3D ROW_MAJOR; &nbsp; &nbsp; &nbsp; /* Variable data majority. */<=
/div><div>long &nbsp; &nbsp; &nbsp; &nbsp;form =3D SINGLE_FILE; &nbsp; &nbs=
p; &nbsp; &nbsp; /* Format of CDF. */</div><div><br></div></div><div><br></=
div><div>Below is my translation.</div><div>------------------------------ =
below is from nasacdf.pxd ----------------------------</div><div><div>cdef =
extern from "cdf34_1-dist/include/cdf.h":</div><div>&nbsp; &nbsp; ctypedef =
void *CDFid;</div><div>&nbsp; &nbsp; ctypedef long CDFstatus;</div><div>&nb=
sp; &nbsp; static double *TT2000NULL =3D 0;</div><div>&nbsp; &nbsp; enum:</=
div><div>&nbsp; &nbsp; &nbsp; &nbsp; HOST_ENCODING =3D 8;</div><div>&nbsp; =
&nbsp; &nbsp; &nbsp; ROW_MAJOR &nbsp; &nbsp; =3D 1;</div><div>&nbsp; &nbsp;=
 &nbsp; &nbsp; SINGLE_FILE &nbsp; =3D 1;</div></div><div><br></div><div>---=
----------------------------below is from test.pyx ------------------------=
------</div><div><div>cimport nasacdf</div><div><br></div><div>def hello():=
</div><div>&nbsp; &nbsp; cdef CDFid &nbsp; &nbsp; &nbsp; test_id</div><div>=
&nbsp; &nbsp; cdef CDFstatus &nbsp; status</div><div>&nbsp;# &nbsp;cdef cha=
r &nbsp; &nbsp; &nbsp; &nbsp;CDFname[] =3D {"test1"}</div><div>&nbsp; &nbsp=
; cdef char &nbsp; &nbsp; &nbsp; &nbsp;*CDFname =3D "test1"</div><div>&nbsp=
; &nbsp; cdef long &nbsp; &nbsp; &nbsp; &nbsp;numDims =3D 2</div><div>&nbsp=
;# &nbsp;cdef static long dimSizes[2] =3D {100,200}</div><div>&nbsp; &nbsp;=
 cdef long &nbsp; &nbsp; &nbsp; &nbsp;encoding =3D HOST_ENCODING</div><div>=
&nbsp; &nbsp; cdef long &nbsp; &nbsp; &nbsp; &nbsp;majority =3D ROW_MAJOR</=
div><div>&nbsp; &nbsp; cdef long &nbsp; &nbsp; &nbsp; &nbsp;form =3D SINGLE=
_FILE</div><div><br></div><div>&nbsp; &nbsp; print CDFname</div></div><div>=
<br></div><div>----------------------------- below is my setup.py ---------=
------------</div><div><div>from distutils.core import setup</div><div>from=
 distutils.extension import Extension</div><div>from Cython.Distutils impor=
t build_ext</div><div><br></div><div>cdfdist =3D 'cdf34_1-dist/'<br></div><=
div>modules =3D Extension("cdf",</div><div>&nbsp; &nbsp; sources =3D ['test=
.pyx'],</div><div>&nbsp; &nbsp; libraries =3D [cdfdist + 'lib/libcdf.a'],</=
div><div>&nbsp; &nbsp; extra_compile_args =3D ['-D_FILE_OFFSET_BITS=3D64', =
'-D_LARGEFILE64_SOURCE',</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'-D_LARGEFILE_SOURCE'])</=
div><div><br></div><div>setup(name =3D 'pyNASACDF',</div><div>&nbsp; &nbsp;=
 &nbsp; version =3D '0.1.0',</div><div>&nbsp; &nbsp; &nbsp; cmdclass =3D {'=
build_ext':build_ext},<br></div><div>&nbsp; &nbsp; &nbsp; ext_modules =3D [=
modules]</div><div>&nbsp; &nbsp; &nbsp;)</div></div><div><br></div><div>---=
------------------------------------- end of code -------------------------=
-------------</div><div>&nbsp;I modified the CDFname declaration and commen=
ted out dimSizes declaration because the compiler issued errors on them. Af=
ter I run:</div><div>python setup.py build_ext --inplace</div><div>I got er=
rors. I attached the error message below. Can anyone tell me what is wrong =
with my translation, please? Thank you very much.&nbsp;</div><div><div><br>=
</div><div>&gt;$ python setup.py build_ext --inplace</div><div>running buil=
d_ext</div><div>cythoning test.pyx to test.c</div><div><br></div><div>Error=
 compiling Cython file:</div><div>-----------------------------------------=
-------------------</div><div>...</div><div># File: nasacdf.pxd</div><div><=
br></div><div>cdef extern from "cdf34_1-dist/include/cdf.h":</div><div>&nbs=
p; &nbsp; ctypedef void *CDFid;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^</div><div>-------------=
-----------------------------------------------</div><div><br></div><div>na=
sacdf.pxd:4:24: Syntax error in ctypedef statement</div><div><br></div><div=
>Error compiling Cython file:</div><div>-----------------------------------=
-------------------------</div><div>...</div><div># File test.pyx</div><div=
><br></div><div>cimport nasacdf</div><div><br></div><div>def hello():</div>=
<div>&nbsp; &nbsp; cdef CDFid &nbsp; &nbsp; &nbsp; test_id</div><div>&nbsp;=
 &nbsp; &nbsp; &nbsp; ^</div><div>-----------------------------------------=
-------------------</div><div><br></div><div>test.pyx:6:9: 'CDFid' is not a=
 type identifier</div><div><br></div><div>Error compiling Cython file:</div=
><div>------------------------------------------------------------</div><di=
v>...</div><div><br></div><div>cimport nasacdf</div><div><br></div><div>def=
 hello():</div><div>&nbsp; &nbsp; cdef CDFid &nbsp; &nbsp; &nbsp; test_id</=
div><div>&nbsp; &nbsp; cdef CDFstatus &nbsp; status</div><div>&nbsp; &nbsp;=
 &nbsp; &nbsp; ^</div><div>------------------------------------------------=
------------</div><div><br></div><div>test.pyx:7:9: 'CDFstatus' is not a ty=
pe identifier</div><div><br></div><div>Error compiling Cython file:</div><d=
iv>------------------------------------------------------------</div><div>.=
..</div><div>&nbsp; &nbsp; cdef CDFstatus &nbsp; status</div><div>&nbsp;# &=
nbsp;cdef char &nbsp; &nbsp; &nbsp; &nbsp;CDFname[] =3D {"test1"}</div><div=
>&nbsp; &nbsp; cdef char &nbsp; &nbsp; &nbsp; &nbsp;*CDFname =3D "test1"</d=
iv><div>&nbsp; &nbsp; cdef long &nbsp; &nbsp; &nbsp; &nbsp;numDims =3D 2</d=
iv><div>&nbsp;# &nbsp;cdef static long dimSizes[2] =3D {100,200}</div><div>=
&nbsp; &nbsp; cdef long &nbsp; &nbsp; &nbsp; &nbsp;encoding =3D HOST_ENCODI=
NG</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbs=
p; &nbsp; &nbsp; ^</div><div>----------------------------------------------=
--------------</div><div><br></div><div>test.pyx:12:45: undeclared name not=
 builtin: HOST_ENCODING</div><div><br></div><div>Error compiling Cython fil=
e:</div><div>------------------------------------------------------------</=
div><div>...</div><div>&nbsp;# &nbsp;cdef char &nbsp; &nbsp; &nbsp; &nbsp;C=
DFname[] =3D {"test1"}</div><div>&nbsp; &nbsp; cdef char &nbsp; &nbsp; &nbs=
p; &nbsp;*CDFname =3D "test1"</div><div>&nbsp; &nbsp; cdef long &nbsp; &nbs=
p; &nbsp; &nbsp;numDims =3D 2</div><div>&nbsp;# &nbsp;cdef static long dimS=
izes[2] =3D {100,200}</div><div>&nbsp; &nbsp; cdef long &nbsp; &nbsp; &nbsp=
; &nbsp;encoding =3D HOST_ENCODING</div><div>&nbsp; &nbsp; cdef long &nbsp;=
 &nbsp; &nbsp; &nbsp;majority =3D ROW_MAJOR</div><div>&nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</div><div>-------------------=
-----------------------------------------</div><div><br></div><div>test.pyx=
:13:41: undeclared name not builtin: ROW_MAJOR</div><div><br></div><div>Err=
or compiling Cython file:</div><div>---------------------------------------=
---------------------</div><div>...</div><div>&nbsp; &nbsp; cdef char &nbsp=
; &nbsp; &nbsp; &nbsp;*CDFname =3D "test1"</div><div>&nbsp; &nbsp; cdef lon=
g &nbsp; &nbsp; &nbsp; &nbsp;numDims =3D 2</div><div>&nbsp;# &nbsp;cdef sta=
tic long dimSizes[2] =3D {100,200}</div><div>&nbsp; &nbsp; cdef long &nbsp;=
 &nbsp; &nbsp; &nbsp;encoding =3D HOST_ENCODING</div><div>&nbsp; &nbsp; cde=
f long &nbsp; &nbsp; &nbsp; &nbsp;majority =3D ROW_MAJOR</div><div>&nbsp; &=
nbsp; cdef long &nbsp; &nbsp; &nbsp; &nbsp;form =3D SINGLE_FILE</div><div>&=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</div><div>------=
------------------------------------------------------</div><div><br></div>=
<div>test.pyx:14:39: undeclared name not builtin: SINGLE_FILE</div><div>bui=
lding 'cdf' extension</div><div>clang -fno-strict-aliasing -fno-common -dyn=
amic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd =
-DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to=
-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -arch i=
386 -arch x86_64 -I/System/Library/Frameworks/Python.framework/Versions/2.7=
/include/python2.7 -c test.c -o build/temp.macosx-10.8-intel-2.7/test.o -D_=
FILE_OFFSET_BITS=3D64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE</div><div>c=
lang: warning: argument unused during compilation: '-mno-fused-madd'</div><=
div>test.c:1:2: error: Do not use this file, it is the result of a failed C=
ython compilation.</div><div>#error Do not use this file, it is the result =
of a failed Cython compilation.</div><div>&nbsp;^</div><div>1 error generat=
ed.</div><div>error: command 'clang' failed with exit status 1</div></div><=
div><br></div><div><br></div>
------=_Part_276_28048796.1348807169772--

------=_Part_275_2355490.1348807169772--