# Readdlm() Reading Out of Order

**URL:** <https://discourse.julialang.org/t/readdlm-reading-out-of-order/73238>\
**Category:** New to Julia\
**Tags:** question, io\
**Created:** [December 17, 2021, 2:01am UTC](https://discourse.julialang.org/t/readdlm-reading-out-of-order/73238 "2021-12-17T02:01:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ducksoverip](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ducksoverip/32/31967_2.png) [@ducksoverip](https://discourse.julialang.org/u/ducksoverip)\
**Post date:** [December 17, 2021, 2:01am UTC](https://discourse.julialang.org/t/readdlm-reading-out-of-order/73238/1 "2021-12-17T02:01:15Z")

</div>

Hi, I’m a somewhat novice Fortran programmer (I use Fortran 90 for physics research, but have had no formal training as a programmer) dipping my toes into Julia as a possible replacement language. Naturally, I started off trying to replicate basic Fortran tasks, like reading input variables from text files. I created a file “param.inp” as follows:

```julia
1 2
3 4

```

This represents a normal input file, with one or two values per line, delineated by whitespace or newlines. After a fair amount of bashing my head against Julia’s unfamiliar `read()` function, I eventually figured out that to read in each value as a variable, I should use readdlm, which automatically assumes whitespace separation between values. I tried the following test script:

```julia
using DelimitedFiles

a, b, c, d = readdlm("param.inp")
println(a, b, c, d)

```

The output of this script is: `1324`

Notice the issue? `readdlm()` read the first value of the first line (1) and assigned it to `a`, then the first value of the second line (3) and assigned it to `b`, then the second value of the first line (2) went to `c`, and the second value of the second line (4) went to `d`. I expected it to read across the first line before moving to the second, so that a = 1, b = 2, c =3, and d = 4. Yet, b and c are switched around. Could someone explain why this is happening? It’s completely unlike Fortran’s `read()` behavior.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 17, 2021, 2:02am UTC](https://discourse.julialang.org/t/readdlm-reading-out-of-order/73238/2 "2021-12-17T02:02:34Z")

</div>

`readdlm` gives you a matrix, just like Fortran, Julia’s matrix is column major, so the first 2 elements will be `1,3`:

```julia
julia> readdlm("./test")
2×2 Matrix{Float64}:
 1.0 2.0
 3.0 4.0

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 17, 2021, 3:16pm UTC](https://discourse.julialang.org/t/readdlm-reading-out-of-order/73238/3 "2021-12-17T15:16:41Z")

</div>

I think you could also read the text file as follows with Base `readline()`:

```julia
io = open("param.inp", "r");
a, b = parse.(Int64, split(readline(io)))
c, d = parse.(Int64, split(readline(io)))
close(io)

```
