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
 Import ASCII comma delimiter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

toetoe

France
2 Posts

Posted - 08/24/2015 :  07:47:46 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2015 64bits b9.2.214
W7 professionnal SP1

Good Morning,

I'm a beginner with Origin C and I have a problem with the Import Ascii function. First I just want to import that type of .txt file with a comma delimiter :

Header 5 lines
2.907031e-007,0.00320172
2.911031e-007,0.0064016
2.915031e-007,0.00320172

this my code which work with a tab delimiter because the if test doesn't return 0,i don't know how to correct it:

double essai_import1()

{
string x = "C:\\test\\file.txt";
printf ("%s\n",x);
Worksheet wks1 = Project.ActiveLayer();
if (!wks1)
{
printf ("active layer is not a worksheet! \n");
return 0;
}
ASCIMP ai;

ai.iHeaderLines = 5;

if(AscImpReadFileStruct( x, &ai)==0)
{
printf ("ok \n");
return wks1.ImportASCII(x, ai);
}
else
printf("wrong structure \n");

return 0;
}


I 'll be grateful for some informations...

Toetoe

Edited by - toetoe on 08/24/2015 2:29:28 PM

SeanMao

China
288 Posts

Posted - 08/25/2015 :  02:20:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Here is an example for your case:

Prior to calling the import file functions, you need to first programmatically load and compile FileImport.c. This can be done from script using the command:

run.LoadOC(Originlab\FileImport.c, 16);
// Option 16 ensures that all dependent Origin C files are loaded,
// by scanning for the corresponding .h in FileImport.c



#include <..\originlab\fu_utils.h>
 
void ImportASCII_Ex3()
{
	//string fileName = GetOpenBox("*.txt");  // txt file browser
	//printf("The file chosen is %s\n.", fileName);
	string fileName = "E:\\file.txt";
	if( !fileName.IsFile())
		return;
 
	// create a new worksheet
	Worksheet wks;
	wks.Create();
 
	// ascii import
	ASCIMP ai;
	initASCIMP(ai);  // initialize
	ai.iAutoSubHeaderLines = 0;  // disable auto detect headers
	ai.iSubHeaderLines = 5; // set number of header lines to be 5
	ai.nLongNames = ai.iHeaderLines; // Set first header line as Long Name
	ai.nUnits = ai.iHeaderLines + 1;  // Set second header line as Units
	ai.nFirstUserParams = ai.iHeaderLines + 2; // Set header lines 3 to 5 as user parameters
    ai.nNumUserParams = 3; // Set the number of user params
	
	ai.iDelimited = 1;  // use delimiter
	ai.iDelimiter = ASCIMP_DELIM_COMMA;  // comma as delimiter
	int nret = AscImpReadFileStruct(fileName, &ai, AIRF_USE_ASCIMP);
	if(0 == nret )
	{
		// import
		wks.ImportASCII(fileName, ai);
	}	
}


Regards!

Sean
Go to Top of Page

toetoe

France
2 Posts

Posted - 08/25/2015 :  03:33:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,
It works very well, thanks sean !

Best regards

Toetoe

Edited by - toetoe on 08/25/2015 03:34:19 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