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 8L</div><div>#define ROW=
_MAJOR 1L</div><div>#define SINGLE_FILE =
1L</div></div><div><br></div><div><br></div><div>--------------------------=
--- below is from an example, say, example.c -----------------------</div><=
div><div>CDFid test_id; &n=
bsp; /* CDF identifier (handle). */</div>=
<div>CDFstatus status; &nb=
sp; /* Status returned from CDF library. */</div><div>=
static char CDFname[] =3D {"test1"}; /* File name of th=
e CDF. */</div><div>long numDims =3D 2; &=
nbsp; /* Number of dimensions. */<=
/div><div>static long dimSizes[2] =3D {100,200}; /* Dimension =
sizes. */</div><div>long encoding =3D HOST_ENCOD=
ING; /* Data encoding. */</div><div>long =
majority =3D ROW_MAJOR; /* Variable data majority. */<=
/div><div>long form =3D SINGLE_FILE; &nbs=
p; /* 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> ctypedef =
void *CDFid;</div><div> ctypedef long CDFstatus;</div><div>&nb=
sp; static double *TT2000NULL =3D 0;</div><div> enum:</=
div><div> HOST_ENCODING =3D 8;</div><div> =
ROW_MAJOR =3D 1;</div><div> =
SINGLE_FILE =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> cdef CDFid test_id</div><div>=
cdef CDFstatus status</div><div> # cdef cha=
r CDFname[] =3D {"test1"}</div><div>  =
; cdef char *CDFname =3D "test1"</div><div> =
; cdef long numDims =3D 2</div><div> =
;# cdef static long dimSizes[2] =3D {100,200}</div><div> =
cdef long encoding =3D HOST_ENCODING</div><div>=
cdef long majority =3D ROW_MAJOR</=
div><div> cdef long form =3D SINGLE=
_FILE</div><div><br></div><div> 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> sources =3D ['test=
.pyx'],</div><div> libraries =3D [cdfdist + 'lib/libcdf.a'],</=
div><div> extra_compile_args =3D ['-D_FILE_OFFSET_BITS=3D64', =
'-D_LARGEFILE64_SOURCE',</div><div>  =
; '-D_LARGEFILE_SOURCE'])</=
div><div><br></div><div>setup(name =3D 'pyNASACDF',</div><div> =
version =3D '0.1.0',</div><div> cmdclass =3D {'=
build_ext':build_ext},<br></div><div> ext_modules =3D [=
modules]</div><div> )</div></div><div><br></div><div>---=
------------------------------------- end of code -------------------------=
-------------</div><div> 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. </div><div><div><br>=
</div><div>>$ 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; ctypedef void *CDFid;</div><div>  =
; ^</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> cdef CDFid test_id</div><div> =
^</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> cdef CDFid test_id</=
div><div> cdef CDFstatus status</div><div> =
^</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> cdef CDFstatus status</div><div> # &=
nbsp;cdef char CDFname[] =3D {"test1"}</div><div=
> cdef char *CDFname =3D "test1"</d=
iv><div> cdef long numDims =3D 2</d=
iv><div> # cdef static long dimSizes[2] =3D {100,200}</div><div>=
cdef long encoding =3D HOST_ENCODI=
NG</div><div> =
&nbs=
p; ^</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> # cdef char C=
DFname[] =3D {"test1"}</div><div> cdef char &nbs=
p; *CDFname =3D "test1"</div><div> cdef long &nbs=
p; numDims =3D 2</div><div> # cdef static long dimS=
izes[2] =3D {100,200}</div><div> cdef long  =
; encoding =3D HOST_ENCODING</div><div> cdef long =
majority =3D ROW_MAJOR</div><div> =
 =
; ^</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> cdef char  =
; *CDFname =3D "test1"</div><div> cdef lon=
g numDims =3D 2</div><div> # cdef sta=
tic long dimSizes[2] =3D {100,200}</div><div> cdef long =
encoding =3D HOST_ENCODING</div><div> cde=
f long majority =3D ROW_MAJOR</div><div> &=
nbsp; cdef long form =3D SINGLE_FILE</div><div>&=
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> ^</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--