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
 labtalk interpolation to Origin C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cab0008

25 Posts

Posted - 10/05/2011 :  11:19:57 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello everyone,

I've been having some performance issues with some code that I wrote in labtalk. The labtalk code always tends to get hung up on an interpolation loop I have written and therefore I'm looking into switching the code into Origin C because I have heard that compiled codes are generally faster. I tried to get the interplxy x function to work out but I had trouble with the implementation because of syntax.

The code written below is meant to take known positions on an X axis and find an intensity for that position from interpolating another X and Y dataset.
A simplified code piece I'm working with right now is here:


//make workbook
work -b [RBM];
//assign colum names,etc here...
//...

//add set values
RBM_PEAKLOCATIONS[1]=182.4;
RBM_PEAKLOCATIONS[2]=192.5; //etc

RBM_DIAMETER[1]=1.3355771;
RBM_DIAMETER[2]=1.27026066; //etc



range RBMx = [RBM]1!Col(1);
int end = RBMx.nrows;


//This is the expensive operation
loop(i,1,end){
RBM_INTENSITY[i]=RAMAN_INTENSITY(RBM_PEAKS[i]);
}




Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

greg

USA
1379 Posts

Posted - 10/07/2011 :  09:55:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Not sure why the loop is so slow. You can try the X-Function:

interp1 ix:=[RBM]Sheet1!Peaks iy:=[Raman]Sheet1!Intensity method:=linear ox:=[RBM]Sheet1!Intensity;
Go to Top of Page

cab0008

25 Posts

Posted - 10/07/2011 :  5:55:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the response Greg,
I placed the x function in my code and tried it out and it still kind of worked but it still took about 15 minutes to run.

So, I'm working on the code in C using the same type of idea to see if I can get it to run properly and I got some errors doing it this way.
I received internal errors: -898 and -45.

Here's what I have so far.



void RBMChiralities(){
	//setup worksheets
	string RamanWksStr = "[Raman]Sheet1";
	Worksheet RamanWks(RamanWksStr);
	if(!RamanWks)
		return;
		
	WorksheetPage RBMWksPg("RBM");
	if(!RBMWksPg){
		WorksheetPage RBMWksPg;
		RBMWksPg.Create("origin", CREATE_VISIBLE);
		if(!RBMWksPg)
			return;
		RBMWksPg.SetName("RBM");
	}
	string RBMWksStr = "[RBM]Sheet1";
	Worksheet RBMWks(RBMWksStr);
	
	RBMWks.SetSize(11,5);
	
	RBMWks.SetColDesignations("XYLLL"); //L stands for Label
	RBMWks.SetColFormats("00011"); //Numeric, Numeric, Numeric, Text, Text
	RBMWks.Columns(0).SetLongName("PEAKLOCATION");
	RBMWks.Columns(0).SetName("PEAKLOCATION");
	RBMWks.Columns(0).SetLabel("PEAKLOCATION");
	RBMWks.Columns(1).SetLongName("INTENSITY");
	RBMWks.Columns(1).SetName("INTENSITY");
	RBMWks.Columns(1).SetLabel("INTENSITY");
	RBMWks.Columns(2).SetLongName("DIAMETER");
	RBMWks.Columns(2).SetName("DIAMETER");
	RBMWks.Columns(2).SetLabel("DIAMETER");
	RBMWks.Columns(3).SetLongName("NMASSIGNMENT");
	RBMWks.Columns(3).SetName("NMASSIGNMENT");
	RBMWks.Columns(3).SetLabel("NMASSIGNMENT");
	RBMWks.Columns(4).SetLongName("TYPE");
	RBMWks.Columns(4).SetName("TYPE");
	RBMWks.Columns(4).SetLabel("TYPE");

	//data    
	//http://arrow.dit.ie/cgi/viewcontent.cgi?article=1093&context=sciendoc
	//
	//Peak Locations
	RBMWks.SetCell(0,0,182.4);
	RBMWks.SetCell(1,0,192.5);
	RBMWks.SetCell(2,0,213.7);
	RBMWks.SetCell(3,0,222.5);
	RBMWks.SetCell(4,0,233.2);
	RBMWks.SetCell(5,0,244.8);
	RBMWks.SetCell(6,0,254.0);
	RBMWks.SetCell(7,0,268.3);
	RBMWks.SetCell(8,0,278.0);
	RBMWks.SetCell(9,0,295.0);
	RBMWks.SetCell(10,0,317.2);
	//Diameters
	RBMWks.SetCell(0,2,1.3355771);
	RBMWks.SetCell(1,2,1.27026066);
	RBMWks.SetCell(2,2,1.12556841);
	RBMWks.SetCell(3,2,1.09145283);
	RBMWks.SetCell(4,2,1.03817364);
	RBMWks.SetCell(5,2,0.99160114);
	RBMWks.SetCell(6,2,0.95269852);
	RBMWks.SetCell(7,2,0.90171326);
	RBMWks.SetCell(8,2,0.8587524);
	RBMWks.SetCell(9,2,0.80573685);
	RBMWks.SetCell(10,2,0.75734626);
	//NM Assignments
	RBMWks.SetCell(0,3,"(13,6)");
	RBMWks.SetCell(1,3,"(16,0)");
	RBMWks.SetCell(2,3,"(11,5)");
	RBMWks.SetCell(3,3,"(12,3)");
	RBMWks.SetCell(4,3,"(9,6)");
	RBMWks.SetCell(5,3,"(10,4)");
	RBMWks.SetCell(6,3,"(12,0)");
	RBMWks.SetCell(7,3,"(8,5)");
	RBMWks.SetCell(8,3,"(9,3)");
	RBMWks.SetCell(9,3,"(9,2)");
	RBMWks.SetCell(10,3,"(6,5)");
	//Types
	RBMWks.SetCell(0,4,"S");
	RBMWks.SetCell(1,4,"S");
	RBMWks.SetCell(2,4,"M");
	RBMWks.SetCell(3,4,"M");
	RBMWks.SetCell(4,4,"M");
	RBMWks.SetCell(5,4,"M");
	RBMWks.SetCell(6,4,"M");
	RBMWks.SetCell(7,4,"M");
	RBMWks.SetCell(8,4,"M");
	RBMWks.SetCell(9,4,"S");
	RBMWks.SetCell(10,4,"S");


//interpolation code to replace loop

	string XFStr = "interp1";
	XFBase xf(XFStr);
	if(!xf.IsValid()){
		out_str("Falied to load X Function");
		return;
	}
	DataRange vX;
	vX.Add("X", RBMWks, 0, 0, -1, 0);
	DataRange vYreal;
	vYreal.Add("Y", RamanWks, 0, 1, -1, 1);
	DataRange vYinter;
	vYinter.Add("Y", RBMWks, 0, 1, -1, 1);
	xf.SetArg(0,vX); // 0 is ix
	xf.SetArg(1,vYreal); //1 is iy
	xf.SetArg(2, 0); //2 is method, 0 is linear
	xf.SetArg(5, vYinter); //5 is the result (ox)
	xf.Evaluate();
	
}



Thanks for the input.
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