Can we dynamically change the name of the raw file...
# xschem
m
Can we dynamically change the name of the raw file we are writing to, if we are running multiple simulations in a loop and we want each simulation result to be stored in a seperate raw file.
s
Yes you can use a loop variable and append the number to the raw file:
let n=1
tran 50n 1m
write result{$&n}.raw
--> binary raw file "result1.raw"
👍 1
c
• may I ask if there is a variable like $s in xschem exist in ngspice, so that when I "write $s.raw", the filename can automatically match the schematic filename? It sounds like to be a feature for ngspice, but not for xschem, correct me if I was wrong. [$s - schematic name (example: tgate)]
👍 1
s
@Calvin Yan the 's' variable (base name of schematic name) (together with other variables, (S: full schematic path name, N: full path of netlist file, d: simulation directory and so on) are specific to the context of the simulation configuration dialog box. They are defined there so you can build commands using short variables instead of actual names and paths or long 'xschem' tcl command queries. These variables are not defined at global scope, since I don't like leaving predefined variables in the global space. If someone writes a script using these short variables there will be all sort of problems. you can get the name of the current schematic with
xschem get current_name
so if you do this in a code block:
Copy code
value="tcleval(
...
...
.control
  save all
  tran 10n 10u
  remzerovec
  write [file rootname [xschem get current_name]].raw
.endc
)"
You will be writing the raw file to
circuit.raw
if
circuit
is the name of current schematic. The tcleval( .... ) wrapper passes the inner string to TCL for substitution, so the commands inside brackets ([ ... ]) are evaluated and result is substituted. Since ngspice has problems getting environment variables xschem does all the substitutions and presents to ngspice a netlist with no variables left to be expanded. I would be glad to avoid this if ngspice one day gets the ability to expand env vars, like $PDK_ROOT and $PDK and so on.
👍 1