IOBuffer a Matrix?

Hi All!
I am making a pseudo wrapper for a Fortran code. I just need to parse a matrix as an input to it.

In the terminal i can do:

cat data | ./Perplex_LitMod_T

Where data looks like this:

   3      0  0  0
1500  65000  5  0
1500  65000  5  0
1500  65000  5  0

The first line is just the count of lines (followed by zeros) and then the data that the code reads.

I was trying to call the code from Julia like this:

readchomp(pipeline(IOBuffer("$DATA"), ./Perplex_LitMod_T)))

But it is not working. Error massage:

At line 65 of file Perplex_LitMod_T.for (unit = 5, file = 'stdin')
Fortran runtime error: Bad integer for item 1 in list input

Error termination. Backtrace:
#0  0x16115bebd
#1  0x16115cb75
#2  0x16115d76b
#3  0x161381008
#4  0x161385019
#5  0x161385bd2
#6  0x102c3e2f5
#7  0x102c9ad7e
ERROR: failed process: Process(`./Perplex_LitMod_T`, ProcessExited(2)) [2]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:525 [inlined]
 [2] read(cmd::Base.CmdRedirect)
   @ Base ./process.jl:412
 [3] read(cmd::Base.CmdRedirect, #unused#::Type{String})
   @ Base ./process.jl:421
 [4] readchomp(x::Base.CmdRedirect)
   @ Base ./io.jl:923
 [5] top-level scope
   @ none:1

Any ideas how to parse a matrix through Julia?

I think you want the stdin keyword? e.g.

julia> readchomp(pipeline(`sort`, stdin=IOBuffer("foo\nbar\nbaz")))
"bar\nbaz\nfoo"

That being said, you’d probably be better off compiling your Fortran code into a shared library and calling a subroutine via ccall than piping data in and out as text.

1 Like