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
 Origin Forum
 String search in file import

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
Pythe Posted - 07/18/2005 : 08:23:20 AM
Hi,

I want to import multiple ascii files of the format:

useless_data (variable number of rows)
useful_data (starts with fixed string, variable amount of rows)
useless_data (starts with fixed string)

Is it possible to use a script that only imports the useful_data and puts the filename in the column label? Each file contains multiple columns and I want to put all the files into one worksheet. I have no experience whatsoever with LabTalk/OriginC programming (but willing to learn). I would really appreciate it if someone could show me how to do this!

Pythe
3   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 07/18/2005 : 11:52:02 AM
Hi,

Although ASCIMP (which has been around since many versions) and Import Wizard Filter (introduced in 7.5) have many things in common and share internal code, from user point of view, one has to use one or the other and not possible to combine both.

So in your case you already have an import filter created with Import Wizard that has other things taken care of such as running script at end of import to do some tasks etc.

So you may want to work with the filter file alone and not the ASCIMP structure as saved in the worskheet.

You can use code such as below which reads the import filter .OIF file and then changes properties and then calls other Origin C functions to import the file.

The function ImportFile() has multiple prototypes which are declared in FileImport.h and so this header file needs to be added to your OC function code. In addition to that files such as FileImport.c and some other files related to Import Wizard need to be part of your workspace before you can compile and run the code below.

The easiest way to ensure that your workspace is set up for compiling the following code is:
1> Run the import wizard once from the GUI which loads and compiles all necessary files. Then as long as you do not change your workspace the necessary files will be there
OR
2> At the beginning of an Origin session (programmatically) use the run.loadoc() script command to load and compile the import wizard workspace, with command such as: (your path could be different)
run.loadoc("C:\Program Files\OriginLab\OriginPro75SR5\OriginC\OriginLab\ImportWiz.ocw");

Once you have done the above, you can then create a file with the code pasted bwlow and compile and link and call the function.

Easwar
OriginLab


#include <Origin.h>

// The following include file has protype of ImportFile() function
#include <..\OriginLab\FileImport.h>

void custom_import()
{
// Point to data file and to filer XML file
string strFile = "c:\\temp\\myfile.dat";
string strFilter = "c:\\temp\\myfilter.oif";

// Load filter file into a tree and examine current values
Tree trFilter;
trFilter.Load(strFilter);
printf("Num Header Lines: %d\n", trFilter.ASCIMP.iHeaderLines.nVal);
printf("Num SubHeader Lines: %d\n", trFilter.ASCIMP.iSubHeaderLines.nVal);
// or dump entire tree to script window
out_tree(trFilter);

// Change current values in tree
// Note: call your custom function here that examines file to determine
// number of header lines etc
trFilter.ASCIMP.iHeaderLines.nVal = 20;
trFilter.ASCIMP.iSubHeaderLines.nVal = 0;

// Create a new worksheet page (or point to one that exsits)
WorksheetPage wpg;

// Call import function passing tree for filter, and string for filename
int iret = ImportFile(wpg, trFilter, strFile, 0);
if( iret != 0 )
printf("Import call returned error: %d\n", iret);
}




Pythe Posted - 07/18/2005 : 10:52:58 AM
Hi,

Thanks for your help. I think I get the idea: you get the ascii import structure from the current worksheet and alter some properties. I got it working, but I can't get the filename in the column label. Is it possible to let the script ask for an import filter to use instead of the current ascii import options from the worksheet? I have got a filter to do the right stuff and a script that puts the filename in the column label.

Thanks for your help!

Pythe

(If it helps, the file structure is like this:
I only want the part from "Best Fit" to "Fitted Decay", but leaving the last part out is not absolutely necessary)
Header
....
0.0122 0 0.0122 0 0.0122 0
0.0244 0 0.0244 0 0.0244 0
0.0366 0 0.0366 0 0.0366 0
... (this goes on for a while)

Best Fit Parameters: (this is the part I want)
A1 = 1459.8 + 16 - 16 Cnts
t1 = 4.071 + 0.031 - 0.031 ns
A2 = 896 + 53.3 - 53.3 Cnts
t2 = 0.83 + 0.058 - 0.058 ns
Bkgr. Dec = -0.4 + 0.5 - 0.5 Cnts

Fitted Decay and Exponential Components:
Time[ns] Amp(t0) Amp(t1) sum
0 1459.756 895.968 2355.7
0.0371 1446.511 856.787 2303.3
0.0742 1433.386 819.320 2252.7
... (goes on for a while again)
easwar Posted - 07/18/2005 : 09:44:56 AM
Hi Pythe.

You could start by looking at the following posts for example:
http://www.originlab.com/forum/topic.asp?TOPIC_ID=4029
http://www.originlab.com/forum/topic.asp?TOPIC_ID=4043

These post make use of the ASCIMP structure which tells Origin how to interpret your file. There is a property to set the number of header lines which you can programmatically determine and set, thus skipping them from import.

There is also a property to determine what should be done when non-numeric data is encountered. If you set that to "terminate import", then that should take care of the trailing lines in the file. Try this and post if you need more help. Would be beneficial to post the first, some lines from the middle, and the last part of one of your files if you need more help.

Easwar
OriginLab


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