| 
     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
     
 |