EVA Script With Comments | EVA Script

EVA, Extreme Value Analysis Simulation Template With Comments:

*Instruct the netlist builder to show tolerances
#tolerance

*Suppress automatic vector saves
#nosave

*Suppress IsSpice4 printout
#noprint

*Save vectors needed for measurements
#vector

Set the  noecho environment for print formatting
set rewind
set noecho

*Run the specified simulation and save the results
#simulation
pltype = 0 ;Identify the plot type for later use
set printmode = save
#mprint

*Set the print format
SET COLWIDTH=22
SET SPICEDIGITS=5
nameplot ref
newplot evahi ref.default ref.default
evahi.pltype = 0 ;Identify the plot type for later use
*Print status for the user 
printstatus -t "######## sensitivity for each parameter ########"
*Loop through the parameters
nextparam null
while param <> null
    *Alter each parameter
    alterparam tolerance(param)/3
    *Simulate, making a new plot for results
    #simulation
    *Save the current parameter reference
    paramvec = param
    *Tell the user where we are
    printstatus -p paramvec
   *Save the tol and paramval
    paramtol = tolerance(param)
    paramval = getparam(param)
    pltype = 1 ;Identify the plot type for later use
        *Save the simulation results
    #mprint
    *Loop through all the vectors
    nv = nextvector(null)
    while nv <> null
        *Save the sensitivities for all scalar measurements except pltype
         if length(nv) = 1
              if nv <> pltype 
                  nv = nv - ref.nv
              end ;end if
         end ;end if
         nv = nextvector(nv)
    end ;end vector loop
        *Restore the param
    unalterparam
        *Get the next param
    nextparam
end;end parameter loop
*Make ref the current plot
setplot ref
*Loop through the vectors in ref
nv = nextvector(null)
*Tell the user where we are
printstatus -t "######## measurements ########"
while nv <> null
    if length(nv) = 1
        *Loop through all the plots containing scalar vectors 
        pl = nextplot(null)
        while pl <> null
            if pltype = 1
* the inner loop, we are looping through each sensitivity plot looking at the same vector
* we will alter the parameter id'd by paramvec to maximize/minimize the vector
               setparam paramvec 
               *Change each parameter to its worst case extreme value
               if nv >= 0
                   alterparam paramtol
               else
                   alterparam -paramtol
               end
            end
            pl = nextplot(pl)
         end
         *Simulate for the extreme case and save the data in a new plot
         #simulation
         #mprint
         pltype = 2 ;Identify the plot type for later use
* if we want sensitivity at the extreme, we weed to go through each param
* and change it to be a bit different than it is at the extreme, run a simulation ,
* and mark it as pltype 3 along with its paramvec, then we can take the diff
* from the pltype = 2 to get the sensitivity at the extreme if the sign at the extreme
* is different than at the nominal, we can report an error or go on to do worst case
* for worst case, we need to reduce the param change by 1/2 and do this over again...
* either continue in this loop or make a wc loop afterward... save the paramvalue
* and tolerance
         evahi.nv = nv
         if nv <> pltype
            *Tell the user where we are
             printstatus -n nv
         end ;endif
     end ;end plot loop
          ;get the next vector
     nv = nextvector(nv)
end ;end vector loop
*Set print mode and print header
set printmode = print
unset noecho
setplot EVAHI
ECHO
ECHO -U "**********EVA PARAMETER LIST**********"
ECHO
PRINTTEXT -UN PARAMETER 
PRINTTEXT -U NOMINAL TOLERANCE
ECHO
ECHO
*Loop through the parameters
nextparam null
while param <> null
        *Extract the saved param reference and print its data
    paramvec = param
    PRINTNAME PARAMVEC
    PRINTVAL  PARAMVEC
    PRINTTOL  PARAMVEC
    ECHO
    *get the next param
    nextparam
end ;end param loop
ECHO ;print a blank line
*Make a new plot to hold sorted results
newplot evasort ref.default ref.default
*Make ref the current plot
setplot REF
*Loop through all vectors in ref
nv = nextvector(null)
while nv <> null
    if length(nv) = 1
        *save the result in evasort as a percent of its value
        if ref.nv <> 0
            evasort.nv = ((evahi.nv-ref.nv)*100)/ref.nv
        else
            evasort.nv = 0;
        end ;end if
    end ;end if
    *Get the next vector
    nv = nextvector(nv)
end ;end vector loop
*Print some headers
ECHO
ECHO -U "**********EVA-HI RESULTS**********"
ECHO
PRINTTEXT -UN VECTOR 
PRINTTEXT -U NOMINAL EVA-HI CHANGE%
ECHO
ECHO
setplot evasort
*Sort evasort by descanting data
sort -VD
*Loop through the vectors
nv = nextvector(null)
while nv <> null
        *If its the correct data in the correct plot, print it
    if length(nv) = 1
        if nv <> pltype
           PRINTNAME NV
           PRINTVAL  REF.NV
           PRINTVAL  EVAHI.NV
           PRINTVAL  EVASORT.NV
           ECHO
        end ; end if
    end ; end if
        *Get the next vector
    nv = nextvector(nv)
end ; end vector loop
ECHO
ECHO

* now the eva results are in pltype = 2 plots
*Print the results so SpiceNet can read the eva-hi data
set printmode = print
unset noecho
setplot evahi
echo ########## EVA HI analysis Results #############
#mprint

EVA, Extreme Value Analysis Simulation Template:

#tolerance
#nosave
#noprint
#vector
set rewind
set noecho
#simulation
pltype = 0
set printmode = save
#mprint
SET COLWIDTH=22
SET SPICEDIGITS=5
nameplot ref
newplot evahi ref.default ref.default
evahi.pltype = 0
printstatus -t "######## sensitivity for each parameter ########"
nextparam null
while param <> null
    alterparam tolerance(param)/3
    #simulation
    paramvec = param
    printstatus -p paramvec
    paramtol = tolerance(param)
    paramval = getparam(param)
    pltype = 1
    #mprint
    nv = nextvector(null)
    while nv <> null
         if length(nv) = 1
              if nv <> pltype
                  nv = nv - ref.nv
              end
         end
         nv = nextvector(nv)
    end
    unalterparam
    nextparam
end
setplot ref
nv = nextvector(null)
printstatus -t "######## measurements ########"
while nv <> null
    if length(nv) = 1
        pl = nextplot(null)
        while pl <> null
            if pltype = 1
* the inner loop, we are looping through each sensitivity plot looking at the same vector
* we will alter the parameter id'd by paramvec to maximaize/minimize the vector
               setparam paramvec   
               if nv >= 0
                   alterparam paramtol
               else
                   alterparam -paramtol
               end
            end
            pl = nextplot(pl)
         end
         #simulation
         #mprint
         pltype = 2
* if we want sensitivity at the extreme, we weed to go through each param
* and change it to be a bit different than it is at the extreme, run a simulation ,
* and mark it as pltype 3 along with its paramvec, then we can take the diff
* from the pltype = 2 to get the sensitivity at the extreme if the sign at the extreme
* is different than at the nominal, we can report an error or go on to do worst case
* for worstcase, we need to reduce the param change by 1/2 and do this over again...
* either continue in this loop or make a wc loop afterward... save the paramvalue
* and tolerance
         evahi.nv = nv
         if nv <> pltype
             printstatus -n nv
         end
     end
     nv = nextvector(nv)
end
set printmode = print
unset noecho
setplot EVAHI
ECHO
ECHO -U "**********EVA PARAMETER LIST**********"
ECHO
PRINTTEXT -UN PARAMETER 
PRINTTEXT -U NOMINAL TOLERANCE
ECHO
ECHO
nextparam null
while param <> null
    paramvec = param
    PRINTNAME PARAMVEC
    PRINTVAL  PARAMVEC
    PRINTTOL  PARAMVEC
    ECHO
    nextparam
end
ECHO
newplot evasort ref.default ref.default
setplot REF
nv = nextvector(null)
while nv <> null
    if length(nv) = 1
        if ref.nv <> 0
            evasort.nv = ((evahi.nv-ref.nv)*100)/ref.nv
        else
            evasort.nv = 0;
        end
    end
    nv = nextvector(nv)
end

ECHO
ECHO -U "**********EVA-HI RESULTS**********"
ECHO
PRINTTEXT -UN VECTOR 
PRINTTEXT -U NOMINAL EVA-HI CHANGE%
ECHO
ECHO
setplot evasort
sort -VD
nv = nextvector(null)
while nv <> null
    if length(nv) = 1
        if nv <> pltype
           PRINTNAME NV
           PRINTVAL  REF.NV
           PRINTVAL  EVAHI.NV
           PRINTVAL  EVASORT.NV
           ECHO
        end
    end
    nv = nextvector(nv)
end
ECHO
ECHO

* now the eva resultas are in pltype = 2 plots
set printmode = print
unset noecho
setplot evahi
echo ########## EVA HI analysis Results #############
#mprint