Author |
Topic  |
|
MalBru
Germany
Posts |
Posted - 11/20/2009 : 04:50:40 AM
|
Hi folks,
I'm looking for a smart way to import special Data: aT 196062396,195896366,195784816 bT 196060819,195065029,195593139 cT 195792403,195835786,195704117 dT 196023937,195226131,195378983 aT 196062396,195896369,195784818 bT 196060820,195065030,195593144 cT 195792401,195835786,195704119 dT 196023937,195226132,195378985
aT, bT, cT, dT are the addresses of the modules, the numbers are frequencies. The output should be a 12 times X worksheet:
196062396,195896366,195784816,196060819,195065029,195593139,195792403,195835786,195704117,196023937,195226131,195378983 196062396,195896369,195784818,196060820,195065030,195593144,195792401,195835786,195704119,196023937,195226132,195378985
Is there a way that Origin can "read" those Data?
Thank You,
Malte
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8 SR0 v8.0725 Operating System: Windows XP |
|
larry_lan
China
Posts |
Posted - 11/23/2009 : 12:00:42 AM
|
Hi:
There is no directly way to do that. You need to do partial import (skip 1 row while import 1 row) and then reorganize the data by script. For example, run the script after imported data by Import Wizard.
Or, you can run the following script directly, just change the fname$ value.
newbook result:=sb$;
impASC fname:="C:\Documents and Settings\lanyijie\Desktop\sample.dat" options.Hdr.MainHdrLns:=1.
options.Hdr.AutoSubHdr:=0 options.Names.FNameToSht:=0 options.Names.FNameToBk:=0
options.Names.FNameToBkComm:=0 options.PartImp.Partial:=1 options.PartImp.SkipRows:=1;
range rs = [sb$]sheet1!;
newbook result:=tb$;
win -o %(tb$) {
wks.ncols = 12;
for (int ii = 1; ii <= rs.maxrows/4; ii++)
{
col(1)[ii] = %(%(sb$), 1, (ii*4-3));
col(2)[ii] = %(%(sb$), 2, (ii*4-3));
col(3)[ii] = %(%(sb$), 3, (ii*4-3));
col(4)[ii] = %(%(sb$), 1, (ii*4-2));
col(5)[ii] = %(%(sb$), 2, (ii*4-2));
col(6)[ii] = %(%(sb$), 3, (ii*4-2));
col(7)[ii] = %(%(sb$), 1, (ii*4-1));
col(8)[ii] = %(%(sb$), 2, (ii*4-1));
col(9)[ii] = %(%(sb$), 3, (ii*4-1));
col(10)[ii] = %(%(sb$), 1, (ii*4));
col(11)[ii] = %(%(sb$), 2, (ii*4));
col(12)[ii] = %(%(sb$), 3, (ii*4));
}
} Larry |
Edited by - larry_lan on 11/23/2009 12:02:44 AM |
 |
|
MalBru
Germany
Posts |
Posted - 11/23/2009 : 07:28:17 AM
|
Dear Larry,
thank you for the answer. The script above doesn't work right, origin cant read the file. I think I have to specify the delimiter but adding "Options.FileStruct.Delimiter:=1" to your script doesn't work.
With your explanation I was finally able to import the data and save the Importfilter. Now I'm working on the reorganizing script based on your import&reorganize script.
quote: range rs = [Book1]sheet1!; newbook result:=tb$; win -o %(tb$) { wks.ncols = 12; for (int ii = 1; ii <= rs.maxrows/4; ii++) { col(1)[ii] = %([Book1]sheet1!, 1, (ii*4-3)); col(2)[ii] = %([Book1]sheet1!, 2, (ii*4-3)); col(3)[ii] = %([Book1]sheet1!, 3, (ii*4-3)); col(4)[ii] = %([Book1]sheet1!, 1, (ii*4-2)); col(5)[ii] = %([Book1]sheet1!, 2, (ii*4-2)); col(6)[ii] = %([Book1]sheet1!, 3, (ii*4-2)); col(7)[ii] = %([Book1]sheet1!, 1, (ii*4-1)); col(8)[ii] = %([Book1]sheet1!, 2, (ii*4-1)); col(9)[ii] = %([Book1]sheet1!, 3, (ii*4-1)); col(10)[ii] = %([Book1]sheet1!, 1, (ii*4)); col(11)[ii] = %([Book1]sheet1!, 2, (ii*4)); col(12)[ii] = %([Book1]sheet1!, 3, (ii*4)); } }
This code works quite well.
The import filter only works on my test-file (http://www.uni-bonn.de/~brutschy/origin/test.txt) the file I want to import is mutch bigger (http://www.uni-bonn.de/~brutschy/origin/real.txt) and Origin says: quote: File ... does not consist of columns of ASCII data.
The files are exact the same except for the row numbers, I think...
Here is my filter file: http://www.uni-bonn.de/~brutschy/origin/Partial.oif
Regards,
Malte |
Edited by - MalBru on 11/23/2009 09:38:45 AM |
 |
|
MalBru
Germany
Posts |
Posted - 11/23/2009 : 10:22:56 AM
|
Ok I played with the test files and found out, that origin only produces this error when processing files with more than 51 rows?!
Strange....
Malte |
Edited by - MalBru on 11/23/2009 10:47:41 AM |
 |
|
larry_lan
China
Posts |
Posted - 11/24/2009 : 04:13:37 AM
|
Hi:
Yes, you are right. We do have some restriction on 50 rows when the program cannot find a "valid pattern" from you data. So now, you have to use Import Wizard to import your data (impasc doesn't work now). Some key settings as below:
1. Specify the delimiters and do set the Number of Columns:

2. Partial Import Settings:

3. Make a filter and check the Advance options, then Next:

4. Run script after import

The script can be something like:
string sb$ = %H;
range rs = [sb$]sheet1!;
newbook result:=tb$;
win -o %(tb$) {
wks.ncols = 12;
for (int ii = 1; ii <= rs.maxrows/4; ii++)
{
col(1)[ii] = %(%(sb$), 1, (ii*4-3));
col(2)[ii] = %(%(sb$), 2, (ii*4-3));
col(3)[ii] = %(%(sb$), 3, (ii*4-3));
col(4)[ii] = %(%(sb$), 1, (ii*4-2));
col(5)[ii] = %(%(sb$), 2, (ii*4-2));
col(6)[ii] = %(%(sb$), 3, (ii*4-2));
col(7)[ii] = %(%(sb$), 1, (ii*4-1));
col(8)[ii] = %(%(sb$), 2, (ii*4-1));
col(9)[ii] = %(%(sb$), 3, (ii*4-1));
col(10)[ii] = %(%(sb$), 1, (ii*4));
col(11)[ii] = %(%(sb$), 2, (ii*4));
col(12)[ii] = %(%(sb$), 3, (ii*4));
}
} Thanks Larry |
Edited by - larry_lan on 11/24/2009 04:14:38 AM |
 |
|
MalBru
Germany
Posts |
Posted - 11/24/2009 : 05:15:53 AM
|
Thanks man! You're awsome!
But I'm afraid that still doesn't work on files with more than 51 rows.
I've tried to replace all bT,cT,dT and eT with e.g. XX to build an easier pattern but still nothing 
Sorry to bother you with that whole thing for so long time 
Malte |
 |
|
larry_lan
China
Posts |
Posted - 11/24/2009 : 05:32:47 AM
|
I have tested on your full data and it should works for thousands of rows. It's weird. Maybe you can send us your filter and we can have a look?
The filter should be located in the "\Filter" folder of your Origin User File Folder.
Thanks Larry |
Edited by - larry_lan on 11/24/2009 05:34:58 AM |
 |
|
MalBru
Germany
Posts |
Posted - 11/24/2009 : 08:22:38 AM
|
Ok I've sent it. |
 |
|
MalBru
Germany
Posts |
Posted - 11/24/2009 : 09:30:15 AM
|
Hi,
I think I found the cause of the problem: Origin 8.0 I installed an Origin 8.1 Demo and it works with the setting you recommended.
Malte |
 |
|
larry_lan
China
Posts |
Posted - 11/26/2009 : 04:04:39 AM
|
Hi Malte:
Sorry that I didn't test it in 80 intensively. Yes, you are right, the import works in 8.1 only. So for 8.0, you have to write some Origin C code to handle this kind of files. Here is the detail instruction:
1), Create the C file for import source data. This C file only do partial import, that is, skip the rows like dT, aT, etc.
Open the Code Builder from menu item View: Code Builder. And create a new Origin C file, for example, we can name it TestImport.c. You can copy the following code to the new C file and save it.
#include <Origin.h>
void MyImport(string strFileName)
{
Worksheet wks = Project.ActiveLayer();
ASCIMP ai;
if(wks)
{
wks.GetASCIMP(ai);
ai.iRenameWks = 0;
ai.iRenameCols = 0;
ai.iLabels = 0;
ai.iTestLines = 0;
ai.iRenameWks = 0;
ai.iRenameCols = 0;
ai.iHeaderLines = 0;
ai.iSubHeaderLines = 0;
ai.iAutoSubHeaderLines = 0;
ai.iLabels = 0;
ai.iDelimited = 1;
ai.iDelimiter = ASCIMP_DELIM_COMMA;
ai.iPartial = 1;
ai.iSkipRows = 1;
ai.iReadRows = 1;
ai.iNumColumns = 3;
bool ret = wks.ImportASCII(strFileName, ai);
}
}
int ImportMyFile(Layer &lyTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
{
if ( trFilter.Type.nVal != FILTER_TYPE_USERDEFINED ) return 1;
file fIn;
if( fIn.Open(lpcszFile, file::modeRead | file::shareDenyWrite) == FALSE ) return 1;
fIn.Close();
string strName = GetFullPath(lpcszFile);
MyImport(strName);
return 0;
} Then compile (Click Tools: Build in code builder) and save this file. It will be saved in your User File Folder.
2). Import the file by Origin C routine.
Open Import Wizard, select the file and make sure the Data Type is User Defined

Navigate to the User Defined Filters page, and select the C file and import function. The Origin C Source File should be found in your User File Folder, and the Origin C Function is the import function in TestImport.c:

This C File only import data, we can use script to reorganize data after imported. You can also use Origin C to reorganize data directly, please read the Origin C Programming Help for more information.
Again, we will save this filter:

And then copy+past the script in my last post:

Click Finish to import data.
I hope it should work this time. 
Thanks Larry OriginLab Technical Services |
 |
|
MalBru
Germany
Posts |
Posted - 11/26/2009 : 05:03:41 AM
|
Yes! It works!! Thank you very mutch!
Malte |
 |
|
|
Topic  |
|
|
|