From 968ebbf49ccb8299e9b89dd1f1aadaf63c29327e Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 26 Aug 2024 14:56:52 +0200 Subject: [PATCH 1/5] issue #262 --- src/netcdf_c.jl | 21 ++++++++++++++++++++- test/test_variable.jl | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/netcdf_c.jl b/src/netcdf_c.jl index 3d27b558..6529ab9b 100644 --- a/src/netcdf_c.jl +++ b/src/netcdf_c.jl @@ -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 diff --git a/test/test_variable.jl b/test/test_variable.jl index 4f63d0f5..ad016860 100644 --- a/test/test_variable.jl +++ b/test/test_variable.jl @@ -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] From 064e69624a7dc856c3d3a774e87242e664a81cbc Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Fri, 30 Aug 2024 08:48:02 +0200 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7c814b6..6bba1048 100644 --- a/README.md +++ b/README.md @@ -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) From c4b20c06d2d90c87b2840718ed101e4b03bb783b Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Fri, 30 Aug 2024 08:58:46 +0200 Subject: [PATCH 3/5] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 53d8682e..e2734567 100644 --- a/Project.toml +++ b/Project.toml @@ -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" From 218c476591ff7bac3f4bd549a0d32d53a40e63d3 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Fri, 11 Oct 2024 14:39:21 +0200 Subject: [PATCH 4/5] update docs --- src/dataset.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dataset.jl b/src/dataset.jl index 56bfcac3..dea7ef83 100644 --- a/src/dataset.jl +++ b/src/dataset.jl @@ -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 From 5bc914605deca7933760dcbbfaf52a535261ffa1 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Fri, 11 Oct 2024 14:39:37 +0200 Subject: [PATCH 5/5] debug info for nc_create --- src/netcdf_c.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netcdf_c.jl b/src/netcdf_c.jl index 6529ab9b..43d54106 100644 --- a/src/netcdf_c.jl +++ b/src/netcdf_c.jl @@ -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[]