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
 Origin Forum
 using header variables Origin8
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

OndrejMM

Australia
81 Posts

Posted - 08/13/2008 :  01:29:45 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi Guys,

I have a problem to use "header variables" from LabTalk in Origin8,...

when I type:
page.info.user.=

I see my 3 header variables

<USER>
[VARIABLES]
H011$ = "450"
H012$ = "750"
H013$ = "151"

but how to use them?

I've tried following but it doesn't work,...

col(B)=col(A)+ %(H011$)

Many Thanks
Ondrej

GZ_MOD

9 Posts

Posted - 08/13/2008 :  05:09:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ondrej,

After you executed "page.info.user.=" in the command windows, execute the following script:

str$ = %(,@w,H011$);
col(B)=col(A)+ %(str$);



Shirley Tian

Go to Top of Page

OndrejMM

Australia
81 Posts

Posted - 08/13/2008 :  07:12:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Shirley,

thanks a lot for the advice, it works but I have a new problem,... I'm importing many files (script below) and when I want to calculate col(B) values using the "header variables" and rowNum ([i]) it doesn't work, but it doesn't show any error, so I'm not really sure what is wrong,...

aa$ = %(,@w,H011$);
bb$ = %(,@w,H012$);
cc$ = %(,@w,H013$);

col(B)= %(aa$) + (%(bb$)-%(aa$)) / (%(cc$)-1) * ([i]-1);




--- SCRIPT ----

// Point to where the data files are

string path$ = "C:\ondrej\";

// Find all files with wild card

findfiles ext:="*.asc";
int numFiles = fname.GetNumTokens(LF);

// Loop over all files

int nFirst = 1;
for(int ifile = 1; ifile <= numFiles; ifile++)

{
string filepath$, file$;

// Get next file name

filepath$=fname.gettoken(ifile,LF)$;

// Parse out just file name without path and without extension

file$ = filepath.gettoken(filepath.getnumtokens(\),\)$;
file$ = file.gettoken(1,.)$;


// Add a new book and import data file
// Apply filter


newbook;

impfile fname:=filepath$ filtername:="ondrej2.oif" location:=0;

aa$ = %(,@w,H011$);
bb$ = %(,@w,H012$);
cc$ = %(,@w,H013$);

col(B)= %(aa$) + (%(bb$)-%(aa$)) / (%(cc$)-1) * ([i]-1);


}
Go to Top of Page

Shirley_GZ

China
Posts

Posted - 08/13/2008 :  9:47:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ondrej,

The rowNum[i] can only use in the Set Value dialog, which can be open by right-clicking the colomn to choose Set Colomn Values.

If you want to use the row numbers in Command Window, you can add a new colomn and fill the colomn with row numbers.


Shirley Tian

Originlab Technical Service Team
Go to Top of Page

OndrejMM

Australia
81 Posts

Posted - 08/13/2008 :  11:22:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hmm, okay then, I'm going to try to add a column and fill it with row numbers,...

can I do it somehow fast in Origin8? because LabTalk seems to be so different in comparison to Origin7.5,... I'm quite lost here,... it will take some time,...

Thanks
Ondrej
Go to Top of Page

Deanna

China
Posts

Posted - 08/15/2008 :  01:56:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Say you want to put the row numbers in column e and then use it to set values to column (b), the following script shoud work:


col(e)=data(1, wks.maxrows)
col(B)= %(aa$) + (%(bb$)-%(aa$)) / (%(cc$)-1) * (col(e)-1);


Deanna
OriginLab Technical Services
Go to Top of Page

easwar

USA
1964 Posts

Posted - 08/17/2008 :  10:18:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ondrej,

Does your col B already exist as part of your import, and you are simply changing its values after the import is done, using the variables to recompute the values?

If yes, you don't need to use the running index i at all in setting the formula, so you can write your script such as:

double var1, var2;
var1=%(page.info.user.variables.yourvarname1$);
var2=%(page.info.user.variables.yourvarname2$);
col(b)=col(a)*var1/var2;  //or any other formula

and as long as col b has data same length as col a, it will get recomputed.

If on the other hand you are creating a new column and want to compute values into this new column, then you need to add column and set its length and then use a formula, such as:


double var1, var2;
var1=%(page.info.user.variables.yourvarname1$);
var2=%(page.info.user.variables.yourvarname2$);
wks.addcol();
int lastcol = wks.ncols; // get index of last col added
int nrows = wks.nrows; // get how many rows exist
set wcol(icol) -e $(nrows); // set size of last col
wcol(icol)=col(a)*var1/var2; // compute using your formula


The wcol() function can use the index icol directly, whereas with col function you need to do col($(icol))

Also, once you have your formula with the transformation working, you can simply put this part of the script into the import filter itself. In the import wizard, go to the very last page and check the "Save filter" and "Advanced Filter Options" check boxes and then in the page that comes up next, you can put in your script. This way it becomes part of the filter and can also be used when importing the files using this filter, from the GUI.

To see such an example of filter with some script at the end, use import wizard to import the file \samples\signal processing\TR2MM.dat and use the filter that exists in that folder and you can open the very last page with the check boxes turned on and view the script.

Hope this helps.

Easwar
OriginLab
Go to Top of Page

OndrejMM

Australia
81 Posts

Posted - 08/18/2008 :  02:14:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Easwar and Deanna

I solved my problems with a bit of luck as follows: (everything works well,...)

Many thanks
Ondrej



// Point to where the data files are

string path$ = "C:\Christophe\";

// Find all files with wild card

findfiles ext:="*.asc";
int numFiles = fname.GetNumTokens(LF);

// Loop over all files

int nFirst = 1;
for(int ifile = 1; ifile <= numFiles; ifile++)

{
string filepath$, file$;

// Get next file name

filepath$=fname.gettoken(ifile,LF)$;
// Parse out just file name without path and without extension

file$ = filepath.gettoken(filepath.getnumtokens(\),\)$;
file$ = file.gettoken(1,.)$;

// Make a new PE subfolder and set it active

pe_mkdir file$ cd:=1;

// Add a new book and import data file
// Apply filter


newbook;

%W=%H;

impfile fname:=filepath$ filtername:="filter_christophe.oif" location:=0;

// delete imported file


file_delete(filepath$);

//assign header variables

aa$ = %(%W,@w,H011$);
bb$ = %(%W,@w,H012$);
cc$ = %(%W,@w,H013$);


//column ROW

if( !exist(%H_row,1)) work -i 0 row; //insert column ROW
wks.colSel(1, 1); //select 1st column
menu -e 36444; //fill column with row numbers
menu -e 50110; //move column to last
wks.colSel(3, 0); //deselect 3rd column


//move column X to first position

wks.colSel(1, 1); //select 1st column
menu -e 50126;
wks.colSel(2, 0); //deselect 2nd column


col(B)= %(aa$) + (%(bb$)-%(aa$)) / (%(cc$)-1) * (col(row)-1);

wks.col$(colnum(A)).type=1; // make this column Y
wks.col$(colnum(B)).type=4; // make this column X

work -n 1 axis.X;
work -n 2 axis.Y;

%W=%H; // save wks name
doc -t graph_christophe.otp; // create graph window
lay -i202 %W_axis.Y; // plot as line+symbol

lay -a;
lab -xb (axis.X [a.u.]);
lab -yl (axis.Y [a.u.]);


menu -e 57652;

pe_cd ..;

}
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