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

geovel

Greece
Posts

Posted - 06/12/2005 :  4:24:42 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

easwar

USA
1965 Posts

Posted - 06/12/2005 :  9:46:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

geovel

Greece
Posts

Posted - 06/13/2005 :  06:27:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Easwar . It works like a charm! I really appreciate the help.

George
Go to Top of Page

geovel

Greece
Posts

Posted - 06/13/2005 :  07:59:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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;
}
Go to Top of Page

easwar

USA
1965 Posts

Posted - 06/13/2005 :  9:04:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

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