Question regarding Fortran NAPI-interface

Stephan Rosenkranz SRosenkranz at anl.gov
Tue Feb 24 01:01:18 GMT 1998


Hello again,

First, thanks for your comments and for the updated Fortran interface. I
haven't
tested it yet, but with the new c-wrapper routines there shouldn't be any
problem.
Sorry for the confusion with the pointers. I agree that it is actually
pretty simple
enough to just pass the FileId ( as outlined in Freddies last email ) ( and
btw Mark:
no, F90 does not provide generic pointers. In fact, pointers in F90 are
strongly
type-enforced, even the shape of the pointer has to agree with the one of
the target)

Right now however, i have a question concerning the compatibility of Fortran
and C-arrays. As you probably are aware of, in Fortran the fastest moving index
is the innermost one, in contrast to almost any other language ( C, Pascal.. ).
ie. an array of rank 2 with dimension  (2,2) is stored in the following order
Fortran: a(1,1), a(2,1), a(1,2), a(2,2)
and in C: a(1,1), a(1,2), a(2,1), a(2,2).

Looking at the interfaces, i have the impression, that when a Array( rank>1
) is
passed or retrieved through the Fortran-Napi,  the array will be in the
wrong order.
In the example program's ( napi_test.c and napif_test.f ) you avoid this
problem
by using a rank-1 array for the rank-2 data. However, i'm not sure whether this
is very practical in real-life. So if i'm not mistaken, then a data-array
of true
rank > 1 ( i.e. A(i1=1..n1,i2=1..n2) ) put into a NeXus-File through the
current Fortran-interface would actually be stored as the transpose of it (
and it's getting
worse for higher ranks). If this data is read back again through the
Fortran-interface,
then there's no problem. However, if the data is read with a C-program, the
data
could look pretty ugly ( i would have made a test on that if only i had any c-
knowledge :-(  ). So the question remains what should be done about this:

1) nothing. A fortran-programer has to take care of this by himself either by
knowing that the order of indeces is reversed or by packing arrays of rank>1
into an array of rank 1 before passing data to NAPI. Looking again at the
description of the NAPI, i got the impression that this is what you
intended ( it
is stated that fortran data is array of rank 1 ) ? In that case, i suggest
that you
explicitly either state not to use arrays of rank>1, or explain the issues
with this.
However, if possible, i'd really prefer beeing able to retrieve array
directly in
the correct shape because otherwise i have to unpack the array sooner or later
myself.

2) adjust the interface such that it handles this issue correctly. In F90
this could be
done easily through function-overloading ( i.e. a generic function which
automatically
determines from the data-type and shape of the data_array passed to it
which function
actually has to be called), but it could be tricky in F77 - there you don't
know whether
the caller is passing a true Array( rank>1 ) or whether the caller has
already packed the
data into a rank 1 array. Solution ?

With best regards
Stephan

-----------------------------------------------------------------------
Dr. Stephan Rosenkranz             Tel: +1 (630) 252-1154
Intense Pulsed Neutron Source   Fax: +1 (630) 252-7777
Argonne National Laboratory     E-mail: SRosenkranz at anl.gov
Argonne, IL 60439-4845





More information about the NeXus-developers mailing list