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
 Two problems with Origin C in OriginPro 8.6
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

shafei

USA
49 Posts

Posted - 04/03/2012 :  04:41:17 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.6 and 8.1
Operating System:7
Hi,
1. I was working on a code for a couple of hours. After running it, OriginPro 8.6 stopped working. When restarting the program, all I had done in the code disappeared, while the changes I had made in other codes remain intact. I had never such experience before with previous versions of Origin.
2. I use "difftime" in my code. While Origin 8.6 returns a weird number, the same command in the code, with absolutely no changes in the code, returns the correct elapsed time.
For these reasons and some others, it sounds to me that 8.6 is not a stable version!

easwar

USA
1964 Posts

Posted - 04/03/2012 :  12:34:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi shafei,

Regarding 2, can you please send your code to tech support? Or if short, paste here?

I tried our example from this page:
http://ocwiki.originlab.com/index.php?title=OriginC:Difftime_%28global_function%29
and it worked the same in 8.51 and 86.

Thanks,

Easwar
OriginLab
Go to Top of Page

shafei

USA
49 Posts

Posted - 04/03/2012 :  8:20:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is the code:

#include <Origin.h>
#include "MYLibrary.h"

double BetaXXXLoop(int N, int segment)
{

/*******************************APPROACH 1**************************************
* Description: The coordinates are chosen, beta is calulated, then three points of
* rectangular are rotated and beta is measured again. The rotation goes from 0
* to 360/ At the end, the maximum value is stored.
********************************************************************************/
time_t start, finish;
double elapsed_time;
time( &start );

int run = 1;// number of iterations

int i,j,k;

int theta, dtheta=15;//theta is angle and dtheta in theta increment.

vector<double> x(segment);// coordinates of initial point of the first segment is
vector<double> y(segment);// x[0] and y[0]. The last componnets are
// x[segment-1] & y[segment-1]

vector<double> xaux(segment);//stores initial coordinates of the triangle
vector<double> yaux(segment);//to be used in rotations

vector<double> xmax(segment);// to store max values related to max beta
vector<double> ymax(segment);

vector<double> x0max(run);
vector<double> y0max(run);
vector<double> x1max(run);// to store coordinates having the
vector<double> y1max(run);// largest beta in each run and send it to output
vector<double> x2max(run);
vector<double> y2max(run);
/*vector<double> x3max(run);
vector<double> y3max(run);
vector<double> x4max(run);
vector<double> y4max(run);
vector<double> x5max(run);
vector<double> y5max(run);
vector<double> x6max(run);
vector<double> y6max(run);
vector<double> x7max(run);
vector<double> y7max(run);
vector<double> x8max(run);
vector<double> y8max(run);
vector<double> x9max(run);
vector<double> y9max(run);*/


vector E(2*N+1); //energy eigenvalues

matrix<complex> Xmoment(2*N+1,2*N+1); // initialize X position matrix

vector<double> beta;//stores all maximum beta values for each iteration
beta.SetSize(run);

double BetaGraph; // used to extraxt the real part of BetaInt
complex BetaInt; // calculates the beta_intrinsic
double BetaFinal;// the final beta value sent to output in each run

//********************STARTING THE CODE****************************
for(k=0; k < run; k++)
{
//*****Picking up the initial coordinates of triangle randomly*****
/* x[0] = 0.0;
y[0] = 0.0;
xaux[0]=x[0];
yaux[0]=y[0];

for(i=1; i<segment; i++)
{
x[i] = rnd()*10;
y[i] = rnd()*10;
xaux[i] = x[i];//storing initial segment coordinates in xaux & yaux
yaux[i] = y[i];
//printf("x[i] = %f\n", x[i]);
}
*/
x[0] = -32.0;
y[0] = -21.0;
xaux[0] = x[0];
yaux[0] = y[0];
x[1] = -49;
y[1] = -42;
xaux[1] = x[1];
yaux[1] = y[1];
x[2] = -69.0;
y[2] = -88.0;
xaux[2] = x[2];
yaux[2] = y[2];
//*********************** Calculating R and Energies *******************

double R = 0.0;

for(i = 0; i < segment-1; i++) // calculating the loop length
{
R = R + sqrt((x[i+1]-x[i])^2 + (y[i+1]-y[i])^2);
}

R = R + sqrt((x[0]-x[segment-1])^2 + (y[0]-y[segment-1])^2);
// adding the length of the last segment


for(i = 0; i< 2*N+1; i++)
//loop extends over 2N+1 state, N is # of excited states
{
// E[i] = EnergyLoop(i-N, R);
E[i] = (i-N)^2;//using intrinsic values
}

//******** Calculating Beta Values for different triangle rotations******

BetaFinal = 0.0;

for(theta = 0; theta < 10; theta=theta+dtheta)
{
BetaInt = (0.0, 0.0);
BetaGraph = 0.0;


for(i=0; i < segment; i++)
{
x[i] = cos(theta * pi/180) * xaux[i] - sin(theta * pi/180)*yaux[i];
y[i] = sin(theta * pi/180) * xaux[i] + cos(theta * pi/180)*yaux[i];
}

//for the case of labelling states, since in C++ arrays do no accept
//negative numbers, we shift -N to N states to 0 to 2N+1 so that for
//example ground state's label in new system is N'th state. When
//calculating different quantities like energies, every state is
//converted such that i -> (i - N).


for(i = 0; i< 2*N+1; i++)
//loop extends over 2N+1 state, N is # of excited states
{
for(j = 0; j< 2*N+1; j++)
{
Xmoment[i][j] = XnmWireLoop(x, y, i-N, j-N, R);
// N represents ground state
}
}


complex x00 = Xmoment[N][N];
for(i = 0; i < 2*N+1; i++)
// Diagonal moments need ground state moment to be subtracted in
// order to calculate ReBetaSOS
{
Xmoment[i][i] = Xmoment[i][i] - x00;
}


for(i = 0; i< 2*N+1; i++)
{
for(j = 0; j< 2*N+1; j++)
{
if (i != N && j != N)
{
BetaInt = BetaInt + (0.75)^(0.75) * ((2*pi/R)^3) *
Xmoment[N][i] * Xmoment[i][j] * Xmoment[j][N] /E[i]/E[j];
}
}
}


BetaGraph = BetaInt.m_re;


if(abs(BetaFinal) < abs(BetaGraph))
{
BetaFinal = BetaGraph;

for(i=0; i < segment; i++)
{
xmax[i] = x[i];
ymax[i] = y[i];
}
}

}//end of for theta=0;....


x0max[k] = xmax[0];
y0max[k] = ymax[0];
x1max[k] = xmax[1];
y1max[k] = ymax[1];
x2max[k] = xmax[2];
y2max[k] = ymax[2];
/* x3max[k] = xmax[3];
y3max[k] = ymax[3];
x4max[k] = xmax[4];
y4max[k] = ymax[4];
x5max[k] = xmax[5];
y5max[k] = ymax[5];
x6max[k] = xmax[6];
y6max[k] = ymax[6];
x7max[k] = xmax[7];
y7max[k] = ymax[7];
x8max[k] = xmax;
y8max[k] = ymax;
x9max[k] = xmax[9];
y9max[k] = ymax[9];*/

beta[k] = BetaFinal;

}//end of for k=1,...


//*********************now we store beta values in a column*********************

//Get the first workbook's first worksheet's active layer
//Worksheet wks = Project.ActiveLayer();

Worksheet wks;
wks.Create("Origin");


int nNumRows = run;
int nNumCols = 2*segment + 1;// since each segment has a pair of (x,y).
// +1 is for a column for beta values
wks.SetSize(nNumRows, nNumCols);

Column col0 = wks.Columns(0); //get the first column of the worksheet
vectorbase& v0 = col0.GetDataObject(); //get the reference of a column
v0 = beta; //set customer data,operation on vb will take effect instantly
//on column, or you can change elements of vb directly
Column col1 = wks.Columns(1);
vectorbase& v1 = col1.GetDataObject();
v1 = x0max;

Column col2 = wks.Columns(2);
vectorbase& v2 = col2.GetDataObject();
v2 = y0max;

Column col3 = wks.Columns(3);
vectorbase& v3 = col3.GetDataObject();
v3 = x1max;

Column col4 = wks.Columns(4);
vectorbase& v4 = col4.GetDataObject();
v4 = y1max;

Column col5 = wks.Columns(5);
vectorbase& v5 = col5.GetDataObject();
v5 = x2max;

Column col6 = wks.Columns(6);
vectorbase& v6 = col6.GetDataObject();
v6 = y2max;

/* Column col7 = wks.Columns(7);
vectorbase& v7 = col7.GetDataObject();
v7 = x3max;

Column col8 = wks.Columns(8);
vectorbase& v8 = col8.GetDataObject();
v8 = y3max;

Column col9 = wks.Columns(9);
vectorbase& v9 = col9.GetDataObject();
v9 = x4max;

Column col10 = wks.Columns(10);
vectorbase& v10 = col10.GetDataObject();
v10 = y4max;

Column col11 = wks.Columns(11);
vectorbase& v11 = col11.GetDataObject();
v11 = x5max;

Column col12 = wks.Columns(12);
vectorbase& v12 = col12.GetDataObject();
v12 = y5max;

Column col13 = wks.Columns(13);
vectorbase& v13 = col13.GetDataObject();
v13 = x6max;

Column col14 = wks.Columns(14);
vectorbase& v14 = col14.GetDataObject();
v14 = y6max;

Column col15 = wks.Columns(15);
vectorbase& v15 = col15.GetDataObject();
v15 = x7max;

Column col16 = wks.Columns(16);
vectorbase& v16 = col16.GetDataObject();
v16 = y7max;

Column col17 = wks.Columns(17);
vectorbase& v17 = col17.GetDataObject();
v17 = x8max;

Column col18 = wks.Columns(18);
vectorbase& v18 = col18.GetDataObject();
v18 = y8max;

Column col19 = wks.Columns(19);
vectorbase& v19 = col19.GetDataObject();
v19 = x9max;

Column col20 = wks.Columns(20);
vectorbase& v20 = col18.GetDataObject();
v20 = y9max; */


Column col7 = wks.Columns(7);
vectorbase& v7 = col7.GetDataObject();
v7 = x3max;

Column col8 = wks.Columns(8);
vectorbase& v8 = col8.GetDataObject();
v8 = y3max;

/************END OF RECTANGLE CODE************/

time( &finish );
elapsed_time = difftime( finish, start );
printf( "\nProgram takes %4.0f hours.\n", elapsed_time/3600 );
// /3600 convert seconds to hour

return BetaFinal;

}
Go to Top of Page

easwar

USA
1964 Posts

Posted - 04/05/2012 :  11:27:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi shafei,

Thank you for posting the code. This is indeed a bug that affects only 32-bit Origin. The 64-bit version works correctly.

We are looking into fixing this for an upcoming service release for 86

Easwar
OriginLab
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