Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Alexander-Barth/NCDatasets.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Jan 9, 2018
2 parents a98eeb0 + 34208f6 commit 93407c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ Pkg.installed()["NCDatasets"]
Pkg.test("NCDatasets")
```

# Alternative

The package [NetCDF.jl](https://github.com/JuliaGeo/NetCDF.jl) from Fabian Gans and contributors is an alternative to this package which supports a more Matlab/Octave-like interface for reading and writing NetCDF files.

# Credits

Expand Down
14 changes: 11 additions & 3 deletions src/NCDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,23 @@ function defmode(ncid,isdefmode::Vector{Bool})
end

"""
timeunits(units)
t0,plength = timeunits(units)
Parse time units and returns the start time and the scaling factor in
milliseconds.
Parse time units and returns the start time `t0` and the scaling factor
`plength` in milliseconds.
"""
function timeunits(units)
tunit,starttime = strip.(split(units," since "))
tunit = lowercase(tunit)

starttime = replace(starttime,"T"," ")

# remove Z time zone indicator
# all times are assumed UTC anyway
if endswith(starttime,"Z")
starttime = starttime[1:end-1]
end

t0 = DateTime(starttime,"y-m-d H:M:S")

plength = if (tunit == "days") || (tunit == "day")
Expand Down
12 changes: 10 additions & 2 deletions src/netcdf_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,16 @@ end

function nc_open(path,mode::Integer)
ncidp = Vector{Cint}(1)
check(ccall((:nc_open,libnetcdf),Cint,(Ptr{UInt8},Cint,Ptr{Cint}),path,mode,ncidp))
return ncidp[1]

code = ccall((:nc_open,libnetcdf),Cint,(Ptr{UInt8},Cint,Ptr{Cint}),path,mode,ncidp)

if code == Cint(0)
return ncidp[1]
# otherwise throw an error message
else
# return a more helpful error message (i.e. with the path)
throw(NetCDFError(code, "Opening path $(path): $(nc_strerror(code))"))
end
end

function nc_inq_path(ncid::Integer)
Expand Down
6 changes: 6 additions & 0 deletions test/test_timeunits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ for (timeunit,factor) in [("days",1),("hours",24),("minutes",24*60),("seconds",2
rm(filename)

end


t0,plength = NCDatasets.timeunits("days since 1950-01-02T03:04:05Z")

@test t0 == DateTime(1950,1,2, 3,4,5)
@test plength == 86400000

0 comments on commit 93407c9

Please sign in to comment.