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
 How to precompile OriginC-Files
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

datrix

11 Posts

Posted - 07/05/2009 :  12:01:01 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.: 7.5
Service Release: SR0
Operating System: WinXP SP2

---------

Hello,
is it possible to precompile OriginC-File once, so that it isn´t necessary to compile every time I want to use the functions defined in the source-code? Or can I build some binaries (dlls, static libraries) or something like that? Every hint is appreciated.

Thank you.
datrix

Iris_Bai

China
Posts

Posted - 07/05/2009 :  11:56:54 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use Project::FindFunction. See example codes below, FindFunction will compile test.c file and return the function pointer of AddColumns function.


// define a function pointer type for AddColumns funciton.
typedef void (*FUNCTYPE)(Worksheet& wks, int nn);
 
void myFunction()
{
	string strPath; // the full path of file name
	strPath.Format("%sOriginC\\test.c", GetAppPath(false)); 

	string strFunction = "AddColumns";
	FUNCTYPE pfn = Project.FindFunction(strFunction, strPath);

	if( pfn )
	{
		Worksheet wks;
		wks.Create();
		pfn(wks, 5);
	}
	else
		out_str("Fail to find function");
}

// New test.c file under User File Folder\OriginC and copy this function.
void AddColumns(Worksheet& wks, int nn)
{
	if( wks )
	{
		for( int ii = 0; ii < nn; ii++ )
		{
			wks.AddCol();
		}
	}
}	


Iris
Go to Top of Page

christo2

Germany
Posts

Posted - 07/09/2009 :  09:16:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Origin Ver. 8.0
SR 2
Op. System: WinXP

hi.
this programm example is nice, but it doesn't seem to work, at least not for my origin version, and I tried it on different computers.
For your example to work for me, do I have to add global variables or something? I mean it is done for your example, but just copying your code doesn't seem to do the trick. The first time trying to run it, it seemed to work, there was a box saying the function was being processed or something, but trying to call the funktion (neither as myFunction nor as AddColumns) is useless...
Unfortunately that's not the first time an example-code doesn't work. And I tried numerous, even those that were meant to be self-sustained.

I hope you can help me.

Thank you,
conny
Go to Top of Page

Iris_Bai

China
Posts

Posted - 07/10/2009 :  03:41:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by christo2

Origin Ver. 8.0
SR 2
Op. System: WinXP

hi.
this programm example is nice, but it doesn't seem to work, at least not for my origin version, and I tried it on different computers.
For your example to work for me, do I have to add global variables or something? I mean it is done for your example, but just copying your code doesn't seem to do the trick. The first time trying to run it, it seemed to work, there was a box saying the function was being processed or something, but trying to call the funktion (neither as myFunction nor as AddColumns) is useless...
Unfortunately that's not the first time an example-code doesn't work. And I tried numerous, even those that were meant to be self-sustained.

I hope you can help me.

Thank you,
conny



1. New a c file named "test" and save to User File Folder\OriginC. Copy and paste the above AddColumns function to this file.
2. New a c file named "test2" and save to any location. Copy and paste the above myFunction function and FUNCTYPE type define.
3. Only load test2.c file to current workspace and build it. After linking done, run "myFunction" in Command Window.
After "myFunction" running, will create a new worksheet with 7 columns. 7 columns means added 5 columns since there are 2 columns when new a worksheet. You can change the number for "pfn(wks, 5);" in myFunction to try.

Iris

Edited by - Iris_Bai on 07/10/2009 03:43:58 AM
Go to Top of Page

christo2

Germany
Posts

Posted - 07/10/2009 :  10:43:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Iris,

ok, now I'm confused. I did, what you suggested, yesterday and then it didn't work. Now it does. But like I wrote calling myFunction didn't work. My other codes still worked w/o any probs. Perhaps I should reinstall my origin version again, because sometime ago, it forgot a dll and wouldn't do anything anymore.
But that's no Prob.

With that code now working, if I want to put another code which does import and process my data, into such a function, how do I go about it? I'm sorry to ask some stupid questions, but I'm but a beginner who is happy when his code works, but spends way too much time trying not to get too frustrated. You were so kind to answer another problem concerning my/that code in another topic just today. So (again, sorry) my code goes like this:

void mineimport()
{
//opening a new project to get some parameters first
LT_execute("run.section(C:\...\opens.c, Main)"); //shortened filepath
// so the parameter are in the follwing ascii-file
string strFilepara = GetAppPath(0)+"para.dat";
if(strFilepara.IsEmpty()) printf("para.dat existiert nicht");
else
{
ASCIMP ascimp;
if(AscImpReadFileStruct(strFilepara,&ascimp)==0)
{
ascimp.iDelimited = 1;
ascimp.iDelimiter = ASCIMP_DELIM_SPACE;
ascimp.iMode = 1;
ascimp.nNumSep = NF_IS_AMERICAN;
ascimp.iAutoSubHeaderLines = 0;
ascimp.iSubHeaderLines = 0;
ascimp.iHeaderLines = 0;
Worksheet para0 = Project.ActiveLayer();
para0.ImportASCII(strFilepara, ascimp);
}
}
/////////////////////////////////////////////////////////////
//something like (too many, to write here, and not necessary I hope)
Worksheet wks = Project.ActiveLayer();
int statcurrent = wks.Cell(0,1); //static current
/////////////////////////////////////////////////////////////
//getting files to be importet
string strfile, pfad;
StringArray saFilePaths;
StringArray saFileTypes;
saFileTypes.Add("[Messdaten (*.DAT)] *.dat");
string strUserFilesFolder = GetAppPath();
int nFileCount = GetMultiOpenBox(
saFilePaths, saFileTypes, strUserFilesFolder, NULL,
"Test MultiOpen Dialog", false );

//import and process data
for( int i = 0; i < nFileCount; i++ )
{
LT_execute("run.section(C:\scripts_klehr\opens.c, Main)");
string strfile, pfad;
if(normal==0) //just some crutch (from before I new about the ascimp possibilities
{
ASCIMP ascimp;
strfile = saFilePaths[i];
if(saFilePaths[i].IsEmpty())
{printf("Es wurde nichts ausgewhlt!");return;}
if(AscImpReadFileStruct(saFilePaths[i],&ascimp)==0)
{
ascimp.iDelimited = 1;
ascimp.iDelimiter = ASCIMP_DELIM_SPACE;
ascimp.iMode = 1;
ascimp.nNumSep = NF_IS_AMERICAN;
ascimp.iAutoSubHeaderLines = 0;
ascimp.iSubHeaderLines = 0;
ascimp.iHeaderLines = 0;
Worksheet impo;
impo.Create();
impo.ImportASCII(saFilePaths[i], ascimp);
}
}
///////////////////////////////////////////////////////////
// some dataprocessing follows, again, way to long to write here
// and just bore you
///////////////////////////////////////////////////////////
//finally I save the active folder, this part of the code will change soon thanks to your help
Folder fld = Project.ActiveFolder();
fld.SaveAsProject(saFilePaths[i], SFC_INCLUDE_SUBFOLDERS | SFC_INCLUDE_ATTACHED_FILES);

}//end of "for"-loop
} //end of function "mineimport"

So how is it possible to get that whole thing in a precompiled function, which would be absolutely fantastic?

many thanks,
conny
Go to Top of Page

Iris_Bai

China
Posts

Posted - 07/13/2009 :  01:51:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, conny

Assume there is a data processing function in file named DataProcess.c, and the prototype of function like:
bool Data_Process(Worksheet& wks);

So add the following typedef in the beginning of the file which mineimport located in.
Note, the return value and parameter list same as Data_Process function.
typedef bool (*MY_FUNC_POINTER)(Worksheet& wks);

Then in mineimport function data processing part, add codes like:

		///////////////////////////////////////////////////////////
		// some data processing follows, again, way to long to write here 
		// and just bore you
		///////////////////////////////////////////////////////////

		string strPath; // the full path of file name
		strPath.Format("%sOriginC\\test.c", GetAppPath(false));   // assume Data_Process located in User File Folder\OriginC\DataProcess.c file
		string strFunctionName = "Data_Process";
		MY_FUNC_POINTER pfn = Project.FindFunction(strFunctionName, strPath);		
		if( pfn )
		{
			Worksheet wks = Project.ActiveLayer(); // to get the worksheet which import data into above
			pfn(wks);
		}





Iris

Edited by - Iris_Bai on 07/13/2009 01:51:47 AM
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