NeXus SDS

Ray Osborn ROsborn at anl.gov
Mon Jan 10 16:02:23 GMT 2000


on 2000/1/10 10:05 AM, Eric Boucher at boucher at aps.anl.gov wrote:

> 
> 
> Hi all,
> 
> What is the apropriate way to store NeXus SDS.
> Is it the C style   : array[z,y,x]
> or the fortran style: array[x,y,z]
> 
> I know that it does not make much difference if the axis SDS are stored
> accordingly, but since user usually want to have the X axis horizontal, I
> would like to know how NeXus browser are going to use the axis information
> in order to have the "right" plot by default.
> The Fortner browser and the java HDF browser use the C style, but I don't
> know for the other browsers and plotting tools.
> 

In fact, it's both.  I usually have to sit down quietly for a while to make
sure that I have got this right whenever this subject comes up.  The basic
message is that if you are using the Fortran API, use the Fortran
convention; if you're using the C API, use the C convention.  The Fortran
wrapper API automatically reverses the order of the array indices when
passing the data to and from the C API.

This makes sense, of course, because the Fortran array, a(i,j), is
physically  stored in the same way as the C array, a[j][i].  NeXus passes
the same data back to both API's.  You just have to reference it
differently.  As long as you know that, there shouldn't be any problems.

The main complication is with the "axis" attribute that links a dimension
scale SDS to the relevant multidimensional data SDS.  This has values 1, 2,
3 etc. to show that it refers to the x, y, z ... etc. axes of the data.  In
the Fortran API, axis = 1 means that it refers to the first dimension that
you write down (i in the above example), whereas in the C API, axis = 1
means that it refers to the last dimension that you write (still i in the
above example).  In both cases, these are the fastest varying indices of the
data, so it's best to think in these terms :

axis = 1 - fastest-varying dimension
axis = 2 - next-fastest-varying dimension
etc.

As you say, the other case it becomes a problem is with generic browsers.  I
released a Fortran 90 terminal browser a few months ago which used the
Fortran convention.  However, I've just finished writing a C version in
which the arrays have the order reversed.  You have to know which version
you are using in order to interpret the output array indices correctly.  I
tried to make it clear by using square brackets for the C version, round
brackets for the Fortran version.  The Fortran version is probably not going
to be maintained now anyway, so perhaps we should make the C convention the
usual one for generic browsers, and warn Fortran programmers to do the
switch.

This is a mine field that all mixed-language projects encounter.  If you
have any comments on the design choices, please let us know.

Regards,
Ray
-- 
Dr Ray Osborn                Tel: +1 (630) 252-9011
Materials Science Division   Fax: +1 (630) 252-7777
Argonne National Laboratory  E-mail: ROsborn at anl.gov
Argonne, IL 60439-4845







More information about the NeXus mailing list