/* mqspof.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"

/* Common Block Declarations */

struct {
    doublereal vto, beta, gamma, phi, phib, cox, xnsub, xnfs, xd, xj, xld, 
	    xlamda, uo, uexp, vbp, utra, vmax, xneff, xl, xw, vbi, von, vdsat,
	     qspof, beta0, beta1, cdrain, xqco, xqc, fnarrw, fshort;
    integer lev;
} mosarg_;

#define mosarg_1 mosarg_

struct {
    doublereal omega, time, delta, delold[7], ag[7], vt, xni, egfet, xmu, 
	    sfactr;
    integer mode, modedc, icalc, initf, method, iord, maxord, noncon, iterno, 
	    itemno, nosolv, modac, ipiv, ivmflg, ipostp, iscrch, iofile;
} status_;

#define status_1 status_

/*<       subroutine mqspof(vds,vbs,vgs,vpof,vdsat1,vth,vbin,gamasd, >*/
/*<      $qg,qc,qb,cggb,cgdb,cgsb,cbgb,cbdb,cbsb) >*/
/* Subroutine */ int mqspof_(vds, vbs, vgs, vpof, vdsat1, vth, vbin, gamasd, 
	qg, qc, qb, cggb, cgdb, cgsb, cbgb, cbdb, cbsb)
doublereal *vds, *vbs, *vgs, *vpof, *vdsat1, *vth, *vbin, *gamasd, *qg, *qc, *
	qb, *cggb, *cgdb, *cgsb, *cbgb, *cbdb, *cbsb;
{
    static doublereal cbgb1, cgdb1, cbdb1, cggb1, cggb2, cgdb2, cbgb2, cbdb2, 
	    cbsb1, cbsb2, cgsb1, cgsb2, csgb1;
    extern /* Subroutine */ int mosq2_(), mosq3_();
    static doublereal qcpof, qcpof1, qcpof2, qspof2, qd, qs, qb1, qb2, qg1, 
	    qg2;

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

/* spice version 2g.6  sccsid=mosarg 3/15/83 */
/*<       common /mosarg/ vto,beta,gamma,phi,phib,cox,xnsub,xnfs,xd,xj,xld, >*/
/*<      1   xlamda,uo,uexp,vbp,utra,vmax,xneff,xl,xw,vbi,von,vdsat,qspof, >*/
/*<      2   beta0,beta1,cdrain,xqco,xqc,fnarrw,fshort,lev >*/
/* spice version 2g.6  sccsid=status 3/15/83 */
/*<       common /status/ omega,time,delta,delold(7),ag(7),vt,xni,egfet, >*/
/*<      1   xmu,sfactr,mode,modedc,icalc,initf,method,iord,maxord,noncon, >*/
/*<      2   iterno,itemno,nosolv,modac,ipiv,ivmflg,ipostp,iscrch,iofile >*/

/*     vdsat1=dmax1(vds,vdsat1)+1.0d-3 */
/*<       if( lev .eq. 3 ) goto 50 >*/
    if (mosarg_1.lev == 3) {
	goto L50;
    }
/*<       if( lev .ne. 2 ) goto 1000 >*/
    if (mosarg_1.lev != 2) {
	goto L1000;
    }
/*<       call mosq2(vds,vbs,vgs,vdsat,vth,vbin,gamasd,cox,phi, >*/
/*<      $qg,qc,qb,cggb,cgdb,cgsb,cbgb,cbdb,cbsb) >*/
    mosq2_(vds, vbs, vgs, &mosarg_1.vdsat, vth, vbin, gamasd, &mosarg_1.cox, &
	    mosarg_1.phi, qg, qc, qb, cggb, cgdb, cgsb, cbgb, cbdb, cbsb);
/*<       if (vds.ge.vdsat) go to 80 >*/
    if (*vds >= mosarg_1.vdsat) {
	goto L80;
    }
/*<       call mosq2(vds,vbs,vpof,vdsat1,vth,vbin, gamasd,cox,phi, >*/
/*<      $qg1,qcpof1,qb1,cggb1,cgdb1,cgsb1,cbgb1,cbdb1,cbsb1) >*/
    mosq2_(vds, vbs, vpof, vdsat1, vth, vbin, gamasd, &mosarg_1.cox, &
	    mosarg_1.phi, &qg1, &qcpof1, &qb1, &cggb1, &cgdb1, &cgsb1, &cbgb1,
	     &cbdb1, &cbsb1);
/*<       call mosq2(vdsat,vbs,vgs,vdsat,vth,vbin, gamasd,cox,phi, >*/
/*<      $qg2,qcpof2,qb2,cggb2,cgdb2,cgsb2,cbgb2,cbdb2,cbsb2) >*/
    mosq2_(&mosarg_1.vdsat, vbs, vgs, &mosarg_1.vdsat, vth, vbin, gamasd, &
	    mosarg_1.cox, &mosarg_1.phi, &qg2, &qcpof2, &qb2, &cggb2, &cgdb2, 
	    &cgsb2, &cbgb2, &cbdb2, &cbsb2);
/*<       goto 75 >*/
    goto L75;
/*<    50 call mosq3(vds,vbs,vpof,vdsat1,vth,vbin, gamasd,cox,phi, >*/
/*<      $qg,qcpof,qb,cggb1,cgdb1,cgsb1,cbgb1,cbdb1,cbsb1) >*/
L50:
    mosq3_(vds, vbs, vpof, vdsat1, vth, vbin, gamasd, &mosarg_1.cox, &
	    mosarg_1.phi, qg, &qcpof, qb, &cggb1, &cgdb1, &cgsb1, &cbgb1, &
	    cbdb1, &cbsb1);
/*<       call mosq3(vds,vbs,vgs,vdsat,vth,vbin,gamasd,cox,phi, >*/
/*<      $qg,qc,qb,cggb,cgdb,cgsb,cbgb,cbdb,cbsb) >*/
    mosq3_(vds, vbs, vgs, &mosarg_1.vdsat, vth, vbin, gamasd, &mosarg_1.cox, &
	    mosarg_1.phi, qg, qc, qb, cggb, cgdb, cgsb, cbgb, cbdb, cbsb);
/*<    75 if(vgs.gt.vpof. or .vds.lt.vdsat) goto 100 >*/
L75:
    if (*vgs > *vpof || *vds < mosarg_1.vdsat) {
	goto L100;
    }
/*<    80 xqc = xqco >*/
L80:
    mosarg_1.xqc = mosarg_1.xqco;
/*<       goto 1000 >*/
    goto L1000;

/*     tangential limiting of qs */

/*<   100 csgb1=-(1.0d0-xqco)*(cggb1+cbgb1) >*/
L100:
    csgb1 = -(1. - mosarg_1.xqco) * (cggb1 + cbgb1);
/*<       qs=csgb1*(vgs-vpof) >*/
/*<      1   +(1.0d0-xqco)*qcpof1 >*/
    qs = csgb1 * (*vgs - *vpof) + (1. - mosarg_1.xqco) * qcpof1;
/*      write(iofile,*) "vgs,vds,qc,cggb,cgdb,cgsb,cbgb,cbdb,cbsb =", */
/*    1   vgs,vds,qc,cggb,cgdb,cgsb,cbgb,cbdb,cbsb */
/*      write(iofile,*) "vpof,vdsat,vdsat1,qcpof1,qcpof2,qs,csgb1 =", */
/*    1   vpof,vdsat,vdsat1,qcpof1,qcpof2,qs,csgb1 */
/*<       qspof2=(1.0d0-xqco)*qcpof2 >*/
    qspof2 = (1. - mosarg_1.xqco) * qcpof2;
/*<       if (dabs(qs) .lt. dabs(qspof2)) qs=qspof2 >*/
    if (abs(qs) < abs(qspof2)) {
	qs = qspof2;
    }
/*<       if( dabs( qs ) .ge. 0.5d0 * dabs( qc ) ) goto 200 >*/
    if (abs(qs) >= abs(*qc) * .5) {
	goto L200;
    }
/*     csdb=-0.25d0*(cgdb+cbdb) */
/*     qs=qs+csdb*(vdsat-vds) */
/*     xqc=dmin1(0.5d0,(qc-qs)/qc) */
/*<       xqc=0.5d0 >*/
    mosarg_1.xqc = .5;
/*      write(iofile,*) "qs,xqc =", */
/*    1   qs,xqc */
/*<       goto 1000 >*/
    goto L1000;
/*<   200 qd = qc - qs >*/
L200:
    qd = *qc - qs;
/*<       xqc = qd / qc >*/
    mosarg_1.xqc = qd / *qc;
/*     write(iofile,*) "200,qs,qd,xqc =", */
/*    1   qs,qd,xqc */

/*     constant limiting of qs */

/* 100 qdpof = qcpof * xqco */
/*     qspof = qcpof - qdpof */
/*     if( dabs( qspof ) .gt. 0.5d0 * dabs( qc ) ) goto 200 */
/*     xqc = 0.5d0 */
/*     goto 1000 */
/* 200 qd = qc - qspof */
/*     qs = qspof */
/*     xqc = qd / qc */
/*<  1000 return >*/
L1000:
    return 0;
/*<       end >*/
} /* mqspof_ */

