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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Looping over metadata and copying into Worksheet

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
jellyfish123 Posted - 06/16/2011 : 09:40:08 AM
Origin Ver. 8.5 SR1
Operating System: Win7

Hi,

I want to import a bunch of files with a a bunch of metadate, which I saved during Import into the "user.variables" - Tree and also into the Metadata of the Worksheet userParam1 ... n.

After Importing the File I want to loop over the imported Metadata and save it to a new worksheet, so that the Metadata "Variable Name" becomes the Column Label and the particular value of the Variable is written in a row of that column. I want to keep that source code flexible so that I can have a variable number of Metadata and also variable names.
Unfortunately my programming skills are too bad and I am not able to loop over the metadata no matter which type (tree or userParam).

For the tree-variation I didn`t find a method to acces the nodes of a tree by an integervariable e.g. And for the userParam - I thought something should work like:

loop over idx=1 ...
%([Book1]Sheet1,10,2) = wks.userParam$(idx)$;
...

But somehow the access to the userParameter by index does not work. Additionally I didn`t find a way to get the totalnumber of UserParameters in the worksheet/column.

Can anybody hlep me with my problem(s)?

Thanks in advance
Morten

4   L A T E S T    R E P L I E S    (Newest First)
jellyfish123 Posted - 06/18/2011 : 06:01:39 AM
Thanks again. The Code works very well, but now I am running into another problem I don`t understand regarding Metadata Access. It came up, when I tried to update my legend. I am having 7 UserParameters in my worksheet and wrote the following code to demonstrate the problem. I am trying to access the data in two different ways. My goal is to set my legend as explained earlier (Version2). Version1 I implemented to check if I did anything wrong during metadata import: I start with the uotput I see when I execute the script:

Version 1 works fine
Temperatur = 25
Version 2 shows UserParamater1 or Worksheetname instead of UserParamater7
Temperatur = 52190w01


string str$,strParName$;
int idx;

// Range of my Worksheet I am looking at ...
range p=[Scans1]52190w01!;
// Index of UserParameter
idx=7;

// Access UserParameterName and Value Version 1 
type Version 1 works fine;
type p.userparam$(idx)$ + " = " + [Scans1]52190w01!col(4)[D$(idx)]$;

// Access UserParameterName and Value Version 2, which I need to update the Legend of my Graph.
// During Script execution the diagram is open in which the first Layer graphs Data:[Scans1]52190w01!col(4)
type Version 2 shows UserParamater1 or Worksheetname instead of UserParamater7;
strParName$ = p.userparam$(idx)$;
str$ ="%(strParName$) = %(1,@LD$(idx))";
type str$;


The problem is only present for UserParameter7 . All other Parameters work fine with both versions. What am I doing wrong?

Best Regards
Morten
Laurie Posted - 06/17/2011 : 2:10:54 PM
You could try something like the following:

//graph needs to be active
// col range for active plot, -w switch default to get the Y column
range -w aa=%C;
// wks range for the sheet the column belongs to
range rsheet = uid2range(aa.GetLayer())$;
//count number of dataplots and store in count
layer -c;
//declare two string variables
string str$, strParName$;
//declare int variable
int ii;
int ipar=1; //change this to whatever param row number using
strParName$ = rsheet.userparam$(ipar)$;
//loop through dataplots to build new legend
loop(ii,1, count){
str$ =str$ + " "+ "\L($(ii)) %(strParName$) = %($(ii),@LD$(ipar)) %(CRLF)";
}
legend.text$=str$;

OriginLab Technical Support
jellyfish123 Posted - 06/17/2011 : 06:12:30 AM
Thanks, that helped a lot.

May a ask an additional question regarding the graph legend?

Since I have now UserParameters in my Worksheet I can use the values of these Parameters as Legend Text using @LD1 @LD2 ... notation. But how can I also put the Names of the UserParameters in the legend? Until now I am only using the legendupdate dialog box but since I didn`t find a substitution string for the userparameter name I guess this has also to be done via scripting?

Best Regards
Morten
easwar Posted - 06/16/2011 : 5:42:31 PM
Hi Morten,

So your header variables are already stored into user parameter rows in the data sheet, and you just want to loop over them and save them to another book/sheet?

If that is what you meant, you could use code such as below:


// Assuming data book is active...
// Point to worksheet and column 1 of data sheet
range rsheet = !; // active sheet
range rcol=1;
// Create new book to hold parameter info
newbook;

// Loop over user paramter rows of in data sheet column
// Just have a large number for loop and then break out 
for(int ipar=1; ipar<=100; ipar++)
{
	string strParName$, strParValue$;
	strParName$ = rsheet.userparam$(ipar)$;
	strParValue$ = rcol[D$(ipar)]$;
	// If parameter name is empty, break
	if(0 == strParName.GetLength()) break;
	// Add to next column of new book/sheet which is active
	range rout = $(ipar);
	rout[L]$ = strParName$; // set long name using parameter name
	rout[1]$ = strParValue$; // set 1st row of col with value string of parameter
}


Easwar
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000