Menu

#2017 Cannot CTRL-C from interrupted fit

None
closed-not-a-bug
nobody
None
2018-02-12
2018-01-31
No

When interrupting a bad fit via CTRL-C, you're offered the choice to Stop fit/Continue/Execute script, but you cannot stop the whole script, e.g. by pressing CRTL-C another time.

So if you are in a loop, fitting a larger number of datasets, you can't get out except by killing gnuplot.

I thought about putting "exit" or "break" into FIT_SCRIPT via "set fit script" but that doesn't work. Should it?

Here's an ugly four-liner for testing:

set samp 400
f(x) = (d=d/1.2,(a+d)*cos(b+x*c));a=b=c=d=1
plot "+" us 1:(1+rand(0.)),f(x)
while (1) {a=b=c=d=1;fit f(x) "+" us 1:(1+rand(0.)) via a,b,c}

(I couldn't think of a simple artificial fit that really takes forever, so you sometimes can stop this one with CTRL-C if you hit it between two fits.)

I'm on win7/gp5.2.pl2 .

Discussion

  • Ethan Merritt

    Ethan Merritt - 2018-02-01

    I have never looked at this before, so all I can offer from the top of my head is a variant on "don't do that!". Instead make an exit condition for your loop and have the fit script set that condition. E.g.

    set samp 400
    f(x) = (d=d/1.2,(a+d)*cos(b+x*c));a=b=c=d=1
    plot "+" us 1:(1+rand(0.)),f(x)
    done = 0
    set fit script "done = 1"
    while (!done) {a=b=c=d=1;fit f(x) "+" us 1:(1+rand(0.)) via a,b,c}
    

    That works but requires 2 ctrl-C operations:
    (S)top fit, (C)ontinue, (E)xecute FIT_SCRIPT: e
    executing: done = 1
    (S)top fit, (C)ontinue, (E)xecute FIT_SCRIPT: c
    gnuplot>

    If you dig deeper maybe you can construct a variant that works on the 1st ctrl-C.

    If what you want is to exit the whole gnuplot session rather than return to the command line, another option is:

    set samp 400
    f(x) = (d=d/1.2,(a+d)*cos(b+x*c));a=b=c=d=1
    plot "+" us 1:(1+rand(0.)),f(x)
    set print "exit_command"
    print "exit gnuplot"
    unset print
    set fit script "load 'exit_command'"
    done = 0
    while (!done) {a=b=c=d=1;fit f(x) "+" us 1:(1+rand(0.)) via a,b,c}
    
     
    • Karl Ratzsch

      Karl Ratzsch - 2018-02-01

      Thanks! Good idea to set a flag in FIT_SCRIPT, that works fine.

      Less elegant: I found that hitting CTRL-C several times before pressing "S"(top) also most of the time ends the script.

       
      • Ethan Merritt

        Ethan Merritt - 2018-02-02

        Simplest (and stupidest) solution so far:
        set fit script "abcdef"
        while (1) { fit ... }
        ctrl-C
        (S)top fit, (C)ontinue, (E)xecute FIT_SCRIPT: e
        executing: abcdef
        gnuplot> abcdef
        ^
        line 5: invalid command
        gnuplot>

         
  • Ethan Merritt

    Ethan Merritt - 2018-02-12
    • status: open --> closed-not-a-bug
    • Group: -->
    • Priority: -->
     

Log in to post a comment.

MongoDB Logo MongoDB