This library currently only supports netcdf v4
Crystal bindings to libnetcdf v4.
Based on swillner's NodeJS bindings
NetCDF must be installed: brew install hdf5 netcdf
Add this to your application's shard.yml
:
dependencies:
netcdf:
github: fridgerator/netcdfcr
require "netcdf"
file = NetCDF::File.open("path/to/file.nc")
group = file.groups.first
attr = group.attributes.first
puts attr.name
puts attr.value
variable = group.variables.first
puts variable.name
puts variable.read(0) # one dimension
puts variable.read(0, 0, 0) # 3 dimensions
puts variable.read_slice(0, 10, 0, 1, 0, 1) # read slice of 10 for 3 dimensions
attr = variable.attributes.first
puts attr.value
file.close
Properties:
id
: NetCDF file id
Methods:
close
: Close filesync
: Sync file to diskadd_group
: Adds a group to a fileadd_dimension
: Adds a dimension to a fileadd_variable
: Adds a variable to a fileattributes
: Returns an array of global attributesadd_attribute
: Creates a global attribute
Properties:
parent_id
: NetCDF id of parentid
: NetCDF idname
: Group name
Methods:
full_name
: Full nameunlimited
: Returns array of unlimited Dimensions in groupattributes
: Returns an array of attributesdimensions
: Returns an array of dimensionsvariables
: Returns an array of variablesgroups
: Returns an array of groupsadd_group
: Adds a group within a groupadd_dimension
: Adds a dimension to a groupadd_variable
: Adds a variable to a Group
Properties:
parent_id
: NetCDF id of parentid
: NetCDF idname
: Dimension namelength
: Dimension length
Properties:
parent_id
: NetCDF id of parentid
: NetCDF idname
: Attribute nameattribute_type
: Attribute typeInt32
Methods:
value
: Attribute value
Properties:
parent_id
: NetCDF id of parentid
: NetCDF idname
: Variable namevar_type
: Variable typeInt32
ndims
: Number of dimensions
Methods:
attributes
: Returns an array of variable attributesendianness
: Endianness: "little", "big", or "native"checksum_mode
: Checksum mode: "none" or "fletcher32"chunk_mode
: Chunk mode: "contiguous", or "chunked"chunk_sizes
: Array of chunk sizes, one size per dimensionfill_mode
: Boolean switch for fill modefill_value
: Fill valuecompression_shuffle
: Boolean switch for shufflecompression_deflate
: Boolean switch for compressioncompression_level
: Compression level (1-9)read_slice
: Reads and returns an array of values (cf. "Specify a Hyperslab") at positions and sizes given for each dimension,readSlice(pos1, size1, pos2, size2, ...)
e.g.readSlice(2, 3, 4, 2)
gives an array of the values at position 2 for 3 steps along the first dimension and position 4 for 2 steps along the second one.read
: Reads and returns a single value at positions, one argument per dimensionadd_attribute
: Creates an attribute for a variablewrite
: Write a value at positions given,write(2, 3, "a")
writes "a" at position 2 along the first dimension and position 3 along the second onewrite_slice
: Write values from an array (array must be of same type) at positions and sizes given for each dimension.writeSlice(2, 3, 4, 2, [0, 1, 2, 3, 4, 5])
writes the array at position 2 for 3 steps along the first dimension and position 4 for 2 step along the second one
- Fork it ( https://github.com/fridgerator/netcdfcr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- fridgerator Nick Franken - creator, maintainer