// Model generated by Verilog-A Distiller.
// (c)2026 Arpad Buermen. All rights reserved.
// SPDX-License-Identifier: AGPL-3.0-or-later
// 
// SPICE flavour: ngspice
// Version      : ngspice-44-549-ga4ff5a204
// Origin       : https://sourceforge.net/u/arpadbuermen/ngspice/ci/vadng-pre-48/tree/
// Date         : 2026-08-18 12:20:17 UTC
// Module name  : sp_bsim4v8
// Model variant: default
// 
// Notes:
//   Parameter m was replaced with builtin Verilog-A parameter $mfactor.
//
//   All parameters and output variables refer to a single parallel instance,
//   even if $mfactor>1.
//
//   Parameter off was removed. Bypassing is not available in Verilog-A. 
//   
//   Device type is set by the type parameter to NMOS (1) or PMOS (-1). 
//   
//   Instance parameters acnqsmod, trnqsmod, rbodymod, rgatemod, geomod, 
//   rgeomod, cgso, cgdo, cgbo, xgw, ngcon, rbdb, rbsb, rbpb, rbps, rbpd, 
//   and min were prefixed with instance_ (i.e. nqsmod was renamed to 
//   instance_nqsmod). 
//   
//   Parameters ic, icvds, icvgs, and icvbs were removed. Initial conditions 
//   should be set via the simulator's initial conditions mechanism. 
//   
//   Parameters acnqsmod and instance_acnqsmod have the same effect as 
//   trnqsmod and instance_trnqsmod. Verilog-A does not provide frequency 
//   domain modelling for ac analysis. The NQS model always uses the lumped 
//   approximation. 
//   
//   The BSIM4 AC NQS model is independent of the transient NQS model. 
//   Unfortunately it is not consistent with the transient NQS model. 
//   In this Verilog-A implementation the original AC NQS model is not 
//   available. In AC analysis the linearized version of the trnqs model is used. 
//   
//   When used with Ngspice, compile the module with __NGSPICE__ defined. 
//   This will rename the gate resistor noise for rgratemod=3 from rg into rg3. 
//   This is necessary because the gate resistor noise for rgatemod=3 
//   contributes to a different branch than for rgatemod<3. Due to different 
//   references these two noise sources cannot be merged into one by 
//   VADistiller. Unfortunately Ngspice also does not know how to merge 
//   multiple noise sources with the same name into a single contribution. 
//   Therefore the only solution is to rename one of the two rg contributions.
//
//   Full noise model used (appropriate for all noise analyses).
//
// SPICE variable mapping
//   scale -> $simparam("scale", 1)
//
// CKTcircuit member mapping
//      CKTgmin -> ('gmin', '$simparam("gmin", 1e-12)')
//   CKTnomTemp -> ('tnom', '($simparam("tnom", 27)+273.15)')
//      CKTtemp -> (None, '$temperature')
//
// Source files and copyright information:
//   bsim4/b4geo.c
//   bsim4/bsim4def.h
//   bsim4/b4.c
//   bsim4/b4par.c
//   bsim4/b4mpar.c
//   bsim4/b4ask.c
//   bsim4/b4mask.c
//   bsim4/b4set.c
//   bsim4/b4temp.c
//   bsim4/b4ld.c
//   bsim4/b4noi.c
//        ******************************************************************************
//        *  BSIM4 4.8.3 released on 05/19/2025                                        *
//        *  BSIM4 Model Equations                                                     *
//        ******************************************************************************
//     
//        ******************************************************************************
//        *  Copyright (c) 2025 University of California                               *
//        *                                                                            *
//        *  Project Directors: Prof. Sayeef Salahuddin and Prof. Chenming Hu          *
//        *  Developers list: https://www.bsim.berkeley.edu/models/bsim4/auth_bsim4/   *
//        ******************************************************************************
//     Licensed under Educational Community License, Version 2.0 (the "License"); you may
//     not use this file except in compliance with the License. You may obtain a copy of the license at
//     http://opensource.org/licenses/ECL-2.0
//     Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations
//     under the License.
//     
//     BSIM4 model is supported by the members of Silicon Integration Initiative's Compact Model Coalition. A link to the most recent version of this
//     standard can be found at: http://www.si2.org/cmc

`include "constants.vams"
`include "disciplines.vams"

module sp_bsim4v8(d, g, s, b);
  inout d, g, s, b;
  electrical d, g, s, b, d_int, g_int, gmid_int, s_int, b_int, db_int, sb_int, q_int, noise_int;
  branch (noise_int) noise_br_i;
  branch (noise_int) noise_br_r;
  branch (noise_int) noise_br_c;

  // Instance parameters
  (* desc = "Length", type = "instance" *) parameter real l = 5e-06;
  (* desc = "Width", type = "instance" *) parameter real w = 5e-06;
  (* desc = "Number of fingers", type = "instance" *) parameter real nf = 1.0;
  (* desc = "distance between  OD edge to poly of one side ", type = "instance" *) parameter real sa = 0.0;
  (* desc = "distance between  OD edge to poly of the other side", type = "instance" *) parameter real sb = 0.0;
  (* desc = "distance between neighbour fingers", type = "instance" *) parameter real sd = 0;
  (* desc = "Integral of the first distribution function for scattered well dopant", type = "instance" *) parameter real sca = 0.0;
  (* desc = "Integral of the second distribution function for scattered well dopant", type = "instance" *) parameter real scb = 0.0;
  (* desc = "Integral of the third distribution function for scattered well dopant", type = "instance" *) parameter real scc = 0.0;
  (* desc = "Distance to a single well edge ", type = "instance" *) parameter real sc = 0.0;
  (* desc = "Minimize either D or S", type = "instance" *) parameter integer instance_min = 0;
  (* desc = "Drain area", type = "instance" *) parameter real ad = 0.0;
  (* desc = "Source area", type = "instance" *) parameter real as = 0.0;
  (* desc = "Drain perimeter", type = "instance" *) parameter real pd = 0.0;
  (* desc = "Source perimeter", type = "instance" *) parameter real ps = 0.0;
  (* desc = "Number of squares in drain", type = "instance" *) parameter real nrd = 1.0;
  (* desc = "Number of squares in source", type = "instance" *) parameter real nrs = 1.0;
  (* desc = "Body resistance", type = "instance" *) parameter real instance_rbdb = 0;
  (* desc = "Body resistance", type = "instance" *) parameter real instance_rbsb = 0;
  (* desc = "Body resistance", type = "instance" *) parameter real instance_rbpb = 0;
  (* desc = "Body resistance", type = "instance" *) parameter real instance_rbps = 0;
  (* desc = "Body resistance", type = "instance" *) parameter real instance_rbpd = 0;
  (* desc = "Zero bias threshold voltage variation", type = "instance" *) parameter real delvto = 0.0;
  aliasparam delvt0 = delvto;
  (* desc = "Low field mobility multiplier", type = "instance" *) parameter real mulu0 = 1.0;
  (* desc = "Distance from gate contact center to device edge", type = "instance" *) parameter real instance_xgw = 0;
  (* desc = "Number of gate contacts", type = "instance" *) parameter real instance_ngcon = 0;
  (* desc = "W/NF device flag for bin selection", type = "instance" *) parameter integer wnflag = 0;
  (* desc = "Instance temperature difference", type = "instance" *) parameter real dtemp = 0;
  (* desc = "Transient NQS model selector", type = "instance" *) parameter integer instance_trnqsmod = 0;
  (* desc = "AC NQS model selector", type = "instance" *) parameter integer instance_acnqsmod = 0;
  (* desc = "Distributed body R model selector", type = "instance" *) parameter integer instance_rbodymod = 0;
  (* desc = "Gate resistance model selector", type = "instance" *) parameter integer instance_rgatemod = 0;
  (* desc = "Geometry dependent parasitics model selector", type = "instance" *) parameter integer instance_geomod = 0;
  (* desc = "S/D resistance and contact model selector", type = "instance" *) parameter integer instance_rgeomod = 0;
  (* desc = "Variability in current", type = "instance" *) parameter real mult_i = 1.0;
  (* desc = "Variability in charge", type = "instance" *) parameter real mult_q = 1.0;
  (* desc = "Variability in flicker noise", type = "instance" *) parameter real mult_fn = 0;

  // Model parameters
  (* desc = "Capacitance Charge model selector" *) parameter integer cvchargemod = 0;
  (* desc = "Capacitance model selector" *) parameter integer capmod = 2;
  (* desc = "Diode IV model selector" *) parameter integer diomod = 1;
  (* desc = "Bias-dependent S/D resistance model selector" *) parameter integer rdsmod = 0;
  (* desc = "Transient NQS model selector" *) parameter integer trnqsmod = 0;
  (* desc = "AC NQS model selector" *) parameter integer acnqsmod = 0;
  (* desc = "Mobility model selector" *) parameter integer mobmod = 0;
  (* desc = "Distributed body R model selector" *) parameter integer rbodymod = 0;
  (* desc = "Gate R model selector" *) parameter integer rgatemod = 0;
  (* desc = "Pd and Ps model selector" *) parameter integer permod = 1;
  (* desc = "Geometry dependent parasitics model selector" *) parameter integer geomod = 0;
  (* desc = "Flicker noise model selector" *) parameter integer fnoimod = 1;
  (* desc = "Thermal noise model selector" *) parameter integer tnoimod = 0;
  (* desc = "parameter for non-silicon substrate or metal gate selector" *) parameter integer mtrlmod = 0;
  (* desc = "New Material Mod backward compatibility selector" *) parameter integer mtrlcompatmod = 0;
  (* desc = "Gate-to-channel Ig model selector" *) parameter integer igcmod = 0;
  (* desc = "Gate-to-body Ig model selector" *) parameter integer igbmod = 0;
  (* desc = "Temperature model selector" *) parameter integer tempmod = 0;
  (* desc = "parameter for GIDL selector" *) parameter integer gidlmod = 0;
  (* desc = "Model parameter checking selector" *) parameter integer paramchk = 1;
  (* desc = "Bin  unit  selector" *) parameter integer binunit = 1;
  (* desc = "parameter for model version" *) parameter string version = "4.8.3";
  (* desc = "Equivalent gate oxide thickness in meters" *) parameter real eot = 1.5e-09;
  (* desc = "Voltage for extraction of Equivalent gate oxide thickness" *) parameter real vddeot = 0;
  (* desc = " Temperature for extraction of EOT" *) parameter real tempeot = 300.15;
  (* desc = " Effective length for extraction of EOT" *) parameter real leffeot = 1;
  (* desc = "Effective width for extraction of EOT" *) parameter real weffeot = 10;
  (* desc = "Charge centroid parameter" *) parameter real ados = 1.0;
  (* desc = "Charge centroid parameter" *) parameter real bdos = 1.0;
  (* desc = "Electrical gate oxide thickness in meters" *) parameter real toxe = 3e-09;
  (* desc = "Physical gate oxide thickness in meters" *) parameter real toxp = 0;
  (* desc = "Gate oxide thickness at which parameters are extracted" *) parameter real toxm = 0;
  (* desc = "Target tox value" *) parameter real toxref = 3e-09;
  (* desc = "Defined as (toxe - toxp) " *) parameter real dtox = 0.0;
  (* desc = "Dielectric constant of the gate oxide relative to vacuum" *) parameter real epsrox = 3.9;
  (* desc = "Drain/Source and channel coupling capacitance" *) parameter real cdsc = 0.00024;
  (* desc = "Body-bias dependence of cdsc" *) parameter real cdscb = 0.0;
  (* desc = "Drain-bias dependence of cdsc" *) parameter real cdscd = 0.0;
  (* desc = "Interface state capacitance" *) parameter real cit = 0.0;
  (* desc = "Subthreshold swing Coefficient" *) parameter real nfactor = 1.0;
  (* desc = "Junction depth in meters" *) parameter real xj = 1.5e-07;
  (* desc = "Saturation velocity at tnom" *) parameter real vsat = 80000.0;
  (* desc = "Temperature coefficient of vsat" *) parameter real at = 33000.0;
  (* desc = "Non-uniform depletion width effect coefficient." *) parameter real a0 = 1.0;
  (* desc = "Gate bias  coefficient of Abulk." *) parameter real ags = 0.0;
  (* desc = "Non-saturation effect coefficient" *) parameter real a1 = 0.0;
  (* desc = "Non-saturation effect coefficient" *) parameter real a2 = 1.0;
  (* desc = "Body-bias coefficient of non-uniform depletion width effect." *) parameter real keta = 0;
  (* desc = "Body-bias coefficient of non-uniform depletion width effect in dynamic evaluation." *) parameter real ketac = 0;
  (* desc = "Work function of gate" *) parameter real phig = 4.05;
  (* desc = "Dielectric constant of gate relative to vacuum" *) parameter real epsrgate = 11.7;
  (* desc = "Electron affinity of substrate" *) parameter real easub = 4.05;
  (* desc = "Dielectric constant of substrate relative to vacuum" *) parameter real epsrsub = 11.7;
  (* desc = "Intrinsic carrier concentration of substrate at 300.15K" *) parameter real ni0sub = 14500000000.0;
  (* desc = "Band-gap of substrate at T=0K" *) parameter real bg0sub = 1.16;
  (* desc = "First parameter of band-gap change due to temperature" *) parameter real tbgasub = 0.000702;
  (* desc = "Second parameter of band-gap change due to temperature" *) parameter real tbgbsub = 1108.0;
  (* desc = "Substrate doping concentration" *) parameter real nsub = 6e+16;
  (* desc = "Channel doping concentration at the depletion edge" *) parameter real ndep = 1.7e+17;
  (* desc = "S/D doping concentration" *) parameter real nsd = 1e+20;
  (* desc = "Adjusting parameter for surface potential due to non-uniform vertical doping" *) parameter real phin = 0.0;
  (* desc = "Poly-gate doping concentration" *) parameter real ngate = 0;
  (* desc = "Vth body coefficient" *) parameter real gamma1 = 0.0;
  (* desc = "Vth body coefficient" *) parameter real gamma2 = 0.0;
  (* desc = "Vth transition body Voltage" *) parameter real vbx = 0.0;
  (* desc = "Maximum body voltage" *) parameter real vbm = 0;
  (* desc = "Doping depth" *) parameter real xt = 1.55e-07;
  (* desc = "Bulk effect coefficient 1" *) parameter real k1 = 0;
  (* desc = "Temperature coefficient of Vth" *) parameter real kt1 = 0;
  (* desc = "Temperature coefficient of Vth" *) parameter real kt1l = 0.0;
  (* desc = "Body-coefficient of kt1" *) parameter real kt2 = 0.022;
  (* desc = "Bulk effect coefficient 2" *) parameter real k2 = 0;
  (* desc = "Narrow width effect coefficient" *) parameter real k3 = 80.0;
  (* desc = "Body effect coefficient of k3" *) parameter real k3b = 0.0;
  (* desc = "Narrow width effect parameter" *) parameter real w0 = 2.5e-06;
  (* desc = "First parameter for Vth shift due to pocket" *) parameter real dvtp0 = 0.0;
  (* desc = "Second parameter for Vth shift due to pocket" *) parameter real dvtp1 = 0.0;
  (* desc = "3rd parameter for Vth shift due to pocket" *) parameter real dvtp2 = 0.0;
  (* desc = "4th parameter for Vth shift due to pocket" *) parameter real dvtp3 = 0.0;
  (* desc = "5th parameter for Vth shift due to pocket" *) parameter real dvtp4 = 0.0;
  (* desc = "6th parameter for Vth shift due to pocket" *) parameter real dvtp5 = 0.0;
  (* desc = "Equivalent length of pocket region at zero bias" *) parameter real lpe0 = 1.74e-07;
  (* desc = "Equivalent length of pocket region accounting for body bias" *) parameter real lpeb = 0.0;
  (* desc = "Short channel effect coeff. 0" *) parameter real dvt0 = 2.2;
  (* desc = "Short channel effect coeff. 1" *) parameter real dvt1 = 0.53;
  (* desc = "Short channel effect coeff. 2" *) parameter real dvt2 = 0;
  (* desc = "Narrow Width coeff. 0" *) parameter real dvt0w = 0.0;
  (* desc = "Narrow Width effect coeff. 1" *) parameter real dvt1w = 5300000.0;
  (* desc = "Narrow Width effect coeff. 2" *) parameter real dvt2w = 0;
  (* desc = "DIBL coefficient of output resistance" *) parameter real drout = 0.56;
  (* desc = "DIBL coefficient in the subthreshold region" *) parameter real dsub = 0;
  (* desc = "Threshold voltage" *) parameter real vth0 = 0;
  aliasparam vtho = vth0;
  (* desc = "Linear gate dependence of mobility" *) parameter real ua = 0;
  (* desc = "Temperature coefficient of ua" *) parameter real ua1 = 1e-09;
  (* desc = "Quadratic gate dependence of mobility" *) parameter real ub = 1e-19;
  (* desc = "Temperature coefficient of ub" *) parameter real ub1 = 0;
  (* desc = "Body-bias dependence of mobility" *) parameter real uc = 0;
  (* desc = "Temperature coefficient of uc" *) parameter real uc1 = 0;
  (* desc = "Coulomb scattering factor of mobility" *) parameter real ud = 0.0;
  (* desc = "Temperature coefficient of ud" *) parameter real ud1 = 0.0;
  (* desc = "Channel length linear factor of mobility" *) parameter real up = 0.0;
  (* desc = "Channel length exponential factor of mobility" *) parameter real lp = 1e-08;
  (* desc = "Low-field mobility at Tnom" *) parameter real u0 = 0;
  (* desc = "Mobility exponent" *) parameter real eu = 0;
  (* desc = "Colombic scattering exponent" *) parameter real ucs = 0;
  (* desc = "Temperature coefficient of mobility" *) parameter real ute = 0;
  (* desc = "Temperature coefficient of colombic mobility" *) parameter real ucste = 0;
  (* desc = "Threshold voltage offset" *) parameter real voff = 0;
  (* desc = "Fitting parameter for moderate inversion in Vgsteff" *) parameter real minv = 0.0;
  (* desc = "Fitting parameter for moderate inversion in Vgsteffcv" *) parameter real minvcv = 0.0;
  (* desc = "Length dependence parameter for Vth offset" *) parameter real voffl = 0.0;
  (* desc = "Length dependence parameter for Vth offset in CV" *) parameter real voffcvl = 0.0;
  (* desc = "Parameter measurement temperature" *) parameter real tnom = 0;
  (* desc = "Gate-source overlap capacitance per width" *) parameter real cgso = 0;
  (* desc = "Gate-drain overlap capacitance per width" *) parameter real cgdo = 0;
  (* desc = "Gate-bulk overlap capacitance per length" *) parameter real cgbo = 0;
  (* desc = "Channel charge partitioning" *) parameter real xpart = 0.0;
  (* desc = "Effective Vds parameter" *) parameter real delta = 0.01;
  (* desc = "Source-drain sheet resistance" *) parameter real rsh = 0.0;
  (* desc = "Source-drain resistance per width" *) parameter real rdsw = 200.0;
  (* desc = "Source-drain resistance per width at high Vg" *) parameter real rdswmin = 0.0;
  (* desc = "Source resistance per width" *) parameter real rsw = 100.0;
  (* desc = "Drain resistance per width" *) parameter real rdw = 100.0;
  (* desc = "Drain resistance per width at high Vg" *) parameter real rdwmin = 0.0;
  (* desc = "Source resistance per width at high Vg" *) parameter real rswmin = 0.0;
  (* desc = "Gate-bias effect on parasitic resistance " *) parameter real prwg = 1.0;
  (* desc = "Body-effect on parasitic resistance " *) parameter real prwb = 0.0;
  (* desc = "Temperature coefficient of parasitic resistance " *) parameter real prt = 0.0;
  (* desc = "Subthreshold region DIBL coefficient" *) parameter real eta0 = 0.08;
  (* desc = "Subthreshold region DIBL coefficient" *) parameter real etab = 0;
  (* desc = "Channel length modulation Coefficient" *) parameter real pclm = 1.3;
  (* desc = "Drain-induced barrier lowering coefficient" *) parameter real pdiblc1 = 0.39;
  (* desc = "Drain-induced barrier lowering coefficient" *) parameter real pdiblc2 = 0.0086;
  (* desc = "Body-effect on drain-induced barrier lowering" *) parameter real pdiblcb = 0.0;
  (* desc = "Rout degradation coefficient for pocket devices" *) parameter real fprout = 0.0;
  (* desc = "Coefficient for drain-induced Vth shifts" *) parameter real pdits = 0.0;
  (* desc = "Length dependence of drain-induced Vth shifts" *) parameter real pditsl = 0.0;
  (* desc = "Vds dependence of drain-induced Vth shifts" *) parameter real pditsd = 0.0;
  (* desc = "Substrate current body-effect coefficient" *) parameter real pscbe1 = 424000000.0;
  (* desc = "Substrate current body-effect coefficient" *) parameter real pscbe2 = 1e-05;
  (* desc = "Gate dependence of output resistance parameter" *) parameter real pvag = 0.0;
  (* desc = "Bottom source junction reverse saturation current density" *) parameter real jss = 0.0001;
  (* desc = "Isolation edge sidewall source junction reverse saturation current density" *) parameter real jsws = 0.0;
  (* desc = "Gate edge source junction reverse saturation current density" *) parameter real jswgs = 0.0;
  (* desc = "Source junction built-in potential" *) parameter real pbs = 1.0;
  (* desc = "Source junction emission coefficient" *) parameter real njs = 1.0;
  (* desc = "Source junction current temperature exponent" *) parameter real xtis = 3.0;
  (* desc = "Source bottom junction capacitance grading coefficient" *) parameter real mjs = 0.5;
  (* desc = "Source sidewall junction capacitance built in potential" *) parameter real pbsws = 1.0;
  (* desc = "Source sidewall junction capacitance grading coefficient" *) parameter real mjsws = 0.33;
  (* desc = "Source (gate side) sidewall junction capacitance built in potential" *) parameter real pbswgs = 0;
  (* desc = "Source (gate side) sidewall junction capacitance grading coefficient" *) parameter real mjswgs = 0;
  (* desc = "Source bottom junction capacitance per unit area" *) parameter real cjs = 0.0005;
  (* desc = "Source sidewall junction capacitance per unit periphery" *) parameter real cjsws = 5e-10;
  (* desc = "Source (gate side) sidewall junction capacitance per unit width" *) parameter real cjswgs = 0;
  (* desc = "Bottom drain junction reverse saturation current density" *) parameter real jsd = 0;
  (* desc = "Isolation edge sidewall drain junction reverse saturation current density" *) parameter real jswd = 0;
  (* desc = "Gate edge drain junction reverse saturation current density" *) parameter real jswgd = 0;
  (* desc = "Drain junction built-in potential" *) parameter real pbd = 0;
  (* desc = "Drain junction emission coefficient" *) parameter real njd = 0;
  (* desc = "Drainjunction current temperature exponent" *) parameter real xtid = 0;
  (* desc = "Drain bottom junction capacitance grading coefficient" *) parameter real mjd = 0;
  (* desc = "Drain sidewall junction capacitance built in potential" *) parameter real pbswd = 0;
  (* desc = "Drain sidewall junction capacitance grading coefficient" *) parameter real mjswd = 0;
  (* desc = "Drain (gate side) sidewall junction capacitance built in potential" *) parameter real pbswgd = 0;
  (* desc = "Drain (gate side) sidewall junction capacitance grading coefficient" *) parameter real mjswgd = 0;
  (* desc = "Drain bottom junction capacitance per unit area" *) parameter real cjd = 0;
  (* desc = "Drain sidewall junction capacitance per unit periphery" *) parameter real cjswd = 0;
  (* desc = "Drain (gate side) sidewall junction capacitance per unit width" *) parameter real cjswgd = 0;
  (* desc = "Flat Band Voltage parameter for capmod=0 only" *) parameter real vfbcv = 0;
  (* desc = "Flat Band Voltage" *) parameter real vfb = 0;
  (* desc = "Temperature coefficient of pb" *) parameter real tpb = 0.0;
  (* desc = "Temperature coefficient of cj" *) parameter real tcj = 0.0;
  (* desc = "Temperature coefficient of pbsw" *) parameter real tpbsw = 0.0;
  (* desc = "Temperature coefficient of cjsw" *) parameter real tcjsw = 0.0;
  (* desc = "Temperature coefficient of pbswg" *) parameter real tpbswg = 0.0;
  (* desc = "Temperature coefficient of cjswg" *) parameter real tcjswg = 0.0;
  (* desc = "Exponential coefficient for finite charge thickness" *) parameter real acde = 1.0;
  (* desc = "Coefficient for gate-bias dependent surface potential" *) parameter real moin = 15.0;
  (* desc = "C-V turn-on/off parameter" *) parameter real noff = 1.0;
  (* desc = "C-V lateral-shift parameter" *) parameter real voffcv = 0.0;
  (* desc = "Distance of Mid-Contact to Gate edge" *) parameter real dmcg = 0.0;
  (* desc = "Distance of Mid-Contact to Isolation" *) parameter real dmci = 0;
  (* desc = "Distance of Mid-Diffusion to Gate edge" *) parameter real dmdg = 0.0;
  (* desc = "Distance of Mid-Contact to Gate edge in Test structures" *) parameter real dmcgt = 0.0;
  (* desc = "Distance from gate contact center to device edge" *) parameter real xgw = 0.0;
  (* desc = "Variation in Ldrawn" *) parameter real xgl = 0.0;
  (* desc = "Gate sheet resistance" *) parameter real rshg = 0.1;
  (* desc = "Number of gate contacts" *) parameter real ngcon = 1.0;
  (* desc = "First fitting parameter the bias-dependent Rg" *) parameter real xrcrg1 = 12.0;
  (* desc = "Second fitting parameter the bias-dependent Rg" *) parameter real xrcrg2 = 1.0;
  (* desc = " Velocity overshoot parameter" *) parameter real lambda = 0.0;
  (* desc = " thermal velocity" *) parameter real vtl = 200000.0;
  (* desc = " back scattering parameter" *) parameter real lc = 5e-09;
  (* desc = " back scattering parameter" *) parameter real xn = 3.0;
  (* desc = "S/D flatband voltage offset" *) parameter real vfbsdoff = 0.0;
  (* desc = "Temperature parameter for vfbsdoff" *) parameter real tvfbsdoff = 0.0;
  (* desc = "Temperature parameter for voff" *) parameter real tvoff = 0.0;
  (* desc = "Temperature parameter for nfactor" *) parameter real tnfactor = 0.0;
  (* desc = "Temperature parameter for eta0" *) parameter real teta0 = 0.0;
  (* desc = "Temperature parameter for tvoffcv" *) parameter real tvoffcv = 0.0;
  (* desc = "lint offset for noise calculation" *) parameter real lintnoi = 0.0;
  (* desc = "Length reduction parameter" *) parameter real lint = 0.0;
  (* desc = "Length reduction parameter" *) parameter real ll = 0.0;
  (* desc = "Length reduction parameter for CV" *) parameter real llc = 0;
  (* desc = "Length reduction parameter" *) parameter real lln = 1.0;
  (* desc = "Length reduction parameter" *) parameter real lw = 0.0;
  (* desc = "Length reduction parameter for CV" *) parameter real lwc = 0;
  (* desc = "Length reduction parameter" *) parameter real lwn = 1.0;
  (* desc = "Length reduction parameter" *) parameter real lwl = 0.0;
  (* desc = "Length reduction parameter for CV" *) parameter real lwlc = 0;
  (* desc = "Minimum length for the model" *) parameter real lmin = 0.0;
  (* desc = "Maximum length for the model" *) parameter real lmax = 1.0;
  (* desc = "Width dependence of rds" *) parameter real wr = 1.0;
  (* desc = "Width reduction parameter" *) parameter real wint = 0.0;
  (* desc = "Width reduction parameter" *) parameter real dwg = 0.0;
  (* desc = "Width reduction parameter" *) parameter real dwb = 0.0;
  (* desc = "Width reduction parameter" *) parameter real wl = 0.0;
  (* desc = "Width reduction parameter for CV" *) parameter real wlc = 0;
  (* desc = "Width reduction parameter" *) parameter real wln = 1.0;
  (* desc = "Width reduction parameter" *) parameter real ww = 0.0;
  (* desc = "Width reduction parameter for CV" *) parameter real wwc = 0;
  (* desc = "Width reduction parameter" *) parameter real wwn = 1.0;
  (* desc = "Width reduction parameter" *) parameter real wwl = 0.0;
  (* desc = "Width reduction parameter for CV" *) parameter real wwlc = 0;
  (* desc = "Minimum width for the model" *) parameter real wmin = 0.0;
  (* desc = "Maximum width for the model" *) parameter real wmax = 1.0;
  (* desc = "Abulk narrow width parameter" *) parameter real b0 = 0.0;
  (* desc = "Abulk narrow width parameter" *) parameter real b1 = 0.0;
  (* desc = "New C-V model parameter" *) parameter real cgsl = 0.0;
  (* desc = "New C-V model parameter" *) parameter real cgdl = 0.0;
  (* desc = "S/G overlap C-V parameter " *) parameter real ckappas = 0.6;
  (* desc = "D/G overlap C-V parameter" *) parameter real ckappad = 0;
  (* desc = "Fringe capacitance parameter" *) parameter real cf = 0;
  (* desc = "Vdsat parameter for C-V model" *) parameter real clc = 1e-07;
  (* desc = "Vdsat parameter for C-V model" *) parameter real cle = 0.6;
  (* desc = "Delta W for C-V model" *) parameter real dwc = 0;
  (* desc = "Delta L for C-V model" *) parameter real dlc = 0;
  (* desc = "W offset for channel width due to mask/etch effect" *) parameter real xw = 0.0;
  (* desc = "L offset for channel length due to mask/etch effect" *) parameter real xl = 0.0;
  (* desc = "Delta L for Ig model" *) parameter real dlcig = 0;
  (* desc = "Delta L for Ig model drain side" *) parameter real dlcigd = 0;
  (* desc = "Delta W for S/D junctions" *) parameter real dwj = 0;
  (* desc = "substrate current model parameter" *) parameter real alpha0 = 0.0;
  (* desc = "substrate current model parameter" *) parameter real alpha1 = 0.0;
  (* desc = "substrate current model parameter" *) parameter real beta0 = 0.0;
  (* desc = "Pre-exponential constant for GIDL" *) parameter real agidl = 0.0;
  (* desc = "Exponential constant for GIDL" *) parameter real bgidl = 2300000000.0;
  (* desc = "Parameter for body-bias dependence of GIDL" *) parameter real cgidl = 0.5;
  (* desc = "GIDL vg parameter" *) parameter real rgidl = 1.0;
  (* desc = "GIDL vb parameter" *) parameter real kgidl = 0.0;
  (* desc = "GIDL vb parameter" *) parameter real fgidl = 1.0;
  (* desc = "Fitting parameter for Bandbending" *) parameter real egidl = 0.8;
  (* desc = "Pre-exponential constant for GISL" *) parameter real agisl = 0;
  (* desc = "Exponential constant for GISL" *) parameter real bgisl = 0;
  (* desc = "Parameter for body-bias dependence of GISL" *) parameter real cgisl = 0;
  (* desc = "GISL vg parameter" *) parameter real rgisl = 0;
  (* desc = "GISL vb parameter" *) parameter real kgisl = 0;
  (* desc = "GISL vb parameter" *) parameter real fgisl = 0;
  (* desc = "Fitting parameter for Bandbending" *) parameter real egisl = 0;
  (* desc = "Parameter for Igc" *) parameter real aigc = 0;
  (* desc = "Parameter for Igc" *) parameter real bigc = 0;
  (* desc = "Parameter for Igc" *) parameter real cigc = 0;
  (* desc = "Parameter for Igs,d" *) parameter real aigsd = 0;
  (* desc = "Parameter for Igs,d" *) parameter real bigsd = 0;
  (* desc = "Parameter for Igs,d" *) parameter real cigsd = 0;
  (* desc = "Parameter for Igs" *) parameter real aigs = 0;
  (* desc = "Parameter for Igs" *) parameter real bigs = 0;
  (* desc = "Parameter for Igs" *) parameter real cigs = 0;
  (* desc = "Parameter for Igd" *) parameter real aigd = 0;
  (* desc = "Parameter for Igd" *) parameter real bigd = 0;
  (* desc = "Parameter for Igd" *) parameter real cigd = 0;
  (* desc = "Parameter for Igb" *) parameter real aigbacc = 0.0136;
  (* desc = "Parameter for Igb" *) parameter real bigbacc = 0.00171;
  (* desc = "Parameter for Igb" *) parameter real cigbacc = 0.075;
  (* desc = "Parameter for Igb" *) parameter real aigbinv = 0.0111;
  (* desc = "Parameter for Igb" *) parameter real bigbinv = 0.000949;
  (* desc = "Parameter for Igb" *) parameter real cigbinv = 0.006;
  (* desc = "Parameter for Igc slope" *) parameter real nigc = 1.0;
  (* desc = "Parameter for Igbinv slope" *) parameter real nigbinv = 3.0;
  (* desc = "Parameter for Igbacc slope" *) parameter real nigbacc = 1.0;
  (* desc = "Exponent for Tox ratio" *) parameter real ntox = 1.0;
  (* desc = "Parameter for the Si bandgap for Igbinv" *) parameter real eigbinv = 1.1;
  (* desc = "Parameter for Igc partition" *) parameter real pigcd = 1.0;
  (* desc = "Factor for the gate edge Tox" *) parameter real poxedge = 1.0;
  (* desc = "Forward drain diode forward limiting current" *) parameter real ijthdfwd = 0;
  (* desc = "Forward source diode forward limiting current" *) parameter real ijthsfwd = 0.1;
  (* desc = "Reverse drain diode forward limiting current" *) parameter real ijthdrev = 0;
  (* desc = "Reverse source diode forward limiting current" *) parameter real ijthsrev = 0.1;
  (* desc = "Fitting parameter for drain diode breakdown current" *) parameter real xjbvd = 0;
  (* desc = "Fitting parameter for source diode breakdown current" *) parameter real xjbvs = 1.0;
  (* desc = "Drain diode breakdown voltage" *) parameter real bvd = 0;
  (* desc = "Source diode breakdown voltage" *) parameter real bvs = 10.0;
  (* desc = "Source bottom trap-assisted saturation current density" *) parameter real jtss = 0.0;
  (* desc = "Drain bottom trap-assisted saturation current density" *) parameter real jtsd = 0;
  (* desc = "Source STI sidewall trap-assisted saturation current density" *) parameter real jtssws = 0.0;
  (* desc = "Drain STI sidewall trap-assisted saturation current density" *) parameter real jtsswd = 0;
  (* desc = "Source gate-edge sidewall trap-assisted saturation current density" *) parameter real jtsswgs = 0.0;
  (* desc = "Drain gate-edge sidewall trap-assisted saturation current density" *) parameter real jtsswgd = 0;
  (* desc = "TAT current width dependance" *) parameter real jtweff = 0.0;
  (* desc = "Non-ideality factor for bottom junction" *) parameter real njts = 20.0;
  (* desc = "Non-ideality factor for STI sidewall junction" *) parameter real njtssw = 20.0;
  (* desc = "Non-ideality factor for gate-edge sidewall junction" *) parameter real njtsswg = 20.0;
  (* desc = "Non-ideality factor for bottom junction drain side" *) parameter real njtsd = 0;
  (* desc = "Non-ideality factor for STI sidewall junction drain side" *) parameter real njtsswd = 0;
  (* desc = "Non-ideality factor for gate-edge sidewall junction drain side" *) parameter real njtsswgd = 0;
  (* desc = "Power dependence of JTSS on temperature" *) parameter real xtss = 0.02;
  (* desc = "Power dependence of JTSD on temperature" *) parameter real xtsd = 0;
  (* desc = "Power dependence of JTSSWS on temperature" *) parameter real xtssws = 0.02;
  (* desc = "Power dependence of JTSSWD on temperature" *) parameter real xtsswd = 0;
  (* desc = "Power dependence of JTSSWGS on temperature" *) parameter real xtsswgs = 0.02;
  (* desc = "Power dependence of JTSSWGD on temperature" *) parameter real xtsswgd = 0;
  (* desc = "Temperature coefficient for NJTS" *) parameter real tnjts = 0.0;
  (* desc = "Temperature coefficient for NJTSSW" *) parameter real tnjtssw = 0.0;
  (* desc = "Temperature coefficient for NJTSSWG" *) parameter real tnjtsswg = 0.0;
  (* desc = "Temperature coefficient for NJTSD" *) parameter real tnjtsd = 0;
  (* desc = "Temperature coefficient for NJTSSWD" *) parameter real tnjtsswd = 0;
  (* desc = "Temperature coefficient for NJTSSWGD" *) parameter real tnjtsswgd = 0;
  (* desc = "Source bottom trap-assisted voltage dependent parameter" *) parameter real vtss = 10.0;
  (* desc = "Drain bottom trap-assisted voltage dependent parameter" *) parameter real vtsd = 0;
  (* desc = "Source STI sidewall trap-assisted voltage dependent parameter" *) parameter real vtssws = 10.0;
  (* desc = "Drain STI sidewall trap-assisted voltage dependent parameter" *) parameter real vtsswd = 0;
  (* desc = "Source gate-edge sidewall trap-assisted voltage dependent parameter" *) parameter real vtsswgs = 10.0;
  (* desc = "Drain gate-edge sidewall trap-assisted voltage dependent parameter" *) parameter real vtsswgd = 0;
  (* desc = "Minimum body conductance" *) parameter real gbmin = 1e-12;
  (* desc = "Resistance between bNode and dbNode" *) parameter real rbdb = 50.0;
  (* desc = "Resistance between bNodePrime and bNode" *) parameter real rbpb = 50.0;
  (* desc = "Resistance between bNode and sbNode" *) parameter real rbsb = 50.0;
  (* desc = "Resistance between bNodePrime and sbNode" *) parameter real rbps = 50.0;
  (* desc = "Resistance between bNodePrime and bNode" *) parameter real rbpd = 50.0;
  (* desc = "Body resistance RBPS scaling" *) parameter real rbps0 = 50.0;
  (* desc = "Body resistance RBPS L scaling" *) parameter real rbpsl = 0.0;
  (* desc = "Body resistance RBPS W scaling" *) parameter real rbpsw = 0.0;
  (* desc = "Body resistance RBPS NF scaling" *) parameter real rbpsnf = 0.0;
  (* desc = "Body resistance RBPD scaling" *) parameter real rbpd0 = 50.0;
  (* desc = "Body resistance RBPD L scaling" *) parameter real rbpdl = 0.0;
  (* desc = "Body resistance RBPD W scaling" *) parameter real rbpdw = 0.0;
  (* desc = "Body resistance RBPD NF scaling" *) parameter real rbpdnf = 0.0;
  (* desc = "Body resistance RBPBX  scaling" *) parameter real rbpbx0 = 100.0;
  (* desc = "Body resistance RBPBX L scaling" *) parameter real rbpbxl = 0.0;
  (* desc = "Body resistance RBPBX W scaling" *) parameter real rbpbxw = 0.0;
  (* desc = "Body resistance RBPBX NF scaling" *) parameter real rbpbxnf = 0.0;
  (* desc = "Body resistance RBPBY  scaling" *) parameter real rbpby0 = 100.0;
  (* desc = "Body resistance RBPBY L scaling" *) parameter real rbpbyl = 0.0;
  (* desc = "Body resistance RBPBY W scaling" *) parameter real rbpbyw = 0.0;
  (* desc = "Body resistance RBPBY NF scaling" *) parameter real rbpbynf = 0.0;
  (* desc = "Body resistance RBSBX  scaling" *) parameter real rbsbx0 = 100.0;
  (* desc = "Body resistance RBSBY  scaling" *) parameter real rbsby0 = 100.0;
  (* desc = "Body resistance RBDBX  scaling" *) parameter real rbdbx0 = 100.0;
  (* desc = "Body resistance RBDBY  scaling" *) parameter real rbdby0 = 100.0;
  (* desc = "Body resistance RBSDBX L scaling" *) parameter real rbsdbxl = 0.0;
  (* desc = "Body resistance RBSDBX W scaling" *) parameter real rbsdbxw = 0.0;
  (* desc = "Body resistance RBSDBX NF scaling" *) parameter real rbsdbxnf = 0.0;
  (* desc = "Body resistance RBSDBY L scaling" *) parameter real rbsdbyl = 0.0;
  (* desc = "Body resistance RBSDBY W scaling" *) parameter real rbsdbyw = 0.0;
  (* desc = "Body resistance RBSDBY NF scaling" *) parameter real rbsdbynf = 0.0;
  (* desc = "Length dependence of cdsc" *) parameter real lcdsc = 0.0;
  (* desc = "Length dependence of cdscb" *) parameter real lcdscb = 0.0;
  (* desc = "Length dependence of cdscd" *) parameter real lcdscd = 0.0;
  (* desc = "Length dependence of cit" *) parameter real lcit = 0.0;
  (* desc = "Length dependence of nfactor" *) parameter real lnfactor = 0.0;
  (* desc = "Length dependence of xj" *) parameter real lxj = 0.0;
  (* desc = "Length dependence of vsat" *) parameter real lvsat = 0.0;
  (* desc = "Length dependence of at" *) parameter real lat = 0.0;
  (* desc = "Length dependence of a0" *) parameter real la0 = 0.0;
  (* desc = "Length dependence of ags" *) parameter real lags = 0.0;
  (* desc = "Length dependence of a1" *) parameter real la1 = 0.0;
  (* desc = "Length dependence of a2" *) parameter real la2 = 0.0;
  (* desc = "Length dependence of keta" *) parameter real lketa = 0.0;
  (* desc = "Length dependence of ketac" *) parameter real lketac = 0;
  (* desc = "Length dependence of nsub" *) parameter real lnsub = 0.0;
  (* desc = "Length dependence of ndep" *) parameter real lndep = 0.0;
  (* desc = "Length dependence of nsd" *) parameter real lnsd = 0.0;
  (* desc = "Length dependence of phin" *) parameter real lphin = 0.0;
  (* desc = "Length dependence of ngate" *) parameter real lngate = 0.0;
  (* desc = "Length dependence of gamma1" *) parameter real lgamma1 = 0.0;
  (* desc = "Length dependence of gamma2" *) parameter real lgamma2 = 0.0;
  (* desc = "Length dependence of vbx" *) parameter real lvbx = 0.0;
  (* desc = "Length dependence of vbm" *) parameter real lvbm = 0.0;
  (* desc = "Length dependence of xt" *) parameter real lxt = 0.0;
  (* desc = "Length dependence of k1" *) parameter real lk1 = 0.0;
  (* desc = "Length dependence of kt1" *) parameter real lkt1 = 0.0;
  (* desc = "Length dependence of kt1l" *) parameter real lkt1l = 0.0;
  (* desc = "Length dependence of kt2" *) parameter real lkt2 = 0.0;
  (* desc = "Length dependence of k2" *) parameter real lk2 = 0.0;
  (* desc = "Length dependence of k3" *) parameter real lk3 = 0.0;
  (* desc = "Length dependence of k3b" *) parameter real lk3b = 0.0;
  (* desc = "Length dependence of w0" *) parameter real lw0 = 0.0;
  (* desc = "Length dependence of dvtp0" *) parameter real ldvtp0 = 0.0;
  (* desc = "Length dependence of dvtp1" *) parameter real ldvtp1 = 0.0;
  (* desc = "Length dependence of dvtp2" *) parameter real ldvtp2 = 0.0;
  (* desc = "Length dependence of dvtp3" *) parameter real ldvtp3 = 0.0;
  (* desc = "Length dependence of dvtp4" *) parameter real ldvtp4 = 0.0;
  (* desc = "Length dependence of dvtp5" *) parameter real ldvtp5 = 0.0;
  (* desc = "Length dependence of lpe0" *) parameter real llpe0 = 0.0;
  (* desc = "Length dependence of lpeb" *) parameter real llpeb = 0.0;
  (* desc = "Length dependence of dvt0" *) parameter real ldvt0 = 0.0;
  (* desc = "Length dependence of dvt1" *) parameter real ldvt1 = 0.0;
  (* desc = "Length dependence of dvt2" *) parameter real ldvt2 = 0.0;
  (* desc = "Length dependence of dvt0w" *) parameter real ldvt0w = 0.0;
  (* desc = "Length dependence of dvt1w" *) parameter real ldvt1w = 0.0;
  (* desc = "Length dependence of dvt2w" *) parameter real ldvt2w = 0.0;
  (* desc = "Length dependence of drout" *) parameter real ldrout = 0.0;
  (* desc = "Length dependence of dsub" *) parameter real ldsub = 0.0;
  (* desc = "Length dependence of vto" *) parameter real lvth0 = 0.0;
  aliasparam lvtho = lvth0;
  (* desc = "Length dependence of ua" *) parameter real lua = 0.0;
  (* desc = "Length dependence of ua1" *) parameter real lua1 = 0.0;
  (* desc = "Length dependence of ub" *) parameter real lub = 0.0;
  (* desc = "Length dependence of ub1" *) parameter real lub1 = 0.0;
  (* desc = "Length dependence of uc" *) parameter real luc = 0.0;
  (* desc = "Length dependence of uc1" *) parameter real luc1 = 0.0;
  (* desc = "Length dependence of ud" *) parameter real lud = 0.0;
  (* desc = "Length dependence of ud1" *) parameter real lud1 = 0.0;
  (* desc = "Length dependence of up" *) parameter real lup = 0.0;
  (* desc = "Length dependence of lp" *) parameter real llp = 0.0;
  (* desc = "Length dependence of u0" *) parameter real lu0 = 0.0;
  (* desc = "Length dependence of ute" *) parameter real lute = 0.0;
  (* desc = "Length dependence of ucste" *) parameter real lucste = 0.0;
  (* desc = "Length dependence of voff" *) parameter real lvoff = 0.0;
  (* desc = "Length dependence of minv" *) parameter real lminv = 0.0;
  (* desc = "Length dependence of minvcv" *) parameter real lminvcv = 0.0;
  (* desc = "Length dependence of delta" *) parameter real ldelta = 0.0;
  (* desc = "Length dependence of rdsw " *) parameter real lrdsw = 0.0;
  (* desc = "Length dependence of rsw" *) parameter real lrsw = 0.0;
  (* desc = "Length dependence of rdw" *) parameter real lrdw = 0.0;
  (* desc = "Length dependence of prwg " *) parameter real lprwg = 0.0;
  (* desc = "Length dependence of prwb " *) parameter real lprwb = 0.0;
  (* desc = "Length dependence of prt " *) parameter real lprt = 0.0;
  (* desc = "Length dependence of eta0" *) parameter real leta0 = 0.0;
  (* desc = "Length dependence of etab" *) parameter real letab = 0;
  (* desc = "Length dependence of pclm" *) parameter real lpclm = 0.0;
  (* desc = "Length dependence of pdiblc1" *) parameter real lpdiblc1 = 0.0;
  (* desc = "Length dependence of pdiblc2" *) parameter real lpdiblc2 = 0.0;
  (* desc = "Length dependence of pdiblcb" *) parameter real lpdiblcb = 0.0;
  (* desc = "Length dependence of pdiblcb" *) parameter real lfprout = 0.0;
  (* desc = "Length dependence of pdits" *) parameter real lpdits = 0.0;
  (* desc = "Length dependence of pditsd" *) parameter real lpditsd = 0.0;
  (* desc = "Length dependence of pscbe1" *) parameter real lpscbe1 = 0.0;
  (* desc = "Length dependence of pscbe2" *) parameter real lpscbe2 = 0.0;
  (* desc = "Length dependence of pvag" *) parameter real lpvag = 0.0;
  (* desc = "Length dependence of wr" *) parameter real lwr = 0.0;
  (* desc = "Length dependence of dwg" *) parameter real ldwg = 0.0;
  (* desc = "Length dependence of dwb" *) parameter real ldwb = 0.0;
  (* desc = "Length dependence of b0" *) parameter real lb0 = 0.0;
  (* desc = "Length dependence of b1" *) parameter real lb1 = 0.0;
  (* desc = "Length dependence of cgsl" *) parameter real lcgsl = 0.0;
  (* desc = "Length dependence of cgdl" *) parameter real lcgdl = 0.0;
  (* desc = "Length dependence of ckappas" *) parameter real lckappas = 0.0;
  (* desc = "Length dependence of ckappad" *) parameter real lckappad = 0.0;
  (* desc = "Length dependence of cf" *) parameter real lcf = 0.0;
  (* desc = "Length dependence of clc" *) parameter real lclc = 0.0;
  (* desc = "Length dependence of cle" *) parameter real lcle = 0.0;
  (* desc = "Length dependence of alpha0" *) parameter real lalpha0 = 0.0;
  (* desc = "Length dependence of alpha1" *) parameter real lalpha1 = 0.0;
  (* desc = "Length dependence of beta0" *) parameter real lbeta0 = 0.0;
  (* desc = "Length dependence of agidl" *) parameter real lagidl = 0.0;
  (* desc = "Length dependence of bgidl" *) parameter real lbgidl = 0.0;
  (* desc = "Length dependence of cgidl" *) parameter real lcgidl = 0.0;
  (* desc = "Length dependence of rgidl" *) parameter real lrgidl = 0.0;
  (* desc = "Length dependence of kgidl" *) parameter real lkgidl = 0.0;
  (* desc = "Length dependence of fgidl" *) parameter real lfgidl = 0.0;
  (* desc = "Length dependence of egidl" *) parameter real legidl = 0.0;
  (* desc = "Length dependence of agisl" *) parameter real lagisl = 0;
  (* desc = "Length dependence of bgisl" *) parameter real lbgisl = 0;
  (* desc = "Length dependence of cgisl" *) parameter real lcgisl = 0;
  (* desc = "Length dependence of rgisl" *) parameter real lrgisl = 0;
  (* desc = "Length dependence of kgisl" *) parameter real lkgisl = 0;
  (* desc = "Length dependence of fgisl" *) parameter real lfgisl = 0;
  (* desc = "Length dependence of egisl" *) parameter real legisl = 0;
  (* desc = "Length dependence of aigc" *) parameter real laigc = 0.0;
  (* desc = "Length dependence of bigc" *) parameter real lbigc = 0.0;
  (* desc = "Length dependence of cigc" *) parameter real lcigc = 0.0;
  (* desc = "Length dependence of aigsd" *) parameter real laigsd = 0.0;
  (* desc = "Length dependence of bigsd" *) parameter real lbigsd = 0.0;
  (* desc = "Length dependence of cigsd" *) parameter real lcigsd = 0.0;
  (* desc = "Length dependence of aigs" *) parameter real laigs = 0.0;
  (* desc = "Length dependence of bigs" *) parameter real lbigs = 0.0;
  (* desc = "Length dependence of cigs" *) parameter real lcigs = 0.0;
  (* desc = "Length dependence of aigd" *) parameter real laigd = 0.0;
  (* desc = "Length dependence of bigd" *) parameter real lbigd = 0.0;
  (* desc = "Length dependence of cigd" *) parameter real lcigd = 0.0;
  (* desc = "Length dependence of aigbacc" *) parameter real laigbacc = 0.0;
  (* desc = "Length dependence of bigbacc" *) parameter real lbigbacc = 0.0;
  (* desc = "Length dependence of cigbacc" *) parameter real lcigbacc = 0.0;
  (* desc = "Length dependence of aigbinv" *) parameter real laigbinv = 0.0;
  (* desc = "Length dependence of bigbinv" *) parameter real lbigbinv = 0.0;
  (* desc = "Length dependence of cigbinv" *) parameter real lcigbinv = 0.0;
  (* desc = "Length dependence of nigc" *) parameter real lnigc = 0.0;
  (* desc = "Length dependence of nigbinv" *) parameter real lnigbinv = 0.0;
  (* desc = "Length dependence of nigbacc" *) parameter real lnigbacc = 0.0;
  (* desc = "Length dependence of ntox" *) parameter real lntox = 0.0;
  (* desc = "Length dependence for eigbinv" *) parameter real leigbinv = 0.0;
  (* desc = "Length dependence for pigcd" *) parameter real lpigcd = 0.0;
  (* desc = "Length dependence for poxedge" *) parameter real lpoxedge = 0.0;
  (* desc = "Length dependence of vfbcv" *) parameter real lvfbcv = 0.0;
  (* desc = "Length dependence of vfb" *) parameter real lvfb = 0.0;
  (* desc = "Length dependence of acde" *) parameter real lacde = 0.0;
  (* desc = "Length dependence of moin" *) parameter real lmoin = 0.0;
  (* desc = "Length dependence of noff" *) parameter real lnoff = 0.0;
  (* desc = "Length dependence of voffcv" *) parameter real lvoffcv = 0.0;
  (* desc = "Length dependence of xrcrg1" *) parameter real lxrcrg1 = 0.0;
  (* desc = "Length dependence of xrcrg2" *) parameter real lxrcrg2 = 0.0;
  (* desc = "Length dependence of lambda" *) parameter real llambda = 0.0;
  (* desc = " Length dependence of vtl" *) parameter real lvtl = 0.0;
  (* desc = " Length dependence of xn" *) parameter real lxn = 0.0;
  (* desc = " Length dependence of eu" *) parameter real leu = 0.0;
  (* desc = "Length dependence of lucs" *) parameter real lucs = 0.0;
  (* desc = "Length dependence of vfbsdoff" *) parameter real lvfbsdoff = 0.0;
  (* desc = "Length dependence of tvfbsdoff" *) parameter real ltvfbsdoff = 0.0;
  (* desc = "Length dependence of tvoff" *) parameter real ltvoff = 0.0;
  (* desc = "Length dependence of tnfactor" *) parameter real ltnfactor = 0.0;
  (* desc = "Length dependence of teta0" *) parameter real lteta0 = 0.0;
  (* desc = "Length dependence of tvoffcv" *) parameter real ltvoffcv = 0.0;
  (* desc = "Width dependence of cdsc" *) parameter real wcdsc = 0.0;
  (* desc = "Width dependence of cdscb" *) parameter real wcdscb = 0.0;
  (* desc = "Width dependence of cdscd" *) parameter real wcdscd = 0.0;
  (* desc = "Width dependence of cit" *) parameter real wcit = 0.0;
  (* desc = "Width dependence of nfactor" *) parameter real wnfactor = 0.0;
  (* desc = "Width dependence of xj" *) parameter real wxj = 0.0;
  (* desc = "Width dependence of vsat" *) parameter real wvsat = 0.0;
  (* desc = "Width dependence of at" *) parameter real wat = 0.0;
  (* desc = "Width dependence of a0" *) parameter real wa0 = 0.0;
  (* desc = "Width dependence of ags" *) parameter real wags = 0.0;
  (* desc = "Width dependence of a1" *) parameter real wa1 = 0.0;
  (* desc = "Width dependence of a2" *) parameter real wa2 = 0.0;
  (* desc = "Width dependence of keta" *) parameter real wketa = 0.0;
  (* desc = "Width dependence of ketac" *) parameter real wketac = 0;
  (* desc = "Width dependence of nsub" *) parameter real wnsub = 0.0;
  (* desc = "Width dependence of ndep" *) parameter real wndep = 0.0;
  (* desc = "Width dependence of nsd" *) parameter real wnsd = 0.0;
  (* desc = "Width dependence of phin" *) parameter real wphin = 0.0;
  (* desc = "Width dependence of ngate" *) parameter real wngate = 0.0;
  (* desc = "Width dependence of gamma1" *) parameter real wgamma1 = 0.0;
  (* desc = "Width dependence of gamma2" *) parameter real wgamma2 = 0.0;
  (* desc = "Width dependence of vbx" *) parameter real wvbx = 0.0;
  (* desc = "Width dependence of vbm" *) parameter real wvbm = 0.0;
  (* desc = "Width dependence of xt" *) parameter real wxt = 0.0;
  (* desc = "Width dependence of k1" *) parameter real wk1 = 0.0;
  (* desc = "Width dependence of kt1" *) parameter real wkt1 = 0.0;
  (* desc = "Width dependence of kt1l" *) parameter real wkt1l = 0.0;
  (* desc = "Width dependence of kt2" *) parameter real wkt2 = 0.0;
  (* desc = "Width dependence of k2" *) parameter real wk2 = 0.0;
  (* desc = "Width dependence of k3" *) parameter real wk3 = 0.0;
  (* desc = "Width dependence of k3b" *) parameter real wk3b = 0.0;
  (* desc = "Width dependence of w0" *) parameter real ww0 = 0.0;
  (* desc = "Width dependence of dvtp0" *) parameter real wdvtp0 = 0.0;
  (* desc = "Width dependence of dvtp1" *) parameter real wdvtp1 = 0.0;
  (* desc = "Width dependence of dvtp2" *) parameter real wdvtp2 = 0.0;
  (* desc = "Width dependence of dvtp3" *) parameter real wdvtp3 = 0.0;
  (* desc = "Width dependence of dvtp4" *) parameter real wdvtp4 = 0.0;
  (* desc = "Width dependence of dvtp5" *) parameter real wdvtp5 = 0.0;
  (* desc = "Width dependence of lpe0" *) parameter real wlpe0 = 0.0;
  (* desc = "Width dependence of lpeb" *) parameter real wlpeb = 0.0;
  (* desc = "Width dependence of dvt0" *) parameter real wdvt0 = 0.0;
  (* desc = "Width dependence of dvt1" *) parameter real wdvt1 = 0.0;
  (* desc = "Width dependence of dvt2" *) parameter real wdvt2 = 0.0;
  (* desc = "Width dependence of dvt0w" *) parameter real wdvt0w = 0.0;
  (* desc = "Width dependence of dvt1w" *) parameter real wdvt1w = 0.0;
  (* desc = "Width dependence of dvt2w" *) parameter real wdvt2w = 0.0;
  (* desc = "Width dependence of drout" *) parameter real wdrout = 0.0;
  (* desc = "Width dependence of dsub" *) parameter real wdsub = 0.0;
  (* desc = "Width dependence of vto" *) parameter real wvth0 = 0.0;
  aliasparam wvtho = wvth0;
  (* desc = "Width dependence of ua" *) parameter real wua = 0.0;
  (* desc = "Width dependence of ua1" *) parameter real wua1 = 0.0;
  (* desc = "Width dependence of ub" *) parameter real wub = 0.0;
  (* desc = "Width dependence of ub1" *) parameter real wub1 = 0.0;
  (* desc = "Width dependence of uc" *) parameter real wuc = 0.0;
  (* desc = "Width dependence of uc1" *) parameter real wuc1 = 0.0;
  (* desc = "Width dependence of ud" *) parameter real wud = 0.0;
  (* desc = "Width dependence of ud1" *) parameter real wud1 = 0.0;
  (* desc = "Width dependence of up" *) parameter real wup = 0.0;
  (* desc = "Width dependence of lp" *) parameter real wlp = 0.0;
  (* desc = "Width dependence of u0" *) parameter real wu0 = 0.0;
  (* desc = "Width dependence of ute" *) parameter real wute = 0.0;
  (* desc = "Width dependence of ucste" *) parameter real wucste = 0.0;
  (* desc = "Width dependence of voff" *) parameter real wvoff = 0.0;
  (* desc = "Width dependence of minv" *) parameter real wminv = 0.0;
  (* desc = "Width dependence of minvcv" *) parameter real wminvcv = 0.0;
  (* desc = "Width dependence of delta" *) parameter real wdelta = 0.0;
  (* desc = "Width dependence of rdsw " *) parameter real wrdsw = 0.0;
  (* desc = "Width dependence of rsw" *) parameter real wrsw = 0.0;
  (* desc = "Width dependence of rdw" *) parameter real wrdw = 0.0;
  (* desc = "Width dependence of prwg " *) parameter real wprwg = 0.0;
  (* desc = "Width dependence of prwb " *) parameter real wprwb = 0.0;
  (* desc = "Width dependence of prt" *) parameter real wprt = 0.0;
  (* desc = "Width dependence of eta0" *) parameter real weta0 = 0.0;
  (* desc = "Width dependence of etab" *) parameter real wetab = 0.0;
  (* desc = "Width dependence of pclm" *) parameter real wpclm = 0.0;
  (* desc = "Width dependence of pdiblc1" *) parameter real wpdiblc1 = 0.0;
  (* desc = "Width dependence of pdiblc2" *) parameter real wpdiblc2 = 0.0;
  (* desc = "Width dependence of pdiblcb" *) parameter real wpdiblcb = 0.0;
  (* desc = "Width dependence of pdiblcb" *) parameter real wfprout = 0.0;
  (* desc = "Width dependence of pdits" *) parameter real wpdits = 0.0;
  (* desc = "Width dependence of pditsd" *) parameter real wpditsd = 0.0;
  (* desc = "Width dependence of pscbe1" *) parameter real wpscbe1 = 0.0;
  (* desc = "Width dependence of pscbe2" *) parameter real wpscbe2 = 0.0;
  (* desc = "Width dependence of pvag" *) parameter real wpvag = 0.0;
  (* desc = "Width dependence of wr" *) parameter real wwr = 0.0;
  (* desc = "Width dependence of dwg" *) parameter real wdwg = 0.0;
  (* desc = "Width dependence of dwb" *) parameter real wdwb = 0.0;
  (* desc = "Width dependence of b0" *) parameter real wb0 = 0.0;
  (* desc = "Width dependence of b1" *) parameter real wb1 = 0.0;
  (* desc = "Width dependence of cgsl" *) parameter real wcgsl = 0.0;
  (* desc = "Width dependence of cgdl" *) parameter real wcgdl = 0.0;
  (* desc = "Width dependence of ckappas" *) parameter real wckappas = 0.0;
  (* desc = "Width dependence of ckappad" *) parameter real wckappad = 0.0;
  (* desc = "Width dependence of cf" *) parameter real wcf = 0.0;
  (* desc = "Width dependence of clc" *) parameter real wclc = 0.0;
  (* desc = "Width dependence of cle" *) parameter real wcle = 0.0;
  (* desc = "Width dependence of alpha0" *) parameter real walpha0 = 0.0;
  (* desc = "Width dependence of alpha1" *) parameter real walpha1 = 0.0;
  (* desc = "Width dependence of beta0" *) parameter real wbeta0 = 0.0;
  (* desc = "Width dependence of agidl" *) parameter real wagidl = 0.0;
  (* desc = "Width dependence of bgidl" *) parameter real wbgidl = 0.0;
  (* desc = "Width dependence of cgidl" *) parameter real wcgidl = 0.0;
  (* desc = "Width dependence of rgidl" *) parameter real wrgidl = 0.0;
  (* desc = "Width dependence of kgidl" *) parameter real wkgidl = 0.0;
  (* desc = "Width dependence of fgidl" *) parameter real wfgidl = 0.0;
  (* desc = "Width dependence of egidl" *) parameter real wegidl = 0.0;
  (* desc = "Width dependence of agisl" *) parameter real wagisl = 0;
  (* desc = "Width dependence of bgisl" *) parameter real wbgisl = 0;
  (* desc = "Width dependence of cgisl" *) parameter real wcgisl = 0;
  (* desc = "Width dependence of rgisl" *) parameter real wrgisl = 0;
  (* desc = "Width dependence of kgisl" *) parameter real wkgisl = 0;
  (* desc = "Width dependence of fgisl" *) parameter real wfgisl = 0;
  (* desc = "Width dependence of egisl" *) parameter real wegisl = 0;
  (* desc = "Width dependence of aigc" *) parameter real waigc = 0.0;
  (* desc = "Width dependence of bigc" *) parameter real wbigc = 0.0;
  (* desc = "Width dependence of cigc" *) parameter real wcigc = 0.0;
  (* desc = "Width dependence of aigsd" *) parameter real waigsd = 0.0;
  (* desc = "Width dependence of bigsd" *) parameter real wbigsd = 0.0;
  (* desc = "Width dependence of cigsd" *) parameter real wcigsd = 0.0;
  (* desc = "Width dependence of aigs" *) parameter real waigs = 0.0;
  (* desc = "Width dependence of bigs" *) parameter real wbigs = 0.0;
  (* desc = "Width dependence of cigs" *) parameter real wcigs = 0.0;
  (* desc = "Width dependence of aigd" *) parameter real waigd = 0.0;
  (* desc = "Width dependence of bigd" *) parameter real wbigd = 0.0;
  (* desc = "Width dependence of cigd" *) parameter real wcigd = 0.0;
  (* desc = "Width dependence of aigbacc" *) parameter real waigbacc = 0.0;
  (* desc = "Width dependence of bigbacc" *) parameter real wbigbacc = 0.0;
  (* desc = "Width dependence of cigbacc" *) parameter real wcigbacc = 0.0;
  (* desc = "Width dependence of aigbinv" *) parameter real waigbinv = 0.0;
  (* desc = "Width dependence of bigbinv" *) parameter real wbigbinv = 0.0;
  (* desc = "Width dependence of cigbinv" *) parameter real wcigbinv = 0.0;
  (* desc = "Width dependence of nigc" *) parameter real wnigc = 0.0;
  (* desc = "Width dependence of nigbinv" *) parameter real wnigbinv = 0.0;
  (* desc = "Width dependence of nigbacc" *) parameter real wnigbacc = 0.0;
  (* desc = "Width dependence of ntox" *) parameter real wntox = 0.0;
  (* desc = "Width dependence for eigbinv" *) parameter real weigbinv = 0.0;
  (* desc = "Width dependence for pigcd" *) parameter real wpigcd = 0.0;
  (* desc = "Width dependence for poxedge" *) parameter real wpoxedge = 0.0;
  (* desc = "Width dependence of vfbcv" *) parameter real wvfbcv = 0.0;
  (* desc = "Width dependence of vfb" *) parameter real wvfb = 0.0;
  (* desc = "Width dependence of acde" *) parameter real wacde = 0.0;
  (* desc = "Width dependence of moin" *) parameter real wmoin = 0.0;
  (* desc = "Width dependence of noff" *) parameter real wnoff = 0.0;
  (* desc = "Width dependence of voffcv" *) parameter real wvoffcv = 0.0;
  (* desc = "Width dependence of xrcrg1" *) parameter real wxrcrg1 = 0.0;
  (* desc = "Width dependence of xrcrg2" *) parameter real wxrcrg2 = 0.0;
  (* desc = "Width dependence of lambda" *) parameter real wlambda = 0.0;
  (* desc = "Width dependence of vtl" *) parameter real wvtl = 0.0;
  (* desc = "Width dependence of xn" *) parameter real wxn = 0.0;
  (* desc = "Width dependence of eu" *) parameter real weu = 0.0;
  (* desc = "Width dependence of ucs" *) parameter real wucs = 0.0;
  (* desc = "Width dependence of vfbsdoff" *) parameter real wvfbsdoff = 0.0;
  (* desc = "Width dependence of tvfbsdoff" *) parameter real wtvfbsdoff = 0.0;
  (* desc = "Width dependence of tvoff" *) parameter real wtvoff = 0.0;
  (* desc = "Width dependence of tnfactor" *) parameter real wtnfactor = 0.0;
  (* desc = "Width dependence of teta0" *) parameter real wteta0 = 0.0;
  (* desc = "Width dependence of tvoffcv" *) parameter real wtvoffcv = 0.0;
  (* desc = "Cross-term dependence of cdsc" *) parameter real pcdsc = 0.0;
  (* desc = "Cross-term dependence of cdscb" *) parameter real pcdscb = 0.0;
  (* desc = "Cross-term dependence of cdscd" *) parameter real pcdscd = 0.0;
  (* desc = "Cross-term dependence of cit" *) parameter real pcit = 0.0;
  (* desc = "Cross-term dependence of nfactor" *) parameter real pnfactor = 0.0;
  (* desc = "Cross-term dependence of xj" *) parameter real pxj = 0.0;
  (* desc = "Cross-term dependence of vsat" *) parameter real pvsat = 0.0;
  (* desc = "Cross-term dependence of at" *) parameter real pat = 0.0;
  (* desc = "Cross-term dependence of a0" *) parameter real pa0 = 0.0;
  (* desc = "Cross-term dependence of ags" *) parameter real pags = 0.0;
  (* desc = "Cross-term dependence of a1" *) parameter real pa1 = 0.0;
  (* desc = "Cross-term dependence of a2" *) parameter real pa2 = 0.0;
  (* desc = "Cross-term dependence of keta" *) parameter real pketa = 0.0;
  (* desc = "Cross-term dependence of ketac" *) parameter real pketac = 0;
  (* desc = "Cross-term dependence of nsub" *) parameter real pnsub = 0.0;
  (* desc = "Cross-term dependence of ndep" *) parameter real pndep = 0.0;
  (* desc = "Cross-term dependence of nsd" *) parameter real pnsd = 0.0;
  (* desc = "Cross-term dependence of phin" *) parameter real pphin = 0.0;
  (* desc = "Cross-term dependence of ngate" *) parameter real pngate = 0.0;
  (* desc = "Cross-term dependence of gamma1" *) parameter real pgamma1 = 0.0;
  (* desc = "Cross-term dependence of gamma2" *) parameter real pgamma2 = 0.0;
  (* desc = "Cross-term dependence of vbx" *) parameter real pvbx = 0.0;
  (* desc = "Cross-term dependence of vbm" *) parameter real pvbm = 0.0;
  (* desc = "Cross-term dependence of xt" *) parameter real pxt = 0.0;
  (* desc = "Cross-term dependence of k1" *) parameter real pk1 = 0.0;
  (* desc = "Cross-term dependence of kt1" *) parameter real pkt1 = 0.0;
  (* desc = "Cross-term dependence of kt1l" *) parameter real pkt1l = 0.0;
  (* desc = "Cross-term dependence of kt2" *) parameter real pkt2 = 0.0;
  (* desc = "Cross-term dependence of k2" *) parameter real pk2 = 0.0;
  (* desc = "Cross-term dependence of k3" *) parameter real pk3 = 0.0;
  (* desc = "Cross-term dependence of k3b" *) parameter real pk3b = 0.0;
  (* desc = "Cross-term dependence of w0" *) parameter real pw0 = 0.0;
  (* desc = "Cross-term dependence of dvtp0" *) parameter real pdvtp0 = 0.0;
  (* desc = "Cross-term dependence of dvtp1" *) parameter real pdvtp1 = 0.0;
  (* desc = "Cross-term dependence of dvtp2" *) parameter real pdvtp2 = 0.0;
  (* desc = "Cross-term dependence of dvtp3" *) parameter real pdvtp3 = 0.0;
  (* desc = "Cross-term dependence of dvtp4" *) parameter real pdvtp4 = 0.0;
  (* desc = "Cross-term dependence of dvtp5" *) parameter real pdvtp5 = 0.0;
  (* desc = "Cross-term dependence of lpe0" *) parameter real plpe0 = 0.0;
  (* desc = "Cross-term dependence of lpeb" *) parameter real plpeb = 0.0;
  (* desc = "Cross-term dependence of dvt0" *) parameter real pdvt0 = 0.0;
  (* desc = "Cross-term dependence of dvt1" *) parameter real pdvt1 = 0.0;
  (* desc = "Cross-term dependence of dvt2" *) parameter real pdvt2 = 0.0;
  (* desc = "Cross-term dependence of dvt0w" *) parameter real pdvt0w = 0.0;
  (* desc = "Cross-term dependence of dvt1w" *) parameter real pdvt1w = 0.0;
  (* desc = "Cross-term dependence of dvt2w" *) parameter real pdvt2w = 0.0;
  (* desc = "Cross-term dependence of drout" *) parameter real pdrout = 0.0;
  (* desc = "Cross-term dependence of dsub" *) parameter real pdsub = 0.0;
  (* desc = "Cross-term dependence of vto" *) parameter real pvth0 = 0.0;
  aliasparam pvtho = pvth0;
  (* desc = "Cross-term dependence of ua" *) parameter real pua = 0.0;
  (* desc = "Cross-term dependence of ua1" *) parameter real pua1 = 0.0;
  (* desc = "Cross-term dependence of ub" *) parameter real pub = 0.0;
  (* desc = "Cross-term dependence of ub1" *) parameter real pub1 = 0.0;
  (* desc = "Cross-term dependence of uc" *) parameter real puc = 0.0;
  (* desc = "Cross-term dependence of uc1" *) parameter real puc1 = 0.0;
  (* desc = "Cross-term dependence of ud" *) parameter real pud = 0.0;
  (* desc = "Cross-term dependence of ud1" *) parameter real pud1 = 0.0;
  (* desc = "Cross-term dependence of up" *) parameter real pup = 0.0;
  (* desc = "Cross-term dependence of lp" *) parameter real plp = 0.0;
  (* desc = "Cross-term dependence of u0" *) parameter real pu0 = 0.0;
  (* desc = "Cross-term dependence of ute" *) parameter real pute = 0.0;
  (* desc = "Cross-term dependence of ucste" *) parameter real pucste = 0.0;
  (* desc = "Cross-term dependence of voff" *) parameter real pvoff = 0.0;
  (* desc = "Cross-term dependence of minv" *) parameter real pminv = 0.0;
  (* desc = "Cross-term dependence of minvcv" *) parameter real pminvcv = 0.0;
  (* desc = "Cross-term dependence of delta" *) parameter real pdelta = 0.0;
  (* desc = "Cross-term dependence of rdsw " *) parameter real prdsw = 0.0;
  (* desc = "Cross-term dependence of rsw" *) parameter real prsw = 0.0;
  (* desc = "Cross-term dependence of rdw" *) parameter real prdw = 0.0;
  (* desc = "Cross-term dependence of prwg " *) parameter real pprwg = 0.0;
  (* desc = "Cross-term dependence of prwb " *) parameter real pprwb = 0.0;
  (* desc = "Cross-term dependence of prt " *) parameter real pprt = 0.0;
  (* desc = "Cross-term dependence of eta0" *) parameter real peta0 = 0.0;
  (* desc = "Cross-term dependence of etab" *) parameter real petab = 0.0;
  (* desc = "Cross-term dependence of pclm" *) parameter real ppclm = 0.0;
  (* desc = "Cross-term dependence of pdiblc1" *) parameter real ppdiblc1 = 0.0;
  (* desc = "Cross-term dependence of pdiblc2" *) parameter real ppdiblc2 = 0.0;
  (* desc = "Cross-term dependence of pdiblcb" *) parameter real ppdiblcb = 0.0;
  (* desc = "Cross-term dependence of pdiblcb" *) parameter real pfprout = 0.0;
  (* desc = "Cross-term dependence of pdits" *) parameter real ppdits = 0.0;
  (* desc = "Cross-term dependence of pditsd" *) parameter real ppditsd = 0.0;
  (* desc = "Cross-term dependence of pscbe1" *) parameter real ppscbe1 = 0.0;
  (* desc = "Cross-term dependence of pscbe2" *) parameter real ppscbe2 = 0.0;
  (* desc = "Cross-term dependence of pvag" *) parameter real ppvag = 0.0;
  (* desc = "Cross-term dependence of wr" *) parameter real pwr = 0.0;
  (* desc = "Cross-term dependence of dwg" *) parameter real pdwg = 0.0;
  (* desc = "Cross-term dependence of dwb" *) parameter real pdwb = 0.0;
  (* desc = "Cross-term dependence of b0" *) parameter real pb0 = 0.0;
  (* desc = "Cross-term dependence of b1" *) parameter real pb1 = 0.0;
  (* desc = "Cross-term dependence of cgsl" *) parameter real pcgsl = 0.0;
  (* desc = "Cross-term dependence of cgdl" *) parameter real pcgdl = 0.0;
  (* desc = "Cross-term dependence of ckappas" *) parameter real pckappas = 0.0;
  (* desc = "Cross-term dependence of ckappad" *) parameter real pckappad = 0.0;
  (* desc = "Cross-term dependence of cf" *) parameter real pcf = 0.0;
  (* desc = "Cross-term dependence of clc" *) parameter real pclc = 0.0;
  (* desc = "Cross-term dependence of cle" *) parameter real pcle = 0.0;
  (* desc = "Cross-term dependence of alpha0" *) parameter real palpha0 = 0.0;
  (* desc = "Cross-term dependence of alpha1" *) parameter real palpha1 = 0.0;
  (* desc = "Cross-term dependence of beta0" *) parameter real pbeta0 = 0.0;
  (* desc = "Cross-term dependence of agidl" *) parameter real pagidl = 0.0;
  (* desc = "Cross-term dependence of bgidl" *) parameter real pbgidl = 0.0;
  (* desc = "Cross-term dependence of cgidl" *) parameter real pcgidl = 0.0;
  (* desc = "Cross-term dependence of rgidl" *) parameter real prgidl = 0.0;
  (* desc = "Cross-term dependence of kgidl" *) parameter real pkgidl = 0.0;
  (* desc = "Cross-term dependence of fgidl" *) parameter real pfgidl = 0.0;
  (* desc = "Cross-term dependence of egidl" *) parameter real pegidl = 0.0;
  (* desc = "Cross-term dependence of agisl" *) parameter real pagisl = 0;
  (* desc = "Cross-term dependence of bgisl" *) parameter real pbgisl = 0;
  (* desc = "Cross-term dependence of cgisl" *) parameter real pcgisl = 0;
  (* desc = "Cross-term dependence of egisl" *) parameter real pegisl = 0;
  (* desc = "Cross-term dependence of rgisl" *) parameter real prgisl = 0;
  (* desc = "Cross-term dependence of kgisl" *) parameter real pkgisl = 0;
  (* desc = "Cross-term dependence of fgisl" *) parameter real pfgisl = 0;
  (* desc = "Cross-term dependence of aigc" *) parameter real paigc = 0.0;
  (* desc = "Cross-term dependence of bigc" *) parameter real pbigc = 0.0;
  (* desc = "Cross-term dependence of cigc" *) parameter real pcigc = 0.0;
  (* desc = "Cross-term dependence of aigsd" *) parameter real paigsd = 0.0;
  (* desc = "Cross-term dependence of bigsd" *) parameter real pbigsd = 0.0;
  (* desc = "Cross-term dependence of cigsd" *) parameter real pcigsd = 0.0;
  (* desc = "Cross-term dependence of aigs" *) parameter real paigs = 0.0;
  (* desc = "Cross-term dependence of bigs" *) parameter real pbigs = 0.0;
  (* desc = "Cross-term dependence of cigs" *) parameter real pcigs = 0.0;
  (* desc = "Cross-term dependence of aigd" *) parameter real paigd = 0.0;
  (* desc = "Cross-term dependence of bigd" *) parameter real pbigd = 0.0;
  (* desc = "Cross-term dependence of cigd" *) parameter real pcigd = 0.0;
  (* desc = "Cross-term dependence of aigbacc" *) parameter real paigbacc = 0.0;
  (* desc = "Cross-term dependence of bigbacc" *) parameter real pbigbacc = 0.0;
  (* desc = "Cross-term dependence of cigbacc" *) parameter real pcigbacc = 0.0;
  (* desc = "Cross-term dependence of aigbinv" *) parameter real paigbinv = 0.0;
  (* desc = "Cross-term dependence of bigbinv" *) parameter real pbigbinv = 0.0;
  (* desc = "Cross-term dependence of cigbinv" *) parameter real pcigbinv = 0.0;
  (* desc = "Cross-term dependence of nigc" *) parameter real pnigc = 0.0;
  (* desc = "Cross-term dependence of nigbinv" *) parameter real pnigbinv = 0.0;
  (* desc = "Cross-term dependence of nigbacc" *) parameter real pnigbacc = 0.0;
  (* desc = "Cross-term dependence of ntox" *) parameter real pntox = 0.0;
  (* desc = "Cross-term dependence for eigbinv" *) parameter real peigbinv = 0.0;
  (* desc = "Cross-term dependence for pigcd" *) parameter real ppigcd = 0.0;
  (* desc = "Cross-term dependence for poxedge" *) parameter real ppoxedge = 0.0;
  (* desc = "Cross-term dependence of vfbcv" *) parameter real pvfbcv = 0.0;
  (* desc = "Cross-term dependence of vfb" *) parameter real pvfb = 0.0;
  (* desc = "Cross-term dependence of acde" *) parameter real pacde = 0.0;
  (* desc = "Cross-term dependence of moin" *) parameter real pmoin = 0.0;
  (* desc = "Cross-term dependence of noff" *) parameter real pnoff = 0.0;
  (* desc = "Cross-term dependence of voffcv" *) parameter real pvoffcv = 0.0;
  (* desc = "Cross-term dependence of xrcrg1" *) parameter real pxrcrg1 = 0.0;
  (* desc = "Cross-term dependence of xrcrg2" *) parameter real pxrcrg2 = 0.0;
  (* desc = "Cross-term dependence of lambda" *) parameter real plambda = 0.0;
  (* desc = "Cross-term dependence of vtl" *) parameter real pvtl = 0.0;
  (* desc = "Cross-term dependence of xn" *) parameter real pxn = 0.0;
  (* desc = "Cross-term dependence of eu" *) parameter real peu = 0.0;
  (* desc = "Cross-term dependence of ucs" *) parameter real pucs = 0.0;
  (* desc = "Cross-term dependence of vfbsdoff" *) parameter real pvfbsdoff = 0.0;
  (* desc = "Cross-term dependence of tvfbsdoff" *) parameter real ptvfbsdoff = 0.0;
  (* desc = "Cross-term dependence of tvoff" *) parameter real ptvoff = 0.0;
  (* desc = "Cross-term dependence of tnfactor" *) parameter real ptnfactor = 0.0;
  (* desc = "Cross-term dependence of teta0" *) parameter real pteta0 = 0.0;
  (* desc = "Cross-term dependence of tvoffcv" *) parameter real ptvoffcv = 0.0;
  (* desc = "Reference distance between OD edge to poly of one side" *) parameter real saref = 1e-06;
  (* desc = "Reference distance between OD edge to poly of the other side" *) parameter real sbref = 1e-06;
  (* desc = "Width parameter for stress effect" *) parameter real wlod = 0;
  (* desc = "Mobility degradation/enhancement coefficient for LOD" *) parameter real ku0 = 0;
  (* desc = "Saturation velocity degradation/enhancement parameter for LOD" *) parameter real kvsat = 0;
  (* desc = "Threshold degradation/enhancement parameter for LOD" *) parameter real kvth0 = 0;
  (* desc = "Temperature coefficient of KU0" *) parameter real tku0 = 0;
  (* desc = "Length parameter for u0 LOD effect" *) parameter real llodku0 = 0;
  (* desc = "Width parameter for u0 LOD effect" *) parameter real wlodku0 = 0;
  (* desc = "Length parameter for vth LOD effect" *) parameter real llodvth = 0;
  (* desc = "Width parameter for vth LOD effect" *) parameter real wlodvth = 0;
  (* desc = "Length dependence of ku0" *) parameter real lku0 = 0;
  (* desc = "Width dependence of ku0" *) parameter real wku0 = 0;
  (* desc = "Cross-term dependence of ku0" *) parameter real pku0 = 0;
  (* desc = "Length dependence of kvth0" *) parameter real lkvth0 = 0;
  (* desc = "Width dependence of kvth0" *) parameter real wkvth0 = 0;
  (* desc = "Cross-term dependence of kvth0" *) parameter real pkvth0 = 0;
  (* desc = "K2 shift factor related to stress effect on vth" *) parameter real stk2 = 0;
  (* desc = "K2 shift modification factor for stress effect" *) parameter real lodk2 = 1.0;
  (* desc = "eta0 shift factor related to stress effect on vth" *) parameter real steta0 = 0;
  (* desc = "eta0 shift modification factor for stress effect" *) parameter real lodeta0 = 1.0;
  (* desc = "Coefficient for SCB" *) parameter real web = 0.0;
  (* desc = "Coefficient for SCC" *) parameter real wec = 0.0;
  (* desc = "Threshold shift factor for well proximity effect" *) parameter real kvth0we = 0.0;
  (* desc = " K2 shift factor for well proximity effect " *) parameter real k2we = 0.0;
  (* desc = " Mobility degradation factor for well proximity effect " *) parameter real ku0we = 0.0;
  (* desc = " Reference distance to calculate SCA, SCB and SCC" *) parameter real scref = 1e-06;
  (* desc = " Flag for WPE model (WPEMOD=1 to activate this model) " *) parameter real wpemod = 0;
  (* desc = "Length dependence of kvth0we" *) parameter real lkvth0we = 0;
  (* desc = " Length dependence of k2we " *) parameter real lk2we = 0;
  (* desc = " Length dependence of ku0we " *) parameter real lku0we = 0;
  (* desc = "Width dependence of kvth0we" *) parameter real wkvth0we = 0;
  (* desc = " Width dependence of k2we " *) parameter real wk2we = 0;
  (* desc = " Width dependence of ku0we " *) parameter real wku0we = 0;
  (* desc = "Cross-term dependence of kvth0we" *) parameter real pkvth0we = 0;
  (* desc = " Cross-term dependence of k2we " *) parameter real pk2we = 0;
  (* desc = " Cross-term dependence of ku0we " *) parameter real pku0we = 0;
  (* desc = "Flicker noise parameter" *) parameter real noia = 0;
  (* desc = "Flicker noise parameter" *) parameter real noib = 0;
  (* desc = "Flicker noise parameter" *) parameter real noic = 8750000000.0;
  (* desc = "Thermal noise parameter" *) parameter real tnoia = 1.5;
  (* desc = "Thermal noise parameter" *) parameter real tnoib = 3.5;
  (* desc = "Thermal noise parameter" *) parameter real tnoic = 0.0;
  (* desc = "Thermal noise coefficient" *) parameter real rnoia = 0.577;
  (* desc = "Thermal noise coefficient" *) parameter real rnoib = 0.5164;
  (* desc = "Thermal noise coefficient" *) parameter real rnoic = 0.395;
  (* desc = "gidl clamp value" *) parameter real gidlclamp = 0;
  (* desc = "noise clamping limit parameter" *) parameter real idovvds = 1e-09;
  (* desc = "Thermal noise parameter" *) parameter real ntnoi = 1.0;
  (* desc = "Flicker noise parameter" *) parameter real em = 41000000.0;
  (* desc = "Flicker noise frequency exponent" *) parameter real ef = 1.0;
  (* desc = "Flicker noise exponent" *) parameter real af = 1.0;
  (* desc = "Flicker noise coefficient" *) parameter real kf = 0.0;
  (* desc = "maximum voltage G-S branch" *) parameter real vgs_max = 1e+99;
  (* desc = "maximum voltage G-D branch" *) parameter real vgd_max = 1e+99;
  (* desc = "maximum voltage G-B branch" *) parameter real vgb_max = 1e+99;
  (* desc = "maximum voltage D-S branch" *) parameter real vds_max = 1e+99;
  (* desc = "maximum voltage B-S branch" *) parameter real vbs_max = 1e+99;
  (* desc = "maximum voltage B-D branch" *) parameter real vbd_max = 1e+99;
  (* desc = "maximum voltage G-S branch" *) parameter real vgsr_max = 1e+99;
  (* desc = "maximum voltage G-D branch" *) parameter real vgdr_max = 1e+99;
  (* desc = "maximum voltage G-B branch" *) parameter real vgbr_max = 1e+99;
  (* desc = "maximum voltage B-S branch" *) parameter real vbsr_max = 1e+99;
  (* desc = "maximum voltage B-D branch" *) parameter real vbdr_max = 1e+99;
  (* desc = "N-type (1) or P-type (-1)" *) parameter integer type = 1;

  // Instance output variables
  (* desc = "Gmb" *) real gmbs;
  (* desc = "Gm" *) real gm;
  (* desc = "Gds" *) real gds;
  (* desc = "Vdsat" *) real vdsat;
  (* desc = "Vth" *) real vth;
  (* desc = "Ids" *) real id;
  (* desc = "Ibd" *) real ibd;
  (* desc = "Ibs" *) real ibs;
  (* desc = "gbd" *) real gbd;
  (* desc = "gbs" *) real gbs;
  (* desc = "Isub" *) real isub;
  (* desc = "Igidl" *) real igidl;
  (* desc = "Igisl" *) real igisl;
  (* desc = "Igs" *) real igs;
  (* desc = "Igd" *) real igd;
  (* desc = "Igb" *) real igb;
  (* desc = "Igcs" *) real igcs;
  (* desc = "Igcd" *) real igcd;
  (* desc = "Vbs" *) real vbs;
  (* desc = "Vgs" *) real vgs;
  (* desc = "Vds" *) real vds;
  (* desc = "Cggb" *) real cgg;
  (* desc = "Cgsb" *) real cgs;
  (* desc = "Cgdb" *) real cgd;
  (* desc = "Cbgb" *) real cbg;
  (* desc = "Cbdb" *) real cbd;
  (* desc = "Cbsb" *) real cbs;
  (* desc = "Cdgb" *) real cdg;
  (* desc = "Cddb" *) real cdd;
  (* desc = "Cdsb" *) real cds;
  (* desc = "Csgb" *) real csg;
  (* desc = "Csdb" *) real csd;
  (* desc = "Cssb" *) real css;
  (* desc = "Cgbb" *) real cgb;
  (* desc = "Cdbb" *) real cdb;
  (* desc = "Csbb" *) real csb;
  (* desc = "Cbbb" *) real cbb;
  (* desc = "Capbd" *) real capbd;
  (* desc = "Capbs" *) real capbs;
  (* desc = "Qgate" *) real qg;
  (* desc = "Qbulk" *) real qb;
  (* desc = "Qdrain" *) real qd;
  (* desc = "Qsource" *) real qs;
  (* desc = "Qinversion" *) real qinv;
  (* desc = "Qdef" *) real qdef;
  (* desc = "Gcrg" *) real gcrg;
  (* desc = "Gtau" *) real gtau;
  (* desc = "Vgsteff" *) real vgsteff;
  (* desc = "Vdseff" *) real vdseff;
  (* desc = "Cgso" *) real c_gso;
  (* desc = "Cgdo" *) real c_gdo;
  (* desc = "Cgbo" *) real c_gbo;
  (* desc = "Weff" *) real weff;
  (* desc = "Leff" *) real leff;

  // Model output variables

  // Instance fields
  real BSIM4ueff = 0;
  real BSIM4thetavth = 0;
  real BSIM4von = 0;
  real BSIM4vdsat = 0;
  real i_BSIM4cgdo = 0;
  real BSIM4qgdo = 0;
  real i_BSIM4cgso = 0;
  real BSIM4qgso = 0;
  real BSIM4grbsb = 0;
  real BSIM4grbdb = 0;
  real BSIM4grbpb = 0;
  real BSIM4grbps = 0;
  real BSIM4grbpd = 0;
  real BSIM4vjsmFwd = 0;
  real BSIM4vjsmRev = 0;
  real BSIM4vjdmFwd = 0;
  real BSIM4vjdmRev = 0;
  real BSIM4XExpBVS = 0;
  real BSIM4XExpBVD = 0;
  real BSIM4SslpFwd = 0;
  real BSIM4SslpRev = 0;
  real BSIM4DslpFwd = 0;
  real BSIM4DslpRev = 0;
  real BSIM4IVjsmFwd = 0;
  real BSIM4IVjsmRev = 0;
  real BSIM4IVjdmFwd = 0;
  real BSIM4IVjdmRev = 0;
  real BSIM4grgeltd = 0;
  real BSIM4Pseff = 0;
  real BSIM4Pdeff = 0;
  real BSIM4Aseff = 0;
  real BSIM4Adeff = 0;
  real BSIM4l = 0;
  real BSIM4w = 0;
  real BSIM4drainArea = 0;
  real BSIM4sourceArea = 0;
  real BSIM4drainPerimeter = 0;
  real BSIM4sourcePerimeter = 0;
  real BSIM4sourceConductance = 0;
  real BSIM4drainConductance = 0;
  real BSIM4sd = 0;
  real BSIM4sca = 0;
  real BSIM4scb = 0;
  real BSIM4scc = 0;
  real BSIM4sc = 0;
  real i_BSIM4rbdb = 0;
  real i_BSIM4rbsb = 0;
  real i_BSIM4rbpb = 0;
  real i_BSIM4rbps = 0;
  real i_BSIM4rbpd = 0;
  real i_BSIM4xgw = 0;
  real i_BSIM4ngcon = 0;
  real BSIM4u0temp = 0;
  real BSIM4vsattemp = 0;
  real i_BSIM4vth0 = 0;
  real i_BSIM4vfb = 0;
  real BSIM4vfbzb = 0;
  real BSIM4vtfbphi1 = 0;
  real BSIM4vtfbphi2 = 0;
  real i_BSIM4k2 = 0;
  real BSIM4vbsc = 0;
  real BSIM4k2ox = 0;
  real i_BSIM4eta0 = 0;
  real i_BSIM4toxp = 0;
  real i_BSIM4coxp = 0;
  real BSIM4mult_fn = 0;
  integer BSIM4mode = 0;
  integer i_BSIM4trnqsMod = 0;
  integer i_BSIM4acnqsMod = 0;
  integer i_BSIM4rbodyMod = 0;
  integer i_BSIM4rgateMod = 0;
  integer i_BSIM4geoMod = 0;
  real BSIM4Vgsteff = 0;
  real BSIM4vgs_eff = 0;
  real BSIM4vgd_eff = 0;
  real BSIM4dvgs_eff_dvg = 0;
  real BSIM4dvgd_eff_dvg = 0;
  real BSIM4Vdseff = 0;
  real BSIM4nstar = 0;
  real BSIM4Abulk = 0;
  real BSIM4EsatL = 0;
  real BSIM4AbovVgst2Vtm = 0;
  real BSIM4qinv = 0;
  real BSIM4cd = 0;
  real BSIM4cbs = 0;
  real BSIM4cbd = 0;
  real BSIM4csub = 0;
  real BSIM4Igidl = 0;
  real BSIM4Igisl = 0;
  real BSIM4gm = 0;
  real BSIM4gds = 0;
  real BSIM4gmbs = 0;
  real BSIM4gbd = 0;
  real BSIM4gbs = 0;
  real BSIM4noiGd0 = 0;
  real BSIM4Coxeff = 0;
  real BSIM4gbbs = 0;
  real BSIM4gbgs = 0;
  real BSIM4gbds = 0;
  real BSIM4ggidld = 0;
  real BSIM4ggidlg = 0;
  real BSIM4ggidls = 0;
  real BSIM4ggidlb = 0;
  real BSIM4ggisld = 0;
  real BSIM4ggislg = 0;
  real BSIM4ggisls = 0;
  real BSIM4ggislb = 0;
  real BSIM4Igcs = 0;
  real BSIM4gIgcsg = 0;
  real BSIM4gIgcsd = 0;
  real BSIM4gIgcss = 0;
  real BSIM4gIgcsb = 0;
  real BSIM4Igcd = 0;
  real BSIM4gIgcdg = 0;
  real BSIM4gIgcdd = 0;
  real BSIM4gIgcds = 0;
  real BSIM4gIgcdb = 0;
  real BSIM4Igs = 0;
  real BSIM4gIgsg = 0;
  real BSIM4gIgss = 0;
  real BSIM4Igd = 0;
  real BSIM4gIgdg = 0;
  real BSIM4gIgdd = 0;
  real BSIM4Igb = 0;
  real BSIM4gIgbg = 0;
  real BSIM4gIgbd = 0;
  real BSIM4gIgbs = 0;
  real BSIM4gIgbb = 0;
  real BSIM4grdsw = 0;
  real BSIM4IdovVds = 0;
  real BSIM4gcrg = 0;
  real BSIM4gcrgd = 0;
  real BSIM4gcrgg = 0;
  real BSIM4gcrgs = 0;
  real BSIM4gcrgb = 0;
  real BSIM4gstot = 0;
  real BSIM4gstotd = 0;
  real BSIM4gstotg = 0;
  real BSIM4gstots = 0;
  real BSIM4gstotb = 0;
  real BSIM4gdtot = 0;
  real BSIM4gdtotd = 0;
  real BSIM4gdtotg = 0;
  real BSIM4gdtots = 0;
  real BSIM4gdtotb = 0;
  real BSIM4cggb = 0;
  real BSIM4cgdb = 0;
  real BSIM4cgsb = 0;
  real BSIM4cbgb = 0;
  real BSIM4cbdb = 0;
  real BSIM4cbsb = 0;
  real BSIM4cdgb = 0;
  real BSIM4cddb = 0;
  real BSIM4cdsb = 0;
  real BSIM4csgb = 0;
  real BSIM4csdb = 0;
  real BSIM4cssb = 0;
  real BSIM4cgbb = 0;
  real BSIM4cdbb = 0;
  real BSIM4csbb = 0;
  real BSIM4cbbb = 0;
  real BSIM4capbd = 0;
  real BSIM4capbs = 0;
  real BSIM4cqgb = 0;
  real BSIM4cqdb = 0;
  real BSIM4cqsb = 0;
  real BSIM4cqbb = 0;
  real BSIM4qgate = 0;
  real BSIM4qbulk = 0;
  real BSIM4qdrn = 0;
  real BSIM4qsrc = 0;
  real i_BSIM4qdef = 0;
  real BSIM4qchqs = 0;
  real BSIM4taunet = 0;
  real BSIM4gtau = 0;
  real BSIM4gtg = 0;
  real BSIM4gtd = 0;
  real BSIM4gts = 0;
  real BSIM4gtb = 0;
  real BSIM4SjctTempRevSatCur = 0;
  real BSIM4DjctTempRevSatCur = 0;
  real BSIM4SswTempRevSatCur = 0;
  real BSIM4DswTempRevSatCur = 0;
  real BSIM4SswgTempRevSatCur = 0;
  real BSIM4DswgTempRevSatCur = 0;
  integer BSIM4lGiven = 0;
  integer BSIM4wGiven = 0;
  integer BSIM4drainAreaGiven = 0;
  integer BSIM4sourceAreaGiven = 0;
  integer BSIM4drainPerimeterGiven = 0;
  integer BSIM4sourcePerimeterGiven = 0;
  integer collapse_q_int = 0;

  // Model fields
  integer BSIM4mobMod = 0;
  integer BSIM4capMod = 0;
  integer BSIM4dioMod = 0;
  integer BSIM4trnqsMod = 0;
  integer BSIM4acnqsMod = 0;
  integer BSIM4fnoiMod = 0;
  integer BSIM4tnoiMod = 0;
  integer BSIM4rdsMod = 0;
  integer BSIM4rbodyMod = 0;
  integer BSIM4rgateMod = 0;
  integer BSIM4perMod = 0;
  integer BSIM4mtrlMod = 0;
  integer BSIM4mtrlCompatMod = 0;
  integer BSIM4igcMod = 0;
  integer BSIM4igbMod = 0;
  integer BSIM4tempMod = 0;
  integer BSIM4v48intVersion = 0;
  real BSIM4eot = 0;
  real BSIM4vddeot = 0;
  real BSIM4toxe = 0;
  real BSIM4toxp = 0;
  real BSIM4toxm = 0;
  real BSIM4keta = 0;
  real BSIM4ketac = 0;
  real BSIM4vbm = 0;
  real BSIM4kt1 = 0;
  real BSIM4dvt2 = 0;
  real BSIM4dvt2w = 0;
  real BSIM4dsub = 0;
  real BSIM4vth0 = 0;
  real BSIM4eu = 0;
  real BSIM4ucs = 0;
  real BSIM4ua = 0;
  real BSIM4ub1 = 0;
  real BSIM4uc = 0;
  real BSIM4uc1 = 0;
  real BSIM4u0 = 0;
  real BSIM4ute = 0;
  real BSIM4ucste = 0;
  real BSIM4voff = 0;
  real BSIM4etab = 0;
  real BSIM4agisl = 0;
  real BSIM4bgisl = 0;
  real BSIM4cgisl = 0;
  real BSIM4egisl = 0;
  real BSIM4fgisl = 0;
  real BSIM4kgisl = 0;
  real BSIM4rgisl = 0;
  real BSIM4aigc = 0;
  real BSIM4bigc = 0;
  real BSIM4cigc = 0;
  real BSIM4aigsd = 0;
  real BSIM4bigsd = 0;
  real BSIM4cigsd = 0;
  real BSIM4aigs = 0;
  real BSIM4bigs = 0;
  real BSIM4cigs = 0;
  real BSIM4aigd = 0;
  real BSIM4bigd = 0;
  real BSIM4cigd = 0;
  real BSIM4ijthdfwd = 0;
  real BSIM4ijthsfwd = 0;
  real BSIM4ijthdrev = 0;
  real BSIM4ijthsrev = 0;
  real BSIM4xjbvd = 0;
  real BSIM4xjbvs = 0;
  real BSIM4bvd = 0;
  real BSIM4bvs = 0;
  real BSIM4jtsd = 0;
  real BSIM4jtsswd = 0;
  real BSIM4jtsswgd = 0;
  real BSIM4jtweff = 0;
  real BSIM4njtsd = 0;
  real BSIM4njtsswd = 0;
  real BSIM4njtsswgd = 0;
  real BSIM4xtsd = 0;
  real BSIM4xtsswd = 0;
  real BSIM4xtsswgd = 0;
  real BSIM4tnjtsd = 0;
  real BSIM4tnjtsswd = 0;
  real BSIM4tnjtsswgd = 0;
  real BSIM4vtsd = 0;
  real BSIM4vtsswd = 0;
  real BSIM4vtsswgd = 0;
  real BSIM4vfb = 0;
  real BSIM4ckappad = 0;
  real BSIM4cf = 0;
  real BSIM4vfbcv = 0;
  real BSIM4dwc = 0;
  real BSIM4dlc = 0;
  real BSIM4dlcig = 0;
  real BSIM4dlcigd = 0;
  real BSIM4dwj = 0;
  real BSIM4dmci = 0;
  real BSIM4lketac = 0;
  real BSIM4letab = 0;
  real BSIM4lagisl = 0;
  real BSIM4lbgisl = 0;
  real BSIM4lcgisl = 0;
  real BSIM4legisl = 0;
  real BSIM4lfgisl = 0;
  real BSIM4lkgisl = 0;
  real BSIM4lrgisl = 0;
  real BSIM4laigs = 0;
  real BSIM4lbigs = 0;
  real BSIM4lcigs = 0;
  real BSIM4laigd = 0;
  real BSIM4lbigd = 0;
  real BSIM4lcigd = 0;
  real BSIM4wketac = 0;
  real BSIM4wagisl = 0;
  real BSIM4wbgisl = 0;
  real BSIM4wcgisl = 0;
  real BSIM4wegisl = 0;
  real BSIM4wfgisl = 0;
  real BSIM4wkgisl = 0;
  real BSIM4wrgisl = 0;
  real BSIM4waigs = 0;
  real BSIM4wbigs = 0;
  real BSIM4wcigs = 0;
  real BSIM4waigd = 0;
  real BSIM4wbigd = 0;
  real BSIM4wcigd = 0;
  real BSIM4pketac = 0;
  real BSIM4pagisl = 0;
  real BSIM4pbgisl = 0;
  real BSIM4pcgisl = 0;
  real BSIM4pegisl = 0;
  real BSIM4pfgisl = 0;
  real BSIM4pkgisl = 0;
  real BSIM4prgisl = 0;
  real BSIM4paigs = 0;
  real BSIM4pbigs = 0;
  real BSIM4pcigs = 0;
  real BSIM4paigd = 0;
  real BSIM4pbigd = 0;
  real BSIM4pcigd = 0;
  real BSIM4tnom = 0;
  real BSIM4cgso = 0;
  real BSIM4cgdo = 0;
  real BSIM4cgbo = 0;
  real BSIM4cFringOut = 0;
  real BSIM4cFringMax = 0;
  real BSIM4DjctSatCurDensity = 0;
  real BSIM4DjctSidewallSatCurDensity = 0;
  real BSIM4DjctGateSidewallSatCurDensity = 0;
  real BSIM4SbulkJctPotential = 0;
  real BSIM4DbulkJctPotential = 0;
  real BSIM4DbulkJctBotGradingCoeff = 0;
  real BSIM4DbulkJctSideGradingCoeff = 0;
  real BSIM4SbulkJctGateSideGradingCoeff = 0;
  real BSIM4DbulkJctGateSideGradingCoeff = 0;
  real BSIM4SsidewallJctPotential = 0;
  real BSIM4DsidewallJctPotential = 0;
  real BSIM4SGatesidewallJctPotential = 0;
  real BSIM4DGatesidewallJctPotential = 0;
  real BSIM4DunitAreaJctCap = 0;
  real BSIM4SunitLengthSidewallJctCap = 0;
  real BSIM4DunitLengthSidewallJctCap = 0;
  real BSIM4SunitLengthGateSidewallJctCap = 0;
  real BSIM4DunitLengthGateSidewallJctCap = 0;
  real BSIM4DjctEmissionCoeff = 0;
  real BSIM4DjctTempExponent = 0;
  real BSIM4njtsstemp = 0;
  real BSIM4njtsswstemp = 0;
  real BSIM4njtsswgstemp = 0;
  real BSIM4njtsdtemp = 0;
  real BSIM4njtsswdtemp = 0;
  real BSIM4njtsswgdtemp = 0;
  real BSIM4Llc = 0;
  real BSIM4Lwc = 0;
  real BSIM4Lwlc = 0;
  real BSIM4Wlc = 0;
  real BSIM4Wwc = 0;
  real BSIM4Wwlc = 0;
  real BSIM4wpemod = 0;
  real BSIM4Eg0 = 0;
  real BSIM4vtm = 0;
  real BSIM4vtm0 = 0;
  real BSIM4coxe = 0;
  real BSIM4coxp = 0;
  real BSIM4cof1 = 0;
  real BSIM4cof2 = 0;
  real BSIM4cof3 = 0;
  real BSIM4cof4 = 0;
  real BSIM4vcrit = 0;
  real BSIM4factor1 = 0;
  real BSIM4PhiBS = 0;
  real BSIM4PhiBSWS = 0;
  real BSIM4PhiBSWGS = 0;
  real BSIM4SjctTempSatCurDensity = 0;
  real BSIM4SjctSidewallTempSatCurDensity = 0;
  real BSIM4SjctGateSidewallTempSatCurDensity = 0;
  real BSIM4PhiBD = 0;
  real BSIM4PhiBSWD = 0;
  real BSIM4PhiBSWGD = 0;
  real BSIM4DjctTempSatCurDensity = 0;
  real BSIM4DjctSidewallTempSatCurDensity = 0;
  real BSIM4DjctGateSidewallTempSatCurDensity = 0;
  real BSIM4SunitAreaTempJctCap = 0;
  real BSIM4DunitAreaTempJctCap = 0;
  real BSIM4SunitLengthSidewallTempJctCap = 0;
  real BSIM4DunitLengthSidewallTempJctCap = 0;
  real BSIM4SunitLengthGateSidewallTempJctCap = 0;
  real BSIM4DunitLengthGateSidewallTempJctCap = 0;
  real BSIM4oxideTrapDensityA = 0;
  real BSIM4oxideTrapDensityB = 0;
  real BSIM4gidlclamp = 0;
  integer BSIM4type = 0;
  integer BSIM4tnomGiven = 0;

  // Structure: size dependent parameters
  real Width = 0;
  real Length = 0;
  real NFinger = 0;
  real sd_BSIM4cdsc = 0;
  real sd_BSIM4cdscb = 0;
  real sd_BSIM4cdscd = 0;
  real sd_BSIM4cit = 0;
  real sd_BSIM4nfactor = 0;
  real sd_BSIM4xj = 0;
  real sd_BSIM4vsat = 0;
  real sd_BSIM4at = 0;
  real sd_BSIM4a0 = 0;
  real sd_BSIM4ags = 0;
  real sd_BSIM4a1 = 0;
  real sd_BSIM4a2 = 0;
  real sd_BSIM4keta = 0;
  real sd_BSIM4ketac = 0;
  real sd_BSIM4nsub = 0;
  real sd_BSIM4ndep = 0;
  real sd_BSIM4nsd = 0;
  real sd_BSIM4phin = 0;
  real sd_BSIM4ngate = 0;
  real sd_BSIM4gamma1 = 0;
  real sd_BSIM4gamma2 = 0;
  real sd_BSIM4vbx = 0;
  real BSIM4vbi = 0;
  real sd_BSIM4vbm = 0;
  real sd_BSIM4xt = 0;
  real BSIM4phi = 0;
  real BSIM4litl = 0;
  real sd_BSIM4k1 = 0;
  real sd_BSIM4kt1 = 0;
  real sd_BSIM4kt1l = 0;
  real sd_BSIM4kt2 = 0;
  real sd_BSIM4k2 = 0;
  real sd_BSIM4k3 = 0;
  real sd_BSIM4k3b = 0;
  real sd_BSIM4w0 = 0;
  real sd_BSIM4dvtp0 = 0;
  real sd_BSIM4dvtp1 = 0;
  real sd_BSIM4dvtp2 = 0;
  real sd_BSIM4dvtp3 = 0;
  real sd_BSIM4dvtp4 = 0;
  real sd_BSIM4dvtp5 = 0;
  real sd_BSIM4lpe0 = 0;
  real sd_BSIM4lpeb = 0;
  real sd_BSIM4dvt0 = 0;
  real sd_BSIM4dvt1 = 0;
  real sd_BSIM4dvt2 = 0;
  real sd_BSIM4dvt0w = 0;
  real sd_BSIM4dvt1w = 0;
  real sd_BSIM4dvt2w = 0;
  real sd_BSIM4drout = 0;
  real sd_BSIM4dsub = 0;
  real sd_BSIM4vth0 = 0;
  real sd_BSIM4ua = 0;
  real sd_BSIM4ua1 = 0;
  real sd_BSIM4ub = 0;
  real sd_BSIM4ub1 = 0;
  real sd_BSIM4uc = 0;
  real sd_BSIM4uc1 = 0;
  real sd_BSIM4ud = 0;
  real sd_BSIM4ud1 = 0;
  real sd_BSIM4up = 0;
  real sd_BSIM4lp = 0;
  real sd_BSIM4u0 = 0;
  real sd_BSIM4eu = 0;
  real sd_BSIM4ucs = 0;
  real sd_BSIM4ute = 0;
  real sd_BSIM4ucste = 0;
  real sd_BSIM4voff = 0;
  real sd_BSIM4tvoff = 0;
  real sd_BSIM4tnfactor = 0;
  real sd_BSIM4teta0 = 0;
  real sd_BSIM4tvoffcv = 0;
  real sd_BSIM4minv = 0;
  real sd_BSIM4minvcv = 0;
  real sd_BSIM4vfb = 0;
  real sd_BSIM4delta = 0;
  real sd_BSIM4rdsw = 0;
  real BSIM4rds0 = 0;
  real BSIM4rs0 = 0;
  real BSIM4rd0 = 0;
  real sd_BSIM4rsw = 0;
  real sd_BSIM4rdw = 0;
  real sd_BSIM4prwg = 0;
  real sd_BSIM4prwb = 0;
  real sd_BSIM4prt = 0;
  real sd_BSIM4eta0 = 0;
  real sd_BSIM4etab = 0;
  real sd_BSIM4pclm = 0;
  real sd_BSIM4pdibl1 = 0;
  real sd_BSIM4pdibl2 = 0;
  real sd_BSIM4pdiblb = 0;
  real sd_BSIM4fprout = 0;
  real sd_BSIM4pdits = 0;
  real sd_BSIM4pditsd = 0;
  real sd_BSIM4pscbe1 = 0;
  real sd_BSIM4pscbe2 = 0;
  real sd_BSIM4pvag = 0;
  real sd_BSIM4wr = 0;
  real sd_BSIM4dwg = 0;
  real sd_BSIM4dwb = 0;
  real sd_BSIM4b0 = 0;
  real sd_BSIM4b1 = 0;
  real sd_BSIM4alpha0 = 0;
  real sd_BSIM4alpha1 = 0;
  real sd_BSIM4beta0 = 0;
  real sd_BSIM4agidl = 0;
  real sd_BSIM4bgidl = 0;
  real sd_BSIM4cgidl = 0;
  real sd_BSIM4egidl = 0;
  real sd_BSIM4fgidl = 0;
  real sd_BSIM4kgidl = 0;
  real sd_BSIM4rgidl = 0;
  real sd_BSIM4agisl = 0;
  real sd_BSIM4bgisl = 0;
  real sd_BSIM4cgisl = 0;
  real sd_BSIM4egisl = 0;
  real sd_BSIM4fgisl = 0;
  real sd_BSIM4kgisl = 0;
  real sd_BSIM4rgisl = 0;
  real sd_BSIM4aigc = 0;
  real sd_BSIM4bigc = 0;
  real sd_BSIM4cigc = 0;
  real sd_BSIM4aigsd = 0;
  real sd_BSIM4bigsd = 0;
  real sd_BSIM4cigsd = 0;
  real sd_BSIM4aigs = 0;
  real sd_BSIM4bigs = 0;
  real sd_BSIM4cigs = 0;
  real sd_BSIM4aigd = 0;
  real sd_BSIM4bigd = 0;
  real sd_BSIM4cigd = 0;
  real sd_BSIM4aigbacc = 0;
  real sd_BSIM4bigbacc = 0;
  real sd_BSIM4cigbacc = 0;
  real sd_BSIM4aigbinv = 0;
  real sd_BSIM4bigbinv = 0;
  real sd_BSIM4cigbinv = 0;
  real sd_BSIM4nigc = 0;
  real sd_BSIM4nigbacc = 0;
  real sd_BSIM4nigbinv = 0;
  real sd_BSIM4ntox = 0;
  real sd_BSIM4eigbinv = 0;
  real sd_BSIM4pigcd = 0;
  real sd_BSIM4poxedge = 0;
  real sd_BSIM4xrcrg1 = 0;
  real sd_BSIM4xrcrg2 = 0;
  real sd_BSIM4lambda = 0;
  real sd_BSIM4vtl = 0;
  real sd_BSIM4xn = 0;
  real sd_BSIM4lc = 0;
  real BSIM4tfactor = 0;
  real sd_BSIM4vfbsdoff = 0;
  real sd_BSIM4tvfbsdoff = 0;
  real sd_BSIM4ku0 = 0;
  real sd_BSIM4kvth0 = 0;
  real BSIM4ku0temp = 0;
  real BSIM4rho_ref = 0;
  real BSIM4inv_od_ref = 0;
  real sd_BSIM4kvth0we = 0;
  real sd_BSIM4k2we = 0;
  real sd_BSIM4ku0we = 0;
  real sd_BSIM4cgsl = 0;
  real sd_BSIM4cgdl = 0;
  real sd_BSIM4ckappas = 0;
  real sd_BSIM4ckappad = 0;
  real sd_BSIM4cf = 0;
  real sd_BSIM4clc = 0;
  real sd_BSIM4cle = 0;
  real sd_BSIM4vfbcv = 0;
  real sd_BSIM4noff = 0;
  real sd_BSIM4voffcv = 0;
  real sd_BSIM4acde = 0;
  real sd_BSIM4moin = 0;
  real BSIM4dw = 0;
  real BSIM4dl = 0;
  real BSIM4leff = 0;
  real BSIM4weff = 0;
  real sd_BSIM4dwc = 0;
  real sd_BSIM4dlc = 0;
  real sd_BSIM4dwj = 0;
  real BSIM4leffCV = 0;
  real BSIM4weffCV = 0;
  real BSIM4weffCJ = 0;
  real BSIM4abulkCVfactor = 0;
  real sd_BSIM4cgso = 0;
  real sd_BSIM4cgdo = 0;
  real sd_BSIM4cgbo = 0;
  real sd_BSIM4u0temp = 0;
  real sd_BSIM4vsattemp = 0;
  real BSIM4sqrtPhi = 0;
  real BSIM4phis3 = 0;
  real BSIM4Xdep0 = 0;
  real BSIM4sqrtXdep0 = 0;
  real BSIM4theta0vb0 = 0;
  real BSIM4thetaRout = 0;
  real BSIM4mstar = 0;
  real BSIM4VgsteffVth = 0;
  real BSIM4mstarcv = 0;
  real BSIM4voffcbn = 0;
  real BSIM4voffcbncv = 0;
  real sd_BSIM4rdswmin = 0;
  real sd_BSIM4rdwmin = 0;
  real sd_BSIM4rswmin = 0;
  real BSIM4vfbsd = 0;
  real sd_BSIM4cof1 = 0;
  real sd_BSIM4cof2 = 0;
  real sd_BSIM4cof3 = 0;
  real sd_BSIM4cof4 = 0;
  real BSIM4cdep0 = 0;
  real BSIM4ToxRatio = 0;
  real BSIM4Aechvb = 0;
  real BSIM4Bechvb = 0;
  real BSIM4ToxRatioEdge = 0;
  real BSIM4AechvbEdgeS = 0;
  real BSIM4AechvbEdgeD = 0;
  real BSIM4BechvbEdge = 0;
  real BSIM4ldeb = 0;
  real BSIM4k1ox = 0;
  real sd_BSIM4k2ox = 0;
  real BSIM4vfbzbfactor = 0;
  real BSIM4dvtp2factor = 0;

  // States
  real BSIM4vbd = 0;
  real BSIM4vbs = 0;
  real BSIM4vgs = 0;
  real BSIM4vds = 0;
  real BSIM4vdbs = 0;
  real BSIM4vdbd = 0;
  real BSIM4vsbs = 0;
  real BSIM4vges = 0;
  real BSIM4vgms = 0;
  real BSIM4vses = 0;
  real BSIM4vdes = 0;
  real BSIM4qb = 0;
  real BSIM4cqb = 0;
  real BSIM4qg = 0;
  real BSIM4cqg = 0;
  real BSIM4qd = 0;
  real BSIM4cqd = 0;
  real BSIM4qgmid = 0;
  real BSIM4cqgmid = 0;
  real BSIM4qbs = 0;
  real BSIM4cqbs = 0;
  real BSIM4qbd = 0;
  real BSIM4cqbd = 0;
  real BSIM4qcheq = 0;
  real BSIM4cqcheq = 0;
  real BSIM4qcdump = 0;
  real BSIM4cqcdump = 0;
  real BSIM4qdef = 0;
  real BSIM4qs = 0;

  // Model parameter access locals

  // Instance parameter access locals

  // Device setup locals
  integer createNode = 0;
  real Rtot = 0;
  real DMCGeff = 0;
  real DMCIeff = 0;
  real DMDGeff = 0;

  // Device temperature dependence locals
  real tmp = 0;
  real tmp1 = 0;
  real tmp2 = 0;
  real tmp3 = 0;
  real Eg = 0;
  real Eg0 = 0;
  real ni = 0;
  real epssub = 0;
  real T0 = 0;
  real T1 = 0;
  real T2 = 0;
  real T3 = 0;
  real T4 = 0;
  real T5 = 0;
  real T6 = 0;
  real T7 = 0;
  real T8 = 0;
  real T9 = 0;
  real Lnew = 0;
  real Wnew = 0;
  real delTemp = 0;
  real Temp = 0;
  real TRatio = 0;
  real Inv_L = 0;
  real Inv_W = 0;
  real Inv_LW = 0;
  real Vtm0 = 0;
  real Tnom = 0;
  real dumPs = 0;
  real dumPd = 0;
  real dumAs = 0;
  real dumAd = 0;
  real PowWeffWr = 0;
  real temp_DMCGeff = 0;
  real temp_DMCIeff = 0;
  real temp_DMDGeff = 0;
  real Nvtms = 0;
  real Nvtmd = 0;
  real SourceSatCurrent = 0;
  real DrainSatCurrent = 0;
  real T10 = 0;
  real T11 = 0;
  real Inv_saref = 0;
  real Inv_sbref = 0;
  real Inv_sa = 0;
  real Inv_sb = 0;
  real rho = 0;
  real Ldrn = 0;
  real dvth0_lod = 0;
  real W_tmp = 0;
  real Inv_ODeff = 0;
  real OD_offset = 0;
  real dk2_lod = 0;
  real deta0_lod = 0;
  real lnl = 0;
  real lnw = 0;
  real lnnf = 0;
  real rbpbx = 0;
  real rbpby = 0;
  real rbsbx = 0;
  real rbsby = 0;
  real rbdbx = 0;
  real rbdby = 0;
  real bodymode = 0;
  real temp_kvsat = 0;
  real temp_wlod = 0;
  real sceff = 0;
  real Wdrn = 0;
  real V0 = 0;
  real lt1 = 0;
  real ltw = 0;
  real Theta0 = 0;
  real Delt_vth = 0;
  real Vth_NarrowW = 0;
  real Lpe_Vb = 0;
  real Vth = 0;
  real n = 0;
  real n0 = 0;
  real Vgsteff = 0;
  real Vgs_eff = 0;
  real niter = 0;
  real toxpf = 0;
  real toxpi = 0;
  real Tcen = 0;
  real temp_toxe = 0;
  real temp_epsrox = 0;
  real temp_vddeot = 0;
  real vtfbphi2eot = 0;
  real phieot = 0;
  real TempRatioeot = 0;
  real Vtm0eot = 0;
  real Vtmeot = 0;
  real vbieot = 0;
  integer i = 0;
  integer Fatal_Flag = 0;
  real chktol = 0;
  integer createnode_d = 0;
  integer createnode_s = 0;

  // Device load locals
  integer limited = 0;
  real ceqgstot = 0;
  real dgstot_dvd = 0;
  real dgstot_dvg = 0;
  real dgstot_dvs = 0;
  real dgstot_dvb = 0;
  real ceqgdtot = 0;
  real dgdtot_dvd = 0;
  real dgdtot_dvg = 0;
  real dgdtot_dvs = 0;
  real dgdtot_dvb = 0;
  real gstot = 0;
  real gstotd = 0;
  real gstotg = 0;
  real gstots = 0;
  real gstotb = 0;
  real gspr = 0;
  real Rs = 0;
  real Rd = 0;
  real gdtot = 0;
  real gdtotd = 0;
  real gdtotg = 0;
  real gdtots = 0;
  real gdtotb = 0;
  real gdpr = 0;
  real vgs_eff = 0;
  real vgd_eff = 0;
  real dvgs_eff_dvg = 0;
  real dvgd_eff_dvg = 0;
  real dRs_dvg = 0;
  real dRd_dvg = 0;
  real dRs_dvb = 0;
  real dRd_dvb = 0;
  real dT0_dvg = 0;
  real dT1_dvb = 0;
  real dT3_dvg = 0;
  real dT3_dvb = 0;
  real vses = 0;
  real vdes = 0;
  real geltd = 0;
  real load_gcrg = 0;
  real gcrgg = 0;
  real gcrgd = 0;
  real gcrgs = 0;
  real gcrgb = 0;
  real ceqgcrg = 0;
  real vges = 0;
  real vgms = 0;
  real vgedo = 0;
  real vgmdo = 0;
  real vged = 0;
  real vgmd = 0;
  real vgmb = 0;
  real qgmb = 0;
  real qgmid = 0;
  real ceqqgmid = 0;
  real vbd = 0;
  real load_vbs = 0;
  real load_vds = 0;
  real vgb = 0;
  real vgd = 0;
  real load_vgs = 0;
  real vgdo = 0;
  real vdbs = 0;
  real vdbd = 0;
  real vsbs = 0;
  real vsbdo = 0;
  real vsbd = 0;
  real vbs_jct = 0;
  real vbd_jct = 0;
  real load_SourceSatCurrent = 0;
  real load_DrainSatCurrent = 0;
  real qgb = 0;
  real von = 0;
  real VgstNVt = 0;
  real ExpVgst = 0;
  real ceqqb = 0;
  real ceqqd = 0;
  real ceqqg = 0;
  real ceqqjd = 0;
  real ceqqjs = 0;
  real ceq = 0;
  real geq = 0;
  real cdrain = 0;
  real ceqdrn = 0;
  real ceqbd = 0;
  real ceqbs = 0;
  real ceqjd = 0;
  real ceqjs = 0;
  real gjbd = 0;
  real gjbs = 0;
  real czbd = 0;
  real czbdsw = 0;
  real czbdswg = 0;
  real czbs = 0;
  real czbssw = 0;
  real czbsswg = 0;
  real evbd = 0;
  real evbs = 0;
  real arg = 0;
  real sarg = 0;
  real Vfbeff = 0;
  real dVfbeff_dVg = 0;
  real dVfbeff_dVb = 0;
  real V3 = 0;
  real V4 = 0;
  real MJD = 0;
  real MJSWD = 0;
  real MJSWGD = 0;
  real MJS = 0;
  real MJSWS = 0;
  real MJSWGS = 0;
  real qgate = 0;
  real qbulk = 0;
  real qdrn = 0;
  real qsrc = 0;
  real cqgate = 0;
  real cqbody = 0;
  real cqdrn = 0;
  real Vdb = 0;
  real Vds = 0;
  real Vgs = 0;
  real Vbs = 0;
  real Gmbs = 0;
  real FwdSum = 0;
  real RevSum = 0;
  real Igidl = 0;
  real Ggidld = 0;
  real Ggidlg = 0;
  real Ggidlb = 0;
  real Voxacc = 0;
  real dVoxacc_dVg = 0;
  real dVoxacc_dVb = 0;
  real Voxdepinv = 0;
  real dVoxdepinv_dVg = 0;
  real dVoxdepinv_dVd = 0;
  real dVoxdepinv_dVb = 0;
  real VxNVt = 0;
  real ExpVxNVt = 0;
  real Vaux = 0;
  real dVaux_dVg = 0;
  real dVaux_dVd = 0;
  real dVaux_dVb = 0;
  real Igc = 0;
  real dIgc_dVg = 0;
  real dIgc_dVd = 0;
  real dIgc_dVb = 0;
  real Igcs = 0;
  real dIgcs_dVg = 0;
  real dIgcs_dVd = 0;
  real dIgcs_dVb = 0;
  real Igcd = 0;
  real dIgcd_dVg = 0;
  real dIgcd_dVd = 0;
  real dIgcd_dVb = 0;
  real Igs = 0;
  real dIgs_dVg = 0;
  real dIgs_dVs = 0;
  real Igd = 0;
  real dIgd_dVg = 0;
  real dIgd_dVd = 0;
  real Igbacc = 0;
  real dIgbacc_dVg = 0;
  real dIgbacc_dVb = 0;
  real Igbinv = 0;
  real dIgbinv_dVg = 0;
  real dIgbinv_dVd = 0;
  real dIgbinv_dVb = 0;
  real Pigcd = 0;
  real dPigcd_dVg = 0;
  real dPigcd_dVd = 0;
  real dPigcd_dVb = 0;
  real Istoteq = 0;
  real gIstotg = 0;
  real gIstotd = 0;
  real gIstots = 0;
  real gIstotb = 0;
  real Idtoteq = 0;
  real gIdtotg = 0;
  real gIdtotd = 0;
  real gIdtots = 0;
  real gIdtotb = 0;
  real Ibtoteq = 0;
  real gIbtotg = 0;
  real gIbtotd = 0;
  real gIbtots = 0;
  real gIbtotb = 0;
  real Igtoteq = 0;
  real gIgtotg = 0;
  real gIgtotd = 0;
  real gIgtots = 0;
  real gIgtotb = 0;
  real load_Vgs_eff = 0;
  real Vfb = 0;
  real load_Vth_NarrowW = 0;
  real Phis = 0;
  real dPhis_dVb = 0;
  real sqrtPhis = 0;
  real dsqrtPhis_dVb = 0;
  real load_Vth = 0;
  real dVth_dVb = 0;
  real dVth_dVd = 0;
  real Vgst = 0;
  real dVgst_dVg = 0;
  real dVgst_dVb = 0;
  real dVgs_eff_dVg = 0;
  real load_Nvtms = 0;
  real load_Nvtmd = 0;
  real Vtm = 0;
  real load_Vtm0 = 0;
  real load_n = 0;
  real dn_dVb = 0;
  real dn_dVd = 0;
  real load_voffcv = 0;
  real load_noff = 0;
  real dnoff_dVd = 0;
  real dnoff_dVb = 0;
  real load_V0 = 0;
  real CoxWLcen = 0;
  real QovCox = 0;
  real LINK = 0;
  real DeltaPhi = 0;
  real dDeltaPhi_dVg = 0;
  real VgDP = 0;
  real dVgDP_dVg = 0;
  real Cox = 0;
  real Tox = 0;
  real load_Tcen = 0;
  real dTcen_dVg = 0;
  real dTcen_dVd = 0;
  real dTcen_dVb = 0;
  real Ccen = 0;
  real Coxeff = 0;
  real dCoxeff_dVd = 0;
  real dCoxeff_dVg = 0;
  real dCoxeff_dVb = 0;
  real Denomi = 0;
  real dDenomi_dVg = 0;
  real dDenomi_dVd = 0;
  real dDenomi_dVb = 0;
  real ueff = 0;
  real dueff_dVg = 0;
  real dueff_dVd = 0;
  real dueff_dVb = 0;
  real Esat = 0;
  real Vdsat = 0;
  real EsatL = 0;
  real dEsatL_dVg = 0;
  real dEsatL_dVd = 0;
  real dEsatL_dVb = 0;
  real dVdsat_dVg = 0;
  real dVdsat_dVb = 0;
  real dVdsat_dVd = 0;
  real Vasat = 0;
  real dAlphaz_dVg = 0;
  real dAlphaz_dVb = 0;
  real dVasat_dVg = 0;
  real dVasat_dVb = 0;
  real dVasat_dVd = 0;
  real Va = 0;
  real dVa_dVd = 0;
  real dVa_dVg = 0;
  real dVa_dVb = 0;
  real Vbseff = 0;
  real dVbseff_dVb = 0;
  real VbseffCV = 0;
  real dVbseffCV_dVb = 0;
  real VgsteffVth = 0;
  real dT11_dVg = 0;
  real Arg1 = 0;
  real One_Third_CoxWL = 0;
  real Two_Third_CoxWL = 0;
  real Alphaz = 0;
  real CoxWL = 0;
  real load_T0 = 0;
  real dT0_dVg = 0;
  real dT0_dVd = 0;
  real dT0_dVb = 0;
  real load_T1 = 0;
  real dT1_dVg = 0;
  real dT1_dVd = 0;
  real dT1_dVb = 0;
  real load_T2 = 0;
  real dT2_dVg = 0;
  real dT2_dVd = 0;
  real dT2_dVb = 0;
  real load_T3 = 0;
  real dT3_dVg = 0;
  real dT3_dVd = 0;
  real dT3_dVb = 0;
  real load_T4 = 0;
  real dT4_dVd = 0;
  real dT4_dVb = 0;
  real load_T5 = 0;
  real dT5_dVg = 0;
  real dT5_dVd = 0;
  real dT5_dVb = 0;
  real load_T6 = 0;
  real dT6_dVg = 0;
  real dT6_dVd = 0;
  real dT6_dVb = 0;
  real load_T7 = 0;
  real dT7_dVg = 0;
  real dT7_dVd = 0;
  real dT7_dVb = 0;
  real load_T8 = 0;
  real dT8_dVg = 0;
  real dT8_dVd = 0;
  real dT8_dVb = 0;
  real load_T9 = 0;
  real dT9_dVg = 0;
  real dT9_dVd = 0;
  real dT9_dVb = 0;
  real load_T10 = 0;
  real dT10_dVg = 0;
  real dT10_dVb = 0;
  real dT10_dVd = 0;
  real load_T11 = 0;
  real T12 = 0;
  real T13 = 0;
  real T14 = 0;
  real load_tmp = 0;
  real Abulk = 0;
  real dAbulk_dVb = 0;
  real Abulk0 = 0;
  real Abulk0_Q = 0;
  real dAbulk0_dVb = 0;
  real dAbulk0_Q_dVb = 0;
  real Cclm = 0;
  real dCclm_dVg = 0;
  real dCclm_dVd = 0;
  real dCclm_dVb = 0;
  real FP = 0;
  real dFP_dVg = 0;
  real PvagTerm = 0;
  real dPvagTerm_dVg = 0;
  real dPvagTerm_dVd = 0;
  real dPvagTerm_dVb = 0;
  real VADITS = 0;
  real dVADITS_dVg = 0;
  real dVADITS_dVd = 0;
  real load_Lpe_Vb = 0;
  real dDITS_Sft_dVb = 0;
  real dDITS_Sft_dVd = 0;
  real DITS_Sft2 = 0;
  real dDITS_Sft2_dVd = 0;
  real VACLM = 0;
  real dVACLM_dVg = 0;
  real dVACLM_dVd = 0;
  real dVACLM_dVb = 0;
  real VADIBL = 0;
  real dVADIBL_dVg = 0;
  real dVADIBL_dVd = 0;
  real dVADIBL_dVb = 0;
  real Xdep = 0;
  real dXdep_dVb = 0;
  real load_lt1 = 0;
  real dlt1_dVb = 0;
  real load_ltw = 0;
  real dltw_dVb = 0;
  real load_Delt_vth = 0;
  real dDelt_vth_dVb = 0;
  real load_Theta0 = 0;
  real dTheta0_dVb = 0;
  real TempRatio = 0;
  real load_tmp1 = 0;
  real load_tmp2 = 0;
  real load_tmp3 = 0;
  real tmp4 = 0;
  real DIBL_Sft = 0;
  real dDIBL_Sft_dVd = 0;
  real Lambda = 0;
  real dLambda_dVg = 0;
  real load_a1 = 0;
  real ScalingFactor = 0;
  real load_Vgsteff = 0;
  real dVgsteff_dVg = 0;
  real dVgsteff_dVd = 0;
  real dVgsteff_dVb = 0;
  real Vdseff = 0;
  real dVdseff_dVg = 0;
  real dVdseff_dVd = 0;
  real dVdseff_dVb = 0;
  real VdseffCV = 0;
  real dVdseffCV_dVg = 0;
  real dVdseffCV_dVd = 0;
  real dVdseffCV_dVb = 0;
  real diffVds = 0;
  real dAbulk_dVg = 0;
  real beta = 0;
  real dbeta_dVg = 0;
  real dbeta_dVd = 0;
  real dbeta_dVb = 0;
  real gche = 0;
  real dgche_dVg = 0;
  real dgche_dVd = 0;
  real dgche_dVb = 0;
  real fgche1 = 0;
  real dfgche1_dVg = 0;
  real dfgche1_dVd = 0;
  real dfgche1_dVb = 0;
  real fgche2 = 0;
  real dfgche2_dVg = 0;
  real dfgche2_dVd = 0;
  real dfgche2_dVb = 0;
  real Idl = 0;
  real dIdl_dVg = 0;
  real dIdl_dVd = 0;
  real dIdl_dVb = 0;
  real Idsa = 0;
  real dIdsa_dVg = 0;
  real dIdsa_dVd = 0;
  real dIdsa_dVb = 0;
  real Ids = 0;
  real Gm = 0;
  real Gds = 0;
  real Gmb = 0;
  real devbs_dvb = 0;
  real devbd_dvb = 0;
  real Isub = 0;
  real Gbd = 0;
  real Gbg = 0;
  real Gbb = 0;
  real VASCBE = 0;
  real dVASCBE_dVg = 0;
  real dVASCBE_dVd = 0;
  real dVASCBE_dVb = 0;
  real CoxeffWovL = 0;
  real Rds = 0;
  real dRds_dVg = 0;
  real dRds_dVb = 0;
  real WVCox = 0;
  real WVCoxRds = 0;
  real Vgst2Vtm = 0;
  real VdsatCV = 0;
  real Leff = 0;
  real Weff = 0;
  real dWeff_dVg = 0;
  real dWeff_dVb = 0;
  real AbulkCV = 0;
  real dAbulkCV_dVb = 0;
  real qcheq = 0;
  real load_qdef = 0;
  real cqdef = 0;
  real cqcheq = 0;
  real dxpart = 0;
  real sxpart = 0;
  real ggtg = 0;
  real ggtd = 0;
  real ggts = 0;
  real ggtb = 0;
  real ddxpart_dVd = 0;
  real ddxpart_dVg = 0;
  real ddxpart_dVb = 0;
  real ddxpart_dVs = 0;
  real dsxpart_dVd = 0;
  real dsxpart_dVg = 0;
  real dsxpart_dVb = 0;
  real dsxpart_dVs = 0;
  real gbspsp = 0;
  real gbbdp = 0;
  real gbbsp = 0;
  real gbspg = 0;
  real gbspb = 0;
  real gbspdp = 0;
  real gbdpdp = 0;
  real gbdpg = 0;
  real gbdpb = 0;
  real gbdpsp = 0;
  real qgdo = 0;
  real qgso = 0;
  real load_cgdo = 0;
  real load_cgso = 0;
  real Cgg = 0;
  real Cgd = 0;
  real Cgb = 0;
  real Cdg = 0;
  real Cdd = 0;
  real Cds = 0;
  real Csg = 0;
  real Csd = 0;
  real Css = 0;
  real Csb = 0;
  real Cbg = 0;
  real Cbd = 0;
  real Cbb = 0;
  real Cgg1 = 0;
  real Cgb1 = 0;
  real Cgd1 = 0;
  real Cbg1 = 0;
  real Cbb1 = 0;
  real Cbd1 = 0;
  real Qac0 = 0;
  real Qsub0 = 0;
  real dQac0_dVg = 0;
  real dQac0_dVb = 0;
  real dQsub0_dVg = 0;
  real dQsub0_dVd = 0;
  real dQsub0_dVb = 0;
  real ggidld = 0;
  real ggidlg = 0;
  real ggidlb = 0;
  real ggislg = 0;
  real ggislb = 0;
  real ggisls = 0;
  real Igisl = 0;
  real Ggislg = 0;
  real Ggislb = 0;
  real Ggisls = 0;
  real Nvtmrss = 0;
  real Nvtmrssws = 0;
  real Nvtmrsswgs = 0;
  real Nvtmrsd = 0;
  real Nvtmrsswd = 0;
  real Nvtmrsswgd = 0;
  real vs = 0;
  real Fsevl = 0;
  real dvs_dVg = 0;
  real dvs_dVd = 0;
  real dvs_dVb = 0;
  real dFsevl_dVg = 0;
  real dFsevl_dVd = 0;
  real dFsevl_dVb = 0;
  real vgdx = 0;
  real vgsx = 0;
  real load_epssub = 0;
  real load_toxe = 0;
  real load_epsrox = 0;
  real load_mult_i = 0;
  real load_mult_q = 0;
  integer finished1 = 0;
  integer goto_destination = -1;
  integer dummy_limited = 0;

  // Device noise locals
  real noise_T0 = 0;
  real noise_T1 = 0;
  real noise_T2 = 0;
  real noise_T3 = 0;
  real noise_T4 = 0;
  real noise_T5 = 0;
  real noise_T6 = 0;
  real noise_T7 = 0;
  real noise_T8 = 0;
  real noise_T9 = 0;
  real noise_T10 = 0;
  real noise_T11 = 0;
  real noise_Vds = 0;
  real Ssi = 0;
  real Swi = 0;
  real noise_tmp = 0;
  real noise_gdpr = 0;
  real noise_gspr = 0;
  real npart_theta = 0;
  real npart_beta = 0;
  real igsquare = 0;
  real noise_bodymode = 0;
  real eta = 0;
  real noise_Leff = 0;
  real Lvsat = 0;
  real gamma = 0;
  real noise_delta = 0;
  real epsilon = 0;
  real GammaGd0 = 0;
  real npart_c = 0;
  real sigrat = 0;
  real C0 = 0;
  real ctnoi = 0;
  real noise_mult_i = 0;
  real noise_mult_fn = 0;
  real cd = 0;
  real esat = 0;
  real DelClm = 0;
  real N0 = 0;
  real Nl = 0;
  real noise1_Leff = 0;
  real Leffsq = 0;
  real noise1_T0 = 0;
  real noise1_T1 = 0;
  real noise1_T2 = 0;
  real noise1_T3 = 0;
  real noise1_T4 = 0;
  real noise1_T5 = 0;
  real noise1_T6 = 0;
  real noise1_T7 = 0;
  real noise1_T8 = 0;
  real noise1_T9 = 0;
  real noise1_Ssi = 0;
  real efn_retval = 0;
  real tn2dspsd = 0;
  real tn2gspsd = 0;
  real tn2sigrat = 0;
  real rg_psd = 0;
  real rbps_psd = 0;
  real rbpd_psd = 0;
  real rbpb_psd = 0;
  real id_psd = 0;
  real igs_psd = 0;
  real igd_psd = 0;
  real flicker_psd = 0;
  real flicker_exp = 1;

  // Global constants
  real CONSTroot2 = sqrt(2.0);
  real CONSTvt0 = 1.38064852e-23*(27+273.15)/1.6021766208e-19;
  real CONSTKoverQ = 1.38064852e-23/1.6021766208e-19;
  real CONSTe = exp(1.0);
  real VACONSTcharge = 1.6021766208e-19;
  real VACONSTboltz = 1.38064852e-23;
  real VACONST_tnom = ($simparam("tnom", 27)+273.15);
  real cpscale = $simparam("scale", 1);

  // Evaluation constants
  real lc_gmin = 0;

  // Translated function definitions
  analog function integer BSIM4NumFingerDiff;
    input nf, minSD;
    inout nuIntD, nuEndD, nuIntS, nuEndS;
    real nf;
    integer minSD;
    real nuIntD;
    real nuEndD;
    real nuIntS;
    real nuEndS;
    integer NF;
    begin
      NF = nf;
      if (NF%2!=0) begin
        nuEndS = 1.0;
        nuEndD = nuEndS;
        nuIntS = 2.0*(((nf-1.0)/2.0>0.0) ? ((nf-1.0)/2.0) : (0.0));
        nuIntD = nuIntS;
      end else if (minSD==1) begin
        nuEndD = 2.0;
        nuIntD = 2.0*((nf/2.0-1.0>0.0) ? (nf/2.0-1.0) : (0.0));
        nuEndS = 0.0;
        nuIntS = nf;
      end else begin
        nuEndD = 0.0;
        nuIntD = nf;
        nuEndS = 2.0;
        nuIntS = 2.0*((nf/2.0-1.0>0.0) ? (nf/2.0-1.0) : (0.0));
      end
      BSIM4NumFingerDiff = 0;
    end
  endfunction

  analog function integer BSIM4PAeffGeo;
    input nf, geo, minSD, Weffcj, DMCG, DMCI, DMDG;
    inout Ps, Pd, As, Ad;
    real nf;
    integer geo;
    integer minSD;
    real Weffcj;
    real DMCG;
    real DMCI;
    real DMDG;
    real Ps;
    real Pd;
    real As;
    real Ad;
    real T0;
    real T1;
    real T2;
    real ADiso;
    real ADsha;
    real ADmer;
    real ASiso;
    real ASsha;
    real ASmer;
    real PDiso;
    real PDsha;
    real PDmer;
    real PSiso;
    real PSsha;
    real PSmer;
    real nuIntD;
    real nuEndD;
    real nuIntS;
    real nuEndS;
    begin
      nuIntD = 0.0;
      nuEndD = 0.0;
      nuIntS = 0.0;
      nuEndS = 0.0;
      if (geo<9) begin
        BSIM4NumFingerDiff(nf, minSD, nuIntD, nuEndD, nuIntS, nuEndS);
      end
      T0 = DMCG+DMCI;
      T1 = DMCG+DMCG;
      T2 = DMDG+DMDG;
      PDiso = T0+T0+Weffcj;
      PSiso = PDiso;
      PDsha = T1;
      PSsha = PDsha;
      PDmer = T2;
      PSmer = PDmer;
      ADiso = T0*Weffcj;
      ASiso = ADiso;
      ADsha = DMCG*Weffcj;
      ASsha = ADsha;
      ADmer = DMDG*Weffcj;
      ASmer = ADmer;
      case (geo)
        0: begin
          Ps = nuEndS*PSiso+nuIntS*PSsha;
          Pd = nuEndD*PDiso+nuIntD*PDsha;
          As = nuEndS*ASiso+nuIntS*ASsha;
          Ad = nuEndD*ADiso+nuIntD*ADsha;
        end
        1: begin
          Ps = nuEndS*PSiso+nuIntS*PSsha;
          Pd = (nuEndD+nuIntD)*PDsha;
          As = nuEndS*ASiso+nuIntS*ASsha;
          Ad = (nuEndD+nuIntD)*ADsha;
        end
        2: begin
          Ps = (nuEndS+nuIntS)*PSsha;
          Pd = nuEndD*PDiso+nuIntD*PDsha;
          As = (nuEndS+nuIntS)*ASsha;
          Ad = nuEndD*ADiso+nuIntD*ADsha;
        end
        3: begin
          Ps = (nuEndS+nuIntS)*PSsha;
          Pd = (nuEndD+nuIntD)*PDsha;
          As = (nuEndS+nuIntS)*ASsha;
          Ad = (nuEndD+nuIntD)*ADsha;
        end
        4: begin
          Ps = nuEndS*PSiso+nuIntS*PSsha;
          Pd = nuEndD*PDmer+nuIntD*PDsha;
          As = nuEndS*ASiso+nuIntS*ASsha;
          Ad = nuEndD*ADmer+nuIntD*ADsha;
        end
        5: begin
          Ps = (nuEndS+nuIntS)*PSsha;
          Pd = nuEndD*PDmer+nuIntD*PDsha;
          As = (nuEndS+nuIntS)*ASsha;
          Ad = nuEndD*ADmer+nuIntD*ADsha;
        end
        6: begin
          Ps = nuEndS*PSmer+nuIntS*PSsha;
          Pd = nuEndD*PDiso+nuIntD*PDsha;
          As = nuEndS*ASmer+nuIntS*ASsha;
          Ad = nuEndD*ADiso+nuIntD*ADsha;
        end
        7: begin
          Ps = nuEndS*PSmer+nuIntS*PSsha;
          Pd = (nuEndD+nuIntD)*PDsha;
          As = nuEndS*ASmer+nuIntS*ASsha;
          Ad = (nuEndD+nuIntD)*ADsha;
        end
        8: begin
          Ps = nuEndS*PSmer+nuIntS*PSsha;
          Pd = nuEndD*PDmer+nuIntD*PDsha;
          As = nuEndS*ASmer+nuIntS*ASsha;
          Ad = nuEndD*ADmer+nuIntD*ADsha;
        end
        9: begin
          Ps = PSiso+(nf-1.0)*PSsha;
          Pd = nf*PDsha;
          As = ASiso+(nf-1.0)*ASsha;
          Ad = nf*ADsha;
        end
        10: begin
          Ps = nf*PSsha;
          Pd = PDiso+(nf-1.0)*PDsha;
          As = nf*ASsha;
          Ad = ADiso+(nf-1.0)*ADsha;
        end
        default: begin
          $warning("Specified GEO = %d not matched", geo);
        end
      endcase

      BSIM4PAeffGeo = 0;
    end
  endfunction

  analog function integer BSIM4RdseffGeo;
    input nf, geo, rgeo, minSD, Weffcj, Rsh, DMCG, DMCI, DMDG, Type;
    inout Rtot;
    real nf;
    integer geo;
    integer rgeo;
    integer minSD;
    real Weffcj;
    real Rsh;
    real DMCG;
    real DMCI;
    real DMDG;
    integer Type;
    real Rtot;
    real Rint;
    real Rend;
    real nuIntD;
    real nuEndD;
    real nuIntS;
    real nuEndS;
    begin
      Rint = 0.0;
      Rend = 0.0;
      nuIntD = 0.0;
      nuEndD = 0.0;
      nuIntS = 0.0;
      nuEndS = 0.0;
      if (geo<9) begin
        BSIM4NumFingerDiff(nf, minSD, nuIntD, nuEndD, nuIntS, nuEndS);
        if (Type==1) begin
          if (nuIntS==0.0) begin
            Rint = 0.0;
          end else begin
            Rint = Rsh*DMCG/(Weffcj*nuIntS);
          end
        end else if (nuIntD==0.0) begin
          Rint = 0.0;
        end else begin
          Rint = Rsh*DMCG/(Weffcj*nuIntD);
        end
      end
      case (geo)
        0: begin
          if (Type==1) begin
            BSIM4RdsEndIso(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndS, rgeo, 1, Rend);
          end else begin
            BSIM4RdsEndIso(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndD, rgeo, 0, Rend);
          end
        end
        1: begin
          if (Type==1) begin
            BSIM4RdsEndIso(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndS, rgeo, 1, Rend);
          end else begin
            BSIM4RdsEndSha(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndD, rgeo, 0, Rend);
          end
        end
        2: begin
          if (Type==1) begin
            BSIM4RdsEndSha(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndS, rgeo, 1, Rend);
          end else begin
            BSIM4RdsEndIso(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndD, rgeo, 0, Rend);
          end
        end
        3: begin
          if (Type==1) begin
            BSIM4RdsEndSha(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndS, rgeo, 1, Rend);
          end else begin
            BSIM4RdsEndSha(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndD, rgeo, 0, Rend);
          end
        end
        4: begin
          if (Type==1) begin
            BSIM4RdsEndIso(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndS, rgeo, 1, Rend);
          end else begin
            Rend = Rsh*DMDG/Weffcj;
          end
        end
        5: begin
          if (Type==1) begin
            BSIM4RdsEndSha(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndS, rgeo, 1, Rend);
          end else begin
            Rend = Rsh*DMDG/(Weffcj*nuEndD);
          end
        end
        6: begin
          if (Type==1) begin
            Rend = Rsh*DMDG/Weffcj;
          end else begin
            BSIM4RdsEndIso(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndD, rgeo, 0, Rend);
          end
        end
        7: begin
          if (Type==1) begin
            Rend = Rsh*DMDG/(Weffcj*nuEndS);
          end else begin
            BSIM4RdsEndSha(Weffcj, Rsh, DMCG, DMCI, DMDG, nuEndD, rgeo, 0, Rend);
          end
        end
        8: begin
          Rend = Rsh*DMDG/Weffcj;
        end
        9: begin
          if (Type==1) begin
            Rend = 0.5*Rsh*DMCG/Weffcj;
            if (nf==2.0) begin
              Rint = 0.0;
            end else begin
              Rint = Rsh*DMCG/(Weffcj*(nf-2.0));
            end
          end else begin
            Rend = 0.0;
            Rint = Rsh*DMCG/(Weffcj*nf);
          end
        end
        10: begin
          if (Type==1) begin
            Rend = 0.0;
            Rint = Rsh*DMCG/(Weffcj*nf);
          end else begin
            Rend = 0.5*Rsh*DMCG/Weffcj;
            if (nf==2.0) begin
              Rint = 0.0;
            end else begin
              Rint = Rsh*DMCG/(Weffcj*(nf-2.0));
            end
          end
        end
        default: begin
          $warning("Specified GEO = %d not matched", geo);
        end
      endcase

      if (Rint<=0.0) begin
        Rtot = Rend;
      end else if (Rend<=0.0) begin
        Rtot = Rint;
      end else begin
        Rtot = Rint*Rend/(Rint+Rend);
      end
      if (Rtot==0.0) begin
        $warning("Zero resistance returned from RdseffGeo");
      end
      BSIM4RdseffGeo = 0;
    end
  endfunction

  analog function integer BSIM4RdsEndIso;
    input Weffcj, Rsh, DMCG, DMCI, DMDG, nuEnd, rgeo, Type;
    inout Rend;
    real Weffcj;
    real Rsh;
    real DMCG;
    real DMCI;
    real DMDG;
    real nuEnd;
    integer rgeo;
    integer Type;
    real Rend;
    begin
      if (Type==1) begin
        case (rgeo)
          1, 
          2, 
          5: begin
            if (nuEnd==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*DMCG/(Weffcj*nuEnd);
            end
          end
          3, 
          4, 
          6: begin
            if (DMCG+DMCI==0.0) begin
              $warning("(DMCG + DMCI) can not be equal to zero");
            end
            if (nuEnd==0.0||DMCG+DMCI==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*Weffcj/(3.0*nuEnd*(DMCG+DMCI));
            end
          end
          default: begin
            $warning("Specified RGEO = %d not matched", rgeo);
          end
        endcase

      end else begin
        case (rgeo)
          1, 
          3, 
          7: begin
            if (nuEnd==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*DMCG/(Weffcj*nuEnd);
            end
          end
          2, 
          4, 
          8: begin
            if (DMCG+DMCI==0.0) begin
              $warning("(DMCG + DMCI) can not be equal to zero");
            end
            if (nuEnd==0.0||DMCG+DMCI==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*Weffcj/(3.0*nuEnd*(DMCG+DMCI));
            end
          end
          default: begin
            $warning("Specified RGEO = %d not matched", rgeo);
          end
        endcase

      end
      BSIM4RdsEndIso = 0;
    end
  endfunction

  analog function integer BSIM4RdsEndSha;
    input Weffcj, Rsh, DMCG, DMCI, DMDG, nuEnd, rgeo, Type;
    inout Rend;
    real Weffcj;
    real Rsh;
    real DMCG;
    real DMCI;
    real DMDG;
    real nuEnd;
    integer rgeo;
    integer Type;
    real Rend;
    begin
      if (Type==1) begin
        case (rgeo)
          1, 
          2, 
          5: begin
            if (nuEnd==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*DMCG/(Weffcj*nuEnd);
            end
          end
          3, 
          4, 
          6: begin
            if (DMCG==0.0) begin
              $warning("DMCG can not be equal to zero");
            end
            if (nuEnd==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*Weffcj/(6.0*nuEnd*DMCG);
            end
          end
          default: begin
            $warning("Specified RGEO = %d not matched", rgeo);
          end
        endcase

      end else begin
        case (rgeo)
          1, 
          3, 
          7: begin
            if (nuEnd==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*DMCG/(Weffcj*nuEnd);
            end
          end
          2, 
          4, 
          8: begin
            if (DMCG==0.0) begin
              $warning("DMCG can not be equal to zero");
            end
            if (nuEnd==0.0) begin
              Rend = 0.0;
            end else begin
              Rend = Rsh*Weffcj/(6.0*nuEnd*DMCG);
            end
          end
          default: begin
            $warning("Specified RGEO = %d not matched", rgeo);
          end
        endcase

      end
      BSIM4RdsEndSha = 0;
    end
  endfunction

  analog function integer BSIM4DioIjthVjmEval;
    input Nvtm, Ijth, Isb, XExpBV;
    inout Vjm;
    real Nvtm;
    real Ijth;
    real Isb;
    real XExpBV;
    real Vjm;
    real Tb;
    real Tc;
    real EVjmovNv;
    begin
      Tc = XExpBV;
      Tb = 1.0+Ijth/Isb-Tc;
      EVjmovNv = 0.5*(Tb+sqrt(Tb*Tb+4.0*Tc));
      Vjm = Nvtm*ln(EVjmovNv);
      BSIM4DioIjthVjmEval = 0;
    end
  endfunction

  analog function integer BSIM4polyDepletion;
    input phi, ngate, epsgate, coxe, Vgs;
    inout Vgs_eff, dVgs_eff_dVg;
    real phi;
    real ngate;
    real epsgate;
    real coxe;
    real Vgs;
    real Vgs_eff;
    real dVgs_eff_dVg;
    real T1;
    real T2;
    real T3;
    real T4;
    real T5;
    real T6;
    real T7;
    real T8;
    begin
      if (ngate>1.0e18&&ngate<1.0e25&&Vgs>phi&&epsgate!=0) begin
        T1 = 1.0e6*1.6021766208e-19*epsgate*ngate/(coxe*coxe);
        T8 = Vgs-phi;
        T4 = sqrt(1.0+2.0*T8/T1);
        T2 = 2.0*T8/(T4+1.0);
        T3 = 0.5*T2*T2/T1;
        T7 = 1.12-T3-0.05;
        T6 = sqrt(T7*T7+0.224);
        T5 = 1.12-0.5*(T7+T6);
        Vgs_eff = Vgs-T5;
        dVgs_eff_dVg = 1.0-(0.5-0.5/T4)*(1.0+T7/T6);
      end else begin
        Vgs_eff = Vgs;
        dVgs_eff_dVg = 1.0;
      end
      BSIM4polyDepletion = 0;
    end
  endfunction

  // Verbatim analog functions
  analog function integer initialize_limiting;
    integer il;
    begin
      il = $simparam("iniLim", -1);
      if (il<0) begin
        // iniLim not available, use heuristics
        initialize_limiting = 
          $simparam("iteration", 10)==1 && 
          (analysis("dc") || analysis("static")) && 
          analysis("nodeset");
      end else begin
        initialize_limiting = il;
      end
    end
  endfunction

  analog function real DEVlimitOldGet;
    input vnew, vold;
    real vnew, vold, result;
    begin
      DEVlimitOldGet = vold;
    end
  endfunction

  analog function real DEVlimitNewSet;
    input vnew, vold, new_value, limited;
    real vnew, vold, new_value;
    integer limited;
    begin
      DEVlimitNewSet = new_value;
      if (limited) begin
        $discontinuity(-1);
      end
    end
  endfunction

  analog function real DEVpnjlim;
    input vnew, vold, vt, vcrit;
    inout limiting_applied;
    real vnew, vold, vt, vcrit, limited, arg;
    integer limiting_applied;
    
    begin
      limited = vnew;
      if ((vnew > vcrit) && (abs(vnew - vold) > (vt + vt))) begin
        // Positive vnew above vcrit, change greater than 2*vt
        if(vold > 0) begin
          arg = (vnew - vold) / vt;
          if(arg > 0) begin
            limited = vold + vt * ln(1+arg);
            limiting_applied = 1;
          end else begin
            limited = vold - vt * ln(1-arg);
            limiting_applied = 1;
          end
        end else begin
          limited = vt *ln(vnew/vt);
          limiting_applied = 1;
        end
      end else if (vnew<0) begin
        // Negative vnew, use ngspice limiting
        if (vold > 0) begin
          arg = -1*vold-1; 
        end else begin
          arg = 2*vold-1;
        end
        if (vnew<arg) begin
          limited = arg;
          limiting_applied = 1;
        end
      end 
      DEVpnjlim = limited;
    end
  endfunction

  analog function real DEVfetlim;
    input vnew, vold, vto;
    inout limiting_applied;
    real vnew, vold, vto, vlimited;
    real vtsthi, vtstlo, vtox, delv, vtemp;
    integer limiting_applied;  
    begin
      vlimited = vnew;
      vtsthi = abs(2*(vold-vto))+2;
      // vtstlo = vtsthi/2 +2;
      vtstlo = abs(vold-vto)+1;
      vtox = vto + 3.5;
      delv = vnew-vold;
      
      if (vold >= vto) begin
        if(vold >= vtox) begin
          if(delv <= 0) begin
            /* going off */
            if(vlimited >= vtox) begin
                if(-delv > vtstlo) begin
                vlimited =  vold - vtstlo;
                end
            end else begin
              vlimited = max(vnew,vto+2);
            end
          end else begin
            /* staying on */
            if(delv >= vtsthi) begin
              vlimited = vold + vtsthi;
            end
          end
        end else begin
          /* middle region */
          if(delv <= 0) begin
            /* decreasing */
            vlimited = max(vnew,vto-0.5);
          end else begin
            /* increasing */
            vlimited = min(vnew,vto+4);
          end
        end
      end else begin
        /* off */
        if(delv <= 0) begin
          if(-delv >vtsthi) begin
            vlimited = vold - vtsthi;
          end
        end else begin
          vtemp = vto + 0.5;
          if(vnew <= vtemp) begin
            if(delv > vtstlo) begin
              vlimited = vold + vtstlo;
            end
          end else begin
            vlimited = vtemp;
          end
        end
      end
      if (vlimited!=vnew) begin
        limiting_applied = 1;
      end
      DEVfetlim = vlimited;
    end
  endfunction

  analog function real DEVlimvds;
    input vnew, vold;
    inout limiting_applied;
    real vnew, vold, vlimited;
    integer limiting_applied;
    begin
      if (vold >= 3.5) begin
        if(vnew > vold) begin
          vlimited = min(vnew, (3 * vold) + 2);
        end else begin
          if (vnew < 3.5) begin
            vlimited = max(vnew, 2);
          end else begin
            vlimited = vnew;
          end
        end
      end else begin
        if(vnew > vold) begin
          vlimited = min(vnew, 4);
        end else begin
          vlimited = max(vnew, -0.5);
        end
      end
      DEVlimvds = vlimited;
      if (vlimited!=vnew) begin
        limiting_applied = 1;
      end
    end
  endfunction

  // Analog block
  analog begin

    // Instance field assignments
    if ($param_given(l)) begin
      BSIM4l = l*cpscale;
      BSIM4lGiven = 1;
    end
    if ($param_given(w)) begin
      BSIM4w = w*cpscale;
      BSIM4wGiven = 1;
    end
    if ($param_given(sd)) begin
      BSIM4sd = sd;
    end
    if ($param_given(sca)) begin
      BSIM4sca = sca;
    end
    if ($param_given(scb)) begin
      BSIM4scb = scb;
    end
    if ($param_given(scc)) begin
      BSIM4scc = scc;
    end
    if ($param_given(sc)) begin
      BSIM4sc = sc;
    end
    if ($param_given(ad)) begin
      BSIM4drainArea = ad*cpscale*cpscale;
      BSIM4drainAreaGiven = 1;
    end
    if ($param_given(as)) begin
      BSIM4sourceArea = as*cpscale*cpscale;
      BSIM4sourceAreaGiven = 1;
    end
    if ($param_given(pd)) begin
      BSIM4drainPerimeter = pd*cpscale;
      BSIM4drainPerimeterGiven = 1;
    end
    if ($param_given(ps)) begin
      BSIM4sourcePerimeter = ps*cpscale;
      BSIM4sourcePerimeterGiven = 1;
    end
    if ($param_given(instance_rbdb)) begin
      i_BSIM4rbdb = instance_rbdb;
    end
    if ($param_given(instance_rbsb)) begin
      i_BSIM4rbsb = instance_rbsb;
    end
    if ($param_given(instance_rbpb)) begin
      i_BSIM4rbpb = instance_rbpb;
    end
    if ($param_given(instance_rbps)) begin
      i_BSIM4rbps = instance_rbps;
    end
    if ($param_given(instance_rbpd)) begin
      i_BSIM4rbpd = instance_rbpd;
    end
    if ($param_given(instance_xgw)) begin
      i_BSIM4xgw = instance_xgw;
    end
    if ($param_given(instance_ngcon)) begin
      i_BSIM4ngcon = instance_ngcon;
    end
    if ($param_given(instance_trnqsmod)) begin
      i_BSIM4trnqsMod = instance_trnqsmod;
    end
    if ($param_given(instance_acnqsmod)) begin
      i_BSIM4acnqsMod = instance_acnqsmod;
    end
    if ($param_given(instance_rbodymod)) begin
      i_BSIM4rbodyMod = instance_rbodymod;
    end
    if ($param_given(instance_rgatemod)) begin
      i_BSIM4rgateMod = instance_rgatemod;
    end
    if ($param_given(instance_geomod)) begin
      i_BSIM4geoMod = instance_geomod;
    end
    if ($param_given(mult_fn)) begin
      BSIM4mult_fn = mult_fn;
    end

    // Model field assignments
    if ($param_given(capmod)) begin
      BSIM4capMod = capmod;
    end
    if ($param_given(diomod)) begin
      BSIM4dioMod = diomod;
    end
    if ($param_given(rdsmod)) begin
      BSIM4rdsMod = rdsmod;
    end
    if ($param_given(trnqsmod)) begin
      BSIM4trnqsMod = trnqsmod;
    end
    if ($param_given(acnqsmod)) begin
      BSIM4acnqsMod = acnqsmod;
    end
    if ($param_given(mobmod)) begin
      BSIM4mobMod = mobmod;
    end
    if ($param_given(rbodymod)) begin
      BSIM4rbodyMod = rbodymod;
    end
    if ($param_given(rgatemod)) begin
      BSIM4rgateMod = rgatemod;
    end
    if ($param_given(permod)) begin
      BSIM4perMod = permod;
    end
    if ($param_given(fnoimod)) begin
      BSIM4fnoiMod = fnoimod;
    end
    if ($param_given(tnoimod)) begin
      BSIM4tnoiMod = tnoimod;
    end
    if ($param_given(mtrlmod)) begin
      BSIM4mtrlMod = mtrlmod;
    end
    if ($param_given(mtrlcompatmod)) begin
      BSIM4mtrlCompatMod = mtrlcompatmod;
    end
    if ($param_given(igcmod)) begin
      BSIM4igcMod = igcmod;
    end
    if ($param_given(igbmod)) begin
      BSIM4igbMod = igbmod;
    end
    if ($param_given(tempmod)) begin
      BSIM4tempMod = tempmod;
    end
    if ($param_given(eot)) begin
      BSIM4eot = eot;
    end
    if ($param_given(vddeot)) begin
      BSIM4vddeot = vddeot;
    end
    if ($param_given(toxe)) begin
      BSIM4toxe = toxe;
    end
    if ($param_given(toxp)) begin
      BSIM4toxp = toxp;
    end
    if ($param_given(toxm)) begin
      BSIM4toxm = toxm;
    end
    if ($param_given(keta)) begin
      BSIM4keta = keta;
    end
    if ($param_given(ketac)) begin
      BSIM4ketac = ketac;
    end
    if ($param_given(vbm)) begin
      BSIM4vbm = vbm;
    end
    if ($param_given(kt1)) begin
      BSIM4kt1 = kt1;
    end
    if ($param_given(dvt2)) begin
      BSIM4dvt2 = dvt2;
    end
    if ($param_given(dvt2w)) begin
      BSIM4dvt2w = dvt2w;
    end
    if ($param_given(dsub)) begin
      BSIM4dsub = dsub;
    end
    if ($param_given(vth0)) begin
      BSIM4vth0 = vth0;
    end
    if ($param_given(ua)) begin
      BSIM4ua = ua;
    end
    if ($param_given(ub1)) begin
      BSIM4ub1 = ub1;
    end
    if ($param_given(uc)) begin
      BSIM4uc = uc;
    end
    if ($param_given(uc1)) begin
      BSIM4uc1 = uc1;
    end
    if ($param_given(u0)) begin
      BSIM4u0 = u0;
    end
    if ($param_given(eu)) begin
      BSIM4eu = eu;
    end
    if ($param_given(ucs)) begin
      BSIM4ucs = ucs;
    end
    if ($param_given(ute)) begin
      BSIM4ute = ute;
    end
    if ($param_given(ucste)) begin
      BSIM4ucste = ucste;
    end
    if ($param_given(voff)) begin
      BSIM4voff = voff;
    end
    if ($param_given(tnom)) begin
      BSIM4tnom = tnom+273.15;
      BSIM4tnomGiven = 1;
    end
    if ($param_given(cgso)) begin
      BSIM4cgso = cgso;
    end
    if ($param_given(cgdo)) begin
      BSIM4cgdo = cgdo;
    end
    if ($param_given(cgbo)) begin
      BSIM4cgbo = cgbo;
    end
    if ($param_given(etab)) begin
      BSIM4etab = etab;
    end
    if ($param_given(pbs)) begin
      BSIM4SbulkJctPotential = pbs;
    end
    if ($param_given(pbsws)) begin
      BSIM4SsidewallJctPotential = pbsws;
    end
    if ($param_given(pbswgs)) begin
      BSIM4SGatesidewallJctPotential = pbswgs;
    end
    if ($param_given(mjswgs)) begin
      BSIM4SbulkJctGateSideGradingCoeff = mjswgs;
    end
    if ($param_given(cjsws)) begin
      BSIM4SunitLengthSidewallJctCap = cjsws;
    end
    if ($param_given(cjswgs)) begin
      BSIM4SunitLengthGateSidewallJctCap = cjswgs;
    end
    if ($param_given(jsd)) begin
      BSIM4DjctSatCurDensity = jsd;
    end
    if ($param_given(jswd)) begin
      BSIM4DjctSidewallSatCurDensity = jswd;
    end
    if ($param_given(jswgd)) begin
      BSIM4DjctGateSidewallSatCurDensity = jswgd;
    end
    if ($param_given(pbd)) begin
      BSIM4DbulkJctPotential = pbd;
    end
    if ($param_given(njd)) begin
      BSIM4DjctEmissionCoeff = njd;
    end
    if ($param_given(xtid)) begin
      BSIM4DjctTempExponent = xtid;
    end
    if ($param_given(mjd)) begin
      BSIM4DbulkJctBotGradingCoeff = mjd;
    end
    if ($param_given(pbswd)) begin
      BSIM4DsidewallJctPotential = pbswd;
    end
    if ($param_given(mjswd)) begin
      BSIM4DbulkJctSideGradingCoeff = mjswd;
    end
    if ($param_given(pbswgd)) begin
      BSIM4DGatesidewallJctPotential = pbswgd;
    end
    if ($param_given(mjswgd)) begin
      BSIM4DbulkJctGateSideGradingCoeff = mjswgd;
    end
    if ($param_given(cjd)) begin
      BSIM4DunitAreaJctCap = cjd;
    end
    if ($param_given(cjswd)) begin
      BSIM4DunitLengthSidewallJctCap = cjswd;
    end
    if ($param_given(cjswgd)) begin
      BSIM4DunitLengthGateSidewallJctCap = cjswgd;
    end
    if ($param_given(vfbcv)) begin
      BSIM4vfbcv = vfbcv;
    end
    if ($param_given(vfb)) begin
      BSIM4vfb = vfb;
    end
    if ($param_given(dmci)) begin
      BSIM4dmci = dmci;
    end
    if ($param_given(llc)) begin
      BSIM4Llc = llc;
    end
    if ($param_given(lwc)) begin
      BSIM4Lwc = lwc;
    end
    if ($param_given(lwlc)) begin
      BSIM4Lwlc = lwlc;
    end
    if ($param_given(wlc)) begin
      BSIM4Wlc = wlc;
    end
    if ($param_given(wwc)) begin
      BSIM4Wwc = wwc;
    end
    if ($param_given(wwlc)) begin
      BSIM4Wwlc = wwlc;
    end
    if ($param_given(ckappad)) begin
      BSIM4ckappad = ckappad;
    end
    if ($param_given(cf)) begin
      BSIM4cf = cf;
    end
    if ($param_given(dwc)) begin
      BSIM4dwc = dwc;
    end
    if ($param_given(dlc)) begin
      BSIM4dlc = dlc;
    end
    if ($param_given(dlcig)) begin
      BSIM4dlcig = dlcig;
    end
    if ($param_given(dlcigd)) begin
      BSIM4dlcigd = dlcigd;
    end
    if ($param_given(dwj)) begin
      BSIM4dwj = dwj;
    end
    if ($param_given(agisl)) begin
      BSIM4agisl = agisl;
    end
    if ($param_given(bgisl)) begin
      BSIM4bgisl = bgisl;
    end
    if ($param_given(cgisl)) begin
      BSIM4cgisl = cgisl;
    end
    if ($param_given(rgisl)) begin
      BSIM4rgisl = rgisl;
    end
    if ($param_given(kgisl)) begin
      BSIM4kgisl = kgisl;
    end
    if ($param_given(fgisl)) begin
      BSIM4fgisl = fgisl;
    end
    if ($param_given(egisl)) begin
      BSIM4egisl = egisl;
    end
    if ($param_given(aigc)) begin
      BSIM4aigc = aigc;
    end
    if ($param_given(bigc)) begin
      BSIM4bigc = bigc;
    end
    if ($param_given(cigc)) begin
      BSIM4cigc = cigc;
    end
    if ($param_given(aigsd)) begin
      BSIM4aigsd = aigsd;
    end
    if ($param_given(bigsd)) begin
      BSIM4bigsd = bigsd;
    end
    if ($param_given(cigsd)) begin
      BSIM4cigsd = cigsd;
    end
    if ($param_given(aigs)) begin
      BSIM4aigs = aigs;
    end
    if ($param_given(bigs)) begin
      BSIM4bigs = bigs;
    end
    if ($param_given(cigs)) begin
      BSIM4cigs = cigs;
    end
    if ($param_given(aigd)) begin
      BSIM4aigd = aigd;
    end
    if ($param_given(bigd)) begin
      BSIM4bigd = bigd;
    end
    if ($param_given(cigd)) begin
      BSIM4cigd = cigd;
    end
    if ($param_given(ijthdfwd)) begin
      BSIM4ijthdfwd = ijthdfwd;
    end
    if ($param_given(ijthsfwd)) begin
      BSIM4ijthsfwd = ijthsfwd;
    end
    if ($param_given(ijthdrev)) begin
      BSIM4ijthdrev = ijthdrev;
    end
    if ($param_given(ijthsrev)) begin
      BSIM4ijthsrev = ijthsrev;
    end
    if ($param_given(xjbvd)) begin
      BSIM4xjbvd = xjbvd;
    end
    if ($param_given(xjbvs)) begin
      BSIM4xjbvs = xjbvs;
    end
    if ($param_given(bvd)) begin
      BSIM4bvd = bvd;
    end
    if ($param_given(bvs)) begin
      BSIM4bvs = bvs;
    end
    if ($param_given(jtsd)) begin
      BSIM4jtsd = jtsd;
    end
    if ($param_given(jtsswd)) begin
      BSIM4jtsswd = jtsswd;
    end
    if ($param_given(jtsswgd)) begin
      BSIM4jtsswgd = jtsswgd;
    end
    if ($param_given(jtweff)) begin
      BSIM4jtweff = jtweff;
    end
    if ($param_given(njtsd)) begin
      BSIM4njtsd = njtsd;
    end
    if ($param_given(njtsswd)) begin
      BSIM4njtsswd = njtsswd;
    end
    if ($param_given(njtsswgd)) begin
      BSIM4njtsswgd = njtsswgd;
    end
    if ($param_given(xtsd)) begin
      BSIM4xtsd = xtsd;
    end
    if ($param_given(xtsswd)) begin
      BSIM4xtsswd = xtsswd;
    end
    if ($param_given(xtsswgd)) begin
      BSIM4xtsswgd = xtsswgd;
    end
    if ($param_given(tnjtsd)) begin
      BSIM4tnjtsd = tnjtsd;
    end
    if ($param_given(tnjtsswd)) begin
      BSIM4tnjtsswd = tnjtsswd;
    end
    if ($param_given(tnjtsswgd)) begin
      BSIM4tnjtsswgd = tnjtsswgd;
    end
    if ($param_given(vtsd)) begin
      BSIM4vtsd = vtsd;
    end
    if ($param_given(vtsswd)) begin
      BSIM4vtsswd = vtsswd;
    end
    if ($param_given(vtsswgd)) begin
      BSIM4vtsswgd = vtsswgd;
    end
    if ($param_given(lketac)) begin
      BSIM4lketac = lketac;
    end
    if ($param_given(letab)) begin
      BSIM4letab = letab;
    end
    if ($param_given(lagisl)) begin
      BSIM4lagisl = lagisl;
    end
    if ($param_given(lbgisl)) begin
      BSIM4lbgisl = lbgisl;
    end
    if ($param_given(lcgisl)) begin
      BSIM4lcgisl = lcgisl;
    end
    if ($param_given(lrgisl)) begin
      BSIM4lrgisl = lrgisl;
    end
    if ($param_given(lkgisl)) begin
      BSIM4lkgisl = lkgisl;
    end
    if ($param_given(lfgisl)) begin
      BSIM4lfgisl = lfgisl;
    end
    if ($param_given(legisl)) begin
      BSIM4legisl = legisl;
    end
    if ($param_given(laigs)) begin
      BSIM4laigs = laigs;
    end
    if ($param_given(lbigs)) begin
      BSIM4lbigs = lbigs;
    end
    if ($param_given(lcigs)) begin
      BSIM4lcigs = lcigs;
    end
    if ($param_given(laigd)) begin
      BSIM4laigd = laigd;
    end
    if ($param_given(lbigd)) begin
      BSIM4lbigd = lbigd;
    end
    if ($param_given(lcigd)) begin
      BSIM4lcigd = lcigd;
    end
    if ($param_given(wketac)) begin
      BSIM4wketac = wketac;
    end
    if ($param_given(wagisl)) begin
      BSIM4wagisl = wagisl;
    end
    if ($param_given(wbgisl)) begin
      BSIM4wbgisl = wbgisl;
    end
    if ($param_given(wcgisl)) begin
      BSIM4wcgisl = wcgisl;
    end
    if ($param_given(wrgisl)) begin
      BSIM4wrgisl = wrgisl;
    end
    if ($param_given(wkgisl)) begin
      BSIM4wkgisl = wkgisl;
    end
    if ($param_given(wfgisl)) begin
      BSIM4wfgisl = wfgisl;
    end
    if ($param_given(wegisl)) begin
      BSIM4wegisl = wegisl;
    end
    if ($param_given(waigs)) begin
      BSIM4waigs = waigs;
    end
    if ($param_given(wbigs)) begin
      BSIM4wbigs = wbigs;
    end
    if ($param_given(wcigs)) begin
      BSIM4wcigs = wcigs;
    end
    if ($param_given(waigd)) begin
      BSIM4waigd = waigd;
    end
    if ($param_given(wbigd)) begin
      BSIM4wbigd = wbigd;
    end
    if ($param_given(wcigd)) begin
      BSIM4wcigd = wcigd;
    end
    if ($param_given(pketac)) begin
      BSIM4pketac = pketac;
    end
    if ($param_given(pagisl)) begin
      BSIM4pagisl = pagisl;
    end
    if ($param_given(pbgisl)) begin
      BSIM4pbgisl = pbgisl;
    end
    if ($param_given(pcgisl)) begin
      BSIM4pcgisl = pcgisl;
    end
    if ($param_given(pegisl)) begin
      BSIM4pegisl = pegisl;
    end
    if ($param_given(prgisl)) begin
      BSIM4prgisl = prgisl;
    end
    if ($param_given(pkgisl)) begin
      BSIM4pkgisl = pkgisl;
    end
    if ($param_given(pfgisl)) begin
      BSIM4pfgisl = pfgisl;
    end
    if ($param_given(paigs)) begin
      BSIM4paigs = paigs;
    end
    if ($param_given(pbigs)) begin
      BSIM4pbigs = pbigs;
    end
    if ($param_given(pcigs)) begin
      BSIM4pcigs = pcigs;
    end
    if ($param_given(paigd)) begin
      BSIM4paigd = paigd;
    end
    if ($param_given(pbigd)) begin
      BSIM4pbigd = pbigd;
    end
    if ($param_given(pcigd)) begin
      BSIM4pcigd = pcigd;
    end
    if ($param_given(wpemod)) begin
      BSIM4wpemod = wpemod;
    end
    if ($param_given(noia)) begin
      BSIM4oxideTrapDensityA = noia;
    end
    if ($param_given(noib)) begin
      BSIM4oxideTrapDensityB = noib;
    end
    if ($param_given(gidlclamp)) begin
      BSIM4gidlclamp = gidlclamp;
    end
    BSIM4type = type;

    // Evaluation constants
    lc_gmin = $simparam("gmin", 1e-12);

    // Tag: setup, function: BSIM4setup
    if (!$param_given(mobmod)) begin
      BSIM4mobMod = 0;
    end else if (BSIM4mobMod!=0&&BSIM4mobMod!=1&&BSIM4mobMod!=2&&BSIM4mobMod!=3&&BSIM4mobMod!=4&&BSIM4mobMod!=5&&BSIM4mobMod!=6) begin
      BSIM4mobMod = 0;
      $warning("mobMod has been set to its default value: 0.");
    end
    if (!$param_given(diomod)) begin
      BSIM4dioMod = 1;
    end else if (BSIM4dioMod!=0&&BSIM4dioMod!=1&&BSIM4dioMod!=2) begin
      BSIM4dioMod = 1;
      $warning("dioMod has been set to its default value: 1.");
    end
    if (!$param_given(capmod)) begin
      BSIM4capMod = 2;
    end else if (BSIM4capMod!=0&&BSIM4capMod!=1&&BSIM4capMod!=2) begin
      BSIM4capMod = 2;
      $warning("capMod has been set to its default value: 2.");
    end
    if (!$param_given(rdsmod)) begin
      BSIM4rdsMod = 0;
    end else if (BSIM4rdsMod!=0&&BSIM4rdsMod!=1) begin
      BSIM4rdsMod = 0;
      $warning("rdsMod has been set to its default value: 0.");
    end
    if (!$param_given(rbodymod)) begin
      BSIM4rbodyMod = 0;
    end else if (BSIM4rbodyMod!=0&&BSIM4rbodyMod!=1&&BSIM4rbodyMod!=2) begin
      BSIM4rbodyMod = 0;
      $warning("rbodyMod has been set to its default value: 0.");
    end
    if (!$param_given(rgatemod)) begin
      BSIM4rgateMod = 0;
    end else if (BSIM4rgateMod!=0&&BSIM4rgateMod!=1&&BSIM4rgateMod!=2&&BSIM4rgateMod!=3) begin
      BSIM4rgateMod = 0;
      $warning("rgateMod has been set to its default value: 0.");
    end
    if (!$param_given(permod)) begin
      BSIM4perMod = 1;
    end else if (BSIM4perMod!=0&&BSIM4perMod!=1) begin
      BSIM4perMod = 1;
      $warning("perMod has been set to its default value: 1.");
    end
    if (!$param_given(fnoimod)) begin
      BSIM4fnoiMod = 1;
    end else if (BSIM4fnoiMod!=0&&BSIM4fnoiMod!=1) begin
      BSIM4fnoiMod = 1;
      $warning("fnoiMod has been set to its default value: 1.");
    end
    if (!$param_given(tnoimod)) begin
      BSIM4tnoiMod = 0;
    end else if (BSIM4tnoiMod!=0&&BSIM4tnoiMod!=1&&BSIM4tnoiMod!=2) begin
      BSIM4tnoiMod = 0;
      $warning("tnoiMod has been set to its default value: 0.");
    end
    if (!$param_given(trnqsmod)) begin
      BSIM4trnqsMod = 0;
    end else if (BSIM4trnqsMod!=0&&BSIM4trnqsMod!=1) begin
      BSIM4trnqsMod = 0;
      $warning("trnqsMod has been set to its default value: 0.");
    end
    if (!$param_given(acnqsmod)) begin
      BSIM4acnqsMod = 0;
    end else if (BSIM4acnqsMod!=0&&BSIM4acnqsMod!=1) begin
      BSIM4acnqsMod = 0;
      $warning("acnqsMod has been set to its default value: 0.");
    end
    if (!$param_given(mtrlmod)) begin
      BSIM4mtrlMod = 0;
    end else if (BSIM4mtrlMod!=0&&BSIM4mtrlMod!=1) begin
      BSIM4mtrlMod = 0;
      $warning("mtrlMod has been set to its default value: 0.");
    end
    if (!$param_given(mtrlcompatmod)) begin
      BSIM4mtrlCompatMod = 0;
    end else if (BSIM4mtrlCompatMod!=0&&BSIM4mtrlCompatMod!=1) begin
      BSIM4mtrlCompatMod = 0;
      $warning("mtrlCompatMod has been set to its default value: 0.");
    end
    if (!$param_given(igcmod)) begin
      BSIM4igcMod = 0;
    end else if (BSIM4igcMod!=0&&BSIM4igcMod!=1&&BSIM4igcMod!=2) begin
      BSIM4igcMod = 0;
      $warning("igcMod has been set to its default value: 0.");
    end
    if (!$param_given(igbmod)) begin
      BSIM4igbMod = 0;
    end else if (BSIM4igbMod!=0&&BSIM4igbMod!=1) begin
      BSIM4igbMod = 0;
      $warning("igbMod has been set to its default value: 0.");
    end
    if (!$param_given(tempmod)) begin
      BSIM4tempMod = 0;
    end else if (BSIM4tempMod!=0&&BSIM4tempMod!=1&&BSIM4tempMod!=2&&BSIM4tempMod!=3) begin
      BSIM4tempMod = 0;
      $warning("tempMod has been set to its default value: 0.");
    end
    if (version=="4.8.3"||version=="4.83"||version=="4.8") begin
      BSIM4v48intVersion = 483;
    end else if (version=="4.8.2"||version=="4.82") begin
      BSIM4v48intVersion = 482;
    end else if (version=="4.8.1"||version=="4.81") begin
      BSIM4v48intVersion = 481;
    end else if (version=="4.8.0"||version=="4.80") begin
      BSIM4v48intVersion = 480;
    end else begin
      $warning("unknown BSIM4 version. Working now with BSIM4.8.3.");
      BSIM4v48intVersion = 483;
    end
    if (!$param_given(eot)) begin
      BSIM4eot = 15.0e-10;
    end
    if (!$param_given(vddeot)) begin
      BSIM4vddeot = ((BSIM4type==1) ? (1.5) : (-1.5));
    end
    if (!$param_given(toxe)) begin
      BSIM4toxe = 30.0e-10;
    end
    if (!$param_given(toxp)) begin
      BSIM4toxp = BSIM4toxe;
    end
    if (!$param_given(toxm)) begin
      BSIM4toxm = BSIM4toxe;
    end
    if (!$param_given(keta)) begin
      BSIM4keta = -0.047;
    end
    if (!$param_given(ketac)) begin
      BSIM4ketac = BSIM4keta;
    end
    if (!$param_given(vbm)) begin
      BSIM4vbm = -3.0;
    end
    if (!$param_given(kt1)) begin
      BSIM4kt1 = -0.11;
    end
    if (!$param_given(dvt2)) begin
      BSIM4dvt2 = -0.032;
    end
    if (!$param_given(dvt2w)) begin
      BSIM4dvt2w = -0.032;
    end
    if (!$param_given(dsub)) begin
      BSIM4dsub = drout;
    end
    if (!$param_given(vth0)) begin
      BSIM4vth0 = ((BSIM4type==1) ? (0.7) : (-0.7));
    end
    if (!$param_given(vfb)) begin
      BSIM4vfb = -1.0;
    end
    if (!$param_given(eu)) begin
      BSIM4eu = ((BSIM4type==1) ? (1.67) : (1.0));
    end
    if (!$param_given(ucs)) begin
      BSIM4ucs = ((BSIM4type==1) ? (1.67) : (1.0));
    end
    if (BSIM4v48intVersion<=480) begin
      if (!$param_given(ua)) begin
        BSIM4ua = ((BSIM4mobMod==2) ? (1.0e-15) : (1.0e-9));
      end
      if (!$param_given(uc)) begin
        BSIM4uc = ((BSIM4mobMod==1) ? (-0.0465) : (-0.0465e-9));
      end
      if (!$param_given(uc1)) begin
        BSIM4uc1 = ((BSIM4mobMod==1) ? (-0.056) : (-0.056e-9));
      end
    end else begin
      if (!$param_given(ua)) begin
        BSIM4ua = ((BSIM4mobMod==2||BSIM4mobMod==6) ? (1.0e-15) : (1.0e-9));
      end
      if (!$param_given(uc)) begin
        BSIM4uc = ((BSIM4mobMod==1||BSIM4mobMod==5) ? (-0.0465) : (-0.0465e-9));
      end
      if (!$param_given(uc1)) begin
        BSIM4uc1 = ((BSIM4mobMod==1||BSIM4mobMod==5) ? (-0.056) : (-0.056e-9));
      end
    end
    if (!$param_given(ub1)) begin
      BSIM4ub1 = -1.0e-18;
    end
    if (!$param_given(u0)) begin
      BSIM4u0 = ((BSIM4type==1) ? (0.067) : (0.025));
    end
    if (!$param_given(ute)) begin
      BSIM4ute = -1.5;
    end
    if (!$param_given(ucste)) begin
      BSIM4ucste = -4.775e-3;
    end
    if (!$param_given(voff)) begin
      BSIM4voff = -0.08;
    end
    if (!$param_given(etab)) begin
      BSIM4etab = -0.07;
    end
    if (!$param_given(agisl)) begin
      BSIM4agisl = agidl;
    end
    if (!$param_given(bgisl)) begin
      BSIM4bgisl = bgidl;
    end
    if (!$param_given(cgisl)) begin
      BSIM4cgisl = cgidl;
    end
    if (!$param_given(egisl)) begin
      BSIM4egisl = egidl;
    end
    if (!$param_given(rgisl)) begin
      BSIM4rgisl = rgidl;
    end
    if (!$param_given(kgisl)) begin
      BSIM4kgisl = kgidl;
    end
    if (!$param_given(fgisl)) begin
      BSIM4fgisl = fgidl;
    end
    if (!$param_given(aigc)) begin
      BSIM4aigc = ((BSIM4type==1) ? (1.36e-2) : (9.80e-3));
    end
    if (!$param_given(bigc)) begin
      BSIM4bigc = ((BSIM4type==1) ? (1.71e-3) : (7.59e-4));
    end
    if (!$param_given(cigc)) begin
      BSIM4cigc = ((BSIM4type==1) ? (0.075) : (0.03));
    end
    if ($param_given(aigsd)) begin
      BSIM4aigd = BSIM4aigsd;
      BSIM4aigs = BSIM4aigd;
    end else begin
      BSIM4aigsd = ((BSIM4type==1) ? (1.36e-2) : (9.80e-3));
      if (!$param_given(aigs)) begin
        BSIM4aigs = ((BSIM4type==1) ? (1.36e-2) : (9.80e-3));
      end
      if (!$param_given(aigd)) begin
        BSIM4aigd = ((BSIM4type==1) ? (1.36e-2) : (9.80e-3));
      end
    end
    if ($param_given(bigsd)) begin
      BSIM4bigd = BSIM4bigsd;
      BSIM4bigs = BSIM4bigd;
    end else begin
      BSIM4bigsd = ((BSIM4type==1) ? (1.71e-3) : (7.59e-4));
      if (!$param_given(bigs)) begin
        BSIM4bigs = ((BSIM4type==1) ? (1.71e-3) : (7.59e-4));
      end
      if (!$param_given(bigd)) begin
        BSIM4bigd = ((BSIM4type==1) ? (1.71e-3) : (7.59e-4));
      end
    end
    if ($param_given(cigsd)) begin
      BSIM4cigd = BSIM4cigsd;
      BSIM4cigs = BSIM4cigd;
    end else begin
      BSIM4cigsd = ((BSIM4type==1) ? (0.075) : (0.03));
      if (!$param_given(cigs)) begin
        BSIM4cigs = ((BSIM4type==1) ? (0.075) : (0.03));
      end
      if (!$param_given(cigd)) begin
        BSIM4cigd = ((BSIM4type==1) ? (0.075) : (0.03));
      end
    end
    if (!$param_given(ijthsfwd)) begin
      BSIM4ijthsfwd = 0.1;
    end
    if (!$param_given(ijthdfwd)) begin
      BSIM4ijthdfwd = BSIM4ijthsfwd;
    end
    if (!$param_given(ijthsrev)) begin
      BSIM4ijthsrev = 0.1;
    end
    if (!$param_given(ijthdrev)) begin
      BSIM4ijthdrev = BSIM4ijthsrev;
    end
    if (!$param_given(gidlclamp)) begin
      BSIM4gidlclamp = -1e-5;
    end
    if (!$param_given(xjbvs)) begin
      BSIM4xjbvs = 1.0;
    end
    if (!$param_given(xjbvd)) begin
      BSIM4xjbvd = BSIM4xjbvs;
    end
    if (!$param_given(bvs)) begin
      BSIM4bvs = 10.0;
    end
    if (!$param_given(bvd)) begin
      BSIM4bvd = BSIM4bvs;
    end
    if (!$param_given(ckappad)) begin
      BSIM4ckappad = ckappas;
    end
    if (!$param_given(vfbcv)) begin
      BSIM4vfbcv = -1.0;
    end
    if (!$param_given(dmci)) begin
      BSIM4dmci = dmcg;
    end
    if (!$param_given(lketac)) begin
      BSIM4lketac = lketa;
    end
    if (!$param_given(letab)) begin
      BSIM4letab = -0.0;
    end
    if (!$param_given(lagisl)) begin
      BSIM4lagisl = lagidl;
    end
    if (!$param_given(lbgisl)) begin
      BSIM4lbgisl = lbgidl;
    end
    if (!$param_given(lcgisl)) begin
      BSIM4lcgisl = lcgidl;
    end
    if (!$param_given(legisl)) begin
      BSIM4legisl = legidl;
    end
    if (!$param_given(lrgisl)) begin
      BSIM4lrgisl = lrgidl;
    end
    if (!$param_given(lkgisl)) begin
      BSIM4lkgisl = lkgidl;
    end
    if (!$param_given(lfgisl)) begin
      BSIM4lfgisl = lfgidl;
    end
    if (!$param_given(aigsd)&&($param_given(aigs)||$param_given(aigd))) begin
      if (!$param_given(laigs)) begin
        BSIM4laigs = 0.0;
      end
      if (!$param_given(laigd)) begin
        BSIM4laigd = 0.0;
      end
    end else begin
      BSIM4laigd = laigsd;
      BSIM4laigs = BSIM4laigd;
    end
    if (!$param_given(bigsd)&&($param_given(bigs)||$param_given(bigd))) begin
      if (!$param_given(lbigs)) begin
        BSIM4lbigs = 0.0;
      end
      if (!$param_given(lbigd)) begin
        BSIM4lbigd = 0.0;
      end
    end else begin
      BSIM4lbigd = lbigsd;
      BSIM4lbigs = BSIM4lbigd;
    end
    if (!$param_given(cigsd)&&($param_given(cigs)||$param_given(cigd))) begin
      if (!$param_given(lcigs)) begin
        BSIM4lcigs = 0.0;
      end
      if (!$param_given(lcigd)) begin
        BSIM4lcigd = 0.0;
      end
    end else begin
      BSIM4lcigd = lcigsd;
      BSIM4lcigs = BSIM4lcigd;
    end
    if (!$param_given(wketac)) begin
      BSIM4wketac = wketa;
    end
    if (!$param_given(wagisl)) begin
      BSIM4wagisl = wagidl;
    end
    if (!$param_given(wbgisl)) begin
      BSIM4wbgisl = wbgidl;
    end
    if (!$param_given(wcgisl)) begin
      BSIM4wcgisl = wcgidl;
    end
    if (!$param_given(wegisl)) begin
      BSIM4wegisl = wegidl;
    end
    if (!$param_given(wrgisl)) begin
      BSIM4wrgisl = wrgidl;
    end
    if (!$param_given(wkgisl)) begin
      BSIM4wkgisl = wkgidl;
    end
    if (!$param_given(wfgisl)) begin
      BSIM4wfgisl = wfgidl;
    end
    if (!$param_given(aigsd)&&($param_given(aigs)||$param_given(aigd))) begin
      if (!$param_given(waigs)) begin
        BSIM4waigs = 0.0;
      end
      if (!$param_given(waigd)) begin
        BSIM4waigd = 0.0;
      end
    end else begin
      BSIM4waigd = waigsd;
      BSIM4waigs = BSIM4waigd;
    end
    if (!$param_given(bigsd)&&($param_given(bigs)||$param_given(bigd))) begin
      if (!$param_given(wbigs)) begin
        BSIM4wbigs = 0.0;
      end
      if (!$param_given(wbigd)) begin
        BSIM4wbigd = 0.0;
      end
    end else begin
      BSIM4wbigd = wbigsd;
      BSIM4wbigs = BSIM4wbigd;
    end
    if (!$param_given(cigsd)&&($param_given(cigs)||$param_given(cigd))) begin
      if (!$param_given(wcigs)) begin
        BSIM4wcigs = 0.0;
      end
      if (!$param_given(wcigd)) begin
        BSIM4wcigd = 0.0;
      end
    end else begin
      BSIM4wcigd = wcigsd;
      BSIM4wcigs = BSIM4wcigd;
    end
    if (!$param_given(pketac)) begin
      BSIM4pketac = pketa;
    end
    if (!$param_given(pagisl)) begin
      BSIM4pagisl = pagidl;
    end
    if (!$param_given(pbgisl)) begin
      BSIM4pbgisl = pbgidl;
    end
    if (!$param_given(pcgisl)) begin
      BSIM4pcgisl = pcgidl;
    end
    if (!$param_given(pegisl)) begin
      BSIM4pegisl = pegidl;
    end
    if (!$param_given(prgisl)) begin
      BSIM4prgisl = prgidl;
    end
    if (!$param_given(pkgisl)) begin
      BSIM4pkgisl = pkgidl;
    end
    if (!$param_given(pfgisl)) begin
      BSIM4pfgisl = pfgidl;
    end
    if (!$param_given(aigsd)&&($param_given(aigs)||$param_given(aigd))) begin
      if (!$param_given(paigs)) begin
        BSIM4paigs = 0.0;
      end
      if (!$param_given(paigd)) begin
        BSIM4paigd = 0.0;
      end
    end else begin
      BSIM4paigd = paigsd;
      BSIM4paigs = BSIM4paigd;
    end
    if (!$param_given(bigsd)&&($param_given(bigs)||$param_given(bigd))) begin
      if (!$param_given(pbigs)) begin
        BSIM4pbigs = 0.0;
      end
      if (!$param_given(pbigd)) begin
        BSIM4pbigd = 0.0;
      end
    end else begin
      BSIM4pbigd = pbigsd;
      BSIM4pbigs = BSIM4pbigd;
    end
    if (!$param_given(cigsd)&&($param_given(cigs)||$param_given(cigd))) begin
      if (!$param_given(pcigs)) begin
        BSIM4pcigs = 0.0;
      end
      if (!$param_given(pcigd)) begin
        BSIM4pcigd = 0.0;
      end
    end else begin
      BSIM4pcigd = pcigsd;
      BSIM4pcigs = BSIM4pcigd;
    end
    if (!BSIM4tnomGiven) begin
      BSIM4tnom = VACONST_tnom;
    end
    if (!$param_given(llc)) begin
      BSIM4Llc = ll;
    end
    if (!$param_given(lwc)) begin
      BSIM4Lwc = lw;
    end
    if (!$param_given(lwlc)) begin
      BSIM4Lwlc = lwl;
    end
    if (!$param_given(wlc)) begin
      BSIM4Wlc = wl;
    end
    if (!$param_given(wwc)) begin
      BSIM4Wwc = ww;
    end
    if (!$param_given(wwlc)) begin
      BSIM4Wwlc = wwl;
    end
    if (!$param_given(dwc)) begin
      BSIM4dwc = wint;
    end
    if (!$param_given(dlc)) begin
      BSIM4dlc = lint;
    end
    if (!$param_given(dlcig)) begin
      BSIM4dlcig = lint;
    end
    if (!$param_given(dlcigd)) begin
      if ($param_given(dlcig)) begin
        BSIM4dlcigd = BSIM4dlcig;
      end else begin
        BSIM4dlcigd = lint;
      end
    end
    if (!$param_given(dwj)) begin
      BSIM4dwj = BSIM4dwc;
    end
    if (!$param_given(cjd)) begin
      BSIM4DunitAreaJctCap = cjs;
    end
    if (!$param_given(cjsws)) begin
      BSIM4SunitLengthSidewallJctCap = 5.0E-10;
    end
    if (!$param_given(cjswd)) begin
      BSIM4DunitLengthSidewallJctCap = BSIM4SunitLengthSidewallJctCap;
    end
    if (!$param_given(cjswgs)) begin
      BSIM4SunitLengthGateSidewallJctCap = BSIM4SunitLengthSidewallJctCap;
    end
    if (!$param_given(cjswgd)) begin
      BSIM4DunitLengthGateSidewallJctCap = BSIM4SunitLengthGateSidewallJctCap;
    end
    if (!$param_given(jsd)) begin
      BSIM4DjctSatCurDensity = jss;
    end
    if (!$param_given(jswd)) begin
      BSIM4DjctSidewallSatCurDensity = jsws;
    end
    if (!$param_given(jswgd)) begin
      BSIM4DjctGateSidewallSatCurDensity = jswgs;
    end
    if (!$param_given(pbs)) begin
      BSIM4SbulkJctPotential = 1.0;
    end
    if (!$param_given(pbd)) begin
      BSIM4DbulkJctPotential = BSIM4SbulkJctPotential;
    end
    if (!$param_given(pbsws)) begin
      BSIM4SsidewallJctPotential = 1.0;
    end
    if (!$param_given(pbswd)) begin
      BSIM4DsidewallJctPotential = BSIM4SsidewallJctPotential;
    end
    if (!$param_given(pbswgs)) begin
      BSIM4SGatesidewallJctPotential = BSIM4SsidewallJctPotential;
    end
    if (!$param_given(pbswgd)) begin
      BSIM4DGatesidewallJctPotential = BSIM4SGatesidewallJctPotential;
    end
    if (!$param_given(mjd)) begin
      BSIM4DbulkJctBotGradingCoeff = mjs;
    end
    if (!$param_given(mjswd)) begin
      BSIM4DbulkJctSideGradingCoeff = mjsws;
    end
    if (!$param_given(mjswgs)) begin
      BSIM4SbulkJctGateSideGradingCoeff = mjsws;
    end
    if (!$param_given(mjswgd)) begin
      BSIM4DbulkJctGateSideGradingCoeff = BSIM4SbulkJctGateSideGradingCoeff;
    end
    if (!$param_given(njd)) begin
      BSIM4DjctEmissionCoeff = njs;
    end
    if (!$param_given(xtid)) begin
      BSIM4DjctTempExponent = xtis;
    end
    if (!$param_given(jtsd)) begin
      BSIM4jtsd = jtss;
    end
    if (!$param_given(jtsswd)) begin
      BSIM4jtsswd = jtssws;
    end
    if (!$param_given(jtsswgd)) begin
      BSIM4jtsswgd = jtsswgs;
    end
    if (!$param_given(jtweff)) begin
      BSIM4jtweff = 0.0;
    end
    if (!$param_given(njtsd)) begin
      if ($param_given(njts)) begin
        BSIM4njtsd = njts;
      end else begin
        BSIM4njtsd = 20.0;
      end
    end
    if (!$param_given(njtsswd)) begin
      if ($param_given(njtssw)) begin
        BSIM4njtsswd = njtssw;
      end else begin
        BSIM4njtsswd = 20.0;
      end
    end
    if (!$param_given(njtsswgd)) begin
      if ($param_given(njtsswg)) begin
        BSIM4njtsswgd = njtsswg;
      end else begin
        BSIM4njtsswgd = 20.0;
      end
    end
    if (!$param_given(xtsd)) begin
      BSIM4xtsd = xtss;
    end
    if (!$param_given(xtsswd)) begin
      BSIM4xtsswd = xtssws;
    end
    if (!$param_given(xtsswgd)) begin
      BSIM4xtsswgd = xtsswgs;
    end
    if (!$param_given(tnjtsd)) begin
      if ($param_given(tnjts)) begin
        BSIM4tnjtsd = tnjts;
      end else begin
        BSIM4tnjtsd = 0.0;
      end
    end
    if (!$param_given(tnjtsswd)) begin
      if ($param_given(tnjtssw)) begin
        BSIM4tnjtsswd = tnjtssw;
      end else begin
        BSIM4tnjtsswd = 0.0;
      end
    end
    if (!$param_given(tnjtsswgd)) begin
      if ($param_given(tnjtsswg)) begin
        BSIM4tnjtsswgd = tnjtsswg;
      end else begin
        BSIM4tnjtsswgd = 0.0;
      end
    end
    if (!$param_given(vtsd)) begin
      BSIM4vtsd = vtss;
    end
    if (!$param_given(vtsswd)) begin
      BSIM4vtsswd = vtssws;
    end
    if (!$param_given(vtsswgd)) begin
      BSIM4vtsswgd = vtsswgs;
    end
    if (!$param_given(noia)) begin
      if (BSIM4type==1) begin
        BSIM4oxideTrapDensityA = 6.25e41;
      end else begin
        BSIM4oxideTrapDensityA = 6.188e40;
      end
    end
    if (!$param_given(noib)) begin
      if (BSIM4type==1) begin
        BSIM4oxideTrapDensityB = 3.125e26;
      end else begin
        BSIM4oxideTrapDensityB = 1.5e25;
      end
    end
    if (!$param_given(wpemod)) begin
      BSIM4wpemod = 0;
    end else if (BSIM4wpemod!=0&&BSIM4wpemod!=1) begin
      BSIM4wpemod = 0;
      $warning("wpemod has been set to its default value: 0.");
    end
    DMCGeff = dmcg-dmcgt;
    DMCIeff = BSIM4dmci;
    DMDGeff = dmdg-dmcgt;
    if (!BSIM4lGiven) begin
      BSIM4l = 5.0e-6;
    end
    if (!BSIM4wGiven) begin
      BSIM4w = 5.0e-6;
    end
    if (!$param_given(mult_fn)) begin
      BSIM4mult_fn = mult_i;
    end
    if (!BSIM4drainAreaGiven) begin
      BSIM4drainArea = 0.0;
    end
    if (!BSIM4drainPerimeterGiven) begin
      BSIM4drainPerimeter = 0.0;
    end
    if (!BSIM4sourceAreaGiven) begin
      BSIM4sourceArea = 0.0;
    end
    if (!BSIM4sourcePerimeterGiven) begin
      BSIM4sourcePerimeter = 0.0;
    end
    if (!$param_given(instance_rbdb)) begin
      i_BSIM4rbdb = rbdb;
    end
    if (!$param_given(instance_rbsb)) begin
      i_BSIM4rbsb = rbsb;
    end
    if (!$param_given(instance_rbpb)) begin
      i_BSIM4rbpb = rbpb;
    end
    if (!$param_given(instance_rbps)) begin
      i_BSIM4rbps = rbps;
    end
    if (!$param_given(instance_rbpd)) begin
      i_BSIM4rbpd = rbpd;
    end
    if (!$param_given(instance_xgw)) begin
      i_BSIM4xgw = xgw;
    end
    if (!$param_given(instance_ngcon)) begin
      i_BSIM4ngcon = ngcon;
    end
    if (!$param_given(instance_rbodymod)) begin
      i_BSIM4rbodyMod = BSIM4rbodyMod;
    end else if (i_BSIM4rbodyMod!=0&&i_BSIM4rbodyMod!=1&&i_BSIM4rbodyMod!=2) begin
      i_BSIM4rbodyMod = BSIM4rbodyMod;
      $warning("rbodyMod has been set to its global value %d.", BSIM4rbodyMod);
    end
    if (!$param_given(instance_rgatemod)) begin
      i_BSIM4rgateMod = BSIM4rgateMod;
    end else if (i_BSIM4rgateMod!=0&&i_BSIM4rgateMod!=1&&i_BSIM4rgateMod!=2&&i_BSIM4rgateMod!=3) begin
      i_BSIM4rgateMod = BSIM4rgateMod;
      $warning("rgateMod has been set to its global value %d.", BSIM4rgateMod);
    end
    if (!$param_given(instance_geomod)) begin
      i_BSIM4geoMod = geomod;
    end
    if (!$param_given(instance_trnqsmod)) begin
      i_BSIM4trnqsMod = BSIM4trnqsMod;
    end else if (i_BSIM4trnqsMod!=0&&i_BSIM4trnqsMod!=1) begin
      i_BSIM4trnqsMod = BSIM4trnqsMod;
      $warning("trnqsMod has been set to its global value %d.", BSIM4trnqsMod);
    end
    if (!$param_given(instance_acnqsmod)) begin
      i_BSIM4acnqsMod = BSIM4acnqsMod;
    end else if (i_BSIM4acnqsMod!=0&&i_BSIM4acnqsMod!=1) begin
      i_BSIM4acnqsMod = BSIM4acnqsMod;
      $warning("acnqsMod has been set to its global value %d.", BSIM4acnqsMod);
    end
    if (!$param_given(sd)) begin
      BSIM4sd = 2*dmcg;
    end
    if (!$param_given(sca)) begin
      BSIM4sca = 0.0;
    end
    if (!$param_given(scb)) begin
      BSIM4scb = 0.0;
    end
    if (!$param_given(scc)) begin
      BSIM4scc = 0.0;
    end
    if (!$param_given(sc)) begin
      BSIM4sc = 0.0;
    end
    createNode = 0;
    if (BSIM4rdsMod!=0||BSIM4tnoiMod==1) begin
      createNode = 1;
    end else if (rsh>0) begin
      if ($param_given(nrd)&&nrd>0) begin
        createNode = 1;
      end else if (!$param_given(nrd)&&instance_rgeomod!=0) begin
        BSIM4RdseffGeo(nf, i_BSIM4geoMod, instance_rgeomod, instance_min, BSIM4w, rsh, DMCGeff, DMCIeff, DMDGeff, 0, Rtot);
        if (Rtot>0) begin
          createNode = 1;
        end
      end
    end
    if (!(createNode!=0&&1)) begin
      V(d_int, d) <+ 0;
    end
    createnode_d = createNode;
    createNode = 0;
    if (BSIM4rdsMod!=0||BSIM4tnoiMod==1) begin
      createNode = 1;
    end else if (rsh>0) begin
      if ($param_given(nrs)&&nrs>0) begin
        createNode = 1;
      end else if (!$param_given(nrs)&&instance_rgeomod!=0) begin
        BSIM4RdseffGeo(nf, i_BSIM4geoMod, instance_rgeomod, instance_min, BSIM4w, rsh, DMCGeff, DMCIeff, DMDGeff, 1, Rtot);
        if (Rtot>0) begin
          createNode = 1;
        end
      end
    end
    if (!(createNode!=0&&1)) begin
      V(s_int, s) <+ 0;
    end
    createnode_s = createNode;
    if (!(i_BSIM4rgateMod>0&&1)) begin
      V(g_int, g) <+ 0;
    end
    if (!(i_BSIM4rgateMod==3&&1)) begin
      V(gmid_int, g) <+ 0;
    end
    if (!(i_BSIM4rbodyMod==1||i_BSIM4rbodyMod==2)) begin
      V(sb_int, b) <+ 0;
      V(b_int, sb_int) <+ 0;
      V(db_int, b_int) <+ 0;
    end
    if (!(i_BSIM4trnqsMod&&1)) begin
      V(q_int) <+ 0;
      collapse_q_int = 1;
    end
    if (BSIM4tnoiMod!=2) begin
        V(noise_int) <+ 0;
    end
    i_BSIM4trnqsMod = i_BSIM4trnqsMod || i_BSIM4acnqsMod;

    // Tag: temp, function: BSIM4temp
    Lnew = 0.0;
    Fatal_Flag = 0;
    Temp = $temperature;
    if (BSIM4SbulkJctPotential<0.1) begin
      BSIM4SbulkJctPotential = 0.1;
      $warning("Given pbs is less than 0.1. Pbs is set to 0.1.");
    end
    if (BSIM4SsidewallJctPotential<0.1) begin
      BSIM4SsidewallJctPotential = 0.1;
      $warning("Given pbsws is less than 0.1. Pbsws is set to 0.1.");
    end
    if (BSIM4SGatesidewallJctPotential<0.1) begin
      BSIM4SGatesidewallJctPotential = 0.1;
      $warning("Given pbswgs is less than 0.1. Pbswgs is set to 0.1.");
    end
    if (BSIM4DbulkJctPotential<0.1) begin
      BSIM4DbulkJctPotential = 0.1;
      $warning("Given pbd is less than 0.1. Pbd is set to 0.1.");
    end
    if (BSIM4DsidewallJctPotential<0.1) begin
      BSIM4DsidewallJctPotential = 0.1;
      $warning("Given pbswd is less than 0.1. Pbswd is set to 0.1.");
    end
    if (BSIM4DGatesidewallJctPotential<0.1) begin
      BSIM4DGatesidewallJctPotential = 0.1;
      $warning("Given pbswgd is less than 0.1. Pbswgd is set to 0.1.");
    end
    if (BSIM4mtrlMod==0) begin
      chktol = abs(BSIM4toxe);
      if (abs(BSIM4toxp)>chktol) begin
        chktol = abs(BSIM4toxp);
      end
      if (abs(dtox)>chktol) begin
        chktol = abs(dtox);
      end
      chktol = chktol*1e-14;
      if ($param_given(toxe)&&$param_given(toxp)&&$param_given(dtox)&&abs(BSIM4toxe-(BSIM4toxp+dtox))>chktol) begin
        $warning("toxe, toxp and dtox all given and toxe != toxp + dtox; dtox ignored.");
      end else if ($param_given(toxe)&&!$param_given(toxp)) begin
        BSIM4toxp = BSIM4toxe-dtox;
      end else if (!$param_given(toxe)&&$param_given(toxp)) begin
        BSIM4toxe = BSIM4toxp+dtox;
        if (!$param_given(toxm)) begin
          BSIM4toxm = BSIM4toxe;
        end
      end
    end else if (BSIM4mtrlCompatMod!=0) begin
      T0 = epsrox/3.9;
      if ($param_given(eot)&&$param_given(toxp)&&$param_given(dtox)&&((BSIM4eot*T0-(BSIM4toxp+dtox)<0.0) ? (-(BSIM4eot*T0-(BSIM4toxp+dtox))) : (BSIM4eot*T0-(BSIM4toxp+dtox)))>1.0e-20) begin
        $warning("eot, toxp and dtox all given and eot * EPSROX / 3.9 != toxp + dtox; dtox ignored.");
      end else if ($param_given(eot)&&!$param_given(toxp)) begin
        BSIM4toxp = T0*BSIM4eot-dtox;
      end else if (!$param_given(eot)&&$param_given(toxp)) begin
        BSIM4eot = (BSIM4toxp+dtox)/T0;
        if (!$param_given(toxm)) begin
          BSIM4toxm = BSIM4eot;
        end
      end
    end
    if (BSIM4mtrlMod) begin
      temp_epsrox = 3.9;
      temp_toxe = BSIM4eot;
      epssub = 8.85418e-12*epsrsub;
    end else begin
      temp_epsrox = epsrox;
      temp_toxe = BSIM4toxe;
      epssub = 1.03594e-10;
    end
    if (!$param_given(cf)) begin
      BSIM4cf = 2.0*temp_epsrox*8.85418e-12/3.141592654*ln(1.0+0.4e-6/temp_toxe);
    end
    BSIM4coxe = temp_epsrox*8.85418e-12/temp_toxe;
    if (BSIM4mtrlMod==0||BSIM4mtrlCompatMod!=0) begin
      BSIM4coxp = epsrox*8.85418e-12/BSIM4toxp;
    end
    if (!$param_given(cgdo)) begin
      if ($param_given(dlc)&&BSIM4dlc>0.0) begin
        BSIM4cgdo = BSIM4dlc*BSIM4coxe-cgdl;
      end else begin
        BSIM4cgdo = 0.6*xj*BSIM4coxe;
      end
    end
    if (!$param_given(cgso)) begin
      if ($param_given(dlc)&&BSIM4dlc>0.0) begin
        BSIM4cgso = BSIM4dlc*BSIM4coxe-cgsl;
      end else begin
        BSIM4cgso = 0.6*xj*BSIM4coxe;
      end
    end
    if (!$param_given(cgbo)) begin
      BSIM4cgbo = 2.0*BSIM4dwc*BSIM4coxe;
    end
    Tnom = BSIM4tnom;
    TRatio = Temp/Tnom;
    BSIM4vcrit = CONSTvt0*ln(CONSTvt0/(CONSTroot2*1.0e-14));
    BSIM4factor1 = sqrt(epssub/(temp_epsrox*8.85418e-12)*temp_toxe);
    BSIM4vtm0 = 8.617087e-5*Tnom;
    Vtm0 = BSIM4vtm0;
    if (BSIM4mtrlMod==0) begin
      Eg0 = 1.16-7.02e-4*Tnom*Tnom/(Tnom+1108.0);
      ni = 1.45e10*(Tnom/300.15)*sqrt(Tnom/300.15)*exp(21.5565981-Eg0/(2.0*Vtm0));
    end else begin
      Eg0 = bg0sub-tbgasub*Tnom*Tnom/(Tnom+tbgbsub);
      T0 = bg0sub-tbgasub*90090.0225/(300.15+tbgbsub);
      ni = ni0sub*(Tnom/300.15)*sqrt(Tnom/300.15)*exp((T0-Eg0)/(2.0*Vtm0));
    end
    BSIM4Eg0 = Eg0;
    BSIM4vtm = 8.617087e-5*Temp;
    if (BSIM4mtrlMod==0) begin
      Eg = 1.16-7.02e-4*Temp*Temp/(Temp+1108.0);
    end else begin
      Eg = bg0sub-tbgasub*Temp*Temp/(Temp+tbgbsub);
    end
    if (Temp!=Tnom) begin
      T0 = Eg0/Vtm0-Eg/BSIM4vtm;
      T1 = ln(Temp/Tnom);
      T2 = T0+xtis*T1;
      T3 = exp(T2/njs);
      BSIM4SjctTempSatCurDensity = jss*T3;
      BSIM4SjctSidewallTempSatCurDensity = jsws*T3;
      BSIM4SjctGateSidewallTempSatCurDensity = jswgs*T3;
      T2 = T0+BSIM4DjctTempExponent*T1;
      T3 = exp(T2/BSIM4DjctEmissionCoeff);
      BSIM4DjctTempSatCurDensity = BSIM4DjctSatCurDensity*T3;
      BSIM4DjctSidewallTempSatCurDensity = BSIM4DjctSidewallSatCurDensity*T3;
      BSIM4DjctGateSidewallTempSatCurDensity = BSIM4DjctGateSidewallSatCurDensity*T3;
    end else begin
      BSIM4SjctTempSatCurDensity = jss;
      BSIM4SjctSidewallTempSatCurDensity = jsws;
      BSIM4SjctGateSidewallTempSatCurDensity = jswgs;
      BSIM4DjctTempSatCurDensity = BSIM4DjctSatCurDensity;
      BSIM4DjctSidewallTempSatCurDensity = BSIM4DjctSidewallSatCurDensity;
      BSIM4DjctGateSidewallTempSatCurDensity = BSIM4DjctGateSidewallSatCurDensity;
    end
    if (BSIM4SjctTempSatCurDensity<0.0) begin
      BSIM4SjctTempSatCurDensity = 0.0;
    end
    if (BSIM4SjctSidewallTempSatCurDensity<0.0) begin
      BSIM4SjctSidewallTempSatCurDensity = 0.0;
    end
    if (BSIM4SjctGateSidewallTempSatCurDensity<0.0) begin
      BSIM4SjctGateSidewallTempSatCurDensity = 0.0;
    end
    if (BSIM4DjctTempSatCurDensity<0.0) begin
      BSIM4DjctTempSatCurDensity = 0.0;
    end
    if (BSIM4DjctSidewallTempSatCurDensity<0.0) begin
      BSIM4DjctSidewallTempSatCurDensity = 0.0;
    end
    if (BSIM4DjctGateSidewallTempSatCurDensity<0.0) begin
      BSIM4DjctGateSidewallTempSatCurDensity = 0.0;
    end
    delTemp = $temperature-BSIM4tnom;
    T0 = tcj*delTemp;
    if (T0>=-1.0) begin
      BSIM4SunitAreaTempJctCap = cjs*(1.0+T0);
      BSIM4DunitAreaTempJctCap = BSIM4DunitAreaJctCap*(1.0+T0);
    end else begin
      if (cjs>0.0) begin
        BSIM4SunitAreaTempJctCap = 0.0;
        $warning("Temperature effect has caused cjs to be negative. Cjs is clamped to zero.");
      end
      if (BSIM4DunitAreaJctCap>0.0) begin
        BSIM4DunitAreaTempJctCap = 0.0;
        $warning("Temperature effect has caused cjd to be negative. Cjd is clamped to zero.");
      end
    end
    T0 = tcjsw*delTemp;
    if (BSIM4SunitLengthSidewallJctCap<0.0) begin
      BSIM4SunitLengthSidewallJctCap = 0.0;
      $warning("CJSWS is negative. Cjsws is clamped to zero.");
    end
    if (BSIM4DunitLengthSidewallJctCap<0.0) begin
      BSIM4DunitLengthSidewallJctCap = 0.0;
      $warning("CJSWD is negative. Cjswd is clamped to zero.");
    end
    if (T0>=-1.0) begin
      BSIM4SunitLengthSidewallTempJctCap = BSIM4SunitLengthSidewallJctCap*(1.0+T0);
      BSIM4DunitLengthSidewallTempJctCap = BSIM4DunitLengthSidewallJctCap*(1.0+T0);
    end else begin
      if (BSIM4SunitLengthSidewallJctCap>0.0) begin
        BSIM4SunitLengthSidewallTempJctCap = 0.0;
        $warning("Temperature effect has caused cjsws to be negative. Cjsws is clamped to zero.");
      end
      if (BSIM4DunitLengthSidewallJctCap>0.0) begin
        BSIM4DunitLengthSidewallTempJctCap = 0.0;
        $warning("Temperature effect has caused cjswd to be negative. Cjswd is clamped to zero.");
      end
    end
    T0 = tcjswg*delTemp;
    if (T0>=-1.0) begin
      BSIM4SunitLengthGateSidewallTempJctCap = BSIM4SunitLengthGateSidewallJctCap*(1.0+T0);
      BSIM4DunitLengthGateSidewallTempJctCap = BSIM4DunitLengthGateSidewallJctCap*(1.0+T0);
    end else begin
      if (BSIM4SunitLengthGateSidewallJctCap>0.0) begin
        BSIM4SunitLengthGateSidewallTempJctCap = 0.0;
        $warning("Temperature effect has caused cjswgs to be negative. Cjswgs is clamped to zero.");
      end
      if (BSIM4DunitLengthGateSidewallJctCap>0.0) begin
        BSIM4DunitLengthGateSidewallTempJctCap = 0.0;
        $warning("Temperature effect has caused cjswgd to be negative. Cjswgd is clamped to zero.");
      end
    end
    BSIM4PhiBS = BSIM4SbulkJctPotential-tpb*delTemp;
    if (BSIM4PhiBS<0.01) begin
      BSIM4PhiBS = 0.01;
      $warning("Temperature effect has caused pbs to be less than 0.01. Pbs is clamped to 0.01.");
    end
    BSIM4PhiBD = BSIM4DbulkJctPotential-tpb*delTemp;
    if (BSIM4PhiBD<0.01) begin
      BSIM4PhiBD = 0.01;
      $warning("Temperature effect has caused pbd to be less than 0.01. Pbd is clamped to 0.01.");
    end
    BSIM4PhiBSWS = BSIM4SsidewallJctPotential-tpbsw*delTemp;
    if (BSIM4PhiBSWS<0.01) begin
      BSIM4PhiBSWS = 0.01;
      $warning("Temperature effect has caused pbsws to be less than 0.01. Pbsws is clamped to 0.01.");
    end
    BSIM4PhiBSWD = BSIM4DsidewallJctPotential-tpbsw*delTemp;
    if (BSIM4PhiBSWD<0.01) begin
      BSIM4PhiBSWD = 0.01;
      $warning("Temperature effect has caused pbswd to be less than 0.01. Pbswd is clamped to 0.01.");
    end
    BSIM4PhiBSWGS = BSIM4SGatesidewallJctPotential-tpbswg*delTemp;
    if (BSIM4PhiBSWGS<0.01) begin
      BSIM4PhiBSWGS = 0.01;
      $warning("Temperature effect has caused pbswgs to be less than 0.01. Pbswgs is clamped to 0.01.");
    end
    BSIM4PhiBSWGD = BSIM4DGatesidewallJctPotential-tpbswg*delTemp;
    if (BSIM4PhiBSWGD<0.01) begin
      BSIM4PhiBSWGD = 0.01;
      $warning("Temperature effect has caused pbswgd to be less than 0.01. Pbswgd is clamped to 0.01.");
    end
    if (BSIM4ijthdfwd<=0.0) begin
      BSIM4ijthdfwd = 0.0;
      $warning("Ijthdfwd reset to %g.", BSIM4ijthdfwd);
    end
    if (BSIM4ijthsfwd<=0.0) begin
      BSIM4ijthsfwd = 0.0;
      $warning("Ijthsfwd reset to %g.", BSIM4ijthsfwd);
    end
    if (BSIM4ijthdrev<=0.0) begin
      BSIM4ijthdrev = 0.0;
      $warning("Ijthdrev reset to %g.", BSIM4ijthdrev);
    end
    if (BSIM4ijthsrev<=0.0) begin
      BSIM4ijthsrev = 0.0;
      $warning("Ijthsrev reset to %g.", BSIM4ijthsrev);
    end
    if (BSIM4xjbvd<=0.0&&BSIM4dioMod==2) begin
      BSIM4xjbvd = 0.0;
      $warning("Xjbvd reset to %g.", BSIM4xjbvd);
    end else if (BSIM4xjbvd<0.0&&BSIM4dioMod==0) begin
      BSIM4xjbvd = 0.0;
      $warning("Xjbvd reset to %g.", BSIM4xjbvd);
    end
    if (BSIM4bvd<=0.0) begin
      BSIM4bvd = 0.0;
      $warning("BVD reset to %g.", BSIM4bvd);
    end
    if (BSIM4xjbvs<=0.0&&BSIM4dioMod==2) begin
      BSIM4xjbvs = 0.0;
      $warning("Xjbvs reset to %g.", BSIM4xjbvs);
    end else if (BSIM4xjbvs<0.0&&BSIM4dioMod==0) begin
      BSIM4xjbvs = 0.0;
      $warning("Xjbvs reset to %g.", BSIM4xjbvs);
    end
    if (BSIM4bvs<=0.0) begin
      BSIM4bvs = 0.0;
      $warning("BVS reset to %g.", BSIM4bvs);
    end
    Ldrn = BSIM4l;
    Wdrn = BSIM4w/nf;
    Length = BSIM4l;
    Width = BSIM4w;
    NFinger = nf;
    Lnew = BSIM4l+xl;
    Wnew = BSIM4w/nf+xw;
    T0 = pow(Lnew, lln);
    T1 = pow(Wnew, lwn);
    tmp1 = ll/T0+lw/T1+lwl/(T0*T1);
    BSIM4dl = lint+tmp1;
    tmp2 = BSIM4Llc/T0+BSIM4Lwc/T1+BSIM4Lwlc/(T0*T1);
    sd_BSIM4dlc = BSIM4dlc+tmp2;
    T2 = pow(Lnew, wln);
    T3 = pow(Wnew, wwn);
    tmp1 = wl/T2+ww/T3+wwl/(T2*T3);
    BSIM4dw = wint+tmp1;
    tmp2 = BSIM4Wlc/T2+BSIM4Wwc/T3+BSIM4Wwlc/(T2*T3);
    sd_BSIM4dwc = BSIM4dwc+tmp2;
    sd_BSIM4dwj = BSIM4dwj+tmp2;
    BSIM4leff = Lnew-2.0*BSIM4dl;
    if (BSIM4leff<=0.0) begin
      $fatal(0, "Effective channel length <= 0");
    end
    BSIM4weff = Wnew-2.0*BSIM4dw;
    if (BSIM4weff<=0.0) begin
      $fatal(0, "Effective channel width <= 0");
    end
    BSIM4leffCV = Lnew-2.0*sd_BSIM4dlc;
    if (BSIM4leffCV<=0.0) begin
      $fatal(0, "Effective channel length for C-V <= 0");
    end
    BSIM4weffCV = Wnew-2.0*sd_BSIM4dwc;
    if (BSIM4weffCV<=0.0) begin
      $fatal(0, "Effective channel width for C-V <= 0");
    end
    BSIM4weffCJ = Wnew-2.0*sd_BSIM4dwj;
    if (BSIM4weffCJ<=0.0) begin
      $fatal(0, "Effective channel width for S/D junctions <= 0");
    end
    if (binunit==1) begin
      Inv_L = 1.0e-6/BSIM4leff;
      Inv_W = 1.0e-6/BSIM4weff;
      Inv_LW = 1.0e-12/(BSIM4leff*BSIM4weff);
    end else begin
      Inv_L = 1.0/BSIM4leff;
      Inv_W = 1.0/BSIM4weff;
      Inv_LW = 1.0/(BSIM4leff*BSIM4weff);
    end
    sd_BSIM4cdsc = cdsc+lcdsc*Inv_L+wcdsc*Inv_W+pcdsc*Inv_LW;
    sd_BSIM4cdscb = cdscb+lcdscb*Inv_L+wcdscb*Inv_W+pcdscb*Inv_LW;
    sd_BSIM4cdscd = cdscd+lcdscd*Inv_L+wcdscd*Inv_W+pcdscd*Inv_LW;
    sd_BSIM4cit = cit+lcit*Inv_L+wcit*Inv_W+pcit*Inv_LW;
    sd_BSIM4nfactor = nfactor+lnfactor*Inv_L+wnfactor*Inv_W+pnfactor*Inv_LW;
    sd_BSIM4tnfactor = tnfactor+ltnfactor*Inv_L+wtnfactor*Inv_W+ptnfactor*Inv_LW;
    sd_BSIM4xj = xj+lxj*Inv_L+wxj*Inv_W+pxj*Inv_LW;
    sd_BSIM4vsat = vsat+lvsat*Inv_L+wvsat*Inv_W+pvsat*Inv_LW;
    sd_BSIM4at = at+lat*Inv_L+wat*Inv_W+pat*Inv_LW;
    sd_BSIM4a0 = a0+la0*Inv_L+wa0*Inv_W+pa0*Inv_LW;
    sd_BSIM4ags = ags+lags*Inv_L+wags*Inv_W+pags*Inv_LW;
    sd_BSIM4a1 = a1+la1*Inv_L+wa1*Inv_W+pa1*Inv_LW;
    sd_BSIM4a2 = a2+la2*Inv_L+wa2*Inv_W+pa2*Inv_LW;
    sd_BSIM4keta = BSIM4keta+lketa*Inv_L+wketa*Inv_W+pketa*Inv_LW;
    sd_BSIM4ketac = BSIM4ketac+BSIM4lketac*Inv_L+BSIM4wketac*Inv_W+BSIM4pketac*Inv_LW;
    sd_BSIM4nsub = nsub+lnsub*Inv_L+wnsub*Inv_W+pnsub*Inv_LW;
    sd_BSIM4ndep = ndep+lndep*Inv_L+wndep*Inv_W+pndep*Inv_LW;
    sd_BSIM4nsd = nsd+lnsd*Inv_L+wnsd*Inv_W+pnsd*Inv_LW;
    sd_BSIM4phin = phin+lphin*Inv_L+wphin*Inv_W+pphin*Inv_LW;
    sd_BSIM4ngate = ngate+lngate*Inv_L+wngate*Inv_W+pngate*Inv_LW;
    sd_BSIM4gamma1 = gamma1+lgamma1*Inv_L+wgamma1*Inv_W+pgamma1*Inv_LW;
    sd_BSIM4gamma2 = gamma2+lgamma2*Inv_L+wgamma2*Inv_W+pgamma2*Inv_LW;
    sd_BSIM4vbx = vbx+lvbx*Inv_L+wvbx*Inv_W+pvbx*Inv_LW;
    sd_BSIM4vbm = BSIM4vbm+lvbm*Inv_L+wvbm*Inv_W+pvbm*Inv_LW;
    sd_BSIM4xt = xt+lxt*Inv_L+wxt*Inv_W+pxt*Inv_LW;
    sd_BSIM4vfb = BSIM4vfb+lvfb*Inv_L+wvfb*Inv_W+pvfb*Inv_LW;
    sd_BSIM4k1 = k1+lk1*Inv_L+wk1*Inv_W+pk1*Inv_LW;
    sd_BSIM4kt1 = BSIM4kt1+lkt1*Inv_L+wkt1*Inv_W+pkt1*Inv_LW;
    sd_BSIM4kt1l = kt1l+lkt1l*Inv_L+wkt1l*Inv_W+pkt1l*Inv_LW;
    sd_BSIM4k2 = k2+lk2*Inv_L+wk2*Inv_W+pk2*Inv_LW;
    sd_BSIM4kt2 = kt2+lkt2*Inv_L+wkt2*Inv_W+pkt2*Inv_LW;
    sd_BSIM4k3 = k3+lk3*Inv_L+wk3*Inv_W+pk3*Inv_LW;
    sd_BSIM4k3b = k3b+lk3b*Inv_L+wk3b*Inv_W+pk3b*Inv_LW;
    sd_BSIM4w0 = w0+lw0*Inv_L+ww0*Inv_W+pw0*Inv_LW;
    sd_BSIM4lpe0 = lpe0+llpe0*Inv_L+wlpe0*Inv_W+plpe0*Inv_LW;
    sd_BSIM4lpeb = lpeb+llpeb*Inv_L+wlpeb*Inv_W+plpeb*Inv_LW;
    sd_BSIM4dvtp0 = dvtp0+ldvtp0*Inv_L+wdvtp0*Inv_W+pdvtp0*Inv_LW;
    sd_BSIM4dvtp1 = dvtp1+ldvtp1*Inv_L+wdvtp1*Inv_W+pdvtp1*Inv_LW;
    sd_BSIM4dvtp2 = dvtp2+ldvtp2*Inv_L+wdvtp2*Inv_W+pdvtp2*Inv_LW;
    sd_BSIM4dvtp3 = dvtp3+ldvtp3*Inv_L+wdvtp3*Inv_W+pdvtp3*Inv_LW;
    sd_BSIM4dvtp4 = dvtp4+ldvtp4*Inv_L+wdvtp4*Inv_W+pdvtp4*Inv_LW;
    sd_BSIM4dvtp5 = dvtp5+ldvtp5*Inv_L+wdvtp5*Inv_W+pdvtp5*Inv_LW;
    sd_BSIM4dvt0 = dvt0+ldvt0*Inv_L+wdvt0*Inv_W+pdvt0*Inv_LW;
    sd_BSIM4dvt1 = dvt1+ldvt1*Inv_L+wdvt1*Inv_W+pdvt1*Inv_LW;
    sd_BSIM4dvt2 = BSIM4dvt2+ldvt2*Inv_L+wdvt2*Inv_W+pdvt2*Inv_LW;
    sd_BSIM4dvt0w = dvt0w+ldvt0w*Inv_L+wdvt0w*Inv_W+pdvt0w*Inv_LW;
    sd_BSIM4dvt1w = dvt1w+ldvt1w*Inv_L+wdvt1w*Inv_W+pdvt1w*Inv_LW;
    sd_BSIM4dvt2w = BSIM4dvt2w+ldvt2w*Inv_L+wdvt2w*Inv_W+pdvt2w*Inv_LW;
    sd_BSIM4drout = drout+ldrout*Inv_L+wdrout*Inv_W+pdrout*Inv_LW;
    sd_BSIM4dsub = BSIM4dsub+ldsub*Inv_L+wdsub*Inv_W+pdsub*Inv_LW;
    sd_BSIM4vth0 = BSIM4vth0+lvth0*Inv_L+wvth0*Inv_W+pvth0*Inv_LW;
    sd_BSIM4ua = BSIM4ua+lua*Inv_L+wua*Inv_W+pua*Inv_LW;
    sd_BSIM4ua1 = ua1+lua1*Inv_L+wua1*Inv_W+pua1*Inv_LW;
    sd_BSIM4ub = ub+lub*Inv_L+wub*Inv_W+pub*Inv_LW;
    sd_BSIM4ub1 = BSIM4ub1+lub1*Inv_L+wub1*Inv_W+pub1*Inv_LW;
    sd_BSIM4uc = BSIM4uc+luc*Inv_L+wuc*Inv_W+puc*Inv_LW;
    sd_BSIM4uc1 = BSIM4uc1+luc1*Inv_L+wuc1*Inv_W+puc1*Inv_LW;
    sd_BSIM4ud = ud+lud*Inv_L+wud*Inv_W+pud*Inv_LW;
    sd_BSIM4ud1 = ud1+lud1*Inv_L+wud1*Inv_W+pud1*Inv_LW;
    sd_BSIM4up = up+lup*Inv_L+wup*Inv_W+pup*Inv_LW;
    sd_BSIM4lp = lp+llp*Inv_L+wlp*Inv_W+plp*Inv_LW;
    sd_BSIM4eu = BSIM4eu+leu*Inv_L+weu*Inv_W+peu*Inv_LW;
    sd_BSIM4u0 = BSIM4u0+lu0*Inv_L+wu0*Inv_W+pu0*Inv_LW;
    sd_BSIM4ute = BSIM4ute+lute*Inv_L+wute*Inv_W+pute*Inv_LW;
    sd_BSIM4ucs = BSIM4ucs+lucs*Inv_L+wucs*Inv_W+pucs*Inv_LW;
    sd_BSIM4ucste = BSIM4ucste+lucste*Inv_L+wucste*Inv_W+pucste*Inv_LW;
    sd_BSIM4voff = BSIM4voff+lvoff*Inv_L+wvoff*Inv_W+pvoff*Inv_LW;
    sd_BSIM4tvoff = tvoff+ltvoff*Inv_L+wtvoff*Inv_W+ptvoff*Inv_LW;
    sd_BSIM4minv = minv+lminv*Inv_L+wminv*Inv_W+pminv*Inv_LW;
    sd_BSIM4minvcv = minvcv+lminvcv*Inv_L+wminvcv*Inv_W+pminvcv*Inv_LW;
    sd_BSIM4fprout = fprout+lfprout*Inv_L+wfprout*Inv_W+pfprout*Inv_LW;
    sd_BSIM4pdits = pdits+lpdits*Inv_L+wpdits*Inv_W+ppdits*Inv_LW;
    sd_BSIM4pditsd = pditsd+lpditsd*Inv_L+wpditsd*Inv_W+ppditsd*Inv_LW;
    sd_BSIM4delta = delta+ldelta*Inv_L+wdelta*Inv_W+pdelta*Inv_LW;
    sd_BSIM4rdsw = rdsw+lrdsw*Inv_L+wrdsw*Inv_W+prdsw*Inv_LW;
    sd_BSIM4rdw = rdw+lrdw*Inv_L+wrdw*Inv_W+prdw*Inv_LW;
    sd_BSIM4rsw = rsw+lrsw*Inv_L+wrsw*Inv_W+prsw*Inv_LW;
    sd_BSIM4prwg = prwg+lprwg*Inv_L+wprwg*Inv_W+pprwg*Inv_LW;
    sd_BSIM4prwb = prwb+lprwb*Inv_L+wprwb*Inv_W+pprwb*Inv_LW;
    sd_BSIM4prt = prt+lprt*Inv_L+wprt*Inv_W+pprt*Inv_LW;
    sd_BSIM4eta0 = eta0+leta0*Inv_L+weta0*Inv_W+peta0*Inv_LW;
    sd_BSIM4teta0 = teta0+lteta0*Inv_L+wteta0*Inv_W+pteta0*Inv_LW;
    sd_BSIM4tvoffcv = tvoffcv+ltvoffcv*Inv_L+wtvoffcv*Inv_W+ptvoffcv*Inv_LW;
    sd_BSIM4etab = BSIM4etab+BSIM4letab*Inv_L+wetab*Inv_W+petab*Inv_LW;
    sd_BSIM4pclm = pclm+lpclm*Inv_L+wpclm*Inv_W+ppclm*Inv_LW;
    sd_BSIM4pdibl1 = pdiblc1+lpdiblc1*Inv_L+wpdiblc1*Inv_W+ppdiblc1*Inv_LW;
    sd_BSIM4pdibl2 = pdiblc2+lpdiblc2*Inv_L+wpdiblc2*Inv_W+ppdiblc2*Inv_LW;
    sd_BSIM4pdiblb = pdiblcb+lpdiblcb*Inv_L+wpdiblcb*Inv_W+ppdiblcb*Inv_LW;
    sd_BSIM4pscbe1 = pscbe1+lpscbe1*Inv_L+wpscbe1*Inv_W+ppscbe1*Inv_LW;
    sd_BSIM4pscbe2 = pscbe2+lpscbe2*Inv_L+wpscbe2*Inv_W+ppscbe2*Inv_LW;
    sd_BSIM4pvag = pvag+lpvag*Inv_L+wpvag*Inv_W+ppvag*Inv_LW;
    sd_BSIM4wr = wr+lwr*Inv_L+wwr*Inv_W+pwr*Inv_LW;
    sd_BSIM4dwg = dwg+ldwg*Inv_L+wdwg*Inv_W+pdwg*Inv_LW;
    sd_BSIM4dwb = dwb+ldwb*Inv_L+wdwb*Inv_W+pdwb*Inv_LW;
    sd_BSIM4b0 = b0+lb0*Inv_L+wb0*Inv_W+pb0*Inv_LW;
    sd_BSIM4b1 = b1+lb1*Inv_L+wb1*Inv_W+pb1*Inv_LW;
    sd_BSIM4alpha0 = alpha0+lalpha0*Inv_L+walpha0*Inv_W+palpha0*Inv_LW;
    sd_BSIM4alpha1 = alpha1+lalpha1*Inv_L+walpha1*Inv_W+palpha1*Inv_LW;
    sd_BSIM4beta0 = beta0+lbeta0*Inv_L+wbeta0*Inv_W+pbeta0*Inv_LW;
    sd_BSIM4agidl = agidl+lagidl*Inv_L+wagidl*Inv_W+pagidl*Inv_LW;
    sd_BSIM4bgidl = bgidl+lbgidl*Inv_L+wbgidl*Inv_W+pbgidl*Inv_LW;
    sd_BSIM4cgidl = cgidl+lcgidl*Inv_L+wcgidl*Inv_W+pcgidl*Inv_LW;
    sd_BSIM4egidl = egidl+legidl*Inv_L+wegidl*Inv_W+pegidl*Inv_LW;
    sd_BSIM4rgidl = rgidl+lrgidl*Inv_L+wrgidl*Inv_W+prgidl*Inv_LW;
    sd_BSIM4kgidl = kgidl+lkgidl*Inv_L+wkgidl*Inv_W+pkgidl*Inv_LW;
    sd_BSIM4fgidl = fgidl+lfgidl*Inv_L+wfgidl*Inv_W+pfgidl*Inv_LW;
    sd_BSIM4agisl = BSIM4agisl+BSIM4lagisl*Inv_L+BSIM4wagisl*Inv_W+BSIM4pagisl*Inv_LW;
    sd_BSIM4bgisl = BSIM4bgisl+BSIM4lbgisl*Inv_L+BSIM4wbgisl*Inv_W+BSIM4pbgisl*Inv_LW;
    sd_BSIM4cgisl = BSIM4cgisl+BSIM4lcgisl*Inv_L+BSIM4wcgisl*Inv_W+BSIM4pcgisl*Inv_LW;
    sd_BSIM4egisl = BSIM4egisl+BSIM4legisl*Inv_L+BSIM4wegisl*Inv_W+BSIM4pegisl*Inv_LW;
    sd_BSIM4rgisl = BSIM4rgisl+BSIM4lrgisl*Inv_L+BSIM4wrgisl*Inv_W+BSIM4prgisl*Inv_LW;
    sd_BSIM4kgisl = BSIM4kgisl+BSIM4lkgisl*Inv_L+BSIM4wkgisl*Inv_W+BSIM4pkgisl*Inv_LW;
    sd_BSIM4fgisl = BSIM4fgisl+BSIM4lfgisl*Inv_L+BSIM4wfgisl*Inv_W+BSIM4pfgisl*Inv_LW;
    sd_BSIM4aigc = BSIM4aigc+laigc*Inv_L+waigc*Inv_W+paigc*Inv_LW;
    sd_BSIM4bigc = BSIM4bigc+lbigc*Inv_L+wbigc*Inv_W+pbigc*Inv_LW;
    sd_BSIM4cigc = BSIM4cigc+lcigc*Inv_L+wcigc*Inv_W+pcigc*Inv_LW;
    sd_BSIM4aigsd = BSIM4aigsd+laigsd*Inv_L+waigsd*Inv_W+paigsd*Inv_LW;
    sd_BSIM4bigsd = BSIM4bigsd+lbigsd*Inv_L+wbigsd*Inv_W+pbigsd*Inv_LW;
    sd_BSIM4cigsd = BSIM4cigsd+lcigsd*Inv_L+wcigsd*Inv_W+pcigsd*Inv_LW;
    sd_BSIM4aigs = BSIM4aigs+BSIM4laigs*Inv_L+BSIM4waigs*Inv_W+BSIM4paigs*Inv_LW;
    sd_BSIM4bigs = BSIM4bigs+BSIM4lbigs*Inv_L+BSIM4wbigs*Inv_W+BSIM4pbigs*Inv_LW;
    sd_BSIM4cigs = BSIM4cigs+BSIM4lcigs*Inv_L+BSIM4wcigs*Inv_W+BSIM4pcigs*Inv_LW;
    sd_BSIM4aigd = BSIM4aigd+BSIM4laigd*Inv_L+BSIM4waigd*Inv_W+BSIM4paigd*Inv_LW;
    sd_BSIM4bigd = BSIM4bigd+BSIM4lbigd*Inv_L+BSIM4wbigd*Inv_W+BSIM4pbigd*Inv_LW;
    sd_BSIM4cigd = BSIM4cigd+BSIM4lcigd*Inv_L+BSIM4wcigd*Inv_W+BSIM4pcigd*Inv_LW;
    sd_BSIM4aigbacc = aigbacc+laigbacc*Inv_L+waigbacc*Inv_W+paigbacc*Inv_LW;
    sd_BSIM4bigbacc = bigbacc+lbigbacc*Inv_L+wbigbacc*Inv_W+pbigbacc*Inv_LW;
    sd_BSIM4cigbacc = cigbacc+lcigbacc*Inv_L+wcigbacc*Inv_W+pcigbacc*Inv_LW;
    sd_BSIM4aigbinv = aigbinv+laigbinv*Inv_L+waigbinv*Inv_W+paigbinv*Inv_LW;
    sd_BSIM4bigbinv = bigbinv+lbigbinv*Inv_L+wbigbinv*Inv_W+pbigbinv*Inv_LW;
    sd_BSIM4cigbinv = cigbinv+lcigbinv*Inv_L+wcigbinv*Inv_W+pcigbinv*Inv_LW;
    sd_BSIM4nigc = nigc+lnigc*Inv_L+wnigc*Inv_W+pnigc*Inv_LW;
    sd_BSIM4nigbacc = nigbacc+lnigbacc*Inv_L+wnigbacc*Inv_W+pnigbacc*Inv_LW;
    sd_BSIM4nigbinv = nigbinv+lnigbinv*Inv_L+wnigbinv*Inv_W+pnigbinv*Inv_LW;
    sd_BSIM4ntox = ntox+lntox*Inv_L+wntox*Inv_W+pntox*Inv_LW;
    sd_BSIM4eigbinv = eigbinv+leigbinv*Inv_L+weigbinv*Inv_W+peigbinv*Inv_LW;
    sd_BSIM4pigcd = pigcd+lpigcd*Inv_L+wpigcd*Inv_W+ppigcd*Inv_LW;
    sd_BSIM4poxedge = poxedge+lpoxedge*Inv_L+wpoxedge*Inv_W+ppoxedge*Inv_LW;
    sd_BSIM4xrcrg1 = xrcrg1+lxrcrg1*Inv_L+wxrcrg1*Inv_W+pxrcrg1*Inv_LW;
    sd_BSIM4xrcrg2 = xrcrg2+lxrcrg2*Inv_L+wxrcrg2*Inv_W+pxrcrg2*Inv_LW;
    sd_BSIM4lambda = lambda+llambda*Inv_L+wlambda*Inv_W+plambda*Inv_LW;
    sd_BSIM4vtl = vtl+lvtl*Inv_L+wvtl*Inv_W+pvtl*Inv_LW;
    sd_BSIM4xn = xn+lxn*Inv_L+wxn*Inv_W+pxn*Inv_LW;
    sd_BSIM4vfbsdoff = vfbsdoff+lvfbsdoff*Inv_L+wvfbsdoff*Inv_W+pvfbsdoff*Inv_LW;
    sd_BSIM4tvfbsdoff = tvfbsdoff+ltvfbsdoff*Inv_L+wtvfbsdoff*Inv_W+ptvfbsdoff*Inv_LW;
    sd_BSIM4cgsl = cgsl+lcgsl*Inv_L+wcgsl*Inv_W+pcgsl*Inv_LW;
    sd_BSIM4cgdl = cgdl+lcgdl*Inv_L+wcgdl*Inv_W+pcgdl*Inv_LW;
    sd_BSIM4ckappas = ckappas+lckappas*Inv_L+wckappas*Inv_W+pckappas*Inv_LW;
    sd_BSIM4ckappad = BSIM4ckappad+lckappad*Inv_L+wckappad*Inv_W+pckappad*Inv_LW;
    sd_BSIM4cf = BSIM4cf+lcf*Inv_L+wcf*Inv_W+pcf*Inv_LW;
    sd_BSIM4clc = clc+lclc*Inv_L+wclc*Inv_W+pclc*Inv_LW;
    sd_BSIM4cle = cle+lcle*Inv_L+wcle*Inv_W+pcle*Inv_LW;
    sd_BSIM4vfbcv = BSIM4vfbcv+lvfbcv*Inv_L+wvfbcv*Inv_W+pvfbcv*Inv_LW;
    sd_BSIM4acde = acde+lacde*Inv_L+wacde*Inv_W+pacde*Inv_LW;
    sd_BSIM4moin = moin+lmoin*Inv_L+wmoin*Inv_W+pmoin*Inv_LW;
    sd_BSIM4noff = noff+lnoff*Inv_L+wnoff*Inv_W+pnoff*Inv_LW;
    sd_BSIM4voffcv = voffcv+lvoffcv*Inv_L+wvoffcv*Inv_W+pvoffcv*Inv_LW;
    sd_BSIM4kvth0we = kvth0we+lkvth0we*Inv_L+wkvth0we*Inv_W+pkvth0we*Inv_LW;
    sd_BSIM4k2we = k2we+lk2we*Inv_L+wk2we*Inv_W+pk2we*Inv_LW;
    sd_BSIM4ku0we = ku0we+lku0we*Inv_L+wku0we*Inv_W+pku0we*Inv_LW;
    BSIM4abulkCVfactor = 1.0+pow(sd_BSIM4clc/BSIM4leffCV, sd_BSIM4cle);
    T0 = TRatio-1.0;
    PowWeffWr = pow(BSIM4weffCJ*1.0e6, sd_BSIM4wr)*nf;
    T4 = 0.0;
    T3 = T4;
    T2 = T3;
    T1 = T2;
    sd_BSIM4ucs = sd_BSIM4ucs*pow(TRatio, sd_BSIM4ucste);
    if (BSIM4tempMod==0) begin
      sd_BSIM4ua = sd_BSIM4ua+sd_BSIM4ua1*T0;
      sd_BSIM4ub = sd_BSIM4ub+sd_BSIM4ub1*T0;
      sd_BSIM4uc = sd_BSIM4uc+sd_BSIM4uc1*T0;
      sd_BSIM4ud = sd_BSIM4ud+sd_BSIM4ud1*T0;
      sd_BSIM4vsattemp = sd_BSIM4vsat-sd_BSIM4at*T0;
      T10 = sd_BSIM4prt*T0;
      if (BSIM4rdsMod) begin
        T1 = sd_BSIM4rdw+T10;
        T2 = rdwmin+T10;
        T3 = sd_BSIM4rsw+T10;
        T4 = rswmin+T10;
      end
      BSIM4rds0 = (sd_BSIM4rdsw+T10)*nf/PowWeffWr;
      sd_BSIM4rdswmin = (rdswmin+T10)*nf/PowWeffWr;
    end else begin
      if (BSIM4tempMod==3) begin
        sd_BSIM4ua = sd_BSIM4ua*pow(TRatio, sd_BSIM4ua1);
        sd_BSIM4ub = sd_BSIM4ub*pow(TRatio, sd_BSIM4ub1);
        sd_BSIM4uc = sd_BSIM4uc*pow(TRatio, sd_BSIM4uc1);
        sd_BSIM4ud = sd_BSIM4ud*pow(TRatio, sd_BSIM4ud1);
      end else begin
        sd_BSIM4ua = sd_BSIM4ua*(1.0+sd_BSIM4ua1*delTemp);
        sd_BSIM4ub = sd_BSIM4ub*(1.0+sd_BSIM4ub1*delTemp);
        sd_BSIM4uc = sd_BSIM4uc*(1.0+sd_BSIM4uc1*delTemp);
        sd_BSIM4ud = sd_BSIM4ud*(1.0+sd_BSIM4ud1*delTemp);
      end
      sd_BSIM4vsattemp = sd_BSIM4vsat*(1.0-sd_BSIM4at*delTemp);
      T10 = 1.0+sd_BSIM4prt*delTemp;
      if (BSIM4rdsMod) begin
        T1 = sd_BSIM4rdw*T10;
        T2 = rdwmin*T10;
        T3 = sd_BSIM4rsw*T10;
        T4 = rswmin*T10;
      end
      BSIM4rds0 = sd_BSIM4rdsw*T10*nf/PowWeffWr;
      sd_BSIM4rdswmin = rdswmin*T10*nf/PowWeffWr;
    end
    if (T1<0.0) begin
      T1 = 0.0;
      $warning("Rdw at current temperature is negative; set to 0.");
    end
    if (T2<0.0) begin
      T2 = 0.0;
      $warning("Rdwmin at current temperature is negative; set to 0.");
    end
    BSIM4rd0 = T1/PowWeffWr;
    sd_BSIM4rdwmin = T2/PowWeffWr;
    if (T3<0.0) begin
      T3 = 0.0;
      $warning("Rsw at current temperature is negative; set to 0.");
    end
    if (T4<0.0) begin
      T4 = 0.0;
      $warning("Rswmin at current temperature is negative; set to 0.");
    end
    BSIM4rs0 = T3/PowWeffWr;
    sd_BSIM4rswmin = T4/PowWeffWr;
    if (sd_BSIM4u0>1.0) begin
      sd_BSIM4u0 = sd_BSIM4u0/1.0e4;
    end
    T5 = 1.0-sd_BSIM4up*exp(-BSIM4leff/sd_BSIM4lp);
    sd_BSIM4u0temp = sd_BSIM4u0*T5*pow(TRatio, sd_BSIM4ute);
    if (sd_BSIM4eu<0.0) begin
      sd_BSIM4eu = 0.0;
      $warning("eu has been negative; reset to 0.0.");
    end
    if (sd_BSIM4ucs<0.0) begin
      sd_BSIM4ucs = 0.0;
      $warning("ucs has been negative; reset to 0.0.");
    end
    sd_BSIM4vfbsdoff = sd_BSIM4vfbsdoff*(1.0+sd_BSIM4tvfbsdoff*delTemp);
    sd_BSIM4voff = sd_BSIM4voff*(1.0+sd_BSIM4tvoff*delTemp);
    sd_BSIM4nfactor = sd_BSIM4nfactor+sd_BSIM4tnfactor*delTemp/Tnom;
    sd_BSIM4voffcv = sd_BSIM4voffcv*(1.0+sd_BSIM4tvoffcv*delTemp);
    sd_BSIM4eta0 = sd_BSIM4eta0+sd_BSIM4teta0*delTemp/Tnom;
    if ($param_given(vtl)&&vtl>0.0) begin
      if (lc<0.0) begin
        sd_BSIM4lc = 0.0;
      end else begin
        sd_BSIM4lc = lc;
      end
      T0 = BSIM4leff/(sd_BSIM4xn*BSIM4leff+sd_BSIM4lc);
      BSIM4tfactor = (1.0-T0)/(1.0+T0);
    end
    sd_BSIM4cgdo = (BSIM4cgdo+sd_BSIM4cf)*BSIM4weffCV;
    sd_BSIM4cgso = (BSIM4cgso+sd_BSIM4cf)*BSIM4weffCV;
    sd_BSIM4cgbo = BSIM4cgbo*BSIM4leffCV*nf;
    if (!$param_given(ndep)&&$param_given(gamma1)) begin
      T0 = sd_BSIM4gamma1*BSIM4coxe;
      sd_BSIM4ndep = 3.01248e22*T0*T0;
    end
    BSIM4phi = Vtm0*ln(sd_BSIM4ndep/ni)+sd_BSIM4phin+0.4;
    if (BSIM4phi<=0.0) begin
      $warning("Fatal: Phi = %g is not positive. Please check Phin and Ndep", BSIM4phi);
      $warning("       Phin = %g  Ndep = %g ", sd_BSIM4phin, sd_BSIM4ndep);
      Fatal_Flag = 1;
    end
    BSIM4sqrtPhi = sqrt(BSIM4phi);
    BSIM4phis3 = BSIM4sqrtPhi*BSIM4phi;
    BSIM4Xdep0 = sqrt(2.0*epssub/(1.60219e-19*sd_BSIM4ndep*1.0e6))*BSIM4sqrtPhi;
    BSIM4sqrtXdep0 = sqrt(BSIM4Xdep0);
    if (BSIM4mtrlMod==0) begin
      BSIM4litl = sqrt(3.0*3.9/temp_epsrox*sd_BSIM4xj*temp_toxe);
    end else begin
      BSIM4litl = sqrt(epsrsub/temp_epsrox*sd_BSIM4xj*temp_toxe);
    end
    BSIM4vbi = Vtm0*ln(sd_BSIM4nsd*sd_BSIM4ndep/(ni*ni));
    if (BSIM4mtrlMod==0) begin
      if (sd_BSIM4ngate>0.0) begin
        BSIM4vfbsd = Vtm0*ln(sd_BSIM4ngate/sd_BSIM4nsd);
      end else begin
        BSIM4vfbsd = 0.0;
      end
    end else begin
      T0 = Vtm0*ln(sd_BSIM4nsd/ni);
      T1 = 0.5*Eg0;
      if (T0>T1) begin
        T0 = T1;
      end
      T2 = easub+T1-BSIM4type*T0;
      BSIM4vfbsd = phig-T2;
    end
    BSIM4cdep0 = sqrt(1.60219e-19*epssub*sd_BSIM4ndep*1.0e6/2.0/BSIM4phi);
    BSIM4ToxRatio = exp(sd_BSIM4ntox*ln(toxref/temp_toxe))/temp_toxe/temp_toxe;
    BSIM4ToxRatioEdge = exp(sd_BSIM4ntox*ln(toxref/(temp_toxe*sd_BSIM4poxedge)))/temp_toxe/temp_toxe/sd_BSIM4poxedge/sd_BSIM4poxedge;
    BSIM4Aechvb = ((BSIM4type==1) ? (4.97232e-7) : (3.42537e-7));
    BSIM4Bechvb = ((BSIM4type==1) ? (7.45669e11) : (1.16645e12));
    if (BSIM4v48intVersion<=480) begin
      BSIM4AechvbEdgeS = BSIM4Aechvb*BSIM4weff*BSIM4dlcig*BSIM4ToxRatioEdge;
      BSIM4AechvbEdgeD = BSIM4Aechvb*BSIM4weff*BSIM4dlcigd*BSIM4ToxRatioEdge;
    end else begin
      if (BSIM4dlcig<0.0) begin
        $warning("dlcig = %g is negative. Set to zero.", BSIM4dlcig);
        BSIM4dlcig = 0.0;
      end
      BSIM4AechvbEdgeS = BSIM4Aechvb*BSIM4weff*BSIM4dlcig*BSIM4ToxRatioEdge;
      if (BSIM4dlcigd<0.0) begin
        $warning("dlcigd = %g is negative. Set to zero.", BSIM4dlcigd);
        BSIM4dlcigd = 0.0;
      end
      BSIM4AechvbEdgeD = BSIM4Aechvb*BSIM4weff*BSIM4dlcigd*BSIM4ToxRatioEdge;
    end
    BSIM4BechvbEdge = -BSIM4Bechvb*temp_toxe*sd_BSIM4poxedge;
    BSIM4Aechvb = BSIM4Aechvb * (BSIM4weff*BSIM4leff*BSIM4ToxRatio);
    BSIM4Bechvb = BSIM4Bechvb * (-temp_toxe);
    BSIM4mstar = 0.5+atan(sd_BSIM4minv)/3.141592654;
    BSIM4mstarcv = 0.5+atan(sd_BSIM4minvcv)/3.141592654;
    BSIM4voffcbn = sd_BSIM4voff+voffl/BSIM4leff;
    BSIM4voffcbncv = sd_BSIM4voffcv+voffcvl/BSIM4leff;
    BSIM4ldeb = sqrt(epssub*Vtm0/(1.60219e-19*sd_BSIM4ndep*1.0e6))/3.0;
    sd_BSIM4acde = sd_BSIM4acde * (pow(sd_BSIM4ndep/2.0e16, -0.25));
    if ($param_given(k1)||$param_given(k2)) begin
      if (!$param_given(k1)) begin
        $warning("k1 should be specified with k2.");
        sd_BSIM4k1 = 0.53;
      end
      if (!$param_given(k2)) begin
        $warning("k2 should be specified with k1.");
        sd_BSIM4k2 = -0.0186;
      end
      if ($param_given(nsub)) begin
        $warning("nsub is ignored because k1 or k2 is given.");
      end
      if ($param_given(xt)) begin
        $warning("xt is ignored because k1 or k2 is given.");
      end
      if ($param_given(vbx)) begin
        $warning("vbx is ignored because k1 or k2 is given.");
      end
      if ($param_given(gamma1)) begin
        $warning("gamma1 is ignored because k1 or k2 is given.");
      end
      if ($param_given(gamma2)) begin
        $warning("gamma2 is ignored because k1 or k2 is given.");
      end
    end else begin
      if (!$param_given(vbx)) begin
        sd_BSIM4vbx = BSIM4phi-7.7348e-4*sd_BSIM4ndep*sd_BSIM4xt*sd_BSIM4xt;
      end
      if (sd_BSIM4vbx>0.0) begin
        sd_BSIM4vbx = -sd_BSIM4vbx;
      end
      if (sd_BSIM4vbm>0.0) begin
        sd_BSIM4vbm = -sd_BSIM4vbm;
      end
      if (!$param_given(gamma1)) begin
        sd_BSIM4gamma1 = 5.753e-12*sqrt(sd_BSIM4ndep)/BSIM4coxe;
      end
      if (!$param_given(gamma2)) begin
        sd_BSIM4gamma2 = 5.753e-12*sqrt(sd_BSIM4nsub)/BSIM4coxe;
      end
      T0 = sd_BSIM4gamma1-sd_BSIM4gamma2;
      T1 = sqrt(BSIM4phi-sd_BSIM4vbx)-BSIM4sqrtPhi;
      T2 = sqrt(BSIM4phi*(BSIM4phi-sd_BSIM4vbm))-BSIM4phi;
      sd_BSIM4k2 = T0*T1/(2.0*T2+sd_BSIM4vbm);
      sd_BSIM4k1 = sd_BSIM4gamma2-2.0*sd_BSIM4k2*sqrt(BSIM4phi-sd_BSIM4vbm);
    end
    if (!$param_given(vfb)) begin
      if ($param_given(vth0)) begin
        sd_BSIM4vfb = BSIM4type*sd_BSIM4vth0-BSIM4phi-sd_BSIM4k1*BSIM4sqrtPhi;
      end else if (BSIM4mtrlMod&&$param_given(phig)&&$param_given(nsub)) begin
        T0 = Vtm0*ln(sd_BSIM4nsub/ni);
        T1 = 0.5*Eg0;
        if (T0>T1) begin
          T0 = T1;
        end
        T2 = easub+T1+BSIM4type*T0;
        sd_BSIM4vfb = phig-T2;
      end else begin
        sd_BSIM4vfb = -1.0;
      end
    end
    if (!$param_given(vth0)) begin
      sd_BSIM4vth0 = BSIM4type*(sd_BSIM4vfb+BSIM4phi+sd_BSIM4k1*BSIM4sqrtPhi);
    end
    BSIM4k1ox = sd_BSIM4k1*temp_toxe/BSIM4toxm;
    tmp = sqrt(epssub/(temp_epsrox*8.85418e-12)*temp_toxe*BSIM4Xdep0);
    T0 = sd_BSIM4dsub*BSIM4leff/tmp;
    if (T0<34.0) begin
      T1 = exp(T0);
      T2 = T1-1.0;
      T3 = T2*T2;
      T4 = T3+2.0*T1*1.713908431e-15;
      BSIM4theta0vb0 = T1/T4;
    end else begin
      BSIM4theta0vb0 = 1.0/(5.834617425e14-2.0);
    end
    T0 = sd_BSIM4drout*BSIM4leff/tmp;
    if (T0<34.0) begin
      T1 = exp(T0);
      T2 = T1-1.0;
      T3 = T2*T2;
      T4 = T3+2.0*T1*1.713908431e-15;
      T5 = T1/T4;
    end else begin
      T5 = 1.0/(5.834617425e14-2.0);
    end
    BSIM4thetaRout = sd_BSIM4pdibl1*T5+sd_BSIM4pdibl2;
    tmp = sqrt(BSIM4Xdep0);
    tmp1 = BSIM4vbi-BSIM4phi;
    tmp2 = BSIM4factor1*tmp;
    T0 = sd_BSIM4dvt1w*BSIM4weff*BSIM4leff/tmp2;
    if (T0<34.0) begin
      T1 = exp(T0);
      T2 = T1-1.0;
      T3 = T2*T2;
      T4 = T3+2.0*T1*1.713908431e-15;
      T8 = T1/T4;
    end else begin
      T8 = 1.0/(5.834617425e14-2.0);
    end
    T0 = sd_BSIM4dvt0w*T8;
    T8 = T0*tmp1;
    T0 = sd_BSIM4dvt1*BSIM4leff/tmp2;
    if (T0<34.0) begin
      T1 = exp(T0);
      T2 = T1-1.0;
      T3 = T2*T2;
      T4 = T3+2.0*T1*1.713908431e-15;
      T9 = T1/T4;
    end else begin
      T9 = 1.0/(5.834617425e14-2.0);
    end
    T9 = sd_BSIM4dvt0*T9*tmp1;
    T4 = temp_toxe*BSIM4phi/(BSIM4weff+sd_BSIM4w0);
    T0 = sqrt(1.0+sd_BSIM4lpe0/BSIM4leff);
    if (BSIM4tempMod==1||BSIM4tempMod==0) begin
      T3 = (sd_BSIM4kt1+sd_BSIM4kt1l/BSIM4leff)*(TRatio-1.0);
    end
    if (BSIM4tempMod==2||BSIM4tempMod==3) begin
      T3 = -sd_BSIM4kt1*(TRatio-1.0);
    end
    T5 = BSIM4k1ox*(T0-1.0)*BSIM4sqrtPhi+T3;
    BSIM4vfbzbfactor = -T8-T9+sd_BSIM4k3*T4+T5-BSIM4phi-sd_BSIM4k1*BSIM4sqrtPhi;
    temp_wlod = wlod;
    if (wlod<0.0) begin
      $warning("WLOD = %g is less than 0. 0.0 is used", wlod);
      temp_wlod = 0.0;
    end
    T0 = pow(Lnew, llodku0);
    W_tmp = Wnew+temp_wlod;
    T1 = pow(W_tmp, wlodku0);
    tmp1 = lku0/T0+wku0/T1+pku0/(T0*T1);
    sd_BSIM4ku0 = 1.0+tmp1;
    T0 = pow(Lnew, llodvth);
    T1 = pow(W_tmp, wlodvth);
    tmp1 = lkvth0/T0+wkvth0/T1+pkvth0/(T0*T1);
    sd_BSIM4kvth0 = 1.0+tmp1;
    sd_BSIM4kvth0 = sqrt(sd_BSIM4kvth0*sd_BSIM4kvth0+1.0E-9);
    T0 = TRatio-1.0;
    BSIM4ku0temp = sd_BSIM4ku0*(1.0+tku0*T0)+1.0E-9;
    Inv_saref = 1.0/(saref+0.5*Ldrn);
    Inv_sbref = 1.0/(sbref+0.5*Ldrn);
    BSIM4inv_od_ref = Inv_saref+Inv_sbref;
    BSIM4rho_ref = ku0/BSIM4ku0temp*BSIM4inv_od_ref;
    if (BSIM4mobMod==3) begin
      lt1 = BSIM4factor1*BSIM4sqrtXdep0;
      T0 = sd_BSIM4dvt1*BSIM4leff/lt1;
      if (T0<34.0) begin
        T1 = exp(T0);
        T2 = T1-1.0;
        T3 = T2*T2;
        T4 = T3+2.0*T1*1.713908431e-15;
        Theta0 = T1/T4;
      end else begin
        Theta0 = 1.0/(5.834617425e14-2.0);
      end
      tmp1 = epssub/BSIM4Xdep0;
      tmp2 = sd_BSIM4nfactor*tmp1;
      tmp3 = (tmp2+sd_BSIM4cdsc*Theta0+sd_BSIM4cit)/BSIM4coxe;
      if (tmp3>=-0.5) begin
        n0 = 1.0+tmp3;
      end else begin
        T0 = 1.0/(3.0+8.0*tmp3);
        n0 = (1.0+3.0*tmp3)*T0;
      end
      T0 = n0*BSIM4vtm;
      T1 = BSIM4voffcbn;
      T2 = T1/T0;
      if (T2<-34.0) begin
        T3 = BSIM4coxe*1.713908431e-15/BSIM4cdep0;
        T4 = BSIM4mstar+T3*n0;
      end else if (T2>34.0) begin
        T3 = BSIM4coxe*5.834617425e14/BSIM4cdep0;
        T4 = BSIM4mstar+T3*n0;
      end else begin
        T3 = exp(T2)*BSIM4coxe/BSIM4cdep0;
        T4 = BSIM4mstar+T3*n0;
      end
      BSIM4VgsteffVth = T0*ln(2.0)/T4;
    end
    T0 = -sd_BSIM4dvtp3*ln(BSIM4leff);
    if (T0>34.0) begin
      T1 = 5.834617425e14*(1.0+T0-34.0);
    end else if (T0<-34.0) begin
      T1 = 1.713908431e-15;
    end else begin
      T1 = exp(T0);
    end
    BSIM4dvtp2factor = sd_BSIM4dvtp5+sd_BSIM4dvtp2*T1;
    if (sa>0.0&&sb>0.0&&(nf==1.0||nf>1.0&&BSIM4sd>0.0)) begin
      Inv_sa = 0;
      Inv_sb = 0;
      temp_kvsat = kvsat;
      if (kvsat<-1.0) begin
        $warning("KVSAT = %g is too small; -1.0 is used.", kvsat);
        temp_kvsat = -1.0;
      end
      if (kvsat>1.0) begin
        $warning("KVSAT = %g is too big; 1.0 is used.", kvsat);
        temp_kvsat = 1.0;
      end
      for(i = 0; i<nf; i = i+1) begin
        T0 = 1.0/nf/(sa+0.5*Ldrn+i*(BSIM4sd+Ldrn));
        T1 = 1.0/nf/(sb+0.5*Ldrn+i*(BSIM4sd+Ldrn));
        Inv_sa = Inv_sa + (T0);
        Inv_sb = Inv_sb + (T1);
      end
      Inv_ODeff = Inv_sa+Inv_sb;
      rho = ku0/BSIM4ku0temp*Inv_ODeff;
      T0 = (1.0+rho)/(1.0+BSIM4rho_ref);
      BSIM4u0temp = sd_BSIM4u0temp*T0;
      T1 = (1.0+temp_kvsat*rho)/(1.0+temp_kvsat*BSIM4rho_ref);
      BSIM4vsattemp = sd_BSIM4vsattemp*T1;
      OD_offset = Inv_ODeff-BSIM4inv_od_ref;
      dvth0_lod = kvth0/sd_BSIM4kvth0*OD_offset;
      dk2_lod = stk2/pow(sd_BSIM4kvth0, lodk2)*OD_offset;
      deta0_lod = steta0/pow(sd_BSIM4kvth0, lodeta0)*OD_offset;
      i_BSIM4vth0 = sd_BSIM4vth0+dvth0_lod;
      i_BSIM4eta0 = sd_BSIM4eta0+deta0_lod;
      i_BSIM4k2 = sd_BSIM4k2+dk2_lod;
    end else begin
      BSIM4u0temp = sd_BSIM4u0temp;
      i_BSIM4vth0 = sd_BSIM4vth0;
      BSIM4vsattemp = sd_BSIM4vsattemp;
      i_BSIM4eta0 = sd_BSIM4eta0;
      i_BSIM4k2 = sd_BSIM4k2;
    end
    if (BSIM4wpemod) begin
      if (!$param_given(sca)&&!$param_given(scb)&&!$param_given(scc)) begin
        if ($param_given(sc)&&BSIM4sc>0.0) begin
          T1 = BSIM4sc+Wdrn;
          T2 = 1.0/scref;
          BSIM4sca = scref*scref/(BSIM4sc*T1);
          BSIM4scb = ((0.1*BSIM4sc+0.01*scref)*exp(-10.0*BSIM4sc*T2)-(0.1*T1+0.01*scref)*exp(-10.0*T1*T2))/Wdrn;
          BSIM4scc = ((0.05*BSIM4sc+0.0025*scref)*exp(-20.0*BSIM4sc*T2)-(0.05*T1+0.0025*scref)*exp(-20.0*T1*T2))/Wdrn;
        end else begin
          $warning("No WPE as none of SCA, SCB, SCC, SC is given and/or SC not positive.");
        end
      end
      if (BSIM4sca<0.0) begin
        $warning("SCA = %g is negative. Set to 0.0.", BSIM4sca);
        BSIM4sca = 0.0;
      end
      if (BSIM4scb<0.0) begin
        $warning("SCB = %g is negative. Set to 0.0.", BSIM4scb);
        BSIM4scb = 0.0;
      end
      if (BSIM4scc<0.0) begin
        $warning("SCC = %g is negative. Set to 0.0.", BSIM4scc);
        BSIM4scc = 0.0;
      end
      if (BSIM4sc<0.0) begin
        $warning("SC = %g is negative. Set to 0.0.", BSIM4sc);
        BSIM4sc = 0.0;
      end
      sceff = BSIM4sca+web*BSIM4scb+wec*BSIM4scc;
      i_BSIM4vth0 = i_BSIM4vth0 + (sd_BSIM4kvth0we*sceff);
      i_BSIM4k2 = i_BSIM4k2 + (sd_BSIM4k2we*sceff);
      T3 = 1.0+sd_BSIM4ku0we*sceff;
      if (T3<=0.0) begin
        T3 = 0.0;
        $warning("ku0we = %g is negatively too high. Negative mobility! ", sd_BSIM4ku0we);
      end
      BSIM4u0temp = BSIM4u0temp * (T3);
    end
    i_BSIM4vth0 = i_BSIM4vth0 + (delvto);
    i_BSIM4vfb = sd_BSIM4vfb+BSIM4type*delvto;
    BSIM4u0temp = sd_BSIM4u0temp*mulu0;
    T3 = BSIM4type*i_BSIM4vth0-i_BSIM4vfb-BSIM4phi;
    T4 = T3+T3;
    T5 = 2.5*T3;
    BSIM4vtfbphi1 = ((BSIM4type==1) ? (T4) : (T5));
    if (BSIM4vtfbphi1<0.0) begin
      BSIM4vtfbphi1 = 0.0;
    end
    BSIM4vtfbphi2 = 4.0*T3;
    if (BSIM4vtfbphi2<0.0) begin
      BSIM4vtfbphi2 = 0.0;
    end
    if (i_BSIM4k2<0.0) begin
      T0 = 0.5*sd_BSIM4k1/i_BSIM4k2;
      BSIM4vbsc = 0.9*(BSIM4phi-T0*T0);
      if (BSIM4vbsc>-3.0) begin
        BSIM4vbsc = -3.0;
      end else if (BSIM4vbsc<-30.0) begin
        BSIM4vbsc = -30.0;
      end
    end else begin
      BSIM4vbsc = -30.0;
    end
    if (BSIM4vbsc>sd_BSIM4vbm) begin
      BSIM4vbsc = sd_BSIM4vbm;
    end
    BSIM4k2ox = i_BSIM4k2*temp_toxe/BSIM4toxm;
    BSIM4vfbzb = BSIM4vfbzbfactor+BSIM4type*i_BSIM4vth0;
    i_BSIM4cgso = sd_BSIM4cgso;
    i_BSIM4cgdo = sd_BSIM4cgdo;
    lnl = ln(BSIM4leff*1.0e6);
    lnw = ln(BSIM4weff*1.0e6);
    lnnf = ln(nf);
    bodymode = 5;
    if (!$param_given(rbps0)||!$param_given(rbpd0)) begin
      bodymode = 1;
    end else if (!$param_given(rbsbx0)&&!$param_given(rbsby0)||!$param_given(rbdbx0)&&!$param_given(rbdby0)) begin
      bodymode = 3;
    end
    if (i_BSIM4rbodyMod==2) begin
      if (bodymode==5) begin
        rbsbx = rbsbx0*exp(rbsdbxl*lnl+rbsdbxw*lnw+rbsdbxnf*lnnf);
        rbsby = rbsby0*exp(rbsdbyl*lnl+rbsdbyw*lnw+rbsdbynf*lnnf);
        i_BSIM4rbsb = rbsbx*rbsby/(rbsbx+rbsby);
        rbdbx = rbdbx0*exp(rbsdbxl*lnl+rbsdbxw*lnw+rbsdbxnf*lnnf);
        rbdby = rbdby0*exp(rbsdbyl*lnl+rbsdbyw*lnw+rbsdbynf*lnnf);
        i_BSIM4rbdb = rbdbx*rbdby/(rbdbx+rbdby);
      end
      if (bodymode==3||bodymode==5) begin
        i_BSIM4rbps = rbps0*exp(rbpsl*lnl+rbpsw*lnw+rbpsnf*lnnf);
        i_BSIM4rbpd = rbpd0*exp(rbpdl*lnl+rbpdw*lnw+rbpdnf*lnnf);
      end
      rbpbx = rbpbx0*exp(rbpbxl*lnl+rbpbxw*lnw+rbpbxnf*lnnf);
      rbpby = rbpby0*exp(rbpbyl*lnl+rbpbyw*lnw+rbpbynf*lnnf);
      i_BSIM4rbpb = rbpbx*rbpby/(rbpbx+rbpby);
    end
    if (i_BSIM4rbodyMod==1||i_BSIM4rbodyMod==2&&bodymode==5) begin
      if (i_BSIM4rbdb<1.0e-3) begin
        BSIM4grbdb = 1.0e3;
      end else begin
        BSIM4grbdb = gbmin+1.0/i_BSIM4rbdb;
      end
      if (i_BSIM4rbpb<1.0e-3) begin
        BSIM4grbpb = 1.0e3;
      end else begin
        BSIM4grbpb = gbmin+1.0/i_BSIM4rbpb;
      end
      if (i_BSIM4rbps<1.0e-3) begin
        BSIM4grbps = 1.0e3;
      end else begin
        BSIM4grbps = gbmin+1.0/i_BSIM4rbps;
      end
      if (i_BSIM4rbsb<1.0e-3) begin
        BSIM4grbsb = 1.0e3;
      end else begin
        BSIM4grbsb = gbmin+1.0/i_BSIM4rbsb;
      end
      if (i_BSIM4rbpd<1.0e-3) begin
        BSIM4grbpd = 1.0e3;
      end else begin
        BSIM4grbpd = gbmin+1.0/i_BSIM4rbpd;
      end
    end
    if (i_BSIM4rbodyMod==2&&bodymode==3) begin
      BSIM4grbsb = gbmin;
      BSIM4grbdb = BSIM4grbsb;
      if (i_BSIM4rbpb<1.0e-3) begin
        BSIM4grbpb = 1.0e3;
      end else begin
        BSIM4grbpb = gbmin+1.0/i_BSIM4rbpb;
      end
      if (i_BSIM4rbps<1.0e-3) begin
        BSIM4grbps = 1.0e3;
      end else begin
        BSIM4grbps = gbmin+1.0/i_BSIM4rbps;
      end
      if (i_BSIM4rbpd<1.0e-3) begin
        BSIM4grbpd = 1.0e3;
      end else begin
        BSIM4grbpd = gbmin+1.0/i_BSIM4rbpd;
      end
    end
    if (i_BSIM4rbodyMod==2&&bodymode==1) begin
      BSIM4grbsb = gbmin;
      BSIM4grbdb = BSIM4grbsb;
      BSIM4grbpd = 1.0e3;
      BSIM4grbps = BSIM4grbpd;
      if (i_BSIM4rbpb<1.0e-3) begin
        BSIM4grbpb = 1.0e3;
      end else begin
        BSIM4grbpb = gbmin+1.0/i_BSIM4rbpb;
      end
    end
    BSIM4grgeltd = rshg*(i_BSIM4xgw+BSIM4weffCJ/3.0/i_BSIM4ngcon)/(i_BSIM4ngcon*nf*(Lnew-xgl));
    if (BSIM4grgeltd>0.0) begin
      BSIM4grgeltd = 1.0/BSIM4grgeltd;
    end else begin
      BSIM4grgeltd = 1.0e3;
      if (i_BSIM4rgateMod!=0) begin
        $warning("The gate conductance reset to 1.0e3 mho.");
      end
    end
    temp_DMCGeff = dmcg-dmcgt;
    temp_DMCIeff = BSIM4dmci;
    temp_DMDGeff = dmdg-dmcgt;
    if (BSIM4sourcePerimeterGiven) begin
      if (BSIM4sourcePerimeter==0.0) begin
        BSIM4Pseff = 0.0;
      end else if (BSIM4sourcePerimeter<0.0) begin
        $warning("Source Perimeter is specified as negative, it is set to zero.");
        BSIM4Pseff = 0.0;
      end else if (BSIM4perMod==0) begin
        BSIM4Pseff = BSIM4sourcePerimeter;
      end else begin
        BSIM4Pseff = BSIM4sourcePerimeter-BSIM4weffCJ*nf;
      end
    end else begin
      BSIM4PAeffGeo(nf, i_BSIM4geoMod, instance_min, BSIM4weffCJ, temp_DMCGeff, temp_DMCIeff, temp_DMDGeff, BSIM4Pseff, dumPd, dumAs, dumAd);
    end
    if (BSIM4Pseff<0.0) begin
      BSIM4Pseff = 0.0;
      $warning("Pseff is negative, it is set to zero.");
    end
    if (BSIM4drainPerimeterGiven) begin
      if (BSIM4drainPerimeter==0.0) begin
        BSIM4Pdeff = 0.0;
      end else if (BSIM4drainPerimeter<0.0) begin
        $warning("Drain Perimeter is specified as negative, it is set to zero.");
        BSIM4Pdeff = 0.0;
      end else if (BSIM4perMod==0) begin
        BSIM4Pdeff = BSIM4drainPerimeter;
      end else begin
        BSIM4Pdeff = BSIM4drainPerimeter-BSIM4weffCJ*nf;
      end
    end else begin
      BSIM4PAeffGeo(nf, i_BSIM4geoMod, instance_min, BSIM4weffCJ, temp_DMCGeff, temp_DMCIeff, temp_DMDGeff, dumPs, BSIM4Pdeff, dumAs, dumAd);
    end
    if (BSIM4Pdeff<0.0) begin
      BSIM4Pdeff = 0.0;
      $warning("Pdeff is negative, it is set to zero.");
    end
    if (BSIM4sourceAreaGiven) begin
      BSIM4Aseff = BSIM4sourceArea;
    end else begin
      BSIM4PAeffGeo(nf, i_BSIM4geoMod, instance_min, BSIM4weffCJ, temp_DMCGeff, temp_DMCIeff, temp_DMDGeff, dumPs, dumPd, BSIM4Aseff, dumAd);
    end
    if (BSIM4Aseff<0.0) begin
      BSIM4Aseff = 0.0;
      $warning("Aseff is negative, it is set to zero.");
    end
    if (BSIM4drainAreaGiven) begin
      BSIM4Adeff = BSIM4drainArea;
    end else begin
      BSIM4PAeffGeo(nf, i_BSIM4geoMod, instance_min, BSIM4weffCJ, temp_DMCGeff, temp_DMCIeff, temp_DMDGeff, dumPs, dumPd, dumAs, BSIM4Adeff);
    end
    if (BSIM4Adeff<0.0) begin
      BSIM4Adeff = 0.0;
      $warning("Adeff is negative, it is set to zero.");
    end
    if (createnode_s) begin
      BSIM4sourceConductance = 0.0;
      if ($param_given(nrs)) begin
        BSIM4sourceConductance = rsh*nrs;
      end else if (instance_rgeomod>0) begin
        BSIM4RdseffGeo(nf, i_BSIM4geoMod, instance_rgeomod, instance_min, BSIM4weffCJ, rsh, temp_DMCGeff, temp_DMCIeff, temp_DMDGeff, 1, BSIM4sourceConductance);
      end else begin
        BSIM4sourceConductance = 0.0;
      end
      if (BSIM4sourceConductance>0.0) begin
        BSIM4sourceConductance = 1.0/BSIM4sourceConductance;
      end else begin
        BSIM4sourceConductance = 1.0e3;
        $warning("Source conductance reset to 1.0e3 mho.");
      end
    end else begin
      BSIM4sourceConductance = 0.0;
    end
    if (createnode_d) begin
      BSIM4drainConductance = 0.0;
      if ($param_given(nrd)) begin
        BSIM4drainConductance = rsh*nrd;
      end else if (instance_rgeomod>0) begin
        BSIM4RdseffGeo(nf, i_BSIM4geoMod, instance_rgeomod, instance_min, BSIM4weffCJ, rsh, temp_DMCGeff, temp_DMCIeff, temp_DMDGeff, 0, BSIM4drainConductance);
      end else begin
        BSIM4drainConductance = 0.0;
      end
      if (BSIM4drainConductance>0.0) begin
        BSIM4drainConductance = 1.0/BSIM4drainConductance;
      end else begin
        BSIM4drainConductance = 1.0e3;
        $warning("Drain conductance reset to 1.0e3 mho.");
      end
    end else begin
      BSIM4drainConductance = 0.0;
    end
    Nvtms = BSIM4vtm*njs;
    if (BSIM4Aseff<=0.0&&BSIM4Pseff<=0.0) begin
      SourceSatCurrent = 0.0;
    end else begin
      SourceSatCurrent = BSIM4Aseff*BSIM4SjctTempSatCurDensity+BSIM4Pseff*BSIM4SjctSidewallTempSatCurDensity+BSIM4weffCJ*nf*BSIM4SjctGateSidewallTempSatCurDensity;
    end
    if (SourceSatCurrent>0.0) begin
      case (BSIM4dioMod)
        0: begin
          if (BSIM4bvs/Nvtms>34.0) begin
            BSIM4XExpBVS = BSIM4xjbvs*1.713908431e-15;
          end else begin
            BSIM4XExpBVS = BSIM4xjbvs*exp(-BSIM4bvs/Nvtms);
          end
        end
        1: begin
          BSIM4DioIjthVjmEval(Nvtms, BSIM4ijthsfwd, SourceSatCurrent, 0.0, BSIM4vjsmFwd);
          BSIM4IVjsmFwd = SourceSatCurrent*exp(BSIM4vjsmFwd/Nvtms);
        end
        2: begin
          if (BSIM4bvs/Nvtms>34.0) begin
            BSIM4XExpBVS = BSIM4xjbvs*1.713908431e-15;
            tmp = 1.713908431e-15;
          end else begin
            BSIM4XExpBVS = exp(-BSIM4bvs/Nvtms);
            tmp = BSIM4XExpBVS;
            BSIM4XExpBVS = BSIM4XExpBVS * (BSIM4xjbvs);
          end
          BSIM4DioIjthVjmEval(Nvtms, BSIM4ijthsfwd, SourceSatCurrent, BSIM4XExpBVS, BSIM4vjsmFwd);
          T0 = exp(BSIM4vjsmFwd/Nvtms);
          BSIM4IVjsmFwd = SourceSatCurrent*(T0-BSIM4XExpBVS/T0+BSIM4XExpBVS-1.0);
          BSIM4SslpFwd = SourceSatCurrent*(T0+BSIM4XExpBVS/T0)/Nvtms;
          T2 = BSIM4ijthsrev/SourceSatCurrent;
          if (T2<1.0) begin
            T2 = 10.0;
            $warning("ijthsrev too small and set to 10 times IsbSat.");
          end
          BSIM4vjsmRev = -BSIM4bvs-Nvtms*ln((T2-1.0)/BSIM4xjbvs);
          T1 = BSIM4xjbvs*exp(-(BSIM4bvs+BSIM4vjsmRev)/Nvtms);
          BSIM4IVjsmRev = SourceSatCurrent*(1.0+T1);
          BSIM4SslpRev = -SourceSatCurrent*T1/Nvtms;
        end
        default: begin
          $warning("Specified dioMod = %d not matched", BSIM4dioMod);
        end
      endcase

    end
    Nvtmd = BSIM4vtm*BSIM4DjctEmissionCoeff;
    if (BSIM4Adeff<=0.0&&BSIM4Pdeff<=0.0) begin
      DrainSatCurrent = 0.0;
    end else begin
      DrainSatCurrent = BSIM4Adeff*BSIM4DjctTempSatCurDensity+BSIM4Pdeff*BSIM4DjctSidewallTempSatCurDensity+BSIM4weffCJ*nf*BSIM4DjctGateSidewallTempSatCurDensity;
    end
    if (DrainSatCurrent>0.0) begin
      case (BSIM4dioMod)
        0: begin
          if (BSIM4bvd/Nvtmd>34.0) begin
            BSIM4XExpBVD = BSIM4xjbvd*1.713908431e-15;
          end else begin
            BSIM4XExpBVD = BSIM4xjbvd*exp(-BSIM4bvd/Nvtmd);
          end
        end
        1: begin
          BSIM4DioIjthVjmEval(Nvtmd, BSIM4ijthdfwd, DrainSatCurrent, 0.0, BSIM4vjdmFwd);
          BSIM4IVjdmFwd = DrainSatCurrent*exp(BSIM4vjdmFwd/Nvtmd);
        end
        2: begin
          if (BSIM4bvd/Nvtmd>34.0) begin
            BSIM4XExpBVD = BSIM4xjbvd*1.713908431e-15;
            tmp = 1.713908431e-15;
          end else begin
            BSIM4XExpBVD = exp(-BSIM4bvd/Nvtmd);
            tmp = BSIM4XExpBVD;
            BSIM4XExpBVD = BSIM4XExpBVD * (BSIM4xjbvd);
          end
          BSIM4DioIjthVjmEval(Nvtmd, BSIM4ijthdfwd, DrainSatCurrent, BSIM4XExpBVD, BSIM4vjdmFwd);
          T0 = exp(BSIM4vjdmFwd/Nvtmd);
          BSIM4IVjdmFwd = DrainSatCurrent*(T0-BSIM4XExpBVD/T0+BSIM4XExpBVD-1.0);
          BSIM4DslpFwd = DrainSatCurrent*(T0+BSIM4XExpBVD/T0)/Nvtmd;
          T2 = BSIM4ijthdrev/DrainSatCurrent;
          if (T2<1.0) begin
            T2 = 10.0;
            $warning("ijthdrev too small and set to 10 times IdbSat.");
          end
          BSIM4vjdmRev = -BSIM4bvd-Nvtmd*ln((T2-1.0)/BSIM4xjbvd);
          T1 = BSIM4xjbvd*exp(-(BSIM4bvd+BSIM4vjdmRev)/Nvtmd);
          BSIM4IVjdmRev = DrainSatCurrent*(1.0+T1);
          BSIM4DslpRev = -DrainSatCurrent*T1/Nvtmd;
        end
        default: begin
          $warning("Specified dioMod = %d not matched", BSIM4dioMod);
        end
      endcase

    end
    T0 = TRatio-1.0;
    BSIM4njtsstemp = njts*(1.0+tnjts*T0);
    BSIM4njtsswstemp = njtssw*(1.0+tnjtssw*T0);
    BSIM4njtsswgstemp = njtsswg*(1.0+tnjtsswg*T0);
    BSIM4njtsdtemp = BSIM4njtsd*(1.0+BSIM4tnjtsd*T0);
    BSIM4njtsswdtemp = BSIM4njtsswd*(1.0+BSIM4tnjtsswd*T0);
    BSIM4njtsswgdtemp = BSIM4njtsswgd*(1.0+BSIM4tnjtsswgd*T0);
    T7 = Eg0/BSIM4vtm*T0;
    T9 = xtss*T7;
    if (T9>34.0) begin
      T1 = 5.834617425e14*(1.0+T9-34.0);
    end else if (T9<-34.0) begin
      T1 = 1.713908431e-15;
    end else begin
      T1 = exp(T9);
    end
    T9 = BSIM4xtsd*T7;
    if (T9>34.0) begin
      T2 = 5.834617425e14*(1.0+T9-34.0);
    end else if (T9<-34.0) begin
      T2 = 1.713908431e-15;
    end else begin
      T2 = exp(T9);
    end
    T9 = xtssws*T7;
    if (T9>34.0) begin
      T3 = 5.834617425e14*(1.0+T9-34.0);
    end else if (T9<-34.0) begin
      T3 = 1.713908431e-15;
    end else begin
      T3 = exp(T9);
    end
    T9 = BSIM4xtsswd*T7;
    if (T9>34.0) begin
      T4 = 5.834617425e14*(1.0+T9-34.0);
    end else if (T9<-34.0) begin
      T4 = 1.713908431e-15;
    end else begin
      T4 = exp(T9);
    end
    T9 = xtsswgs*T7;
    if (T9>34.0) begin
      T5 = 5.834617425e14*(1.0+T9-34.0);
    end else if (T9<-34.0) begin
      T5 = 1.713908431e-15;
    end else begin
      T5 = exp(T9);
    end
    T9 = BSIM4xtsswgd*T7;
    if (T9>34.0) begin
      T6 = 5.834617425e14*(1.0+T9-34.0);
    end else if (T9<-34.0) begin
      T6 = 1.713908431e-15;
    end else begin
      T6 = exp(T9);
    end
    if (BSIM4jtweff<0.0) begin
      BSIM4jtweff = 0.0;
      $warning("TAT width dependence effect is negative. Jtweff is clamped to zero.");
    end
    T11 = sqrt(BSIM4jtweff/BSIM4weffCJ)+1.0;
    T10 = BSIM4weffCJ*nf;
    BSIM4SjctTempRevSatCur = T1*BSIM4Aseff*jtss;
    BSIM4DjctTempRevSatCur = T2*BSIM4Adeff*BSIM4jtsd;
    BSIM4SswTempRevSatCur = T3*BSIM4Pseff*jtssws;
    BSIM4DswTempRevSatCur = T4*BSIM4Pdeff*BSIM4jtsswd;
    BSIM4SswgTempRevSatCur = T5*T10*T11*jtsswgs;
    BSIM4DswgTempRevSatCur = T6*T10*T11*BSIM4jtsswgd;
    if (BSIM4mtrlMod!=0&&BSIM4mtrlCompatMod==0) begin
      Vtm0eot = 8.617087e-5*tempeot;
      Vtmeot = Vtm0eot;
      vbieot = Vtm0eot*ln(sd_BSIM4nsd*sd_BSIM4ndep/(ni*ni));
      phieot = Vtm0eot*ln(sd_BSIM4ndep/ni)+sd_BSIM4phin+0.4;
      if (phieot<=0.0) begin
        $warning("Fatal: phieot = %g is not positive. Please Check Phin and Ndep", BSIM4phi);
        $warning("phieot = %g Ndep = %g ", sd_BSIM4phin, sd_BSIM4ndep);
        Fatal_Flag = 1;
      end
      tmp2 = i_BSIM4vfb+phieot;
      temp_vddeot = BSIM4type*BSIM4vddeot;
      T0 = epsrgate*8.85418e-12;
      if (sd_BSIM4ngate>1.0e18&&sd_BSIM4ngate<1.0e25&&temp_vddeot>tmp2&&T0!=0) begin
        T1 = 1.0e6*1.6021766208e-19*T0*sd_BSIM4ngate/(BSIM4coxe*BSIM4coxe);
        T8 = temp_vddeot-tmp2;
        T4 = sqrt(1.0+2.0*T8/T1);
        T2 = 2.0*T8/(T4+1.0);
        T3 = 0.5*T2*T2/T1;
        T7 = 1.12-T3-0.05;
        T6 = sqrt(T7*T7+0.224);
        T5 = 1.12-0.5*(T7+T6);
        Vgs_eff = temp_vddeot-T5;
      end else begin
        Vgs_eff = temp_vddeot;
      end
      V0 = vbieot-phieot;
      lt1 = BSIM4factor1*BSIM4sqrtXdep0;
      ltw = lt1;
      T0 = sd_BSIM4dvt1*leffeot/lt1;
      if (T0<34.0) begin
        T1 = exp(T0);
        T2 = T1-1.0;
        T3 = T2*T2;
        T4 = T3+2.0*T1*1.713908431e-15;
        Theta0 = T1/T4;
      end else begin
        Theta0 = 1.0/(5.834617425e14-2.0);
      end
      Delt_vth = sd_BSIM4dvt0*Theta0*V0;
      T0 = sd_BSIM4dvt1w*weffeot*leffeot/ltw;
      if (T0<34.0) begin
        T1 = exp(T0);
        T2 = T1-1.0;
        T3 = T2*T2;
        T4 = T3+2.0*T1*1.713908431e-15;
        T5 = T1/T4;
      end else begin
        T5 = 1.0/(5.834617425e14-2.0);
      end
      T2 = sd_BSIM4dvt0w*T5*V0;
      TempRatioeot = tempeot/BSIM4tnom-1.0;
      T0 = sqrt(1.0+sd_BSIM4lpe0/leffeot);
      T1 = BSIM4k1ox*(T0-1.0)*sqrt(phieot)+(sd_BSIM4kt1+sd_BSIM4kt1l/leffeot)*TempRatioeot;
      Vth_NarrowW = temp_toxe*phieot/(weffeot+sd_BSIM4w0);
      Lpe_Vb = sqrt(1.0+sd_BSIM4lpeb/leffeot);
      Vth = BSIM4type*i_BSIM4vth0+(BSIM4k1ox-sd_BSIM4k1)*sqrt(phieot)*Lpe_Vb-Delt_vth-T2+sd_BSIM4k3*Vth_NarrowW+T1;
      tmp1 = epssub/BSIM4Xdep0;
      tmp2 = sd_BSIM4nfactor*tmp1;
      tmp3 = (tmp2+sd_BSIM4cdsc*Theta0+sd_BSIM4cit)/BSIM4coxe;
      if (tmp3>=-0.5) begin
        n = 1.0+tmp3;
      end else begin
        T0 = 1.0/(3.0+8.0*tmp3);
        n = (1.0+3.0*tmp3)*T0;
      end
      if (sd_BSIM4dvtp0>0.0) begin
        T3 = leffeot+sd_BSIM4dvtp0*2.0;
        if (BSIM4tempMod<2) begin
          T4 = Vtmeot*ln(leffeot/T3);
        end else begin
          T4 = Vtm0eot*ln(leffeot/T3);
        end
        Vth = Vth - (n*T4);
      end
      Vgsteff = Vgs_eff-Vth;
      T3 = BSIM4type*i_BSIM4vth0-i_BSIM4vfb-phieot;
      T4 = T3+T3;
      T5 = 2.5*T3;
      vtfbphi2eot = 4.0*T3;
      if (vtfbphi2eot<0.0) begin
        vtfbphi2eot = 0.0;
      end
      niter = 0;
      toxpf = temp_toxe;
      while(niter==0||niter<=4&&((toxpf-toxpi<0.0) ? (-(toxpf-toxpi)) : (toxpf-toxpi))>1e-12) begin
        toxpi = toxpf;
        tmp2 = 2.0e8*toxpf;
        T0 = (Vgsteff+vtfbphi2eot)/tmp2;
        T1 = 1.0+exp(bdos*0.7*ln(T0));
        Tcen = ados*1.9e-9/T1;
        toxpf = temp_toxe-temp_epsrox/epsrsub*Tcen;
        niter = niter+1;
      end
      i_BSIM4toxp = toxpf;
      i_BSIM4coxp = temp_epsrox*8.85418e-12/i_BSIM4toxp;
    end else begin
      i_BSIM4toxp = BSIM4toxp;
      i_BSIM4coxp = BSIM4coxp;
    end

    // Tag: load, function: BSIM4load
    qgmid = 0.0;
    ceqqjd = 0.0;
    ceqqjs = 0.0;
    qgate = 0.0;
    qbulk = 0.0;
    qdrn = 0.0;
    Voxacc = 0.0;
    dVoxacc_dVg = 0.0;
    dVoxacc_dVb = 0.0;
    Voxdepinv = 0.0;
    dVoxdepinv_dVg = 0.0;
    dVoxdepinv_dVd = 0.0;
    dVoxdepinv_dVb = 0.0;
    VxNVt = 0.0;
    Vaux = 0.0;
    dVaux_dVg = 0.0;
    dVaux_dVd = 0.0;
    dVaux_dVb = 0.0;
    Vfb = 0.0;
    load_T0 = 0.0;
    cqdef = 0.0;
    cqcheq = 0.0;
    ScalingFactor = 1.0e-9;
    limited = 0;
    /* Previous vgs, vds, vbs, vges, vgms, vdbs, vsbs, vses, and vdes */
    BSIM4vgs  = BSIM4type * $limit(V(g_int, s_int), DEVlimitOldGet);
    BSIM4vds  = BSIM4type * $limit(V(d_int, s_int), DEVlimitOldGet);
    BSIM4vbs  = BSIM4type * $limit(V(b_int, s_int), DEVlimitOldGet);
    BSIM4vges = BSIM4type * $limit(V(g, s_int), DEVlimitOldGet);
    BSIM4vgms = BSIM4type * $limit(V(gmid_int, s_int), DEVlimitOldGet);
    BSIM4vdbs = BSIM4type * $limit(V(db_int, s_int), DEVlimitOldGet);
    BSIM4vsbs = BSIM4type * $limit(V(sb_int, s_int), DEVlimitOldGet);
    BSIM4vses = BSIM4type * $limit(V(s, s_int), DEVlimitOldGet);
    BSIM4vdes = BSIM4type * $limit(V(d, s_int), DEVlimitOldGet);
    
    /* Previous values computed from stored previous values */
    BSIM4vbd  = BSIM4vbs  - BSIM4vds;
    BSIM4vdbd = BSIM4vdbs - BSIM4vds;
    vgdo     = BSIM4vgs  - BSIM4vds;
    vgedo    = BSIM4vges - BSIM4vds;
    vgmdo    = BSIM4vgms - BSIM4vds;
    vsbdo    = BSIM4vsbs - BSIM4vds;
    
    if (BSIM4mtrlMod) begin
        load_toxe = BSIM4eot;
    end else begin
        load_toxe = BSIM4toxe;
    end
    
    BSIM4von = BSIM4type * i_BSIM4vth0 + (
        - sd_BSIM4k1 * BSIM4sqrtPhi * sqrt(1.0 + sd_BSIM4lpeb / BSIM4leff)
        + sd_BSIM4k3 * load_toxe * BSIM4phi / ( BSIM4weff + sd_BSIM4w0 )
    );
    load_vds = BSIM4type*V(d_int, s_int);
    load_vgs = BSIM4type*V(g_int, s_int);
    load_vbs = BSIM4type*V(b_int, s_int);
    vges = BSIM4type*V(g, s_int);
    vgms = BSIM4type*V(gmid_int, s_int);
    vdbs = BSIM4type*V(db_int, s_int);
    vsbs = BSIM4type*V(sb_int, s_int);
    vses = BSIM4type*V(s, s_int);
    vdes = BSIM4type*V(d, s_int);
    load_qdef = BSIM4type*V(q_int);
    vgdo = BSIM4vgs-BSIM4vds;
    vgedo = BSIM4vges-BSIM4vds;
    vgmdo = BSIM4vgms-BSIM4vds;
    vbd = load_vbs-load_vds;
    vdbd = vdbs-load_vds;
    vgd = load_vgs-load_vds;
    vged = vges-load_vds;
    vgmd = vgms-load_vds;
    von = BSIM4von;
    if (BSIM4vds>=0.0) begin
      load_vgs = DEVfetlim(load_vgs, BSIM4vgs, von, limited);
      load_vds = load_vgs-vgd;
      load_vds = DEVlimvds(load_vds, BSIM4vds, limited);
      vgd = load_vgs-load_vds;
      if (i_BSIM4rgateMod==3) begin
        vges = DEVfetlim(vges, BSIM4vges, von, dummy_limited);
        vgms = DEVfetlim(vgms, BSIM4vgms, von, limited);
        vged = vges-load_vds;
        vgmd = vgms-load_vds;
      end else if (i_BSIM4rgateMod==1||i_BSIM4rgateMod==2) begin
        vges = DEVfetlim(vges, BSIM4vges, von, dummy_limited);
        vged = vges-load_vds;
      end
      if (BSIM4rdsMod) begin
        vdes = DEVlimvds(vdes, BSIM4vdes, limited);
        vses = -DEVlimvds(-vses, -BSIM4vses, limited);
      end
    end else begin
      vgd = DEVfetlim(vgd, vgdo, von, limited);
      load_vds = load_vgs-vgd;
      load_vds = -DEVlimvds(-load_vds, -BSIM4vds, limited);
      load_vgs = vgd+load_vds;
      if (i_BSIM4rgateMod==3) begin
        vged = DEVfetlim(vged, vgedo, von, dummy_limited);
        vges = vged+load_vds;
        vgmd = DEVfetlim(vgmd, vgmdo, von, dummy_limited);
        vgms = vgmd+load_vds;
      end
      if (i_BSIM4rgateMod==1||i_BSIM4rgateMod==2) begin
        vged = DEVfetlim(vged, vgedo, von, dummy_limited);
        vges = vged+load_vds;
      end
      if (BSIM4rdsMod) begin
        vdes = -DEVlimvds(-vdes, -BSIM4vdes, limited);
        vses = DEVlimvds(vses, BSIM4vses, limited);
      end
    end
    if (load_vds>=0.0) begin
      load_vbs = DEVpnjlim(load_vbs, BSIM4vbs, CONSTvt0, BSIM4vcrit, limited);
      vbd = load_vbs-load_vds;
      if (i_BSIM4rbodyMod) begin
        vdbs = DEVpnjlim(vdbs, BSIM4vdbs, CONSTvt0, BSIM4vcrit, limited);
        vdbd = vdbs-load_vds;
        vsbs = DEVpnjlim(vsbs, BSIM4vsbs, CONSTvt0, BSIM4vcrit, limited);
      end
    end else begin
      vbd = DEVpnjlim(vbd, BSIM4vbd, CONSTvt0, BSIM4vcrit, limited);
      load_vbs = vbd+load_vds;
      if (i_BSIM4rbodyMod) begin
        vdbd = DEVpnjlim(vdbd, BSIM4vdbd, CONSTvt0, BSIM4vcrit, limited);
        vdbs = vdbd+load_vds;
        vsbdo = BSIM4vsbs-BSIM4vds;
        vsbd = vsbs-load_vds;
        vsbd = DEVpnjlim(vsbd, vsbdo, CONSTvt0, BSIM4vcrit, limited);
        vsbs = vsbd+load_vds;
      end
    end
    if (initialize_limiting()) begin
        load_vds = 0.1;
        vdes = 0.11;
        vses = -0.01;
        load_vgs = BSIM4type * i_BSIM4vth0 + 0.1;
        vges = BSIM4type * i_BSIM4vth0 + 0.1;
        vgms = BSIM4type * i_BSIM4vth0 + 0.1;
        load_vbs = 0;
        vdbs = 0;
        vsbs = 0;
    end
    
    load_vgs = BSIM4type * $limit(V(g_int, s_int), DEVlimitNewSet, BSIM4type * load_vgs, limited);
    load_vds = BSIM4type * $limit(V(d_int, s_int), DEVlimitNewSet, BSIM4type * load_vds, limited);
    load_vbs = BSIM4type * $limit(V(b_int, s_int), DEVlimitNewSet, BSIM4type * load_vbs, limited);
    vges = BSIM4type * $limit(V(g, s_int), DEVlimitNewSet, BSIM4type * vges, limited);
    vgms = BSIM4type * $limit(V(gmid_int, s_int), DEVlimitNewSet, BSIM4type * vgms, limited);
    vdbs = BSIM4type * $limit(V(db_int, s_int), DEVlimitNewSet, BSIM4type * vdbs, limited);
    vsbs = BSIM4type * $limit(V(sb_int, s_int), DEVlimitNewSet, BSIM4type * vsbs, limited);
    vses = BSIM4type * $limit(V(s, s_int), DEVlimitNewSet, BSIM4type * vses, limited);
    vdes = BSIM4type * $limit(V(d, s_int), DEVlimitNewSet, BSIM4type * vdes, limited);
    vbd = load_vbs-load_vds;
    vgd = load_vgs-load_vds;
    vgb = load_vgs-load_vbs;
    vged = vges-load_vds;
    vgmd = vgms-load_vds;
    vgmb = vgms-load_vbs;
    vdbd = vdbs-load_vds;
    vbs_jct = ((!i_BSIM4rbodyMod) ? (load_vbs) : (vsbs));
    vbd_jct = ((!i_BSIM4rbodyMod) ? (vbd) : (vdbd));
    load_Nvtms = BSIM4vtm*njs;
    if (BSIM4Aseff<=0.0&&BSIM4Pseff<=0.0) begin
      load_SourceSatCurrent = 0.0;
    end else begin
      load_SourceSatCurrent = BSIM4Aseff*BSIM4SjctTempSatCurDensity+BSIM4Pseff*BSIM4SjctSidewallTempSatCurDensity+BSIM4weffCJ*nf*BSIM4SjctGateSidewallTempSatCurDensity;
    end
    if (load_SourceSatCurrent<=0.0) begin
      BSIM4gbs = lc_gmin;
      BSIM4cbs = BSIM4gbs*vbs_jct;
    end else begin
      case (BSIM4dioMod)
        0: begin
          evbs = exp(vbs_jct/load_Nvtms);
          load_T1 = BSIM4xjbvs*exp(-(BSIM4bvs+vbs_jct)/load_Nvtms);
          BSIM4gbs = load_SourceSatCurrent*(evbs+load_T1)/load_Nvtms+lc_gmin;
          BSIM4cbs = load_SourceSatCurrent*(evbs+BSIM4XExpBVS-load_T1-1.0)+lc_gmin*vbs_jct;
        end
        1: begin
          load_T2 = vbs_jct/load_Nvtms;
          if (load_T2<-34.0) begin
            BSIM4gbs = lc_gmin;
            BSIM4cbs = load_SourceSatCurrent*(1.713908431e-15-1.0)+lc_gmin*vbs_jct;
          end else if (vbs_jct<=BSIM4vjsmFwd) begin
            evbs = exp(load_T2);
            BSIM4gbs = load_SourceSatCurrent*evbs/load_Nvtms+lc_gmin;
            BSIM4cbs = load_SourceSatCurrent*(evbs-1.0)+lc_gmin*vbs_jct;
          end else begin
            load_T0 = BSIM4IVjsmFwd/load_Nvtms;
            BSIM4gbs = load_T0+lc_gmin;
            BSIM4cbs = BSIM4IVjsmFwd-load_SourceSatCurrent+load_T0*(vbs_jct-BSIM4vjsmFwd)+lc_gmin*vbs_jct;
          end
        end
        2: begin
          if (vbs_jct<BSIM4vjsmRev) begin
            load_T0 = vbs_jct/load_Nvtms;
            if (load_T0<-34.0) begin
              evbs = 1.713908431e-15;
              devbs_dvb = 0.0;
            end else begin
              evbs = exp(load_T0);
              devbs_dvb = evbs/load_Nvtms;
            end
            load_T1 = evbs-1.0;
            load_T2 = BSIM4IVjsmRev+BSIM4SslpRev*(vbs_jct-BSIM4vjsmRev);
            BSIM4gbs = devbs_dvb*load_T2+load_T1*BSIM4SslpRev+lc_gmin;
            BSIM4cbs = load_T1*load_T2+lc_gmin*vbs_jct;
          end else if (vbs_jct<=BSIM4vjsmFwd) begin
            load_T0 = vbs_jct/load_Nvtms;
            if (load_T0<-34.0) begin
              evbs = 1.713908431e-15;
              devbs_dvb = 0.0;
            end else begin
              evbs = exp(load_T0);
              devbs_dvb = evbs/load_Nvtms;
            end
            load_T1 = (BSIM4bvs+vbs_jct)/load_Nvtms;
            if (load_T1>34.0) begin
              load_T2 = 1.713908431e-15;
              load_T3 = 0.0;
            end else begin
              load_T2 = exp(-load_T1);
              load_T3 = -load_T2/load_Nvtms;
            end
            BSIM4gbs = load_SourceSatCurrent*(devbs_dvb-BSIM4xjbvs*load_T3)+lc_gmin;
            BSIM4cbs = load_SourceSatCurrent*(evbs+BSIM4XExpBVS-1.0-BSIM4xjbvs*load_T2)+lc_gmin*vbs_jct;
          end else begin
            BSIM4gbs = BSIM4SslpFwd+lc_gmin;
            BSIM4cbs = BSIM4IVjsmFwd+BSIM4SslpFwd*(vbs_jct-BSIM4vjsmFwd)+lc_gmin*vbs_jct;
          end
        end
      endcase

    end
    load_Nvtmd = BSIM4vtm*BSIM4DjctEmissionCoeff;
    if (BSIM4Adeff<=0.0&&BSIM4Pdeff<=0.0) begin
      load_DrainSatCurrent = 0.0;
    end else begin
      load_DrainSatCurrent = BSIM4Adeff*BSIM4DjctTempSatCurDensity+BSIM4Pdeff*BSIM4DjctSidewallTempSatCurDensity+BSIM4weffCJ*nf*BSIM4DjctGateSidewallTempSatCurDensity;
    end
    if (load_DrainSatCurrent<=0.0) begin
      BSIM4gbd = lc_gmin;
      BSIM4cbd = BSIM4gbd*vbd_jct;
    end else begin
      case (BSIM4dioMod)
        0: begin
          evbd = exp(vbd_jct/load_Nvtmd);
          load_T1 = BSIM4xjbvd*exp(-(BSIM4bvd+vbd_jct)/load_Nvtmd);
          BSIM4gbd = load_DrainSatCurrent*(evbd+load_T1)/load_Nvtmd+lc_gmin;
          BSIM4cbd = load_DrainSatCurrent*(evbd+BSIM4XExpBVD-load_T1-1.0)+lc_gmin*vbd_jct;
        end
        1: begin
          load_T2 = vbd_jct/load_Nvtmd;
          if (load_T2<-34.0) begin
            BSIM4gbd = lc_gmin;
            BSIM4cbd = load_DrainSatCurrent*(1.713908431e-15-1.0)+lc_gmin*vbd_jct;
          end else if (vbd_jct<=BSIM4vjdmFwd) begin
            evbd = exp(load_T2);
            BSIM4gbd = load_DrainSatCurrent*evbd/load_Nvtmd+lc_gmin;
            BSIM4cbd = load_DrainSatCurrent*(evbd-1.0)+lc_gmin*vbd_jct;
          end else begin
            load_T0 = BSIM4IVjdmFwd/load_Nvtmd;
            BSIM4gbd = load_T0+lc_gmin;
            BSIM4cbd = BSIM4IVjdmFwd-load_DrainSatCurrent+load_T0*(vbd_jct-BSIM4vjdmFwd)+lc_gmin*vbd_jct;
          end
        end
        2: begin
          if (vbd_jct<BSIM4vjdmRev) begin
            load_T0 = vbd_jct/load_Nvtmd;
            if (load_T0<-34.0) begin
              evbd = 1.713908431e-15;
              devbd_dvb = 0.0;
            end else begin
              evbd = exp(load_T0);
              devbd_dvb = evbd/load_Nvtmd;
            end
            load_T1 = evbd-1.0;
            load_T2 = BSIM4IVjdmRev+BSIM4DslpRev*(vbd_jct-BSIM4vjdmRev);
            BSIM4gbd = devbd_dvb*load_T2+load_T1*BSIM4DslpRev+lc_gmin;
            BSIM4cbd = load_T1*load_T2+lc_gmin*vbd_jct;
          end else if (vbd_jct<=BSIM4vjdmFwd) begin
            load_T0 = vbd_jct/load_Nvtmd;
            if (load_T0<-34.0) begin
              evbd = 1.713908431e-15;
              devbd_dvb = 0.0;
            end else begin
              evbd = exp(load_T0);
              devbd_dvb = evbd/load_Nvtmd;
            end
            load_T1 = (BSIM4bvd+vbd_jct)/load_Nvtmd;
            if (load_T1>34.0) begin
              load_T2 = 1.713908431e-15;
              load_T3 = 0.0;
            end else begin
              load_T2 = exp(-load_T1);
              load_T3 = -load_T2/load_Nvtmd;
            end
            BSIM4gbd = load_DrainSatCurrent*(devbd_dvb-BSIM4xjbvd*load_T3)+lc_gmin;
            BSIM4cbd = load_DrainSatCurrent*(evbd+BSIM4XExpBVD-1.0-BSIM4xjbvd*load_T2)+lc_gmin*vbd_jct;
          end else begin
            BSIM4gbd = BSIM4DslpFwd+lc_gmin;
            BSIM4cbd = BSIM4IVjdmFwd+BSIM4DslpFwd*(vbd_jct-BSIM4vjdmFwd)+lc_gmin*vbd_jct;
          end
        end
      endcase

    end
    Nvtmrssws = BSIM4vtm0*BSIM4njtsswstemp;
    Nvtmrsswgs = BSIM4vtm0*BSIM4njtsswgstemp;
    Nvtmrss = BSIM4vtm0*BSIM4njtsstemp;
    Nvtmrsswd = BSIM4vtm0*BSIM4njtsswdtemp;
    Nvtmrsswgd = BSIM4vtm0*BSIM4njtsswgdtemp;
    Nvtmrsd = BSIM4vtm0*BSIM4njtsdtemp;
    if (vtss-vbs_jct<vtss*1e-3) begin
      load_T9 = 1.0e3;
      load_T0 = -vbs_jct/Nvtmrss*load_T9;
      if (load_T0>34.0) begin
        load_T1 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T1 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T1 = exp(load_T0);
        load_T10 = load_T1;
      end
      dT1_dVb = load_T10/Nvtmrss*load_T9;
    end else begin
      load_T9 = 1.0/(vtss-vbs_jct);
      load_T0 = -vbs_jct/Nvtmrss*vtss*load_T9;
      dT0_dVb = vtss/Nvtmrss*(load_T9+vbs_jct*load_T9*load_T9);
      if (load_T0>34.0) begin
        load_T1 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T1 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T1 = exp(load_T0);
        load_T10 = load_T1;
      end
      dT1_dVb = load_T10*dT0_dVb;
    end
    if (BSIM4vtsd-vbd_jct<BSIM4vtsd*1e-3) begin
      load_T9 = 1.0e3;
      load_T0 = -vbd_jct/Nvtmrsd*load_T9;
      if (load_T0>34.0) begin
        load_T2 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T2 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T2 = exp(load_T0);
        load_T10 = load_T2;
      end
      dT2_dVb = load_T10/Nvtmrsd*load_T9;
    end else begin
      load_T9 = 1.0/(BSIM4vtsd-vbd_jct);
      load_T0 = -vbd_jct/Nvtmrsd*BSIM4vtsd*load_T9;
      dT0_dVb = BSIM4vtsd/Nvtmrsd*(load_T9+vbd_jct*load_T9*load_T9);
      if (load_T0>34.0) begin
        load_T2 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T2 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T2 = exp(load_T0);
        load_T10 = load_T2;
      end
      dT2_dVb = load_T10*dT0_dVb;
    end
    if (vtssws-vbs_jct<vtssws*1e-3) begin
      load_T9 = 1.0e3;
      load_T0 = -vbs_jct/Nvtmrssws*load_T9;
      if (load_T0>34.0) begin
        load_T3 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T3 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T3 = exp(load_T0);
        load_T10 = load_T3;
      end
      dT3_dVb = load_T10/Nvtmrssws*load_T9;
    end else begin
      load_T9 = 1.0/(vtssws-vbs_jct);
      load_T0 = -vbs_jct/Nvtmrssws*vtssws*load_T9;
      dT0_dVb = vtssws/Nvtmrssws*(load_T9+vbs_jct*load_T9*load_T9);
      if (load_T0>34.0) begin
        load_T3 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T3 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T3 = exp(load_T0);
        load_T10 = load_T3;
      end
      dT3_dVb = load_T10*dT0_dVb;
    end
    if (BSIM4vtsswd-vbd_jct<BSIM4vtsswd*1e-3) begin
      load_T9 = 1.0e3;
      load_T0 = -vbd_jct/Nvtmrsswd*load_T9;
      if (load_T0>34.0) begin
        load_T4 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T4 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T4 = exp(load_T0);
        load_T10 = load_T4;
      end
      dT4_dVb = load_T10/Nvtmrsswd*load_T9;
    end else begin
      load_T9 = 1.0/(BSIM4vtsswd-vbd_jct);
      load_T0 = -vbd_jct/Nvtmrsswd*BSIM4vtsswd*load_T9;
      dT0_dVb = BSIM4vtsswd/Nvtmrsswd*(load_T9+vbd_jct*load_T9*load_T9);
      if (load_T0>34.0) begin
        load_T4 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T4 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T4 = exp(load_T0);
        load_T10 = load_T4;
      end
      dT4_dVb = load_T10*dT0_dVb;
    end
    if (vtsswgs-vbs_jct<vtsswgs*1e-3) begin
      load_T9 = 1.0e3;
      load_T0 = -vbs_jct/Nvtmrsswgs*load_T9;
      if (load_T0>34.0) begin
        load_T5 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T5 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T5 = exp(load_T0);
        load_T10 = load_T5;
      end
      dT5_dVb = load_T10/Nvtmrsswgs*load_T9;
    end else begin
      load_T9 = 1.0/(vtsswgs-vbs_jct);
      load_T0 = -vbs_jct/Nvtmrsswgs*vtsswgs*load_T9;
      dT0_dVb = vtsswgs/Nvtmrsswgs*(load_T9+vbs_jct*load_T9*load_T9);
      if (load_T0>34.0) begin
        load_T5 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T5 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T5 = exp(load_T0);
        load_T10 = load_T5;
      end
      dT5_dVb = load_T10*dT0_dVb;
    end
    if (BSIM4vtsswgd-vbd_jct<BSIM4vtsswgd*1e-3) begin
      load_T9 = 1.0e3;
      load_T0 = -vbd_jct/Nvtmrsswgd*load_T9;
      if (load_T0>34.0) begin
        load_T6 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T6 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T6 = exp(load_T0);
        load_T10 = load_T6;
      end
      dT6_dVb = load_T10/Nvtmrsswgd*load_T9;
    end else begin
      load_T9 = 1.0/(BSIM4vtsswgd-vbd_jct);
      load_T0 = -vbd_jct/Nvtmrsswgd*BSIM4vtsswgd*load_T9;
      dT0_dVb = BSIM4vtsswgd/Nvtmrsswgd*(load_T9+vbd_jct*load_T9*load_T9);
      if (load_T0>34.0) begin
        load_T6 = 5.834617425e14*(1.0+load_T0-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T0<-34.0) begin
        load_T6 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T6 = exp(load_T0);
        load_T10 = load_T6;
      end
      dT6_dVb = load_T10*dT0_dVb;
    end
    BSIM4gbs = BSIM4gbs + (BSIM4SjctTempRevSatCur*dT1_dVb+BSIM4SswTempRevSatCur*dT3_dVb+BSIM4SswgTempRevSatCur*dT5_dVb);
    BSIM4cbs = BSIM4cbs - (BSIM4SjctTempRevSatCur*(load_T1-1.0)+BSIM4SswTempRevSatCur*(load_T3-1.0)+BSIM4SswgTempRevSatCur*(load_T5-1.0));
    BSIM4gbd = BSIM4gbd + (BSIM4DjctTempRevSatCur*dT2_dVb+BSIM4DswTempRevSatCur*dT4_dVb+BSIM4DswgTempRevSatCur*dT6_dVb);
    BSIM4cbd = BSIM4cbd - (BSIM4DjctTempRevSatCur*(load_T2-1.0)+BSIM4DswTempRevSatCur*(load_T4-1.0)+BSIM4DswgTempRevSatCur*(load_T6-1.0));
    if (load_vds>=0.0) begin
      BSIM4mode = 1;
      Vds = load_vds;
      Vgs = load_vgs;
      Vbs = load_vbs;
      Vdb = load_vds-load_vbs;
    end else begin
      BSIM4mode = -1;
      Vds = -load_vds;
      Vgs = vgd;
      Vbs = vbd;
      Vdb = -load_vbs;
    end
    if (BSIM4mtrlMod) begin
      load_epsrox = 3.9;
      load_toxe = BSIM4eot;
      load_epssub = 8.85418e-12*epsrsub;
    end else begin
      load_epsrox = epsrox;
      load_toxe = BSIM4toxe;
      load_epssub = 1.03594e-10;
    end
    load_T0 = Vbs-BSIM4vbsc-0.001;
    load_T1 = sqrt(load_T0*load_T0-0.004*BSIM4vbsc);
    if (load_T0>=0.0) begin
      Vbseff = BSIM4vbsc+0.5*(load_T0+load_T1);
      dVbseff_dVb = 0.5*(1.0+load_T0/load_T1);
    end else begin
      load_T2 = -0.002/(load_T1-load_T0);
      Vbseff = BSIM4vbsc*(1.0+load_T2);
      dVbseff_dVb = load_T2*BSIM4vbsc/load_T1;
    end
    load_T9 = 0.95*BSIM4phi;
    load_T0 = load_T9-Vbseff-0.001;
    load_T1 = sqrt(load_T0*load_T0+0.004*load_T9);
    Vbseff = load_T9-0.5*(load_T0+load_T1);
    dVbseff_dVb = dVbseff_dVb * (0.5*(1.0+load_T0/load_T1));
    Phis = BSIM4phi-Vbseff;
    dPhis_dVb = -1.0;
    sqrtPhis = sqrt(Phis);
    dsqrtPhis_dVb = -0.5/sqrtPhis;
    Xdep = BSIM4Xdep0*sqrtPhis/BSIM4sqrtPhi;
    dXdep_dVb = BSIM4Xdep0/BSIM4sqrtPhi*dsqrtPhis_dVb;
    Leff = BSIM4leff;
    Vtm = BSIM4vtm;
    load_Vtm0 = BSIM4vtm0;
    load_T3 = sqrt(Xdep);
    load_V0 = BSIM4vbi-BSIM4phi;
    load_T0 = sd_BSIM4dvt2*Vbseff;
    if (load_T0>=-0.5) begin
      load_T1 = 1.0+load_T0;
      load_T2 = sd_BSIM4dvt2;
    end else begin
      load_T4 = 1.0/(3.0+8.0*load_T0);
      load_T1 = (1.0+3.0*load_T0)*load_T4;
      load_T2 = sd_BSIM4dvt2*load_T4*load_T4;
    end
    load_lt1 = BSIM4factor1*load_T3*load_T1;
    dlt1_dVb = BSIM4factor1*(0.5/load_T3*load_T1*dXdep_dVb+load_T3*load_T2);
    load_T0 = sd_BSIM4dvt2w*Vbseff;
    if (load_T0>=-0.5) begin
      load_T1 = 1.0+load_T0;
      load_T2 = sd_BSIM4dvt2w;
    end else begin
      load_T4 = 1.0/(3.0+8.0*load_T0);
      load_T1 = (1.0+3.0*load_T0)*load_T4;
      load_T2 = sd_BSIM4dvt2w*load_T4*load_T4;
    end
    load_ltw = BSIM4factor1*load_T3*load_T1;
    dltw_dVb = BSIM4factor1*(0.5/load_T3*load_T1*dXdep_dVb+load_T3*load_T2);
    load_T0 = sd_BSIM4dvt1*Leff/load_lt1;
    if (load_T0<34.0) begin
      load_T1 = exp(load_T0);
      load_T2 = load_T1-1.0;
      load_T3 = load_T2*load_T2;
      load_T4 = load_T3+2.0*load_T1*1.713908431e-15;
      load_Theta0 = load_T1/load_T4;
      dT1_dVb = -load_T0*load_T1*dlt1_dVb/load_lt1;
      dTheta0_dVb = dT1_dVb*(load_T4-2.0*load_T1*(load_T2+1.713908431e-15))/load_T4/load_T4;
    end else begin
      load_Theta0 = 1.0/(5.834617425e14-2.0);
      dTheta0_dVb = 0.0;
    end
    BSIM4thetavth = sd_BSIM4dvt0*load_Theta0;
    load_Delt_vth = BSIM4thetavth*load_V0;
    dDelt_vth_dVb = sd_BSIM4dvt0*dTheta0_dVb*load_V0;
    load_T0 = sd_BSIM4dvt1w*BSIM4weff*Leff/load_ltw;
    if (load_T0<34.0) begin
      load_T1 = exp(load_T0);
      load_T2 = load_T1-1.0;
      load_T3 = load_T2*load_T2;
      load_T4 = load_T3+2.0*load_T1*1.713908431e-15;
      load_T5 = load_T1/load_T4;
      dT1_dVb = -load_T0*load_T1*dltw_dVb/load_ltw;
      dT5_dVb = dT1_dVb*(load_T4-2.0*load_T1*(load_T2+1.713908431e-15))/load_T4/load_T4;
    end else begin
      load_T5 = 1.0/(5.834617425e14-2.0);
      dT5_dVb = 0.0;
    end
    load_T0 = sd_BSIM4dvt0w*load_T5;
    load_T2 = load_T0*load_V0;
    dT2_dVb = sd_BSIM4dvt0w*dT5_dVb*load_V0;
    TempRatio = $temperature/BSIM4tnom-1.0;
    load_T0 = sqrt(1.0+sd_BSIM4lpe0/Leff);
    load_T1 = BSIM4k1ox*(load_T0-1.0)*BSIM4sqrtPhi+(sd_BSIM4kt1+sd_BSIM4kt1l/Leff+sd_BSIM4kt2*Vbseff)*TempRatio;
    load_Vth_NarrowW = load_toxe*BSIM4phi/(BSIM4weff+sd_BSIM4w0);
    load_T3 = i_BSIM4eta0+sd_BSIM4etab*Vbseff;
    if (load_T3<1.0e-4) begin
      load_T9 = 1.0/(3.0-2.0e4*load_T3);
      load_T3 = (2.0e-4-load_T3)*load_T9;
      load_T4 = load_T9*load_T9;
    end else begin
      load_T4 = 1.0;
    end
    dDIBL_Sft_dVd = load_T3*BSIM4theta0vb0;
    DIBL_Sft = dDIBL_Sft_dVd*Vds;
    load_Lpe_Vb = sqrt(1.0+sd_BSIM4lpeb/Leff);
    load_Vth = BSIM4type*i_BSIM4vth0+(BSIM4k1ox*sqrtPhis-sd_BSIM4k1*BSIM4sqrtPhi)*load_Lpe_Vb-BSIM4k2ox*Vbseff-load_Delt_vth-load_T2+(sd_BSIM4k3+sd_BSIM4k3b*Vbseff)*load_Vth_NarrowW+load_T1-DIBL_Sft;
    dVth_dVb = load_Lpe_Vb*BSIM4k1ox*dsqrtPhis_dVb-BSIM4k2ox-dDelt_vth_dVb-dT2_dVb+sd_BSIM4k3b*load_Vth_NarrowW-sd_BSIM4etab*Vds*BSIM4theta0vb0*load_T4+sd_BSIM4kt2*TempRatio;
    dVth_dVd = -dDIBL_Sft_dVd;
    load_tmp1 = load_epssub/Xdep;
    BSIM4nstar = BSIM4vtm/1.60219e-19*(BSIM4coxe+load_tmp1+sd_BSIM4cit);
    load_tmp2 = sd_BSIM4nfactor*load_tmp1;
    load_tmp3 = sd_BSIM4cdsc+sd_BSIM4cdscb*Vbseff+sd_BSIM4cdscd*Vds;
    tmp4 = (load_tmp2+load_tmp3*load_Theta0+sd_BSIM4cit)/BSIM4coxe;
    if (tmp4>=-0.5) begin
      load_n = 1.0+tmp4;
      dn_dVb = (-load_tmp2/Xdep*dXdep_dVb+load_tmp3*dTheta0_dVb+sd_BSIM4cdscb*load_Theta0)/BSIM4coxe;
      dn_dVd = sd_BSIM4cdscd*load_Theta0/BSIM4coxe;
    end else begin
      load_T0 = 1.0/(3.0+8.0*tmp4);
      load_n = (1.0+3.0*tmp4)*load_T0;
      load_T0 = load_T0 * (load_T0);
      dn_dVb = (-load_tmp2/Xdep*dXdep_dVb+load_tmp3*dTheta0_dVb+sd_BSIM4cdscb*load_Theta0)/BSIM4coxe*load_T0;
      dn_dVd = sd_BSIM4cdscd*load_Theta0/BSIM4coxe*load_T0;
    end
    if (sd_BSIM4dvtp0>0.0) begin
      load_T0 = -sd_BSIM4dvtp1*Vds;
      if (load_T0<-34.0) begin
        load_T2 = 1.713908431e-15;
        dT2_dVd = 0.0;
      end else begin
        load_T2 = exp(load_T0);
        dT2_dVd = -sd_BSIM4dvtp1*load_T2;
      end
      load_T3 = Leff+sd_BSIM4dvtp0*(1.0+load_T2);
      dT3_dVd = sd_BSIM4dvtp0*dT2_dVd;
      if (BSIM4tempMod<2) begin
        load_T4 = Vtm*ln(Leff/load_T3);
        dT4_dVd = -Vtm*dT3_dVd/load_T3;
      end else begin
        load_T4 = BSIM4vtm0*ln(Leff/load_T3);
        dT4_dVd = -BSIM4vtm0*dT3_dVd/load_T3;
      end
      dDITS_Sft_dVd = dn_dVd*load_T4+load_n*dT4_dVd;
      dDITS_Sft_dVb = load_T4*dn_dVb;
      load_Vth = load_Vth - (load_n*load_T4);
      dVth_dVd = dVth_dVd - (dDITS_Sft_dVd);
      dVth_dVb = dVth_dVb - (dDITS_Sft_dVb);
    end
    if (sd_BSIM4dvtp4==0.0||BSIM4dvtp2factor==0.0) begin
      load_T0 = 0.0;
      DITS_Sft2 = 0.0;
    end else begin
      load_T1 = 2.0*sd_BSIM4dvtp4*Vds;
      if (load_T1>34.0) begin
        load_T0 = 5.834617425e14*(1.0+load_T1-34.0);
        load_T10 = 5.834617425e14;
      end else if (load_T1<-34.0) begin
        load_T0 = 1.713908431e-15;
        load_T10 = 0;
      end else begin
        load_T0 = exp(load_T1);
        load_T10 = load_T0;
      end
      DITS_Sft2 = BSIM4dvtp2factor*(load_T0-1)/(load_T0+1);
      dDITS_Sft2_dVd = BSIM4dvtp2factor*sd_BSIM4dvtp4*4.0*load_T10/((load_T0+1)*(load_T0+1));
      load_Vth = load_Vth - (DITS_Sft2);
      dVth_dVd = dVth_dVd - (dDITS_Sft2_dVd);
    end
    BSIM4von = load_Vth;
    load_T0 = i_BSIM4vfb+BSIM4phi;
    if (BSIM4mtrlMod==0) begin
      load_T1 = 1.03594e-10;
    end else begin
      load_T1 = epsrgate*8.85418e-12;
    end
    BSIM4polyDepletion(load_T0, sd_BSIM4ngate, load_T1, BSIM4coxe, load_vgs, vgs_eff, dvgs_eff_dvg);
    BSIM4polyDepletion(load_T0, sd_BSIM4ngate, load_T1, BSIM4coxe, vgd, vgd_eff, dvgd_eff_dvg);
    if (BSIM4mode>0) begin
      load_Vgs_eff = vgs_eff;
      dVgs_eff_dVg = dvgs_eff_dvg;
    end else begin
      load_Vgs_eff = vgd_eff;
      dVgs_eff_dVg = dvgd_eff_dvg;
    end
    BSIM4vgs_eff = vgs_eff;
    BSIM4vgd_eff = vgd_eff;
    BSIM4dvgs_eff_dvg = dvgs_eff_dvg;
    BSIM4dvgd_eff_dvg = dvgd_eff_dvg;
    Vgst = load_Vgs_eff-load_Vth;
    load_T0 = load_n*Vtm;
    load_T1 = BSIM4mstar*Vgst;
    load_T2 = load_T1/load_T0;
    if (load_T2>34.0) begin
      load_T10 = load_T1;
      dT10_dVg = BSIM4mstar*dVgs_eff_dVg;
      dT10_dVd = -dVth_dVd*BSIM4mstar;
      dT10_dVb = -dVth_dVb*BSIM4mstar;
    end else if (load_T2<-34.0) begin
      load_T10 = Vtm*ln(1.0+1.713908431e-15);
      dT10_dVg = 0.0;
      dT10_dVd = load_T10*dn_dVd;
      dT10_dVb = load_T10*dn_dVb;
      load_T10 = load_T10 * (load_n);
    end else begin
      ExpVgst = exp(load_T2);
      load_T3 = Vtm*ln(1.0+ExpVgst);
      load_T10 = load_n*load_T3;
      dT10_dVg = BSIM4mstar*ExpVgst/(1.0+ExpVgst);
      dT10_dVb = load_T3*dn_dVb-dT10_dVg*(dVth_dVb+Vgst*dn_dVb/load_n);
      dT10_dVd = load_T3*dn_dVd-dT10_dVg*(dVth_dVd+Vgst*dn_dVd/load_n);
      dT10_dVg = dT10_dVg * (dVgs_eff_dVg);
    end
    load_T1 = BSIM4voffcbn-(1.0-BSIM4mstar)*Vgst;
    load_T2 = load_T1/load_T0;
    if (load_T2<-34.0) begin
      load_T3 = BSIM4coxe*1.713908431e-15/BSIM4cdep0;
      load_T9 = BSIM4mstar+load_T3*load_n;
      dT9_dVg = 0.0;
      dT9_dVd = dn_dVd*load_T3;
      dT9_dVb = dn_dVb*load_T3;
    end else if (load_T2>34.0) begin
      load_T3 = BSIM4coxe*5.834617425e14/BSIM4cdep0;
      load_T9 = BSIM4mstar+load_T3*load_n;
      dT9_dVg = 0.0;
      dT9_dVd = dn_dVd*load_T3;
      dT9_dVb = dn_dVb*load_T3;
    end else begin
      ExpVgst = exp(load_T2);
      load_T3 = BSIM4coxe/BSIM4cdep0;
      load_T4 = load_T3*ExpVgst;
      load_T5 = load_T1*load_T4/load_T0;
      load_T9 = BSIM4mstar+load_n*load_T4;
      dT9_dVg = load_T3*(BSIM4mstar-1.0)*ExpVgst/Vtm;
      dT9_dVb = load_T4*dn_dVb-dT9_dVg*dVth_dVb-load_T5*dn_dVb;
      dT9_dVd = load_T4*dn_dVd-dT9_dVg*dVth_dVd-load_T5*dn_dVd;
      dT9_dVg = dT9_dVg * (dVgs_eff_dVg);
    end
    load_Vgsteff = load_T10/load_T9;
    BSIM4Vgsteff = load_Vgsteff;
    load_T11 = load_T9*load_T9;
    dVgsteff_dVg = (load_T9*dT10_dVg-load_T10*dT9_dVg)/load_T11;
    dVgsteff_dVd = (load_T9*dT10_dVd-load_T10*dT9_dVd)/load_T11;
    dVgsteff_dVb = (load_T9*dT10_dVb-load_T10*dT9_dVb)/load_T11;
    load_T9 = sqrtPhis-BSIM4sqrtPhi;
    Weff = BSIM4weff-2.0*(sd_BSIM4dwg*load_Vgsteff+sd_BSIM4dwb*load_T9);
    dWeff_dVg = -2.0*sd_BSIM4dwg;
    dWeff_dVb = -2.0*sd_BSIM4dwb*dsqrtPhis_dVb;
    if (Weff<2.0e-8) begin
      load_T0 = 1.0/(6.0e-8-2.0*Weff);
      Weff = 2.0e-8*(4.0e-8-Weff)*load_T0;
      load_T0 = load_T0 * (load_T0*4.0e-16);
      dWeff_dVg = dWeff_dVg * (load_T0);
      dWeff_dVb = dWeff_dVb * (load_T0);
    end
    if (BSIM4rdsMod==1) begin
      dRds_dVb = 0.0;
      dRds_dVg = dRds_dVb;
      Rds = dRds_dVg;
    end else begin
      load_T0 = 1.0+sd_BSIM4prwg*load_Vgsteff;
      dT0_dVg = -sd_BSIM4prwg/load_T0/load_T0;
      load_T1 = sd_BSIM4prwb*load_T9;
      dT1_dVb = sd_BSIM4prwb*dsqrtPhis_dVb;
      load_T2 = 1.0/load_T0+load_T1;
      load_T3 = load_T2+sqrt(load_T2*load_T2+0.01);
      dT3_dVg = 1.0+load_T2/(load_T3-load_T2);
      dT3_dVb = dT3_dVg*dT1_dVb;
      dT3_dVg = dT3_dVg * (dT0_dVg);
      load_T4 = BSIM4rds0*0.5;
      Rds = sd_BSIM4rdswmin+load_T3*load_T4;
      dRds_dVg = load_T4*dT3_dVg;
      dRds_dVb = load_T4*dT3_dVb;
      if (Rds>0.0) begin
        BSIM4grdsw = 1.0/Rds*nf;
      end else begin
        BSIM4grdsw = 0.0;
      end
    end
    load_T9 = 0.5*BSIM4k1ox*load_Lpe_Vb/sqrtPhis;
    load_T1 = load_T9+BSIM4k2ox-sd_BSIM4k3b*load_Vth_NarrowW;
    dT1_dVb = -load_T9/sqrtPhis*dsqrtPhis_dVb;
    load_T9 = sqrt(sd_BSIM4xj*Xdep);
    load_tmp1 = Leff+2.0*load_T9;
    load_T5 = Leff/load_tmp1;
    load_tmp2 = sd_BSIM4a0*load_T5;
    load_tmp3 = BSIM4weff+sd_BSIM4b1;
    tmp4 = sd_BSIM4b0/load_tmp3;
    load_T2 = load_tmp2+tmp4;
    dT2_dVb = -load_T9/load_tmp1/Xdep*dXdep_dVb;
    load_T6 = load_T5*load_T5;
    load_T7 = load_T5*load_T6;
    Abulk0 = 1.0+load_T1*load_T2;
    dAbulk0_dVb = load_T1*load_tmp2*dT2_dVb+load_T2*dT1_dVb;
    load_T8 = sd_BSIM4ags*sd_BSIM4a0*load_T7;
    dAbulk_dVg = -load_T1*load_T8;
    Abulk = Abulk0+dAbulk_dVg*load_Vgsteff;
    dAbulk_dVb = dAbulk0_dVb-load_T8*load_Vgsteff*(dT1_dVb+3.0*load_T1*dT2_dVb);
    if (Abulk0<0.1) begin
      load_T9 = 1.0/(3.0-20.0*Abulk0);
      Abulk0 = (0.2-Abulk0)*load_T9;
      dAbulk0_dVb = dAbulk0_dVb * (load_T9*load_T9);
    end
    if (Abulk<0.1) begin
      load_T9 = 1.0/(3.0-20.0*Abulk);
      Abulk = (0.2-Abulk)*load_T9;
      load_T10 = load_T9*load_T9;
      dAbulk_dVb = dAbulk_dVb * (load_T10);
      dAbulk_dVg = dAbulk_dVg * (load_T10);
    end
    BSIM4Abulk = Abulk;
    load_T2 = sd_BSIM4keta*Vbseff;
    if (load_T2>=-0.9) begin
      load_T0 = 1.0/(1.0+load_T2);
      dT0_dVb = -sd_BSIM4keta*load_T0*load_T0;
    end else begin
      load_T1 = 1.0/(0.8+load_T2);
      load_T0 = (17.0+20.0*load_T2)*load_T1;
      dT0_dVb = -sd_BSIM4keta*load_T1*load_T1;
    end
    dAbulk_dVg = dAbulk_dVg * (load_T0);
    dAbulk_dVb = dAbulk_dVb*load_T0+Abulk*dT0_dVb;
    dAbulk0_Q_dVb = dAbulk0_dVb;
    dAbulk0_dVb = dAbulk0_dVb*load_T0+Abulk0*dT0_dVb;
    Abulk = Abulk * (load_T0);
    Abulk0_Q = Abulk0;
    Abulk0 = Abulk0 * (load_T0);
    if (sd_BSIM4ketac!=sd_BSIM4keta) begin
      load_T2 = sd_BSIM4ketac*Vbseff;
      if (load_T2>=-0.9) begin
        load_T0 = 1.0/(1.0+load_T2);
        dT0_dVb = -sd_BSIM4ketac*load_T0*load_T0;
      end else begin
        load_T1 = 1.0/(0.8+load_T2);
        load_T0 = (17.0+20.0*load_T2)*load_T1;
        dT0_dVb = -sd_BSIM4ketac*load_T1*load_T1;
      end
      dAbulk0_Q_dVb = dAbulk0_Q_dVb*load_T0+Abulk0_Q*dT0_dVb;
      Abulk0_Q = Abulk0_Q * (load_T0);
    end else begin
      dAbulk0_Q_dVb = dAbulk0_dVb;
      Abulk0_Q = Abulk0;
    end
    if (BSIM4mtrlMod&&BSIM4mtrlCompatMod==0) begin
      T14 = 2.0*BSIM4type*(phig-easub-0.5*BSIM4Eg0+0.45);
    end else begin
      T14 = 0.0;
    end
    if (BSIM4mobMod==0) begin
      load_T0 = load_Vgsteff+load_Vth+load_Vth-T14;
      load_T2 = sd_BSIM4ua+sd_BSIM4uc*Vbseff;
      load_T3 = load_T0/load_toxe;
      T12 = sqrt(load_Vth*load_Vth+0.0001);
      load_T9 = 1.0/(load_Vgsteff+2*T12);
      load_T10 = load_T9*load_toxe;
      load_T8 = sd_BSIM4ud*load_T10*load_T10*load_Vth;
      load_T6 = load_T8*load_Vth;
      load_T5 = load_T3*(load_T2+sd_BSIM4ub*load_T3)+load_T6;
      load_T7 = -2.0*load_T6*load_T9;
      load_T11 = load_T7*load_Vth/T12;
      dDenomi_dVg = (load_T2+2.0*sd_BSIM4ub*load_T3)/load_toxe;
      T13 = 2.0*(dDenomi_dVg+load_T11+load_T8);
      dDenomi_dVd = T13*dVth_dVd;
      dDenomi_dVb = T13*dVth_dVb+sd_BSIM4uc*load_T3;
      dDenomi_dVg = dDenomi_dVg + (load_T7);
    end else if (BSIM4mobMod==1) begin
      load_T0 = load_Vgsteff+load_Vth+load_Vth-T14;
      load_T2 = 1.0+sd_BSIM4uc*Vbseff;
      load_T3 = load_T0/load_toxe;
      load_T4 = load_T3*(sd_BSIM4ua+sd_BSIM4ub*load_T3);
      T12 = sqrt(load_Vth*load_Vth+0.0001);
      load_T9 = 1.0/(load_Vgsteff+2*T12);
      load_T10 = load_T9*load_toxe;
      load_T8 = sd_BSIM4ud*load_T10*load_T10*load_Vth;
      load_T6 = load_T8*load_Vth;
      load_T5 = load_T4*load_T2+load_T6;
      load_T7 = -2.0*load_T6*load_T9;
      load_T11 = load_T7*load_Vth/T12;
      dDenomi_dVg = (sd_BSIM4ua+2.0*sd_BSIM4ub*load_T3)*load_T2/load_toxe;
      T13 = 2.0*(dDenomi_dVg+load_T11+load_T8);
      dDenomi_dVd = T13*dVth_dVd;
      dDenomi_dVb = T13*dVth_dVb+sd_BSIM4uc*load_T4;
      dDenomi_dVg = dDenomi_dVg + (load_T7);
    end else if (BSIM4mobMod==2) begin
      load_T0 = (load_Vgsteff+BSIM4vtfbphi1)/load_toxe;
      load_T1 = exp(sd_BSIM4eu*ln(load_T0));
      dT1_dVg = load_T1*sd_BSIM4eu/load_T0/load_toxe;
      load_T2 = sd_BSIM4ua+sd_BSIM4uc*Vbseff;
      T12 = sqrt(load_Vth*load_Vth+0.0001);
      load_T9 = 1.0/(load_Vgsteff+2*T12);
      load_T10 = load_T9*load_toxe;
      load_T8 = sd_BSIM4ud*load_T10*load_T10*load_Vth;
      load_T6 = load_T8*load_Vth;
      load_T5 = load_T1*load_T2+load_T6;
      load_T7 = -2.0*load_T6*load_T9;
      load_T11 = load_T7*load_Vth/T12;
      dDenomi_dVg = load_T2*dT1_dVg+load_T7;
      T13 = 2.0*(load_T11+load_T8);
      dDenomi_dVd = T13*dVth_dVd;
      dDenomi_dVb = T13*dVth_dVb+load_T1*sd_BSIM4uc;
    end else if (BSIM4mobMod==4) begin
      load_T0 = load_Vgsteff+BSIM4vtfbphi1-T14;
      load_T2 = sd_BSIM4ua+sd_BSIM4uc*Vbseff;
      load_T3 = load_T0/load_toxe;
      T12 = sqrt(BSIM4vtfbphi1*BSIM4vtfbphi1+0.0001);
      load_T9 = 1.0/(load_Vgsteff+2*T12);
      load_T10 = load_T9*load_toxe;
      load_T8 = sd_BSIM4ud*load_T10*load_T10*BSIM4vtfbphi1;
      load_T6 = load_T8*BSIM4vtfbphi1;
      load_T5 = load_T3*(load_T2+sd_BSIM4ub*load_T3)+load_T6;
      load_T7 = -2.0*load_T6*load_T9;
      dDenomi_dVg = (load_T2+2.0*sd_BSIM4ub*load_T3)/load_toxe;
      dDenomi_dVd = 0.0;
      dDenomi_dVb = sd_BSIM4uc*load_T3;
      dDenomi_dVg = dDenomi_dVg + (load_T7);
    end else if (BSIM4mobMod==5) begin
      load_T0 = load_Vgsteff+BSIM4vtfbphi1-T14;
      load_T2 = 1.0+sd_BSIM4uc*Vbseff;
      load_T3 = load_T0/load_toxe;
      load_T4 = load_T3*(sd_BSIM4ua+sd_BSIM4ub*load_T3);
      T12 = sqrt(BSIM4vtfbphi1*BSIM4vtfbphi1+0.0001);
      load_T9 = 1.0/(load_Vgsteff+2*T12);
      load_T10 = load_T9*load_toxe;
      load_T8 = sd_BSIM4ud*load_T10*load_T10*BSIM4vtfbphi1;
      load_T6 = load_T8*BSIM4vtfbphi1;
      load_T5 = load_T4*load_T2+load_T6;
      load_T7 = -2.0*load_T6*load_T9;
      dDenomi_dVg = (sd_BSIM4ua+2.0*sd_BSIM4ub*load_T3)*load_T2/load_toxe;
      dDenomi_dVd = 0.0;
      dDenomi_dVb = sd_BSIM4uc*load_T4;
      dDenomi_dVg = dDenomi_dVg + (load_T7);
    end else if (BSIM4mobMod==6) begin
      load_T0 = (load_Vgsteff+BSIM4vtfbphi1)/load_toxe;
      load_T1 = exp(sd_BSIM4eu*ln(load_T0));
      dT1_dVg = load_T1*sd_BSIM4eu/load_T0/load_toxe;
      load_T2 = sd_BSIM4ua+sd_BSIM4uc*Vbseff;
      T12 = sqrt(BSIM4vtfbphi1*BSIM4vtfbphi1+0.0001);
      load_T9 = 1.0/(load_Vgsteff+2*T12);
      load_T10 = load_T9*load_toxe;
      load_T8 = sd_BSIM4ud*load_T10*load_T10*BSIM4vtfbphi1;
      load_T6 = load_T8*BSIM4vtfbphi1;
      load_T5 = load_T1*load_T2+load_T6;
      load_T7 = -2.0*load_T6*load_T9;
      dDenomi_dVg = load_T2*dT1_dVg+load_T7;
      dDenomi_dVd = 0;
      dDenomi_dVb = load_T1*sd_BSIM4uc;
    end else begin
      load_T0 = (load_Vgsteff+BSIM4vtfbphi1)*1.0e-8/load_toxe/6.0;
      load_T1 = exp(sd_BSIM4eu*ln(load_T0));
      dT1_dVg = load_T1*sd_BSIM4eu*1.0e-8/load_T0/load_toxe/6.0;
      load_T2 = sd_BSIM4ua+sd_BSIM4uc*Vbseff;
      VgsteffVth = BSIM4VgsteffVth;
      load_T10 = exp(sd_BSIM4ucs*ln(0.5+0.5*load_Vgsteff/VgsteffVth));
      load_T11 = sd_BSIM4ud/load_T10;
      dT11_dVg = -0.5*sd_BSIM4ucs*load_T11/(0.5+0.5*load_Vgsteff/VgsteffVth)/VgsteffVth;
      dDenomi_dVg = load_T2*dT1_dVg+dT11_dVg;
      dDenomi_dVd = 0.0;
      dDenomi_dVb = load_T1*sd_BSIM4uc;
      load_T5 = load_T1*load_T2+load_T11;
    end
    if (load_T5>=-0.8) begin
      Denomi = 1.0+load_T5;
    end else begin
      load_T9 = 1.0/(7.0+10.0*load_T5);
      Denomi = (0.6+load_T5)*load_T9;
      load_T9 = load_T9 * (load_T9);
      dDenomi_dVg = dDenomi_dVg * (load_T9);
      dDenomi_dVd = dDenomi_dVd * (load_T9);
      dDenomi_dVb = dDenomi_dVb * (load_T9);
    end
    ueff = BSIM4u0temp/Denomi;
    BSIM4ueff = ueff;
    load_T9 = -ueff/Denomi;
    dueff_dVg = load_T9*dDenomi_dVg;
    dueff_dVd = load_T9*dDenomi_dVd;
    dueff_dVb = load_T9*dDenomi_dVb;
    WVCox = Weff*BSIM4vsattemp*BSIM4coxe;
    WVCoxRds = WVCox*Rds;
    Esat = 2.0*BSIM4vsattemp/ueff;
    EsatL = Esat*Leff;
    BSIM4EsatL = EsatL;
    load_T0 = -EsatL/ueff;
    dEsatL_dVg = load_T0*dueff_dVg;
    dEsatL_dVd = load_T0*dueff_dVd;
    dEsatL_dVb = load_T0*dueff_dVb;
    load_a1 = sd_BSIM4a1;
    if (load_a1==0.0) begin
      Lambda = sd_BSIM4a2;
      dLambda_dVg = 0.0;
    end else if (load_a1>0.0) begin
      load_T0 = 1.0-sd_BSIM4a2;
      load_T1 = load_T0-sd_BSIM4a1*load_Vgsteff-0.0001;
      load_T2 = sqrt(load_T1*load_T1+0.0004*load_T0);
      Lambda = sd_BSIM4a2+load_T0-0.5*(load_T1+load_T2);
      dLambda_dVg = 0.5*sd_BSIM4a1*(1.0+load_T1/load_T2);
    end else begin
      load_T1 = sd_BSIM4a2+sd_BSIM4a1*load_Vgsteff-0.0001;
      load_T2 = sqrt(load_T1*load_T1+0.0004*sd_BSIM4a2);
      Lambda = 0.5*(load_T1+load_T2);
      dLambda_dVg = 0.5*sd_BSIM4a1*(1.0+load_T1/load_T2);
    end
    Vgst2Vtm = load_Vgsteff+2.0*Vtm;
    if (Rds>0) begin
      load_tmp2 = dRds_dVg/Rds+dWeff_dVg/Weff;
      load_tmp3 = dRds_dVb/Rds+dWeff_dVb/Weff;
    end else begin
      load_tmp2 = dWeff_dVg/Weff;
      load_tmp3 = dWeff_dVb/Weff;
    end
    if (Rds==0.0&&Lambda==1.0) begin
      load_T0 = 1.0/(Abulk*EsatL+Vgst2Vtm);
      load_tmp1 = 0.0;
      load_T1 = load_T0*load_T0;
      load_T2 = Vgst2Vtm*load_T0;
      load_T3 = EsatL*Vgst2Vtm;
      Vdsat = load_T3*load_T0;
      dT0_dVg = -(Abulk*dEsatL_dVg+EsatL*dAbulk_dVg+1.0)*load_T1;
      dT0_dVd = -(Abulk*dEsatL_dVd)*load_T1;
      dT0_dVb = -(Abulk*dEsatL_dVb+dAbulk_dVb*EsatL)*load_T1;
      dVdsat_dVg = load_T3*dT0_dVg+load_T2*dEsatL_dVg+EsatL*load_T0;
      dVdsat_dVd = load_T3*dT0_dVd+load_T2*dEsatL_dVd;
      dVdsat_dVb = load_T3*dT0_dVb+load_T2*dEsatL_dVb;
    end else begin
      load_tmp1 = dLambda_dVg/(Lambda*Lambda);
      load_T9 = Abulk*WVCoxRds;
      load_T8 = Abulk*load_T9;
      load_T7 = Vgst2Vtm*load_T9;
      load_T6 = Vgst2Vtm*WVCoxRds;
      load_T0 = 2.0*Abulk*(load_T9-1.0+1.0/Lambda);
      dT0_dVg = 2.0*(load_T8*load_tmp2-Abulk*load_tmp1+(2.0*load_T9+1.0/Lambda-1.0)*dAbulk_dVg);
      dT0_dVb = 2.0*(load_T8*(2.0/Abulk*dAbulk_dVb+load_tmp3)+(1.0/Lambda-1.0)*dAbulk_dVb);
      dT0_dVd = 0.0;
      load_T1 = Vgst2Vtm*(2.0/Lambda-1.0)+Abulk*EsatL+3.0*load_T7;
      dT1_dVg = 2.0/Lambda-1.0-2.0*Vgst2Vtm*load_tmp1+Abulk*dEsatL_dVg+EsatL*dAbulk_dVg+3.0*(load_T9+load_T7*load_tmp2+load_T6*dAbulk_dVg);
      dT1_dVb = Abulk*dEsatL_dVb+EsatL*dAbulk_dVb+3.0*(load_T6*dAbulk_dVb+load_T7*load_tmp3);
      dT1_dVd = Abulk*dEsatL_dVd;
      load_T2 = Vgst2Vtm*(EsatL+2.0*load_T6);
      dT2_dVg = EsatL+Vgst2Vtm*dEsatL_dVg+load_T6*(4.0+2.0*Vgst2Vtm*load_tmp2);
      dT2_dVb = Vgst2Vtm*(dEsatL_dVb+2.0*load_T6*load_tmp3);
      dT2_dVd = Vgst2Vtm*dEsatL_dVd;
      load_T3 = sqrt(load_T1*load_T1-2.0*load_T0*load_T2);
      Vdsat = (load_T1-load_T3)/load_T0;
      dT3_dVg = (load_T1*dT1_dVg-2.0*(load_T0*dT2_dVg+load_T2*dT0_dVg))/load_T3;
      dT3_dVd = (load_T1*dT1_dVd-2.0*(load_T0*dT2_dVd+load_T2*dT0_dVd))/load_T3;
      dT3_dVb = (load_T1*dT1_dVb-2.0*(load_T0*dT2_dVb+load_T2*dT0_dVb))/load_T3;
      dVdsat_dVg = (dT1_dVg-(load_T1*dT1_dVg-dT0_dVg*load_T2-load_T0*dT2_dVg)/load_T3-Vdsat*dT0_dVg)/load_T0;
      dVdsat_dVb = (dT1_dVb-(load_T1*dT1_dVb-dT0_dVb*load_T2-load_T0*dT2_dVb)/load_T3-Vdsat*dT0_dVb)/load_T0;
      dVdsat_dVd = (dT1_dVd-(load_T1*dT1_dVd-load_T0*dT2_dVd)/load_T3)/load_T0;
    end
    BSIM4vdsat = Vdsat;
    load_T1 = Vdsat-Vds-sd_BSIM4delta;
    dT1_dVg = dVdsat_dVg;
    dT1_dVd = dVdsat_dVd-1.0;
    dT1_dVb = dVdsat_dVb;
    load_T2 = sqrt(load_T1*load_T1+4.0*sd_BSIM4delta*Vdsat);
    load_T0 = load_T1/load_T2;
    load_T9 = 2.0*sd_BSIM4delta;
    load_T3 = load_T9/load_T2;
    dT2_dVg = load_T0*dT1_dVg+load_T3*dVdsat_dVg;
    dT2_dVd = load_T0*dT1_dVd+load_T3*dVdsat_dVd;
    dT2_dVb = load_T0*dT1_dVb+load_T3*dVdsat_dVb;
    if (load_T1>=0.0) begin
      Vdseff = Vdsat-0.5*(load_T1+load_T2);
      dVdseff_dVg = dVdsat_dVg-0.5*(dT1_dVg+dT2_dVg);
      dVdseff_dVd = dVdsat_dVd-0.5*(dT1_dVd+dT2_dVd);
      dVdseff_dVb = dVdsat_dVb-0.5*(dT1_dVb+dT2_dVb);
    end else begin
      load_T4 = load_T9/(load_T2-load_T1);
      load_T5 = 1.0-load_T4;
      load_T6 = Vdsat*load_T4/(load_T2-load_T1);
      Vdseff = Vdsat*load_T5;
      dVdseff_dVg = dVdsat_dVg*load_T5+load_T6*(dT2_dVg-dT1_dVg);
      dVdseff_dVd = dVdsat_dVd*load_T5+load_T6*(dT2_dVd-dT1_dVd);
      dVdseff_dVb = dVdsat_dVb*load_T5+load_T6*(dT2_dVb-dT1_dVb);
    end
    if (Vds==0.0) begin
      Vdseff = 0.0;
      dVdseff_dVg = 0.0;
      dVdseff_dVb = 0.0;
    end
    if (Vdseff>Vds) begin
      Vdseff = Vds;
    end
    diffVds = Vds-Vdseff;
    BSIM4Vdseff = Vdseff;
    if ($param_given(lambda)&&lambda>0.0) begin
      load_T1 = Leff*ueff;
      load_T2 = sd_BSIM4lambda/load_T1;
      load_T3 = -load_T2/load_T1*Leff;
      dT2_dVd = load_T3*dueff_dVd;
      dT2_dVg = load_T3*dueff_dVg;
      dT2_dVb = load_T3*dueff_dVb;
      load_T5 = 1.0/(Esat*BSIM4litl);
      load_T4 = -load_T5/EsatL;
      dT5_dVg = dEsatL_dVg*load_T4;
      dT5_dVd = dEsatL_dVd*load_T4;
      dT5_dVb = dEsatL_dVb*load_T4;
      load_T6 = 1.0+diffVds*load_T5;
      dT6_dVg = dT5_dVg*diffVds-dVdseff_dVg*load_T5;
      dT6_dVd = dT5_dVd*diffVds+(1.0-dVdseff_dVd)*load_T5;
      dT6_dVb = dT5_dVb*diffVds-dVdseff_dVb*load_T5;
      load_T7 = 2.0/(load_T6*load_T6+1.0);
      load_T8 = 1.0-load_T7;
      load_T9 = load_T6*load_T7*load_T7;
      dT8_dVg = load_T9*dT6_dVg;
      dT8_dVd = load_T9*dT6_dVd;
      dT8_dVb = load_T9*dT6_dVb;
      load_T10 = 1.0+load_T2*load_T8;
      dT10_dVg = dT2_dVg*load_T8+load_T2*dT8_dVg;
      dT10_dVd = dT2_dVd*load_T8+load_T2*dT8_dVd;
      dT10_dVb = dT2_dVb*load_T8+load_T2*dT8_dVb;
      if (load_T10==1.0) begin
        dT10_dVb = 0.0;
        dT10_dVd = dT10_dVb;
        dT10_dVg = dT10_dVd;
      end
      dEsatL_dVg = dEsatL_dVg * (load_T10);
      dEsatL_dVg = dEsatL_dVg + (EsatL*dT10_dVg);
      dEsatL_dVd = dEsatL_dVd * (load_T10);
      dEsatL_dVd = dEsatL_dVd + (EsatL*dT10_dVd);
      dEsatL_dVb = dEsatL_dVb * (load_T10);
      dEsatL_dVb = dEsatL_dVb + (EsatL*dT10_dVb);
      EsatL = EsatL * (load_T10);
      Esat = EsatL/Leff;
      BSIM4EsatL = EsatL;
    end
    tmp4 = 1.0-0.5*Abulk*Vdsat/Vgst2Vtm;
    load_T9 = WVCoxRds*load_Vgsteff;
    load_T8 = load_T9/Vgst2Vtm;
    load_T0 = EsatL+Vdsat+2.0*load_T9*tmp4;
    load_T7 = 2.0*WVCoxRds*tmp4;
    dT0_dVg = dEsatL_dVg+dVdsat_dVg+load_T7*(1.0+load_tmp2*load_Vgsteff)-load_T8*(Abulk*dVdsat_dVg-Abulk*Vdsat/Vgst2Vtm+Vdsat*dAbulk_dVg);
    dT0_dVb = dEsatL_dVb+dVdsat_dVb+load_T7*load_tmp3*load_Vgsteff-load_T8*(dAbulk_dVb*Vdsat+Abulk*dVdsat_dVb);
    dT0_dVd = dEsatL_dVd+dVdsat_dVd-load_T8*Abulk*dVdsat_dVd;
    load_T9 = WVCoxRds*Abulk;
    load_T1 = 2.0/Lambda-1.0+load_T9;
    dT1_dVg = -2.0*load_tmp1+WVCoxRds*(Abulk*load_tmp2+dAbulk_dVg);
    dT1_dVb = dAbulk_dVb*WVCoxRds+load_T9*load_tmp3;
    Vasat = load_T0/load_T1;
    dVasat_dVg = (dT0_dVg-Vasat*dT1_dVg)/load_T1;
    dVasat_dVb = (dT0_dVb-Vasat*dT1_dVb)/load_T1;
    dVasat_dVd = dT0_dVd/load_T1;
    load_tmp1 = BSIM4vtfbphi2;
    load_tmp2 = 2.0e8*i_BSIM4toxp;
    dT0_dVg = 1.0/load_tmp2;
    load_T0 = (load_Vgsteff+load_tmp1)*dT0_dVg;
    load_tmp3 = exp(bdos*0.7*ln(load_T0));
    load_T1 = 1.0+load_tmp3;
    load_T2 = bdos*0.7*load_tmp3/load_T0;
    load_Tcen = ados*1.9e-9/load_T1;
    dTcen_dVg = -load_Tcen*load_T2*dT0_dVg/load_T1;
    Coxeff = load_epssub*i_BSIM4coxp/(load_epssub+i_BSIM4coxp*load_Tcen);
    BSIM4Coxeff = Coxeff;
    dCoxeff_dVg = -Coxeff*Coxeff*dTcen_dVg/load_epssub;
    CoxeffWovL = Coxeff*Weff/Leff;
    beta = ueff*CoxeffWovL;
    load_T3 = ueff/Leff;
    dbeta_dVg = CoxeffWovL*dueff_dVg+load_T3*(Weff*dCoxeff_dVg+Coxeff*dWeff_dVg);
    dbeta_dVd = CoxeffWovL*dueff_dVd;
    dbeta_dVb = CoxeffWovL*dueff_dVb+load_T3*Coxeff*dWeff_dVb;
    BSIM4AbovVgst2Vtm = Abulk/Vgst2Vtm;
    load_T0 = 1.0-0.5*Vdseff*BSIM4AbovVgst2Vtm;
    dT0_dVg = -0.5*(Abulk*dVdseff_dVg-Abulk*Vdseff/Vgst2Vtm+Vdseff*dAbulk_dVg)/Vgst2Vtm;
    dT0_dVd = -0.5*Abulk*dVdseff_dVd/Vgst2Vtm;
    dT0_dVb = -0.5*(Abulk*dVdseff_dVb+dAbulk_dVb*Vdseff)/Vgst2Vtm;
    fgche1 = load_Vgsteff*load_T0;
    dfgche1_dVg = load_Vgsteff*dT0_dVg+load_T0;
    dfgche1_dVd = load_Vgsteff*dT0_dVd;
    dfgche1_dVb = load_Vgsteff*dT0_dVb;
    load_T9 = Vdseff/EsatL;
    fgche2 = 1.0+load_T9;
    dfgche2_dVg = (dVdseff_dVg-load_T9*dEsatL_dVg)/EsatL;
    dfgche2_dVd = (dVdseff_dVd-load_T9*dEsatL_dVd)/EsatL;
    dfgche2_dVb = (dVdseff_dVb-load_T9*dEsatL_dVb)/EsatL;
    gche = beta*fgche1/fgche2;
    dgche_dVg = (beta*dfgche1_dVg+fgche1*dbeta_dVg-gche*dfgche2_dVg)/fgche2;
    dgche_dVd = (beta*dfgche1_dVd+fgche1*dbeta_dVd-gche*dfgche2_dVd)/fgche2;
    dgche_dVb = (beta*dfgche1_dVb+fgche1*dbeta_dVb-gche*dfgche2_dVb)/fgche2;
    load_T0 = 1.0+gche*Rds;
    Idl = gche/load_T0;
    load_T1 = (1.0-Idl*Rds)/load_T0;
    load_T2 = Idl*Idl;
    dIdl_dVg = load_T1*dgche_dVg-load_T2*dRds_dVg;
    dIdl_dVd = load_T1*dgche_dVd;
    dIdl_dVb = load_T1*dgche_dVb-load_T2*dRds_dVb;
    if (sd_BSIM4fprout<=0.0) begin
      FP = 1.0;
      dFP_dVg = 0.0;
    end else begin
      load_T9 = sd_BSIM4fprout*sqrt(Leff)/Vgst2Vtm;
      FP = 1.0/(1.0+load_T9);
      dFP_dVg = FP*FP*load_T9/Vgst2Vtm;
    end
    load_T8 = sd_BSIM4pvag/EsatL;
    load_T9 = load_T8*load_Vgsteff;
    if (load_T9>-0.9) begin
      PvagTerm = 1.0+load_T9;
      dPvagTerm_dVg = load_T8*(1.0-load_Vgsteff*dEsatL_dVg/EsatL);
      dPvagTerm_dVb = -load_T9*dEsatL_dVb/EsatL;
      dPvagTerm_dVd = -load_T9*dEsatL_dVd/EsatL;
    end else begin
      load_T4 = 1.0/(17.0+20.0*load_T9);
      PvagTerm = (0.8+load_T9)*load_T4;
      load_T4 = load_T4 * (load_T4);
      dPvagTerm_dVg = load_T8*(1.0-load_Vgsteff*dEsatL_dVg/EsatL)*load_T4;
      load_T9 = load_T9 * (load_T4/EsatL);
      dPvagTerm_dVb = -load_T9*dEsatL_dVb;
      dPvagTerm_dVd = -load_T9*dEsatL_dVd;
    end
    if (sd_BSIM4pclm>1.713908431e-15&&diffVds>1.0e-10) begin
      load_T0 = 1.0+Rds*Idl;
      dT0_dVg = dRds_dVg*Idl+Rds*dIdl_dVg;
      dT0_dVd = Rds*dIdl_dVd;
      dT0_dVb = dRds_dVb*Idl+Rds*dIdl_dVb;
      load_T2 = Vdsat/Esat;
      load_T1 = Leff+load_T2;
      dT1_dVg = (dVdsat_dVg-load_T2*dEsatL_dVg/Leff)/Esat;
      dT1_dVd = (dVdsat_dVd-load_T2*dEsatL_dVd/Leff)/Esat;
      dT1_dVb = (dVdsat_dVb-load_T2*dEsatL_dVb/Leff)/Esat;
      Cclm = FP*PvagTerm*load_T0*load_T1/(sd_BSIM4pclm*BSIM4litl);
      dCclm_dVg = Cclm*(dFP_dVg/FP+dPvagTerm_dVg/PvagTerm+dT0_dVg/load_T0+dT1_dVg/load_T1);
      dCclm_dVb = Cclm*(dPvagTerm_dVb/PvagTerm+dT0_dVb/load_T0+dT1_dVb/load_T1);
      dCclm_dVd = Cclm*(dPvagTerm_dVd/PvagTerm+dT0_dVd/load_T0+dT1_dVd/load_T1);
      VACLM = Cclm*diffVds;
      dVACLM_dVg = dCclm_dVg*diffVds-dVdseff_dVg*Cclm;
      dVACLM_dVb = dCclm_dVb*diffVds-dVdseff_dVb*Cclm;
      dVACLM_dVd = dCclm_dVd*diffVds+(1.0-dVdseff_dVd)*Cclm;
    end else begin
      Cclm = 5.834617425e14;
      VACLM = Cclm;
      dVACLM_dVb = 0.0;
      dVACLM_dVg = dVACLM_dVb;
      dVACLM_dVd = dVACLM_dVg;
      dCclm_dVb = 0.0;
      dCclm_dVg = dCclm_dVb;
      dCclm_dVd = dCclm_dVg;
    end
    if (BSIM4thetaRout>1.713908431e-15) begin
      load_T8 = Abulk*Vdsat;
      load_T0 = Vgst2Vtm*load_T8;
      dT0_dVg = Vgst2Vtm*Abulk*dVdsat_dVg+load_T8+Vgst2Vtm*Vdsat*dAbulk_dVg;
      dT0_dVb = Vgst2Vtm*(dAbulk_dVb*Vdsat+Abulk*dVdsat_dVb);
      dT0_dVd = Vgst2Vtm*Abulk*dVdsat_dVd;
      load_T1 = Vgst2Vtm+load_T8;
      dT1_dVg = 1.0+Abulk*dVdsat_dVg+Vdsat*dAbulk_dVg;
      dT1_dVb = Abulk*dVdsat_dVb+dAbulk_dVb*Vdsat;
      dT1_dVd = Abulk*dVdsat_dVd;
      load_T9 = load_T1*load_T1;
      load_T2 = BSIM4thetaRout;
      VADIBL = (Vgst2Vtm-load_T0/load_T1)/load_T2;
      dVADIBL_dVg = (1.0-dT0_dVg/load_T1+load_T0*dT1_dVg/load_T9)/load_T2;
      dVADIBL_dVb = (-dT0_dVb/load_T1+load_T0*dT1_dVb/load_T9)/load_T2;
      dVADIBL_dVd = (-dT0_dVd/load_T1+load_T0*dT1_dVd/load_T9)/load_T2;
      load_T7 = sd_BSIM4pdiblb*Vbseff;
      if (load_T7>=-0.9) begin
        load_T3 = 1.0/(1.0+load_T7);
        VADIBL = VADIBL * (load_T3);
        dVADIBL_dVg = dVADIBL_dVg * (load_T3);
        dVADIBL_dVb = (dVADIBL_dVb-VADIBL*sd_BSIM4pdiblb)*load_T3;
        dVADIBL_dVd = dVADIBL_dVd * (load_T3);
      end else begin
        load_T4 = 1.0/(0.8+load_T7);
        load_T3 = (17.0+20.0*load_T7)*load_T4;
        dVADIBL_dVg = dVADIBL_dVg * (load_T3);
        dVADIBL_dVb = dVADIBL_dVb*load_T3-VADIBL*sd_BSIM4pdiblb*load_T4*load_T4;
        dVADIBL_dVd = dVADIBL_dVd * (load_T3);
        VADIBL = VADIBL * (load_T3);
      end
      dVADIBL_dVg = dVADIBL_dVg*PvagTerm+VADIBL*dPvagTerm_dVg;
      dVADIBL_dVb = dVADIBL_dVb*PvagTerm+VADIBL*dPvagTerm_dVb;
      dVADIBL_dVd = dVADIBL_dVd*PvagTerm+VADIBL*dPvagTerm_dVd;
      VADIBL = VADIBL * (PvagTerm);
    end else begin
      VADIBL = 5.834617425e14;
      dVADIBL_dVb = 0.0;
      dVADIBL_dVg = dVADIBL_dVb;
      dVADIBL_dVd = dVADIBL_dVg;
    end
    Va = Vasat+VACLM;
    dVa_dVg = dVasat_dVg+dVACLM_dVg;
    dVa_dVb = dVasat_dVb+dVACLM_dVb;
    dVa_dVd = dVasat_dVd+dVACLM_dVd;
    load_T0 = sd_BSIM4pditsd*Vds;
    if (load_T0>34.0) begin
      load_T1 = 5.834617425e14;
      dT1_dVd = 0;
    end else begin
      load_T1 = exp(load_T0);
      dT1_dVd = load_T1*sd_BSIM4pditsd;
    end
    if (sd_BSIM4pdits>1.713908431e-15) begin
      load_T2 = 1.0+pditsl*Leff;
      VADITS = (1.0+load_T2*load_T1)/sd_BSIM4pdits;
      dVADITS_dVg = VADITS*dFP_dVg;
      dVADITS_dVd = FP*load_T2*dT1_dVd/sd_BSIM4pdits;
      VADITS = VADITS * (FP);
    end else begin
      VADITS = 5.834617425e14;
      dVADITS_dVd = 0;
      dVADITS_dVg = dVADITS_dVd;
    end
    if (sd_BSIM4pscbe2>0.0&&sd_BSIM4pscbe1>=0.0) begin
      if (diffVds>sd_BSIM4pscbe1*BSIM4litl/34.0) begin
        load_T0 = sd_BSIM4pscbe1*BSIM4litl/diffVds;
        VASCBE = Leff*exp(load_T0)/sd_BSIM4pscbe2;
        load_T1 = load_T0*VASCBE/diffVds;
        dVASCBE_dVg = load_T1*dVdseff_dVg;
        dVASCBE_dVd = -load_T1*(1.0-dVdseff_dVd);
        dVASCBE_dVb = load_T1*dVdseff_dVb;
      end else begin
        VASCBE = 5.834617425e14*Leff/sd_BSIM4pscbe2;
        dVASCBE_dVb = 0.0;
        dVASCBE_dVd = dVASCBE_dVb;
        dVASCBE_dVg = dVASCBE_dVd;
      end
    end else begin
      VASCBE = 5.834617425e14;
      dVASCBE_dVb = 0.0;
      dVASCBE_dVd = dVASCBE_dVb;
      dVASCBE_dVg = dVASCBE_dVd;
    end
    load_T9 = diffVds/VADIBL;
    load_T0 = 1.0+load_T9;
    Idsa = Idl*load_T0;
    dIdsa_dVg = load_T0*dIdl_dVg-Idl*(dVdseff_dVg+load_T9*dVADIBL_dVg)/VADIBL;
    dIdsa_dVd = load_T0*dIdl_dVd+Idl*(1.0-dVdseff_dVd-load_T9*dVADIBL_dVd)/VADIBL;
    dIdsa_dVb = load_T0*dIdl_dVb-Idl*(dVdseff_dVb+load_T9*dVADIBL_dVb)/VADIBL;
    load_T9 = diffVds/VADITS;
    load_T0 = 1.0+load_T9;
    dIdsa_dVg = load_T0*dIdsa_dVg-Idsa*(dVdseff_dVg+load_T9*dVADITS_dVg)/VADITS;
    dIdsa_dVd = load_T0*dIdsa_dVd+Idsa*(1.0-dVdseff_dVd-load_T9*dVADITS_dVd)/VADITS;
    dIdsa_dVb = load_T0*dIdsa_dVb-Idsa*dVdseff_dVb/VADITS;
    Idsa = Idsa * (load_T0);
    load_T0 = ln(Va/Vasat);
    dT0_dVg = dVa_dVg/Va-dVasat_dVg/Vasat;
    dT0_dVb = dVa_dVb/Va-dVasat_dVb/Vasat;
    dT0_dVd = dVa_dVd/Va-dVasat_dVd/Vasat;
    load_T1 = load_T0/Cclm;
    load_T9 = 1.0+load_T1;
    dT9_dVg = (dT0_dVg-load_T1*dCclm_dVg)/Cclm;
    dT9_dVb = (dT0_dVb-load_T1*dCclm_dVb)/Cclm;
    dT9_dVd = (dT0_dVd-load_T1*dCclm_dVd)/Cclm;
    dIdsa_dVg = dIdsa_dVg*load_T9+Idsa*dT9_dVg;
    dIdsa_dVb = dIdsa_dVb*load_T9+Idsa*dT9_dVb;
    dIdsa_dVd = dIdsa_dVd*load_T9+Idsa*dT9_dVd;
    Idsa = Idsa * (load_T9);
    load_tmp = sd_BSIM4alpha0+sd_BSIM4alpha1*Leff;
    if (load_tmp<=0.0||sd_BSIM4beta0<=0.0) begin
      Gbg = 0.0;
      Gbb = Gbg;
      Gbd = Gbb;
      Isub = Gbd;
    end else begin
      load_T2 = load_tmp/Leff;
      if (diffVds>sd_BSIM4beta0/34.0) begin
        load_T0 = -sd_BSIM4beta0/diffVds;
        load_T1 = load_T2*diffVds*exp(load_T0);
        load_T3 = load_T1/diffVds*(load_T0-1.0);
        dT1_dVg = load_T3*dVdseff_dVg;
        dT1_dVd = load_T3*(dVdseff_dVd-1.0);
        dT1_dVb = load_T3*dVdseff_dVb;
      end else begin
        load_T3 = load_T2*1.713908431e-15;
        load_T1 = load_T3*diffVds;
        dT1_dVg = -load_T3*dVdseff_dVg;
        dT1_dVd = load_T3*(1.0-dVdseff_dVd);
        dT1_dVb = -load_T3*dVdseff_dVb;
      end
      load_T4 = Idsa*Vdseff;
      Isub = load_T1*load_T4;
      Gbg = load_T1*(dIdsa_dVg*Vdseff+Idsa*dVdseff_dVg)+load_T4*dT1_dVg;
      Gbd = load_T1*(dIdsa_dVd*Vdseff+Idsa*dVdseff_dVd)+load_T4*dT1_dVd;
      Gbb = load_T1*(dIdsa_dVb*Vdseff+Idsa*dVdseff_dVb)+load_T4*dT1_dVb;
      Gbd = Gbd + (Gbg*dVgsteff_dVd);
      Gbb = Gbb + (Gbg*dVgsteff_dVb);
      Gbg = Gbg * (dVgsteff_dVg);
      Gbb = Gbb * (dVbseff_dVb);
    end
    BSIM4csub = Isub;
    BSIM4gbbs = Gbb;
    BSIM4gbgs = Gbg;
    BSIM4gbds = Gbd;
    load_T9 = diffVds/VASCBE;
    load_T0 = 1.0+load_T9;
    Ids = Idsa*load_T0;
    Gm = load_T0*dIdsa_dVg-Idsa*(dVdseff_dVg+load_T9*dVASCBE_dVg)/VASCBE;
    Gds = load_T0*dIdsa_dVd+Idsa*(1.0-dVdseff_dVd-load_T9*dVASCBE_dVd)/VASCBE;
    Gmb = load_T0*dIdsa_dVb-Idsa*(dVdseff_dVb+load_T9*dVASCBE_dVb)/VASCBE;
    load_tmp1 = Gds;
    load_tmp2 = Gmb;
    load_tmp3 = 0;
    Gm = (Ids*dVdseff_dVg+Vdseff*load_tmp3)*dVgsteff_dVg;
    Gds = Ids*(dVdseff_dVd+dVdseff_dVg*dVgsteff_dVd)+Vdseff*load_tmp1;
    Gmb = (Ids*(dVdseff_dVb+dVdseff_dVg*dVgsteff_dVb)+Vdseff*load_tmp2)*dVbseff_dVb;
    cdrain = Ids*Vdseff;
    if ($param_given(vtl)&&vtl>0.0) begin
      T12 = 1.0/Leff/CoxeffWovL;
      load_T11 = T12/load_Vgsteff;
      load_T10 = -load_T11/load_Vgsteff;
      vs = cdrain*load_T11;
      dvs_dVg = cdrain*load_T10*dVgsteff_dVg;
      dvs_dVd = Gds*load_T11+cdrain*load_T10*dVgsteff_dVd;
      dvs_dVb = Gmb*load_T11+cdrain*load_T10*dVgsteff_dVb;
      load_T0 = 2*3;
      load_T1 = vs/(sd_BSIM4vtl*BSIM4tfactor);
      if (load_T1>0.0) begin
        load_T2 = 1.0+exp(load_T0*ln(load_T1));
        load_T3 = (load_T2-1.0)*load_T0/vs;
        Fsevl = 1.0/exp(ln(load_T2)/load_T0);
        dT2_dVg = load_T3*dvs_dVg;
        dT2_dVd = load_T3*dvs_dVd;
        dT2_dVb = load_T3*dvs_dVb;
        load_T4 = -1.0/load_T0*Fsevl/load_T2;
        dFsevl_dVg = load_T4*dT2_dVg;
        dFsevl_dVd = load_T4*dT2_dVd;
        dFsevl_dVb = load_T4*dT2_dVb;
      end else begin
        Fsevl = 1.0;
        dFsevl_dVg = 0.0;
        dFsevl_dVd = 0.0;
        dFsevl_dVb = 0.0;
      end
      Gm = Gm * (Fsevl);
      Gm = Gm + (cdrain*dFsevl_dVg);
      Gmb = Gmb * (Fsevl);
      Gmb = Gmb + (cdrain*dFsevl_dVb);
      Gds = Gds * (Fsevl);
      Gds = Gds + (cdrain*dFsevl_dVd);
      cdrain = cdrain * (Fsevl);
    end
    BSIM4gds = Gds;
    BSIM4gm = Gm;
    BSIM4gmbs = Gmb;
    BSIM4IdovVds = Ids;
    if (BSIM4IdovVds<=idovvds) begin
      BSIM4IdovVds = idovvds;
    end
    if (i_BSIM4rgateMod>1||i_BSIM4trnqsMod!=0||i_BSIM4acnqsMod!=0) begin
      load_T9 = sd_BSIM4xrcrg2*BSIM4vtm;
      load_T0 = load_T9*beta;
      dT0_dVd = (dbeta_dVd+dbeta_dVg*dVgsteff_dVd)*load_T9;
      dT0_dVb = (dbeta_dVb+dbeta_dVg*dVgsteff_dVb)*load_T9;
      dT0_dVg = dbeta_dVg*load_T9;
      BSIM4gcrg = sd_BSIM4xrcrg1*(load_T0+Ids);
      BSIM4gcrgd = sd_BSIM4xrcrg1*(dT0_dVd+load_tmp1);
      BSIM4gcrgb = sd_BSIM4xrcrg1*(dT0_dVb+load_tmp2)*dVbseff_dVb;
      BSIM4gcrgg = sd_BSIM4xrcrg1*(dT0_dVg+load_tmp3)*dVgsteff_dVg;
      if (nf!=1.0) begin
        BSIM4gcrg = BSIM4gcrg * (nf);
        BSIM4gcrgg = BSIM4gcrgg * (nf);
        BSIM4gcrgd = BSIM4gcrgd * (nf);
        BSIM4gcrgb = BSIM4gcrgb * (nf);
      end
      if (i_BSIM4rgateMod==2) begin
        load_T10 = BSIM4grgeltd*BSIM4grgeltd;
        load_T11 = BSIM4grgeltd+BSIM4gcrg;
        BSIM4gcrg = BSIM4grgeltd*BSIM4gcrg/load_T11;
        T12 = load_T10/load_T11/load_T11;
        BSIM4gcrgg = BSIM4gcrgg * (T12);
        BSIM4gcrgd = BSIM4gcrgd * (T12);
        BSIM4gcrgb = BSIM4gcrgb * (T12);
      end
      BSIM4gcrgs = -(BSIM4gcrgg+BSIM4gcrgd+BSIM4gcrgb);
    end
    if (BSIM4rdsMod) begin
      load_T0 = load_vgs-BSIM4vfbsd;
      load_T1 = sqrt(load_T0*load_T0+1.0e-4);
      vgs_eff = 0.5*(load_T0+load_T1);
      dvgs_eff_dvg = vgs_eff/load_T1;
      load_T0 = 1.0+sd_BSIM4prwg*vgs_eff;
      dT0_dvg = -sd_BSIM4prwg/load_T0/load_T0*dvgs_eff_dvg;
      load_T1 = -sd_BSIM4prwb*load_vbs;
      dT1_dvb = -sd_BSIM4prwb;
      load_T2 = 1.0/load_T0+load_T1;
      load_T3 = load_T2+sqrt(load_T2*load_T2+0.01);
      dT3_dvg = load_T3/(load_T3-load_T2);
      dT3_dvb = dT3_dvg*dT1_dvb;
      dT3_dvg = dT3_dvg * (dT0_dvg);
      load_T4 = BSIM4rs0*0.5;
      Rs = sd_BSIM4rswmin+load_T3*load_T4;
      dRs_dvg = load_T4*dT3_dvg;
      dRs_dvb = load_T4*dT3_dvb;
      load_T0 = 1.0+BSIM4sourceConductance*Rs;
      BSIM4gstot = BSIM4sourceConductance/load_T0;
      load_T0 = -BSIM4gstot*BSIM4gstot;
      dgstot_dvd = 0.0;
      dgstot_dvg = load_T0*dRs_dvg;
      dgstot_dvb = load_T0*dRs_dvb;
      dgstot_dvs = -(dgstot_dvg+dgstot_dvb+dgstot_dvd);
      load_T0 = vgd-BSIM4vfbsd;
      load_T1 = sqrt(load_T0*load_T0+1.0e-4);
      vgd_eff = 0.5*(load_T0+load_T1);
      dvgd_eff_dvg = vgd_eff/load_T1;
      load_T0 = 1.0+sd_BSIM4prwg*vgd_eff;
      dT0_dvg = -sd_BSIM4prwg/load_T0/load_T0*dvgd_eff_dvg;
      load_T1 = -sd_BSIM4prwb*vbd;
      dT1_dvb = -sd_BSIM4prwb;
      load_T2 = 1.0/load_T0+load_T1;
      load_T3 = load_T2+sqrt(load_T2*load_T2+0.01);
      dT3_dvg = load_T3/(load_T3-load_T2);
      dT3_dvb = dT3_dvg*dT1_dvb;
      dT3_dvg = dT3_dvg * (dT0_dvg);
      load_T4 = BSIM4rd0*0.5;
      Rd = sd_BSIM4rdwmin+load_T3*load_T4;
      dRd_dvg = load_T4*dT3_dvg;
      dRd_dvb = load_T4*dT3_dvb;
      load_T0 = 1.0+BSIM4drainConductance*Rd;
      BSIM4gdtot = BSIM4drainConductance/load_T0;
      load_T0 = -BSIM4gdtot*BSIM4gdtot;
      dgdtot_dvs = 0.0;
      dgdtot_dvg = load_T0*dRd_dvg;
      dgdtot_dvb = load_T0*dRd_dvb;
      dgdtot_dvd = -(dgdtot_dvg+dgdtot_dvb+dgdtot_dvs);
      BSIM4gstotd = vses*dgstot_dvd;
      BSIM4gstotg = vses*dgstot_dvg;
      BSIM4gstots = vses*dgstot_dvs;
      BSIM4gstotb = vses*dgstot_dvb;
      load_T2 = vdes-load_vds;
      BSIM4gdtotd = load_T2*dgdtot_dvd;
      BSIM4gdtotg = load_T2*dgdtot_dvg;
      BSIM4gdtots = load_T2*dgdtot_dvs;
      BSIM4gdtotb = load_T2*dgdtot_dvb;
    end else begin
      BSIM4gstotg = 0.0;
      BSIM4gstotd = BSIM4gstotg;
      BSIM4gstot = BSIM4gstotd;
      BSIM4gstotb = 0.0;
      BSIM4gstots = BSIM4gstotb;
      BSIM4gdtotg = 0.0;
      BSIM4gdtotd = BSIM4gdtotg;
      BSIM4gdtot = BSIM4gdtotd;
      BSIM4gdtotb = 0.0;
      BSIM4gdtots = BSIM4gdtotb;
    end
    if (BSIM4mtrlMod==0) begin
      load_T0 = 3.0*load_toxe;
    end else begin
      load_T0 = epsrsub*load_toxe/load_epsrox;
    end
    vgs_eff = BSIM4vgs_eff;
    dvgs_eff_dvg = BSIM4dvgs_eff_dvg;
    vgd_eff = BSIM4vgd_eff;
    dvgd_eff_dvg = BSIM4dvgd_eff_dvg;
    if (gidlmod==0) begin
      if (BSIM4mtrlMod==0) begin
        load_T1 = (load_vds-vgs_eff-sd_BSIM4egidl)/load_T0;
      end else begin
        load_T1 = (load_vds-vgs_eff-sd_BSIM4egidl+BSIM4vfbsd)/load_T0;
      end
      if (sd_BSIM4agidl<=0.0||sd_BSIM4bgidl<=0.0||load_T1<=0.0||sd_BSIM4cgidl<=0.0||vbd>0.0) begin
        Ggidlb = 0.0;
        Ggidlg = Ggidlb;
        Ggidld = Ggidlg;
        Igidl = Ggidld;
      end else begin
        dT1_dVd = 1.0/load_T0;
        dT1_dVg = -dvgs_eff_dvg*dT1_dVd;
        load_T2 = sd_BSIM4bgidl/load_T1;
        if (load_T2<100.0) begin
          Igidl = sd_BSIM4agidl*BSIM4weffCJ*load_T1*exp(-load_T2);
          load_T3 = Igidl*(1.0+load_T2)/load_T1;
          Ggidld = load_T3*dT1_dVd;
          Ggidlg = load_T3*dT1_dVg;
        end else begin
          Igidl = sd_BSIM4agidl*BSIM4weffCJ*3.720075976e-44;
          Ggidld = Igidl*dT1_dVd;
          Ggidlg = Igidl*dT1_dVg;
          Igidl = Igidl * (load_T1);
        end
        load_T4 = vbd*vbd;
        load_T5 = -vbd*load_T4;
        load_T6 = sd_BSIM4cgidl+load_T5;
        load_T7 = load_T5/load_T6;
        load_T8 = 3.0*sd_BSIM4cgidl*load_T4/load_T6/load_T6;
        Ggidld = Ggidld*load_T7+Igidl*load_T8;
        Ggidlg = Ggidlg*load_T7;
        Ggidlb = -Igidl*load_T8;
        Igidl = Igidl * (load_T7);
      end
      BSIM4Igidl = Igidl;
      BSIM4ggidld = Ggidld;
      BSIM4ggidlg = Ggidlg;
      BSIM4ggidlb = Ggidlb;
      if (BSIM4mtrlMod==0) begin
        load_T1 = (-load_vds-vgd_eff-sd_BSIM4egisl)/load_T0;
      end else begin
        load_T1 = (-load_vds-vgd_eff-sd_BSIM4egisl+BSIM4vfbsd)/load_T0;
      end
      if (sd_BSIM4agisl<=0.0||sd_BSIM4bgisl<=0.0||load_T1<=0.0||sd_BSIM4cgisl<=0.0||load_vbs>0.0) begin
        Ggislb = 0.0;
        Ggislg = Ggislb;
        Ggisls = Ggislg;
        Igisl = Ggisls;
      end else begin
        dT1_dVd = 1.0/load_T0;
        dT1_dVg = -dvgd_eff_dvg*dT1_dVd;
        load_T2 = sd_BSIM4bgisl/load_T1;
        if (load_T2<100.0) begin
          Igisl = sd_BSIM4agisl*BSIM4weffCJ*load_T1*exp(-load_T2);
          load_T3 = Igisl*(1.0+load_T2)/load_T1;
          Ggisls = load_T3*dT1_dVd;
          Ggislg = load_T3*dT1_dVg;
        end else begin
          Igisl = sd_BSIM4agisl*BSIM4weffCJ*3.720075976e-44;
          Ggisls = Igisl*dT1_dVd;
          Ggislg = Igisl*dT1_dVg;
          Igisl = Igisl * (load_T1);
        end
        load_T4 = load_vbs*load_vbs;
        load_T5 = -load_vbs*load_T4;
        load_T6 = sd_BSIM4cgisl+load_T5;
        load_T7 = load_T5/load_T6;
        load_T8 = 3.0*sd_BSIM4cgisl*load_T4/load_T6/load_T6;
        Ggisls = Ggisls*load_T7+Igisl*load_T8;
        Ggislg = Ggislg*load_T7;
        Ggislb = -Igisl*load_T8;
        Igisl = Igisl * (load_T7);
      end
      BSIM4Igisl = Igisl;
      BSIM4ggisls = Ggisls;
      BSIM4ggislg = Ggislg;
      BSIM4ggislb = Ggislb;
    end else begin
      if (BSIM4mtrlMod==0) begin
        load_T1 = (-load_vds-sd_BSIM4rgisl*vgd_eff-sd_BSIM4egisl)/load_T0;
      end else begin
        load_T1 = (-load_vds-sd_BSIM4rgisl*vgd_eff-sd_BSIM4egisl+BSIM4vfbsd)/load_T0;
      end
      if (sd_BSIM4agisl<=0.0||sd_BSIM4bgisl<=0.0||load_T1<=0.0||sd_BSIM4cgisl<0.0) begin
        Ggislb = 0.0;
        Ggislg = Ggislb;
        Ggisls = Ggislg;
        Igisl = Ggisls;
      end else begin
        dT1_dVd = 1/load_T0;
        dT1_dVg = -sd_BSIM4rgisl*dT1_dVd*dvgd_eff_dvg;
        load_T2 = sd_BSIM4bgisl/load_T1;
        if (load_T2<100.0) begin
          Igisl = BSIM4weffCJ*sd_BSIM4agisl*load_T1*exp(-load_T2);
          load_T3 = Igisl/load_T1*(load_T2+1);
          Ggisls = load_T3*dT1_dVd;
          Ggislg = load_T3*dT1_dVg;
        end else begin
          load_T3 = BSIM4weffCJ*sd_BSIM4agisl*3.720075976e-44;
          Igisl = load_T3*load_T1;
          Ggisls = load_T3*dT1_dVd;
          Ggislg = load_T3*dT1_dVg;
        end
        load_T4 = load_vbs-sd_BSIM4fgisl;
        if (load_T4>BSIM4gidlclamp) begin
          load_T4 = BSIM4gidlclamp;
        end
        if (load_T4==0) begin
          load_T5 = 100.0;
        end else begin
          load_T5 = sd_BSIM4kgisl/load_T4;
        end
        if (load_T5<100.0) begin
          load_T6 = exp(load_T5);
          Ggislb = -Igisl*load_T6*load_T5/load_T4;
        end else begin
          load_T6 = 2.688117142e+43;
          Ggislb = 0.0;
        end
        Ggisls = Ggisls * (load_T6);
        Ggislg = Ggislg * (load_T6);
        Igisl = Igisl * (load_T6);
      end
      BSIM4Igisl = Igisl;
      BSIM4ggisls = Ggisls;
      BSIM4ggislg = Ggislg;
      BSIM4ggislb = Ggislb;
      if (BSIM4mtrlMod==0) begin
        load_T1 = (load_vds-sd_BSIM4rgidl*vgs_eff-sd_BSIM4egidl)/load_T0;
      end else begin
        load_T1 = (load_vds-sd_BSIM4rgidl*vgs_eff-sd_BSIM4egidl+BSIM4vfbsd)/load_T0;
      end
      if (sd_BSIM4agidl<=0.0||sd_BSIM4bgidl<=0.0||load_T1<=0.0||sd_BSIM4cgidl<0.0) begin
        Ggidlb = 0.0;
        Ggidlg = Ggidlb;
        Ggidld = Ggidlg;
        Igidl = Ggidld;
      end else begin
        dT1_dVd = 1/load_T0;
        dT1_dVg = -sd_BSIM4rgidl*dT1_dVd*dvgs_eff_dvg;
        load_T2 = sd_BSIM4bgidl/load_T1;
        if (load_T2<100.0) begin
          Igidl = BSIM4weffCJ*sd_BSIM4agidl*load_T1*exp(-load_T2);
          load_T3 = Igidl/load_T1*(load_T2+1);
          Ggidld = load_T3*dT1_dVd;
          Ggidlg = load_T3*dT1_dVg;
        end else begin
          load_T3 = BSIM4weffCJ*sd_BSIM4agidl*3.720075976e-44;
          Igidl = load_T3*load_T1;
          Ggidld = load_T3*dT1_dVd;
          Ggidlg = load_T3*dT1_dVg;
        end
        load_T4 = vbd-sd_BSIM4fgidl;
        if (load_T4>BSIM4gidlclamp) begin
          load_T4 = BSIM4gidlclamp;
        end
        if (load_T4==0) begin
          load_T5 = 100.0;
        end else begin
          load_T5 = sd_BSIM4kgidl/load_T4;
        end
        if (load_T5<100.0) begin
          load_T6 = exp(load_T5);
          Ggidlb = -Igidl*load_T6*load_T5/load_T4;
        end else begin
          load_T6 = 2.688117142e+43;
          Ggidlb = 0.0;
        end
        Ggidld = Ggidld * (load_T6);
        Ggidlg = Ggidlg * (load_T6);
        Igidl = Igidl * (load_T6);
      end
      BSIM4Igidl = Igidl;
      BSIM4ggidld = Ggidld;
      BSIM4ggidlg = Ggidlg;
      BSIM4ggidlb = Ggidlb;
    end
    if (BSIM4igcMod!=0||BSIM4igbMod!=0) begin
      Vfb = BSIM4vfbzb;
      V3 = Vfb-load_Vgs_eff+Vbseff-0.02;
      if (Vfb<=0.0) begin
        load_T0 = sqrt(V3*V3-4.0*0.02*Vfb);
      end else begin
        load_T0 = sqrt(V3*V3+4.0*0.02*Vfb);
      end
      load_T1 = 0.5*(1.0+V3/load_T0);
      Vfbeff = Vfb-0.5*(V3+load_T0);
      dVfbeff_dVg = load_T1*dVgs_eff_dVg;
      dVfbeff_dVb = -load_T1;
      Voxacc = Vfb-Vfbeff;
      dVoxacc_dVg = -dVfbeff_dVg;
      dVoxacc_dVb = -dVfbeff_dVb;
      if (Voxacc<0.0) begin
        dVoxacc_dVb = 0.0;
        dVoxacc_dVg = dVoxacc_dVb;
        Voxacc = dVoxacc_dVg;
      end
      load_T0 = 0.5*BSIM4k1ox;
      load_T3 = load_Vgs_eff-Vfbeff-Vbseff-load_Vgsteff;
      if (BSIM4k1ox==0.0) begin
        dVoxdepinv_dVb = 0.0;
        dVoxdepinv_dVd = dVoxdepinv_dVb;
        dVoxdepinv_dVg = dVoxdepinv_dVd;
        Voxdepinv = dVoxdepinv_dVg;
      end else if (load_T3<0.0) begin
        Voxdepinv = -load_T3;
        dVoxdepinv_dVg = -dVgs_eff_dVg+dVfbeff_dVg+dVgsteff_dVg;
        dVoxdepinv_dVd = dVgsteff_dVd;
        dVoxdepinv_dVb = dVfbeff_dVb+1.0+dVgsteff_dVb;
      end else begin
        load_T1 = sqrt(load_T0*load_T0+load_T3);
        load_T2 = load_T0/load_T1;
        Voxdepinv = BSIM4k1ox*(load_T1-load_T0);
        dVoxdepinv_dVg = load_T2*(dVgs_eff_dVg-dVfbeff_dVg-dVgsteff_dVg);
        dVoxdepinv_dVd = -load_T2*dVgsteff_dVd;
        dVoxdepinv_dVb = -load_T2*(dVfbeff_dVb+1.0+dVgsteff_dVb);
      end
      Voxdepinv = Voxdepinv + (load_Vgsteff);
      dVoxdepinv_dVg = dVoxdepinv_dVg + (dVgsteff_dVg);
      dVoxdepinv_dVd = dVoxdepinv_dVd + (dVgsteff_dVd);
      dVoxdepinv_dVb = dVoxdepinv_dVb + (dVgsteff_dVb);
    end
    if (BSIM4tempMod<2) begin
      load_tmp = Vtm;
    end else begin
      load_tmp = load_Vtm0;
    end
    if (BSIM4igcMod) begin
      load_T0 = load_tmp*sd_BSIM4nigc;
      if (BSIM4igcMod==1) begin
        VxNVt = (load_Vgs_eff-BSIM4type*i_BSIM4vth0)/load_T0;
        if (VxNVt>34.0) begin
          Vaux = load_Vgs_eff-BSIM4type*i_BSIM4vth0;
          dVaux_dVg = dVgs_eff_dVg;
          dVaux_dVd = 0.0;
          dVaux_dVb = 0.0;
        end
      end else if (BSIM4igcMod==2) begin
        VxNVt = (load_Vgs_eff-BSIM4von)/load_T0;
        if (VxNVt>34.0) begin
          Vaux = load_Vgs_eff-BSIM4von;
          dVaux_dVg = dVgs_eff_dVg;
          dVaux_dVd = -dVth_dVd;
          dVaux_dVb = -dVth_dVb;
        end
      end
      if (VxNVt<-34.0) begin
        Vaux = load_T0*ln(1.0+1.713908431e-15);
        dVaux_dVb = 0.0;
        dVaux_dVd = dVaux_dVb;
        dVaux_dVg = dVaux_dVd;
      end else if (VxNVt>=-34.0&&VxNVt<=34.0) begin
        ExpVxNVt = exp(VxNVt);
        Vaux = load_T0*ln(1.0+ExpVxNVt);
        dVaux_dVg = ExpVxNVt/(1.0+ExpVxNVt);
        if (BSIM4igcMod==1) begin
          dVaux_dVd = 0.0;
          dVaux_dVb = 0.0;
        end else if (BSIM4igcMod==2) begin
          dVaux_dVd = -dVaux_dVg*dVth_dVd;
          dVaux_dVb = -dVaux_dVg*dVth_dVb;
        end
        dVaux_dVg = dVaux_dVg * (dVgs_eff_dVg);
      end
      load_T2 = Vgs*Vaux;
      dT2_dVg = Vaux+Vgs*dVaux_dVg;
      dT2_dVd = Vgs*dVaux_dVd;
      dT2_dVb = Vgs*dVaux_dVb;
      load_T11 = BSIM4Aechvb;
      T12 = BSIM4Bechvb;
      load_T3 = sd_BSIM4aigc*sd_BSIM4cigc-sd_BSIM4bigc;
      load_T4 = sd_BSIM4bigc*sd_BSIM4cigc;
      load_T5 = T12*(sd_BSIM4aigc+load_T3*Voxdepinv-load_T4*Voxdepinv*Voxdepinv);
      if (load_T5>34.0) begin
        load_T6 = 5.834617425e14;
        dT6_dVb = 0.0;
        dT6_dVd = dT6_dVb;
        dT6_dVg = dT6_dVd;
      end else if (load_T5<-34.0) begin
        load_T6 = 1.713908431e-15;
        dT6_dVb = 0.0;
        dT6_dVd = dT6_dVb;
        dT6_dVg = dT6_dVd;
      end else begin
        load_T6 = exp(load_T5);
        dT6_dVg = load_T6*T12*(load_T3-2.0*load_T4*Voxdepinv);
        dT6_dVd = dT6_dVg*dVoxdepinv_dVd;
        dT6_dVb = dT6_dVg*dVoxdepinv_dVb;
        dT6_dVg = dT6_dVg * (dVoxdepinv_dVg);
      end
      Igc = load_T11*load_T2*load_T6;
      dIgc_dVg = load_T11*(load_T2*dT6_dVg+load_T6*dT2_dVg);
      dIgc_dVd = load_T11*(load_T2*dT6_dVd+load_T6*dT2_dVd);
      dIgc_dVb = load_T11*(load_T2*dT6_dVb+load_T6*dT2_dVb);
      if ($param_given(pigcd)) begin
        Pigcd = sd_BSIM4pigcd;
        dPigcd_dVb = 0.0;
        dPigcd_dVd = dPigcd_dVb;
        dPigcd_dVg = dPigcd_dVd;
      end else begin
        load_T11 = -BSIM4Bechvb;
        T12 = load_Vgsteff+1.0e-20;
        T13 = load_T11/T12/T12;
        T14 = -T13/T12;
        Pigcd = T13*(1.0-0.5*Vdseff/T12);
        dPigcd_dVg = T14*(2.0+0.5*(dVdseff_dVg-3.0*Vdseff/T12));
        dPigcd_dVd = 0.5*T14*dVdseff_dVd;
        dPigcd_dVb = 0.5*T14*dVdseff_dVb;
      end
      load_T7 = -Pigcd*Vdseff;
      dT7_dVg = -Vdseff*dPigcd_dVg-Pigcd*dVdseff_dVg;
      dT7_dVd = -Vdseff*dPigcd_dVd-Pigcd*dVdseff_dVd+dT7_dVg*dVgsteff_dVd;
      dT7_dVb = -Vdseff*dPigcd_dVb-Pigcd*dVdseff_dVb+dT7_dVg*dVgsteff_dVb;
      dT7_dVg = dT7_dVg * (dVgsteff_dVg);
      load_T8 = load_T7*load_T7+2.0e-4;
      dT8_dVg = 2.0*load_T7;
      dT8_dVd = dT8_dVg*dT7_dVd;
      dT8_dVb = dT8_dVg*dT7_dVb;
      dT8_dVg = dT8_dVg * (dT7_dVg);
      if (load_T7>34.0) begin
        load_T9 = 5.834617425e14;
        dT9_dVb = 0.0;
        dT9_dVd = dT9_dVb;
        dT9_dVg = dT9_dVd;
      end else if (load_T7<-34.0) begin
        load_T9 = 1.713908431e-15;
        dT9_dVb = 0.0;
        dT9_dVd = dT9_dVb;
        dT9_dVg = dT9_dVd;
      end else begin
        load_T9 = exp(load_T7);
        dT9_dVg = load_T9*dT7_dVg;
        dT9_dVd = load_T9*dT7_dVd;
        dT9_dVb = load_T9*dT7_dVb;
      end
      load_T0 = load_T8*load_T8;
      load_T1 = load_T9-1.0+1.0e-4;
      load_T10 = (load_T1-load_T7)/load_T8;
      dT10_dVg = (dT9_dVg-dT7_dVg-load_T10*dT8_dVg)/load_T8;
      dT10_dVd = (dT9_dVd-dT7_dVd-load_T10*dT8_dVd)/load_T8;
      dT10_dVb = (dT9_dVb-dT7_dVb-load_T10*dT8_dVb)/load_T8;
      Igcs = Igc*load_T10;
      dIgcs_dVg = dIgc_dVg*load_T10+Igc*dT10_dVg;
      dIgcs_dVd = dIgc_dVd*load_T10+Igc*dT10_dVd;
      dIgcs_dVb = dIgc_dVb*load_T10+Igc*dT10_dVb;
      load_T1 = load_T9-1.0-1.0e-4;
      load_T10 = (load_T7*load_T9-load_T1)/load_T8;
      dT10_dVg = (dT7_dVg*load_T9+(load_T7-1.0)*dT9_dVg-load_T10*dT8_dVg)/load_T8;
      dT10_dVd = (dT7_dVd*load_T9+(load_T7-1.0)*dT9_dVd-load_T10*dT8_dVd)/load_T8;
      dT10_dVb = (dT7_dVb*load_T9+(load_T7-1.0)*dT9_dVb-load_T10*dT8_dVb)/load_T8;
      Igcd = Igc*load_T10;
      dIgcd_dVg = dIgc_dVg*load_T10+Igc*dT10_dVg;
      dIgcd_dVd = dIgc_dVd*load_T10+Igc*dT10_dVd;
      dIgcd_dVb = dIgc_dVb*load_T10+Igc*dT10_dVb;
      BSIM4Igcs = Igcs;
      BSIM4gIgcsg = dIgcs_dVg;
      BSIM4gIgcsd = dIgcs_dVd;
      BSIM4gIgcsb = dIgcs_dVb*dVbseff_dVb;
      BSIM4Igcd = Igcd;
      BSIM4gIgcdg = dIgcd_dVg;
      BSIM4gIgcdd = dIgcd_dVd;
      BSIM4gIgcdb = dIgcd_dVb*dVbseff_dVb;
      load_T0 = load_vgs-(BSIM4vfbsd+sd_BSIM4vfbsdoff);
      vgs_eff = sqrt(load_T0*load_T0+1.0e-4);
      dvgs_eff_dvg = load_T0/vgs_eff;
      load_T2 = load_vgs*vgs_eff;
      dT2_dVg = load_vgs*dvgs_eff_dvg+vgs_eff;
      load_T11 = BSIM4AechvbEdgeS;
      T12 = BSIM4BechvbEdge;
      load_T3 = sd_BSIM4aigs*sd_BSIM4cigs-sd_BSIM4bigs;
      load_T4 = sd_BSIM4bigs*sd_BSIM4cigs;
      load_T5 = T12*(sd_BSIM4aigs+load_T3*vgs_eff-load_T4*vgs_eff*vgs_eff);
      if (load_T5>34.0) begin
        load_T6 = 5.834617425e14;
        dT6_dVg = 0.0;
      end else if (load_T5<-34.0) begin
        load_T6 = 1.713908431e-15;
        dT6_dVg = 0.0;
      end else begin
        load_T6 = exp(load_T5);
        dT6_dVg = load_T6*T12*(load_T3-2.0*load_T4*vgs_eff)*dvgs_eff_dvg;
      end
      Igs = load_T11*load_T2*load_T6;
      dIgs_dVg = load_T11*(load_T2*dT6_dVg+load_T6*dT2_dVg);
      dIgs_dVs = -dIgs_dVg;
      load_T0 = vgd-(BSIM4vfbsd+sd_BSIM4vfbsdoff);
      vgd_eff = sqrt(load_T0*load_T0+1.0e-4);
      dvgd_eff_dvg = load_T0/vgd_eff;
      load_T2 = vgd*vgd_eff;
      dT2_dVg = vgd*dvgd_eff_dvg+vgd_eff;
      load_T11 = BSIM4AechvbEdgeD;
      load_T3 = sd_BSIM4aigd*sd_BSIM4cigd-sd_BSIM4bigd;
      load_T4 = sd_BSIM4bigd*sd_BSIM4cigd;
      load_T5 = T12*(sd_BSIM4aigd+load_T3*vgd_eff-load_T4*vgd_eff*vgd_eff);
      if (load_T5>34.0) begin
        load_T6 = 5.834617425e14;
        dT6_dVg = 0.0;
      end else if (load_T5<-34.0) begin
        load_T6 = 1.713908431e-15;
        dT6_dVg = 0.0;
      end else begin
        load_T6 = exp(load_T5);
        dT6_dVg = load_T6*T12*(load_T3-2.0*load_T4*vgd_eff)*dvgd_eff_dvg;
      end
      Igd = load_T11*load_T2*load_T6;
      dIgd_dVg = load_T11*(load_T2*dT6_dVg+load_T6*dT2_dVg);
      dIgd_dVd = -dIgd_dVg;
      BSIM4Igs = Igs;
      BSIM4gIgsg = dIgs_dVg;
      BSIM4gIgss = dIgs_dVs;
      BSIM4Igd = Igd;
      BSIM4gIgdg = dIgd_dVg;
      BSIM4gIgdd = dIgd_dVd;
    end else begin
      BSIM4gIgcsb = 0.0;
      BSIM4gIgcsd = BSIM4gIgcsb;
      BSIM4gIgcsg = BSIM4gIgcsd;
      BSIM4Igcs = 0;
      BSIM4gIgcdb = 0.0;
      BSIM4gIgcdd = BSIM4gIgcdb;
      BSIM4gIgcdg = BSIM4gIgcdd;
      BSIM4Igcd = 0;
      BSIM4gIgss = 0.0;
      BSIM4gIgsg = BSIM4gIgss;
      BSIM4Igs = 0;
      BSIM4gIgdd = 0.0;
      BSIM4gIgdg = BSIM4gIgdd;
      BSIM4Igd = 0;
    end
    if (BSIM4igbMod) begin
      load_T0 = load_tmp*sd_BSIM4nigbacc;
      load_T1 = -load_Vgs_eff+Vbseff+Vfb;
      VxNVt = load_T1/load_T0;
      if (VxNVt>34.0) begin
        Vaux = load_T1;
        dVaux_dVg = -dVgs_eff_dVg;
        dVaux_dVb = 1.0;
      end else if (VxNVt<-34.0) begin
        Vaux = load_T0*ln(1.0+1.713908431e-15);
        dVaux_dVb = 0.0;
        dVaux_dVg = dVaux_dVb;
      end else begin
        ExpVxNVt = exp(VxNVt);
        Vaux = load_T0*ln(1.0+ExpVxNVt);
        dVaux_dVb = ExpVxNVt/(1.0+ExpVxNVt);
        dVaux_dVg = -dVaux_dVb*dVgs_eff_dVg;
      end
      load_T2 = (Vgs-Vbs)*Vaux;
      dT2_dVg = Vaux+(Vgs-Vbs)*dVaux_dVg;
      dT2_dVb = -Vaux+(Vgs-Vbs)*dVaux_dVb;
      load_T11 = 4.97232e-7*BSIM4weff*BSIM4leff*BSIM4ToxRatio;
      T12 = -7.45669e11*load_toxe;
      load_T3 = sd_BSIM4aigbacc*sd_BSIM4cigbacc-sd_BSIM4bigbacc;
      load_T4 = sd_BSIM4bigbacc*sd_BSIM4cigbacc;
      load_T5 = T12*(sd_BSIM4aigbacc+load_T3*Voxacc-load_T4*Voxacc*Voxacc);
      if (load_T5>34.0) begin
        load_T6 = 5.834617425e14;
        dT6_dVb = 0.0;
        dT6_dVg = dT6_dVb;
      end else if (load_T5<-34.0) begin
        load_T6 = 1.713908431e-15;
        dT6_dVb = 0.0;
        dT6_dVg = dT6_dVb;
      end else begin
        load_T6 = exp(load_T5);
        dT6_dVg = load_T6*T12*(load_T3-2.0*load_T4*Voxacc);
        dT6_dVb = dT6_dVg*dVoxacc_dVb;
        dT6_dVg = dT6_dVg * (dVoxacc_dVg);
      end
      Igbacc = load_T11*load_T2*load_T6;
      dIgbacc_dVg = load_T11*(load_T2*dT6_dVg+load_T6*dT2_dVg);
      dIgbacc_dVb = load_T11*(load_T2*dT6_dVb+load_T6*dT2_dVb);
      load_T0 = load_tmp*sd_BSIM4nigbinv;
      load_T1 = Voxdepinv-sd_BSIM4eigbinv;
      VxNVt = load_T1/load_T0;
      if (VxNVt>34.0) begin
        Vaux = load_T1;
        dVaux_dVg = dVoxdepinv_dVg;
        dVaux_dVd = dVoxdepinv_dVd;
        dVaux_dVb = dVoxdepinv_dVb;
      end else if (VxNVt<-34.0) begin
        Vaux = load_T0*ln(1.0+1.713908431e-15);
        dVaux_dVb = 0.0;
        dVaux_dVd = dVaux_dVb;
        dVaux_dVg = dVaux_dVd;
      end else begin
        ExpVxNVt = exp(VxNVt);
        Vaux = load_T0*ln(1.0+ExpVxNVt);
        dVaux_dVg = ExpVxNVt/(1.0+ExpVxNVt);
        dVaux_dVd = dVaux_dVg*dVoxdepinv_dVd;
        dVaux_dVb = dVaux_dVg*dVoxdepinv_dVb;
        dVaux_dVg = dVaux_dVg * (dVoxdepinv_dVg);
      end
      load_T2 = (Vgs-Vbs)*Vaux;
      dT2_dVg = Vaux+(Vgs-Vbs)*dVaux_dVg;
      dT2_dVd = (Vgs-Vbs)*dVaux_dVd;
      dT2_dVb = -Vaux+(Vgs-Vbs)*dVaux_dVb;
      load_T11 = load_T11 * (0.75610);
      T12 = T12 * (1.31724);
      load_T3 = sd_BSIM4aigbinv*sd_BSIM4cigbinv-sd_BSIM4bigbinv;
      load_T4 = sd_BSIM4bigbinv*sd_BSIM4cigbinv;
      load_T5 = T12*(sd_BSIM4aigbinv+load_T3*Voxdepinv-load_T4*Voxdepinv*Voxdepinv);
      if (load_T5>34.0) begin
        load_T6 = 5.834617425e14;
        dT6_dVb = 0.0;
        dT6_dVd = dT6_dVb;
        dT6_dVg = dT6_dVd;
      end else if (load_T5<-34.0) begin
        load_T6 = 1.713908431e-15;
        dT6_dVb = 0.0;
        dT6_dVd = dT6_dVb;
        dT6_dVg = dT6_dVd;
      end else begin
        load_T6 = exp(load_T5);
        dT6_dVg = load_T6*T12*(load_T3-2.0*load_T4*Voxdepinv);
        dT6_dVd = dT6_dVg*dVoxdepinv_dVd;
        dT6_dVb = dT6_dVg*dVoxdepinv_dVb;
        dT6_dVg = dT6_dVg * (dVoxdepinv_dVg);
      end
      Igbinv = load_T11*load_T2*load_T6;
      dIgbinv_dVg = load_T11*(load_T2*dT6_dVg+load_T6*dT2_dVg);
      dIgbinv_dVd = load_T11*(load_T2*dT6_dVd+load_T6*dT2_dVd);
      dIgbinv_dVb = load_T11*(load_T2*dT6_dVb+load_T6*dT2_dVb);
      BSIM4Igb = Igbinv+Igbacc;
      BSIM4gIgbg = dIgbinv_dVg+dIgbacc_dVg;
      BSIM4gIgbd = dIgbinv_dVd;
      BSIM4gIgbb = (dIgbinv_dVb+dIgbacc_dVb)*dVbseff_dVb;
    end else begin
      BSIM4gIgbb = 0.0;
      BSIM4gIgbs = BSIM4gIgbb;
      BSIM4gIgbd = BSIM4gIgbs;
      BSIM4gIgbg = BSIM4gIgbd;
      BSIM4Igb = 0;
    end
    if (nf!=1.0) begin
      cdrain = cdrain * (nf);
      BSIM4gds = BSIM4gds * (nf);
      BSIM4gm = BSIM4gm * (nf);
      BSIM4gmbs = BSIM4gmbs * (nf);
      BSIM4IdovVds = BSIM4IdovVds * (nf);
      BSIM4gbbs = BSIM4gbbs * (nf);
      BSIM4gbgs = BSIM4gbgs * (nf);
      BSIM4gbds = BSIM4gbds * (nf);
      BSIM4csub = BSIM4csub * (nf);
      BSIM4Igidl = BSIM4Igidl * (nf);
      BSIM4ggidld = BSIM4ggidld * (nf);
      BSIM4ggidlg = BSIM4ggidlg * (nf);
      BSIM4ggidlb = BSIM4ggidlb * (nf);
      BSIM4Igisl = BSIM4Igisl * (nf);
      BSIM4ggisls = BSIM4ggisls * (nf);
      BSIM4ggislg = BSIM4ggislg * (nf);
      BSIM4ggislb = BSIM4ggislb * (nf);
      BSIM4Igcs = BSIM4Igcs * (nf);
      BSIM4gIgcsg = BSIM4gIgcsg * (nf);
      BSIM4gIgcsd = BSIM4gIgcsd * (nf);
      BSIM4gIgcsb = BSIM4gIgcsb * (nf);
      BSIM4Igcd = BSIM4Igcd * (nf);
      BSIM4gIgcdg = BSIM4gIgcdg * (nf);
      BSIM4gIgcdd = BSIM4gIgcdd * (nf);
      BSIM4gIgcdb = BSIM4gIgcdb * (nf);
      BSIM4Igs = BSIM4Igs * (nf);
      BSIM4gIgsg = BSIM4gIgsg * (nf);
      BSIM4gIgss = BSIM4gIgss * (nf);
      BSIM4Igd = BSIM4Igd * (nf);
      BSIM4gIgdg = BSIM4gIgdg * (nf);
      BSIM4gIgdd = BSIM4gIgdd * (nf);
      BSIM4Igb = BSIM4Igb * (nf);
      BSIM4gIgbg = BSIM4gIgbg * (nf);
      BSIM4gIgbd = BSIM4gIgbd * (nf);
      BSIM4gIgbb = BSIM4gIgbb * (nf);
    end
    BSIM4ggidls = -(BSIM4ggidld+BSIM4ggidlg+BSIM4ggidlb);
    BSIM4ggisld = -(BSIM4ggisls+BSIM4ggislg+BSIM4ggislb);
    BSIM4gIgbs = -(BSIM4gIgbg+BSIM4gIgbd+BSIM4gIgbb);
    BSIM4gIgcss = -(BSIM4gIgcsg+BSIM4gIgcsd+BSIM4gIgcsb);
    BSIM4gIgcds = -(BSIM4gIgcdg+BSIM4gIgcdd+BSIM4gIgcdb);
    BSIM4cd = cdrain;
    if (BSIM4tnoiMod==0) begin
      Abulk = Abulk0_Q*BSIM4abulkCVfactor;
      Vdsat = load_Vgsteff/Abulk;
      load_T0 = Vdsat-Vds-0.02;
      load_T1 = sqrt(load_T0*load_T0+4.0*0.02*Vdsat);
      if (load_T0>=0.0) begin
        Vdseff = Vdsat-0.5*(load_T0+load_T1);
      end else begin
        load_T3 = (0.02+0.02)/(load_T1-load_T0);
        load_T4 = 1.0-load_T3;
        load_T5 = Vdsat*load_T3/(load_T1-load_T0);
        Vdseff = Vdsat*load_T4;
      end
      if (Vds==0.0) begin
        Vdseff = 0.0;
      end
      load_T0 = Abulk*Vdseff;
      load_T1 = 12.0*(load_Vgsteff-0.5*load_T0+1.0e-20);
      load_T2 = Vdseff/load_T1;
      load_T3 = load_T0*load_T2;
      BSIM4qinv = Coxeff*BSIM4weffCV*nf*BSIM4leffCV*(load_Vgsteff-0.5*load_T0+Abulk*load_T3);
    end else if (BSIM4tnoiMod==2) begin
      BSIM4noiGd0 = nf*beta*load_Vgsteff/(1.0+gche*Rds);
    end
    if (xpart<0||!1) begin
      qbulk = 0.0;
      qsrc = qbulk;
      qdrn = qsrc;
      qgate = qdrn;
      BSIM4cgdb = 0.0;
      BSIM4cgsb = BSIM4cgdb;
      BSIM4cggb = BSIM4cgsb;
      BSIM4cddb = 0.0;
      BSIM4cdsb = BSIM4cddb;
      BSIM4cdgb = BSIM4cdsb;
      BSIM4cbdb = 0.0;
      BSIM4cbsb = BSIM4cbdb;
      BSIM4cbgb = BSIM4cbsb;
      BSIM4csdb = 0.0;
      BSIM4cssb = BSIM4csdb;
      BSIM4csgb = BSIM4cssb;
      BSIM4cbbb = 0.0;
      BSIM4cdbb = BSIM4cbbb;
      BSIM4csbb = BSIM4cdbb;
      BSIM4cgbb = BSIM4csbb;
      BSIM4cqbb = 0.0;
      BSIM4cqgb = BSIM4cqbb;
      BSIM4cqsb = BSIM4cqgb;
      BSIM4cqdb = BSIM4cqsb;
      BSIM4gtau = 0.0;
      goto_destination = finished1;
    end else if (BSIM4capMod==0) begin
      if (Vbseff<0.0) begin
        VbseffCV = Vbs;
        dVbseffCV_dVb = 1.0;
      end else begin
        VbseffCV = BSIM4phi-Phis;
        dVbseffCV_dVb = -dPhis_dVb*dVbseff_dVb;
      end
      Vfb = sd_BSIM4vfbcv;
      load_Vth = Vfb+BSIM4phi+BSIM4k1ox*sqrtPhis;
      Vgst = load_Vgs_eff-load_Vth;
      dVth_dVb = BSIM4k1ox*dsqrtPhis_dVb*dVbseff_dVb;
      dVgst_dVb = -dVth_dVb;
      dVgst_dVg = dVgs_eff_dVg;
      CoxWL = BSIM4coxe*BSIM4weffCV*BSIM4leffCV*nf;
      Arg1 = load_Vgs_eff-VbseffCV-Vfb;
      if (Arg1<=0.0) begin
        qgate = CoxWL*Arg1;
        qbulk = -qgate;
        qdrn = 0.0;
        BSIM4cggb = CoxWL*dVgs_eff_dVg;
        BSIM4cgdb = 0.0;
        BSIM4cgsb = CoxWL*(dVbseffCV_dVb-dVgs_eff_dVg);
        BSIM4cdgb = 0.0;
        BSIM4cddb = 0.0;
        BSIM4cdsb = 0.0;
        BSIM4cbgb = -CoxWL*dVgs_eff_dVg;
        BSIM4cbdb = 0.0;
        BSIM4cbsb = -BSIM4cgsb;
      end else if (Vgst<=0.0) begin
        load_T1 = 0.5*BSIM4k1ox;
        load_T2 = sqrt(load_T1*load_T1+Arg1);
        qgate = CoxWL*BSIM4k1ox*(load_T2-load_T1);
        qbulk = -qgate;
        qdrn = 0.0;
        load_T0 = CoxWL*load_T1/load_T2;
        BSIM4cggb = load_T0*dVgs_eff_dVg;
        BSIM4cgdb = 0.0;
        BSIM4cgsb = load_T0*(dVbseffCV_dVb-dVgs_eff_dVg);
        BSIM4cdgb = 0.0;
        BSIM4cddb = 0.0;
        BSIM4cdsb = 0.0;
        BSIM4cbgb = -BSIM4cggb;
        BSIM4cbdb = 0.0;
        BSIM4cbsb = -BSIM4cgsb;
      end else begin
        One_Third_CoxWL = CoxWL/3.0;
        Two_Third_CoxWL = 2.0*One_Third_CoxWL;
        AbulkCV = Abulk0_Q*BSIM4abulkCVfactor;
        dAbulkCV_dVb = BSIM4abulkCVfactor*dAbulk0_Q_dVb*dVbseff_dVb;
        dVdsat_dVg = 1.0/AbulkCV;
        Vdsat = Vgst*dVdsat_dVg;
        dVdsat_dVb = -(Vdsat*dAbulkCV_dVb+dVth_dVb)*dVdsat_dVg;
        if (xpart>0.5) begin
          if (Vdsat<=Vds) begin
            load_T1 = Vdsat/3.0;
            qgate = CoxWL*(load_Vgs_eff-Vfb-BSIM4phi-load_T1);
            load_T2 = -Two_Third_CoxWL*Vgst;
            qbulk = -(qgate+load_T2);
            qdrn = 0.0;
            BSIM4cggb = One_Third_CoxWL*(3.0-dVdsat_dVg)*dVgs_eff_dVg;
            load_T2 = -One_Third_CoxWL*dVdsat_dVb;
            BSIM4cgsb = -(BSIM4cggb+load_T2);
            BSIM4cgdb = 0.0;
            BSIM4cdgb = 0.0;
            BSIM4cddb = 0.0;
            BSIM4cdsb = 0.0;
            BSIM4cbgb = -(BSIM4cggb-Two_Third_CoxWL*dVgs_eff_dVg);
            load_T3 = -(load_T2+Two_Third_CoxWL*dVth_dVb);
            BSIM4cbsb = -(BSIM4cbgb+load_T3);
            BSIM4cbdb = 0.0;
          end else begin
            Alphaz = Vgst/Vdsat;
            load_T1 = 2.0*Vdsat-Vds;
            load_T2 = Vds/(3.0*load_T1);
            load_T3 = load_T2*Vds;
            load_T9 = 0.25*CoxWL;
            load_T4 = load_T9*Alphaz;
            load_T7 = 2.0*Vds-load_T1-3.0*load_T3;
            load_T8 = load_T3-load_T1-2.0*Vds;
            qgate = CoxWL*(load_Vgs_eff-Vfb-BSIM4phi-0.5*(Vds-load_T3));
            load_T10 = load_T4*load_T8;
            qdrn = load_T4*load_T7;
            qbulk = -(qgate+qdrn+load_T10);
            load_T5 = load_T3/load_T1;
            BSIM4cggb = CoxWL*(1.0-load_T5*dVdsat_dVg)*dVgs_eff_dVg;
            load_T11 = -CoxWL*load_T5*dVdsat_dVb;
            BSIM4cgdb = CoxWL*(load_T2-0.5+0.5*load_T5);
            BSIM4cgsb = -(BSIM4cggb+load_T11+BSIM4cgdb);
            load_T6 = 1.0/Vdsat;
            dAlphaz_dVg = load_T6*(1.0-Alphaz*dVdsat_dVg);
            dAlphaz_dVb = -load_T6*(dVth_dVb+Alphaz*dVdsat_dVb);
            load_T7 = load_T9*load_T7;
            load_T8 = load_T9*load_T8;
            load_T9 = 2.0*load_T4*(1.0-3.0*load_T5);
            BSIM4cdgb = (load_T7*dAlphaz_dVg-load_T9*dVdsat_dVg)*dVgs_eff_dVg;
            T12 = load_T7*dAlphaz_dVb-load_T9*dVdsat_dVb;
            BSIM4cddb = load_T4*(3.0-6.0*load_T2-3.0*load_T5);
            BSIM4cdsb = -(BSIM4cdgb+T12+BSIM4cddb);
            load_T9 = 2.0*load_T4*(1.0+load_T5);
            load_T10 = (load_T8*dAlphaz_dVg-load_T9*dVdsat_dVg)*dVgs_eff_dVg;
            load_T11 = load_T8*dAlphaz_dVb-load_T9*dVdsat_dVb;
            T12 = load_T4*(2.0*load_T2+load_T5-1.0);
            load_T0 = -(load_T10+load_T11+T12);
            BSIM4cbgb = -(BSIM4cggb+BSIM4cdgb+load_T10);
            BSIM4cbdb = -(BSIM4cgdb+BSIM4cddb+T12);
            BSIM4cbsb = -(BSIM4cgsb+BSIM4cdsb+load_T0);
          end
        end else if (xpart<0.5) begin
          if (Vds>=Vdsat) begin
            load_T1 = Vdsat/3.0;
            qgate = CoxWL*(load_Vgs_eff-Vfb-BSIM4phi-load_T1);
            load_T2 = -Two_Third_CoxWL*Vgst;
            qbulk = -(qgate+load_T2);
            qdrn = 0.4*load_T2;
            BSIM4cggb = One_Third_CoxWL*(3.0-dVdsat_dVg)*dVgs_eff_dVg;
            load_T2 = -One_Third_CoxWL*dVdsat_dVb;
            BSIM4cgsb = -(BSIM4cggb+load_T2);
            BSIM4cgdb = 0.0;
            load_T3 = 0.4*Two_Third_CoxWL;
            BSIM4cdgb = -load_T3*dVgs_eff_dVg;
            BSIM4cddb = 0.0;
            load_T4 = load_T3*dVth_dVb;
            BSIM4cdsb = -(load_T4+BSIM4cdgb);
            BSIM4cbgb = -(BSIM4cggb-Two_Third_CoxWL*dVgs_eff_dVg);
            load_T3 = -(load_T2+Two_Third_CoxWL*dVth_dVb);
            BSIM4cbsb = -(BSIM4cbgb+load_T3);
            BSIM4cbdb = 0.0;
          end else begin
            Alphaz = Vgst/Vdsat;
            load_T1 = 2.0*Vdsat-Vds;
            load_T2 = Vds/(3.0*load_T1);
            load_T3 = load_T2*Vds;
            load_T9 = 0.25*CoxWL;
            load_T4 = load_T9*Alphaz;
            qgate = CoxWL*(load_Vgs_eff-Vfb-BSIM4phi-0.5*(Vds-load_T3));
            load_T5 = load_T3/load_T1;
            BSIM4cggb = CoxWL*(1.0-load_T5*dVdsat_dVg)*dVgs_eff_dVg;
            load_tmp = -CoxWL*load_T5*dVdsat_dVb;
            BSIM4cgdb = CoxWL*(load_T2-0.5+0.5*load_T5);
            BSIM4cgsb = -(BSIM4cggb+BSIM4cgdb+load_tmp);
            load_T6 = 1.0/Vdsat;
            dAlphaz_dVg = load_T6*(1.0-Alphaz*dVdsat_dVg);
            dAlphaz_dVb = -load_T6*(dVth_dVb+Alphaz*dVdsat_dVb);
            load_T6 = 8.0*Vdsat*Vdsat-6.0*Vdsat*Vds+1.2*Vds*Vds;
            load_T8 = load_T2/load_T1;
            load_T7 = Vds-load_T1-load_T8*load_T6;
            qdrn = load_T4*load_T7;
            load_T7 = load_T7 * (load_T9);
            load_tmp = load_T8/load_T1;
            load_tmp1 = load_T4*(2.0-4.0*load_tmp*load_T6+load_T8*(16.0*Vdsat-6.0*Vds));
            BSIM4cdgb = (load_T7*dAlphaz_dVg-load_tmp1*dVdsat_dVg)*dVgs_eff_dVg;
            load_T10 = load_T7*dAlphaz_dVb-load_tmp1*dVdsat_dVb;
            BSIM4cddb = load_T4*(2.0-(1.0/(3.0*load_T1*load_T1)+2.0*load_tmp)*load_T6+load_T8*(6.0*Vdsat-2.4*Vds));
            BSIM4cdsb = -(BSIM4cdgb+load_T10+BSIM4cddb);
            load_T7 = 2.0*(load_T1+load_T3);
            qbulk = -(qgate-load_T4*load_T7);
            load_T7 = load_T7 * (load_T9);
            load_T0 = 4.0*load_T4*(1.0-load_T5);
            T12 = (-load_T7*dAlphaz_dVg-load_T0*dVdsat_dVg)*dVgs_eff_dVg-BSIM4cdgb;
            load_T11 = -load_T7*dAlphaz_dVb-load_T10-load_T0*dVdsat_dVb;
            load_T10 = -4.0*load_T4*(load_T2-0.5+0.5*load_T5)-BSIM4cddb;
            load_tmp = -(load_T10+load_T11+T12);
            BSIM4cbgb = -(BSIM4cggb+BSIM4cdgb+T12);
            BSIM4cbdb = -(BSIM4cgdb+BSIM4cddb+load_T10);
            BSIM4cbsb = -(BSIM4cgsb+BSIM4cdsb+load_tmp);
          end
        end else if (Vds>=Vdsat) begin
          load_T1 = Vdsat/3.0;
          qgate = CoxWL*(load_Vgs_eff-Vfb-BSIM4phi-load_T1);
          load_T2 = -Two_Third_CoxWL*Vgst;
          qbulk = -(qgate+load_T2);
          qdrn = 0.5*load_T2;
          BSIM4cggb = One_Third_CoxWL*(3.0-dVdsat_dVg)*dVgs_eff_dVg;
          load_T2 = -One_Third_CoxWL*dVdsat_dVb;
          BSIM4cgsb = -(BSIM4cggb+load_T2);
          BSIM4cgdb = 0.0;
          BSIM4cdgb = -One_Third_CoxWL*dVgs_eff_dVg;
          BSIM4cddb = 0.0;
          load_T4 = One_Third_CoxWL*dVth_dVb;
          BSIM4cdsb = -(load_T4+BSIM4cdgb);
          BSIM4cbgb = -(BSIM4cggb-Two_Third_CoxWL*dVgs_eff_dVg);
          load_T3 = -(load_T2+Two_Third_CoxWL*dVth_dVb);
          BSIM4cbsb = -(BSIM4cbgb+load_T3);
          BSIM4cbdb = 0.0;
        end else begin
          Alphaz = Vgst/Vdsat;
          load_T1 = 2.0*Vdsat-Vds;
          load_T2 = Vds/(3.0*load_T1);
          load_T3 = load_T2*Vds;
          load_T9 = 0.25*CoxWL;
          load_T4 = load_T9*Alphaz;
          qgate = CoxWL*(load_Vgs_eff-Vfb-BSIM4phi-0.5*(Vds-load_T3));
          load_T5 = load_T3/load_T1;
          BSIM4cggb = CoxWL*(1.0-load_T5*dVdsat_dVg)*dVgs_eff_dVg;
          load_tmp = -CoxWL*load_T5*dVdsat_dVb;
          BSIM4cgdb = CoxWL*(load_T2-0.5+0.5*load_T5);
          BSIM4cgsb = -(BSIM4cggb+BSIM4cgdb+load_tmp);
          load_T6 = 1.0/Vdsat;
          dAlphaz_dVg = load_T6*(1.0-Alphaz*dVdsat_dVg);
          dAlphaz_dVb = -load_T6*(dVth_dVb+Alphaz*dVdsat_dVb);
          load_T7 = load_T1+load_T3;
          qdrn = -load_T4*load_T7;
          qbulk = -(qgate+qdrn+qdrn);
          load_T7 = load_T7 * (load_T9);
          load_T0 = load_T4*(2.0*load_T5-2.0);
          BSIM4cdgb = (load_T0*dVdsat_dVg-load_T7*dAlphaz_dVg)*dVgs_eff_dVg;
          T12 = load_T0*dVdsat_dVb-load_T7*dAlphaz_dVb;
          BSIM4cddb = load_T4*(1.0-2.0*load_T2-load_T5);
          BSIM4cdsb = -(BSIM4cdgb+T12+BSIM4cddb);
          BSIM4cbgb = -(BSIM4cggb+2.0*BSIM4cdgb);
          BSIM4cbdb = -(BSIM4cgdb+2.0*BSIM4cddb);
          BSIM4cbsb = -(BSIM4cgsb+2.0*BSIM4cdsb);
        end
      end
    end else begin
      if (Vbseff<0.0) begin
        VbseffCV = Vbseff;
        dVbseffCV_dVb = 1.0;
      end else begin
        VbseffCV = BSIM4phi-Phis;
        dVbseffCV_dVb = -dPhis_dVb;
      end
      CoxWL = BSIM4coxe*BSIM4weffCV*BSIM4leffCV*nf;
      if (cvchargemod==0) begin
        load_noff = load_n*sd_BSIM4noff;
        dnoff_dVd = sd_BSIM4noff*dn_dVd;
        dnoff_dVb = sd_BSIM4noff*dn_dVb;
        load_T0 = Vtm*load_noff;
        load_voffcv = sd_BSIM4voffcv;
        VgstNVt = (Vgst-load_voffcv)/load_T0;
        if (VgstNVt>34.0) begin
          load_Vgsteff = Vgst-load_voffcv;
          dVgsteff_dVg = dVgs_eff_dVg;
          dVgsteff_dVd = -dVth_dVd;
          dVgsteff_dVb = -dVth_dVb;
        end else if (VgstNVt<-34.0) begin
          load_Vgsteff = load_T0*ln(1.0+1.713908431e-15);
          dVgsteff_dVg = 0.0;
          dVgsteff_dVd = load_Vgsteff/load_noff;
          dVgsteff_dVb = dVgsteff_dVd*dnoff_dVb;
          dVgsteff_dVd = dVgsteff_dVd * (dnoff_dVd);
        end else begin
          ExpVgst = exp(VgstNVt);
          load_Vgsteff = load_T0*ln(1.0+ExpVgst);
          dVgsteff_dVg = ExpVgst/(1.0+ExpVgst);
          dVgsteff_dVd = -dVgsteff_dVg*(dVth_dVd+(Vgst-load_voffcv)/load_noff*dnoff_dVd)+load_Vgsteff/load_noff*dnoff_dVd;
          dVgsteff_dVb = -dVgsteff_dVg*(dVth_dVb+(Vgst-load_voffcv)/load_noff*dnoff_dVb)+load_Vgsteff/load_noff*dnoff_dVb;
          dVgsteff_dVg = dVgsteff_dVg * (dVgs_eff_dVg);
        end
      end else begin
        load_T0 = load_n*Vtm;
        load_T1 = BSIM4mstarcv*Vgst;
        load_T2 = load_T1/load_T0;
        if (load_T2>34.0) begin
          load_T10 = load_T1;
          dT10_dVg = BSIM4mstarcv*dVgs_eff_dVg;
          dT10_dVd = -dVth_dVd*BSIM4mstarcv;
          dT10_dVb = -dVth_dVb*BSIM4mstarcv;
        end else if (load_T2<-34.0) begin
          load_T10 = Vtm*ln(1.0+1.713908431e-15);
          dT10_dVg = 0.0;
          dT10_dVd = load_T10*dn_dVd;
          dT10_dVb = load_T10*dn_dVb;
          load_T10 = load_T10 * (load_n);
        end else begin
          ExpVgst = exp(load_T2);
          load_T3 = Vtm*ln(1.0+ExpVgst);
          load_T10 = load_n*load_T3;
          dT10_dVg = BSIM4mstarcv*ExpVgst/(1.0+ExpVgst);
          dT10_dVb = load_T3*dn_dVb-dT10_dVg*(dVth_dVb+Vgst*dn_dVb/load_n);
          dT10_dVd = load_T3*dn_dVd-dT10_dVg*(dVth_dVd+Vgst*dn_dVd/load_n);
          dT10_dVg = dT10_dVg * (dVgs_eff_dVg);
        end
        load_T1 = BSIM4voffcbncv-(1.0-BSIM4mstarcv)*Vgst;
        load_T2 = load_T1/load_T0;
        if (load_T2<-34.0) begin
          load_T3 = BSIM4coxe*1.713908431e-15/BSIM4cdep0;
          load_T9 = BSIM4mstarcv+load_T3*load_n;
          dT9_dVg = 0.0;
          dT9_dVd = dn_dVd*load_T3;
          dT9_dVb = dn_dVb*load_T3;
        end else if (load_T2>34.0) begin
          load_T3 = BSIM4coxe*5.834617425e14/BSIM4cdep0;
          load_T9 = BSIM4mstarcv+load_T3*load_n;
          dT9_dVg = 0.0;
          dT9_dVd = dn_dVd*load_T3;
          dT9_dVb = dn_dVb*load_T3;
        end else begin
          ExpVgst = exp(load_T2);
          load_T3 = BSIM4coxe/BSIM4cdep0;
          load_T4 = load_T3*ExpVgst;
          load_T5 = load_T1*load_T4/load_T0;
          load_T9 = BSIM4mstarcv+load_n*load_T4;
          dT9_dVg = load_T3*(BSIM4mstarcv-1.0)*ExpVgst/Vtm;
          dT9_dVb = load_T4*dn_dVb-dT9_dVg*dVth_dVb-load_T5*dn_dVb;
          dT9_dVd = load_T4*dn_dVd-dT9_dVg*dVth_dVd-load_T5*dn_dVd;
          dT9_dVg = dT9_dVg * (dVgs_eff_dVg);
        end
        load_Vgsteff = load_T10/load_T9;
        load_T11 = load_T9*load_T9;
        dVgsteff_dVg = (load_T9*dT10_dVg-load_T10*dT9_dVg)/load_T11;
        dVgsteff_dVd = (load_T9*dT10_dVd-load_T10*dT9_dVd)/load_T11;
        dVgsteff_dVb = (load_T9*dT10_dVb-load_T10*dT9_dVb)/load_T11;
      end
      if (BSIM4capMod==1) begin
        Vfb = BSIM4vfbzb;
        V3 = Vfb-load_Vgs_eff+VbseffCV-0.02;
        if (Vfb<=0.0) begin
          load_T0 = sqrt(V3*V3-4.0*0.02*Vfb);
        end else begin
          load_T0 = sqrt(V3*V3+4.0*0.02*Vfb);
        end
        load_T1 = 0.5*(1.0+V3/load_T0);
        Vfbeff = Vfb-0.5*(V3+load_T0);
        dVfbeff_dVg = load_T1*dVgs_eff_dVg;
        dVfbeff_dVb = -load_T1*dVbseffCV_dVb;
        Qac0 = CoxWL*(Vfbeff-Vfb);
        dQac0_dVg = CoxWL*dVfbeff_dVg;
        dQac0_dVb = CoxWL*dVfbeff_dVb;
        load_T0 = 0.5*BSIM4k1ox;
        load_T3 = load_Vgs_eff-Vfbeff-VbseffCV-load_Vgsteff;
        if (BSIM4k1ox==0.0) begin
          load_T1 = 0.0;
          load_T2 = 0.0;
        end else if (load_T3<0.0) begin
          load_T1 = load_T0+load_T3/BSIM4k1ox;
          load_T2 = CoxWL;
        end else begin
          load_T1 = sqrt(load_T0*load_T0+load_T3);
          load_T2 = CoxWL*load_T0/load_T1;
        end
        Qsub0 = CoxWL*BSIM4k1ox*(load_T1-load_T0);
        dQsub0_dVg = load_T2*(dVgs_eff_dVg-dVfbeff_dVg-dVgsteff_dVg);
        dQsub0_dVd = -load_T2*dVgsteff_dVd;
        dQsub0_dVb = -load_T2*(dVfbeff_dVb+dVbseffCV_dVb+dVgsteff_dVb);
        AbulkCV = Abulk0_Q*BSIM4abulkCVfactor;
        dAbulkCV_dVb = BSIM4abulkCVfactor*dAbulk0_Q_dVb;
        VdsatCV = load_Vgsteff/AbulkCV;
        load_T0 = VdsatCV-Vds-0.02;
        dT0_dVg = 1.0/AbulkCV;
        dT0_dVb = -VdsatCV*dAbulkCV_dVb/AbulkCV;
        load_T1 = sqrt(load_T0*load_T0+4.0*0.02*VdsatCV);
        dT1_dVg = (load_T0+0.02+0.02)/load_T1;
        dT1_dVd = -load_T0/load_T1;
        dT1_dVb = dT1_dVg*dT0_dVb;
        dT1_dVg = dT1_dVg * (dT0_dVg);
        if (load_T0>=0.0) begin
          VdseffCV = VdsatCV-0.5*(load_T0+load_T1);
          dVdseffCV_dVg = 0.5*(dT0_dVg-dT1_dVg);
          dVdseffCV_dVd = 0.5*(1.0-dT1_dVd);
          dVdseffCV_dVb = 0.5*(dT0_dVb-dT1_dVb);
        end else begin
          load_T3 = (0.02+0.02)/(load_T1-load_T0);
          load_T4 = 1.0-load_T3;
          load_T5 = VdsatCV*load_T3/(load_T1-load_T0);
          VdseffCV = VdsatCV*load_T4;
          dVdseffCV_dVg = dT0_dVg*load_T4+load_T5*(dT1_dVg-dT0_dVg);
          dVdseffCV_dVd = load_T5*(dT1_dVd+1.0);
          dVdseffCV_dVb = dT0_dVb*(load_T4-load_T5)+load_T5*dT1_dVb;
        end
        if (Vds==0.0) begin
          VdseffCV = 0.0;
          dVdseffCV_dVg = 0.0;
          dVdseffCV_dVb = 0.0;
        end
        load_T0 = AbulkCV*VdseffCV;
        load_T1 = 12.0*(load_Vgsteff-0.5*load_T0+1.0e-20);
        load_T2 = VdseffCV/load_T1;
        load_T3 = load_T0*load_T2;
        load_T4 = 1.0-12.0*load_T2*load_T2*AbulkCV;
        load_T5 = 6.0*load_T0*(4.0*load_Vgsteff-load_T0)/(load_T1*load_T1)-0.5;
        load_T6 = 12.0*load_T2*load_T2*load_Vgsteff;
        qgate = CoxWL*(load_Vgsteff-0.5*VdseffCV+load_T3);
        Cgg1 = CoxWL*(load_T4+load_T5*dVdseffCV_dVg);
        Cgd1 = CoxWL*load_T5*dVdseffCV_dVd+Cgg1*dVgsteff_dVd;
        Cgb1 = CoxWL*(load_T5*dVdseffCV_dVb+load_T6*dAbulkCV_dVb)+Cgg1*dVgsteff_dVb;
        Cgg1 = Cgg1 * (dVgsteff_dVg);
        load_T7 = 1.0-AbulkCV;
        qbulk = CoxWL*load_T7*(0.5*VdseffCV-load_T3);
        load_T4 = -load_T7*(load_T4-1.0);
        load_T5 = -load_T7*load_T5;
        load_T6 = -(load_T7*load_T6+(0.5*VdseffCV-load_T3));
        Cbg1 = CoxWL*(load_T4+load_T5*dVdseffCV_dVg);
        Cbd1 = CoxWL*load_T5*dVdseffCV_dVd+Cbg1*dVgsteff_dVd;
        Cbb1 = CoxWL*(load_T5*dVdseffCV_dVb+load_T6*dAbulkCV_dVb)+Cbg1*dVgsteff_dVb;
        Cbg1 = Cbg1 * (dVgsteff_dVg);
        if (xpart>0.5) begin
          load_T1 = load_T1+load_T1;
          qsrc = -CoxWL*(0.5*load_Vgsteff+0.25*load_T0-load_T0*load_T0/load_T1);
          load_T7 = (4.0*load_Vgsteff-load_T0)/(load_T1*load_T1);
          load_T4 = -(0.5+24.0*load_T0*load_T0/(load_T1*load_T1));
          load_T5 = -(0.25*AbulkCV-12.0*AbulkCV*load_T0*load_T7);
          load_T6 = -(0.25*VdseffCV-12.0*load_T0*VdseffCV*load_T7);
          Csg = CoxWL*(load_T4+load_T5*dVdseffCV_dVg);
          Csd = CoxWL*load_T5*dVdseffCV_dVd+Csg*dVgsteff_dVd;
          Csb = CoxWL*(load_T5*dVdseffCV_dVb+load_T6*dAbulkCV_dVb)+Csg*dVgsteff_dVb;
          Csg = Csg * (dVgsteff_dVg);
        end else if (xpart<0.5) begin
          load_T1 = load_T1/12.0;
          load_T2 = 0.5*CoxWL/(load_T1*load_T1);
          load_T3 = load_Vgsteff*(2.0*load_T0*load_T0/3.0+load_Vgsteff*(load_Vgsteff-4.0*load_T0/3.0))-2.0*load_T0*load_T0*load_T0/15.0;
          qsrc = -load_T2*load_T3;
          load_T7 = 4.0/3.0*load_Vgsteff*(load_Vgsteff-load_T0)+0.4*load_T0*load_T0;
          load_T4 = -2.0*qsrc/load_T1-load_T2*(load_Vgsteff*(3.0*load_Vgsteff-8.0*load_T0/3.0)+2.0*load_T0*load_T0/3.0);
          load_T5 = (qsrc/load_T1+load_T2*load_T7)*AbulkCV;
          load_T6 = qsrc/load_T1*VdseffCV+load_T2*load_T7*VdseffCV;
          Csg = load_T4+load_T5*dVdseffCV_dVg;
          Csd = load_T5*dVdseffCV_dVd+Csg*dVgsteff_dVd;
          Csb = load_T5*dVdseffCV_dVb+load_T6*dAbulkCV_dVb+Csg*dVgsteff_dVb;
          Csg = Csg * (dVgsteff_dVg);
        end else begin
          qsrc = -0.5*(qgate+qbulk);
          Csg = -0.5*(Cgg1+Cbg1);
          Csb = -0.5*(Cgb1+Cbb1);
          Csd = -0.5*(Cgd1+Cbd1);
        end
        qgate = qgate + (Qac0+Qsub0);
        qbulk = qbulk - (Qac0+Qsub0);
        qdrn = -(qgate+qbulk+qsrc);
        Cgg = dQac0_dVg+dQsub0_dVg+Cgg1;
        Cgd = dQsub0_dVd+Cgd1;
        Cgb = dQac0_dVb+dQsub0_dVb+Cgb1;
        Cbg = Cbg1-dQac0_dVg-dQsub0_dVg;
        Cbd = Cbd1-dQsub0_dVd;
        Cbb = Cbb1-dQac0_dVb-dQsub0_dVb;
        Cgb = Cgb * (dVbseff_dVb);
        Cbb = Cbb * (dVbseff_dVb);
        Csb = Csb * (dVbseff_dVb);
        BSIM4cggb = Cgg;
        BSIM4cgsb = -(Cgg+Cgd+Cgb);
        BSIM4cgdb = Cgd;
        BSIM4cdgb = -(Cgg+Cbg+Csg);
        BSIM4cdsb = Cgg+Cgd+Cgb+Cbg+Cbd+Cbb+Csg+Csd+Csb;
        BSIM4cddb = -(Cgd+Cbd+Csd);
        BSIM4cbgb = Cbg;
        BSIM4cbsb = -(Cbg+Cbd+Cbb);
        BSIM4cbdb = Cbd;
      end else if (BSIM4capMod==2) begin
        V3 = BSIM4vfbzb-load_Vgs_eff+VbseffCV-0.02;
        if (BSIM4vfbzb<=0.0) begin
          load_T0 = sqrt(V3*V3-4.0*0.02*BSIM4vfbzb);
        end else begin
          load_T0 = sqrt(V3*V3+4.0*0.02*BSIM4vfbzb);
        end
        load_T1 = 0.5*(1.0+V3/load_T0);
        Vfbeff = BSIM4vfbzb-0.5*(V3+load_T0);
        dVfbeff_dVg = load_T1*dVgs_eff_dVg;
        dVfbeff_dVb = -load_T1*dVbseffCV_dVb;
        Cox = i_BSIM4coxp;
        Tox = 1.0e8*i_BSIM4toxp;
        load_T0 = (load_Vgs_eff-VbseffCV-BSIM4vfbzb)/Tox;
        dT0_dVg = dVgs_eff_dVg/Tox;
        dT0_dVb = -dVbseffCV_dVb/Tox;
        load_tmp = load_T0*sd_BSIM4acde;
        if (-34.0<load_tmp&&load_tmp<34.0) begin
          load_Tcen = BSIM4ldeb*exp(load_tmp);
          dTcen_dVg = sd_BSIM4acde*load_Tcen;
          dTcen_dVb = dTcen_dVg*dT0_dVb;
          dTcen_dVg = dTcen_dVg * (dT0_dVg);
        end else if (load_tmp<=-34.0) begin
          load_Tcen = BSIM4ldeb*1.713908431e-15;
          dTcen_dVb = 0.0;
          dTcen_dVg = dTcen_dVb;
        end else begin
          load_Tcen = BSIM4ldeb*5.834617425e14;
          dTcen_dVb = 0.0;
          dTcen_dVg = dTcen_dVb;
        end
        LINK = 1.0e-3*i_BSIM4toxp;
        V3 = BSIM4ldeb-load_Tcen-LINK;
        V4 = sqrt(V3*V3+4.0*LINK*BSIM4ldeb);
        load_Tcen = BSIM4ldeb-0.5*(V3+V4);
        load_T1 = 0.5*(1.0+V3/V4);
        dTcen_dVg = dTcen_dVg * (load_T1);
        dTcen_dVb = dTcen_dVb * (load_T1);
        Ccen = load_epssub/load_Tcen;
        load_T2 = Cox/(Cox+Ccen);
        Coxeff = load_T2*Ccen;
        load_T3 = -Ccen/load_Tcen;
        dCoxeff_dVg = load_T2*load_T2*load_T3;
        dCoxeff_dVb = dCoxeff_dVg*dTcen_dVb;
        dCoxeff_dVg = dCoxeff_dVg * (dTcen_dVg);
        CoxWLcen = CoxWL*Coxeff/BSIM4coxe;
        Qac0 = CoxWLcen*(Vfbeff-BSIM4vfbzb);
        QovCox = Qac0/Coxeff;
        dQac0_dVg = CoxWLcen*dVfbeff_dVg+QovCox*dCoxeff_dVg;
        dQac0_dVb = CoxWLcen*dVfbeff_dVb+QovCox*dCoxeff_dVb;
        load_T0 = 0.5*BSIM4k1ox;
        load_T3 = load_Vgs_eff-Vfbeff-VbseffCV-load_Vgsteff;
        if (BSIM4k1ox==0.0) begin
          load_T1 = 0.0;
          load_T2 = 0.0;
        end else if (load_T3<0.0) begin
          load_T1 = load_T0+load_T3/BSIM4k1ox;
          load_T2 = CoxWLcen;
        end else begin
          load_T1 = sqrt(load_T0*load_T0+load_T3);
          load_T2 = CoxWLcen*load_T0/load_T1;
        end
        Qsub0 = CoxWLcen*BSIM4k1ox*(load_T1-load_T0);
        QovCox = Qsub0/Coxeff;
        dQsub0_dVg = load_T2*(dVgs_eff_dVg-dVfbeff_dVg-dVgsteff_dVg)+QovCox*dCoxeff_dVg;
        dQsub0_dVd = -load_T2*dVgsteff_dVd;
        dQsub0_dVb = -load_T2*(dVfbeff_dVb+dVbseffCV_dVb+dVgsteff_dVb)+QovCox*dCoxeff_dVb;
        if (BSIM4k1ox<=0.0) begin
          Denomi = 0.25*sd_BSIM4moin*Vtm;
          load_T0 = 0.5*BSIM4sqrtPhi;
        end else begin
          Denomi = sd_BSIM4moin*Vtm*BSIM4k1ox*BSIM4k1ox;
          load_T0 = BSIM4k1ox*BSIM4sqrtPhi;
        end
        load_T1 = 2.0*load_T0+load_Vgsteff;
        DeltaPhi = Vtm*ln(1.0+load_T1*load_Vgsteff/Denomi);
        dDeltaPhi_dVg = 2.0*Vtm*(load_T1-load_T0)/(Denomi+load_T1*load_Vgsteff);
        load_T0 = load_Vgsteff-DeltaPhi-0.001;
        dT0_dVg = 1.0-dDeltaPhi_dVg;
        load_T1 = sqrt(load_T0*load_T0+load_Vgsteff*0.004);
        VgDP = 0.5*(load_T0+load_T1);
        dVgDP_dVg = 0.5*(dT0_dVg+(load_T0*dT0_dVg+0.002)/load_T1);
        Tox = Tox + (Tox);
        load_T0 = (load_Vgsteff+BSIM4vtfbphi2)/Tox;
        load_tmp = exp(bdos*0.7*ln(load_T0));
        load_T1 = 1.0+load_tmp;
        load_T2 = bdos*0.7*load_tmp/(load_T0*Tox);
        load_Tcen = ados*1.9e-9/load_T1;
        dTcen_dVg = -load_Tcen*load_T2/load_T1;
        dTcen_dVd = dTcen_dVg*dVgsteff_dVd;
        dTcen_dVb = dTcen_dVg*dVgsteff_dVb;
        dTcen_dVg = dTcen_dVg * (dVgsteff_dVg);
        Ccen = load_epssub/load_Tcen;
        load_T0 = Cox/(Cox+Ccen);
        Coxeff = load_T0*Ccen;
        load_T1 = -Ccen/load_Tcen;
        dCoxeff_dVg = load_T0*load_T0*load_T1;
        dCoxeff_dVd = dCoxeff_dVg*dTcen_dVd;
        dCoxeff_dVb = dCoxeff_dVg*dTcen_dVb;
        dCoxeff_dVg = dCoxeff_dVg * (dTcen_dVg);
        CoxWLcen = CoxWL*Coxeff/BSIM4coxe;
        AbulkCV = Abulk0_Q*BSIM4abulkCVfactor;
        dAbulkCV_dVb = BSIM4abulkCVfactor*dAbulk0_Q_dVb;
        VdsatCV = VgDP/AbulkCV;
        load_T0 = VdsatCV-Vds-0.02;
        dT0_dVg = dVgDP_dVg/AbulkCV;
        dT0_dVb = -VdsatCV*dAbulkCV_dVb/AbulkCV;
        load_T1 = sqrt(load_T0*load_T0+4.0*0.02*VdsatCV);
        dT1_dVg = (load_T0+0.02+0.02)/load_T1;
        dT1_dVd = -load_T0/load_T1;
        dT1_dVb = dT1_dVg*dT0_dVb;
        dT1_dVg = dT1_dVg * (dT0_dVg);
        if (load_T0>=0.0) begin
          VdseffCV = VdsatCV-0.5*(load_T0+load_T1);
          dVdseffCV_dVg = 0.5*(dT0_dVg-dT1_dVg);
          dVdseffCV_dVd = 0.5*(1.0-dT1_dVd);
          dVdseffCV_dVb = 0.5*(dT0_dVb-dT1_dVb);
        end else begin
          load_T3 = (0.02+0.02)/(load_T1-load_T0);
          load_T4 = 1.0-load_T3;
          load_T5 = VdsatCV*load_T3/(load_T1-load_T0);
          VdseffCV = VdsatCV*load_T4;
          dVdseffCV_dVg = dT0_dVg*load_T4+load_T5*(dT1_dVg-dT0_dVg);
          dVdseffCV_dVd = load_T5*(dT1_dVd+1.0);
          dVdseffCV_dVb = dT0_dVb*(load_T4-load_T5)+load_T5*dT1_dVb;
        end
        if (Vds==0.0) begin
          VdseffCV = 0.0;
          dVdseffCV_dVg = 0.0;
          dVdseffCV_dVb = 0.0;
        end
        load_T0 = AbulkCV*VdseffCV;
        load_T1 = VgDP;
        load_T2 = 12.0*(load_T1-0.5*load_T0+1.0e-20);
        load_T3 = load_T0/load_T2;
        load_T4 = 1.0-12.0*load_T3*load_T3;
        load_T5 = AbulkCV*(6.0*load_T0*(4.0*load_T1-load_T0)/(load_T2*load_T2)-0.5);
        load_T6 = load_T5*VdseffCV/AbulkCV;
        qgate = CoxWLcen*(load_T1-load_T0*(0.5-load_T3));
        QovCox = qgate/Coxeff;
        Cgg1 = CoxWLcen*(load_T4*dVgDP_dVg+load_T5*dVdseffCV_dVg);
        Cgd1 = CoxWLcen*load_T5*dVdseffCV_dVd+Cgg1*dVgsteff_dVd+QovCox*dCoxeff_dVd;
        Cgb1 = CoxWLcen*(load_T5*dVdseffCV_dVb+load_T6*dAbulkCV_dVb)+Cgg1*dVgsteff_dVb+QovCox*dCoxeff_dVb;
        Cgg1 = Cgg1*dVgsteff_dVg+QovCox*dCoxeff_dVg;
        load_T7 = 1.0-AbulkCV;
        load_T8 = load_T2*load_T2;
        load_T9 = 12.0*load_T7*load_T0*load_T0/(load_T8*AbulkCV);
        load_T10 = load_T9*dVgDP_dVg;
        load_T11 = -load_T7*load_T5/AbulkCV;
        T12 = -(load_T9*load_T1/AbulkCV+VdseffCV*(0.5-load_T0/load_T2));
        qbulk = CoxWLcen*load_T7*(0.5*VdseffCV-load_T0*VdseffCV/load_T2);
        QovCox = qbulk/Coxeff;
        Cbg1 = CoxWLcen*(load_T10+load_T11*dVdseffCV_dVg);
        Cbd1 = CoxWLcen*load_T11*dVdseffCV_dVd+Cbg1*dVgsteff_dVd+QovCox*dCoxeff_dVd;
        Cbb1 = CoxWLcen*(load_T11*dVdseffCV_dVb+T12*dAbulkCV_dVb)+Cbg1*dVgsteff_dVb+QovCox*dCoxeff_dVb;
        Cbg1 = Cbg1*dVgsteff_dVg+QovCox*dCoxeff_dVg;
        if (xpart>0.5) begin
          qsrc = -CoxWLcen*(load_T1/2.0+load_T0/4.0-0.5*load_T0*load_T0/load_T2);
          QovCox = qsrc/Coxeff;
          load_T2 = load_T2 + (load_T2);
          load_T3 = load_T2*load_T2;
          load_T7 = -(0.25-12.0*load_T0*(4.0*load_T1-load_T0)/load_T3);
          load_T4 = -(0.5+24.0*load_T0*load_T0/load_T3)*dVgDP_dVg;
          load_T5 = load_T7*AbulkCV;
          load_T6 = load_T7*VdseffCV;
          Csg = CoxWLcen*(load_T4+load_T5*dVdseffCV_dVg);
          Csd = CoxWLcen*load_T5*dVdseffCV_dVd+Csg*dVgsteff_dVd+QovCox*dCoxeff_dVd;
          Csb = CoxWLcen*(load_T5*dVdseffCV_dVb+load_T6*dAbulkCV_dVb)+Csg*dVgsteff_dVb+QovCox*dCoxeff_dVb;
          Csg = Csg*dVgsteff_dVg+QovCox*dCoxeff_dVg;
        end else if (xpart<0.5) begin
          load_T2 = load_T2/12.0;
          load_T3 = 0.5*CoxWLcen/(load_T2*load_T2);
          load_T4 = load_T1*(2.0*load_T0*load_T0/3.0+load_T1*(load_T1-4.0*load_T0/3.0))-2.0*load_T0*load_T0*load_T0/15.0;
          qsrc = -load_T3*load_T4;
          QovCox = qsrc/Coxeff;
          load_T8 = 4.0/3.0*load_T1*(load_T1-load_T0)+0.4*load_T0*load_T0;
          load_T5 = -2.0*qsrc/load_T2-load_T3*(load_T1*(3.0*load_T1-8.0*load_T0/3.0)+2.0*load_T0*load_T0/3.0);
          load_T6 = AbulkCV*(qsrc/load_T2+load_T3*load_T8);
          load_T7 = load_T6*VdseffCV/AbulkCV;
          Csg = load_T5*dVgDP_dVg+load_T6*dVdseffCV_dVg;
          Csd = Csg*dVgsteff_dVd+load_T6*dVdseffCV_dVd+QovCox*dCoxeff_dVd;
          Csb = Csg*dVgsteff_dVb+load_T6*dVdseffCV_dVb+load_T7*dAbulkCV_dVb+QovCox*dCoxeff_dVb;
          Csg = Csg*dVgsteff_dVg+QovCox*dCoxeff_dVg;
        end else begin
          qsrc = -0.5*qgate;
          Csg = -0.5*Cgg1;
          Csd = -0.5*Cgd1;
          Csb = -0.5*Cgb1;
        end
        qgate = qgate + (Qac0+Qsub0-qbulk);
        qbulk = qbulk - (Qac0+Qsub0);
        qdrn = -(qgate+qbulk+qsrc);
        Cbg = Cbg1-dQac0_dVg-dQsub0_dVg;
        Cbd = Cbd1-dQsub0_dVd;
        Cbb = Cbb1-dQac0_dVb-dQsub0_dVb;
        Cgg = Cgg1-Cbg;
        Cgd = Cgd1-Cbd;
        Cgb = Cgb1-Cbb;
        Cgb = Cgb * (dVbseff_dVb);
        Cbb = Cbb * (dVbseff_dVb);
        Csb = Csb * (dVbseff_dVb);
        BSIM4cggb = Cgg;
        BSIM4cgsb = -(Cgg+Cgd+Cgb);
        BSIM4cgdb = Cgd;
        BSIM4cdgb = -(Cgg+Cbg+Csg);
        BSIM4cdsb = Cgg+Cgd+Cgb+Cbg+Cbd+Cbb+Csg+Csd+Csb;
        BSIM4cddb = -(Cgd+Cbd+Csd);
        BSIM4cbgb = Cbg;
        BSIM4cbsb = -(Cbg+Cbd+Cbb);
        BSIM4cbdb = Cbd;
      end
    end
    if (goto_destination<0) begin
      BSIM4csgb = -BSIM4cggb-BSIM4cdgb-BSIM4cbgb;
      BSIM4csdb = -BSIM4cgdb-BSIM4cddb-BSIM4cbdb;
      BSIM4cssb = -BSIM4cgsb-BSIM4cdsb-BSIM4cbsb;
      BSIM4cgbb = -BSIM4cgdb-BSIM4cggb-BSIM4cgsb;
      BSIM4cdbb = -BSIM4cddb-BSIM4cdgb-BSIM4cdsb;
      BSIM4cbbb = -BSIM4cbgb-BSIM4cbdb-BSIM4cbsb;
      BSIM4csbb = -BSIM4cgbb-BSIM4cdbb-BSIM4cbbb;
      BSIM4qgate = qgate;
      BSIM4qbulk = qbulk;
      BSIM4qdrn = qdrn;
      BSIM4qsrc = -(qgate+qbulk+qdrn);
      if (i_BSIM4trnqsMod||i_BSIM4acnqsMod) begin
        qcheq = -(qbulk+qgate);
        BSIM4qchqs = qcheq;
        BSIM4cqgb = -(BSIM4cggb+BSIM4cbgb);
        BSIM4cqdb = -(BSIM4cgdb+BSIM4cbdb);
        BSIM4cqsb = -(BSIM4cgsb+BSIM4cbsb);
        BSIM4cqbb = -(BSIM4cqgb+BSIM4cqdb+BSIM4cqsb);
        CoxWL = BSIM4coxe*BSIM4weffCV*nf*BSIM4leffCV;
        load_T1 = BSIM4gcrg/CoxWL;
        BSIM4gtau = load_T1*ScalingFactor;
        if (i_BSIM4acnqsMod) begin
          BSIM4taunet = 1.0/load_T1;
        end
        BSIM4qcheq = qcheq;
      end
    end
    goto_destination = -1;
    if (!i_BSIM4trnqsMod) begin
      BSIM4qcheq = 0;
    end
    geq = 0;
    BSIM4cqcheq = ddt(BSIM4qcheq);
    ceq = BSIM4cqcheq;
    czbd = BSIM4DunitAreaTempJctCap*BSIM4Adeff;
    czbs = BSIM4SunitAreaTempJctCap*BSIM4Aseff;
    czbdsw = BSIM4DunitLengthSidewallTempJctCap*BSIM4Pdeff;
    czbdswg = BSIM4DunitLengthGateSidewallTempJctCap*BSIM4weffCJ*nf;
    czbssw = BSIM4SunitLengthSidewallTempJctCap*BSIM4Pseff;
    czbsswg = BSIM4SunitLengthGateSidewallTempJctCap*BSIM4weffCJ*nf;
    MJS = mjs;
    MJSWS = mjsws;
    MJSWGS = BSIM4SbulkJctGateSideGradingCoeff;
    MJD = BSIM4DbulkJctBotGradingCoeff;
    MJSWD = BSIM4DbulkJctSideGradingCoeff;
    MJSWGD = BSIM4DbulkJctGateSideGradingCoeff;
    if (!i_BSIM4rbodyMod) begin
      BSIM4qbs = 0;
      BSIM4qbd = 0;
    end
    if (vbs_jct==0.0) begin
      BSIM4qbs = 0.0;
      BSIM4capbs = czbs+czbssw+czbsswg;
    end else if (vbs_jct<0.0) begin
      if (czbs>0.0) begin
        arg = 1.0-vbs_jct/BSIM4PhiBS;
        if (MJS==0.5) begin
          sarg = 1.0/sqrt(arg);
        end else begin
          sarg = exp(-MJS*ln(arg));
        end
        BSIM4qbs = BSIM4PhiBS*czbs*(1.0-arg*sarg)/(1.0-MJS);
        BSIM4capbs = czbs*sarg;
      end else begin
        BSIM4qbs = 0.0;
        BSIM4capbs = 0.0;
      end
      if (czbssw>0.0) begin
        arg = 1.0-vbs_jct/BSIM4PhiBSWS;
        if (MJSWS==0.5) begin
          sarg = 1.0/sqrt(arg);
        end else begin
          sarg = exp(-MJSWS*ln(arg));
        end
        BSIM4qbs = BSIM4qbs + (BSIM4PhiBSWS*czbssw*(1.0-arg*sarg)/(1.0-MJSWS));
        BSIM4capbs = BSIM4capbs + (czbssw*sarg);
      end
      if (czbsswg>0.0) begin
        arg = 1.0-vbs_jct/BSIM4PhiBSWGS;
        if (MJSWGS==0.5) begin
          sarg = 1.0/sqrt(arg);
        end else begin
          sarg = exp(-MJSWGS*ln(arg));
        end
        BSIM4qbs = BSIM4qbs + (BSIM4PhiBSWGS*czbsswg*(1.0-arg*sarg)/(1.0-MJSWGS));
        BSIM4capbs = BSIM4capbs + (czbsswg*sarg);
      end
    end else begin
      load_T0 = czbs+czbssw+czbsswg;
      load_T1 = vbs_jct*(czbs*MJS/BSIM4PhiBS+czbssw*MJSWS/BSIM4PhiBSWS+czbsswg*MJSWGS/BSIM4PhiBSWGS);
      BSIM4qbs = vbs_jct*(load_T0+0.5*load_T1);
      BSIM4capbs = load_T0+load_T1;
    end
    if (vbd_jct==0.0) begin
      BSIM4qbd = 0.0;
      BSIM4capbd = czbd+czbdsw+czbdswg;
    end else if (vbd_jct<0.0) begin
      if (czbd>0.0) begin
        arg = 1.0-vbd_jct/BSIM4PhiBD;
        if (MJD==0.5) begin
          sarg = 1.0/sqrt(arg);
        end else begin
          sarg = exp(-MJD*ln(arg));
        end
        BSIM4qbd = BSIM4PhiBD*czbd*(1.0-arg*sarg)/(1.0-MJD);
        BSIM4capbd = czbd*sarg;
      end else begin
        BSIM4qbd = 0.0;
        BSIM4capbd = 0.0;
      end
      if (czbdsw>0.0) begin
        arg = 1.0-vbd_jct/BSIM4PhiBSWD;
        if (MJSWD==0.5) begin
          sarg = 1.0/sqrt(arg);
        end else begin
          sarg = exp(-MJSWD*ln(arg));
        end
        BSIM4qbd = BSIM4qbd + (BSIM4PhiBSWD*czbdsw*(1.0-arg*sarg)/(1.0-MJSWD));
        BSIM4capbd = BSIM4capbd + (czbdsw*sarg);
      end
      if (czbdswg>0.0) begin
        arg = 1.0-vbd_jct/BSIM4PhiBSWGD;
        if (MJSWGD==0.5) begin
          sarg = 1.0/sqrt(arg);
        end else begin
          sarg = exp(-MJSWGD*ln(arg));
        end
        BSIM4qbd = BSIM4qbd + (BSIM4PhiBSWGD*czbdswg*(1.0-arg*sarg)/(1.0-MJSWGD));
        BSIM4capbd = BSIM4capbd + (czbdswg*sarg);
      end
    end else begin
      load_T0 = czbd+czbdsw+czbdswg;
      load_T1 = vbd_jct*(czbd*MJD/BSIM4PhiBD+czbdsw*MJSWD/BSIM4PhiBSWD+czbdswg*MJSWGD/BSIM4PhiBSWGD);
      BSIM4qbd = vbd_jct*(load_T0+0.5*load_T1);
      BSIM4capbd = load_T0+load_T1;
    end
    BSIM4vds = load_vds;
    BSIM4vgs = load_vgs;
    BSIM4vbs = load_vbs;
    BSIM4vbd = vbd;
    BSIM4vges = vges;
    BSIM4vgms = vgms;
    BSIM4vdbs = vdbs;
    BSIM4vdbd = vdbd;
    BSIM4vsbs = vsbs;
    BSIM4vses = vses;
    BSIM4vdes = vdes;
    BSIM4qdef = load_qdef;
    if (i_BSIM4rgateMod==3) begin
      vgdx = vgmd;
      vgsx = vgms;
    end else begin
      vgdx = vgd;
      vgsx = load_vgs;
    end
    if (BSIM4capMod==0) begin
      load_cgdo = sd_BSIM4cgdo;
      qgdo = sd_BSIM4cgdo*vgdx;
      load_cgso = sd_BSIM4cgso;
      qgso = sd_BSIM4cgso*vgsx;
    end else begin
      load_T0 = vgdx+0.02;
      load_T1 = sqrt(load_T0*load_T0+4.0*0.02);
      load_T2 = 0.5*(load_T0-load_T1);
      load_T3 = BSIM4weffCV*sd_BSIM4cgdl;
      load_T4 = sqrt(1.0-4.0*load_T2/sd_BSIM4ckappad);
      load_cgdo = sd_BSIM4cgdo+load_T3-load_T3*(1.0-1.0/load_T4)*(0.5-0.5*load_T0/load_T1);
      qgdo = (sd_BSIM4cgdo+load_T3)*vgdx-load_T3*(load_T2+0.5*sd_BSIM4ckappad*(load_T4-1.0));
      load_T0 = vgsx+0.02;
      load_T1 = sqrt(load_T0*load_T0+4.0*0.02);
      load_T2 = 0.5*(load_T0-load_T1);
      load_T3 = BSIM4weffCV*sd_BSIM4cgsl;
      load_T4 = sqrt(1.0-4.0*load_T2/sd_BSIM4ckappas);
      load_cgso = sd_BSIM4cgso+load_T3-load_T3*(1.0-1.0/load_T4)*(0.5-0.5*load_T0/load_T1);
      qgso = (sd_BSIM4cgso+load_T3)*vgsx-load_T3*(load_T2+0.5*sd_BSIM4ckappas*(load_T4-1.0));
    end
    if (nf!=1.0) begin
      load_cgdo = load_cgdo * (nf);
      load_cgso = load_cgso * (nf);
      qgdo = qgdo * (nf);
      qgso = qgso * (nf);
    end
    i_BSIM4cgdo = load_cgdo;
    BSIM4qgdo = qgdo;
    i_BSIM4cgso = load_cgso;
    BSIM4qgso = qgso;
    if (BSIM4mode>0) begin
      if (i_BSIM4trnqsMod==0) begin
        qdrn = qdrn - (qgdo);
        if (i_BSIM4rgateMod==3) begin
          qgmb = sd_BSIM4cgbo*vgmb;
          qgmid = qgdo+qgso+qgmb;
          qbulk = qbulk - (qgmb);
          qsrc = -(qgate+qgmid+qbulk+qdrn);
        end else begin
          qgb = sd_BSIM4cgbo*vgb;
          qgate = qgate + (qgdo+qgso+qgb);
          qbulk = qbulk - (qgb);
          qsrc = -(qgate+qbulk+qdrn);
        end
        ggts = 0.0;
        ggtb = ggts;
        ggtd = ggtb;
        ggtg = ggtd;
        sxpart = 0.6;
        dxpart = 0.4;
        ddxpart_dVs = 0.0;
        ddxpart_dVb = ddxpart_dVs;
        ddxpart_dVg = ddxpart_dVb;
        ddxpart_dVd = ddxpart_dVg;
        dsxpart_dVs = 0.0;
        dsxpart_dVb = dsxpart_dVs;
        dsxpart_dVg = dsxpart_dVb;
        dsxpart_dVd = dsxpart_dVg;
      end else begin
        qcheq = BSIM4qchqs;
        CoxWL = BSIM4coxe*BSIM4weffCV*nf*BSIM4leffCV;
        load_T0 = load_qdef*ScalingFactor/CoxWL;
        BSIM4gtg = load_T0*BSIM4gcrgg;
        ggtg = BSIM4gtg;
        BSIM4gtd = load_T0*BSIM4gcrgd;
        ggtd = BSIM4gtd;
        BSIM4gts = load_T0*BSIM4gcrgs;
        ggts = BSIM4gts;
        BSIM4gtb = load_T0*BSIM4gcrgb;
        ggtb = BSIM4gtb;
        if (abs(qcheq)<=1.0e-5*CoxWL) begin
          if (xpart<0.5) begin
            dxpart = 0.4;
          end else if (xpart>0.5) begin
            dxpart = 0.0;
          end else begin
            dxpart = 0.5;
          end
          ddxpart_dVs = 0.0;
          ddxpart_dVb = ddxpart_dVs;
          ddxpart_dVg = ddxpart_dVb;
          ddxpart_dVd = ddxpart_dVg;
        end else begin
          dxpart = qdrn/qcheq;
          Cdd = BSIM4cddb;
          Csd = -(BSIM4cgdb+BSIM4cddb+BSIM4cbdb);
          ddxpart_dVd = (Cdd-dxpart*(Cdd+Csd))/qcheq;
          Cdg = BSIM4cdgb;
          Csg = -(BSIM4cggb+BSIM4cdgb+BSIM4cbgb);
          ddxpart_dVg = (Cdg-dxpart*(Cdg+Csg))/qcheq;
          Cds = BSIM4cdsb;
          Css = -(BSIM4cgsb+BSIM4cdsb+BSIM4cbsb);
          ddxpart_dVs = (Cds-dxpart*(Cds+Css))/qcheq;
          ddxpart_dVb = -(ddxpart_dVd+ddxpart_dVg+ddxpart_dVs);
        end
        sxpart = 1.0-dxpart;
        dsxpart_dVd = -ddxpart_dVd;
        dsxpart_dVg = -ddxpart_dVg;
        dsxpart_dVs = -ddxpart_dVs;
        dsxpart_dVb = -(dsxpart_dVd+dsxpart_dVg+dsxpart_dVs);
        if (i_BSIM4rgateMod==3) begin
          qgmb = sd_BSIM4cgbo*vgmb;
          qgmid = qgdo+qgso+qgmb;
          qgate = 0.0;
          qbulk = -qgmb;
          qdrn = -qgdo;
          qsrc = -(qgmid+qbulk+qdrn);
        end else begin
          qgb = sd_BSIM4cgbo*vgb;
          qgate = qgdo+qgso+qgb;
          qbulk = -qgb;
          qdrn = -qgdo;
          qsrc = -(qgate+qbulk+qdrn);
        end
      end
    end else if (i_BSIM4trnqsMod==0) begin
      qsrc = qdrn-qgso;
      if (i_BSIM4rgateMod==3) begin
        qgmb = sd_BSIM4cgbo*vgmb;
        qgmid = qgdo+qgso+qgmb;
        qbulk = qbulk - (qgmb);
        qdrn = -(qgate+qgmid+qbulk+qsrc);
      end else begin
        qgb = sd_BSIM4cgbo*vgb;
        qgate = qgate + (qgdo+qgso+qgb);
        qbulk = qbulk - (qgb);
        qdrn = -(qgate+qbulk+qsrc);
      end
      ggts = 0.0;
      ggtb = ggts;
      ggtd = ggtb;
      ggtg = ggtd;
      sxpart = 0.4;
      dxpart = 0.6;
      ddxpart_dVs = 0.0;
      ddxpart_dVb = ddxpart_dVs;
      ddxpart_dVg = ddxpart_dVb;
      ddxpart_dVd = ddxpart_dVg;
      dsxpart_dVs = 0.0;
      dsxpart_dVb = dsxpart_dVs;
      dsxpart_dVg = dsxpart_dVb;
      dsxpart_dVd = dsxpart_dVg;
    end else begin
      qcheq = BSIM4qchqs;
      CoxWL = BSIM4coxe*BSIM4weffCV*nf*BSIM4leffCV;
      load_T0 = load_qdef*ScalingFactor/CoxWL;
      BSIM4gtg = load_T0*BSIM4gcrgg;
      ggtg = BSIM4gtg;
      BSIM4gts = load_T0*BSIM4gcrgd;
      ggts = BSIM4gts;
      BSIM4gtd = load_T0*BSIM4gcrgs;
      ggtd = BSIM4gtd;
      BSIM4gtb = load_T0*BSIM4gcrgb;
      ggtb = BSIM4gtb;
      if (abs(qcheq)<=1.0e-5*CoxWL) begin
        if (xpart<0.5) begin
          sxpart = 0.4;
        end else if (xpart>0.5) begin
          sxpart = 0.0;
        end else begin
          sxpart = 0.5;
        end
        dsxpart_dVs = 0.0;
        dsxpart_dVb = dsxpart_dVs;
        dsxpart_dVg = dsxpart_dVb;
        dsxpart_dVd = dsxpart_dVg;
      end else begin
        sxpart = qdrn/qcheq;
        Css = BSIM4cddb;
        Cds = -(BSIM4cgdb+BSIM4cddb+BSIM4cbdb);
        dsxpart_dVs = (Css-sxpart*(Css+Cds))/qcheq;
        Csg = BSIM4cdgb;
        Cdg = -(BSIM4cggb+BSIM4cdgb+BSIM4cbgb);
        dsxpart_dVg = (Csg-sxpart*(Csg+Cdg))/qcheq;
        Csd = BSIM4cdsb;
        Cdd = -(BSIM4cgsb+BSIM4cdsb+BSIM4cbsb);
        dsxpart_dVd = (Csd-sxpart*(Csd+Cdd))/qcheq;
        dsxpart_dVb = -(dsxpart_dVd+dsxpart_dVg+dsxpart_dVs);
      end
      dxpart = 1.0-sxpart;
      ddxpart_dVd = -dsxpart_dVd;
      ddxpart_dVg = -dsxpart_dVg;
      ddxpart_dVs = -dsxpart_dVs;
      ddxpart_dVb = -(ddxpart_dVd+ddxpart_dVg+ddxpart_dVs);
      if (i_BSIM4rgateMod==3) begin
        qgmb = sd_BSIM4cgbo*vgmb;
        qgmid = qgdo+qgso+qgmb;
        qgate = 0.0;
        qbulk = -qgmb;
        qdrn = -qgdo;
        qsrc = -qgso;
      end else begin
        qgb = sd_BSIM4cgbo*vgb;
        qgate = qgdo+qgso+qgb;
        qbulk = -qgb;
        qdrn = -qgdo;
        qsrc = -qgso;
      end
    end
    if (i_BSIM4trnqsMod) begin
      BSIM4qcdump = load_qdef*ScalingFactor;
    end else begin
      BSIM4qcdump = 0;
    end
    geq = 0;
    BSIM4cqcdump = ddt(BSIM4qcdump);
    ceq = BSIM4cqcdump;
    BSIM4qg = qgate;
    BSIM4qd = qdrn-BSIM4qbd;
    BSIM4qs = qsrc-BSIM4qbs;
    if (i_BSIM4rgateMod==3) begin
      BSIM4qgmid = qgmid;
    end else begin
      BSIM4qgmid = 0;
    end
    if (!i_BSIM4rbodyMod) begin
      BSIM4qb = qbulk+BSIM4qbd+BSIM4qbs;
    end else begin
      BSIM4qb = qbulk;
    end
    geq = 0;
    BSIM4cqb = ddt(BSIM4qb);
    ceq = BSIM4cqb;
    geq = 0;
    BSIM4cqg = ddt(BSIM4qg);
    ceq = BSIM4cqg;
    geq = 0;
    BSIM4cqd = ddt(BSIM4qd);
    ceq = BSIM4cqd;
    geq = 0;
    BSIM4cqgmid = ddt(BSIM4qgmid);
    ceq = BSIM4cqgmid;
    geq = 0;
    BSIM4cqbs = ddt(BSIM4qbs);
    ceq = BSIM4cqbs;
    geq = 0;
    BSIM4cqbd = ddt(BSIM4qbd);
    ceq = BSIM4cqbd;
    cqgate = BSIM4cqg;
    cqbody = BSIM4cqb;
    cqdrn = BSIM4cqd;
    ceqqg = cqgate;
    ceqqd = cqdrn;
    ceqqb = cqbody;
    if (i_BSIM4rgateMod==3) begin
      ceqqgmid = BSIM4cqgmid;
    end else begin
      ceqqgmid = 0.0;
    end
    if (i_BSIM4rbodyMod) begin
      ceqqjs = BSIM4cqbs;
      ceqqjd = BSIM4cqbd;
    end
    if (i_BSIM4trnqsMod) begin
      load_T0 = 0;
      ceqqg = ceqqg + (load_T0);
      load_T1 = 0;
      ceqqd = ceqqd - (dxpart*load_T0);
      cqdef = BSIM4cqcdump;
      cqcheq = BSIM4cqcheq+load_T0;
    end
    if (BSIM4mode>=0) begin
      Gm = BSIM4gm;
      Gmbs = BSIM4gmbs;
      FwdSum = Gm+Gmbs;
      RevSum = 0.0;
      ceqdrn = BSIM4type*cdrain;
      ceqbd = BSIM4type*(BSIM4csub+BSIM4Igidl);
      ceqbs = BSIM4type*BSIM4Igisl;
      gbbdp = -BSIM4gbds;
      gbbsp = BSIM4gbds+BSIM4gbgs+BSIM4gbbs;
      gbdpg = BSIM4gbgs;
      gbdpdp = BSIM4gbds;
      gbdpb = BSIM4gbbs;
      gbdpsp = -(gbdpg+gbdpdp+gbdpb);
      gbspg = 0.0;
      gbspdp = 0.0;
      gbspb = 0.0;
      gbspsp = 0.0;
      if (BSIM4igcMod) begin
        gIstotg = BSIM4gIgsg+BSIM4gIgcsg;
        gIstotd = BSIM4gIgcsd;
        gIstots = BSIM4gIgss+BSIM4gIgcss;
        gIstotb = BSIM4gIgcsb;
        Istoteq = BSIM4type*(BSIM4Igs+BSIM4Igcs);
        gIdtotg = BSIM4gIgdg+BSIM4gIgcdg;
        gIdtotd = BSIM4gIgdd+BSIM4gIgcdd;
        gIdtots = BSIM4gIgcds;
        gIdtotb = BSIM4gIgcdb;
        Idtoteq = BSIM4type*(BSIM4Igd+BSIM4Igcd);
      end else begin
        Istoteq = 0.0;
        gIstotb = Istoteq;
        gIstots = gIstotb;
        gIstotd = gIstots;
        gIstotg = gIstotd;
        Idtoteq = 0.0;
        gIdtotb = Idtoteq;
        gIdtots = gIdtotb;
        gIdtotd = gIdtots;
        gIdtotg = gIdtotd;
      end
      if (BSIM4igbMod) begin
        gIbtotg = BSIM4gIgbg;
        gIbtotd = BSIM4gIgbd;
        gIbtots = BSIM4gIgbs;
        gIbtotb = BSIM4gIgbb;
        Ibtoteq = BSIM4type*BSIM4Igb;
      end else begin
        Ibtoteq = 0.0;
        gIbtotb = Ibtoteq;
        gIbtots = gIbtotb;
        gIbtotd = gIbtots;
        gIbtotg = gIbtotd;
      end
      if (BSIM4igcMod!=0||BSIM4igbMod!=0) begin
        gIgtotg = gIstotg+gIdtotg+gIbtotg;
        gIgtotd = gIstotd+gIdtotd+gIbtotd;
        gIgtots = gIstots+gIdtots+gIbtots;
        gIgtotb = gIstotb+gIdtotb+gIbtotb;
        Igtoteq = Istoteq+Idtoteq+Ibtoteq;
      end else begin
        Igtoteq = 0.0;
        gIgtotb = Igtoteq;
        gIgtots = gIgtotb;
        gIgtotd = gIgtots;
        gIgtotg = gIgtotd;
      end
      if (i_BSIM4rgateMod==2) begin
        load_T0 = vges-load_vgs;
      end else if (i_BSIM4rgateMod==3) begin
        load_T0 = vgms-load_vgs;
      end
      if (i_BSIM4rgateMod>1) begin
        gcrgd = BSIM4gcrgd*load_T0;
        gcrgg = BSIM4gcrgg*load_T0;
        gcrgs = BSIM4gcrgs*load_T0;
        gcrgb = BSIM4gcrgb*load_T0;
        ceqgcrg = 0;
        gcrgg = gcrgg - (BSIM4gcrg);
        load_gcrg = BSIM4gcrg;
      end else begin
        gcrgb = 0.0;
        gcrgs = gcrgb;
        gcrgg = gcrgs;
        gcrgd = gcrgg;
        load_gcrg = gcrgd;
        ceqgcrg = 0;
      end
    end else begin
      Gm = -BSIM4gm;
      Gmbs = -BSIM4gmbs;
      FwdSum = 0.0;
      RevSum = -(Gm+Gmbs);
      ceqdrn = -BSIM4type*cdrain;
      ceqbs = BSIM4type*(BSIM4csub+BSIM4Igisl);
      ceqbd = BSIM4type*BSIM4Igidl;
      gbbsp = -BSIM4gbds;
      gbbdp = BSIM4gbds+BSIM4gbgs+BSIM4gbbs;
      gbdpg = 0.0;
      gbdpsp = 0.0;
      gbdpb = 0.0;
      gbdpdp = 0.0;
      gbspg = BSIM4gbgs;
      gbspsp = BSIM4gbds;
      gbspb = BSIM4gbbs;
      gbspdp = -(gbspg+gbspsp+gbspb);
      if (BSIM4igcMod) begin
        gIstotg = BSIM4gIgsg+BSIM4gIgcdg;
        gIstotd = BSIM4gIgcds;
        gIstots = BSIM4gIgss+BSIM4gIgcdd;
        gIstotb = BSIM4gIgcdb;
        Istoteq = BSIM4type*(BSIM4Igs+BSIM4Igcd);
        gIdtotg = BSIM4gIgdg+BSIM4gIgcsg;
        gIdtotd = BSIM4gIgdd+BSIM4gIgcss;
        gIdtots = BSIM4gIgcsd;
        gIdtotb = BSIM4gIgcsb;
        Idtoteq = BSIM4type*(BSIM4Igd+BSIM4Igcs);
      end else begin
        Istoteq = 0.0;
        gIstotb = Istoteq;
        gIstots = gIstotb;
        gIstotd = gIstots;
        gIstotg = gIstotd;
        Idtoteq = 0.0;
        gIdtotb = Idtoteq;
        gIdtots = gIdtotb;
        gIdtotd = gIdtots;
        gIdtotg = gIdtotd;
      end
      if (BSIM4igbMod) begin
        gIbtotg = BSIM4gIgbg;
        gIbtotd = BSIM4gIgbs;
        gIbtots = BSIM4gIgbd;
        gIbtotb = BSIM4gIgbb;
        Ibtoteq = BSIM4type*BSIM4Igb;
      end else begin
        Ibtoteq = 0.0;
        gIbtotb = Ibtoteq;
        gIbtots = gIbtotb;
        gIbtotd = gIbtots;
        gIbtotg = gIbtotd;
      end
      if (BSIM4igcMod!=0||BSIM4igbMod!=0) begin
        gIgtotg = gIstotg+gIdtotg+gIbtotg;
        gIgtotd = gIstotd+gIdtotd+gIbtotd;
        gIgtots = gIstots+gIdtots+gIbtots;
        gIgtotb = gIstotb+gIdtotb+gIbtotb;
        Igtoteq = Istoteq+Idtoteq+Ibtoteq;
      end else begin
        Igtoteq = 0.0;
        gIgtotb = Igtoteq;
        gIgtots = gIgtotb;
        gIgtotd = gIgtots;
        gIgtotg = gIgtotd;
      end
      if (i_BSIM4rgateMod==2) begin
        load_T0 = vges-load_vgs;
      end else if (i_BSIM4rgateMod==3) begin
        load_T0 = vgms-load_vgs;
      end
      if (i_BSIM4rgateMod>1) begin
        gcrgd = BSIM4gcrgs*load_T0;
        gcrgg = BSIM4gcrgg*load_T0;
        gcrgs = BSIM4gcrgd*load_T0;
        gcrgb = BSIM4gcrgb*load_T0;
        ceqgcrg = 0;
        gcrgg = gcrgg - (BSIM4gcrg);
        load_gcrg = BSIM4gcrg;
      end else begin
        gcrgb = 0.0;
        gcrgs = gcrgb;
        gcrgg = gcrgs;
        gcrgd = gcrgg;
        load_gcrg = gcrgd;
        ceqgcrg = 0;
      end
    end
    if (BSIM4rdsMod==1) begin
      ceqgstot = BSIM4type*(BSIM4gstotd*load_vds+BSIM4gstotg*load_vgs+BSIM4gstotb*load_vbs);
      gstot = BSIM4gstot;
      gstotd = BSIM4gstotd;
      gstotg = BSIM4gstotg;
      gstots = BSIM4gstots-gstot;
      gstotb = BSIM4gstotb;
      ceqgdtot = -BSIM4type*(BSIM4gdtotd*load_vds+BSIM4gdtotg*load_vgs+BSIM4gdtotb*load_vbs);
      gdtot = BSIM4gdtot;
      gdtotd = BSIM4gdtotd-gdtot;
      gdtotg = BSIM4gdtotg;
      gdtots = BSIM4gdtots;
      gdtotb = BSIM4gdtotb;
    end else begin
      ceqgstot = 0.0;
      gstotb = ceqgstot;
      gstots = gstotb;
      gstotg = gstots;
      gstotd = gstotg;
      gstot = gstotd;
      ceqgdtot = 0.0;
      gdtotb = ceqgdtot;
      gdtots = gdtotb;
      gdtotg = gdtots;
      gdtotd = gdtotg;
      gdtot = gdtotd;
    end
    if (BSIM4type>0) begin
      ceqjs = BSIM4cbs;
      ceqjd = BSIM4cbd;
    end else begin
      ceqjs = -BSIM4cbs;
      ceqjd = -BSIM4cbd;
      ceqqg = -ceqqg;
      ceqqd = -ceqqd;
      ceqqb = -ceqqb;
      ceqgcrg = -ceqgcrg;
      if (i_BSIM4trnqsMod) begin
        cqdef = -cqdef;
        cqcheq = -cqcheq;
      end
      if (i_BSIM4rbodyMod) begin
        ceqqjs = -ceqqjs;
        ceqqjd = -ceqqjd;
      end
      if (i_BSIM4rgateMod==3) begin
        ceqqgmid = -ceqqgmid;
      end
    end
    load_mult_i = mult_i;
    load_mult_q = mult_q;
    if (!i_BSIM4rbodyMod) begin
      gjbd = BSIM4gbd;
      gjbs = BSIM4gbs;
    end else begin
      gjbs = 0.0;
      gjbd = gjbs;
    end
    if (!BSIM4rdsMod) begin
      gdpr = BSIM4drainConductance;
      gspr = BSIM4sourceConductance;
    end else begin
      gspr = 0.0;
      gdpr = gspr;
    end
    geltd = BSIM4grgeltd;
    load_T1 = 0;
    ggidld = BSIM4ggidld;
    ggidlg = BSIM4ggidlg;
    ggidlb = BSIM4ggidlb;
    ggislg = BSIM4ggislg;
    ggisls = BSIM4ggisls;
    ggislb = BSIM4ggislb;
    I(d_int) <+ -load_mult_i * ( 
          ceqjd 
        - ceqbd 
        - ceqdrn 
        + Idtoteq
    ) + load_mult_q * ceqqd;
    I(g_int) <+ (
          load_mult_q * ceqqg 
        + load_mult_i * Igtoteq
    );
    
    // Substrate resistance network
    if (!i_BSIM4rbodyMod) begin
        // Disabled substrate resistance network
        // Diodes b_int-s_int and b_int-d_int
        I(b_int) <+ -load_mult_i * ( 
              ceqbd 
            + ceqbs 
            - ceqjd 
            - ceqjs 
            + Ibtoteq 
        ) + load_mult_q * ceqqb ;
        I(s_int) <+ -load_mult_i * ( 
              ceqdrn 
            - ceqbs 
            + ceqjs 
            + Istoteq
        ) - load_mult_q * (
            + ceqqg 
            + ceqqb 
            + ceqqd
            + ceqqgmid 
        );
    end else begin
        // Enabled substrate resistance network
        // Nonlinear/capacitive part
        // Diodes sb_int-s_int and sb_int-s_int
        // Capacitive current flowing towards d_int/s_int is ceqqjd/ceqqjs 
        I(db_int) <+ load_mult_i * ceqjd + load_mult_q * ceqqjd; 
        I(b_int) <+ -load_mult_i * ( 
              ceqbd 
            + ceqbs 
            + Ibtoteq 
        ) + load_mult_q * ceqqb;
        I(sb_int) <+ load_mult_i * ceqjs + load_mult_q * ceqqjs;
        I(s_int) <+ -load_mult_i * ( 
              ceqdrn 
            - ceqbs 
            + ceqjs 
            + Istoteq
        ) - load_mult_q * (
              ceqqd 
            + ceqqg 
            + ceqqb 
            + ceqqjd // qs = -(qg+qd+qb), ceqqd is ddt(qd-qbd), ceqqjd=ddt(qbd)
                                // therefore ddt(qd)=ceqqd+ceqqjd
            + ceqqjs // ceqjs=ddt(qbs) flows into s_int, we must add it here
            + ceqqgmid 
        );
    
        // Linear resistive part
        I(b, db_int) <+ load_mult_i * BSIM4grbdb * V(b, db_int);
        I(b, b_int) <+ load_mult_i * BSIM4grbpb * V(b, b_int);
        I(b_int, db_int) <+ load_mult_i * BSIM4grbpd * V(b_int, db_int);
        I(b_int, sb_int) <+ load_mult_i * BSIM4grbps * V(b_int, sb_int);
        I(b, sb_int) <+ load_mult_i * BSIM4grbsb * V(b, sb_int);
    end
    
    // Gate series resistance 
    // It was eliminated during nonlinear term processing. 
    if (i_BSIM4rgateMod==1) begin
        // geltd is the conductance of Rgeltd
        I(g, g_int) <+ load_mult_i * geltd * V(g, g_int);
    end else if (i_BSIM4rgateMod==2) begin
        // BSIM4gcrg is the conductance of Rgeltd and Rii in series
        I(g, g_int) <+ load_mult_i * BSIM4gcrg * V(g, g_int);
    end else if (i_BSIM4rgateMod==3) begin
        // geltd is the conductance of Rgeltd
        I(g, gmid_int) <+ load_mult_i * geltd * V(g, gmid_int);
        // BSIM4gcrg is the conductance of Rii
        I(gmid_int, g_int) <+ load_mult_i * BSIM4gcrg * V(gmid_int, g_int);
        // Capacitors connected to gmid
        I(gmid_int) <+ load_mult_q * ceqqgmid;
    end
    
    // Series resistance of D/S
    if (!BSIM4rdsMod) begin
        // Internal Rds model (rdsmod=0)
        // Voltage-dependent Rds is symmetric wrt. D/S and accounted for in Ids characteristic
        // Drain series resistance Rddiff
        I(d, d_int) <+ load_mult_i * gdpr * V(d, d_int);
        // Source series resistance Rsdiff
        I(s, s_int) <+ load_mult_i * gspr * V(s, s_int);
    end else begin
        // External Rd/Rs model (included in series resistances of D/S)
        // Rd and Rs are voltage dependent 
        // Drain series resistance: Rddiff + Rd(V)
        // Source series resistance: Rsdiff + Rs(V)
        I(d, d_int) <+ load_mult_i * BSIM4gdtot * V(d, d_int);
        I(s, s_int) <+ load_mult_i * BSIM4gstot * V(s, s_int);
    end
    
    // NQS model
    if (i_BSIM4trnqsMod) begin
        // Internal charge node, input is unscaled charge, output is unscaled delayed charge
        I(q_int) <+ -(cqcheq-cqdef) + BSIM4gtau * V(q_int);
        // Contributions to d_int, g_int, and s_int, scaled with mult_q
        I(d_int) <+ load_mult_q * dxpart * BSIM4gtau * V(q_int);
        I(s_int) <+ load_mult_q * sxpart * BSIM4gtau * V(q_int);
        I(g_int) <+ - load_mult_q * BSIM4gtau * V(q_int);
    end

    // Tag: noise, function: BSIM4noise
    noise_tmp = 0.0;
    npart_theta = 0.0;
    npart_beta = 0.0;
    GammaGd0 = 0.0;
    sigrat = 0.0;
    ctnoi = 0.0;
    noise_mult_i = mult_i;
    noise_mult_fn = BSIM4mult_fn;
    if (BSIM4tnoiMod==0) begin
      if (BSIM4rdsMod==0) begin
        noise_gspr = BSIM4sourceConductance;
        noise_gdpr = BSIM4drainConductance;
        if (BSIM4grdsw>0.0) begin
          noise_tmp = 1.0/BSIM4grdsw;
        end else begin
          noise_tmp = 0.0;
        end
      end else begin
        noise_gspr = BSIM4gstot;
        noise_gdpr = BSIM4gdtot;
        noise_tmp = 0.0;
      end
    end else if (BSIM4tnoiMod==1) begin
      noise_T5 = BSIM4Vgsteff/BSIM4EsatL;
      noise_T5 = noise_T5 * (noise_T5);
      npart_beta = rnoia*(1.0+noise_T5*tnoia*BSIM4leff);
      npart_theta = rnoib*(1.0+noise_T5*tnoib*BSIM4leff);
      if (npart_theta>0.9) begin
        npart_theta = 0.9;
      end
      if (npart_theta>0.9*npart_beta) begin
        npart_theta = 0.9*npart_beta;
      end
      if (BSIM4rdsMod==0) begin
        noise_gspr = BSIM4sourceConductance;
        noise_gdpr = BSIM4drainConductance;
      end else begin
        noise_gspr = BSIM4gstot;
        noise_gdpr = BSIM4gdtot;
      end
      if (BSIM4vds>=0.0) begin
        noise_gspr = noise_gspr*(1.0+npart_theta*npart_theta*noise_gspr/BSIM4IdovVds);
      end else begin
        noise_gdpr = noise_gdpr*(1.0+npart_theta*npart_theta*noise_gdpr/BSIM4IdovVds);
      end
    end else if (BSIM4rdsMod==0) begin
      noise_gspr = BSIM4sourceConductance;
      noise_gdpr = BSIM4drainConductance;
    end else begin
      noise_gspr = BSIM4gstot;
      noise_gdpr = BSIM4gdtot;
    end
    I(d_int, d) <+ white_noise(4*(VACONSTboltz*($temperature*(noise_gdpr*noise_mult_i))), "rd");
    I(s_int, s) <+ white_noise(4*(VACONSTboltz*($temperature*(noise_gspr*noise_mult_i))), "rs");
    if (i_BSIM4rgateMod==1) begin
      rg_psd = 4*(VACONSTboltz*($temperature*(BSIM4grgeltd*noise_mult_i)));
    end else if (i_BSIM4rgateMod==2) begin
      noise_T0 = 1.0+BSIM4grgeltd/BSIM4gcrg;
      noise_T1 = noise_T0*noise_T0;
      rg_psd = 4*(VACONSTboltz*($temperature*(BSIM4grgeltd*noise_mult_i/noise_T1)));
    end else if (i_BSIM4rgateMod==3) begin
      `ifdef __NGSPICE__
      I(gmid_int, g) <+ white_noise(4*(VACONSTboltz*($temperature*(BSIM4grgeltd*noise_mult_i))), "rg3");
      `else
      I(gmid_int, g) <+ white_noise(4*(VACONSTboltz*($temperature*(BSIM4grgeltd*noise_mult_i))), "rg");
      `endif
    end
    noise_bodymode = 5;
    if (i_BSIM4rbodyMod==2) begin
      if (!$param_given(rbps0)||!$param_given(rbpd0)) begin
        noise_bodymode = 1;
      end else if (!$param_given(rbsbx0)&&!$param_given(rbsby0)||!$param_given(rbdbx0)&&!$param_given(rbdby0)) begin
        noise_bodymode = 3;
      end
    end
    if (i_BSIM4rbodyMod) begin
      if (noise_bodymode==5) begin
        rbps_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbps*noise_mult_i)));
        rbpd_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbpd*noise_mult_i)));
        rbpb_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbpb*noise_mult_i)));
        I(b, sb_int) <+ white_noise(4*(VACONSTboltz*($temperature*(BSIM4grbsb*noise_mult_i))), "rbsb");
        I(b, db_int) <+ white_noise(4*(VACONSTboltz*($temperature*(BSIM4grbdb*noise_mult_i))), "rbdb");
      end
      if (noise_bodymode==3) begin
        rbps_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbps*noise_mult_i)));
        rbpd_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbpd*noise_mult_i)));
        rbpb_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbpb*noise_mult_i)));
      end
      if (noise_bodymode==1) begin
        rbpb_psd = 4*(VACONSTboltz*($temperature*(BSIM4grbpb*noise_mult_i)));
      end
    end
    if (BSIM4tnoiMod==2) begin
      eta = 1.0-BSIM4Vdseff*BSIM4AbovVgst2Vtm;
      noise_T0 = 1.0-eta;
      noise_T1 = 1.0+eta;
      noise_T2 = noise_T1+2.0*BSIM4Abulk*BSIM4vtm/BSIM4Vgsteff;
      noise_Leff = BSIM4leff;
      Lvsat = noise_Leff*(1.0+BSIM4Vdseff/BSIM4EsatL);
      noise_T6 = noise_Leff/Lvsat;
      gamma = noise_T6*(0.5*noise_T1+noise_T0*noise_T0/(6.0*noise_T2));
      noise_T3 = noise_T2*noise_T2;
      noise_T4 = noise_T0*noise_T0;
      noise_T5 = noise_T3*noise_T3;
      noise_delta = (noise_T1/noise_T3-(5.0*noise_T1+noise_T2)*noise_T4/(15.0*noise_T5)+noise_T4*noise_T4/(9.0*noise_T5*noise_T2))/(6.0*noise_T6*noise_T6*noise_T6);
      noise_T7 = noise_T0/noise_T2;
      epsilon = (noise_T7-noise_T7*noise_T7*noise_T7/3.0)/(6.0*noise_T6);
      noise_T8 = BSIM4Vgsteff/BSIM4EsatL;
      noise_T8 = noise_T8 * (noise_T8);
      if (BSIM4v48intVersion<=480) begin
        npart_c = rnoic*(1.0+noise_T8*tnoic*noise_Leff);
        ctnoi = epsilon/sqrt(gamma*noise_delta)*(2.5316*npart_c);
        npart_beta = rnoia*(1.0+noise_T8*tnoia*noise_Leff);
        npart_theta = rnoib*(1.0+noise_T8*tnoib*noise_Leff);
        gamma = gamma*(3.0*npart_beta*npart_beta);
        noise_delta = noise_delta*(3.75*npart_theta*npart_theta);
        GammaGd0 = gamma*BSIM4noiGd0;
        C0 = BSIM4Coxeff*BSIM4weffCV*nf*BSIM4leffCV;
        noise_T0 = C0/BSIM4noiGd0;
        sigrat = noise_T0*sqrt(noise_delta/gamma);
      end else begin
        npart_c = rnoic*(1.0+noise_T8*tnoic*noise_Leff);
        noise_T9 = gamma*noise_delta;
        if (noise_T9>0) begin
          ctnoi = epsilon/sqrt(gamma*noise_delta)*(2.5316*npart_c);
        end else begin
          ctnoi = 1.0;
        end
        if (ctnoi>1) begin
          ctnoi = 1;
        end
        if (ctnoi<0) begin
          ctnoi = 0;
        end
        npart_beta = rnoia*(1.0+noise_T8*tnoia*noise_Leff);
        npart_theta = rnoib*(1.0+noise_T8*tnoib*noise_Leff);
        gamma = gamma*(3.0*npart_beta*npart_beta);
        noise_delta = noise_delta*(3.75*npart_theta*npart_theta);
        GammaGd0 = gamma*BSIM4noiGd0;
        C0 = BSIM4Coxeff*BSIM4weffCV*nf*BSIM4leffCV;
        noise_T0 = C0/BSIM4noiGd0;
        if (gamma>0&&noise_delta>0) begin
          sigrat = noise_T0*sqrt(noise_delta/gamma);
        end else begin
          sigrat = 0.0;
        end
      end
    end
    case (BSIM4tnoiMod)
      0: begin
        if (BSIM4v48intVersion<=480) begin
          noise_T0 = BSIM4ueff*abs(BSIM4qinv);
          noise_T1 = noise_T0*noise_tmp+BSIM4leff*BSIM4leff;
          id_psd = 4*(VACONSTboltz*($temperature*(noise_T0/noise_T1*ntnoi*noise_mult_i)));
        end else begin
          noise_T0 = BSIM4ueff*abs(BSIM4qinv);
          noise_T1 = noise_T0*noise_tmp+BSIM4leff*BSIM4leff;
          id_psd = 4*(VACONSTboltz*($temperature*(noise_T0/noise_T1*ntnoi*noise_mult_i)));
        end
      end
      1: begin
        if (BSIM4v48intVersion<=480) begin
          noise_T0 = BSIM4gm+BSIM4gmbs+BSIM4gds;
          noise_T0 = noise_T0 * (noise_T0);
          igsquare = npart_theta*npart_theta*noise_T0/BSIM4IdovVds;
          noise_T1 = npart_beta*(BSIM4gm+BSIM4gmbs)+BSIM4gds;
          noise_T2 = noise_T1*noise_T1/BSIM4IdovVds;
          id_psd = 4*(VACONSTboltz*($temperature*((noise_T2-igsquare)*noise_mult_i)));
        end else begin
          noise_T0 = BSIM4gm+BSIM4gmbs+BSIM4gds;
          noise_T0 = noise_T0 * (noise_T0);
          igsquare = npart_theta*npart_theta*noise_T0/BSIM4IdovVds;
          noise_T1 = npart_beta*(BSIM4gm+BSIM4gmbs)+BSIM4gds;
          noise_T2 = noise_T1*noise_T1/BSIM4IdovVds;
          id_psd = 4*(VACONSTboltz*($temperature*((noise_T2-igsquare)*noise_mult_i)));
        end
      end
      2: begin
        noise_T2 = GammaGd0;
        noise_T3 = ctnoi*ctnoi;
        noise_T4 = 1.0-noise_T3;
        id_psd = 4*(VACONSTboltz*($temperature*(noise_T2*noise_T4*noise_mult_i)));
        tn2dspsd = 4 * VACONSTboltz * $temperature * noise_T2 * noise_T3;
        tn2gspsd = 4 * VACONSTboltz * $temperature * noise_T2;
        tn2sigrat = sigrat;
      end
    endcase

    case (BSIM4fnoiMod)
      0: begin
        flicker_psd = ((BSIM4mode*BSIM4cd>=0) ? (1) : (-1))*(noise_mult_fn*kf*exp(af*ln(((abs(BSIM4mode*BSIM4cd)>1E-38) ? (abs(BSIM4mode*BSIM4cd)) : (1E-38))))/(BSIM4leff*BSIM4leff*BSIM4coxe));
        flicker_exp = ef;
      end
      1: begin
        noise_Vds = BSIM4vds;
        if (noise_Vds<0.0) begin
          noise_Vds = -noise_Vds;
        end
        // inlined: Eval1ovFNoise(Vds, model, here, data->freq, ckt->CKTtemp) -> efn_retval
        cd = abs(BSIM4cd);
        noise1_Leff = BSIM4leff-2.0*lintnoi;
        Leffsq = noise1_Leff*noise1_Leff;
        esat = 2.0*BSIM4vsattemp/BSIM4ueff;
        if (em<=0.0) begin
          DelClm = 0.0;
        end else begin
          noise1_T0 = ((noise_Vds-BSIM4Vdseff)/BSIM4litl+em)/esat;
          DelClm = BSIM4litl*ln(((noise1_T0>1E-38) ? (noise1_T0) : (1E-38)));
          if (DelClm<0.0) begin
            DelClm = 0.0;
          end
        end
        noise1_T1 = 1.6021766208e-19*1.6021766208e-19*1.38064852e-23*cd*$temperature*BSIM4ueff;
        noise1_T2 = 1.0e10*BSIM4Abulk*BSIM4coxe*Leffsq;
        N0 = BSIM4coxe*BSIM4Vgsteff/1.6021766208e-19;
        Nl = BSIM4coxe*BSIM4Vgsteff*(1.0-BSIM4AbovVgst2Vtm*BSIM4Vdseff)/1.6021766208e-19;
        noise1_T3 = BSIM4oxideTrapDensityA*ln((((N0+BSIM4nstar)/(Nl+BSIM4nstar)>1E-38) ? ((N0+BSIM4nstar)/(Nl+BSIM4nstar)) : (1E-38)));
        noise1_T4 = BSIM4oxideTrapDensityB*(N0-Nl);
        noise1_T5 = noic*0.5*(N0*N0-Nl*Nl);
        noise1_T6 = 1.38064852e-23*$temperature*cd*cd;
        noise1_T7 = 1.0e10*Leffsq*BSIM4weff*nf;
        noise1_T8 = BSIM4oxideTrapDensityA+BSIM4oxideTrapDensityB*Nl+noic*Nl*Nl;
        noise1_T9 = (Nl+BSIM4nstar)*(Nl+BSIM4nstar);
        noise1_Ssi = noise1_T1/noise1_T2*(noise1_T3+noise1_T4+noise1_T5)+noise1_T6/noise1_T7*DelClm*noise1_T8/noise1_T9;
        efn_retval = noise1_Ssi;
        // end of inlined: Eval1ovFNoise(Vds, model, here, data->freq, ckt->CKTtemp) -> efn_retval
        Ssi = efn_retval;
        noise_T10 = BSIM4oxideTrapDensityA*1.38064852e-23*$temperature;
        noise_T11 = BSIM4weff*nf*BSIM4leff*1.0e10*BSIM4nstar*BSIM4nstar;
        Swi = noise_T10/noise_T11*BSIM4cd*BSIM4cd;
        noise_T1 = Swi+Ssi;
        if (noise_T1>0.0) begin
          flicker_psd = ((BSIM4mode*BSIM4cd>=0) ? (1) : (-1))*(noise_mult_fn*(Ssi*Swi)/noise_T1);
          flicker_exp = ef;
        end else begin
          flicker_psd = 0.0;
          flicker_exp = ef;
        end
      end
    endcase

    if (BSIM4mode>=0) begin
      igs_psd = 2*(VACONSTcharge*(noise_mult_i*(BSIM4Igs+BSIM4Igcs)));
      igd_psd = 2*(VACONSTcharge*(noise_mult_i*(BSIM4Igd+BSIM4Igcd)));
    end else begin
      igs_psd = 2*(VACONSTcharge*(noise_mult_i*(BSIM4Igs+BSIM4Igcd)));
      igd_psd = 2*(VACONSTcharge*(noise_mult_i*(BSIM4Igd+BSIM4Igcs)));
    end
    I(g_int, b_int) <+ white_noise(2*(VACONSTcharge*(noise_mult_i*BSIM4Igb)), "igb");
    I(g_int, g) <+ white_noise(rg_psd, "rg");
    I(b_int, sb_int) <+ white_noise(rbps_psd, "rbps");
    I(b_int, db_int) <+ white_noise(rbpd_psd, "rbpd");
    I(b_int, b) <+ white_noise(rbpb_psd, "rbpb");
    I(d_int, s_int) <+ white_noise(id_psd, "id");
    I(g_int, s_int) <+ white_noise(igs_psd, "igs");
    I(g_int, d_int) <+ white_noise(igd_psd, "igd");
    I(d_int, s_int) <+ flicker_noise(flicker_psd, flicker_exp, "flicker");
    // Correlated D-S, G-S noise subcircuit
    I(noise_br_r) <+ V(noise_int);
    I(noise_br_c) <+ ddt(tn2sigrat*V(noise_int));
    if (BSIM4tnoiMod==2) begin
        I(noise_br_i) <+ white_noise(1, "corl");
        if (BSIM4mode>=0) begin
            I(d_int, s_int) <+   sqrt(tn2dspsd) * I(noise_br_i);
            I(g_int, s_int) <+ - sqrt(tn2gspsd) * I(noise_br_c);
        end else begin
            I(s_int, d_int) <+   sqrt(tn2dspsd) * I(noise_br_i);
            I(g_int, d_int) <+ - sqrt(tn2gspsd) * I(noise_br_c);
        end
    end

    // Instance output variable computation
    gmbs = BSIM4gmbs;
    gmbs = gmbs * (mult_i);
    gm = BSIM4gm;
    gm = gm * (mult_i);
    gds = BSIM4gds;
    gds = gds * (mult_i);
    vdsat = BSIM4vdsat;
    vth = BSIM4von;
    id = BSIM4cd;
    id = id * (mult_i);
    ibd = BSIM4cbd;
    ibd = ibd * (mult_i);
    ibs = BSIM4cbs;
    ibs = ibs * (mult_i);
    gbd = BSIM4gbd;
    gbd = gbd * (mult_i);
    gbs = BSIM4gbs;
    gbs = gbs * (mult_i);
    isub = BSIM4csub;
    isub = isub * (mult_i);
    igidl = BSIM4Igidl;
    igidl = igidl * (mult_i);
    igisl = BSIM4Igisl;
    igisl = igisl * (mult_i);
    igs = BSIM4Igs;
    igs = igs * (mult_i);
    igd = BSIM4Igd;
    igd = igd * (mult_i);
    igb = BSIM4Igb;
    igb = igb * (mult_i);
    igcs = BSIM4Igcs;
    igcs = igcs * (mult_i);
    igcd = BSIM4Igcd;
    igcd = igcd * (mult_i);
    vbs = BSIM4vbs;
    vgs = BSIM4vgs;
    vds = BSIM4vds;
    cgg = BSIM4cggb;
    cgg = cgg * (mult_q);
    cgs = BSIM4cgsb;
    cgs = cgs * (mult_q);
    cgd = BSIM4cgdb;
    cgd = cgd * (mult_q);
    cbg = BSIM4cbgb;
    cbg = cbg * (mult_q);
    cbd = BSIM4cbdb;
    cbd = cbd * (mult_q);
    cbs = BSIM4cbsb;
    cbs = cbs * (mult_q);
    cdg = BSIM4cdgb;
    cdg = cdg * (mult_q);
    cdd = BSIM4cddb;
    cdd = cdd * (mult_q);
    cds = BSIM4cdsb;
    cds = cds * (mult_q);
    csg = BSIM4csgb;
    csg = csg * (mult_q);
    csd = BSIM4csdb;
    csd = csd * (mult_q);
    css = BSIM4cssb;
    css = css * (mult_q);
    cgb = BSIM4cgbb;
    cgb = cgb * (mult_q);
    cdb = BSIM4cdbb;
    cdb = cdb * (mult_q);
    csb = BSIM4csbb;
    csb = csb * (mult_q);
    cbb = BSIM4cbbb;
    cbb = cbb * (mult_q);
    capbd = BSIM4capbd;
    capbd = capbd * (mult_q);
    capbs = BSIM4capbs;
    capbs = capbs * (mult_q);
    qg = BSIM4qgate;
    qg = qg * (mult_q);
    qb = BSIM4qbulk;
    qb = qb * (mult_q);
    qd = BSIM4qdrn;
    qd = qd * (mult_q);
    qs = BSIM4qsrc;
    qs = qs * (mult_q);
    qinv = BSIM4qinv;
    qdef = BSIM4qdef;
    gcrg = BSIM4gcrg;
    gcrg = gcrg * (mult_i);
    gtau = BSIM4gtau;
    vgsteff = BSIM4Vgsteff;
    vdseff = BSIM4Vdseff;
    c_gso = i_BSIM4cgso;
    c_gso = c_gso * (mult_q);
    c_gdo = i_BSIM4cgdo;
    c_gdo = c_gdo * (mult_q);
    c_gbo = sd_BSIM4cgbo;
    c_gbo = c_gbo * (mult_q);
    weff = BSIM4weff;
    leff = BSIM4leff;

    // Model output variable computation

  end
endmodule
