Questions tagged [streams]

A source of input or output: files and pipes are both examples of general Mathematica objects known as streams.

Files and pipes are both examples of general Mathematica objects known as streams. A stream in Mathematica is a source of input or output.

When you open a file or a pipe, Mathematica creates a "stream object" that specifies the open stream associated with the file or pipe. In general, the stream object contains the name of the file or the external command used in a pipe, together with a unique number. The reason that the stream object needs to include a unique number is that in general you can have several streams connected to the same file or external program at the same time.

Streams and Low-Level Input and Output

107 questions
15
votes
2 answers

Stream reading 1000 times faster in Python

I have a 26GB CSV. I want to extract all the rows that have data for a specific sensor. In Mathematica I write: stream = OpenRead[my26GBFile]; Reap[Block[{line}, line = ReadLine[stream]; While[ StringQ[line], If[StringContainsQ[line,…
10
votes
1 answer

How to read a named pipe on Windows?

Tried to open an Out named pipe from Powershell $pipe = new-object System.IO.Pipes.NamedPipeServerStream 'testpipe','Out' $pipe.WaitForConnection() $sw = new-object System.IO.StreamWriter $pipe $sw.AutoFlush = $true $sw.WriteLine("Server pid is…
kenkangxgwe
  • 93
  • 1
  • 8
7
votes
3 answers

Reading from a stream of strings and numbers delimited by commas

I am trying to read from a stream of strings and numbers delimited by commas similar to the way I have read from a stream of strings and numbers delimited by spaces. Example delimited by spaces (which works): stream = StringToStream["Apple Jack 1…
mmorris
  • 1,172
  • 7
  • 18
6
votes
4 answers

How can I close a stream without knowing its name?

If I initialise a stream as follows OpenWrite["~/example"] How do I close this stream? Close seems to expect a name, but I do not know the name of the stream in this format. [edit] - Thanks for all the responses. It seems the simplest solution…
DJames
  • 187
  • 5
6
votes
1 answer

Is there a way to redirect the output from `Echo`?

The newish function Echo is tremendously useful in quick-and-dirty debugging, since you can stick it pretty much anywhere in an expression and get feedback about what's going on. However, like almost everything else in Mathematica (except $Messages…
Pillsy
  • 18,498
  • 2
  • 46
  • 92
4
votes
0 answers

Is there an equivalent to "Open Update"

I'm writing a binary file that contains a header followed by the data. The header contains the length of the data. The data is written first, skipping past the header. Once done, I would like to update the data length in the header (something easily…
Leon
  • 41
  • 1
4
votes
1 answer

Write and Read to StreamPosition

One OutputStream and one InputStream are opened on the same file: atmp = OpenAppend["tmp"]; Write[atmp, "a"]; Write[atmp, "b"]; Write[atmp, "cde"]; rtmp = OpenRead["tmp"]; Read[rtmp]; Write[atmp, "ABC"]; ReadList[rtmp] {"b", "cde"}…
4
votes
0 answers

Reading a specified line number from a text file

Possible Duplicate: How to read data file quickly? I have a huge text file (~500 MB). The file is too large to Import into Mathematica, although I can read it in Emacs. Is there a way to tell Mathematica to Read in only line number 23681…
Andrew
  • 10,569
  • 5
  • 51
  • 104
4
votes
3 answers

how do I to create a function similar to feof in C?

Using C language,I can use feof to test if the pointer at end of file. while(!feof(fp)) { //to do } But in the mma,I usually use this method to simulate C. file = OpenRead["http://home.ustc.edu.cn/~xiaozh/SE/stu.dat", BinaryFormat -> True]; …
partida
  • 6,816
  • 22
  • 48
3
votes
1 answer

How to substitute the Skip function in special cases?

filedata={" 1 2578Hot Pink 47:21:17 9512971 ", " 2 294Pale Green 24:57:18 4437289 ", " 3 2497Light Yellow 39:40:57 4987642 ", " 4 2010Turquoise …
3
votes
0 answers

How to flush stdout stream?

I am aware that one can write to a terminal standard output like so: WriteString["stdout","Some stuff","\r"]; Note here that I am using a carriage return on purpose, as part of some output monitoring. However, sometimes the output gets a bit messed…
Ben Farmer
  • 193
  • 6
3
votes
1 answer

Directing output of PrintTemporary to an additional OutputStream

I want to log messages that I send to the screen, even temporary ones. By setting $Output appropriately, it is possible to log Print messages, but not PrintTemporary messages: oldout = $Output; logfile = FileNameJoin[{$TemporaryDirectory,…
JxB
  • 5,111
  • 1
  • 23
  • 40
2
votes
1 answer

Use e notation in Stream output

I'm trying to save the results of a huge Radia calculation. I evaluate the function in a loop at multiple locations. To export the data my first approach was to fill a Table and use the Export function: xdim := 500; ydim := 500; zdim := 500; Output…
2
votes
1 answer

Phase portrait on the sphere

I have that $(x,y)\in S^1$, i.e. on the sphere, and in Mathematica, the ODE system f = x^3 - x y^2 + y^3 ; xdot = x (-x + f); ydot = y (x - y + f); vector = {xdot, ydot}; How can I plot the phase portrait on $S^1$? I do not know how to plot this…
Scuderi
  • 193
  • 5
1
vote
0 answers

How to extend length of the streams in this StreamPlot

Is it possible the force the streams in StreamPlot[] to extend the full range of the graphic given specific points of my choosing? For example, notice the streams for the following code are short. I would like to streams to extend through the entire…
B flat
  • 5,523
  • 2
  • 14
  • 36
1
2