HDFql Reference Manual v2.6.0

4.3Examples

The following C code snippets demonstrate how HDFql cursors and subcursors are populated with (variable) data stored in HDF5 datasets or attributes, along with illustrations to facilitate understanding of the populating process and its final result.

// create an HDF5 dataset named "my_dataset0" of data type short 
hdfql_execute("CREATE DATASET my_dataset0 AS SMALLINT"); 

// insert (i.e. write) a value into dataset "my_dataset0" 
hdfql_execute("INSERT INTO my_dataset0 VALUES(7)"); 

// select (i.e. read) data from dataset "my_dataset0" and populate cursor in use with it  
hdfql_execute("SELECT FROM my_dataset0");
Figure 4.2 – Cursor populated with data from dataset “my_dataset0”
Figure 4.2 – Cursor populated with data from dataset “my_dataset0”
// create an HDF5 dataset named "my_dataset1" of data type float of one dimension (size 3) 
hdfql_execute("CREATE DATASET my_dataset1 AS FLOAT(3)");

// insert (i.e. write) values into dataset "my_dataset1" 
hdfql_execute("INSERT INTO my_dataset1 VALUES(5.5, 8.1, 4.9)");

// select (i.e. read) data from dataset "my_dataset1" and populate cursor in use with it  
hdfql_execute("SELECT FROM my_dataset1");
Figure 4.3 – Cursor populated with data from dataset “my_dataset1”
Figure 4.3 – Cursor populated with data from dataset “my_dataset1”
// create an HDF5 dataset named "my_dataset2" of data type double of two dimensions (size 3x2)
hdfql_execute("CREATE DATASET my_dataset2 AS DOUBLE(3, 2)");

// insert (i.e. write) values into dataset "my_dataset2" 
hdfql_execute("INSERT INTO my_dataset2 VALUES((3.2, 1.3), (0, 0.2), (9.1, 6.5))");

// select (i.e. read) data from dataset "my_dataset2" and populate cursor in use with it  
hdfql_execute("SELECT FROM my_dataset2");
Figure 4.4 – Cursor populated with data from dataset “my_dataset2”
Figure 4.4 – Cursor populated with data from dataset “my_dataset2”
// create an HDF5 dataset named "my_dataset3" of data type variable-length short 
hdfql_execute("CREATE DATASET my_dataset3 AS VARSMALLINT"); 

// insert (i.e. write) values into dataset "my_dataset3" 
hdfql_execute("INSERT INTO my_dataset3 VALUES(7, 9, 3)"); 

// select (i.e. read) data from dataset "my_dataset3" and populate cursor in use with it  
hdfql_execute("SELECT FROM my_dataset3");
Figure 4.5 – Cursor and its subcursor populated with data from dataset “my_dataset3”
Figure 4.5 – Cursor and its subcursor populated with data from dataset “my_dataset3”
// create an HDF5 dataset named "my_dataset4" of data type variable-length float of one dimension (size 3)
hdfql_execute("CREATE DATASET my_dataset4 AS VARFLOAT(3)"); 

// insert (i.e. write) values into dataset "my_dataset4" 
hdfql_execute("INSERT INTO my_dataset4 VALUES((5.5), (8.1, 2.2), (4.9, 3.4, 5.6))"); 

// select (i.e. read) data from dataset "my_dataset4" and populate cursor in use with it  
hdfql_execute("SELECT FROM my_dataset4");
Figure 4.6 – Cursor and its subcursors populated with data from dataset “my_dataset4”
Figure 4.6 – Cursor and its subcursors populated with data from dataset “my_dataset4”
// create an HDF5 dataset named "my_dataset5" of data type variable-length double of two dimensions (size 3x2)
hdfql_execute("CREATE DATASET my_dataset5 AS VARDOUBLE(3, 2)"); 

// insert (i.e. write) values into dataset "my_dataset5" 
hdfql_execute("INSERT INTO my_dataset5 VALUES(((3.2, 8, 6.7), (1.3, 0.2)), ((0), (0.2, 1.5)), ((9.1, 2, 4, 7), (6.5)))"); 

// select (i.e. read) data from dataset "my_dataset5" and populate cursor in use with it  
hdfql_execute("SELECT FROM my_dataset5");
Figure 4.7 – Cursor and its subcursors populated with data from dataset “my_dataset5”
Figure 4.7 – Cursor and its subcursors populated with data from dataset “my_dataset5”