WCS Script | WCS Script With Comments

WCS, Worst Case by Sensitivity Simulation Template:

#tolerance
#nosave
#noprint
#vector
set rewind
set noecho
#simulation
set printmode = save
#mprint
SET COLWIDTH=22
SET SPICEDIGITS=5
nameplot ref
newplot result ref.default ref.default
setplot ref
printstatus -t "######## sensitivity for each parameter ########"
nextparam null
while param <> null
    alterparam tolerance(param)/3
	#simulation
	paramvec = param
	printstatus -p paramvec
    #mprint
    nv = nextvector(null)
    while nv <> null
    	if length(nv) = 1
        	nv = nv - ref.nv
        	result.nv = result.nv + abs(3*nv)
        end
	nv = nextvector(nv)
    end
    unalterparam
    nextparam
end
set printmode = print
unset noecho
setplot result
ECHO
ECHO -U "**********WCS 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 wcsort ref.default ref.default
setplot REF
nv = nextvector(null)
while nv <> null
    if length(nv) = 1
        if ref.nv <> 0
            wcsort.nv = ((result.nv-ref.nv)*100)/ref.nv
        else
            wcsort.nv = 0;
    	end
    end
	nv = nextvector(nv)
end

ECHO
ECHO -U "**********WCS-HI RESULTS**********"
ECHO
PRINTTEXT -UN VECTOR 
PRINTTEXT -U NOMINAL WCS-HI CHANGE%
ECHO
ECHO
setplot wcsort
sort -VD
nv = nextvector(null)
while nv <> null
    if length(nv) = 1
        PRINTNAME NV
        PRINTVAL  REF.NV
        PRINTVAL  RESULT.NV
        PRINTVAL  WCSORT.NV
    	ECHO
    end
	nv = nextvector(nv)
end
ECHO
ECHO
setplot result
echo ########## WCS HI analysis Results #############
#mprint
rusage elapsed

WCS, Worst Case by Sensitivity 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 output file pointer to the beginning to remove
* the input net list
set rewind

*Set the  noecho environment for print formatting
set noecho

*Run the specified simulation and save the results
#simulation
set printmode = save
#mprint

*Set the print format
SET COLWIDTH=22
SET SPICEDIGITS=5

*Rename the simulation plot
nameplot ref

*Make a newplot for results
newplot result ref.default ref.default

*Set the current plot to ref
setplot ref

*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
    *Inform the user about what's being done
	    printstatus -p paramvec
    *Make and save the measurements
    #mprint
    *Loop through the vectors
    nv = nextvector(null)
    	while nv <> null
        *Save the sensitivity of scalar quantities
    	if length(nv) = 1
        	nv = nv - ref.nv
        	*Save the worst case -hi value
        	result.nv = result.nv + abs(3*nv)
        end ;end if
        nv = nextvector(nv)
    end ;end vector loop
    *restore the parameter value
    unalterparam
    *get the next parameter
    nextparam
end ;end parameter loop

*Set the print mode to print instead of save
set printmode = print
*Restore the echo mode for printing
unset noecho
*Set result to the current plot
setplot result
*Print the header
ECHO
ECHO -U "**********WCS PARAMETER LIST**********"
ECHO
PRINTTEXT -UN PARAMETER 
PRINTTEXT -U NOMINAL TOLERANCE
ECHO
ECHO
*Loop through the parameters
nextparam null
while param <> null
	paramvec = param
  	*Print the row
  	PRINTNAME PARAMVEC
  	PRINTVAL  PARAMVEC
  	PRINTTOL  PARAMVEC
    ECHO
    nextparam
end
ECHO
*Make a new plot to hold sorted results
newplot wcsort ref.default ref.default
*Set the current plot to ref
setplot REF
*Loop through its vectors
nv = nextvector(null)
while nv <> null
    *Calculate the wc as a percent change results
    if length(nv) = 1
        if ref.nv <> 0
            wcsort.nv = ((result.nv-ref.nv)*100)/ref.nv
        else
            wcsort.nv = 0;
    	end ;end if
    end ;end if
	nv = nextvector(nv)
end ;end vector loop

*Print headers
ECHO
ECHO -U "**********WCS-HI RESULTS**********"
ECHO
PRINTTEXT -UN VECTOR 
PRINTTEXT -U NOMINAL WCS-HI CHANGE%
ECHO
ECHO
;sort wcsort by descending value
setplot wcsort
sort -VD
*Print the ordered list
nv = nextvector(null)
while nv <> null
    if length(nv) = 1
        PRINTNAME NV
        PRINTVAL  REF.NV
        PRINTVAL  RESULT.NV
        PRINTVAL  WCSORT.NV
    	ECHO
    end
	nv = nextvector(nv)
end
ECHO
ECHO
*Set the current plot to the wc results
setplot result
echo ########## WCS HI analysis Results #############
*Print the measured results in a form that can be read back
*into SpiceNet
#mprint
*Report the elapsed time in the output file
rusage elapsed