The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 reading and writing in multiple worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

JulesOZ

18 Posts

Posted - 03/13/2013 :  7:18:19 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Pro8 SR1
Operating System: Win7

I'd like to run Gauss fits automated on data stored in the same workbook but in multiple worksheets. I do know how to address and work with the data that is in the first worksheet, but I can't figure out what the syntax is to use the data in the other worksheets.
Here is my program that works well if there is only one sheet in a workbook:
doc -ef W
{
int numWKB = page.nLayers;
string Bname$ = page.name$;
type %(Bname$) has $(numWKB) Worksheets;
doc -e LW
{
string Sname$ = wks.name$;
type "Layer $(page.active) named %(Sname$)";


nlsf.func$ = gauss;
nlsf.numReplica = 1;
nlsf.cleanupfitdata();
string colA$ = Bname$+"_A";
string colB$ = Bname$+"_B";
string colFit$ = Bname$+"_Fit";

type "Name von colA ist %(colA$)";
type "Name von colB ist %(colB$)";
type "Name von colFit ist %(colFit$)";


nlsf.fitdata$ = colB$;
y0=500;
xc1=42;
w1=0.6;
A1=3000;
xc2=49;
w2=0.5;
A2=3100;

nlsf.iterate(500);
nlsf.xmode = 2;

nlsf.funcx$ = colA$;

nlsf.funccol$ = colFit$; //dataset to store fitted Y values
nlsf.makecurve(func); //dataset generated for the fitted curve


}
}

I use the strings colA$, colB$ and colFit$ to tell the various nlsf-Fitfunctions where the data is stored and where the fitted data should be written to. But the way it is now the strings contain just information about the workbook and the columns and not about the worksheets. I even have the sheet names already stored in the string Sname$, but I don't know how to glue this information between the workbook and column information.
Is there an easy way to do this?

Thanks,
Jules

Edited by - JulesOZ on 03/13/2013 7:19:57 PM

greg

USA
1378 Posts

Posted - 03/14/2013 :  11:26:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
For additional sheets in a workbook, the programmatic column name appends an '@' symbol plus the sheet index. So your column Bs would look like:
Book1_B
Book1_B@2
Book1_B@3
etc.

This suggests this fix:
Change
string colA$ = Bname$+"_A";
string colB$ = Bname$+"_B";
string colFit$ = Bname$+"_Fit";

to
@global = 1;
if(wks.index < 2)
{
string colA$ = Bname$+"_A";
string colB$ = Bname$+"_B";
string colFit$ = Bname$+"_Fit";
}
else
{
string sIndex$ = $(wks.index);
string colA$ = Bname$+"_A@"+sIndex$;
string colB$ = Bname$+"_B@"+sIndex$;
string colFit$ = Bname$+"_Fit@"+sIndex$;
}
@global = 0;


I could equally write this
string colA$;
string colB$;
string colFit$;
if(wks.index < 2)
{
colA$ = Bname$+"_A";
colB$ = Bname$+"_B";
colFit$ = Bname$+"_Fit";
}
else
{
string sIndex$ = $(wks.index);
colA$ = Bname$+"_A@"+sIndex$;
colB$ = Bname$+"_B@"+sIndex$;
colFit$ = Bname$+"_Fit@"+sIndex$;
}


In the first case, the strings were declared in a loop and would go out of scope at the exit of the loop without the added @global = 1.
In the second case, I declared the strings outside the loop.

Moving forward you should stop using the programmatic short names in favor of the new range notation:
http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Range_Notation

You should also patch your Origin 8 up to SR6 and take a look at the new nlbegin, nlfit and nlend functions for fitting:
http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Curve_Fitting#Fit_Multiple_Peaks_with_Replica
Go to Top of Page

JulesOZ

18 Posts

Posted - 03/18/2013 :  02:33:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks greg - this was really helpful!
I managed to get the "looping through all worksheets" going, so that I get Gauss Fits for data in all worksheets in the active folder. Even if one workbook contains more than one worksheet.
Here is the code in case anybody wants to use it:


doc -ef W {

int numWKB = page.nLayers;
int i=1;
string Bname$ = page.name$;
type %(Bname$) has $(numWKB) Worksheets;

type "Window: %H, layer number: $(page.active)";

string colA$;
string colB$;
string colFit$;

for(i=1; i<=numWKB; i++)
{
if(i < 2)
{
colA$ = Bname$+"_A";
colB$ = Bname$+"_B";
colFit$ = Bname$+"_Fit";
}

else
{
string sIndex$ = $(i);
colA$ = Bname$+"_A@"+sIndex$;
colB$ = Bname$+"_B@"+sIndex$;
colFit$ = Bname$+"_Fit@"+sIndex$;
}

type "Name von colA ist %(colA$)";
type "Name von colB ist %(colB$)";
type "Name von colFit ist %(colFit$)";


nlsf.func$ = gauss;
nlsf.numReplica = 1;
nlsf.cleanupfitdata();

nlsf.fitdata$ = colB$;
y0=500;
xc1=42;
w1=0.6;
A1=3000;
xc2=49;
w2=0.5;
A2=3100;

nlsf.iterate(500);
nlsf.xmode = 2;

nlsf.funcx$ = colA$;

nlsf.funccol$ = colFit$; //dataset to store fitted Y values
nlsf.makecurve(func); //dataset generated for the fitted curve


}
}

However, so far this code generates one graph for each workbook each and plots the original and fitted data in it. If one workbook contains more than one worksheet it still will be plotted in one graph.
Can you tell me, which function is responsible for these graphs and can I tell it to make one graph for each worksheet and not only workbook?

Thanks,
Jules
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000