1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 #include "hdf5.h"
15 #include "hdf5_hl.h"
16 #include <stdlib.h>
17
18 /*-------------------------------------------------------------------------
19 * Table API example
20 *
21 * H5TBget_table_info
22 *
23 *-------------------------------------------------------------------------
24 */
25
26 #define NFIELDS (hsize_t) 5
27 #define NRECORDS (hsize_t) 8
28 #define TABLE_NAME "table"
29
main(void)30 int main( void )
31 {
32 typedef struct Particle
33 {
34 char name[16];
35 int lati;
36 int longi;
37 float pressure;
38 double temperature;
39 } Particle;
40
41 /* Calculate the size and the offsets of our struct members in memory */
42 size_t dst_size = sizeof( Particle );
43 size_t dst_offset[NFIELDS] = { HOFFSET( Particle, name ),
44 HOFFSET( Particle, lati ),
45 HOFFSET( Particle, longi ),
46 HOFFSET( Particle, pressure ),
47 HOFFSET( Particle, temperature )};
48
49 /* Define field information */
50 const char *field_names[NFIELDS] =
51 { "Name","Latitude", "Longitude", "Pressure", "Temperature" };
52 hid_t field_type[NFIELDS];
53 hid_t string_type;
54 hid_t file_id;
55 hsize_t chunk_size = 10;
56 Particle fill_data[1] =
57 { {"no data",-1,-1, -99.0f, -99.0} }; /* Fill value particle */
58 int compress = 0;
59 hsize_t nfields_out;
60 hsize_t nrecords_out;
61
62 /* Initialize field_type */
63 string_type = H5Tcopy( H5T_C_S1 );
64 H5Tset_size( string_type, 16 );
65 field_type[0] = string_type;
66 field_type[1] = H5T_NATIVE_INT;
67 field_type[2] = H5T_NATIVE_INT;
68 field_type[3] = H5T_NATIVE_FLOAT;
69 field_type[4] = H5T_NATIVE_DOUBLE;
70
71 /* Create a new file using default properties. */
72 file_id = H5Fcreate( "ex_table_06.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
73
74 /* Make a table */
75 H5TBmake_table( "Table Title",file_id,TABLE_NAME,NFIELDS,NRECORDS,dst_size,
76 field_names, dst_offset, field_type,
77 chunk_size, fill_data, compress, NULL);
78
79 /* Get table info */
80 H5TBget_table_info (file_id,TABLE_NAME, &nfields_out, &nrecords_out );
81
82 /* print */
83 printf ("Table has %d fields and %d records\n",(int)nfields_out,(int)nrecords_out);
84
85 /* close type */
86 H5Tclose( string_type );
87
88 /* close the file */
89 H5Fclose( file_id );
90
91 return 0;
92
93
94 }
95
96