Gnuplot prints differently when piping - command-line

I have file like this:
662.0,,9624
663.0,,9625
771.0,9624,
772.0,,9626
912.0,9625,
913.0,,9627
1083.0,9626,
1083.0,,9628
1174.0,9627,
1175.0,,9629
And when I use gnuplit console, it prints as expected:
set datafile separator ',';
plot 'data-exchange.log' using 1:2 pt 7 ps 2, '' using 1:3 pt 7 ps 2;
However, when I do the same when piping, it doesn't plot as expected:
cat data-exchange.log | gnuplot -p -e 'set datafile separator ","; plot "<cat" using 1:2 pt 7 ps 2, "" using 1:3 pt 7 ps 2;'
Not sure why is that...

Related

How to color scatter plot points by the value of a third column in Paraview like gnuplot palette?

For example, I generate the data with:
i=0; while [ "$i" -lt 10 ]; do echo "$i,$((2*i)),$((4*i))"; i=$((i+1)); done > main.csv
which contains:
0,0,0
1,2,4
2,4,8
3,6,12
4,8,16
5,10,20
6,12,24
7,14,28
8,16,32
9,18,36
Then for example in gnuplot, I get what I want with palette:
#!/usr/bin/env gnuplot
set terminal png size 1024,1024
set output "main.png"
set datafile separator ","
set key off
plot "main.csv" using 1:2:3 palette pt 7 pointsize 10
which gives the desired:
How to achieve this effect with Paraview?
I managed to make the scatter plot with a Line Chart View, but all points are red like this:
Also I could not resize the marker sizes, but for that I found an open issue: https://gitlab.kitware.com/paraview/paraview/issues/14169
I am initially learning the GUI for plotting, but if you have a scripting option that is good to know too.
The reason I am looking into Parasol is that I need to plot 10M points interactively, which I have found gnuplot and matplotlib not to handle well, so I'm curious if this VTK-based solution will cut it. More info at: Large plot: ~20 million samples, gigabytes of data
Tested in Ubuntu 18.10, Paraview 5.4.1.
Here is the python script to read the file and display the markers in the ParaView 3D Render View.
import paraview.simple as pvs
# create a new 'CSV Reader'
csvReader = pvs.CSVReader(FileName=['C:\\your_file.csv'])
csvReader.HaveHeaders = 0
# create a new 'Table To Points'
tableToPoints = pvs.TableToPoints(Input=csvReader)
tableToPoints.XColumn = 'Field 0'
tableToPoints.YColumn = 'Field 1'
tableToPoints.ZColumn = 'Field 2'
tableToPoints.KeepAllDataArrays = 1
tableToPoints.a2DPoints = 1
# create a new 'Glyph'
glyph = pvs.Glyph(Input=tableToPoints, GlyphType='Arrow')
glyph.Scalars = ['POINTS', 'Field 0']
glyph.Vectors = ['POINTS', 'None']
glyph.GlyphType = '2D Glyph'
glyph.GlyphType.GlyphType = 'Square'
glyph.GlyphType.Filled = 1
glyph.ScaleMode = 'off'
glyph.ScaleFactor = 1.0
glyph.GlyphMode = 'All Points'
### uncomment to scale markers by 'Field 2'
# glyph1.Scalars = ['POINTS', 'Field 2']
# glyph1.ScaleMode = 'scalar'
# show data in view
renderView = pvs.GetActiveView()
glyphDisplay = pvs.Show(glyph, renderView)
glyphDisplay.Representation = 'Surface'
pvs.ColorBy(glyphDisplay, ('POINTS', 'Field 2'))
glyphDisplay.SetScalarBarVisibility(renderView, True)
glyphDisplay.RescaleTransferFunctionToDataRange(True, False)
renderView.Update()
pvs.UpdatePipeline()
renderView.AxesGrid.Visibility = 1
renderView.ResetCamera()
pvs.Render(renderView)
And the result:

Why does powershell script from inno setup print spaces between each two characters?

I am running a powershell script from my inno setup installer via the command:
[Run]
Filename: {cmd}; Parameters: "/c powershell.exe -executionpolicy bypass -File ""{app}\InstallScripts\powershellScript.ps1""
and transcribing my commands/output to a text file by running the command:
StartTranscript -Path $logFile at the beginning of my script.
But in my log file which records all the commands/output I get really weird spaces between each pair of characters like so:
W i n d o w s P o w e r S h e l l T r a n s c r i p t S t a r t
S t a r t t i m e : 2 0 1 8 1 0 0 8 1 3 5 9 1 7
U s e r n a m e : D a v i d
But when I run the script manually I get the printings to the file normally, without the weird spaces.
Why is this happening and how can I correct it so when I run the script from my installer it will print the commands/output normally without these spaces between characters?

How to combine outputs of multiple tasks performed using Matlab SGE?

I have the following batch file launching some m-files (main.m and f.m which are scripts) 4 times (4 tasks).
#$ -S /bin/bash
#$ -l h_vmem=2G
#$ -l tmem=2G
#$ -cwd
#$ -j y
#Run 4 tasks where each task has a different $SGE_TASK_ID ranging from 1 to 4
#$ -t 1-4
#$ -N example
#Output the Task ID
echo "Task ID is $SGE_TASK_ID"
cat main.m f.m | matlab -nodisplay -nodesktop -nojvm -nosplash
At the end I obtain 4 outputs that are example.o[...].1,example.o[...].2, example.o[...].3, example.o[...].4. Each of them looks like
...
Task ID is ...
< M A T L A B (R) >
...
>> >> >> >> >> >> >> >> >> >> >>
output =
4.0234 -3.4763
How can I combine these 4 outputs in a matrix 4x2 and save it?
You should save the relevant output from within f.m using MATLAB's save or something similar.
If you use the -r flag to call main and f from the command line you can add a variable which will contain the task ID and you can then access that from within f.m
matlab -nodisplay -nodesktop -nojvm -nosplash -r "main; ID = $SGE_TASK_ID; f; exit"
Then within f.m
% You theoretically generate some numeric result
result = rand(1, 2);
filename = sprintf('Result.%d.mat', ID);
save(filename, 'result')
This will save Result.0.mat, Result.1.mat etc.
Alternately, you could modify f.m such that it loads the data from the file, appends to it, and re-saves it every time
result = rand(1,2);
filename = 'Results.mat';
% If this is the first task, then create a new file, otherwise append to the old
if ID == 1
data = result;
else
tmp = load(filename, '-mat');
data = tmp.data;
data(ID,:) = result;
end
save(filename, 'data')

Gnuplot reading not locale encoding file

I want to plot data of an ISO_8859_1 encoded file (two columns of numbers). Those are the first 10 data points of the file:
#Pe2
1 0.8000
2 0.8000
3 0.8000
4 0.8000
5 0.8000
6 0.8000
7 0.8000
8 0.8000
9 0.8000
10 0.8000
The original file has 15000 data points. I create this data with MATLAB, specifically setting ISO_8859_1 encoding, so I am sure that that's the encoding. This is a snippet of the matlab code:
slCharacterEncoding('ISO-8859-1'); %Instruction before writing anything to the file.
fprintf(fileID,' %7d %7.4f',Tempo(i),y(i)); %For loop in this instruction
fprintf(fileID,'\r'); %Closing the file
fclose(fileID);
This is the script that I run. This file is encoded with the default Windows txt files encoding:
set encoding iso_8859_1
set terminal wxt size 1000,551
# Line width of the axes
set border linewidth 1.5
# Line styles
set style line 1 lc rgb '#dd181f' lt 1 lw 1 pt 0 # red
# Axes label
set xlabel 'tiempo'
set ylabel 'valor'
plot 'Pe2.txt' with lines ls 1
This is the output of the gnuplot console when I run the script. After that I input "show encoding":
G N U P L O T
Version 4.6 patchlevel 5 last modified February 2014
Build System: MS-Windows 32 bit
Copyright (C) 1986-1993, 1998, 2004, 2007-2014
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type set to 'wxt'
gnuplot> cd 'C:\Example'
gnuplot> load 'script.txt'
"script.txt", line 10: warning: Skipping data file with no valid points
gnuplot> plot 'Pe2.txt' with lines ls 1
^
"script.txt", line 10: x range is invalid
gnuplot> show encoding
nominal character encoding is iso_8859_1
however LC_CTYPE in current locale is Spanish_Spain.1252
gnuplot>
If I open the file, make some change undo the change and save the file, gnuplot plots the file. I guess that it's because it saves it with local encoding which is the one gnuplot uses to read files.
How do I plot files with gnuplot which are not with the local encoding format?
I also have what it seems to be a similar problem when I output a file with VS2010Css. If I don't specifically set the culture with:
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
I am not able to save a file wich gnuplot is able to plot. I believe that this last problem is because of the "," and the "."
In Css I save the files with this:
StreamWriter Writer = new StreamWriter(dir + #"\" + + (k+1) + "_" + nombre + extension);
Writer.WriteLine("#" + (k+1) + "_" + nombre);
Writer.WriteLine();
Writer.WriteLine("{0,32} {1,32}", "#tiempo", "#valor");
for (int i = 0; i < tiempo.GetLength(0); i++)
{
Writer.WriteLine("{0,32} {1,32}", tiempo[i].ToString(), valor[i, k]);
}
Thank you.
Your file has only carriage returns (\r 0xd) as line breaks which doesn't work with gnuplot. You must use only line feed (\n 0xa), but \r\n does also work.

Shell variable name queried from Matlab has additional character

I'm working with the following script, run_test:
#!/bin/sh
temp=$1;
cat <<EOF | matlab
[status name] = unix('echo $temp');
disp(name);
% some Matlab code
test_complete = 1;
save(name)
exit
EOF
I want to pass a name to the script, run some code then save a .mat file with the name that was passed. However, there is a curious piece of behavior:
[energon2] ~ $ ./run_test 'run1'
Warning: No display specified. You will not be able to display graphics on the screen.
< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (glnxa64)
March 18, 2011
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> >> >> >> run1
>> >> >> >> >>
[energon2] ~ $ ls *.mat
run1?.mat
There is a "?" at the end of the file name when it's saved, but not when displayed on command line. This is acceptable for my needs, but a bit irritating to not know why it's occurring. Any explanation would be appreciated.
Edits, solution:
Yuk was correct below in the underlying cause and the use of save('$temp'). I'm now using the following script
#!/bin/sh
temp=$1;
cat <<EOF | matlab
% some Matlab code
test_complete = 1;
save('$temp')
exit
EOF
Thanks for the help.
You name variable has end-of-line as the last character. When you run echo run1 in unix this command display run1 and then "hit enter". In your script all the output of echo are saved to the name variable.
You can confirm it with the following:
>> format compact
>> [status, name] = unix('echo run1')
status =
0
name =
run1
>> numel(name)
ans =
5
>> int8(name(end))
ans =
10
>> int8(sprintf('\n'))
ans =
10
Apparently this character can be a part of a file name in unix, but shell displays it as ?.
Can't you do save($temp) instead?
EDIT: See my comments below for correction and more explanation.