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
 Error calling x-function "rowstats" in OriginC
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

malkovich

Germany
14 Posts

Posted - 01/26/2010 :  05:28:02 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 8.1G and Service Release SR1 (v8.1.13.88) (Select Help-->About Origin):
Operating System: Windows XP SR3

For the calculation of the mean and std of 9 columns for each row I want to call the x-function "rowstats" in my OriginC script. But when the script reaches this point Origin prints the error:

rowstats:X-Function failed to execute!
Internal error code: -898, -45

and Origin crashes completely.
The code that causes the error is the following:


[...]
			//
			// calculate the mean and standard deviation of the correction factors
			//
			
			// Add a new column to the worksheet for the mean correction factor
			int colNumMean = -1;
			string colNameMean = "mean";
			colNumMean = wksCalculation.AddCol(colNameMean);
			
			if( colNumMean == -1 )
			{
				log_file_text.Format("Error: Couldn't create new column \"%s\" in worksheet \"%s\"\n", colNameMean, short_name_calculation);
				WriteUserLogFile(log_file_text, TRUE);
				return;
			}
			
			// Add a new column to the worksheet for the correction factor standard deviation
			int colNumStd = -1;
			string colNameStd = "SD";
			colNumStd = wksCalculation.AddCol(colNameStd);
			
			if( colNumStd == -1 )
			{
				log_file_text.Format("Error: Couldn't create new column \"%s\" in worksheet \"%s\"\n", colNameStd, short_name_calculation);
				WriteUserLogFile(log_file_text, TRUE);
				return;
			}

			//
			// Go thru all columns (values of different configs) and calculate mean and std
			//
			
			// rows and cols begin at "1" for x-function arguments!
			
			int numRows = wksCalculation.GetNumRows();
			
			// use x-function "rowstats" to calculate:
			// example: rowstats mean:=[m01p02cor]Sheet1!mean sd:=[m01p02cor]Sheet1!SD  irng:=[m01p02cor]Sheet1!col(2)[1]:col(10)[25] 
			
			XFBase xf("rowstats");
			if( !xf.IsValid() )
			{
	    		log_file_text.Format("Error: Could not load X-Function \"rowstats\"\n");
	    		WriteUserLogFile(log_file_text, TRUE);
	    		return;
			}
			
			string strIRNG;
			strIRNG.Format("[%s]Sheet1!col(%d)[1]:col(%d)[%d]", short_name_calculation, 2, colNumMean, numRows);
			if( !xf.SetArg("irng", strIRNG) )
			{
				log_file_text.Format("Error: failed to set argument \"irng\" in X-Function \"rowstats\"\n");
	    		WriteUserLogFile(log_file_text, TRUE);
	    		return;
			}
			
			string strMean;
			strMean.Format("[%s]Sheet1!%s", short_name_calculation, colNameMean);
			if( !xf.SetArg("mean", strMean) )
			{
				log_file_text.Format("Error: failed to set argument \"mean\" in X-Function \"rowstats\"\n");
	    		WriteUserLogFile(log_file_text, TRUE);
	    		return;
			}
			
			string strSD;
			strSD.Format("[%s]Sheet1!%s", short_name_calculation, colNameStd);
			if( !xf.SetArg("sd", strSD) )
			{
				log_file_text.Format("Error: failed to set argument \"sd\" in X-Function \"rowstats\"\n");
	    		WriteUserLogFile(log_file_text, TRUE);
	    		return;
			}
			
			if( !xf.Evaluate() )
			{
				log_file_text.Format("Error: failed to execute the X-Function \"rowstats\"\n");
	    		WriteUserLogFile(log_file_text, TRUE);
	    		return;
			}


Do you have an idea what I can do to avoid this error/program crash and to get the mean and std values?
When I call the function manually from the command window it works fine ( example: rowstats mean:=[m01p02cor]Sheet1!mean sd:=[m01p02cor]Sheet1!SD irng:=[m01p02cor]Sheet1!col(2)[1]:col(10)[25] ).

Echo_Chu

China
Posts

Posted - 01/27/2010 :  05:27:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, Hans,

To calculate the row statistics in OC, I suggest you to use our oc function, ocmath_row_desc_stats().

You can refer to this page for an example how to call the oc function

Echo
OriginLab Corp.
Go to Top of Page

malkovich

Germany
14 Posts

Posted - 01/27/2010 :  09:35:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Echo,

thanks for your help. I tried this but the function ocmath_row_desc_stats() return -3. I could not find out what this error code means...

Greetings,

Hans
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 01/27/2010 :  6:52:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
-3 means either nRows or nCols =0. So check the argument to see what values they were when calling this function.

The original example was not very clear, so I have updated to indicate how to specify the columns. You can read more about DataRange Add to see how to specify row ranges if that is needed.


CP
Go to Top of Page

Iris_Bai

China
Posts

Posted - 01/28/2010 :  02:41:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hans,

Please click here to see the description of return value and other information about ocmath_row_desc_stats.

If want to know more about DataRange, please go to Data Range Examples.




Iris

Edited by - Iris_Bai on 01/28/2010 03:24:47 AM
Go to Top of Page

malkovich

Germany
14 Posts

Posted - 01/28/2010 :  06:04:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your help, my scripts are working now.
But I dont know what one of the parameters mean. Just for a better understanding:

DataRange::Add() - the parameter "lpcszName". "X", "Y" and so on sounds to me more like the plot designation. The name I assign to the columns is more like "mean" or "wavelength". The plot designations of the columns I use in my script are "Y". But when I use "Y" for lpcszName it does not work. Using "X" the funtion does what it should do(?)
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 01/28/2010 :  10:50:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You are absolutely right that we didnt document the DataRange area clearly, and we will try to fix it asap.

DataRange subnodes all must have names and they are usually plot designations for more complex DataRange like XYRange. When constructing a datarange with just a bunch of cells without explicite desingation, then "X" must be used, due to some historical reason. We could improve our code such that if the range name is not specified, then we internally set it to "X", but that will need to be in the next version. So for now, we will just need to improve our documentation.

Thanks for pointing this out.

CP
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