% Called by salinas.m

  while run_flag > 0
    t = t+1;
    run_flag = run_flag - 1;

    DecayRate = 0.9;
    External = get(gcf,'UserData');

    xi = max(1,min(NEUNITS,floor(NEUNITS*get(inp_slider,'Value'))));
    Hiv = Hvmax * xv(xi,:)' + External;
    Hig = mi .* yi + bi;
    Hi = Hiv + Hig;

    ri = s * max(0, Hi + Wij*ri + minW*sum(ri) - Hth + ...
		 rand(NEUNITS,1)*randscale-randscale./ 2);

    External = External * DecayRate;
    set(gcf,'UserData',External);

    if 1 % ~rem(t,10)
     cla
     h=plot(xpd,ri);
     plot(xpd,External,'r')
     axis([xmin xmax 0 1])
     set(h,'ButtonDownFcn','clickhandler(xv)')
     cospeak = sum(coscoords .* ri) / max(1e-5,sum(ri));
     sinpeak = sum(sincoords .* ri) / max(1e-5,sum(ri));
     peakpos = (atan2(sinpeak,cospeak)+pi)/(2*pi)*NEUNITS;
     peakval = max(ri);
     title(sprintf(...
       'Iteration %4d:  Peak %5.3f at %6.2f   (Bias %4.2f)  Width=%2d', ...
	t,peakval,peakpos,yi,sum(ri>.001)))
     drawnow
    end

  end
