Skip to content

Commit

Permalink
issue #262
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Aug 26, 2024
1 parent 35991a8 commit 968ebbf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/netcdf_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,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]

2 comments on commit 968ebbf

@Alexander-Barth
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114149

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.5 -m "<description of version>" 968ebbf49ccb8299e9b89dd1f1aadaf63c29327e
git push origin v0.14.5

Please sign in to comment.