Menu

#2488 "print" command limitations

None
closed
nobody
None
2023-02-01
2022-01-25
No

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.

Discussion

  • Tatsuro MATSUOKA

    For 1)
    print function on Python behaves the similar asthat of gnuplot e. g.

    print(1.0,  2.0, "test")
    

    gives
    1.0 2.0 test
    Each item is separated by a space.
    If one want separate by comma(,) :

    print ("{:},{:},{:}".format(1.0, 2.0, "test"))
    

    For gnuplot :

    print sprintf("%f,%f.%s", 1.0,2.0,"test")
    

    I do not think that the current state print for gnuplot is strange.

     

    Last edit: Tatsuro MATSUOKA 2022-01-25
    • Ethan Merritt

      Ethan Merritt - 2022-01-25

      Separating by a space is fine. The surprise is that spaces are only added between two successive numerical values, not strings

            gnuplot> print "A", "B", 1, 2, "C", 3
      AB1 2C3
      
       
      • Tatsuro MATSUOKA

        Indeed, it is strange.
        For python print("A", "B", 1, 2, "C", 3)

        A B 1 2 C 3
        
         
  • Tatsuro MATSUOKA

    2)
    make an array A

    array A[10]
    do for [i=1:10] { A[i] = i * 10.0 }
    

    print A

    print A
    
    [10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0]
    

    What do you mean by " print an array to a datablock"?

     

    Last edit: Tatsuro MATSUOKA 2022-01-25
    • Ethan Merritt

      Ethan Merritt - 2022-01-25
      array A = [ 1, 2, "three", 4.0 ]
      set print $FOO
      print "before", A, "after"
      unset print 
      print "datablock $FOO contains: " , $FOO
      
       
  • Tatsuro MATSUOKA

    Thanks! I understand.

     
  • Tatsuro MATSUOKA

    sprintf is very useful for the formatted print.
    I think that it is better to mention to sprinftf in explanation of the print command.

     
    • Ethan Merritt

      Ethan Merritt - 2022-01-26

      Good idea. I will add it as an example.

       
      • Tatsuro MATSUOKA

        I have confirmed that you add the explanation of sprintf and gprintf and example to the help and the manual.
        Thanks!

         
  • Ethan Merritt

    Ethan Merritt - 2022-01-27
    • status: open --> pending-fixed
     
  • Ethan Merritt

    Ethan Merritt - 2022-07-11
    • Status: pending-fixed --> closed-fixed
     
  • Dennis Han

    Dennis Han - 2022-07-19
     
  • Dennis Han

    Dennis Han - 2022-07-19

    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?

     
    • Ethan Merritt

      Ethan Merritt - 2022-07-19

      Use sprintf() to construct a string containing whatever special formatting you need, then print the string.

      array base = [1, 2, 3, 4, 5]
      array ext = ["a", "b", "c","d","e"]
      
      print for [i=1:5] sprintf("%d%s", base[i],ext[i])
          1a 2b 3c 4d 5e
      
       
  • Dennis Han

    Dennis Han - 2022-07-19

    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?

     
    • Ethan Merritt

      Ethan Merritt - 2022-07-19

      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.

       
  • Dennis Han

    Dennis Han - 2022-07-19

    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.

     
    • Ethan Merritt

      Ethan Merritt - 2022-07-19

      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.

       
  • Dennis Han

    Dennis Han - 2022-07-19

    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?

     
    • Ethan Merritt

      Ethan Merritt - 2022-07-19

      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 setting set table separator {whitespace|tab|comma|"<char>"} and defaults to whitespace (blanks) between output fields. Would your use case benefit from having a similar configuration setting set print separator ... with an option for none? 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.

       
  • Dennis Han

    Dennis Han - 2022-07-19

    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.

     
    • Ethan Merritt

      Ethan Merritt - 2022-07-19

      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.

       
  • Ethan Merritt

    Ethan Merritt - 2022-07-19
    • status: closed-fixed --> open
     
  • Ethan Merritt

    Ethan Merritt - 2023-02-01
    • status: open --> closed
     

Log in to post a comment.