[Nexus] NXgetinfo for NX_CHAR datasets (HDF5 ONLY!!)

Hartmut Gilde Hartmut.Gilde at frm2.tum.de
Mon Mar 29 15:46:55 BST 2004


Hello Mark,

Am Montag, 29. März 2004 08:50 schrieben Sie:
> Dear Hartmut Gilde,
>
> On Fri, 26 Mar 2004, Hartmut Gilde wrote:
> > Hi all,
> >
> > i forgot to mention, that the behaviour of NXgetinfo for NX_CHAR datasets
> > described above only arises when using HDF5 as the underlying Format.
> > With HDF4, NXgetinfo returns exactly what we would expect.
>
>   sorry I was away from the office for a couple of days. This answers
>   one of the questions I would have asked. NXgetinfo is supposed to
>   behave the same independent of HDF4 or HDF5. If it doesn't this is a
>   bug. As the HDF4 and HDF5 implementation use different libraries this
>   may have happened.

Thats what i thought first, but when i examined the Nexus source code i 
discovered that its explicitly programmed to behave this way. 
Take a look at the NX5getinfo implementation:
.
.
.
    iRank = H5Sget_simple_extent_ndims(pFile->iCurrentS);
    iRet = H5Sget_simple_extent_dims(pFile->iCurrentS, myDim, NULL);   
    /* conversion to proper ints for the platform */ 
    *iType = (int)mType;
    if (data_id==H5T_STRING) {
       for (i = 0; i < iRank; i++)
       {
         myDim[i] = H5Tget_size(pFile->iCurrentT);    
       }
    } 
    *rank = (int)iRank;
    for (i = 0; i < iRank; i++)
    {
         dimension[i] = (int)myDim[i];
    }
    return NX_OK;


it seems pretty obvious, that for NX_CHAR (H5T_STRING) the same value is 
returned in any dimension !!!
For comparison the Nexus HDF4 implementation of NX4getinfo:
.
.
.
    SDgetinfo (pFile->iCurrentSDS, pBuffer, &iRank, myDim, 
               &mType, &iAtt);

    /* conversion to proper ints for the platform */ 
    *iType = (int)mType;
    *rank = (int)iRank;
    for(i = 0; i < iRank; i++)
    {
       dimension[i] = (int)myDim[i];
    }
    return NX_OK;





>   The second question is the sequence of calls you use. You need:
>      NXmakedate(........)
>      NXopendata(........)
>      NXgetinfo(........)

yes of course.

>   to get proper results. NXmakedata does not open the dataset. If you call
>   NXgetinfo without a dataset open, the results are undefined and
>   NXgetinfo should return NX_ERROR. Did you check for this? Please send a
>   snippet of code which exhibits the problem so that we can look at it
>   and solve the issue.

i use the correct sequence.
here a snippet of a very simple piece of code:

.
.
int i, NXrank, NXdims[32], NXtype;
int dims[2] = {2, 4};
char teststring[2][4] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
.
.
if (NXmakedata (fileid, "strdata", NX_CHAR, 2, dims) != NX_OK) return 1;
if (NXopendata (fileid, "strdata") != NX_OK) return 1;
if (NXputdata  (fileid, teststring) != NX_OK) return 1;
if (NXclosedata (fileid) != NX_OK) return 1;

if (NXopendata (fileid, "strdata") != NX_OK) return 1;
if (NXgetinfo (fileid, &NXrank, NXdims, &NXtype) != NX_OK) return 1;
if (NXclosedata (fileid) != NX_OK) return 1;

printf("dims: ");
for (i=0; i<NXrank; i++) {
        printf ("[%d]", NXdims[i]);     
}
printf("\n");
.
.


using HDF4 the correct values are returned: 
dims: [2][4]

with HDF5 the following is output:
dims: [2][2]






More information about the NeXus mailing list