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 for Programming
 Forum for Origin C
 autosorting two columns with blank spaces
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Kazkek

2 Posts

Posted - 01/04/2011 :  2:18:38 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello, I've been having a problem with autosorting, for a template file, two columns that must have the numbers appear at the top with null characters at the bottom, here is an example:

ColA    ColB
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
-493.33	-0.00109
-987.79	-0.00108
-1484.1 -0.00108
-1981.9 -0.00108
-2481.3 -0.00108
-2983.7	-0.00107
-3486.1	-0.00107
-3990.7	-0.00107
-4497.8	-0.00107
-5004.4	-0.00106



I want this to be autosorted into this:

ColA     ColB
-5004.4	-0.00106
-4497.8	-0.00107
-3990.7	-0.00107
-3486.1	-0.00107
-2983.7	-0.00107
-2481.3 -0.00108
-1981.9 -0.00108
-1484.1 -0.00108
-987.79	-0.00108
-493.33	-0.00109
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--
0	--


That is ColA sorted descending or ascending (Values change sign through different sample sets) and ColB follows ColA values. It just so happens that this data set had ColB values that looks like they were sorted also, but they were not. ColB values are matched to ColA values.

I tried getting some of the C stuff working thats posted around here, but I must not be implementing it correctly into Origin8. I would like this to be automatic because I have hundreds of data files that have to be analysed and can be done by hand but I would much rather have a template to do this.

Thank you.

Penn

China
644 Posts

Posted - 01/05/2011 :  03:36:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Kazkek,

You can use the Sort method in the Worksheet class.

Penn
Go to Top of Page

Kazkek

2 Posts

Posted - 01/05/2011 :  11:39:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That is exactly what I wanted.

edit: figured something out.

But now I am kind of stuck, just realized that I need to be able to take data from a column and split it into two seperate columns for positive and negative values.

ColA
5003.4
4504.4
4014.9
3487.9
3005
2505.6
2006.37
1505.55
1004.08
492.06
23.521
-489.04
-1005.06
-1506.27
-2007.07
-2506.49
-3005
-3486.3
-3995.8
-4502.3
-5002.6


I was doing this before by having the Labtalk "Set Column Values" do the work, but if I have this set to "Auto" to run with the template, I cannot get the C code to sort the values for me.

I was thinking of writing more C to split the values also, but Im not sure how to call the data from the columns. So what I figured out would be something like this:


if(data < 0)
   Set to colA
else
   set to ColB


I know I have to use the Column class and the Dataset class, but I am kind of unsure how to declare the data.
Thank you so much already.

Edited by - Kazkek on 01/05/2011 1:32:33 PM
Go to Top of Page

Penn

China
644 Posts

Posted - 01/05/2011 :  10:18:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Kazkek;

Please try the following solution:
1) Get the data of column A by using GetDataObject method.
2) Compare each data with zero to decide which one will be put into column B, and which one will stay in column A.
3) Set new data to column A and column B by using DataRange.

See the code below:

void split_column()
{
	Worksheet wks = Project.ActiveLayer();
	if(!wks)
		return;
	Column colA = wks.Columns(0);  // column A
	Column colB = wks.Columns(1);  // column B
	if(!colA || !colB)
		return;
	
	vector vA = colA.GetDataObject();  // get data in column A
	vector vB;  // hold data of column B
	vector vANew;  // hold new data of column A
	for(int iEle=0; iEle<vA.GetSize(); iEle++)  // loop all data in column A
	{
		if(vA[iEle]>0)  // if >0, add to column B
			vB.Add(vA[iEle]);
		else
			vANew.Add(vA[iEle]);  // else, stay in column A
	}

	DataRange drA;
	drA.Add("X", wks, 0, 0, -1, 0);  // data range of column A
	drA.SetData(vANew);  // set new data to column A
	DataRange drB;
	drB.Add("X", wks, 0, 1, -1, 1);  // data range of column B
	drB.SetData(vB);  // set data to column B
}


Penn
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