3.5C#
HDFql can be used in the C# programming language through a wrapper named “HDFql.cs”, which is stored in the directory “csharp” found under the directory “wrapper”. The following short program illustrates how HDFql can be used in this language.
// use HDFql namespace (make sure it can be found by the C# compiler)
using AS.HDFql;
public class Example
{
public static void Main(string []args)
{
// display HDFql version in use
System.Console.WriteLine("HDFql version: {0}", HDFql.Version);
// create an HDF5 file named "my_file.h5" and use (i.e. open) it
HDFql.Execute("CREATE AND USE FILE my_file.h5");
// create an HDF5 dataset named "my_dataset" of data type int
HDFql.Execute("CREATE DATASET my_dataset AS INT VALUES(10)");
// select (i.e. read) data from dataset "my_dataset" and populate cursor in use with it
HDFql.Execute("SELECT FROM my_dataset");
// move cursor in use to the first position within the result set
HDFql.CursorFirst();
// display content of cursor in use
System.Console.WriteLine("Dataset value: {0}", HDFql.CursorGetInt());
}
}Assuming that the program is stored in a file named “Example.cs”, it can be launched by executing the following command in a terminal:
dotnet run --property:StartupObject=ExampleIn case the program does not launch, it is most likely that either (1) Microsoft .NET is not installed or (2) the HDFql C# wrapper and/or the MPI shared library were not found (these are needed to launch the program). To fix the former issue, download and install Microsoft .NET from the website https://dotnet.microsoft.com/download. To fix the latter issue:
- On Windows, add the directory where the file “HDFql.cs” (i.e. the wrapper) is located to the environment variable “PATH” by executing the following command in a terminal:
set PATH=<hdfql_csharp_wrapper_directory>;%PATH% - On Linux, add the directories where the files “HDFql.cs” and (optionally) “libmpi.so” are located to the environment variable “LD_LIBRARY_PATH” by executing the following command in a terminal:
- With an HDFql non MPI-based distribution:
export LD_LIBRARY_PATH=<hdfql_csharp_wrapper_directory>:$LD_LIBRARY_PATH - With an HDFql MPI-based distribution:
export LD_LIBRARY_PATH=<hdfql_csharp_wrapper_directory>:<mpi_lib_directory>:$LD_LIBRARY_PATH
- With an HDFql non MPI-based distribution:
- On macOS, add the directories where the files “HDFql.cs” and (optionally) “libmpi.dylib” are located to the environment variable “DYLD_LIBRARY_PATH”7 by executing the following command in a terminal:
- With an HDFql non MPI-based distribution:
export DYLD_LIBRARY_PATH=<hdfql_csharp_wrapper_directory>:$DYLD_LIBRARY_PATH - With an HDFql MPI-based distribution:
export DYLD_LIBRARY_PATH=<hdfql_csharp_wrapper_directory>:<mpi_lib_directory>:$DYLD_LIBRARY_PATH
- With an HDFql non MPI-based distribution:
Notes
- Starting with version 10.11 (i.e. El Capitan), Apple introduced a security feature named System Integrity Protection (SIP) that may prevent setting the environment variable “DYLD_LIBRARY_PATH” and, ultimately, launching the program. To overcome this, SIP should be disabled (please refer to https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html for additional information). ↩