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
 Origin 9.0 // Fit information collect and write
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

LaurP

Estonia
16 Posts

Posted - 11/13/2012 :  07:24:49 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

I am new to this LabTalk thing and I have tried to write a script that looks over all the project and writes then necessary fit information (peak position, area, standard error) to a new book. I have very many fits there and it would be not vice to use copy paste for every position and area.

doc -ef W {

doc -e LW {

// Loops over the columns to find the right place where data is.

loop (j, 11, 30) {

// Loops over rows to find empty slot where to write data.

loop(i,1,5)(

// Fitting results position depend on how many baseline anchor points there are. The first anchor point is always at same place. So we look with loop which column the anchor point value ends and turns to zero. All data in our experiment is higher then 3000.

If( [%H]%(wks.Name$)!cell(1,j) > 3000 ) { };

else {
if ( [Book87]Sheet1!Cell(i,3)==empty ) { [Book87]Sheet1!Cell(i,3)=[%H]%(wks.Name$)!cell(i,j) ;}
else { };
};


// End of two loops!
;);
;);


// Ending of doc-s!
};
};

Is this script too long or is there any problem with the loops inside loops and if inside if?

It gives me User Abort error...

Every idea would be helpful..

LaurP

Estonia
16 Posts

Posted - 11/13/2012 :  08:30:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is the script that this discussion is speaking of!

It looks the fits data from all over the project and puts it all to one workbook named ScriptFitData. Have fun digesting it ;) !

// If you use this form then you have to look that anchor point wavelenght value is above 3000 (cm^-1)!!! Also make scriptfitdata active workbook with atleast 7 columns! Otherwise it will not work!
// How to use scripts? Open script window from menu (WINDOW - SCRIPT WINDOW) and copy paste script there, then highlight the part you want to run and hit enter.


//Script starting! Highlight the script to run it from here!
//------------------------------------------------------------------------------------------------------------------------------------------------------------

//Declaring that data write place is a range.;

range raSFD = [ScriptFitData]Sheet1!;

// Defining a value for iRow and then increasing it when script changes the workbook by iRow++;

iRow = 1;

// Looks all the W workbooks in -ef current active folder or -e currently active project.

doc -e W {

// If the active workbook is scriptfitdata, then ......

if("%H"!="ScriptFitData")
{

// Looks -e all subpages of workbooks.

doc -e LW {

// Loops over the columns to find the right place where data is.

loop (j, 12, 35){

// Finding out which sheets we want to use.
range rWb = !;
NumColumns = rWb.ncols;

// If there are lesser then 12 columns we are not interested in the worksheet!;

If ( NumColumns<j ) { };
else { If ( [%H]%(wks.Name$)!cell(1,j) > 3000 && [%H]%(wks.Name$)!cell(1,j-1) > 3000 ) { };
else { If ( [%H]%(wks.Name$)!cell(2,j) > 3000 ) {

// Finds if there are more then 1 fit in that workbook.
Loop (k,0,10){

// Breakes the k loop if the cell we were interested is empty! When breaked it does not move to i loop.
If ( [%H]%(wks.Name$)!cell(2+k*4,j)==empty ){ break; };


// Loops over rows to find empty slot where to write data.
loop (i,1,300){


// As the script has to put right data to right output row. We are looking the empty cell from wavelength column.
if ( [ScriptFitData]Sheet1!Cell(i,1)==empty ){

// Wavelength!;
[ScriptFitData]Sheet1!Cell(i,1)=[%H]%(wks.Name$)!cell(2+k*4,j);
// Wavelength Standard Error. It is situated 2 columns further then wavelength so j+2 column.
[ScriptFitData]Sheet1!Cell(i,2)=[%H]%(wks.Name$)!cell(2+k*4,j+2);
//Area!
[ScriptFitData]Sheet1!Cell(i,3)=[%H]%(wks.Name$)!cell(3+k*4,j);
//Area Standard Error!
[ScriptFitData]Sheet1!Cell(i,4)=[%H]%(wks.Name$)!cell(3+k*4,j+2);
//Width!;
[ScriptFitData]Sheet1!Cell(i,5)=[%H]%(wks.Name$)!cell(4+k*4,j);
//Width Standard Error!;
[ScriptFitData]Sheet1!Cell(i,6)=[%H]%(wks.Name$)!cell(4+k*4,j+2);
// Book name / Sheet name
string strBookName$ = page.longname$;
if(strBookName.GetLength() == 0) strBookName$ = page.name$;
string strSheetName$ = layer.name$;
raSFD!cell(iRow,7)$=[%(strBookName$)]%(strSheetName$);
iRow++;
Break;

};
else { };

// The last if sentence has to have BREAK inside (last argument)!
// i loop end!;
};
//k loop end!
};
//3rd if end.
};
else { };

//2nd else end.
};
//If else end.
};

// j loop end.
If ( [%H]%(wks.Name$)!cell(1,j) > 3000 ){ };
else { break; };
};

// Ending of doc-s! And the "%H"!="ScriptFitData" statement!
};
};
};
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Notes
// There is no difference if you use Cell or cell.
// There is limidation to script sizes. Look: "Extending a Statement over Multiple Lines";
// It is smart to put space after every function and between different cells.
// Break has to be after anything you want to do also in same cell!;
// There has to be space after else or any funcktion! Also remember to use ; .;

Edited by - LaurP on 11/22/2012 09:14:17 AM
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 11/16/2012 :  06:37:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I want to write active sheet long name to a exact cell.

To go over all the sheets and workbook

doc -e W {

doc -e LW {

loop (i,1,300){

// Where to write data
if ( [ScriptFitData]Sheet1!Cell(i,7)==empty ){
[ScriptFitData]Sheet1!Cell(i,7)$= %(page.longname$) ; };
else { }:

};
// Ending of doc-s!
};
};


The sentence in this structure remembers the first %(page.longname$) and doesn't overwrite the name when doc activates other. It returns the same value 300 times.

I have other things in this kind of structure, because of that I would like something that will work in this structure.

1) How can I write the activated workbook name?

2) How can I write same way the folder name, which is activated, to a cell?

Edited by - LaurP on 11/16/2012 06:38:53 AM
Go to Top of Page

greg

USA
1378 Posts

Posted - 11/16/2012 :  12:57:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The Workbook Name(s) can be gotten from the PAGE object. Since a Workbook does not have to have a Long Name, you might want to do something like this:

doc -e W
{
// Get the current Workbook name
string strBookName$ = page.longname$;
if(strBookName.GetLength() == 0) strBookName$ = page.name$;
ty strBookName$;
}

The Worksheet name can be gotten from the LAYER object, as in:
doc -e LW
{
// Get the current sheet name
string strSheetName$ = layer.name$;
ty strSheetName$;
}
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 11/20/2012 :  07:49:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Greg it doesn't work. But I really thank you for your notes.

I need to write things to CELL. Writing things to CELL is different then writing things to script window. Make a example how can I write all these values to cell that it types to script window.(That would really help me out.)

Right now the simplified script. It looks which cell is empty and then should write the workbook name to that empty cell. If it founds the right i it breaks the loop and looks other workbooks.


doc -e W {
doc -e LW {
loop (i,1,300){
if ( [ScriptFitData]Sheet1!Cell(i,7)==empty ){
string strBookName$ = page.longname$;
if(strBookName.GetLength() == 0) strBookName$ = page.name$;
[ScriptFitData]Sheet1!Cell(i,7)$=%(strBookName$);
Type " %(strBookName$)"; break;
};
else { };
};
};
};


I can see that the values %(strBookName$) are changing as it goes over the project but it only writes the last value of %(strBookName$) to the first cell of [ScriptFitData]Sheet1!Cell(i,7). It doesn't want to change the i inside. I think it is because of $ behind the destination.

--------------------------------------

I have also tried this way:



doc -e W {
doc -e LW {
loop (ii,1,300){
if ( [ScriptFitData]Sheet1!Cell(ii,7)==empty ) {
string strBookName$ = page.longname$;
if(strBookName.GetLength() == 0) strBookName$ = page.name$;
%A = %(strBookName$);
[ScriptFitData]Sheet1!Cell(ii,7) = %[%A, #1,\t];
Break;

};
else { };
};
};
};

This tells that all the workbook long names are undefined variables.


Also how can I get folder name where the workbook is?


quote:
Originally posted by greg

The Workbook Name(s) can be gotten from the PAGE object. Since a Workbook does not have to have a Long Name, you might want to do something like this:

doc -e W
{
// Get the current Workbook name
string strBookName$ = page.longname$;
if(strBookName.GetLength() == 0) strBookName$ = page.name$;
ty strBookName$;
}

The Worksheet name can be gotten from the LAYER object, as in:
doc -e LW
{
// Get the current sheet name
string strSheetName$ = layer.name$;
ty strSheetName$;
}



Edited by - LaurP on 11/20/2012 10:18:57 AM
Go to Top of Page

greg

USA
1378 Posts

Posted - 11/20/2012 :  3:25:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Range notation cannot be used for arbitrary read/writes so both these lines fail:
if([ScriptFitData]Sheet1!Cell(ii,7)==empty)
[ScriptFitData]Sheet1!Cell(ii,7)$=%(strBookName$);
Also "empty" is not a LabTalk keyword.

You can use the cell function with a sheet range variable, and if I understand what you are trying to do here (just a test that you can read from all sheets and write to a specific sheet) then you should forget the i loop with the break and also test that ScriptFitData is not the current book/sheet, as in:

range raSFD = [ScriptFitData]Sheet1!;
iRow = 1;
doc -e W
{
if("%H"!="ScriptFitData")
{
doc -e LW
{
string strBookName$ = page.longname$;
if(strBookName.GetLength() == 0) strBookName$ = page.name$;
string strSheetName$ = layer.name$;
raSFD!cell(iRow,7)$=[%(strBookName$)]%(strSheetName$);
iRow++;
}
}
}
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 11/21/2012 :  06:58:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Greg! I got it working. I will little bit optimize the structure of my script and then copy it here for others.

(It will be copied to the message where I have the full script. I will not put it to here, as the discussion is long enough and no point to hold false data above!)

Probably in eyes of script writer it is a really ugly piece of script with several if-s and the "bad" loops systems, but it works!!! Making the structure around will probably take more days that I am not eager to waste if it would be really needed.

When things work, there is no point to change them without real need!

Hopefully my script will help others as well!
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 11/21/2012 :  07:46:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Some questions still:

1) Is there anyway possible to get the folder name where the workbook is or not?
Go to Top of Page

greg

USA
1378 Posts

Posted - 11/21/2012 :  10:42:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
pe_path page:=Book3 path:=MyPath;
ty MyPath$;
string strFld$ = MyPath.GetToken(MyPath.GetNumTokens('/')-1,'/')$;
ty strFld$;
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 11/22/2012 :  09:09:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
How to sort active worksheet. I have reached to this:

// Sort the data using active workbook and temp line.;
sort.wksname$ = Sheet1; // For the worksheet Sheet1;
sort.c1 = 0; // all columns;
sort.cname1$ = A: G; // asending order and use col G (Temp) for sorting
sort.wks(); // execute sort;

Doesn't work....
Go to Top of Page

Kathy_Wang

China
159 Posts

Posted - 11/23/2012 :  04:42:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

when you define the worksheet to be sorted, you should use the syntax
sort.wksname$=[Book1]Sheet1!;


I'm afraid that there is a typo in our labtalk document and we will improve it soon. Sorry for the confusion.

Kathy
Originlab
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 01/18/2013 :  09:34:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

The first script that I made to make my life easier has some flaws depending on the structure of fit report sheet. Got it working but it's too long....

Now I am interested how to get this working:

Idea: Loop over all fits in project and write them to one sheet.

Concerns:
1) It doesn't work.
2) How does getresults handle multifit under 1 report?

doc -e W {

doc -e LW {

// Looking if the right workbook is open;
If (wks.Name$==FitPeaks1){
getresults tr:=MyResults iw:=[%H]%(wks.Name$)!;
loop (i,1,500){
if ( [Book89]Sheet1!Cell(i,1)==empty ){

y0$=$(MyResults.Parameters.y0.Value);
y0er$=$(MyResults.Parameters.y0.Error);
xc$=$(MyResults.Parameters.xc.Value);
xcer$=$(MyResults.Parameters.xc.Error);
w$=$(MyResults.Parameters.w.Value);
wer$=$(MyResults.Parameters.w.Error);
A$=$(MyResults.Parameters.A.Value);
Aer$=$(MyResults.Parameters.A.Error);

[Book89]Sheet1!Cell(i,1)=%(y0$);
[Book89]Sheet1!Cell(i,2)=%(y0er$);
[Book89]Sheet1!Cell(i,3)=%(xc$);
[Book89]Sheet1!Cell(i,4)=%(xcer$);
[Book89]Sheet1!Cell(i,5)=%(w$);
[Book89]Sheet1!Cell(i,6)=%(wer$);
[Book89]Sheet1!Cell(i,7)=%(A$);
[Book89]Sheet1!Cell(i,8)=%(Aer$);

break;
};
else { };

};
};
else {};
};
};
Go to Top of Page

greg

USA
1378 Posts

Posted - 01/18/2013 :  11:14:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
When using getresults you have to be aware that parameter names in the tree can vary depending on the type of fit.
e.g.
The NLFit tree is different than the Peak Analyzer tree.
One Input variable has a different tree than multiple input variables.

Other fixes..
Your kludge for finding where to add rows should be replaced with a direct query. Since the 'doc' loops make each sheet Active, you can let the default of getresults do its magic. You can use tree value directly to write to cell.

range raTest = [Book89]Sheet1!1; // Use to find next row
doc -e W
{
doc -e LW
{
// Looking if the right workbook is open;
if(wks.name$ == FitPeaks1)
{
getresults tr:=MyResults; // Active is the default
nextrow = raTest.GetSize() + 1;
[Book89]Sheet1!Cell(nextrow,1) = MyResults.Parameters.y0.Value;
[Book89]Sheet1!Cell(nextrow,2) = MyResults.Parameters.y0.Error;
[Book89]Sheet1!Cell(nextrow,3) = MyResults.Parameters.xc__1.Value;
[Book89]Sheet1!Cell(nextrow,4) = MyResults.Parameters.xc__1.Error;
[Book89]Sheet1!Cell(nextrow,5) = MyResults.Parameters.A__1.Value;
[Book89]Sheet1!Cell(nextrow,6) = MyResults.Parameters.A__1.Error;
[Book89]Sheet1!Cell(nextrow,7) = MyResults.Parameters.w__1.Value;
[Book89]Sheet1!Cell(nextrow,8) = MyResults.Parameters.w__1.Error;
}
else
{
;
}
}
}
Go to Top of Page

LaurP

Estonia
16 Posts

Posted - 01/22/2013 :  07:45:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks!! I got it working my way but it only takes the 1st fitted peak.

How can I make something like this:

loop(i,1,3){
getresults tr:=MyResults; // Active is the default;
MyResults.Parameters.xc__i.Value$=;
};

I think this will crash, because if he doesn't find the element then it doesn't know what to do and aborts the script.

Maybe using a if sentence it will not crash!

loop(i,1,10){
getresults tr:=MyResults; // Active is the default;
if (MyResults.Parameters.xc__i.Value$>1){ Type "all the stuff to copy with new i parameter"; };
else { break;}; // Break the action because there is no more peaks in that fit;
};

Problem is that it doesn't want to read i! When I use i as a string and put it in there as
MyResults.Parameters.xc__%(i$).Value$
then i can get the values out, but I can't assign undirect values to i$. I can only put there real numbers, and directly as i$=1; aso.

Help neede....
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