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
 Data extraction

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
gurg Posted - 06/03/2011 : 11:14:23 AM
Hi,

I’m analyzing photodiodes so I have text files with two columns, current (I) and voltage(V). I have created an analysis template so that I can manipulate the data to calculate the current density (J=I/area) and the power density (P = JV), and imported my data sets successfully in this way.

Next, I want to automate sorting through the data to extract the short circuit current density (Jsc) and open circuit voltage (Voc) and maximum power point (Pmax). I want to extract these parameters from each data set and make them three columns on a new line of a single worksheet. I warn you I only have limited programming experience, but in pseudo code I believe the conditions should be:

//Find Jsc.
If V[i] == 0, then make J[i] the cell of column A of a summary sheet
//Find Voc
If J[i] > 0 and J[i-1] < 0, then make V[i] the cell of column B of a summary sheet
//Find max power
If PCE[i] == Max(PCE), then make P[i] the cell of column C of a summary sheet

(with J, V and PCE being the names for the columns containing all the data points) Then you’d loop the above block for each data set, creating a new line for each data set within the summary sheet.

Ideally, I’d like to set it up so the extraction occurs simultaneous with the importing, which I think means I need to do batch processing of some sort.

So far, I’ve tried setting up the extraction conditions as a worksheet query where I scripted it as:
Script Before If Condition:
temp = 0;

if (V[i] == 0 || (J[i] > 0 && J[i-1] < 0) || PCE[i] == Max(PCE))
{
temp = 1;
}

And then an Extraction If condition of temp == 1.

Unfortunately this instead creates three rows each containing all the variables (one row for each condition) when I would really prefer to extract only the one variable from each condition.

Then I tried using the wxt function and adding it into the Import Wizard Advanced Options to run LabTalk code after each file import. The column naming is done in the analysis template part, so I think this should work, but I get two workbooks named Summary1 and Summary2 each with a single column labelled J. In the script window I get a message saying “Invalid data range.” Here’s my code:

//Define ranges V, J, and PCE columns
range V=col(V), J=col(J), PCE=col(PCE);


//Worksheet data extraction Jsc
wxt test:="V[i]==0" ow:=[Summary]Results!”Jsc” c1:=3 c2:=3;
//Worksheet data extraction Voc
wxt test:="J[i]>0 and J[i-1]<0" ow:=[Summary]Results!”Voc” c1:=1 c2:=1;
//Worksheet data extraction Pmax
wxt test:="PCE[i]==Max(PCE)" ow:=[Summary]Results!”PCE” c1:=5 c2:=5;

I suspect one of my problem is that the J and P values are not calculated (even though I set them to autorecalculate) until after I import the file, yet the code is run directly after the import of each file, before J and P have been calculated. I tried to figure out how to add a recalculate call to the top of my Labtalk code, I tried –r 1 Labtalk command, but I don’t think that is really what I want because it seems to totally stop any creation of new workbooks/worksheets, so I took it out again.

But that can’t be the only thing I’m doing wrong, since I’m only getting the J column showing up in my summary results workbook. I also can’t find directions for naming columns for the ow part of the wxt function, I know I read the appropriate help page at some point, but I can’t find it now, so I suspect my formatting is off and probably contributing to the problem.

I would greatly appreciate any help you can offer. Many thanks.
4   L A T E S T    R E P L I E S    (Newest First)
Samy Almosni Posted - 04/11/2018 : 12:57:57 AM
Dear Yuki,
thank you very much for your kind reply which helped me a lot.
your proposal was good I just have changed the copydata function by the wrcopy function has this last one also allows to copy chain of character which was needed for my samples name.
So the code became
int ii = 0;
//loop over all worksheets in the folder
doc -ef LB {
if(exist(%H,2)==0) //not a workbook, must be a matrix
continue;
if(%H == "Result")
continue;
ii = ii + 1;
string str=wks.Name$;
//Copy data to result sheet
wrcopy iw:=[%H]%(str$)! r1:=1 c1:=4 c2:=9 ow:=[Result]Sheet1! dr1:=$(ii) label:=1;
}
Thanks again for your kind help.
Kindest regards,
Samy
yuki_wu Posted - 03/29/2018 : 11:19:51 PM
Hi Sam,

I suppose you want to do something like this:
int ii = 0;
//loop over all worksheets in project
doc -e LB 
{   
	if(exist(%H,2)==0) //not a workbook, must be a matrix
        	continue; 
	if(%H == "Result") 
		continue;
	ii = ii + 1;
	string str=wks.Name$;     
	//Copy data to result sheet   
	copydata irng:=[%H]%(str$)!4[1]:7[1] orng:=[Result]Sheet1!1[$(ii):$(ii)] clear:=1; 
}

Hope it helps.

Regards,
Yuki
OriginLab
Samy Almosni Posted - 03/29/2018 : 9:54:36 PM
Hi,
First of all I present you in advance my apologies for my poor english and my bad programming skills...
I've a very similar problem and I also want to extract Jsc, Voc, FF and the PCE in a summary table. In my case I'm using a different approach... Here are the few lines I've wrote in the import wizard so far

col(c)=0;
col(d)=0;
col(e)=0;
col(f)=0;
col(g)=0;

//changing current to current density
col(b)=col(b)*1000/0.1875;
//Calulating Pmax and PCE
col(c)=col(a)*col(b);

//assume worksheet is active
//perform linear fit with data from cols 1,2 to find Jsc and Voc;
range r1 = [%H]wks.name$!col(1);
range r2 = [%H]wks.name$!col(2);
r2(0)=;
r1(0, r2)=;

//extract Jsc
cell(1,4)=r2(0);
//extract Voc
cell(1,5)=r1(0,r2);
//Extract PCE and FF
effbw=max(col(c));
FF=max(col(c))/(r2(0)*r1(0,r2));
cell(1,6)=FF;
cell(1,7)=effbw;

col(a)[L]$ = "U"; // Long name
col(a)[U]$ = "V"; // Units
col(b)[L]$ = "J"; // Long name
col(b)[U]$ = "mA/cm\+(-2)"; // Units
col(c)[L]$ = "Power"; // Long name
col(c)[U]$ = "mW"; // Units
col(d)[L]$ = "Jsc"; // Long name
col(d)[U]$ = "mA/cm\+(-2)"; // Units
col(e)[L]$ = "Voc"; // Long name
col(e)[U]$ = "V"; // Units
col(f)[L]$ = "FF"; // Long name
col(f)[U]$ = "%"; // Units
col(g)[L]$ = "PCE"; // Long name
col(g)[U]$ = "%"; // Units

From here I would like extract cells of row 1 from column 4 to 7 [so cell(1,4-->7)] of the many workbook I've in my project to create a summary and ideally put the name of the workbook they are coming from.

So the table would look like that

book1 Jsc1 Voc1 FF1 PCE1

..... .... .... ... ....

bookN JscN VocN FFN PCEN

Thanks in advance for any help you can provide.
Best,
Sam
Laurie Posted - 06/03/2011 : 3:25:16 PM
When using the Worksheet Query tool, there is only one query that can be set and saved. The columns that are checked in the Extract list of checkboxes are the ones that get extracted.

The problem with the wxt function is that the ow:= parameter is a worksheet and not a column, so you can only specify the worksheet to extract the values to; you can't say put them in a specified column.

It seems you will need to write a loop. For example:
int count = 1;
range rrI=col(V); range rrO=Summary!col(A);
loop(i,1,rrI.getsize()){
if(rrI[i]==0){
rrO[count]=col(J)[i]; count++;}
}

OriginLab Technical Support

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