Keep track of iterations between calls, change script to do outer loop in R to allow Ctl-C interuption.