Gnuplot Maximum Concurrent Lines within single Graph - real-time

I'm implementing real-time plotting with gnuPlot by sending the plot '-' command through pipe. I observed that the maximum number of lines that I can create on a single graph stops at 64. Is this limitation known to anyone? With the piped command I would push plot '-' ... , '-' ... , '-' .... and then the data in consecutive lines ending with e\n. I don't believe the issue lies in pipe as, if the buffer overflows it would simply flush first, and gnuPlot would wait until all the commands have arrived due to the , placed after each none terminating intermediate '-' command. Please provide insights if you know the solution. Thank you!

Related

Gnuplot from 3D datafile with strange format

Hi I am looking for a quick and dirty answer,
I try to make a surface or contourplot with gnuplot from a data file. The problem is the fileformat:
Its all in one row
line 1 till line 32 contain the values for the x-coordinates 1-32 and y=1,
line 33 is the value for x=1 and y=2 and so on...
I tried to do that with the "everyline" command but since they are not separated by a blank line this is not working.
Since this data file is an output file and from my program I get many of them, it is not practicable to modify each of them. It would be best if I find a way to do that directly with gnuplot.
I also tried it with "sed" but I am not yet further than extracing values from a specific line to a specific line.
If someone could help me with a quick applicable solution for this problem, it would be great.
You could use awk to add the needed columns, e.g.,
splot "<awk '{print int(NR/32),NR%32,$1}' datafile" u 1:2:3 with points
I may have switched the x and y columns around

How do I read the HITRAN2012 database into MATLAB?

The HITRAN database is a listing of molecular rotational-vibrational transitions. It is given in a text file where each line is 160 characters, with fixed width fields defining molecule, isotope, etc. The format is well documented, and there is even a program on the MathWorks File Exchange that will read in the database and simulate a portion of the spectrum. However, I need to read in a specific portion of the spectrum and then use it to do some fitting to a measured spectrum, so I need something much more custom.
As given in the comment section of that function, as well as elsewhere, the following line should read each line in properly:
database = which('HITRAN2012.par');
fid = fopen(database);
hitran = textscan(fid,'%2u%1u%12f%10f%10f%5f%5f%10f%4f%8f%15c%15c%15c%15c%6c%12c%1c%7f%7f','delimiter','','whitespace','');
fclose(fid);
The first two fields denote the molecule code, which runs from 1-47, and the isotope code which runs from 1-9.
Unfortunately, molecules 1-9 do not have a leading zero, and no matter what I do, it seems to silently confuse MATLAB. If I load in the entire database and then type
unique(hitran{1})
I do not get the numbers 1-47, but I get 10-92 with a few numbers missing. As far as I can figure, when MATLAB encounters a leading space, it shifts the line over and then pads the end, so that ' 12' becomes '12', but I'm not exactly sure. I have also tried
hitran = textscan(fid,'%160c','delimiter','\n','whitespace','');
and then tried to parse the resulting strings, but that also sometimes gets confused by the first space.
For instance, the first water line looks like
exampleHitranLine = ' 14 0.007002 1.165E-32 2.071E-14.05870.305 818.00670.590.000000 0 0 0 0 0 0 7 5 2 7 5 3 005540 02227 5 2 0 90.0 90.0';
The first bit of code comes across this line and returns '14' instead of ' 1' and '4'. If I just read in a subset that only contains molecule 1 (as in this example), then the second method of reading works fine. If I try to read in the entire database, however, the lines with molecule 1-9 are shifted the the left, which messes up all the other fields.
I should note that I've tried reading the numerical fields both as floats and as integers, and neither gives satisfactory results. The entire database in text form is nearly 700 MB, and so I need something that works as efficiently as possible.
What am I doing wrong?
I have a new file on the FileExchange that will read in HITRAN 2004+ format data. Please try it out and let me know if there are any issues with it.
I don't have an answer as to why this is happening, but I do have a solution. If anyone has an answer as to why, I'd be happy to accept it.
It is the leading space that is screwing things up. MATLAB is being a little too clever, and when textscan encounters a leading space, it decides that it's extra and discards it and moves on to the next two characters. To get it to properly read in the file, I had to go line by line and test whether the first character is a space and then replace it with a leading zero, like this:
database = which('HITRAN2012_First100Lines.par');
fileParams = dir(database);
K = fileParams.bytes/162;
hitran = cell(K,19);
fid = fopen(database);
for k = 1:K
hitranTemp = fgetl(fid);
if abs(hitranTemp(1)) == 32;
hitranTemp(1) = '0';
end
hitran(k,:) = deal(textscan(hitranTemp,'%2u%1u%12f%10f%10f%5f%5f%10f%4f%8f%15c%15c%15c%15c%6c%12c%1c%7f%7f','delimiter','','whitespace',''));
end
fclose(fid);
I'm working in MATLAB 2013a. Should I consider this to be a bug and report it? Is there some reason that the leading space should be gobbled up like this?
Update:
My workaround above was slow, but worked. Then I had to process the HITEMP database, which is several times larger, so I finally did submit a support ticket to MathWorks. The workaround suggested by MathWorks technical support is to read everything in as text and then convert. This saves a lot of disk reads and works.
fileParams = dir(database);
fid = fopen(database);
hitran = textscan(fid,'%2c%1c%12c%10c%10c%5c%5c%10c%4c%8c%15c%15c%15c%15c%6c%12c%1c%7c%7c','delimiter','','whitespace','');
fclose(fid);
moleculeNumber = uint8(str2num(hitran{1}));
isotopologueNumber = uint8(str2num(hitran{2});
vacuumWavenumber = str2num(hitran{3});
...
etc.
Depending on the application, for larger databases one would probably want to do this in chunks rather than all at once.
He also said he would forward the behavior to the development team for consideration in a future update.

Avoid list being truncated by Matlab

Edit 1 - This question has been solved and it was due to a typo thanks to Floris for spotting this.
I have a one line matrix in Matlab which it is truncating and causing me to loose data.
My code reads:
[status,Vf_rpm_string] = system (fragment_velocity_string);
Vf_rpm_shape=regexprep(Vf_rpm_string,'\n',' ');
Vf_rpm_vector=str2num(Vf_rpm_string);
Vf_rpm= reshape(Vf_rpm_vector,[],1);
The code conducts a system command and stores the result, the result is a Matrix of numbers and sometimes the last line in the matrix has less columns than the previous lines. Matlab doesn't like this, as it does not know what to do with the empty few columns in the last line. So I have to remove the new line character from the results (\n) and replace it with a space.
This was working fine until the results from the system command were too large and so when I remove the new line character (\n) and replace it with a space creating a one line matrix it is too long for Matlab and it truncates it and I loose a lot of my data. So when I convert the returned data (which is returned as a string) to a number it gives me an empty matrix, then the reshape command is pointless at this point.
This is how it reads in Matlab:
20.65866342... Output truncated. Text exceeds maximum line length of 25,000 characters for Command Window display.
So the 20.65866342 is the last value before I start to loose data. I know it says it is too large for the command window but still the variable does not store all the data and it is lost.
Does anyone have any solutions to avoid this truncation?
Or does anyone want to suggest an alternative method for me to convert my data?
I am using Matlab 2012b and Windows 7
Thanks for your time.
Could the problem be that you strip the newlines, but the stripped string isn't the one you are parsing?
[status,Vf_rpm_string] = system (fragment_velocity_string);
Vf_rpm_shape=regexprep(Vf_rpm_string,'\n',' ');
Vf_rpm_vector=str2num(Vf_rpm_string);
Vf_rpm= reshape(Vf_rpm_vector,[],1);
That third line of code should be
Vf_rpm_vector=str2num(Vf_rpm_shape);
if I understand the logic of your code.

Using GraphViz in MATLAB

I tried to plot graphs on MATLAB using GraphViz, using this GraphViz interface.
I keep getting this error:
>> [x,y]=draw_dot(G)
??? Attempted to access node_pos(2); index out of bounds because numel(node_pos)=1.
Error in ==> dot_to_graph at 94
y(lst_node) = node_pos(2);
Error in ==> draw_dot at 30
[trash, names, x, y] = dot_to_graph(tmpLAYOUT); % load NEATO layout
Whats really bugging me is that it worked great before (on my old computer).
Any idea how to solve this problem?
After debugging, I find the solution.
Just find the line 92 in dot_to_graph.m, as written:
[node_pos] = sscanf(line(pos_pos:length(line)), ' pos = "%d,%d"')';
Change the %d,%d to %f,%f. Because there are float numbers in the dot file.
This is difficult to answer completely since you are not giving us the G you are using, so we can't reproduce your problem directly; I'll attempt to answer anyhow "on the dry":
The error messages you get mean that the temporary DOT files created by neato in draw_dot can not be read properly; a line in the dot file which is parsed by dot_to_graph using the format string pos = "%d,%d" is expected to contain two numbers, e.g pos ="42,3", but MATLAB's sscanf only reads one number from that line.
Is it possible that your new computer uses a different language setting, i.e. using a decimal comma instead of a decimal point? This might cause Matlab to read the two numbers as one, not sure how sscanf adapts to local decimal point settings.
Otherwise, are you still using the same version of neato as before? Could it be that its output format has changed in some way?
The best way to find out might be to set a debugging break point in the offending line 94 ([node_pos] = sscanf(line(pos_pos:length(line)), ' pos = "%d,%d"')';) and check what line(pos_pos:length(line)) evaluates to.

Displaying information from MATLAB without a line feed

Is there any way to output/display information from a MATLAB program without an ending line feed?
My MATLAB program outputs a number a bit now and then. Between outputting the number the program does a lot of other stuff. This is a construct mainly to indicate some kind of progress and it would be nice not to have a line feed each time, just to make it more readable for the user. This is approximately what I'm looking for:
Current random seed:
4 7 1 1
The next output from the program would be on the same row if it is still doing the same thing as before.
I've read the doc on disp, sprintf, and format but haven't found what I'm looking for. This doesn't mean it isn't there. ;)
The fprintf function does not add a line feed unless you explicitly tell it to. Omit the fid argument to have it print to the Command Window.
fprintf('Doing stuff... ');
for i = 1:5
fprintf('%d ', i);
% do some work on that pass...
end
fprintf(' done.\n'); % That \n explicitly adds the linefeed
Using sprintf won't quite work: it creates a string without a line feed, but then if you use disp() or omit the semicolon, disp's own display logic will add a line feed.