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
 Origin Forum
 skipping the comments
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cnalaka

USA
Posts

Posted - 06/15/2005 :  5:41:05 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5 student version
Operating System:windows XP
I have bunch of data files. Each contains 3 coloum data set. In the begining of each data file there are not fixed number of commets lines. Each of theses lines starts with '#'. Origin data sheet is not capble of understanding this. I am a new bee to this lab talk. Can some one tell me how to omit this comments and make 3 coloum data set.
Also I don't want to change my data files. as you guess the comments have some meaning

Thank you in advance,
Nalaka.

Mike Buess

USA
3037 Posts

Posted - 06/15/2005 :  9:44:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Nalaka,

First, there's no need to cross-post. These forums are small enough that your topic will be noticed wherever you post it.

Second, how are you importing? Import Wizard, ASCII Options, LabTalk script or what? Each method has its own strengths and weaknesses. One could construct a LabTalk or Origin C function to do what you want but the old ASCII Options method should handle the files you describe quite easily.

1. Open a new worksheet.
2. Select File > Import > ASCII Options.
3. Specify the column delimiter but leave all other options in the File Structure section unchecked.
4. File Header section:
Skip main header... 0 lines
Select "Auto determine to select more header lines"
Max lines to store in column labels: doesn't matter
5. # of Columns = 3
6. Import into worksheet as: New Data
7. Other Options: Deselect everything except "Rename Worksheet to Data File Name" (optional)
8. Close Other Options and click the Update Options button.
9. Select File > Save Template As... and select a name.
10. File > Import > Simple Single ASCII.
11. Select one of your files and check if the start of the data was determined correctly. The file header is saved as the string variable %Z and you can create a text label on the worksheet with the header info with this LabTalk command...

label -s -sa %Z;

If that works just create a worksheet from your template whenever you want to import a file. If it doesn't work off the bat you'll have to fiddle with the ASCII Options. (Remember to Update Options and Save Template with each attempt.) Should work first time.

...If you prefer a programmatic approach you can try the Origin C method suggested in a previous topic

http://www.originlab.com/forum/topic.asp?TOPIC_ID=4029

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/15/2005 9:47:06 PM

Edited by - Mike Buess on 06/16/2005 10:09:34 AM
Go to Top of Page

cnalaka

USA
Posts

Posted - 06/16/2005 :  8:59:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike
Sorry about the cross-post. Yes the first method did work. But I would like to try the other programming method too. How dod i inwlk the program. As I said I am a new bee.

Thank you

Nalaka.

Edited by - cnalaka on 06/16/2005 9:02:41 PM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 06/16/2005 :  11:22:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Nalaka,

In the topic I cited earlier the header length was determined by locating the string "[Data]". You need to find the first line that does not begin with the character '#'. It took a few simple modifications to the earlier code to make it work for you. Refer to the Programming Guide for instructions on how to use the code below.

Help > Programming > Code Builder User's Guide > Working with Files and Origin C Compiler

// code starts here
void test_ascimp()
{
int iNumSelFiles;
string strPath,strHeader;
StringArray saFiletypes,saFilePaths;
saFiletypes.SetSize( 2 );
saFiletypes[0]="[data (*.dat)] *.dat";
saFiletypes[1]="[all (*.*)] *.*";
iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes );

for (int i = 0; i < iNumSelFiles; i++)
{
// Find where header stops and retrieve its text
int nHdrLines = get_header(saFilePaths[i], '#', strHeader);
if( nHdrLines < 1)
{
printf("%d\m", nHdrLines);
out_str("Failed to find marker in file");
continue;
}

// Create new worksheet
WorksheetPage wpg;
wpg.Create("Origin");
Worksheet wks = wpg.Layers(0);
// 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();
}
else
{
// create text label from header string
LT_execute("label -s -sa " + strHeader);
}
}
}
//--------------------------------------------------------------------------------------
// Function to read file and look for a line that does not begin with the marker
// Note that the search for marker is case sensitive
static int get_header(string strFile, char strMarker, string& strHeader)
{
stdioFile ff;
bool bRet = ff.Open(strFile, file::modeRead);
if( !bRet ) return -1;

int nMarkerLine = -1;
string strTemp;
int iLine;
while( ff.ReadString(strTemp) )
{
if( strTemp.Find(strMarker) != 0 )
{
nMarkerLine = iLine;
break;
}
iLine++;
// add line to header string
strHeader.Format("%s\n%s", strHeader, strTemp);
}
ff.Close();
return nMarkerLine;
}


Mike Buess
Origin WebRing Member
Go to Top of Page

cnalaka

USA
Posts

Posted - 06/18/2005 :  1:46:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,
I tried to go through the help. I was able to save and complie the code. But I couldn't find a way to invoke the program. How do I do it.
Thanks for your help,

Nalaka.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 06/18/2005 :  2:04:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Nalaka,

Just type the function name in the script window and hit Enter...

test_ascimp<Enter>

...You can also run the function from a toolbar button. Easiest is the Custom Routine button.

1. Open Custom.ogs (probably in Origin's program folder) in CodeBuilder or Notepad.
2. Replace everything under the [Main] section with the function name and save. Should look like this...

[Main]
test_ascimp;

3. To execute, click the Custom Routine button on the standard toolbar.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/18/2005 2:11:40 PM

Edited by - Mike Buess on 06/18/2005 4:35:52 PM
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