/* pnjlim.f -- translated by f2c (version of 3 February 1990  3:36:42).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/*<       subroutine pnjlim(vnew,vold,vt,vcrit,icheck) >*/
/* Subroutine */ int pnjlim_(vnew, vold, vt, vcrit, icheck)
doublereal *vnew, *vold, *vt, *vcrit;
integer *icheck;
{
    /* Builtin functions */
    double log();

    /* Local variables */
    static doublereal delv, vlim, arg;

/*<       implicit double precision (a-h,o-z) >*/

/*     this routine limits the change-per-iteration of device pn-junction 
*/
/* voltages. */

/*<       if (vnew.le.vcrit) go to 30 >*/
    if (*vnew <= *vcrit) {
	goto L30;
    }
/*<       vlim=vt+vt >*/
    vlim = *vt + *vt;
/*<       delv=vnew-vold >*/
    delv = *vnew - *vold;
/*<       if (dabs(delv).le.vlim) go to 30 >*/
    if (abs(delv) <= vlim) {
	goto L30;
    }
/*<       if (vold.le.0.0d0) go to 20 >*/
    if (*vold <= 0.) {
	goto L20;
    }
/*<       arg=1.0d0+delv/vt >*/
    arg = delv / *vt + 1.;
/*<       if (arg.le.0.0d0) go to 10 >*/
    if (arg <= 0.) {
	goto L10;
    }
/*<       vnew=vold+vt*dlog(arg) >*/
    *vnew = *vold + *vt * log(arg);
/*<       go to 100 >*/
    goto L100;
/*<    10 vnew=vcrit >*/
L10:
    *vnew = *vcrit;
/*<       go to 100 >*/
    goto L100;
/*<    20 vnew=vt*dlog(vnew/vt) >*/
L20:
    *vnew = *vt * log(*vnew / *vt);
/*<       go to 100 >*/
    goto L100;
/*<    30 icheck=0 >*/
L30:
    *icheck = 0;

/*  finished */

/*<   100 return >*/
L100:
    return 0;
/*<       end >*/
} /* pnjlim_ */

