Skip to content

Commit

Permalink
fix single string attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed May 24, 2018
1 parent ab9c7de commit 5c75ae6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/netcdf_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function nc_put_att(ncid::Integer,varid::Integer,name::AbstractString,data::Vect
nc_put_att(ncid,varid,name,join(data))
end

# NetCDF does not support 64 bit attributes
# NetCDF does not necessarily support 64 bit attributes
nc_put_att(ncid::Integer,varid::Integer,name::AbstractString,data::Int64) =
nc_put_att(ncid,varid,name,Int32(data))

Expand Down Expand Up @@ -546,7 +546,13 @@ function nc_get_att(ncid::Integer,varid::Integer,name)
elseif xtype == NC_STRING
val = Vector{Ptr{UInt8}}(len)
check(ccall((:nc_get_att,libnetcdf),Cint,(Cint,Cint,Cstring,Ptr{Void}),ncid,varid,name,val))
return unsafe_string.(val)

str = unsafe_string.(val)
if len == 1
return str[1]
else
return str
end
else
val = Vector{jlType[xtype]}(len)
check(ccall((:nc_get_att,libnetcdf),Cint,(Cint,Cint,Cstring,Ptr{Void}),ncid,varid,name,val))
Expand Down

0 comments on commit 5c75ae6

Please sign in to comment.