Skip to content

Commit

Permalink
Merge branch 'master' into DiskArray0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Oct 11, 2024
2 parents 2d0e7cb + 5bc9146 commit fb7d0aa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
keywords = ["netcdf", "climate and forecast conventions", "oceanography", "meteorology", "climatology", "opendap"]
license = "MIT"
desc = "Load and create NetCDF files in Julia"
version = "0.14.5"
version = "0.14.6"

[deps]
CFTime = "179af706-886a-5703-950a-314cd64e0468"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NCDatasets

[![Build Status](https://github.com/Alexander-Barth/NCDatasets.jl/workflows/CI/badge.svg)](https://github.com/Alexander-Barth/NCDatasets.jl/actions)
[![codecov.io](http://codecov.io/github/Alexander-Barth/NCDatasets.jl/coverage.svg?branch=master)](http://app.codecov.io/github/Alexander-Barth/NCDatasets.jl?branch=master)
[![codecov](https://codecov.io/github/Alexander-Barth/NCDatasets.jl/graph/badge.svg?token=SXpIBsfRrI)](https://codecov.io/github/Alexander-Barth/NCDatasets.jl)
[![documentation stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://alexander-barth.github.io/NCDatasets.jl/stable/)
[![documentation dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://alexander-barth.github.io/NCDatasets.jl/dev/)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.06504/status.svg)](https://doi.org/10.21105/joss.06504)
Expand Down
5 changes: 3 additions & 2 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ Load, create, or even overwrite a NetCDF file at `filename`, depending on `mode`
If `share` is true, the `NC_SHARE` flag is set allowing to have multiple
processes to read the file and one writer process. Likewise setting `diskless`
or `persist` to `true` will enable the flags `NC_DISKLESS` or `NC_PERSIST` flag.
processes to read the file and one writer process (netcdf classic files only).
Likewise setting `diskless` or `persist` to `true` will enable the flags
`NC_DISKLESS` or `NC_PERSIST` flag.
More information is available in the [NetCDF C-API](https://www.unidata.ucar.edu/software/netcdf/docs/).
Notice that this does not close the dataset, use `close` on the
Expand Down
22 changes: 21 additions & 1 deletion src/netcdf_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ end
# end

function nc_create(path,cmode::Integer)
@debug "nc_create $path with mode $cmode"
ncidp = Ref(Cint(0))
check(ccall((:nc_create,libnetcdf),Cint,(Cstring,Cint,Ptr{Cint}),path,cmode,ncidp))
return ncidp[]
Expand Down Expand Up @@ -1026,7 +1027,26 @@ end

function nc_get_vars!(ncid::Integer,varid::Integer,startp,countp,stridep,ip)
@debug "nc_get_vars!: $startp,$countp,$stridep"
check(ccall((:nc_get_vars,libnetcdf),Cint,(Cint,Cint,Ptr{Csize_t},Ptr{Csize_t},Ptr{Cint},Ptr{Nothing}),ncid,varid,startp,countp,stridep,ip))

if any(<(0),stridep)
reverse_dim = stridep .< 0
strider = copy(stridep)
startr = copy(startp)

for i = 1:length(stridep)
if reverse_dim[i]
strider[i] = -stridep[i]
startr[i] = startp[i] + (countp[i]-1)*stridep[i]
end
end

check(ccall((:nc_get_vars,libnetcdf),Cint,(Cint,Cint,Ptr{Csize_t},Ptr{Csize_t},Ptr{Cint},Ptr{Nothing}),ncid,varid,startr,countp,strider,ip))

# reverse(reverse_dim) is necessary because stride uses the C ordering
reverse!(ip,dims=Tuple(findall(reverse(reverse_dim))))
else
check(ccall((:nc_get_vars,libnetcdf),Cint,(Cint,Cint,Ptr{Csize_t},Ptr{Csize_t},Ptr{Cint},Ptr{Nothing}),ncid,varid,startp,countp,stridep,ip))
end
end


Expand Down
18 changes: 18 additions & 0 deletions test/test_variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,21 @@ vv = [1.0f0]
NCDatasets.load!(variable(ds, "temperature"), vv, CartesianIndex(5,5))
@test vv[1] == data[CartesianIndex(5,5)]
close(ds)

# issue 262
fname = tempname()
ds = NCDataset(fname,"c")
defDim(ds,"lon",10)
defDim(ds,"lat",11)
data = [Float32(i+j) for i = 1:10, j = 1:11];
data2 = similar(data)
v = defVar(ds,"temperature",data,("lon","lat"))

@test v[:,end:-1:1] == data[:,end:-1:1]
@test v[:,end:-2:1] == data[:,end:-2:1]
@test v[:,5:-1:1] == data[:,5:-1:1]
@test v[:,5:-1:3] == data[:,5:-1:3]
@test v[end:-1:1,:] == data[end:-1:1,:]

NCDatasets.load!(variable(ds, "temperature"), data2, :,11:-1:1)
@test data2 == data[:,end:-1:1]

0 comments on commit fb7d0aa

Please sign in to comment.