Menu

#2656 inline data (as distinct from data block) is not allowed within a function block ... but generates no error message

None
closed-fixed
nobody
None
2023-12-30
2023-09-26
najevi
No

The same piece of demo script is submitted for 4 separately reported bugs.

The ban on defining a data block within a function block is well documented.
It may be a bit cheeky to try getting away with an inline data for plot (ie.e via '-' as the data source) however I am not likely to be the last person to try doing so.

No error is reported and the script execution hangs. Normal Ctrl+C does not terminate the script. The only method of termination I could discover was to locate the gnuplot.exe process and kill it via windows task manager.

## Some bugs related to function blocks and/or data blocks 
##  (gnuplot v6 rc1  on Windows 11)
##
## Given that function blocks are still experiemental I hesitate to call these "bugs" however,
## they are definitely not intuitive/expeceted behaviour. 
## To experience each bug uncomment that/those script line(s) that has/have just a single hash '#'.
##
##(1) using the backslash "\" to break a (very long) plot command across multiple lines (within a function block) throws an error: "invalid character \"
##(2) datablock definition within an if or else compound statement throws error: "attempt to define data block from invalid context"
##(3) "function block" usage of the special string variables, ARGC, ARG0, ARG1..ARG9 is not consistent with "call" usage
##(3a) cannot access ARGV[1] as the string, ARG1; 
##(3b) cannot access function block name as ARG0; (script filename is returned instead)
##(3c) ... but _can_ access argument count for function block as ARGC
##(4) inline data "plot '-'" may not be used within a function block (somewhat akin to the ban on defining a data block within a function block)
##

function $myPlot(strSource,strFont) << _EOFD
    set title strSource." - variable color and orientation in plotstyle 'with labels'" offset 0,-2

    ## within a function block, a backslash throws the error: "invalid character \" .. but not within main script block
    #plot @strSource \
    #   using 1:1:2:3:0 \
    #   with labels rotate variable tc variable font @strFont
    plot @strSource using 1:1:2:3:0 with labels rotate variable tc variable font @strFont

    ## ARG0 returns script filename (not function block name) ..  but ARGC correctly returns a count of arguments passed to function
    ##return sprintf("function, %s, completed; with %d arguments", "$myPlot", ARGC)
    return sprintf("function, %s, completed; with %d arguments", ARG0, ARGC)
_EOFD

function $myInlinePlot << _EOFD
    set title "function block INLINE - variable color and orientation in plotstyle 'with labels'" offset 0,-2
    ## within a function block, attempting to use inline data as the data source causes script execution to hang without any error message
    ## ... Ctrl+C will not terminate script execution from this point
    ## ... the only remedy I have found is to locate the hung gnuplot.exe process and terminate it 
    plot '-' using 1:1:2:3:0 with labels rotate variable tc variable font ",8"
1 one -30
2 two -60
3 three -90
4 four -120
5 five -150
6 six -180
7 seven -210
8 eight -240
9 nine -270
10 ten -300
11 eleven -330
12 twelve -360
EOD
    ## it seems that inline data may not be used within a function block 
    ## (somewhat akin to the ban on defining a data block within a function block)
    ## however, the script hangs without any error message
    return sprintf("function, %s, completed; with %d arguments", "$myInlinePlot", ARGC)
_EOFD

##
## Additional data columns can be used to hold text rotation or color
## for plot style "with labels"
##

debug = 1

#if (debug) {   ## defining a datablock inside an if/else throws: "attempt to define data block from invalid context"
    $Data1 <<EOD
    1 one -30
    2 two -60
    3 three -90
    4 four -120
    5 five -150
    6 six -180
    7 seven -210
    8 eight -240
    9 nine -270
    10 ten -300
    11 eleven -330
    12 twelve -360
EOD
## leading whitespace before the above EOD _does_ throw an error: "no datablock named $Data2"
##  ... fair enough since $Data1 definition never correctly ends if EOD not found at start of line.
#   }
#else {
$Data2 <<EOD
1 one -30
2 two -60
3 three -90
4 four -120
5 five -150
6 six -180
7 seven -210
8 eight -240
9 nine -270
10 ten -300
11 eleven -330
12 twelve -360
EOD
#   }

$Data3 <<EOD
1 one -30
2 two -60
3 three -90
4 four -120
5 five -150
6 six -180
7 seven -210
8 eight -240
9 nine -270
10 ten -300
11 eleven -330
12 twelve -360
EOD

set angle degrees
unset key
set title "variable color and orientation in plotstyle 'with labels'" offset 0,-2

set xrange [0:13]
set yrange [0:13]
set xtics 1,1,12 nomirror
set ytics 1,1,12 nomirror
set border 3

stringFont = "\"Times,10\""     ## exercising care to escape double quotes is necessary (and appropriate)
##plot $Data3 using 1:1:2:3:0 with labels rotate variable tc variable font ",20"
## no error from using backslash to break the above plot command over multiple lines
plot $Data3 \
    using 1:1:2:3:0 \
    with labels rotate variable tc variable font @stringFont
pause mouse close

printerr $myPlot("$Data1","\"Times,12\"")
pause mouse close

printerr $myPlot("$Data2","\"Times,16\"")
pause mouse close

printerr $myPlot("$Data3","\"Times,20\"")
pause mouse close

set title "INLINE - variable color and orientation in plotstyle 'with labels'" offset 0,-2
plot '-' using 1:1:2:3:0 with labels rotate variable tc variable font ",24"
    1 one -30
    2 two -60
    3 three -90
    4 four -120
    5 five -150
    6 six -180
    7 seven -210
    8 eight -240
    9 nine -270
    10 ten -300
    11 eleven -330
    12 twelve -360
EOD
#   EOD
    ## leading whitespace before EOD, above, does not _seem_ to matter however,
    ## for the inline data example within a function block this leading whitspace was avoided just to remove any possible doubt
pause mouse close

## to demonstrate bug (4) (and this script hanging without any error message) uncomment the following function call
#printerr $myInlinePlot()
#pause mouse close

Discussion

  • najevi

    najevi - 2023-09-26

    The inline data example given is a poor one. The following is a more realistic one that I think emphasizes why a user would want/expect to freely use inline data within a function block.

    local strN = sprintf("%d",ARGV[1])
    :
    :
    plot @inFile \
        using ($f($1)[3]) : ($f($1)[4]) : ($f($1)[5]) : ($f($1)[6]) : ($f($1)[7]) \
        with sectors linecolor @varColor \
        , '-' using 1:2:3:4:5 with sectors linecolor variable # NOTE: the use of inline data, '-', throws no error but hangs script execution
    0 0 2 @strN 0
    EOD
    

    ... and how much more elegant/streamlined that would be if the simple string variable, ARG1, might be used instead of ARGV[1] !

    plot @inFile \
        using ($f($1)[3]) : ($f($1)[4]) : ($f($1)[5]) : ($f($1)[6]) : ($f($1)[7]) \
        with sectors linecolor @varColor \
        , '-' using 1:2:3:4:5 with sectors linecolor variable # NOTE: the use of inline data, '-', throws no error but hangs script execution
    0 0 2 @ARG1 0
    EOD
    
     
  • Ethan Merritt

    Ethan Merritt - 2023-09-29
    • status: open --> pending-fixed
    • Group: -->
    • Priority: -->
     
  • Ethan Merritt

    Ethan Merritt - 2023-09-29

    This is a real bug. Or at least it is true that trying to read from pseudofile '-' inside a function block does not do the "obvious" thing. Instead it tries to read from stdin, or if you are executing from a file then it tries to read from that file. That makes sense of a sort, but there is very little chance that it is what the user really wants. So it should be added to the set of restrictions on what can be done inside a function block.

    Now trapped as an error and documented as a restriction.

     
  • Ethan Merritt

    Ethan Merritt - 2023-12-30
    • Status: pending-fixed --> closed-fixed
     

Log in to post a comment.