use rustyhdf5::DType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NcType {
Byte,
UByte,
Short,
UShort,
Int,
UInt,
Int64,
UInt64,
Float,
Double,
String,
Char,
}
impl std::fmt::Display for NcType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NcType::Byte => write!(f, "NC_BYTE"),
NcType::UByte => write!(f, "NC_UBYTE"),
NcType::Short => write!(f, "NC_SHORT"),
NcType::UShort => write!(f, "NC_USHORT"),
NcType::Int => write!(f, "NC_INT"),
NcType::UInt => write!(f, "NC_UINT"),
NcType::Int64 => write!(f, "NC_INT64"),
NcType::UInt64 => write!(f, "NC_UINT64"),
NcType::Float => write!(f, "NC_FLOAT"),
NcType::Double => write!(f, "NC_DOUBLE"),
NcType::String => write!(f, "NC_STRING"),
NcType::Char => write!(f, "NC_CHAR"),
}
}
}
pub fn dtype_to_nctype(dtype: &DType) -> NcType {
match dtype {
DType::I8 => NcType::Byte,
DType::U8 => NcType::UByte,
DType::I16 => NcType::Short,
DType::U16 => NcType::UShort,
DType::I32 => NcType::Int,
DType::U32 => NcType::UInt,
DType::I64 => NcType::Int64,
DType::U64 => NcType::UInt64,
DType::F32 => NcType::Float,
DType::F64 => NcType::Double,
DType::String | DType::VariableLengthString => NcType::String,
_ => NcType::Char, }
}