Author |
Topic  |
|
aeolian1
Germany
Posts |
Posted - 11/05/2013 : 06:49:34 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): 9.0.0, SR 2 Operating System: Windows
Hello,
I have written a script that contains a loop which produces plots with fit curves. Each pass of the loop plots certain rows of a particular worksheet and fits them with a function using nonlinear fitting. Since the script generates around 50 plots, I would like to have the script paste the parameters to each plot.
I have written two versions of this code; one uses the old nlsf commands and the other nlbegin/nlfit/end. They produce exactly the same results. The problem is that I can't get either version to paste the parameters to the plots.
I am using a user-defined function; its fdf file contains the line Paste Parameters to Plot After Fitting = 1 , so that is presumably not the problem.
With nlbegin/nlfit/nlend, using "nlend;" does not paste the parameters to the plot. Using "nlend 1;" gives me the dialog box that asks me whether I want to see the Report Sheet or not. If I click "No", the parameters are not pasted to the plot. Clicking "Yes" causes a disaster for my code (and does not results in the parameters being pasted to the plot).
With the nlsf commands, I have tried 1. nlsf.pasteToPlot = 1; 2. nlsf.pasteToPlot = 2; 3. NLSF.PasteParams("P");
but none of these work. Could you please provide a tip for how to do this with either nlsf or the X-function commands? (I would prefer to get this to work with nlsf commands, since the Report Sheet seems more problematic.) Thank you.
|
|
greg
USA
1379 Posts |
Posted - 11/05/2013 : 09:31:40 AM
|
nlsf.pasteparams(P) should do it, provided a graph window is active and the command executes after fitting. Note that P is not quoted.
|
 |
|
aeolian1
Germany
Posts |
Posted - 11/05/2013 : 10:04:49 AM
|
Many thanks for your fast reply, Greg!! That did the trick. I am thrilled.
There's only one small problem: I actually do TWO fits per plot, and would like to see both parameter sets. When I do "nlsf.pasteparams(P);" for the second time in a given plot window, the second set of parameters replaces the first. How can I copy the first object and move it seomwhere else on the plot (like one usually does manually, when not using a script) before pasting the second set of parameters to the plot?
And now I'll go for broke: ideally, I'd like to control 1) the exact position of the boxes that contain the parameters and 2) their font size. (The default font size is so big, and the default positioning such, that a good portion of my plots is obscured.)
Thank you again! |
 |
|
aeolian1
Germany
Posts |
Posted - 11/05/2013 : 10:41:55 AM
|
P.S. With regard to one of the three followup questions listed above, namely that of how to reposition the parameters table generated via nlsf.pasteparams(P): I found the code fragment
page.active=1; doc -e G { string str1=%B; if( str1.GetLength()>=5 ) { string str2 = str1.Left(5)$; if( str2.Compare("Table")==0 ) { GObject tab=%B; tab.x = layer.x.to - tab.dx/2; } } }
at http://www.originlab.com/forum/topic.asp?TOPIC_ID=10755 . I don't understand this code at all, and it also doesn't seem to work for me: it doesn't move the table, and it also puts an unwanted box around a text label that I have placed on the plot (even if I generate the text label *after* running the above code). |
 |
|
aeolian1
Germany
Posts |
Posted - 11/05/2013 : 11:15:26 AM
|
P.P.S. Aha! I found a really helpful chunk of code at http://www.originlab.de/www/support/resultstech.aspx?ID=511&language=English&Version=All . I've incorporated this twice per loop (naming the window "FITP2" in the second instance of the code chunk, rather than "FITP"), and it does exactly what I want: I get two parameter windows at the desired positions with the desired font size.
Only one tiny detail remains: the portion of the code that looks like
loop(ii,1,nlsf.npara) { // Loop on all parameters %N=nlsf.n$(II)$; // Get iith parameter name %P=$(nlsf.p$(II)); // Get iith parameter value %Q=$(nlsf.e$(II)); // Get iith parameter error %Z=%Z\r\n%N %P \(177)%Q; // Add iith line to %Z string };
causes an enormous number of decimal places to appear. What is the default numerical precision for Fit.P, and what should I change in the above code chunk to achieve it? Thank you very much. |
 |
|
greg
USA
1379 Posts |
Posted - 11/05/2013 : 11:23:20 AM
|
The old NLSF fitter unfortunately had that behavior. Worse is the fact that the parameter object was named "FIT.P". That dot in the name is problematic when it comes to any kind of automation because you cannot address the object, such as FIT.P.X = X1;
You can rename graphic objects using Origin C so you will have to add that functionality. Here is a simple graphic object renamer written to work with the active graph window:
void RenameGraphObject(string strOriginal, string strNew) { GraphLayer gl = Project.ActiveLayer(); if( gl.IsValid() ) { GraphObject go = gl.GraphObjects(strOriginal); if(go.IsValid()) BOOL bRet = go.SetName(strNew); } } Build in Code Builder before continuing...
After doing the pasteparams, you can execute:
RenameGraphObject("FIT.P", "FIT1");
to give it a useable name. (FIT2 for the next...)
Now you can set the font size (do this BEFORE positioning!):
fit1.fsize = 8;
and position it using .x, .y for position of the center of the object and .dx, .dy to use the full width and height of the object in your positioning expression:
fit1.x = x2 + fit1.dx / 2; fit1.y = y2 - fit1.dy / 2;
The above code puts the object flush with the top of the y axis and flush-right of the end of the x axis. |
 |
|
aeolian1
Germany
Posts |
Posted - 11/05/2013 : 11:35:09 AM
|
OK, I've got it now. Using %P=$(nlsf.p$(II),*5); (instead of %P=$(nlsf.p$(II)); ) gives 5 digits of precision. |
 |
|
aeolian1
Germany
Posts |
Posted - 11/05/2013 : 11:38:58 AM
|
Thank you for your reply, Greg! I didn't see it before posting just now at 11:35:09. I actually prefer the code chunk mentioned at 11:15:26 (plus the reduced precision) because I don't have to compile anything in Origin C... I'll see if the results are OK... |
 |
|
aeolian1
Germany
Posts |
Posted - 11/15/2013 : 05:25:56 AM
|
P.S. (To Greg?)
Now everything works fine in the version that uses nlsf-commands, which is great. One thing: it would be very helpful to achieve parameter-pasting with the X-function version as well.
To recap: with nlbegin/nlfit/nlend commands in my script, using "nlend;" does not paste the parameters to the plot. Using "nlend 1;" gives me the dialog box that asks me whether I want to see the Report Sheet or not. If I click "No", the parameters are not pasted to the plot. Clicking "Yes" causes a complete disaster for my code in subsequent passes through the loop (and does not result in any parameters being pasted to any plots!). I would not like to have to click "No, and don't bother me with this again", since I would like to leave this option open for the future (in manual fits).
I would ideally like to have things in the X-function code version work just like in the nlsf version. That is, the "reminder message" dialog box that asks "Do you want to switch to the Report Sheet?" would never appear, and the parameters would simply be pasted to the plot.
(With regard to obtaining two different "boxes" of pasted parameters per plot: in contrast to what is the case for a) earlier versions of Origin or b) a script utilizing the nlsf commands, the second set of parameters seems in version 9.0.0 not to "erase" the first pasted set, at least when I try this manually. It doesn't bother me much to have to drag the second box of parameters to the side in order to see the first, so I don't really need to come up with a snippet of code to perform this shift, should this be tricky.)
Thank you very much! |
 |
|
aeolian1
Germany
Posts |
Posted - 11/15/2013 : 12:21:26 PM
|
P.P.S. I now see that I could in fact use "Help:Reactivate Reminder Messages" to bring back the reminder message if I were to select the option "No, and don't bother me with this again."
However, it seems that I almost certainly need to deactivate this reminder message somehow *before* running my script, as it turns out that choosing "No, and don't bother me with this again" after the first pass through the loop is not at all helpful. The effects are similar to those from choosing "Yes", namely
1) the parameters aren't pasted to the first plot 2) the rest of the loop behaves in a completely bizarre and disastrous fashion.
So, perhaps my questions boil down to 1) How can I prevent the reminder message from ever appearing? 2) How can I force "paste parameters to plot" to occur? |
 |
|
greg
USA
1379 Posts |
Posted - 11/18/2013 : 3:20:30 PM
|
The X-Functions bypass the dialog and have no way of pasting parameters to the plot. This might have been possible for a Theme, but it seems nlbegin has not been designed to load all features of a theme into the tree used during the fit.
You will need to use add_table_to_graph in a script to create your own table on the plot.
You can use the type command to temporarily shut off reminder messages. You can even specify how your script should respond to messages even though they do not appear.
This script starts with your graph and does NOT switch to the Report sheet: nlbegin %C func:=gauss; nlfit 100; type -me; // End reminder messages type -mb 0; // Respond NO to any reminder that might have occurred nlend 1 AU_AUTO; type -mb; // Resume reminder messages
This script starts with your worksheet and DOES switch to the Report sheet: nlbegin (1,2) func:=gauss; nlfit 100; type -me; // End reminder messages type -mb 1; // Respond YES to any reminder that might have occurred nlend 1 AU_AUTO; type -mb; // Resume reminder messages
|
Edited by - greg on 11/18/2013 3:22:12 PM |
 |
|
aeolian1
Germany
Posts |
Posted - 11/19/2013 : 10:08:12 AM
|
Dear Greg,
Thank you very much for your answer! The first script fragment, combined with a parameter table of my own construction, solves the problem: the code seems to function fine. |
 |
|
|
Topic  |
|
|
|