[Nexus] Problems with NXgetnextentry

Mark Koennecke Mark.Koennecke at psi.ch
Wed May 28 07:52:49 BST 2003


 Dear Paul Simmonds,


On Tue, 27 May 2003, Simmonds Paul wrote:

> 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?

  First, you are right about NXgetnextentry, the class attribute should 
  contain either SDS or the class name after the call. But I have a couple
  off comments on all this.

  - We are currently working on a general interface between the NeXus-API
    and scripting languages using SWIG (http://www.swig.org). This SWIG
    interface is already known to work for Tcl and mzScheme. I would like
    to ask you to download the most recent version of the NAPI from the
    CVS repository and to donate you experience with python to get this 
    SWIG interface to work with python. If the promise of SWIG holds 
    this might give you a working Python NeXus API in half a  day. 
    Moreover, some important bug fixes have recently been made to the
    version of NAPI in the  CVS repository, perhaps you would like to
    benefit of those as well. If you wish to follow this road either 
    Freddy Akeroyd (Freddy.Akeroyd at rl.ac.uk) or I can give you the 
    details how to access the NAPI CVS repository. Or give you a dump
    of it if you are not familiar with CVS.

  - I experienced some trouble with attributes with HDF5 recently.
    In HDF5-NAPI, the class is an attribute.  
    Depending on the version of HDF5 the code either worked or did not.
    I'am now waiting for the upcoming  1.6 release of HDF5 before I start
    looking into this in more detail. Moreover this means I cannot really
    help you without knowing on which OS your are, if you are using
    HDF4 or HDF5 and which versions of the respective libraries you are
    running.    

  - Though my knowledge of python is next to zero, I noticed a problem
    in your code: No space is allocated for name and class. NXgetnextentry
    now copies data to pointers pointing to nowhere. Your program is in
    trouble memory wise then and anything could happen. I suggest to
    change:
        char *name, *class;
    to:
	NXname name, class;
    and to try again. NXname is a typedef to char[128], see napi.h
   

			I hope this helps,

				Mark Koennecke

> <------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)
> type:1965"*/
>     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