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
 help importing multiple files

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
geovel Posted - 06/12/2005 : 4:24:42 PM
Hello,

I need to import several files into origin. These files have around 50 lines of comments and then 8 columns of data. How can I do this with origin C? The problem is that both the number of comment lines as well as the number of data lines is not the same in each file. Apart from this the files look alike. I tried to use the importASCII() using different properties of ascimp but I did not succeeded. I guess what I need is to search inside each file after using the getmultiopenbox() and find a specific word (Let's say DATA) and then import the data from this point on in 8 columns.

thank you in advance

4   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 06/13/2005 : 9:04:06 PM
Hi George,

What version of Origin are you using?
I tried your code with the GetMultiOpenBox and it worked fine for me with more than 3 files. Where are your files located? Can you place them in some simple folder location such as c:\temp and try?

Easwar
OriginLab

geovel Posted - 06/13/2005 : 07:59:28 AM
Hi Easwar,

The code you wrote it works very well. Nevertheless I modified it a little bacause I want to import multiple files. So I put a GetMultiOpenBox() and then I used a for loop to do the same procedure for all files (see the code that follows). The problem is that it works when I select up to 3 files but it doesn't work for more than 3 files. If I use GetOpenBox() then it works. Can you help me on this?

void test_ascimp()
{

int iNumSelFiles;
string strPath;
StringArray saFiletypes, saFilePaths;
saFiletypes.SetSize( 2 );
saFiletypes[0]="[data (*.data)] *.data";
saFiletypes[1]="[all (*.*)] *.*";
iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes );

for (int i = 0; i < iNumSelFiles; i++)
{
// Create new worksheet
WorksheetPage wpg;
wpg.Create("Origin");
Worksheet wks = wpg.Layers(0);

// Find where header stops
int nHdrLines = find_header_marker(saFilePaths[i], "[DATA]");
if( nHdrLines < 1)
{
printf("%d\m", nHdrLines);
out_str("Failed to find marker in file");
return;
}

// Get current ascimp settings from worksheet
ASCIMP ascimp;
wks.GetASCIMP(ascimp);
// Set header lines
ascimp.iHeaderLines = nHdrLines;

// Import file
int iRet = wks.ImportASCII(saFilePaths[i], ascimp);
if( iRet != 0 )
{
printf("Import failed with error: %d\n", iRet);
wpg.Destroy();
}
}
}
//--------------------------------------------------------------------------------------
// Function to read file and look for marker
// Note that the search for marker is case sensitive
static int find_header_marker(string strFile, string strMarker)
{
stdioFile ff;
bool bRet = ff.Open(strFile, file::modeRead);
if( !bRet ) return -1;

int nMarkerLine = -2;
string strTemp;
int iLine = 1;
while( ff.ReadString(strTemp) )
{
if( strTemp.Find(strMarker) != -1 )
{
nMarkerLine = iLine;
break;
}
iLine++;
}
ff.Close();
return nMarkerLine;
}
geovel Posted - 06/13/2005 : 06:27:12 AM
Thank you Easwar . It works like a charm! I really appreciate the help.

George
easwar Posted - 06/12/2005 : 9:46:31 PM
Hi,

You can try using code such as posted below where there is a function to first read thru file to find the line that marks end of header lines, and then that line number is used to set the ascimp structure header lines property.

Easwar
OriginLab

P.S. This was tested in Origin 7.5 with the following sample data, where the data columns are tab separated:

-------- data file ---------------

some header lines
again more header
some header lines
again more header
some header lines
again more header
some header lines
again more header
some header lines
again more header
some header lines
again more header
some header lines
again more header
some header lines
again more header
some header lines
again more header
[DATA]
Alpha Beta Gamma Delta
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7
8 8 8 8
9 9 9 9
10 10 10 10


----------------- code -------------


void test_ascimp()
{
// Create new worksheet
WorksheetPage wpg;
wpg.Create("Origin");
Worksheet wks = wpg.Layers(0);

// Point to file
string strFile = "c:\\temp\\myfile.dat";

// Find where header stops
int nHdrLines = find_header_marker(strFile, "[DATA]");
if( nHdrLines < 1)
{
printf("%d\m", nHdrLines);
out_str("Failed to find marker in file");
return;
}

// Get current ascimp settings from worksheet
ASCIMP ascimp;
wks.GetASCIMP(ascimp);

// Set header lines
ascimp.iHeaderLines = nHdrLines;

// Import file
int iRet = wks.ImportASCII(strFile, ascimp);
if( iRet != 0 )
{
printf("Import failed with error: %d\n", iRet);
wpg.Destroy();
}
}

// Function to read file and look for marker
// Note that the search for marker is case sensitive
static int find_header_marker(string strFile, string strMarker)
{
stdioFile ff;
bool bRet = ff.Open(strFile, file::modeRead);
if( !bRet ) return -1;

int nMarkerLine = -2;
string strTemp;
int iLine = 1;
while( ff.ReadString(strTemp) )
{
if( strTemp.Find(strMarker) != -1 )
{
nMarkerLine = iLine;
break;
}
iLine++;
}
ff.Close();
return nMarkerLine;
}





Edited by - easwar on 06/12/2005 9:47:31 PM

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