|
| 1 | +/*--------------------------------------------------------------------------- |
| 2 | + NeXus - Neutron & X-ray Common Data Format |
| 3 | +
|
| 4 | + Test program for C API |
| 5 | +
|
| 6 | + Copyright (C) 1997-2009 Freddie Akeroyd |
| 7 | +
|
| 8 | + This library is free software; you can redistribute it and/or |
| 9 | + modify it under the terms of the GNU Lesser General Public |
| 10 | + License as published by the Free Software Foundation; either |
| 11 | + version 2 of the License, or (at your option) any later version. |
| 12 | +
|
| 13 | + This library is distributed in the hope that it will be useful, |
| 14 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + Lesser General Public License for more details. |
| 17 | +
|
| 18 | + You should have received a copy of the GNU Lesser General Public |
| 19 | + License along with this library; if not, write to the Free Software |
| 20 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | +
|
| 22 | + For further information, see <http://www.nexusformat.org> |
| 23 | +
|
| 24 | + $Id: napi_test.c 1178 2009-01-21 12:28:55Z Freddie Akeroyd $ |
| 25 | +
|
| 26 | +----------------------------------------------------------------------------*/ |
| 27 | +#include "MantidNexusCpp/napi.h" |
| 28 | +#include "MantidNexusCpp/napiconfig.h" |
| 29 | +#include <stdio.h> |
| 30 | +#include <stdlib.h> |
| 31 | +#include <string.h> |
| 32 | +#include <time.h> |
| 33 | + |
| 34 | +#define DATA_SIZE 200000 |
| 35 | + |
| 36 | +int test_unlimited(int file_type, const char *filename) { |
| 37 | + static double d[DATA_SIZE]; |
| 38 | + int dims[2] = {NX_UNLIMITED, DATA_SIZE}; |
| 39 | + int i, slab_start[2], slab_size[2]; |
| 40 | + NXhandle file_id = NULL; |
| 41 | + remove(filename); |
| 42 | + NXopen(filename, file_type, &file_id); |
| 43 | + NXmakegroup(file_id, "entry1", "NXentry"); |
| 44 | + NXopengroup(file_id, "entry1", "NXentry"); |
| 45 | + NXmakedata(file_id, "data", NX_FLOAT64, 2, dims); |
| 46 | + NXopendata(file_id, "data"); |
| 47 | + slab_start[1] = 0; |
| 48 | + slab_size[0] = 1; |
| 49 | + slab_size[1] = DATA_SIZE; |
| 50 | + |
| 51 | + for (i = 0; i < 2; i++) { |
| 52 | + slab_start[0] = i; |
| 53 | + NXputslab(file_id, d, slab_start, slab_size); |
| 54 | + } |
| 55 | + |
| 56 | + NXclosedata(file_id); |
| 57 | + NXclosegroup(file_id); |
| 58 | + NXclose(&file_id); |
| 59 | + return 0; |
| 60 | +} |
| 61 | + |
| 62 | +int main(int argc, char *argv[]) { |
| 63 | + time_t tim; |
| 64 | +#ifdef WITH_HDF4 |
| 65 | + printf("Testing HDF4\n"); |
| 66 | + time(&tim); |
| 67 | + test_unlimited(NXACC_CREATE4, "test_unlimited.nx4"); |
| 68 | + printf("Took %u seconds\n", (unsigned)(time(NULL) - tim)); |
| 69 | +#endif |
| 70 | + |
| 71 | +#ifdef WITH_HDF5 |
| 72 | + printf("Testing HDF5\n"); |
| 73 | + time(&tim); |
| 74 | + test_unlimited(NXACC_CREATE5, "test_unlimited.nx5"); |
| 75 | + printf("Took %u seconds\n", (unsigned)(time(NULL) - tim)); |
| 76 | +#endif |
| 77 | + return 0; |
| 78 | +} |
0 commit comments