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
 Origin C error (24) in X-Function code,

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
Hebi Posted - 10/24/2016 : 01:22:11 AM
Origin 9, It is the first time I use this software, I know how to program in C, so I just want to create some X-functions with Origin C to calculate some thermal properties, I create the code in the X-function, it compile, but when I run it into the booksheet (excel looks like) the x-function does not execute and send this weird message that I do not know what means

Origin C error (24) in X-Function code.

code is as follow...

void Visco(const vector& TEMP, const vector& DENS, vector& VISMU)
{
vector <float> DENREF, TEMPREF, PRESSREF, MUREF;
DENREF = 322.0;
TEMPREF = 647.096;
PRESSREF = 22.064;
MUREF = 1;
vector <float> TEMPWOD, DENWOD;
TEMPWOD = TEMP*0.42211666;
DENWOD = DENS / DENREF;
vector <float> MU, MU0, MU1;
vector H0 = { 1.67752,2.20462,0.6366564,-0.241605 };
vector <int> i1 = { 0,1,2,3,0,1,2,3,5,0,1,2,3,4,0,1,0,3,4,3,5 };
vector <int> j1 = { 0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,4,4,5,6,6 };
vector <float> S0=0, S1=0;
vector <float> H1 = { 0.520094,0.0850895,-1.08374,-0.289555,0.222531,0.999115,1.88797,1.26613,0.120573,-0.281378,-0.906851,-0.772479,-0.489837,-0.25704,0.161913,0.257399,-0.0325372,0.0698452,0.00872102,-0.00435673,-0.000593264 };
for (int i = 0; i <= 3; i = i + 1)
{
S0=S0+(H0[i]/(TEMPWOD^i));
}
MU0 = (100 * (TEMPWOD^(1/2))) / S0;
//Calculation of MU1//
for (int j = 0; j <= 20; j = j + 1)
{
S1 = S1 + (H1[j] * (((1 / TEMPWOD) - 1)^i1[j])*((DENWOD - 1)^j1[j]));
}
MU1 = 2.7182818284590^(DENWOD*S1);
//Final calculation of viscosity//
MU = MU0*MU1*MUREF;
VISMU=MU;
}

additionally I do not know why I can not debug (it is not that there are error messages, is just the debug option is watermark gray and is not active...)

if somebody can help me it will be great (I already send an e-mail for support a couple days ago, with no answer -maybe because of weekend...)
3   L A T E S T    R E P L I E S    (Newest First)
yuki_wu Posted - 10/26/2016 : 01:01:47 AM
Hi,

I think it is fine to declare an input column as a vector.

As what I mentioned above, I think you may confuse the calculation of vector.

The following code will help you make it clear:

void testdatatype()
{
        vector vX = {1,2,3};
	vector vY = {1,2,3};
	vector vResult1;
	vResult1 = vY / vX;
	
	printf("vResult1 is\n");

	for(int n = 0 ; n < vResult1.GetSize(); n++)
	{
        	printf("%f\n", vResult1[n]);
	}
	
	double dX = 0.5;
	vector vResult2;
	vResult2 = vX / dX;
	
	printf("vResult2 is\n");
	for(n = 0 ; n < vResult2.GetSize(); n++)
	{
        	printf("%f\n", vResult2[n]);
	}
}

You can perform division between two vectors with the same size or between one vector and one data, but you cannot perform division between two vectors with different sizes.

For example, you can try to correct the mistake above:

float DENREF;
DENREF = 322.0;
vector <float> DENWOD;
DENWOD = DENS / DENREF;



Yuki
OriginLab
Hebi Posted - 10/25/2016 : 03:21:43 AM
Oh, thanks Yuki_wu for the explanation, yes, you understood my problem 100%, but, when I create the X-function, it declares the values of the column (that are variables), as vector, I want to use the values I declared as variables in each calculation, but I am not able to take these values in vector (that has multiple values - a different value per each line in the spreadsheet-) to be part of each individual calculation.

I already changed the declaration of all other variables to do not be vector anymore, but the problem persist, it means, how can I combine these values..., or do I need to create columns just to have vectors that allocate these intermediate values...?

now I am really confused.
yuki_wu Posted - 10/24/2016 : 05:21:09 AM
Hi,

I suppose you create this X-Function in X-Function Builder and want to get a new result column from two input columns.
If so, I think you have little bit confusion in the data type: vector.

Please try the following steps:
1. Press F10 to open the X-Function Builder dialog
2. Click the Open button to bring up a browse dialog and find out your X-function
3. Select your X-function and open it in X-Function Builder
4. Click the Code Builder button
5. In Line 13: DENREF = 322.0; you defined a vector with one element
6. In Line 20: DENWOD = DENS / DENREF; you divide a vector with multiple elements by only-one-element vector and get error

There are other similar mistakes in your code. Some information about vector can be found here:
http://www.originlab.com/doc/OriginC/ref/vector

BTW, I have a small tip. You can set some breaking points in Code Builder (press F9). When you run the X-Function, the program will stop at the breaking points, then you can run your code step by step(press F8) to debug your code.

Hope it helps.

Regards,
Yuki
OriginLab

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