Rust

Rust is a programming language that emphasizes performance, type safety, and concurrency.

Installation

Rust support many operating systems. Thus, you can install Rust using a system package manager. For example, use the following command on macOS.

$brew install rust

Rust installation includes cargo command line tool.

Usage

Create a new HDF5 project using cargo.

$cargo new h5rust $cd h5rust

Edit src/main.rs. We assume that the OMI sample file is under /tmp/ directory.

use hdf5::{File, Result}; use ndarray::Array2; fn main() -> Result<()> { // Open file. let file = File::open("/tmp/OMI-Aura_L2-OMNO2_2008m0720t2016-o21357_v003-2016m0820t102252.he5")?; // Read datasets. let ds = file.dataset("/HDFEOS/SWATHS/ColumnAmountNO2/Data Fields/CloudFraction")?; let lat = file.dataset("/HDFEOS/SWATHS/ColumnAmountNO2/Geolocation Fields/Latitude")?; let lon = file.dataset("/HDFEOS/SWATHS/ColumnAmountNO2/Geolocation Fields/Longitude")?; // Read an attribute. let a = lat.attr("_FillValue").unwrap(); let f = a.read_1d::<f32>()?; let fv = f.as_slice().unwrap(); println!("{:?}", fv); let _arr:Array2<f32> = ds.read_slice((.., ..))?; println!("{:?}", _arr); let _lat:Array2<f32> = lat.read_slice((.., ..))?; println!("{:?}", _lat); let _lon:Array2<f32> = lon.read_slice((.., ..))?; println!("{:?}", _lon); Ok(()) }

Add hdf5 dependency to Cargo.toml file.

[package] name = "h5rust" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] hdf5 = "0.8.1" ndarray = "0.15"

Run the program.

$cargo run

It will generate an output as follows:

$ cargo run Compiling h5rust v0.1.0 (/Users/hdfeos/h5rust) Finished dev [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/h5rust` [-1.2676506e30] [[-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], ..., [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0], [-32767.0, -32767.0, -32767.0, -32767.0, -32767.0, ..., -32767.0, -32767.0, -32767.0, -32767.0, -32767.0]], shape=[1644, 60], strides=[60, 1], layout=Cc (0x5), const ndim=2 [[-74.78585, -74.95536, -75.00605, -74.9891, -74.93198, ..., -67.629845, -67.13152, -66.537544, -65.810814, -64.8892], [-74.67247, -74.83917, -74.88825, -74.87044, -74.81292, ..., -67.54824, -67.05215, -66.46069, -65.73688, -64.81871], [-74.55884, -74.722786, -74.77029, -74.75162, -74.69372, ..., -67.46631, -66.972435, -66.38351, -65.66261, -64.74791], [-74.44529, -74.606514, -74.65246, -74.63295, -74.57466, ..., -67.384056, -66.892395, -66.305984, -65.588005, -64.67676], [-74.33163, -74.49016, -74.53455, -74.514206, -74.45554, ..., -67.30142, -66.81196, -66.22805, -65.51296, -64.60515], ..., [50.726025, 51.227768, 51.6115, 51.917244, 52.168324, ..., 56.10587, 56.203827, 56.299873, 56.388687, 56.45964], [50.622738, 51.122555, 51.504776, 51.80929, 52.059345, ..., 55.9859, 56.084, 56.180286, 56.26949, 56.341084], [50.51932, 51.017223, 51.397945, 51.70124, 51.950275, ..., 55.8659, 55.964134, 56.060654, 56.150246, 56.222477], [50.415745, 50.91176, 51.290997, 51.593082, 51.841114, ..., 55.745953, 55.844326, 55.941086, 56.031067, 56.103943], [50.312187, 50.806282, 51.18402, 51.48489, 51.731907, ..., 55.626, 55.724518, 55.821514, 55.911884, 55.985394]], shape=[1644, 60], strides=[60, 1], layout=Cc (0x5), const ndim=2 [[-121.10775, -116.02946, -111.87781, -108.399216, -105.42942, ..., -56.614407, -55.17542, -53.58119, -51.787773, -49.725952], [-120.99896, -115.95704, -111.83671, -108.38495, -105.43817, ..., -56.850685, -55.411453, -53.816357, -52.021214, -49.95641], [-120.892, -115.885994, -111.796555, -108.37124, -105.44712, ..., -57.08548, -55.646084, -54.050217, -52.253456, -50.185814], [-120.78728, -115.8166, -111.75751, -108.358154, -105.456314, ..., -57.318626, -55.879154, -54.28261, -52.484352, -50.413998], [-120.683655, -115.74796, -111.71888, -108.34518, -105.46532, ..., -57.550014, -56.110523, -54.513374, -52.713684, -50.640705], ..., [93.476654, 91.638794, 90.11595, 88.81602, 87.68258, ..., 60.714207, 59.42934, 57.933777, 56.152336, 53.962345], [93.37615, 91.54117, 90.02093, 88.72337, 87.59212, ..., 60.695957, 59.41517, 57.92438, 56.148647, 53.965664], [93.2762, 91.44408, 89.92642, 88.63123, 87.50215, ..., 60.67776, 59.40104, 57.915, 56.14495, 53.968952], [93.1769, 91.3476, 89.832504, 88.53966, 87.41273, ..., 60.659664, 59.386982, 57.90568, 56.14129, 53.97225], [93.0775, 91.251114, 89.73865, 88.44819, 87.32343, ..., 60.64126, 59.372543, 57.89588, 56.137024, 53.974777]], shape=[1644, 60], strides=[60, 1], layout=Cc (0x5), const ndim=2

See Also

  1. netcdf
  2. dars

Last modified: 02/20/2023
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by Subcontract number 4400528183 under Raytheon Contract number NNG15HZ39C, funded by NASA / Maintained by The HDF Group