ContentsOverviewNeXus IDL Api binds the NeXus libraries to IDL (Interactive Data Language). It brings functionality of the NeXus API to IDL for reading, writing and modifying NeXus Files. IDL NeXus API imitates the functionality NeXus API with few exeptions discussed later. Information on NeXus Dataformat: http://www.nexusformat.org/Introduction. Information on IDL: http://www.nexusformat.org/Introduction.
InstallationRequirementsPrecompiled versions of the DLM (Dynamic Link Module) for Windows (NeXusIDL-API.dll) and Linux (NeXusIDL-API.so) are included in the package. If you want to build the DLM a C compiler is required. GCC for Linux and Microsoft Visual C++ version 6 have been tested. IDL (ver 6) and the latest NeXus API are required. The NeXus packages and installation instructions are available at http://www.nexusformat.org/Download. Microsoft offers a free Microsoft C Compiler Toolkit to Compile DLMs for IDL on Windows http://msdn.microsoft.com/visualc/vctoolkit2003/ For Windows the NeXus Data Format Windows Installer Kit, which includes the necessary hdf5, hdf4 and xml libraries, is recommended. http://download.nexusformat.org/kits/windows/ If the NeXus API header file napi.h is not installed in path you have to edit the correct path to #include list in NeXusIDL-API.c
LinuxEdit correct IDL, HDF libraries and NeXus Library paths to Makefile.
Compile with 'make'. WindowsEdit buildwin.bat and change the correct IDL and NeXus directories.
The compiler and linker have to be set to a path. In Visual C++ they can be set with running the batch file in "Microsoft Visual C Directory\VC98\bin\vcvars32.bat". Run buildwin.bat to run build the API.
Using API from IDLInstalling a New DLM File To IDLRecommeneded way to install the DLM file (NeXusIDL-API.dlm) and the library (NeXusIDL-API.so or NeXusIDL-API.dll) is to copy them to one of the directories IDL searches at startup (and contained in the !IDL_PATH system variable). NOTE: The DLM file and the library must excist in the same directory. DLM's can be also loaded with the DLM_REGISTER command in IDL. Also IDL registeres all the DLM files that are located in the directory where it was started in. These options are only preferred for testing.
Test Files
The IDLNeXus-API includes IDL files for testing write and read functions of the API. write_test.pro and read_test.pro provide identical functionality as in the orginal C api napi_test.h Testfiles write_test.pro and read_test.pro are included. After registering the DLM run in IDL: write_test.pro: Writes a test NeXus file. Accessmethod can be assigned with parameters hdf5, hdf4 and xml. The error codes returned by the routines are printed to IDL console. 1 = NX_OK, 0 = NX_ERROR
read_test: reads the NXtest file produced by write_test and tests the reading functions. Results are printed to IDL console.
recursiveread.pro: Takes a NeXus supported file as a parameter and prints all the data and attributes of the file to IDL console.
Using The API And An ExampleThe API's functions aim to reproduce the funtionality of the C API closely. Some low level functionality has been hidden from the user. Memory allocation functions NXmalloc and NXfree are done automatically in the API when needed. In the spirit of IDL, variables or arrays retrieved with nxgetdata, nxgetslab or nxgetattr don't have to be datatyped beforehand. However when inputting data or attributes with nxputdata, nxputslab or nxputattr the datatypes in IDL have to match with the datatype of the dataset which is declared with nxmakedata or in the nxputattr parameters. The matching datatypes are:
1. Creates a NeXus file with access method HDF5 2. adds datagroups 3. makes a data array of data type NX_INT32 4. puts data to the array 5. reads the data and attributes 6. prints data and attribute value 7.closes the groups and the file.
NeXus IDL API RoutinesHere's the list of functions in the NeXus IDL API. |
Opens the NeXus file, and creates and initializes the NeXus file structure. The returned handle is integer assosiated with a pointer structure, do not modify it.
status = NXopen (file_name, access_method, file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_name | string | Name of NeXus file to be opened |
access_method | int or string |
| |
Output Arguments | file_id | int | Identifier of NeXus file |
Closes NeXus file and deletes all associated data structures from memory.
status = NXclose (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Creates a NeXus group at the current level in the group hierarchy, defining its name and class. This does not open the new group automatically.
status = NXmakegroup (file_id, group_name, group_class)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
group_name | string | Name of NeXus group | |
group_class | string | Class of NeXus group |
Opens an existing NeXus group for input and output of data.
status = NXopengroup (file_id, group_name, group_class)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
group_name | string | Name of NeXus group | |
group_class | string | Class of NeXus group |
Opens a NeXus group or dataset from a path string. The NeXus item must exist for NXopenpath to work correctly. The path string for NXopenpath has the same form as a unix path string: /group1/group/group2/dataset. Both absolute and relative path are supported.
status = NXopenpath(file_id, path_string)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
path_string | string | path to dataset or group in NeXus file |
Opens a NeXus group from a path string. This function is subtly different from NXopenpath in that it only opens the path to the last group; it does not open datasets. The NeXus item must exist for NXopengrouppath to work correctly. The path string for NXopengrouppath has the same form as a unix path string: /group1/group/group2/dataset. Both absolute and relative path are supported.
status = NXopengrouppath(file_id, path_string)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
path_string | string | path to dataset or group in NeXus file |
Closes the currently open group. If this group is a top-level group (i.e. with class NXentry), no groups are left open. Otherwise, the next group up in the hierarchy (i.e. the group containing the currently open group) is left open.
status = NXclosegroup (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Creates a new NeXus data set with the specified name, type, rank and dimensions.
NeXus IDL API NOTE: The data type for the dimensions array must be type long.
status = NXmakedata (file_id, data_name, data_type, rank, dimensions[])
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
data_name | string | Name of NeXus data set | |
data_type | int or string |
| |
rank | int | Rank of data | |
dimensions | Array of IDL type Long | Dimensions of data. The array is of size 'rank' |
Creates a new NeXus data set with the specified name, type, rank and dimensions, compressed using the specified protocol.
NeXus IDL API NOTE: The data type for the dimensions array and bufsize array must be type long in IDL.
status = NXcompmakedata (file_id, data_name, data_type, rank, dimensions[], compress_type, bufsize[])
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
data_name | string | Name of NeXus data set | |
data_type | int or string |
| |
rank | int | Rank of data | |
dimensions | Array of IDL type Long | Dimensions of data. The array is of size 'rank' | |
compress_type | int or string |
| |
bufsize | Array of IDL type Long | The typical buffersize for writing. |
The buffersize requires further explanation. HDF-5 compresses data in chunks. And the buffersize is this chunksize. If data is written in one go with a NXputdata, this is the dimensions of the data. If data is written in slabs, this is the preferred size of the slabs. Please note, that this has only a performance impact when writing, it is no show stopper. Please note that HDF-4 does not support compression on data sets written in slabs: If you want compression with HDF-4, data must be written with one call to NXputdata. Compression is ignored for XML-NeXus files.
Opens an existing NeXus data set for further processing i.e. reading and writing data or attributes, defining compression algorithms, and obtaining data set information.
status = NXopendata (file_id, data_name)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
data_name | string | Name of NeXus data set |
Defines a compression algorithm for subsequent calls to NXputdata. This routine is now deprecated; please use NXcompmakedata instead.
status = NXcompress (file_id, compress_type)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
compress_type | int or string |
|
Ends access to the currently active data set
status = NXclosedata (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Sets the number format when writing to ASCII files. When serializing NeXus file to ASCII-XML files a format for printing numbers is required. The NeXus-API has reasonable defaults for this. However, with this function a desired format can be choosen for special cases. Please note that calls to this function will be silently ignored for the binary NeXus formats HDF-4 and HDF-5.
status = NXsetnumberformat(file_id,data_type,format_string
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
data_type | int or string | The NeXus data type for which to change the print format.
| |
format_string | string | A ANSI-C language style format string |
Reads data values from the currently open data set. Please note that memory overwrite occurs if the caller has not allocated enough memory to hold all the data available. Call NXgetinfo to determine the required dimension sizes. The data set must have been opened by NXopendata.
status = NXgetdata (file_id, data)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | data | equivalent IDL data type of the NeXus data | Data values |
Reads a subset of the data in the current data set specifying the starting indices and size of each dimension. The caller is responsible for allocating enough memory for the data.
NeXus IDL API NOTE: The data type for the slab start and slab size arrays must be type long in IDL.
status = NXgetslab (file_id, data, start[], size[])
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
start[] | Array of IDL type Long | Indices of starting values in each dimension | |
size[] | Array of IDL type Long | Length of slab in each dimension | |
Output Arguments | data | equivalent IDL data type of the NeXus data | Data values |
Reads attribute values associated with the currently open data set. The attribute is defined by its name. Attributes are meta-data; data that provides information on the associated data set such as units, long names etc. If no data set is open, it looks for a global attribute i.e. attributes of the NeXus file. The caller is responsible for allocating enough memory for the attribute values. Note, however, that only the first 'length' bytes of the attribute are read to prevent memory overwrite.
status = NXgetattr (file_id, attr_name, value, length, type)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
attr_name | string | Name of attribute | |
length | int | Length of buffer for storing attribute data | |
type | int or string |
| |
Output Arguments | value | equivalent IDL data type of the NeXus data | Value of attribute |
length | int | Actual length of attribute data |
Writes data into the specified data set. Datatype of the dataset and the IDL data type of the input data must be of equivalent data type. Refer to the chart: 3.3 Using The API And An Example
status = NXputdata (file_id, data[])
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
data | equivalent IDL data type of the prepared NeXus data | Data values |
Writes a subset of a multidimensional data array, specified by the starting indices and size of each dimension, into the currently open dataset.
Datatype of the dataset and the IDL data type of the input data must be of equivalent data type. Refer to the chart: 3.3 Using The API And An Example
NeXus IDL API NOTE: The data type for the slab start and slab size arrays must be type long in IDL.
status = NXputslab (file_id, data, start[], size[])
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
data | equivalent IDL data type of the NeXus data | Data values | |
start[] | Array of IDL type Long | Indices of starting values in each dimension | |
size[] | Array of IDL type Long | Length of slab in each dimension |
Writes an attribute of the currently open data set. If no data set is open, a global attribute is generated. The attribute has both a name and a value.
status = NXputattr (file_id, attr_name, value, length, type)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Return Value | status | int | Error status |
Input Arguments | file_id | int | Identifier of NeXus file |
attr_name | string | Name of attribute | |
value | equivalent IDL data type of the prepared NeXus data | Value of attribute | |
length | int | Length of data | |
type | int or string |
|
Flushes all data to the NeXus file. Since this command closes and reopens the file, a new file handle is returned. The command leaves the program in the same state, i.e. with the same group and/or data set open.
status = NXflush (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input & Output Argument | file_id | int | Identifier of NeXus file |
Gets the rank, dimensions and data type of the currently open data set.
status = NXgetinfo (file_id, rank, dimensions[], data_type)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | rank | int | Rank of data |
dimensions | int[] | Dimensions of data | |
data_type | int |
|
Returns the number of items in the current group, and the name and class of the current group.
status = NXgetgroupinfo (file_id, item_number, group_name, group_class)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | item_number | int | Number of NeXus data items in the current group |
group_name | string | Name of currently open NeXus group | |
group_class | string | Class of currently open NeXus group |
Initializes directory searches of the currently open group. This is required to reset searches using NXgetnextentry that may have been interrupted before completion.
status = NXinitgroupdir (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Implements a directory search facility on the current group level. The first call initializes the search and returns information on the first data item in the list. Subsequent calls yield information about the remaining items. If the item is a group, its name and class is returned. If it is a data set, its name and type is returned with a class of "SDS."
status = NXgetnextentry (file_id, name, class, data_type)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR, NX_EOD) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | name | string | Name of NeXus data item (group or set) |
class | string | Class of NeXus group | |
data_type | int |
|
Returns the number of attributes in the current data set.
status = NXgetattrinfo (file_id, attr_number)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | attr_number | int | Number of attributes in the current data set |
Initializes attribute searches of the currently open data set. This is required to reset searches using NXgetnextattr that may have been interrupted before completion.
status = NXinitattrdir (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Implements a search facility of the attributes of the currently open data set. The first call initializes the search and returns information on the first attribute in the list. Subsequent calls yield information about the remaining attributes. This routine returns global attributes if no data set is open.
status = NXgetnextattr (file_id, attr_name, length, attr_type)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR, NX_EOD) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | attr_name | string | Name of next attribute |
length | int | Length of next attribute | |
attr_type | int |
|
Returns the identifier of the currently open group as an NXlink structure.
status = NXgetgroupID (file_id, group_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | group_id | int | Identifier of NeXus group |
Gets the identifier of the currently open data set as an NXlink structure. Returns NX_ERROR if there is no open data set.
status = NXgetdataID (file_id, data_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Output Arguments | data_id | int | Identifier of NeXus data set |
Links a data item (group or set) to a NeXus group. Returns NX_ERROR if the current group level is the root level, since no data item can be linked here.
status = NXmakelink (file_id, link)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
link | int | Identifier of linked group |
Links a data item (group or set) to a named NeXus group. Returns NX_ERROR if the current group level is the root level, since no data item can be linked here.
status = NXmakenamedlink (file_id, linkname, link)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
linkname | string | Name of the link to be created | |
link | int | Identifier of linked group |
Tests if two data items are the same, i.e. one is linked to the other.
status = NXsameID (file_id, link1, link2)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
link1 | int | Identifier of first item | |
link2 | int | Indentifier of second item |
Opens the group from which a linked dataset was linked. This is useful for accessing auxiliary information related to the dataset. This works only if the linked dataset is currently open.
status = NXopensourcegroup (file_id)
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | file_id | int | Identifier of NeXus file |
Queries which file is really active.
status = NXinquirefile(handle,filename, filenameLength);
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | handle | int | handle to a currently open NeXus file. |
filenameLenght | int | length of filename buffer | |
Output Arguments | filename | string | buffer to receive filename |
Links an external file. This happens by creating a group which points to an external file. Navigating into such a group automatically opens the external file.
status = NXlinkexternal(handle,name, nxclass, nxurl);
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | handle | int | handle to a currently open NeXus file. |
name | string (NXname) | The name of the group to link the file to. | |
nxclass | string (NXname) | The NeXus class of the group to which the external file is to be linked. | |
nxurl | string (NXURL) | An URL of a format which the NeXus-API understands. The only URL format so far is: nxfile://path-to-file#path-to-group-in-file. This consistes of two parts: The file path and a path to a group in the file which is to be mapped into the source file. |
Tests in the group is an external group. If not, NX_ERROR is returned. If yes, NX_OK is returned and the URL of the external file is copied into nxurl.
status = NXisexternalgroup(handle,name, nxclass, nxurl,nxurllen);
Name | Type | Description | |
---|---|---|---|
Return Value | status | int | Error status (NX_OK, NX_ERROR) |
Input Arguments | handle | int | handle to a currently open NeXus file. |
name | string (NXname) | The name of the group to test. | |
nxclass | string (NXname) | The NeXus class of the group to test. | |
nxurllen | int | length of the nxurl buffer | |
Output Arguments | nxurl | string | buffer to copy the URL, too. |