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 * H5TBdelete_record
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 an array of Particles */
50 Particle p_data[NRECORDS] = {
51 {"zero",0,0, 0.0f, 0.0},
52 {"one",10,10, 1.0f, 10.0},
53 {"two", 20,20, 2.0f, 20.0},
54 {"three",30,30, 3.0f, 30.0},
55 {"four", 40,40, 4.0f, 40.0},
56 {"five", 50,50, 5.0f, 50.0},
57 {"six", 60,60, 6.0f, 60.0},
58 {"seven",70,70, 7.0f, 70.0}
59 };
60
61 const char *field_names[NFIELDS] = /* Define field information */
62 { "Name","Latitude", "Longitude", "Pressure", "Temperature" };
63 hid_t field_type[NFIELDS];
64 hid_t string_type;
65 hid_t file_id;
66 hsize_t chunk_size = 10;
67 int compress = 0;
68 Particle fill_data[1] =
69 { {"no data",-1,-1, -99.0f, -99.0} };
70 hsize_t start; /* Record to start reading */
71 hsize_t nrecords; /* Number of records to insert/delete */
72 hsize_t nfields_out;
73 hsize_t nrecords_out;
74
75 /* Initialize the field field_type */
76 string_type = H5Tcopy( H5T_C_S1 );
77 H5Tset_size( string_type, 16 );
78 field_type[0] = string_type;
79 field_type[1] = H5T_NATIVE_INT;
80 field_type[2] = H5T_NATIVE_INT;
81 field_type[3] = H5T_NATIVE_FLOAT;
82 field_type[4] = H5T_NATIVE_DOUBLE;
83
84 /* Create a new file using default properties. */
85 file_id = H5Fcreate( "ex_table_07.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
86
87 /* Make the table */
88 H5TBmake_table( "Table Title",file_id,TABLE_NAME,NFIELDS,NRECORDS,
89 dst_size,field_names, dst_offset, field_type,
90 chunk_size, fill_data, compress, p_data );
91
92 /* Delete records */
93 start = 3;
94 nrecords = 3;
95 H5TBdelete_record( file_id, TABLE_NAME, start, nrecords );
96
97 /* Get table info */
98 H5TBget_table_info (file_id,TABLE_NAME, &nfields_out, &nrecords_out );
99
100 /* print */
101 printf ("Table has %d fields and %d records\n",(int)nfields_out,(int)nrecords_out);
102
103 /* close type */
104 H5Tclose( string_type );
105
106 /* close the file */
107 H5Fclose( file_id );
108
109 return 0;
110
111 }
112
113