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
 Origin Forum
 sorting paired columns

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
elirosen Posted - 04/12/2006 : 3:54:47 PM
Origin Version (Select Help-->About Origin): 7.5 SR5
Operating System: Win XP

I have written a LabTalk script to create a summary worksheet concatenating X and Y data columns from several imported files. On import, each new worksheet is named after the file (ex: apr10001). However, concatenation doesn't occur in order of file name (i.e. apr10001, apr 10002, etc.) I'd like to sort the columns to have the paired X,Y columns ordered by column name. Can someone advise how to do this?

Currently I have named only the Y columns:

win -n d Summary_Data;

%W=%H;
doc -ef W {
if("%W"!="%H") {
%W!wks.addCol();
%W!wks.col$(%W!wks.ncols).type = 4;
%(%W,%W!wks.ncols) = %(%H,3);
%W!wks.addCol();
%W!wks.col$(%W!wks.ncols).type = 1;
%(%W,%W!wks.ncols) = %(%H,4);
%W!wks.col$(%W!wks.ncols).name$ = %H;

};
};

My attempts to use sort() have been in vain and I'm not sure I fully understand primary vs secondary sorting critieria.

Many thanks!

-Eli



3   L A T E S T    R E P L I E S    (Newest First)
Deanna Posted - 04/16/2006 : 11:43:46 PM
Hi, Eli.

To set a column as X data, you may just use SetType(). For example, wks.Columns(str).SetType(OKDATAOBJ_DESIGNATION_X).

Mike's code can be modified as follows:

void test()
{
Worksheet wksSrc = Project.ActiveLayer();
if( !wksSrc )
return;
string wksName = wksSrc.GetPage().GetName();
Worksheet wksSort;
wksSort.Create();
for(int i=0;i<wksSrc.GetNumCols(); i+=2)
{
wksSort.SetCell(i/2,0,wksSrc.Columns(i).GetName()); // X col names to 1st col
wksSort.SetCell(i/2,1,wksSrc.Columns(i+1).GetName()); // Y col names to 2nd col
}
wksSort.Sort(1); // sort ascending w.r.t second column (Y col names)
Dataset dd1,dd2;
string str;
Worksheet wks;
wks.Create();
wks.DeleteCol(0);
wks.DeleteCol(0); // start with a blank wks
for(i=0;i<wksSrc.GetNumCols()/2;i++)
{
wksSort.GetCell(i,0,str);
wks.AddCol(str);

wks.Columns(str).SetType(OKDATAOBJ_DESIGNATION_X);//Set the column to X

dd1.Attach(wksSrc.Columns(str));
dd2.Attach(wks.Columns(str));
dd2 = dd1; // copy X column
wksSort.GetCell(i,1,str);
wks.AddCol(str);
dd1.Attach(wksSrc.Columns(str));
dd2.Attach(wks.Columns(str));
dd2 = dd1; // copy Y column
}
wksSort.Destroy(); // close sort wks
wksSrc.Destroy(); // close source wks
wks.GetPage().Rename(wksName); // rename sorted wks
}


Deanna
OriginLab GZ Office

Edited by - Deanna on 04/17/2006 9:45:36 PM
elirosen Posted - 04/16/2006 : 6:14:10 PM
Many thanks for your help, Mike. Can you tell me how modify the C code to set the copied X columns as X data. As implemented, the code leaves all columns generated in the summary worksheet as Y data.

Again, thanks for the help! This forum is invaluable.

-Eli

Edited by - elirosen on 04/16/2006 8:58:50 PM
Mike Buess Posted - 04/12/2006 : 5:15:17 PM
Hi Eli,

The following Origin C function creates a sorting worksheet and fills the first column with all X-column names from the source worksheet and the second column with the corresponding Y-column names. It then sorts that wks with respect to the second column producing the order you want. Finally it creates another worksheet and copies columns from the source wks in the order determined by the sort wks. (Probably clearer by looking at the function than reading my explanation.)
void test()
{
Worksheet wksSrc = Project.ActiveLayer();
if( !wksSrc )
return;
string wksName = wksSrc.GetPage().GetName();
Worksheet wksSort;
wksSort.Create();
for(int i=0;i<wksSrc.GetNumCols(); i+=2)
{
wksSort.SetCell(i/2,0,wksSrc.Columns(i).GetName()); // X col names to 1st col
wksSort.SetCell(i/2,1,wksSrc.Columns(i+1).GetName()); // Y col names to 2nd col
}
wksSort.Sort(1); // sort ascending w.r.t second column (Y col names)
Dataset dd1,dd2;
string str;
Worksheet wks;
wks.Create();
wks.DeleteCol(0);
wks.DeleteCol(0); // start with a blank wks
for(i=0;i<wksSrc.GetNumCols()/2;i++)
{
wksSort.GetCell(i,0,str);
wks.AddCol(str);
dd1.Attach(wksSrc.Columns(str));
dd2.Attach(wks.Columns(str));
dd2 = dd1; // copy X column
wksSort.GetCell(i,1,str);
wks.AddCol(str);
dd1.Attach(wksSrc.Columns(str));
dd2.Attach(wks.Columns(str));
dd2 = dd1; // copy Y column
}
wksSort.Destroy(); // close sort wks
wksSrc.Destroy(); // close source wks
wks.GetPage().Rename(wksName); // rename sorted wks
}


Mike Buess
Origin WebRing Member

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