[Nexus] Problems with NXgetnextentry

Simmonds Paul simmonds at ill.fr
Tue May 27 15:51:37 BST 2003

Hi all,

At the moment I am in the process of creating a Python wrapper for the
NeXus C API using the Python native C API. If anyone is interested, I
can post more details about it, but at the moment I'm just trying to
print all the attributes and subgroups of a group in the hierarchy. The
problem occurs in the getnextentry call. The 'class' pointer argument
after the call still contains a NULL pointer. As far as I understand
the NeXus API routine spec, this should contain either the string "SDS"
for a data set, or the group's class for any other type. Have I
misunderstood, or missing something else?

I've included the offending code below, with some extra comments for
people unfamiliar with the Python C API. To be able to compile this
the Python interpreter (there should not be version-specific code
and the NeXus API.

Thanks in advance,
Paul Simmonds

<------Code Listing (+extra comments)------->
#include "Python.h"
#include "napi.h"
/* Macro extracting NXhandle from object */
#define HND(x) *(NXhandle*)PyCObject_AsVoidPtr(x)

PyObject *NXPyfile_getnextentry(PyObject *self, PyObject *args)
    PyObject *NXfile;  /* Python Object (a PyCObject) containing the
NXhandle */
    char *name,*class; /* DO THESE NEED TO BE MALLOCED? */
    int *type=malloc(sizeof(int));

    /* Parses 'args' object into components */
    if(!PyArg_ParseTuple(args,"O",&NXfile)) return NULL;

    if (NXgetnextentry(HND(NXfile),name,class,type)!=NX_OK)
    {   PyErr_SetString(PyExc_IOError,           /* sets an error if
call fails */
                "NXPygetnextentry: NXgetnextentry failed");
        return NULL;}

    /* Debug statement- prints e.g."name:Entry1 class:(null)
    printf("name:%s class:%s type:%d\n",name,class,*type);

    /* Builds values into return object */
    return Py_BuildValue("ssi",name,class,*type); /*
returns('Entry1',None,1965) */
<------End of Code Listing------->

More information about the NeXus mailing list