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
 Batch Import Text Files Into Origin 8

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
mtremblay Posted - 03/19/2009 : 8:45:19 PM
Origin Ver 8.0 SR4 (Select Help-->About Origin):
Operating System: XP

I am now converting my Origin 7.5 batch import program so it works with Origin 8; however, I am having some issues. I can load the worksheet LONG NAME and UNITS labels correct, but I cannot load the COMMENTS label and PARAMETERS label correctly. See details below. Any suggestions welcome.

A typical text file I import has 4 header lines. They are:
1) Parameter Name (I limit these to 16 characters or less)
2) Parameter Units
3) Parameter description
4) Parameter Type (Analog or Discrete)

I want to import the text file into an Origin Workbook (with one worksheet) and set following worksheet column label rows with the information below

LONG NAME: (I want to set this to the same name as the column)
UNITS (I want this to hold the parameter units)
COMMENTS (I want this to hold the Parameter description)
PARAMETERS (I want this to hold the Parameter type)


When I run the section of C code below the worksheet label row set as

COLUMN NAME: This label is set correctly
LONG NAME This label is set correctly
UNITS This label is set correctly
COMMENTS This label contains the Parameter Description on the
first row and the Parameter type on the second row.
I only want the Parameter Description in this
Comments label, not the Parameter type.
PARAMETERS Nothing is in this label. I want the Parameter
type in this label.

The main section of C code I use is listed below.

//----------------------------------------------------------
// for each import file selected conduct the following code

for(int iFile = 0; iFile < iNumFiles; iFile++)
{
string strFileName = GetFileName( saFilePaths[iFile], TRUE );
string strMessage = "Processing: " + strFileName;
SetDataDisplayText(strMessage);

//----------------------------------
wks.Destroy();
//------------------------------
// import file has 4 header lines
// 1st line: parameter name (column name also known as short name)
// 2nd line: parameter units
// 3nd line: parameter description
// 4th line: parameter type, (analog or discrete)


if(AscImpReadFileStruct(saFilePaths[iFile], &ai)==0)
{

ai.iAutoSubHeaderLines = 0;
ai.iSubHeaderLines = 4; //import file has 4 header lines
ai.nLongNames = ai.iHeaderLines;//set long name to short name
ai.nUnits = ai.iHeaderLines +1; // set units label
ai.iMaxLabels = ai.iHeaderLines +2; // set description
ai.nFirstUserParams = ai.iHeaderLines +3; //set parameters label?

ASCIMPRESULT air;
Worksheet wks;
wks.Create("MyWorksheet1.otw");
//--
wks.GetPage().Rename("Mdata1");
//--
int nRet=wks.ImportASCII(saFilePaths[iFile], ai, &air);
out_int("nRet = ", nRet);
}
else
{
out_str("failed to read ascii file");
};
////////////////////////////////////////////////
3   L A T E S T    R E P L I E S    (Newest First)
mtremblay Posted - 03/28/2009 : 08:53:27 AM
I worked on the issue some more and found the OriginC code you provided does work, just not what I was expecting. Your code creates a new UserDefined label called UserParameter0. I did not see this new label until I clicked on the upper left hand gray box on the worksheet and selected the option to display the UserParameter0 label. This labels contains the parameter type from the text file. For some reason I was expecting the parameter type to load into the existing worksheet label called PARAMETERS, which I had displayed. I could not find a way to load the parameter type into the PARAMETER label, so I changed some of my other code to use the UserParameter0 label and changed its name to PARAMETER TYPE. Thanks.
mtremblay Posted - 03/26/2009 : 5:09:55 PM
Thank you for your input. Unfortunately I am still having a problem.

I modified the OriginC code as you indicated. Now the COMMENTS line is limited to one line instead of two, which is good; however, the PARAMETERS line is still blank. I expect the PARAMETERS line to hold the parameter type imported from the text file. The text file parameter type appears to have disappeared. Any thoughts?
greg Posted - 03/26/2009 : 2:11:37 PM
The OriginC code for ASCII Import is less clear than the new XFunction for ASCII Import from LabTalk.

Here's what the OC code should look like:
ai.iAutoSubHeaderLines = 0;
ai.iSubHeaderLines = 4;
ai.nLongNames = ai.iHeaderLines;
ai.nUnits = ai.iHeaderLines + 1;
ai.iMaxLabels = 1; // Limits Comments to one line
ai.nNumUserParams = 1;
ai.nFirstUserParams = ai.iHeaderLines + 3;

The idea of a range of lines for comments and parameters is clearer in the XF:
impasc fname:="D:\TEST.DAT"
options.hdr.LNames:=1
options.hdr.Units:=2
options.hdr.CommsFrom:=3
options.hdr.CommsTo:=3
options.hdr.ParamsFrom:=4
options.hdr.ParamsTo:=4;

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