I'm still working for a solution for .csv ngspice ...
# analog-design
l
I'm still working for a solution for .csv ngspice output. The wrdata function outputs text files with column formatted data, but it has an extra space for positive values, for better displaying it. However, this is horrible for csv reading tools. See this spice test example
Copy code
* resistor tb

r0 a 0 1k
va a 0 0

.control

    dc va -1 1 0.2
    wrdata res.txt v(a) i(va)
    shell sed 's/^/ /; s/  /,/g; s/ /,/g; s/^,//g' res.txt > res.csv
    
.endc

.end
This outputs this text file, res.txt
Copy code
-1.00000000e+00 -1.00000000e+00 -1.00000000e+00  1.00000000e-03 
-8.00000000e-01 -8.00000000e-01 -8.00000000e-01  8.00000000e-04 
-6.00000000e-01 -6.00000000e-01 -6.00000000e-01  6.00000000e-04 
-4.00000000e-01 -4.00000000e-01 -4.00000000e-01  4.00000000e-04 
-2.00000000e-01 -2.00000000e-01 -2.00000000e-01  2.00000000e-04 
-5.55111512e-17 -5.55111512e-17 -5.55111512e-17  5.55111512e-20 
 2.00000000e-01  2.00000000e-01  2.00000000e-01 -2.00000000e-04 
 4.00000000e-01  4.00000000e-01  4.00000000e-01 -4.00000000e-04 
 6.00000000e-01  6.00000000e-01  6.00000000e-01 -6.00000000e-04 
 8.00000000e-01  8.00000000e-01  8.00000000e-01 -8.00000000e-04 
 1.00000000e+00  1.00000000e+00  1.00000000e+00 -1.00000000e-03
It well aligned, but I really wanted this:
Copy code
-1.00000000e+00,-1.00000000e+00,-1.00000000e+00,1.00000000e-03,
-8.00000000e-01,-8.00000000e-01,-8.00000000e-01,8.00000000e-04,
-6.00000000e-01,-6.00000000e-01,-6.00000000e-01,6.00000000e-04,
-4.00000000e-01,-4.00000000e-01,-4.00000000e-01,4.00000000e-04,
-2.00000000e-01,-2.00000000e-01,-2.00000000e-01,2.00000000e-04,
-5.55111512e-17,-5.55111512e-17,-5.55111512e-17,5.55111512e-20,
2.00000000e-01,2.00000000e-01,2.00000000e-01,-2.00000000e-04,
4.00000000e-01,4.00000000e-01,4.00000000e-01,-4.00000000e-04,
6.00000000e-01,6.00000000e-01,6.00000000e-01,-6.00000000e-04,
8.00000000e-01,8.00000000e-01,8.00000000e-01,-8.00000000e-04,
1.00000000e+00,1.00000000e+00,1.00000000e+00,-1.00000000e-03,
This can be done by using the bash shell command
shell sed 's/^/ /; s/  /,/g; s/ /,/g; s/^,//g' res.txt > res.csv
. I've tried to do that using the ngspice shell command but it gives me an error: `sed: -e expression #1, char 4: unterminated
s' command
. Can someone explain me this? @Jorge Marin
c
If you want to use python, you can skip the sed part and then simply read the output using pandas with the delim_whitespace option.
Copy code
import pandas as pd
df = pd.read_csv("res.txt", delim_whitespace=True)
l
Thanks! I'll try that later. I'm using pgfplots within my latex files. Maybe I should just plot it with matplotlib with python instead.
y
Or just read the raw using https://github.com/gmagno/spyci and forget about the ngspice control statements
👍 3
c
Also perhaps you want to use: "set wr_vecnames" in ngspice, if you want a header with the column names. That makes it a bit easier to access the data using pandas.
👍 1