Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding a variable to a closed file #55

Closed
jannefiluren opened this issue Jan 18, 2018 · 4 comments
Closed

Error when adding a variable to a closed file #55

jannefiluren opened this issue Jan 18, 2018 · 4 comments

Comments

@jannefiluren
Copy link
Contributor

I have an old netcdf file, to which I want to add a new variable, like follows:

nccreate(file, "time_array", "ymdh", 4, "dim_time")

This raises the following error:

       nccreate(file, "time_array", "ymdh", 4, "dim_time")
reopening file in WRITE mode
ERROR: MethodError: no method matching open(::String, ::UInt16)
Closest candidates are:
  open(::AbstractString; mode, readdimvar) at /home/jmg/.julia/v0.6/NetCDF/src/NetCDF.jl:654
  open(::AbstractString, ::AbstractString; mode, readdimvar) at /home/jmg/.julia/v0.6/NetCDF/src/NetCDF.jl:638
Stacktrace:
 [1] #nccreate#46(::Dict{Any,Any}, ::Dict{Any,Any}, ::Int64, ::Int64, ::UInt16, ::Tuple{Int64}, ::Function, ::String, ::String, ::String, ::Vararg{Any,N} where N) at /home/jmg/.julia/v0.6/NetCDF/src/NetCDF.jl:858
 [2] nccreate(::String, ::String, ::String, ::Vararg{Any,N} where N) at /home/jmg/.julia/v0.6/NetCDF/src/NetCDF.jl:847

This error disappears if I change the open file statement on line 858 from:

open(fil,NC_WRITE)

to:

open(fil,mode=NC_WRITE)

Did I do something wrong from the beginning, or should there be a keyword in the open statement?

Thanks for any help.
Jan

@visr
Copy link
Member

visr commented Jun 18, 2018

Yeah in the source code mode is a keyword argument:

function open(fil::AbstractString; mode::Integer=NC_NOWRITE, readdimvar::Bool=false)

And indeed as you suspect there should be a keyword in the open statement, since this doesn't work:

julia> f(a; b=2) = @show a b
f (generic function with 1 method)

julia> f(1, 2)
ERROR: MethodError: no method matching f(::Int64, ::Int64)
Closest candidates are:
  f(::Any; b) at REPL[6]:1

julia> f(1, b=2)
a = 1
b = 2

Would be appreciated if you could look for any mistakes like this in the code and correct them. And if possible also add a test for this. We can help if you have questions.

@meggart
Copy link
Member

meggart commented Jun 18, 2018

Thanks for reporting this and sorry for my long silence. I missed some issues because I messed up my notification settings. I am currently working on the 0.7 updates for the package and this will be fixed in the new version.

@visr
Copy link
Member

visr commented Jun 18, 2018

Great! Maybe you can use this to make it easier: https://discourse.julialang.org/t/femtocleaner-usage-howto/11762

It might be easier to drop 0.6 support and switch to 0.7. In that case we could still fix this issue on 0.6 and tag a last NetCDF.

@jannefiluren
Copy link
Contributor Author

I have created a pull request that hopefully is correct. My editor (vs code with julia extension) automatically also made some changes to the code formatting when saving. Those are in a separate commit. Hope that is okay.

meggart added a commit that referenced this issue Jun 21, 2018
ikselven pushed a commit to ikselven/NetCDF.jl that referenced this issue Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants