Class NetCdfFile
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
Format
The on-disk format.
public abstract NetCdfFormat Format { get; }
Property Value
GlobalAttributes
The file's global attributes, in file order.
public IReadOnlyList<NetCdfAttribute> GlobalAttributes { get; }
Property Value
Variables
The file's variables, in file order.
public IReadOnlyList<NetCdfVariable> Variables { get; }
Property Value
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
leadingBytesReadOnlySpan<byte>At least the first 8 bytes of the file.
Returns
Dispose()
Closes the file.
public void Dispose()
FindGlobalAttribute(string)
Finds a global attribute by name (case-sensitive).
public NetCdfAttribute? FindGlobalAttribute(string name)
Parameters
namestringThe attribute's name.
Returns
- NetCdfAttribute
The attribute, or null.
FindVariable(string)
Finds a variable by name (case-sensitive).
public NetCdfVariable? FindVariable(string name)
Parameters
namestringThe 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
namestringThe attribute's name.
Returns
Open(Stream, bool)
Opens a NetCDF file from a seekable stream.
public static NetCdfFile Open(Stream stream, bool leaveOpen = false)
Parameters
streamStreamThe file's bytes, positioned anywhere; it must be readable and seekable.
leaveOpenboolWhether disposing the file leaves
streamopen.
Returns
- NetCdfFile
The open file.
Exceptions
- ArgumentException
streamisn'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
pathstringThe 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
variableNetCdfVariableA numeric variable of this file.
startReadOnlySpan<long>The first index along each dimension.
countReadOnlySpan<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
variableNetCdfVariableA numeric variable of this file.
Returns
- double[]
The values, as stored.