Author |
Topic  |
|
G.Bartsch
Germany
Posts |
Posted - 06/22/2005 : 10:14:23 AM
|
while running a self made multiple lorentz fit originc program, in the code builder the error messages
C:\Program Files\OriginLab\OriginPro7\OriginC\NLSF\_nlpLorentz.fit(43) :Error, Variable "w" not declared C:\Program Files\OriginLab\OriginPro7\OriginC\NLSF\_nlpLorentz.fit(43) :Error, general compile error C:\Program Files\OriginLab\OriginPro7\OriginC\NLSF\_nlpLorentz.fit(29) :Error, error(s) found in compiling function _nlsfPara
appear. Nevertheless the fitting seems to work fine. I wonder why there is any parameter "w" because as im fitting two peaks there are only "w1" and "w2". Could these errors be a reason for the poor performance of this originc code? It isnt faster than the old labtalk code i used before. I would appreciate any hints according to this problem.
Originc code: //Lorentz function definition float Lorentzz(float a,float xc,float w,float y0,float x) { float y=y0+(2.*a*w)/(3.1415*(4.*(x-xc)*(x-xc)+w*w)); return y; }
void fitallc() { using nlsf = LabTalk.NLSF; double xc1, xc2, a1, a2, w1, w2, y0, xmin, xmax, imax, tra, trw, trz, trc, polydeg, pts; string A,PeakData; LT_get_var("xc1", &xc1); LT_get_var("xc2", &xc2); LT_get_var("a1", &a1); LT_get_var("a2", &a2); LT_get_var("w1", &w1); LT_get_var("w2", &w2); LT_get_var("y0", &y0); LT_get_var("xmin", &xmin); LT_get_var("xmax", &xmax); LT_get_var("imax", &imax); LT_get_var("tra", &tra); LT_get_var("trw", &trw); LT_get_var("trz", &trz); LT_get_var("trc", &trc); LT_get_var("polydeg", &polydeg); LT_get_var("pts", &pts);
LT_get_str("%A", A, 100); LT_get_str("PeakData", PeakData, 100);
nlsf.p2=xc1; nlsf.p3=w1; nlsf.p4=a1; nlsf.p7=a2; nlsf.p5=xc2; nlsf.p6=w2; nlsf.p1=y0;
string wholedata=A; Worksheet whole=wholedata; Worksheet peakdata="PeakData"; int cols=whole.GetNumCols(); //Plotothers int ii;
for (ii = 2; ii <= cols;ii++) { string data = wholedata + "_" + ii;
Curve cc(data); GraphLayer lay("Spectra"); int nIndex = lay.AddPlot(cc, IDM_PLOT_LINE);
LT_execute("doc -uw; clr;"); };
//fit all
int err; ii=0; progressBox prog("Fit Status Origin.C"); prog.SetRange(0,(cols-1)); for(ii = 2; ii < (cols); ii++) {
float xc1old=xc1; float xc2old=xc2; float a1old=a1; float a2old=a2; float w1old=w1; float w2old=w2; float y0old=y0; nlsf.msgPrompt=0; nlsf.cleanupfitdata(); nlsf.func$ = "lorentz"; nlsf.xbegin = xmin; nlsf.xend = xmax; nlsf.numReplica=1; string data = wholedata + "_" + ii; nlsf.fitdata$ = data; nlsf.iterate(imax); data = wholedata + "_0"; nlsf.funcx$ = data; xc1=nlsf.p2; w1=nlsf.p3; a1=nlsf.p4; a2=nlsf.p7; xc2=nlsf.p5; w2=nlsf.p6; y0=nlsf.p1; if (abs(xc1-xc1old)>=((trc/100)*abs(xc1old))) { xc1=xc1old; peakdata.SetCell((ii-1),5,1); err=1; }; if (abs(xc2-xc2old)>=((trc/100)*abs(xc2old))) { xc2=xc2old; peakdata.SetCell((ii-1),5,1); err=1; }; if (abs(a1-a1old)>=((tra/100)*abs(a1old))) { a1=a1old; peakdata.SetCell((ii-1),5,1); err=1; }; if (abs(a2-a2old)>=((tra/100)*abs(a2old))) { a2=a2old; peakdata.SetCell((ii-1),5,1); err=1; }; if (abs(w1-w1old)>=((trw/100)*abs(w1old))) { w1=w1old; peakdata.SetCell((ii-1),5,1); err=1; }; if (abs(w2-w2old)>=((trw/100)*abs(w2old))) { w2=w2old; peakdata.SetCell((ii-1),5,1); err=1; }; if (abs(y0-y0old)>=((trz/100)*abs(y0old))) { y0=y0old; peakdata.SetCell((ii-1),5,1); err=1; }; if (xc1<xc2) { xmin = xmin+(xc1-xc1old); xmax = xmax+(xc2-xc2old); }; if (xc1>=xc2) { xmin = xmin+(xc2-xc2old); xmax = xmax+(xc1-xc1old); }; peakdata.SetCell((ii-1),1, xc1); peakdata.SetCell((ii-1),3, xc2); peakdata.SetCell((ii-1),2,(Lorentzz(a1, xc1, w1, y0, xc1)+Lorentzz(a2, xc2, w2, y0, xc1))); peakdata.SetCell((ii-1),4,(Lorentzz(a1, xc1, w1, y0, xc2)+Lorentzz(a2, xc2, w2, y0, xc2))); out_str(" xmin " + xmin + " xc1 " + xc1 + " xc2 " + xc2 + " xmax " + xmax + " a1 " + a1 + " a2 " + a2 + " w1 " + w1 + " w2 " + w2 + " y0 " + y0); prog.Set(ii); };
return; }
|
|
easwar
USA
1965 Posts |
Posted - 06/22/2005 : 10:45:41 AM
|
Hi,
The reason you are getting this error message during run time is because the parameter initialization code is run automatically when the function and data to fit are assigned in the nlsf object. The current parameter initialization code does not deal with replicas. You are using replicas and you are assinging the parameter values yourselves to w1, w2 etc, but the initialization code is assuming there are no replicas and so it looks for w instead of w1 and w2 and so the message is generated.
As long as the fit results look consistent/correct (which you should probably verify by manually fitting some datasets) you could just ignore this error.
If the error is annoying, one thing you can do is to open the NLSF tool, select the function, go to the Scripts->Parameter Initialization page and then uncheck the check box named "Enable automatic parameter initialization". Then the para init code will not be run and the error message will not be generated. Then of course if this box is turned off, next time you fit manually with the NLSF tool you will have to go to this page and click the Execute button to run the initialization code yourself for the current data.
Now regarding speed, what you are doing here is to use the NLSF object and then use a built-in function. So as far as fitting is concerned, the speed of fitting will not be any different from before. However all the looping over datasets and manipulating columns etc which you are now doing with Origin C should be faster compared to working with LabTalk.
Also, it is a good idea to close the Code Builder window when running your Origin C function. This turns off/dsiables debugging and the Origin C code will run faster. One could also just turn off the "Enable break points" option under the Debug menu in Code Builder instead if you want to have the same effect but keep Code Builder open.
Easwar OriginLab
P.S. Not sure if currently there is a way to keep the "Enable automatic parameter initialization" checkbox checked and still suppress this message using some NLSF object property - we will look into that.
|
 |
|
G.Bartsch
Germany
Posts |
Posted - 06/22/2005 : 11:03:07 AM
|
Thank you very much for the fast feedback. Though unexpected the program runs faster now without automatic parm initialization. The breaks between each fit seem to be shorter. Would be very nice to find out how to disable automatic parm init from originc or labtalk.
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 06/22/2005 : 11:04:52 AM
|
quote: If the error is annoying, one thing you can do is to open the NLSF tool, select the function, go to the Scripts->Parameter Initialization page and then uncheck the check box named "Enable automatic parameter initialization". Then the para init code will not be run and the error message will not be generated. Then of course if this box is turned off, next time you fit manually with the NLSF tool you will have to go to this page and click the Execute button to run the initialization code yourself for the current data.
Disable auto initialization and then save the function under a new name, say LorentzForReplicas. Use LorentzForReplicas to fit multiple peaks and Lorentz for single peaks. (Then you don't need to remember to turn the auto initialization option on and off.)
...That seems to replace the Lorentz function with the new function on the NLSF function lists. Add the old Lorentz function again with Function > Add on the NLSF menu bar. Then you'll have both.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 06/22/2005 11:46:55 AM |
 |
|
G.Bartsch
Germany
Posts |
Posted - 06/22/2005 : 11:59:44 AM
|
Thank you, Mike Buess. The self defined function trick worked well. |
 |
|
|
Topic  |
|
|
|