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] ).