Table of Contents

Class NetCdfFile

Namespace
EncDotNet.S100.Datasets.NetCdf
Assembly
EncDotNet.S100.Datasets.NetCdf.dll

An open NetCDF file: its dimensions, variables and global attributes, and reads of a variable's raw values. NetCDF-3 (classic and 64-bit offset) is read by a small managed reader written from the Unidata NetCDF classic format specification; NetCDF-4 is read through PureHDF.

public abstract class NetCdfFile : IDisposable
Inheritance
NetCdfFile
Implements
Inherited Members

Remarks

This is the format layer only. Values come back as stored: packing (scale_factor, add_offset) and missing values aren't applied here; NetCdfWeatherDataset applies them.

Reads are serialised on the file, so one file can serve several threads. The file keeps its stream open until it's disposed.

Properties

Dimensions

The file's dimensions, in file order.

public IReadOnlyList<NetCdfDimension> Dimensions { get; }

Property Value

IReadOnlyList<NetCdfDimension>

Format

The on-disk format.

public abstract NetCdfFormat Format { get; }

Property Value

NetCdfFormat

GlobalAttributes

The file's global attributes, in file order.

public IReadOnlyList<NetCdfAttribute> GlobalAttributes { get; }

Property Value

IReadOnlyList<NetCdfAttribute>

Variables

The file's variables, in file order.

public IReadOnlyList<NetCdfVariable> Variables { get; }

Property Value

IReadOnlyList<NetCdfVariable>

Methods

DetectFormat(ReadOnlySpan<byte>)

Returns the format the leading bytes of a file announce: NetCDF-3 classic (CDF\x01), 64-bit offset (CDF\x02), or HDF5 (the container of NetCDF-4), or null for anything else, including CDF-5 (CDF\x05).

public static NetCdfFormat? DetectFormat(ReadOnlySpan<byte> leadingBytes)

Parameters

leadingBytes ReadOnlySpan<byte>

At least the first 8 bytes of the file.

Returns

NetCdfFormat?

Dispose()

Closes the file.

public void Dispose()

FindGlobalAttribute(string)

Finds a global attribute by name (case-sensitive).

public NetCdfAttribute? FindGlobalAttribute(string name)

Parameters

name string

The attribute's name.

Returns

NetCdfAttribute

The attribute, or null.

FindVariable(string)

Finds a variable by name (case-sensitive).

public NetCdfVariable? FindVariable(string name)

Parameters

name string

The variable's name.

Returns

NetCdfVariable

The variable, or null.

GetGlobalText(string)

The text of global attribute name, trimmed, or null when absent, numeric or empty.

public string? GetGlobalText(string name)

Parameters

name string

The attribute's name.

Returns

string

Open(Stream, bool)

Opens a NetCDF file from a seekable stream.

public static NetCdfFile Open(Stream stream, bool leaveOpen = false)

Parameters

stream Stream

The file's bytes, positioned anywhere; it must be readable and seekable.

leaveOpen bool

Whether disposing the file leaves stream open.

Returns

NetCdfFile

The open file.

Exceptions

ArgumentException

stream isn't readable and seekable.

NetCdfFormatException

The bytes aren't a NetCDF file this library can read.

Open(string)

Opens the NetCDF file at path.

public static NetCdfFile Open(string path)

Parameters

path string

The file's path.

Returns

NetCdfFile

The open file; dispose it to close the file.

Exceptions

NetCdfFormatException

The file isn't a NetCDF file this library can read.

Read(NetCdfVariable, ReadOnlySpan<long>, ReadOnlySpan<long>)

Reads a hyperslab of a numeric variable's raw values: count points from start along each dimension, row-major (the last dimension varies fastest).

public double[] Read(NetCdfVariable variable, ReadOnlySpan<long> start, ReadOnlySpan<long> count)

Parameters

variable NetCdfVariable

A numeric variable of this file.

start ReadOnlySpan<long>

The first index along each dimension.

count ReadOnlySpan<long>

The number of points along each dimension.

Returns

double[]

The values, as stored (no packing or missing-value handling).

Exceptions

ArgumentException

The hyperslab doesn't fit the variable, or the variable isn't numeric.

NetCdfFormatException

The data can't be read, for example because it uses an unsupported compression filter.

ObjectDisposedException

The file was disposed.

ReadAll(NetCdfVariable)

Reads every raw value of a numeric variable, row-major.

public double[] ReadAll(NetCdfVariable variable)

Parameters

variable NetCdfVariable

A numeric variable of this file.

Returns

double[]

The values, as stored.