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

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

return -1
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

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
        splitstring/E="//Coef\\[\\d+\\]:\\s([a-zA-Z\\d]+)" s3,s4
    return s5  

<pre><code class="language-igor">
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.