Extract # Coefs from FitFunc

I'm writing a procedure to generalize the way I use DoNewGlobalFit.

I would like to utilize something like the //CurveFitDialog/ Coefficients 3 line from standard global FitFunc usage so that I can modify the size of the CoefDataSetLinkage matrix for whatever number of coefficients are present.

How can I extract a variable returning the number of coefficients in a fitfunction without doing it manually?
how about something like this (which I haven't tested but I use something similar) :

function Return_Coefs(Fitname)
string Fitname 

        //Try Dialog method
    string str=ProcedureText(Fitname,-1)
    variable SPos, EPos

    //Beginning of line
        SPos=strsearch(str,"//CurveFitDialog/ Coefficients" ,0,2)+30
    EPos=strsearch(str,"\r" ,SPos+1,2)-1
    str=str[SPos,EPos]

    variable Num=str2num(str)
    if(numtype(Num) == 0 && Num!= 0)
             return Num
       else
             return -1
    endif

return -1
end
I often do like this. You can get coefficients number and names at the same time.
function fitfun(coef,x):fitfunc
    wave coef
    //Coef description
    //Coef[0]: CoefInfo0
    //Coef[1]: CoefInfo1
    //Coef[2]: CoefInfo2
    variable x 
    return 0
end

function/S getfitfuncoef(fitname)
    string fitname
    string s1=proceduretext(fitname,0)
    string s2=greplist(s1,"//Coef\\[\\d+\\]:",0,"\r")
    variable i,n
    string s3,s4,s5
    s5="";
    n=itemsinlist(s2,"\r")
    for(i=0;i<n;i+=1)
        s3=stringfromlist(i,s2,"\r")
        splitstring/E="//Coef\\[\\d+\\]:\\s([a-zA-Z\\d]+)" s3,s4
        s5=s5+s4+";"
    endfor
    return s5  
end


<pre><code class="language-igor">
Hi,
I felt this question is relevant to this discussion, hence I am asking.

How do I get fit Coefficients if I am using curve fit in a loop?

Thanks in advance
May I cite from displayhelptopic "CurveFit": Parameters
kwCWave=coefWaveName specifies an optional coefficient wave. If present, the specified coefficient wave is set to the final coefficients determined by the curve fit. If absent, a wave named W_coef is created and is set to the final coefficients determined by the curve fit.

In every single call in the loop. You will need to store them after the fit in 'user' waves.
HJ