/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * This example shows how to create a compound data type, * write an array which has the compound data type to the file, * and read back fields' subsets. */ #include "hdf5.h" #define H5FILE_NAME "comp-inter2.h5" #define DATASETNAME "MoreCompArrayOfStructures2" #define RANK 1 int main(void) { /* First structure and dataset*/ typedef struct { int a; float b; } s1_t; typedef struct { int c; s1_t d; } s2_t; s2_t s2[3]; hid_t s1_tid,s2_tid; /* File datatype identifier */ int i; hid_t file, dataset, space,t_string; /* Handles */ herr_t status; hsize_t dim[1]; /* Dataspace dimensions */ for (i=0;i<3;i++){ s2[i].c=i; s2[i].d.a=i+1; s2[i].d.b=i*0.6; } /* * Create the data space. */ dim[0] = 3; space = H5Screate_simple(RANK, dim, NULL); /* * Create the file. */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create the memory data type. */ s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)); H5Tinsert(s1_tid, "inner_int", HOFFSET(s1_t, a), H5T_NATIVE_INT); H5Tinsert(s1_tid, "inner_float", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT); s2_tid = H5Tcreate (H5T_COMPOUND, sizeof(s2_t)); H5Tinsert(s2_tid,"outer_int",HOFFSET(s2_t,c),H5T_NATIVE_INT); H5Tinsert(s2_tid,"outer_com",HOFFSET(s2_t,d),s1_tid); /* * Create the dataset. */ dataset = H5Dcreate(file, DATASETNAME, s2_tid, space, H5P_DEFAULT); /* * Wtite data to the dataset; */ status = H5Dwrite(dataset, s2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s2); /* * Release resources */ H5Tclose(s2_tid); H5Tclose(s1_tid); H5Sclose(space); H5Dclose(dataset); H5Fclose(file); return 0; }