This started with a request for the print command to support iteration, but it turned out that several properties of the current "print" implementation get in the way of this. Two of these are arguably bugs in their own right and should be ironed out before worrying about iteration.
1) The command is inconsistent in separating the items being printed; some combinations have a space inserted between, others not.
2) It is not possible to print an array to a datablock. Should it be? With or without the square brackets? Should there be a function or setting that controls how an array is represented on output?
3) The printerr
command does not work as documented. It is intended to be the same as print
except that it always prints to the screen. Currently set print $DATABLOCK
affects the output of both commands. This is easy to fix.
For 1)
print function on Python behaves the similar asthat of gnuplot e. g.
gives
1.0 2.0 test
Each item is separated by a space.
If one want separate by comma(,) :
For gnuplot :
I do not think that the current state print for gnuplot is strange.
Last edit: Tatsuro MATSUOKA 2022-01-25
Separating by a space is fine. The surprise is that spaces are only added between two successive numerical values, not strings
Indeed, it is strange.
For python print("A", "B", 1, 2, "C", 3)
2)
make an array A
print A
What do you mean by " print an array to a datablock"?
Last edit: Tatsuro MATSUOKA 2022-01-25
Thanks! I understand.
sprintf is very useful for the formatted print.
I think that it is better to mention to sprinftf in explanation of the print command.
Good idea. I will add it as an example.
I have confirmed that you add the explanation of sprintf and gprintf and example to the help and the manual.
Thanks!
The extra space between numbers and alpha characters is messing up my reports and data files. How do I get rid of the extra space?
Use sprintf() to construct a string containing whatever special formatting you need, then print the string.
Thanks for the reply, but I use gnuplot to create graphs and also to write text reports and configuration files for other software all with one large program. There's got to be another way. How about creating a new command called oldprint?
I guess I am not understanding you. Maybe you could show an example of what you were doing previously that no longer works? I will either be able to show how to do the equivalent now, or else understand why it's a new problem and maybe how to improve the options in gnuplot.
The text reports and configuration files have many hundreds of lines of unique text that can't be created with an array. Some of the text is numbers determined from equations. I probably should be using Perl instead, but gnuplot used to make this so easy to do.
There is nothing special about the array; I just used it as an example. Whatever constants or variables you are printing, you can feed them through sprintf for complete control of the output format.
I have figured out how to make sprintf work for me, but the problem is I have probably 10,000 instances to fix that are not a simple search and replace. Making a command that operates the same as print had operated would be more helpful. Am I the only one to have a problem with the new print?
So far as I know you are the first person to report a problem. Admittedly, most people use the release version (5.4) as packaged for Windows or linux, so they would not yet have seen changes like this one that are only in the development version. I'm not trying to discount your problem! The whole purpose of having a separate development branch is so that new features, changes, etc can be thrashed out before they are part of a full release.
I still think it would help me to think about the problem if you gave a specific example. If nothing else it would provide a test case for possible fixes.
Here's a thought. The tabular output produced by
plot ... with table
has a configuration settingset table separator {whitespace|tab|comma|"<char>"}
and defaults to whitespace (blanks) between output fields. Would your use case benefit from having a similar configuration settingset print separator ...
with an option fornone
? That would not be exactly the same as what happens in current release versions because those have the issue of sometimes inserting a space and other times not that was the motivation for this change in the first place.In my case, I always have a number followed by an alpha character, so I never noticed that print inserts spaces differently depending on the situation. Using a configuration setting would be helpful to have. I've found ways to make the changes faster with Notepad++, fortunately.
I'm using version 5.4.4, which I thought was the preferred version once it was released yesterday. I'm using the Windows binary.
Oops. My mistake. I had not remembered that part of this change made it into 5.4.4. I guess this is an instance where a change did not sit in the development version long enough to see testing by anyone who would be in your situation. I apologize. I try to be pretty conservative about what changes go into a minor release version.
I'll re-open this tracker issue and think about how best to move forward.