NXDICT API Usage Example

This piece of code writes also three data items to a NeXus file but uses the NXDICT API. Furthermore, a whole set of file attributes are written in one gom using one of the utility functions. Compare the length with the same code for doing less with the base NeXus API.

#include "napi.h"

int main()
{
    int counts[1000][50], n_t, n_p, dims[2], i;
    float t[1000], phi[50];
    NXhandle file_id;
    NXdict   dict_id;
/* Read in data using local routines */
    getdata (n_t, t, n_p, phi, counts);

/* Open output file and output global attributes */
    NXopen ("OUTPUT.HDF", NXACC_CREATE, &file_id);
    NXDinitfromfile("example.dict",&dict_id);

/* Put file attributes, all of them!! */
    NXUwriteglobals(file_id,
                    "output.hdf",
                    "Joe Bloggs",
                    "Institute for Advanced Studies",
                    "+44-1235-34567",
                    "Joe.Bloggs@IFAS.edu",
                    "+44-1235-34568",
                    "Room Temperature superconductor");
  
/* Output time channels */
    NXDputalias(file_id, dict_id,"tof", &n_t); 
/* Output detector angles */
    NXDputalias(file_id, dict_id,"phi", &n_p); 
/* Output data */
    NXDputalias(file_id, dict_id,"data", counts); 
/* close everything */
    NXclose (&file_id);
    NXDclose(&dict_id,NULL);
    return;
}


File translated from TEX by TTH, version 0.9.