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
 Project (global) tree variables

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
lunchpack Posted - 06/10/2014 : 1:54:57 PM
Origin Ver. and Service Release (Select Help-->About Origin): 9.1 SR2
Operating System: Win7 Pro x64

Hi,
I'm wondering how it is possible to define a tree variable with a project (global) scope.

Let's say I want to declare a tree with the name CM, i have to declere it using

tree CM;

otherwise I cannot create nodes and leaves e.g.:

CM.info = 1;
CM.blubb = 2;

However: As soon as i declare a tree as shown above, it is automatically declared as a session variable. Also switching @global to 1 does not help.

The only way to declare a tree with global scope so far was to call a x-function and write the output data into a tree, like this:

impinfo t:=CM;

This creates a global tree called CM. However it is already filled with data. Does anyone know how to create an empty tree with global scope?

Thanks a lot!

Cheers,
lunchpack

Edit: This should also work for an script file attached to an ASCII-Import Filter. Background: I want to store user variables from the header of the ASCII files *permanently* into trees to access them later for plotting data, creating legends and so on
7   L A T E S T    R E P L I E S    (Newest First)
lunchpack Posted - 07/20/2014 : 05:58:17 AM
Ok. Yes, I noticed ;-)
cdrozdowski111 Posted - 07/19/2014 : 9:04:37 PM
It would appear that the @global forces a typed variable to be a Session variable and not a Project variable.

The docs are a bit wishy-washy.
lunchpack Posted - 07/19/2014 : 8:10:55 PM
Yes, thanks, for scalar variables it's possible by directly defining them without declaring the type.

Still, just out of curiosity: Does the manual give wrong examples or is the @global switch just thought to be used another way? At least it seems not possible to force a global scope by using it...
cdrozdowski111 Posted - 07/19/2014 : 6:24:10 PM
lunchpack,

Just to make sure you know that they function I provided creates a Tree variable that gets saved when you save the current project. If you open another project, the Tree will be gone. But if you reopen the first project, the Tree will be available again.

As far as creating Project-level scalar variables (strings, doubles, etc), you can create them as such:

myString$ = "This string gets saved with project"; // Notice it isn't proceeded by the variable type declaration

myDouble = 1234.56789; // Notice it isn't proceeded by the variable type declaration

Those will get saved with the project and will go away when you open a new project like the Tree above.
lunchpack Posted - 07/19/2014 : 5:26:33 PM
Just as a follow up on the origin labtalk documentation:

http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Data_Types_and_Variables&rdfrom=http%3A%2F%2Fwiki.originlab.com%2F~originla%2Fwiki%2Findex.php%3Ftitle%3DLabTalk%3AData_Types_and_Variables%26redirect%3Dno#Forcing_Global_Scope

In the wiki and also the printed manual the @global switch is explained. However I have not come across a scenario yet, where it actually worked (as I expected).
Just test the code given in the wiki above and you will see, that none of the declared variables will have project scope. I thought this is only a problem for trees earlier, but it seems to be true for all types of variables.

Of course one can re-write the c code above to also serve global doubles, strings etc.

Thanks again!
lunchpack
lunchpack Posted - 07/19/2014 : 5:13:43 PM
Hey cdrozdowski111,

thank you very much for your help, this is gold! Sorry for the late reply, i messed up some folders when i first tried it so the c-file did not compile correctly and only returned errors. My fault.

Tried it again and it does exectly what it should. Also thanks for commenting the code, it's really helpful!

Best regards,
lunchpack
cdrozdowski111 Posted - 06/11/2014 : 7:59:39 PM
Assuming that I haven't missed something blatantly obvious, I created a method that is a little complicated but does create a project-level Tree! Give it a try and see if it does what you need.

It is an Origin C function that accepts a string with the name which you wish to give your tree variable (e.g. "mytree"). It then creates the Tree and sets it to be project-level. The OriginC code is below and a LabTalk example is after that. Read the comments for the OC function to understand what it returns.

In Code Builder, create an Origin C file called "make_proj_level_tree_var.c" in your UFF\OriginC folder and put the following code in the file.

// File name: make_proj_level_tree_var.c

#include <Origin.h>

#pragma labtalk(1)


/*
Function creates a new project-level Tree variable named after string parameter passed into function.
Returns 1 if the new Tree was created and added to the current project.
Returns 0 if there is already a project-level Tree variable with the desired name.
Returns -1 if strTreeName param isn't a valid variable name.
Returns -2 if the project-level Tree simply wasn't created (for another reason).
*/
int make_proj_level_tree_var(string strTreeName)
{
	// Make sure the string param isn't empty.
	// If empty, return -1.
	if (0 == strTreeName.GetLength())
	{
		return -1;
	}

	// Make sure desired name is a valid name for a variable.
	// If not, return -1.
	if (!is_good_C_identifier(strTreeName))
	{
		return -1;
	}

	// See if a project-level Tree with the desired name already exists.
	// If so, return 0.
	TreeNode trTest1;
	Project.GetTree(strTreeName, trTest1);
	if(trTest1.IsValid())
	{
		return 0;
	}

	// Create a new Tree with the desired name and make it project-level.
	Tree trNew;
	trNew.SetAttribute(STR_LABEL_ATTRIB, strTreeName);
	Project.AddTree(strTreeName, trNew);

	// Test again to see if the new Tree was created and added to project.
	// If not, return -2;
	TreeNode trTest2;
	Project.GetTree(strTreeName, trTest2);
	if(!trTest2.IsValid())
	{
		return -2;
	}

	// Finally return 1 indicating sucess.
	return 1;
}


LabTalk example:

// Compile the Origin C file
run.LoadOC("%YOriginC\make_proj_level_tree_var.c", 16);

// Now create the project-level Tree var
string strTreeName$ = "mytree";
int nRet = make_proj_level_tree_var(strTreeName$);
if (nRet < 0)
{
	// Some sort of error in creating the Tree variable. See function documentation.
}

mytree.test$ = "It Works";
mytree.test$ = ;


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