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
 Forum for Origin C
 Error calling x-function "rowstats" in OriginC

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
malkovich Posted - 01/26/2010 : 05:28:02 AM
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] ).
6   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 01/28/2010 : 10:50:55 AM
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
malkovich Posted - 01/28/2010 : 06:04:53 AM
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(?)
Iris_Bai Posted - 01/28/2010 : 02:41:31 AM
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
cpyang Posted - 01/27/2010 : 6:52:11 PM
-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
malkovich Posted - 01/27/2010 : 09:35:29 AM
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
Echo_Chu Posted - 01/27/2010 : 05:27:12 AM
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.

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