diff --git a/src/netcdf_c.jl b/src/netcdf_c.jl index a7684f3c..34a24e24 100644 --- a/src/netcdf_c.jl +++ b/src/netcdf_c.jl @@ -547,8 +547,14 @@ function nc_inq_user_type(ncid::Integer,xtype::Integer) end +function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,typeid::Integer,data::Vector) + check(ccall((:nc_put_att,libnetcdf),Cint,(Cint,Cint,Cstring,nc_type,Csize_t,Ptr{Nothing}), + ncid,varid,name,typeid,length(data),data)) +end + + function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::AbstractString) - if name == "_FillValue" + if Symbol(name) == :_FillValue nc_put_att_string(ncid,varid,"_FillValue",[data]) else check(ccall((:nc_put_att_text,libnetcdf),Cint,(Cint,Cint,Cstring,Csize_t,Cstring), @@ -561,8 +567,13 @@ function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::Vect end # NetCDF does not necessarily support 64 bit attributes -nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::Int64) = - nc_put_att(ncid,varid,name,Int32(data)) +function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::Int64) + if Symbol(name) == :_FillValue + nc_put_att(ncid,varid,name,ncType[Int64],[data]) + else + nc_put_att(ncid,varid,name,Int32(data)) + end +end nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::Vector{Int64}) = nc_put_att(ncid,varid,name,Int32.(data)) @@ -589,11 +600,6 @@ function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::Vect nc_put_att(ncid,varid,name,ncType[T],data) end -function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,typeid::Integer,data::Vector) - check(ccall((:nc_put_att,libnetcdf),Cint,(Cint,Cint,Cstring,nc_type,Csize_t,Ptr{Nothing}), - ncid,varid,name,typeid,length(data),data)) -end - # convert e.g. ranges to vectors function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::AbstractVector) nc_put_att(ncid,varid,name,Vector(data)) @@ -603,6 +609,7 @@ function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data) error("attributes can only be scalars or vectors") end + function nc_get_att(ncid::Integer,varid::Integer,name) xtype,len = nc_inq_att(ncid,varid,name) diff --git a/test/test_fillvalue.jl b/test/test_fillvalue.jl index 752b360b..f61583b5 100644 --- a/test/test_fillvalue.jl +++ b/test/test_fillvalue.jl @@ -194,3 +194,11 @@ ncv = ds["data"] @test ncv[1,1] == data[1,1] @test isnan(ncv[2,2]) + +# issue 264 +fname = tempname() +ds = NCDataset(fname,"c") +defDim(ds,"mydim", 2) +defVar(ds,"test_array_i64_missing", [missing, 2], ("mydim", )) +close(ds) +rm(fname)