Menu

Is it possible to reset

simpletk
2022-06-08
2022-06-08
  • simpletk

    simpletk - 2022-06-08

    I'm running fourier 123 v(out) in a loop and calculating THD from fourier11 vector. But because I do it in the loop, the second call will store the output in fourier21, third call in fourier31 and so on. I don't know how to change the code to read from different variable each time the loop runs. The variable that is increasing in the name of the vector is "static int callstof = 1;" in fourier.c:

    int
    fourier(wordlist *wl, struct plot *current_plot)
    {
    ...
    static int callstof = 1;
    ...
    /* create and assign a new vector n */
    /* with size 3 * nfreqs in current plot */
    /* generate name for new vector, using vec->name */
    n = dvec_alloc(tprintf("fourier%d%d", callstof, newveccount),
        SV_NOTYPE,
        VF_REAL | VF_PERMANENT,
        3 * nfreqs, NULL);
    ...
    callstof++;
    

    Is it possible to reset this variable or to somehow get to the generated vector or something like that:

    let i = 0
    dowhile i < 10
      let i = i + 1
      fourier 123 v(out)
      let f = getVariableFromName("fourier"+i+"1")
    

    Or maybe some special option not to increment callstof

    if (!some_special_option) {
      callstof++;
    }
    

    I only need fouriermn to calculate thd and put it in a variable, if there is a way to get thd from last fourier call that would help too, something like

    fourier 123 v(out)
    let thd = fourier_last_thd
    
     
  • Holger Vogt

    Holger Vogt - 2022-06-08

    Try using 'destroy fourier11' at the end of the loop. The new 'fourier' command from the loop then will create a new fourier11.

     
  • simpletk

    simpletk - 2022-06-08

    It doesn't work like that, even if I destroy fourier11 the fourier21 will be used:

    * first line
    V1 1 0 DC 0 AC 100m 0 SIN(0 100m 196 0 0 0)
    R1 1 0 50k
    .options NOACCT NOPAGE
    .control
    tran 40u 580m 0
    fourier 196 v(1)
    print fourier11[1][0]
    print fourier11[1][1]
    print fourier11[1][2]
    destroy fourier11
    tran 40u 580m 0
    fourier 222 v(1)
    print fourier21[1][0]
    print fourier21[1][1]
    print fourier21[1][2]
    .endc
    .end
    
     
  • Holger Vogt

    Holger Vogt - 2022-06-08
    * use vector or variable substitution
    V1 1 0 DC 0 AC 100m 0 SIN(0 100m 196 0 0 0)
    R1 1 0 50k
    .options NOACCT NOPAGE
    .control
    let i = 1
    tran 40u 580m 0
    fourier 196 v(1)
    print fourier{$&i}1[1][0]
    print fourier{$&i}1[1][1]
    print fourier{$&i}1[1][2]
    let i = i + 1
    tran 40u 580m 0
    fourier 222 v(1)
    print fourier{$&i}1[1][0]
    print fourier{$&i}1[1][1]
    print fourier{$&i}1[1][2]
    .endc
    .end
    
     
  • simpletk

    simpletk - 2022-06-08

    ok it works

     
  • simpletk

    simpletk - 2022-06-08

    ok it works

     

Log in to post a comment.