Credits Overview Plotting Styles Commands Terminals

error recovery

Starting with gnuplot version 6, the fit command always returns to the next command input line regardless of the success or failure of fitting. This allows scripted recovery from fit errors. The variable FIT_ERROR is set to 0 on success, non-zero on error. This example plots however many of five data sets can be successfully fit. Failure for data set 2 would not prevent fitting data sets 3 through 5.

     do for [i=1:5] {
         DATA = sprintf("Data_%05d.dat", i)
         fit f(x) DATA via a,b,c
         if (FIT_ERROR || !FIT_CONVERGED) {
             print "Fit failed for ", DATA
             continue
         }
         set output sprintf("dataset_%05.png", i)
         plot DATA, f(x)
         unset output
     }