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
 How to script 'set many column values'
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

nanodori

3 Posts

Posted - 05/29/2010 :  9:18:41 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 7.5 and Service Release 2006(Select Help-->About Origin):
Operating System: windows xp

Basically, I need to do 'set many column values' with a script.
For example, columns 2p,2n,2,7p,7n,7,12p,12n,12,17p,17n,17,...
each column name increases 5 every three.
column values, col(2)=2/(col(2p)-col(2n)), col(7)=2/(col(7p)-col(7n)), col(12)=2/(col(12p)-col(12n)), col(17)=2/(col(17p)-col(17n)),...
It's terrible doing over 100 columns like that.
Can you write a script for me?

TreeNode

64 Posts

Posted - 05/30/2010 :  12:54:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I could write you some functions using OriginC. But havent you tried own your own?
Or do you have no experience in programming?

There are examples doing things like that to:
http://ocwiki.originlab.com/index.php?title=OriginC:Data_Access_from_Worksheet

When I should help you in your buisness I need a few more basic conditions about
your problem:

- do all columns you need allready exist in your worksheet? Or do you have to create
the result Columns

- how does your worksheet look like after importing data? Do you have to rename
columns?

So please tell me something about the initial situation, then I might be able
to help you.

|-- TreeNode
...|-- a??
...|-- ha!!
Go to Top of Page

nanodori

3 Posts

Posted - 05/31/2010 :  06:04:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have no experience in programming.
I do import many files, where each file has 5 columns.
only the second column is necessary, but its name is determined by
the closest integer value of data in the fourth column and the sign of the fifth.
For example,

column 1, column 2, column 3, column 4, column 5
-45, 2345, 4363, 2.003, -20000
-44.8, 2435, 23432, 2.003, -20000

would be converted to

column 1, 2n
-45, 2345,
-44.8, 2435

where 'n' in '2n' means negative sign of the data, the fifth, -20000,
another one is

column 6, column 7, column 8, column 9, column 10
-45, 23455, 4363, 1.998, 20000
-44.8, 243255, 23432, 1.998, 20000

->
column 6, 2
-45, 23455
-44.8, 243255

I say 2 from the positive sign.

then, I need to insert a column before the third file like

column 1, 2n, column 6, 2, n2(a new column)
....

col(n2)=2/(col(2)-col(2n))

does it make sense?
it's hard to write out the problem, I can email you with the original file.

Jinseong
Go to Top of Page

TreeNode

64 Posts

Posted - 05/31/2010 :  06:35:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

think I got a better understanding of what you want to do,
but only better...

It would be best if you would send me the file per email, and
an example how the result should look like, when function operated on them.

When I am able to understand exactly what you want to do, I could give it a try.
Think its not that hard, do write a function that can do what you want to do.

|-- TreeNode
...|-- a??
...|-- ha!!
Go to Top of Page

nanodori

3 Posts

Posted - 06/01/2010 :  9:50:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ok I don't know how to attach a file with this system. I just paste and copy a few columns below.


a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20
-2 -582.4353 -1.14203E-4 302.003 -19999.049 -2 -949.6506 -1.86206E-4 302.0012 20001.684 -2 -770.9058 -1.51158E-4 297.0026 -20000.414 -2 -1027.4715 -2.01465E-4 296.9996 20001.166
-1.98 -578.7888 -1.13488E-4 302.003 -19999.049 -1.98 -865.7505 -1.69755E-4 302.0012 20001.684 -1.98 -573.9234 -1.12534E-4 297.0026 -20000.414 -1.98 -817.1118 -1.60218E-4 296.9996 20001.166
-1.96 -615.264 -1.2064E-4 302.003 -19999.049 -1.96 -826.8426 -1.62126E-4 302.0012 20001.684 -1.96 -609.1848 -1.19448E-4 297.0026 -20000.414 -1.96 -779.4177 -1.52827E-4 296.9996 20001.166
-1.94 -578.7888 -1.13488E-4 302.003 -19999.049 -1.94 -828.0564 -1.62364E-4 302.0012 20001.684 -1.94 -614.0502 -1.20402E-4 297.0026 -20000.414 -1.94 -836.5683 -1.64033E-4 296.9996 20001.166
-1.92 -583.6491 -1.14441E-4 302.003 -19999.049 -1.92 -864.5367 -1.69517E-4 302.0012 20001.684 -1.92 -589.7283 -1.15633E-4 297.0026 -20000.414 -1.92 -849.9456 -1.66656E-4 296.9996 20001.166
-1.9 -652.9632 -1.28032E-4 302.003 -19999.049 -1.9 -879.1278 -1.72378E-4 302.0012 20001.684 -1.9 -581.2215 -1.13965E-4 297.0026 -20000.414 -1.9 -876.6951 -1.71901E-4 296.9996 20001.166
-1.88 -582.4353 -1.14203E-4 302.003 -19999.049 -1.88 -865.7505 -1.69755E-4 302.0012 20001.684 -1.88 -609.1848 -1.19448E-4 297.0026 -20000.414 -1.88 -836.5683 -1.64033E-4 296.9996 20001.166
-1.86 -616.4829 -1.20879E-4 302.003 -19999.049 -1.86 -843.8613 -1.65463E-4 302.0012 20001.684 -1.86 -561.765 -1.1015E-4 297.0026 -20000.414 -1.86 -843.8613 -1.65463E-4 296.9996 20001.166
-1.84 -634.7205 -1.24455E-4 302.003 -19999.049 -1.84 -869.397 -1.7047E-4 302.0012 20001.684 -1.84 -590.9472 -1.15872E-4 297.0026 -20000.414 -1.84 -860.8851 -1.68801E-4 296.9996 20001.166
-1.82 -627.4275 -1.23025E-4 302.003 -19999.049 -1.82 -848.7267 -1.66417E-4 302.0012 20001.684 -1.82 -605.5383 -1.18733E-4 297.0026 -20000.414 -1.82 -864.5367 -1.69517E-4 296.9996 20001.166

->

a1(X) 302n 302 n302 297n 297 n297
-2 -582.4353 -949.6506 6.808 -770.9058 -1027.4715 9.74409
-1.98 -578.7888 -865.7505 8.71196 -573.9234 -817.1118 10.2801
-1.96 -615.264 -826.8426 11.81594 -609.1848 -779.4177 14.68576
-1.94 -578.7888 -828.0564 10.02938 -614.0502 -836.5683 11.23504
-1.92 -583.6491 -864.5367 8.90036 -589.7283 -849.9456 9.60736
-1.9 -652.9632 -879.1278 11.0539 -581.2215 -876.6951 8.46099
-1.88 -582.4353 -865.7505 8.82409 -609.1848 -836.5683 10.99464
-1.86 -616.4829 -843.8613 10.99489 -561.765 -843.8613 8.86222
-1.84 -634.7205 -869.397 10.65296 -590.9472 -860.8851 9.26139
-1.82 -627.4275 -848.7267 11.29692 -605.5383 -864.5367 9.65257

col(n302)=1000/1.6*4/(col(302n)-col(302))
col(n297)=1000/1.6*4/(col(297n)-col(297))
..... iteration for all columns

Jinseong
Go to Top of Page

TreeNode

64 Posts

Posted - 06/02/2010 :  05:10:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok, now I understand what you want to do. (hope I got you right)
I will write you a script to do this. I will post it here soon.

|-- TreeNode
...|-- a??
...|-- ha!!
Go to Top of Page

TreeNode

64 Posts

Posted - 06/02/2010 :  11:25:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
So...here you are!
I wrote a OriginC function, that does what you want to do.
Remember, when calling this function the Worksheet with the source data
must be active!

To operate on the columns: for example -> col(n302)=1000/1.6*4/(col(302n)-col(302))
I used a Labtalk statement, at the end of the function.

I dont think that my function is perfect. But it works ;D
Perhabs there is a easier way to implement it. But who cares...
When I got enough time perhabs I will try to code a optimized version.

For now please try this one. I tested it on your sample data. Works fine.

void work_on_columns_ex1(void)
{
	Worksheet wksSource, wksResult;
	wksSource = Project.ActiveLayer();
	
	if(!wksSource)
		return;
	
	// Create a result Worksheet
	wksResult.Create();
	
	if(!wksResult)
		return;
	
	Column col;
	int nC, nC1, nC2,
		nR, nR1, nR2,
		nDestC1,
		nNumCols,
		nPos = 0,
		nValue;
		
	double dValue;
	
	string	strName	= "",
			strValue = "",
			strColNameCreated = "";
			
	vector<int>		naFourthColumn;
	vector<double>	daFifthColumn;
	
	bool bRet;
	int  nRet;
	
	for(int i = 3; i < wksSource.Columns.Count(); i+=5)
	{		
		nR = 0;
		nC = i; // 4., 8., 12. column ...
		bRet = wksSource.GetCell( nR, nC, strValue );
		if( bRet )
		{
			dValue = atof( strValue );	// Convert the String value to Integer
			nValue = nint( dValue );	// next integer to double value
		}
		// Store integer Values in vector
		naFourthColumn.Add(nValue);
	}
	
	for(int ii = 4; ii < wksSource.Columns.Count(); ii+=5)
	{
		nR = 0;
		nC = ii; // 5., 10., 15. column ...
		
		bRet = wksSource.GetCell( nR, nC, strValue );
		if( bRet )
		{
			dValue = atof( strValue ) // Convert the String value to Double;
		}
		// Store double Values in vector
		daFifthColumn.Add(dValue);
	}

	// copy first column to result Worksheet
	col = wksSource.Columns(0);
	nC1 = col.GetIndex();
	nC2 = col.GetIndex();
	nR1 = 0;
	nR2 = col.GetNumRows();
	nDestC1 = 0;
	DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS;
	
	nRet = wksSource.CopyTo(wksResult, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl); 
	
	// copy rest of relevant columns to result Worksheet
	for(int j = 0; j < wksSource.Columns.Count(); j+=5)
	{
		col = wksSource.Columns(j+1); // 2., 7., 12. column ...
		nC1 = col.GetIndex();
		nC2 = col.GetIndex();
		nR1 = 0;
		nR2 = col.GetNumRows();
		nDestC1++;
		DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS;
		
		nRet = wksSource.CopyTo(wksResult, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl); 
	}
	
	// change column names
	nNumCols = wksResult.Columns.Count();
	for(int k = 1; k < nNumCols; k++)
	{		
		// If value of fifth column is negativ append an 'n'
		if( daFifthColumn[k-1] < 0.)
			strName.Format("%dn", naFourthColumn[k-1]);
		else
			strName.Format("%d", naFourthColumn[k-1]);
		
		col = wksResult.Columns(k);
		col.SetName(strName);
	}
	
	string strLT_command;
	int nColResult, nColSource1, nColSource2;

	// Add new result columns
	nNumCols = wksResult.Columns.Count();
	for(int kk = 0; kk < (nNumCols-1); kk+=2)
	{
		nPos += 3;
		string strColNameCreated;

		strName.Format("n%d", naFourthColumn[kk]);
		wksResult.InsertCol( nPos, strName, strColNameCreated );
		
		Collection<Column> cCol;
		cCol = wksResult.Columns;
		
		col = cCol.Item(strColNameCreated);
		nColResult	= col.GetIndex() + 1;
		nColSource1	= nColResult - 2;
		nColSource2	= nColResult - 1;
		
		// Execute a Labtalk statement to operate on the columns
		strLT_command.Format("col(%d) = 1000/1.6*4/(col(%d)-col(%d))", nColResult, nColSource1, nColSource2);
		LT_execute( strLT_command );
	}
}


|-- TreeNode
...|-- a??
...|-- ha!!
Go to Top of Page

TreeNode

64 Posts

Posted - 06/16/2010 :  09:01:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey,

would you please tell me if the script works for you?
I want to know if my work led to success, so that I didnt do
it for nothing.

|-- TreeNode
...|-- a??
...|-- ha!!
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