** Script to run multiple simulations using component values ** read from a file ** First ask the user for a file Let filename = GetSIMetrixFile('Text', ['open', 'all']) if Length(filename)=0 then ** User cancelled box exit script endif ** Read the file Let lines = ReadFile(filename) Let numLines = Length(lines) ** Test it has enough lines if numLines<2 then Echo "Definition file must have at least two lines" exit script endif ** We now parse the file and read in the component values ** to the array "compValues". We do the whole file at the ** beginning so that the user will know straight away if it ** has any errors. ** The first line is the list of components that will be changed Let components=Parse(lines[0]) Let numComponents = Length(components) if numComponents=0 then Echo "No component names specified or first line of config file empty" exit script endif ** Before we read the rest of the file, we will attempt to ** replace the values of all listed components with parameters ** and netlist the circuit. If any of the components dont exist ** then we will find out here. ** array to store original values so that we can restore them later Let origValues = MakeString(numComponents) Unselect Let error = 0 ** Scan through list of components for idx = 0 to numComponents-1 ** Select it Select /prop ref {components[idx]} if SelectCount()=0 then ** Select count is zero so select failed. ** This means the circuit doesn't have this component ** Output a message and set error flag. Echo "Cannot find component " {components[idx]} Let error = 1 else if HasProperty('value') then ** Save original value to be rsetored later Let origValues[idx] = PropValue('value') ** Set value as a parameter of name which is the same as the ref Let newVal = "'{' & PropValue('ref') & '}'" Prop value {newVal} else ** The component does not have a value property to alter. Echo "Component " {components[idx]} " does not have a value" Let error = 1 endif endif Unselect next idx ** We have changed all the components so now we can netlist the circuit if NOT error then Netlist design.net endif ** Once we have the netlist we can restore the original values Unselect for idx = 0 to numComponents-1 Select /prop ref {components[idx]} if SelectCount()<>0 then if HasProperty('value') then Prop value {origValues[idx]} endif endif Unselect next idx ** If we had an error we must now abort if error then exit script endif ** Now read the rest of the file. ** Create an array large enough to hold all the values. ** The values are actually stored as strings. That way we can vary ** model names as well as values. Let compValues = MakeString(numComponents*(numLines-1)) Let error = 0 Let resIdx=0 for lineIdx=1 to numLines-1 ** Parse the line into individual values Let vals = Parse(lines[lineidx]) if Length(vals)<>numComponents then ** A line found with the wrong number of values. This is assumed ** to be a mistake unless the line is completely empty if Length(vals)<>0 then Echo "Wrong number of values at line " {lineIdx} Let error = 1 endif else ** line is OK so write the values to compValues for idx=0 to numComponents-1 Let compValues[resIdx*numComponents+idx] = vals[idx] next idx ** Because some lines may be empty we have to use ** a different index counter for the compValues entries Let resIdx = resIdx+1 endif next idx if error then exit script endif ** resIdx finishes with the number of non-blank data lines Let numRuns = resIdx ** Now, at last, we can run the circuit for idx=0 to numRuns-1 for compIdx=0 to numComponents-1 Let paramName = 'global:' & components[compIdx] Let {paramName} = compValues[idx*numComponents+compIdx] next compIdx Run /file design.net next idx ** This isn't essential, but it is always best to delete ** global variables when we are finished with them for compIdx=0 to numComponents-1 Let paramName = 'global:' & components[compIdx] UnLet {paramName} next compIdx