RSS Script | RSS Script With Comments

RSS, root summed square analysis Simulation Template:

#tolerance
#nosave
#noprint
#vector
set rewind
set noecho
#simulation
set printmode = save
#mprint
SET COLWIDTH=22
SET SPICEDIGITS=5
nameplot ref
nextparam null
printstatus -t "######## sensitivity for each parameter ########"
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
        end
        nv = nextvector(nv)
    end
    unalterparam
    nextparam
end
set printmode = print
unset noecho
newplot rss ref.default ref.default
setplot rss
nv = nextvector(null)
while nv <> null
    IF LENGTH(NV) = 1
        nv = 0
    END
    nv = nextvector(nv)
end
pl = nextplot(null)
printstatus -t "######## computing rss for each measurement ########"
while pl <> null
    if sameplot(rss.default) = 0
  	if sameplot(ref.default) = 0
  		printstatus -l pl
  		SETPARAM PARAMVEC
  		nv = nextvector(null)
  		ECHO
  		ECHO -U "**********RSS DATA**********"
  		ECHO
  		ECHO -UN " PARAMETER NAME: "
  		PRINTNAME PARAMVEC
  		ECHO
  		ECHO -UN "  NOMINAL VALUE: "
  		PRINTVAL  PARAMVEC
  		ECHO
  		ECHO -UN "TOLERANCE VALUE: "
  		PRINTTOL  PARAMVEC
  		ECHO
  		ECHO
  		PRINTTEXT -UN VECTOR 
  		PRINTTEXT -U SENSITIVITY% RSS_CONTRIBUTION
  		ECHO
  		ECHO
  		while nv <> null
  		    if length(nv) = 1
  		        IF REF.NV <> 0
  		            PRINTNAME NV
  		            NEWNV = (300*NV)/REF.NV
  		            PRINTVAL NEWNV
  		        ELSE
  		            PRINTNAME NV
  		            NEWNV = 3*NV
  		            PRINTVAL NEWNV
  		            ECHO -N *
  		        END
  		        rss.nv = rss.nv + nv * nv
  		        PRINTVAL RSS.NV
  		        ECHO
  		    end
  		    nv = nextvector(nv)
  		end
  		sort -vd
		end
	end
	pl = nextplot(pl)
end
setplot rss
SORT -VD
ECHO
ECHO -U "**********RSS HI/LO ANALYSIS RESULTS**********"
ECHO
PRINTTEXT -UN VECTOR 
SET COLWIDTH=15
PRINTTEXT -U NOMINAL RSS-VALUE TOLERANCE% HI_VALUE LO_VALUE
ECHO
ECHO
newplot hirss ref.default ref.default
nv = nextvector(null)
while nv <> null
	if length(nv) = 1
		SET COLWIDTH=22
   		PRINTNAME NV
		SET COLWIDTH=15
		PRINTVAL REF.NV
  		NV = 3 * SQRT(ABS(NV))
		PRINTVAL NV
   		IF REF.NV <> 0
			NEWNV1 = (100*NV)/REF.NV
		ELSE
			NEWNV1 = NV*0
		END
		PRINTVAL NEWNV1
	    NV = REF.NV + NV
		HI_RSS = REF.NV + NV
		LO_RSS = REF.NV - NV
		PRINTVAL HI_RSS
		PRINTVAL LO_RSS 
		ECHO
	end
	nv = nextvector(nv)
end
ECHO
ECHO
setplot hirss
echo ########## RSS HI analysis Results #############
#mprint
RUSAGE ELAPSED

RSS, root summed square 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 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

*Loop through all of the parameters
nextparam null
*Tell the user where we are
printstatus -t "######## sensitivity for each parameter ########"
while param <> null
    *Alter each parameter
    alterparam tolerance(param)/3
    *Simulate
    #simulation
       *Save the parameter reference in the new plot
    paramvec = param
    *Tell the user where we are
    printstatus -p paramvec
    *Save the data
    #mprint
    *Loop through the vectors
    nv = nextvector(null)
    while nv <> null
        *Save the sensitivities of scalar data
    	if length(nv) = 1
        	nv = nv - ref.nv
        end ;  end if
        *Get the next vector
        nv = nextvector(nv)
    end ; end vector loop
        *Restore the parameter
    unalterparam
        *Get the next parameter
    nextparam
end ; end parameter loop
*Set print mode for printing output data
set printmode = print
unset noecho
*Make a new plot for rss data and make it the current plot
newplot rss ref.default ref.default
setplot rss
*Loop through the vectors
nv = nextvector(null)
while nv <> null
        *Initialize the scalar data to zero
    IF LENGTH(NV) = 1
        nv = 0
    END ;  end if
         * Get the next vector
    nv = nextvector(nv)
end ;  end vector loop
*Loop through the plots
pl = nextplot(null)
*Tell the user where we are
printstatus -t "######## computing rss for each measurement ########"
while pl <> null
    *Select plots
    if sameplot(rss.default) = 0
  	if sameplot(ref.default) = 0
  		*Tell the user what we are doing
  		printstatus -l pl
  		*Make the saved parameter reference, paramvec current
  		SETPARAM PARAMVEC
  		*Get the next vector
  		nv = nextvector(null)
  		*Print formatted data
  		ECHO
  		ECHO -U "**********RSS DATA**********"
  		ECHO
  		ECHO -UN " PARAMETER NAME: "
  		PRINTNAME PARAMVEC
  		ECHO
  		ECHO -UN "  NOMINAL VALUE: "
  		PRINTVAL  PARAMVEC
  		ECHO
  		ECHO -UN "TOLERANCE VALUE: "
  		PRINTTOL  PARAMVEC
  		ECHO
  		ECHO
  		PRINTTEXT -UN VECTOR 
  		PRINTTEXT -U SENSITIVITY% RSS_CONTRIBUTION
  		ECHO
  		ECHO
  		*Loop through vectors
  		while nv <> null
  		    if length(nv) = 1
  		        IF REF.NV <> 0
  		            *Calculate the RSS percentage if value is not zero
  		            PRINTNAME NV
  		            NEWNV = (300*NV)/REF.NV
  		            PRINTVAL NEWNV
  		        ELSE
  		            *Calculate the RSS  if value is not zero
  		            PRINTNAME NV
  		            NEWNV = 3*NV
  		            PRINTVAL NEWNV
  		            ECHO -N *
  		        END ;end if
  		        *Save and print each RSS contribution  		        
                cont = newnv*ref.nv/100
                printval cont
                rss.nv = rss.nv + cont * cont
  		        ECHO
  		    end ;end if
  		    * Get next vector
  		    nv = nextvector(nv)
  		end ;end vector loop
  		* Sort plot by descending value
  		sort -vd
  	end ;end if
    end ;end if
    * Get next plot
    pl = nextplot(pl)
end ;end plot loop
*Sort the rss plot by descending value    
setplot rss
SORT -VD
*Print Headers
ECHO
ECHO -U "**********RSS HI/LO ANALYSIS RESULTS**********"
ECHO
PRINTTEXT -UN VECTOR 
SET COLWIDTH=15
PRINTTEXT -U NOMINAL RSS-VALUE TOLERANCE% HI_VALUE LO_VALUE
ECHO
ECHO
*Make a new plot for results
newplot hirss ref.default ref.default
*Loop through the vectors
nv = nextvector(null)
while nv <> null
	if length(nv) = 1
		*Print formatted data
		SET COLWIDTH=22
   		PRINTNAME NV
		SET COLWIDTH=15
		PRINTVAL REF.NV
  		NV = SQRT(ABS(NV))
		PRINTVAL NV
   		IF REF.NV <> 0
			NEWNV = (100*NV)/REF.NV
		ELSE
			NEWNV = NV*0
		END
		PRINTVAL NEWNV
		HI_RSS = REF.NV + NV
		LO_RSS = REF.NV - NV
		PRINTVAL HI_RSS
		PRINTVAL LO_RSS
	    NV = REF.NV + NV 
		ECHO
	end ; end if
	*Get next vector
	nv = nextvector(nv)
end; end vector loop
ECHO
ECHO
*Print data in output file for SpiceNet to read
setplot rss
echo ########## RSS HI analysis Results #############
#mprint
RUSAGE ELAPSED