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