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
 Import ASCII comma delimiter

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
toetoe Posted - 08/24/2015 : 07:47:46 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
toetoe Posted - 08/25/2015 : 03:33:56 AM
Hi,
It works very well, thanks sean !

Best regards

Toetoe
SeanMao Posted - 08/25/2015 : 02:20:07 AM
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

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