# Loading a large complex matrix or array from a \*.jl file

**URL:** <https://discourse.julialang.org/t/loading-a-large-complex-matrix-or-array-from-a-jl-file/96828>\
**Category:** New to Julia\
**Created:** [March 30, 2023, 6:10am UTC](https://discourse.julialang.org/t/loading-a-large-complex-matrix-or-array-from-a-jl-file/96828 "2023-03-30T06:10:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![physh](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@physh](https://discourse.julialang.org/u/physh)\
**Post date:** [March 30, 2023, 6:10am UTC](https://discourse.julialang.org/t/loading-a-large-complex-matrix-or-array-from-a-jl-file/96828/1 "2023-03-30T06:10:06Z")

</div>

Dear all,

I hope to find some help here regarding loading a (relatively) large complex array stored together with some other parameters within a .jl file.  
The .jl data file has the following structure:

```julia
# A comment with a short explanation of what the data is
scalar parameter = 1
tuple = (var1 =1, var2 = 2)
energy_array = ComplexF64[...]
wavefunction_array = [...]

```

Some more explanations for the variables: energy\_array has size (7,60) and contains complex values.  
wavefunction\_array has size (7,20000,60) and contains complex values.

The first dimension (of size 7) is a numerical parameter, for which I would like to check convergence. The last dimension (of size 60) is the number of eigenvalues/eigenfunctions which I saved. The dimension of size 20000 is the size of my eigenvectors.

Before, I only saved the eigenvalues (energy\_array) leading to a file size of some kB, and loading the file via `include(filename)` did the job, so that I could further analyze the results. Now, recently I also calculated the eigenfunctions resulting in a file size of up to a few hundret Megabytes. Attempting to load the file via `include(filename)` leads to `ERROR: LoadErrow: StackOverflowError`.

Any insight, how I can load the file? I dont need the full `wavefunction_array` at once, it would be ok if I can do something like `load(filename, wavefunction_array[num_param_val,:,state_index])`.

Maybe another fileformat istead of “.jl” would be more suitable for this task? I can redo my current calculations (will take 1-2 days) if you tell me the “.jl” fileformat is not really suitable for larger files.

Many thanks.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 30, 2023, 7:00am UTC](https://discourse.julialang.org/t/loading-a-large-complex-matrix-or-array-from-a-jl-file/96828/2 "2023-03-30T07:00:14Z")

</div>

You probably want a JLD file:

> **[GitHub - JuliaIO/JLD.jl: Saving and loading julia variables while preserving...](https://github.com/JuliaIO/JLD.jl)**
>
> Saving and loading julia variables while preserving native types - GitHub - JuliaIO/JLD.jl: Saving and loading julia variables while preserving native types

---

<div class="post-metadata">

**Author:** ![physh](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@physh](https://discourse.julialang.org/u/physh)\
**Post date:** [March 30, 2023, 8:38am UTC](https://discourse.julialang.org/t/loading-a-large-complex-matrix-or-array-from-a-jl-file/96828/3 "2023-03-30T08:38:33Z")

</div>

Thank you, can you tell me if I will be able to convert my `filename.jl` directly to `filename.jld`, or should I redo my calculation and save the results into a `.jld` file?

After a quick glance, I could not find this information in the general info of the linked package.

Best regards

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 30, 2023, 8:51am UTC](https://discourse.julialang.org/t/loading-a-large-complex-matrix-or-array-from-a-jl-file/96828/4 "2023-03-30T08:51:42Z")

</div>

A .jl file is a text file. If you cannot include it directly, then you’re going to have to parse it a different way.

A .jld file is a binary HDF5 file.

I do not know how expensive your calculation is. In terms of your time, it probably is easier just to redo your calculation and save it via JLD.jl.
