F90-Interface to NAPI

Stephan Rosenkranz SRosenkranz at anl.gov
Thu Feb 19 01:07:21 GMT 1998


Hello everybody,

I have tried, and finally succeded, to write a Fortran90 interface for NAPI
( Version 0.9 ). However, in order to write the interface in STANDARD F90,
i had to make minor changes to the C-Routines. Since these changes are
only minor, i thought you might consider taking them over into your regular
version of NAPI. ( I haven't actually written a complete interface yet -
i have only incluede those procedures so far which are used in the
Test-Programs.)

The only problem i had was, that Fortran by default passes any dummy-variable
by Reference and to my knowledge, there is no standard way to force a passing
by value. Some compilers do provide a built-in function to achieve this
( like Digitals %val() ) but others, like the F-compiler, won't do that. So
my suggestion is, that you avoid any passing of variables by value. The
procedures affected are:
NXmakedata (NXhandle handle, char* label, int datatype, int rank, int dim[])
NXputattr(NXhandle handle, char* name, void* data, int iDataLen, int iType)

changing these to
NXmakedata (NXhandle handle, char* label, int* datatype, int* rank, int dim[])
NXputattr(NXhandle handle, char* name, void* data, int* iDataLen, int* iType)
allows a standard f90 interface.

For the moment, i didn't use any pointer's  in my interface ( for the
NXhadle ) and so i didn't call NXOpen ( which also expects a variable to
be passed by value ) directly but rather call NXfOpen. It would be possible
to define pointers to a NeXusFile-Structure in F90 and pass those directly
to NXOpen ( i have tested this and it works ), but i'm not sure whether there
is any gain in doing this: first, you would have to change all Procedures
( except NXOpen and NXCLose ) since again they all expect the handle to be
passe by value. Second, i don't think a user cares to mutch whether he's
passing a pointer or a target to the NAPI.

{   Just as a side-remark. It is actually possible to produce a f90-interface
whithout changing the value-passing of the NXhandle that doesn't
need to call NXfOpen, NXfClose
Consider you have a typedefinition for NeXusFile somewhere in a Module
( obviously in the interface-Module)
then define a pointer and a variable:
type(NeXusFile) :: FileID
type(NeXusFile), Pointer :: pFileID
Calls to NXOpen, NXClose would need pFileID as argument, whereas
all others would use FileID. This of course requires that FileID is
properly assigned after the call to NXOpen (i.e. FileID = pFileID,
which reads the same as FileID = *pFileId in C ). This however requires
too mutch thinking from the user-side, so i would rather stick with the
current way and only use FileID together with NXfOpen and NXfClose   }

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