Menu

sharedspice.h - can't read both .ac and .tran data, only one at a time

simpletk
2023-03-07
2023-03-08
  • simpletk

    simpletk - 2023-03-07

    I have following circuit:

    char *netlist[] = {
        "* voltage divider",
        "V1 1 0 9",
        "R1 1 2 1k",
        "R2 2 0 1k",
        ".control",
        "ac dec 10 16 20k",
        "tran 300u 20m 0",
        ".endc",
        ".end"
      }
    

    I'm using ngSpice_AllPlots(), then ngSpice_AllVecs("ac1") then ngGet_Vec_Info(..) then finally reading v_realdata or v_compdata. If I only use "ac" only or "tran" only, it works. But when I want both, the older one gets somehow rewriten and data is no longer available.

    Attached is minimal demo. When you only use one characteristic (either ac or tran) it works, but when you use both the older one (ac) will have undefined "frequency". If you switch the order:

        "tran 300u 20m 0",
          "ac dec 10 16 20k",
    

    then "tran1" will have undefined "time". Is it possible to read both at the same time?

    If not how to read both "ac" and "tran"? Should I just run netlist with "ac", get data and then replace the entire netlist and run it with only "tran" and get data?

     
  • Holger Vogt

    Holger Vogt - 2023-03-07

    The ac command creates plot ac1, the tran command creates plot tran1.

    So what about
    ngSpice_AllPlots(), then ngSpice_AllVecs("ac1") then ngGet_Vec_Info(..)
    read the ac data, then switch to the other plot by
    ngSpice_AllPlots(), then ngSpice_AllVecs("tran1") then ngGet_Vec_Info(..)
    read the tran data

     
  • simpletk

    simpletk - 2023-03-07

    That's exactly what I'm doing in demo and it doesn't work.

     
  • Holger Vogt

    Holger Vogt - 2023-03-07

    What happens if you send 'run' instead of 'bg_run', no need for usleep then, so to keep everything in the main thread?

     
  • simpletk

    simpletk - 2023-03-08

    It doesn't help.

     
  • Holger Vogt

    Holger Vogt - 2023-03-08

    To analyze what you have you might send the following commands and watch the response:

    setplot ac1
    display
    setplot tran1
    display
    
     
  • simpletk

    simpletk - 2023-03-08

    Ok, this helped. So before calling ngSpice_AllVecs("ac1") I need to call:

    ngSpice_Command("setplot ac1");

    Thanks.

     

    Last edit: simpletk 2023-03-08

Log in to post a comment.