# How to read range of JLD file?

**URL:** <https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954>\
**Category:** Data\
**Tags:** question, jld\
**Created:** [December 14, 2016, 6:35pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954 "2016-12-14T18:35:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [December 14, 2016, 6:35pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/1 "2016-12-14T18:35:42Z")

</div>

```julia
julia> using JLD

julia> D=load("D.jld","D",(:,1))
ERROR: too few arguments
 in println at strings/io.jl:25

```

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [December 22, 2016, 11:35am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/2 "2016-12-22T11:35:34Z")

</div>

No any idea ?  
…

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [December 22, 2016, 11:36am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/3 "2016-12-22T11:36:59Z")

</div>

Maybe show use how you created the JLD? Otherwise it is a bit hard to guess what you are trying to do.

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 15, 2017, 10:42am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/4 "2017-01-15T10:42:28Z")

</div>

Like below:

```
           _

```

\_ \_ _(_)\_ | A fresh approach to technical computing  
(_) | (_) (_) | Documentation: [http://docs.julialang.org](http://docs.julialang.org)  
\_ \_ | | \_\_ \_ | Type “?help” for help.  
| | | | | | |/ ` | |  
| | || | | | (_| | | Version 0.4.5 (2016-03-18 00:58 UTC)  
_/ |\ __‘_|_|_|\__ ’\_| | Official [http://julialang.org/](http://julialang.org/) release  
|\_\_/ | x86\_64-w64-mingw32

julia\> using JLD

julia\> D=rand(10,10)  
10x10 Array{Float64,2}:  
0.0870527 0.436815 0.215768 0.374257 0.477098 0.920663 0.0679468 0.893296 0.656644  
… 0.687406 0.00995926 0.96358 0.846045 0.188301 0.722089 0.109776 0.86346 0.725332 0.36931

julia\> save(“D.jld”,“D”,D)

julia\> D=load(“D.jld”,“D”,(:,1))  
ERROR: too few arguments  
in println at strings/io.jl:25

julia\>

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 15, 2017, 12:14pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/5 "2017-01-15T12:14:03Z")

</div>

Why do you have (:, 1) in there? Does it work without it?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 15, 2017, 1:27pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/6 "2017-01-15T13:27:09Z")

</div>

> [@programista](#):
>
> load(“D.jld”,“D”,(:,1))

Are you trying to do this? `load("D.jld","D")[:,1]`? ( a common error for people that come from Matlab)

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 15, 2017, 1:46pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/7 "2017-01-15T13:46:12Z")

</div>

load(“D.jld”,“D”)  
works  
and  
load(“D.jld”,“D”)[:,1]  
works, but a ned to save memory  
Paul

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 15, 2017, 1:46pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/8 "2017-01-15T13:46:53Z")

</div>

load(“D.jld”,“D”)  
works

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 15, 2017, 3:14pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/9 "2017-01-15T15:14:47Z")

</div>

> [@programista](#):
>
> but a ned to save memory

Then you might try

```julia
save("D.jld", Dict("D$i" => D[:,i] for i in 1:10))
load("D.jld", "D1")

```

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 16, 2017, 8:45am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/10 "2017-01-16T08:45:12Z")

</div>

> [@mkborregaard](#):
>
> save(“D.jld”, Dict(“D$i” =\> D[:,i] for i in 1:10))

Thanks, Idea nice but somethink missing  
julia\> save(“D.jld”, Dict(“D$i” =\> D[:,i] for i in 1:10))  
ERROR: syntax: missing comma or ) in argument list  
Paul

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 16, 2017, 11:56am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/11 "2017-01-16T11:56:54Z")

</div>

It works on my system. If there is an error, I suspect you should be able to find it yourself.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 16, 2017, 12:00pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/12 "2017-01-16T12:00:19Z")

</div>

One explanation might be if you’re on julia 0.4. You shouldn’t unless you have a very good reason to. The old syntax in julia 0.4 would have been:

```julia
save("D.jld", Dict(["D$i" => D[:,i] for i in 1:10]))

```

---

<div class="post-metadata">

**Author:** ![Simon\_Bolland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simon_bolland/32/8920_2.png) [@Simon\_Bolland](https://discourse.julialang.org/u/Simon_Bolland)\
**Post date:** [January 16, 2017, 1:43pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/13 "2017-01-16T13:43:45Z")

</div>

For completeness, it may be worth mentioning that if memory is an issue, there is a lower level interface that allows memory mapped arrays, which only needs a couple more of lines of code.

Example with a larger array:-

```julia
julia> function bigsave()
          save("/tmp/test.jld","bigarray",rand(10000,10000))
       end
bigsave (generic function with 1 method)

julia> function bigload1() # simple interface
          bigarray=load("/tmp/test.jld","bigarray")
          println(sum(bigarray))
       end
bigload1 (generic function with 1 method)

julia> function bigload2() # lower level interface
          f=jldopen("/tmp/test.jld","r",mmaparrays=true)
          bigarray=read(f["bigarray"])
          println(sum(bigarray))
          close(f)
       end
bigload2 (generic function with 1 method)

julia> bigsave()

julia> bigload1()
5.000035653882745e7

julia> @time bigload1()
5.000035653882745e7
  0.190904 seconds (242 allocations: 762.950 MB, 1.12% gc time)

julia> bigload2()
5.000035653882745e7

julia> @time bigload2()
5.000035653882745e7
  0.160253 seconds (189 allocations: 9.828 KB)

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 17, 2017, 1:14pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/14 "2017-01-17T13:14:22Z")

</div>

That is very cool, and actually as fast:

```julia
 function bigsave2()
       D = rand(1000,1000)
       save("D.jld", Dict("D$i" => D[:,i] for i in 1:1000))
       end

function bigload3() # lower level interface
                 f=jldopen("/tmp/test.jld","r",mmaparrays=true)
                 bigarray=read(f["bigarray"])[:,10]
                 println(sum(bigarray))
                 close(f)
              end

function bigload4() # lower level interface
                 f=jldopen("D.jld","r",mmaparrays=true)
                 bigarray=read(f["D10"])
                 println(sum(bigarray))
                 close(f)
              end

bigload3(); bigload4();

@time bigload3()
  0.001467 seconds (188 allocations: 89.938 KB)

@time bigload4()
  0.001425 seconds (125 allocations: 16.734 KB)

```

very nice trick to know.

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 17, 2017, 8:11pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/15 "2017-01-17T20:11:34Z")

</div>

lokk nice but something wrong on last step

Dir tmp exist.

D:\pawel\Julia\_5.0\_otwarty\>C:\Users\PC\AppData\Local\Julia-0.5.0\bin\julia.exe  
-L start.jl  
Pracujesz w aktalogu: D:\pawel\Julia\_5.0\_otwarty

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 17, 2017, 8:18pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/16 "2017-01-17T20:18:44Z")

</div>

or this , the same but without functions

julia\> save(“tmp/test.jld”,“bigarray”,rand(10000,10000))  
julia\> f=jldopen(“tmp/test.jld”,“r”,mmaparrays=true)  
Julia data file version 0.1.1: tmp/test.jld

julia\> bigarray=read(f[“bigarray”])  
ERROR: could not create file mapping: Odmowa dostępu.  
in #mmap#1(::Bool, ::Bool, ::Function, ::IOStream,  
::Type{Array{Float64,2}}, ::Tuple{Int64,Int64}, ::UInt64) at .\mmap.  
jl:133  
in mmap(::IOStream, ::Type{Array{Float64,2}}, ::Tuple{Int64,Int64},  
::UInt64) at .\mmap.jl:102  
in readmmap(::HDF5.HDF5Dataset, ::Type{Array{Float64,N}}) at  
C:\Users\PC.julia\v0.5\HDF5\src\plain.jl:1504  
in read\_vals(::JLD.JldDataset, ::HDF5.HDF5Datatype, ::Type{Float64},  
::Int32, ::Int32, ::Tuple{Int64,Int64}) at C:\User  
s\PC.julia\v0.5\JLD\src\JLD.jl:438  
in read\_array(::JLD.JldDataset, ::HDF5.HDF5Datatype, ::Int32, ::Int32,  
::Tuple{Int64,Int64}) at C:\Users\PC.julia\v0.5  
\JLD\src\JLD.jl:429  
in read(::JLD.JldDataset) at C:\Users\PC.julia\v0.5\JLD\src\JLD.jl:392

julia\>

Paul,

W dniu 2017-01-16 14:47, Simon Bolland pisze:

---

<div class="post-metadata">

**Author:** ![Simon\_Bolland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simon_bolland/32/8920_2.png) [@Simon\_Bolland](https://discourse.julialang.org/u/Simon_Bolland)\
**Post date:** [January 17, 2017, 10:13pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/17 "2017-01-17T22:13:46Z")

</div>

It would appear that the HDF5 format used by JLD doesn’t support the memory mapping functionality on windows, so I think you’ll have to make do with just the Dict solution.

[HDF5 Issue #89](https://github.com/JuliaIO/HDF5.jl/issues/89)

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 18, 2017, 8:18am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/18 "2017-01-18T08:18:07Z")

</div>

Big THX Simon,  
I never used Dict, please show me place with some info about it, (using  
Dict for save big matrix…)  
Paul

W dniu 2017-01-17 23:17, Simon Bolland pisze:

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 18, 2017, 11:00am UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/19 "2017-01-18T11:00:48Z")

</div>

Look at my suggestion above.

```julia
function bigload5()
                        bigarray=load("D.jld","D10")
                        println(sum(bigarray))
                     end

bigload5(); @time bigload5()
0.001044 seconds (264 allocations: 22.906 KB)

```

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 18, 2017, 1:04pm UTC](https://discourse.julialang.org/t/how-to-read-range-of-jld-file/954/20 "2017-01-18T13:04:28Z")

</div>

Thx, is very fine !  
Paul
