go-netcdf
go-netcdf copied to clipboard
Unlimited dimensions not supported
When creating a file with an unlimited dimension, data is not written properly.
package main
import "github.com/fhs/go-netcdf/netcdf"
func main() {
dataset, _ := netcdf.CreateFile("test.nc", netcdf.NETCDF4 | netcdf.WRITE)
dims := make([]netcdf.Dim, 1)
dims[0], _ = dataset.AddDim("time", uint64(4))
ncvar, _ := dataset.AddVar("var", netcdf.FLOAT, dims)
dataset.EndDef()
ncvar.WriteFloat32s([]float32{0.1, 0.2, 0.3, 0.4})
dataset.Close()
}
Output of ncdump test.nc:
netcdf test {
dimensions:
time = UNLIMITED ; // (0 currently)
variables:
float var(time) ;
data:
}
However if the time dimension is defined as having a size of uint64(4) instead:
netcdf test {
dimensions:
time = 4 ;
variables:
float var(time) ;
data:
var = 0.1, 0.2, 0.3, 0.4 ;
}
Unlimited dimensions are a very useful part of the netCDF specification and it would be great if they were supported.