Menu

#490 Plot issue with shared library

v1.0 (example)
closed-wont-fix
None
5
2020-10-11
2020-05-04
No

For this particular desk

.title Pulse
Bsource in 0 v=time^4*exp(-1000*time)
R1 in out 9kOhm
R2 out 0 1kOhm
.options TEMP = 27°C
.options TNOM = 27°C
.ic 
.tran 0.001ms 20ms 0s
.end

that plot No. of Data Rows : 20008 in ngspice cli

PySpice https://github.com/FabriceSalvaire/PySpice is know to retrieve correctly plots but for this desk the plot is wrong see https://github.com/FabriceSalvaire/PySpice/issues/172

I checked for data truncation issue since the plot looks like the beginnning of the expected one.
I dumped the C array from ngspice api to check for PySpice issue.

It looks like there an issue with the API.

Discussion

  • Holger Vogt

    Holger Vogt - 2020-05-04

    This is unfortunately not enough information to check for any bug.

    What part of the ngspice api are you using to transfer the data to the host program?

     
  • Holger Vogt

    Holger Vogt - 2020-05-05

    shared ngspice simulates correctly. I have succsessfully tranferd the netlist to ngspice.dll (ngspice-32, Windows 10) and retrieved the data back to the caller. Adding a gnuplot command shows the correct output.

    What the OP has shown in his 'wrong' plot is not the beginning of the plot, but is the result of a truncated input line
    Bsource in 0 v=time^4 ; *exp(-1000*time)
    Please check if pyspice is sending the complete input line to ngspice. You may check the ngspice input parser by sending a command 'listing' and reading the response. If the line
    set ngdebug
    is put into .spiceinit, then a debug output debug-out.txt is generated to show the input file after parsing in ngepice.

     
  • Fabrice Salvaire

    I supect '*' ...

    debug-out.txt is

    **************** uncommented deck **************
    
         1       1  Pulse
         0       2  .global gnd
         2       4  bsource in 0 v= time ^   4,0000000000e+00 * exp (  -1,0000000000e+03 * time )
         3       5  r1 in out 9kohm
         4       6  r2 out 0 1kohm
         5       7  .options temp=27°c
         6       8  .options tnom=27°c
         7       9  .ic
         8      10  .tran 0.001ms 20ms 0s
        10      12  .end
    
    ****************** complete deck ***************
    
         1       1  Pulse
         0       2  .global gnd
         2       3  *source in 0 v=time^4*exp(-1000*time)
         2       4  bsource in 0 v= time ^   4,0000000000e+00 * exp (  -1,0000000000e+03 * time )
         3       5  r1 in out 9kohm
         4       6  r2 out 0 1kohm
         5       7  .options temp=27°c
         6       8  .options tnom=27°c
         7       9  .ic
         8      10  .tran 0.001ms 20ms 0s
         9      11  *end
        10      12  .end
    
     
  • Fabrice Salvaire

    listing is

    Pulse
    1 : pulse
    2 : .global gnd
    4 : bsource in 0 v= time ^   4,0000000000e+00 * exp (  -1,0000000000e+03 * time )
    5 : r1 in out 9kohm
    6 : r2 out 0 1kohm
    9 : .ic
    10 : .tran 0.001ms 20ms 0s
    7 : .options temp=27__c
    8 : .options tnom=27__c
    12 : .end
    
     
    • Holger Vogt

      Holger Vogt - 2020-05-05

      Just one glimpse, and it is obvious:

      ngspice expects something like
      -1.0000000000e+03
      and it gets
      -1,0000000000e+03
      The difference is the dot versus the comma.

      ngspice does not set locale itself, it expects settings as are obtained by using
      setlocale(LC_NUMERIC, "C");

      standard ngspice executable does this setting automatically (as all C coded executable without explicit locale settings), shared ngspice does not.

       
      • Fabrice Salvaire

        oh, but why we didn't encounter this issue before ? PySpice send the string time^4*exp(-1000*time) thus something strange happen in ngspice

         
  • Fabrice Salvaire

    I got the same result for bsource in 0 v= time ^ 4,0000000000e+00 ** ** exp ( -1,0000000000e+03 * time ) very suspicious

     
  • Holger Vogt

    Holger Vogt - 2020-05-05

    As a shared library ngspice adopts the locale setting of the calling program. This may have changed, or is even user depending. So it might be advisable to set the locale LC_NUMERIC to "C" directly before calling ngspice. This is what KiCAD is doing right now. One could of course think about other solutions, but this is by no means a short term activity.

     
  • Holger Vogt

    Holger Vogt - 2020-10-11
    • status: open --> closed-wont-fix
    • assigned_to: Holger Vogt
     

Log in to post a comment.

MongoDB Logo MongoDB