Author |
Topic  |
|
winflowers
USA
34 Posts |
Posted - 02/01/2006 : 09:40:43 AM
|
Origin Version (Select Help-->About Origin): 7.5 SR4 Operating System: WinXP SP2
I am trying to use OriginC to import my data by using a template. The template works perfectly when I use it by "import ASCII" or "import Multiple ASCII", but something strange happens in OriginC.
Here is part of my data:
IVL-Roboter (V 3.22) File created at : 16:13:15 27/01/06 Wafer type : Spezial Integration time : 1333,64581320305 ms Accumulations : 1 Current through OLED : 2,08187483859294 mA max. ADC counts : 9940 Luminance : 998,016146383981 cd/m² CIE x : 0,175 CIE y : 0,305 CIE z : 0,52 CRI : 0 CCT : 38245,917 K ------------------------------------------------ Wavelength/nm W/(cm²*sr*nm) 380 -3,18148001884607E-10 381 1,28978358607071E-08 382 9,77757721192256E-09 383 7,75515611536902E-09 384 6,37508324741514E-09
I would like to skip first 15 lines as header. The following is the ASCIMP of my template:
iDelimited = 1 iDelimiter = 2 cChar = 0 szFixedWidth = iHeaderLines = 15 iSubHeaderLines = 0 iAutoSubHeaderLines = 0 iAutoColTypes = 0 iTestLines = 3 iMode = 0 iNumColumns = 2 iPartial = 0 iPartialC1 = 0 iPartialC2 = 1 iPartialR1 = 0 iPartialR2 = -1 iRenameWks = 1 iApplyRange = 2 iRenameCols = 0 iLabels = 0 iMaxLabels = 0 iLeadingZeroes = 0 iNonnumeric = 1 iMaxTestLines = 50 iSkipRows = 0 iReadRows = 0 szDateFormat = iLabelSkipChars = 0
I use the following OriginC code to test the importing:
void test() {
string strFile = GetOpenBox("*.els"); if( strFile.IsEmpty() ) { out_str("No file was selected!"); return; }
Worksheet wks; wks.Create("EL.OTW");
BOOL bRet = wks.ImportASCII(strFile); if( !bRet ) { out_str("Failed to import file!"); // Destroy newly created worksheet wks.Destroy(); return; } }
What I got in the worksheet is like this with 4 columns:
CIE -- 0 0,178 CIE -- 0 0,275 CIE -- 0 0,547 CRI 0 0 CCT 0 0 K ------------------------------------------------ -- Wavelength/nm -- 380 3,9975E-9 381 7,44526E-9 382 3,22142E-9 383 1,38515E-8 ......
With debug, I noticed that the correct template was used at least at this step "wks.Create("EL.OTW");" then... I don't know what's wrong with it. It's quite strange to me.
I will appreciate any help from you!
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/01/2006 : 10:53:14 AM
|
I don't think ImportASCII reads the ASCII Options of template. Try setting them yourself as shown below. Apparently you've already located the ASCIMP properties in OC_Types.h and can specify more options if necessary.void test() { string strFile = GetOpenBox("*.els"); if( strFile.IsEmpty() ) { out_str("No file was selected!"); return; } ASCIMP ascimp; if( AscImpReadFileStruct(strFile,&ascimp) ) { out_str("Unable to determine file structure!"); return; } ascimp.iDelimited = 1; ascimp.iDelimiter = ASCIMP_DELIM_TAB; ascimp.iMode = ASCIMP_MODE_REPLACE_DATA; ascimp.iHeaderLines = 15; ascimp.iRenameWks = 1; ascimp.iRenameCols = 0; ascimp.iLabels = 0; ascimp.iNumColumns = 2; Worksheet wks; wks.Create("EL.OTW"); BOOL bRet = wks.ImportASCII(strFile, ascimp); if( !bRet ) { out_str("Failed to import file!"); // Destroy newly created worksheet wks.Destroy(); return; } }
Mike Buess Origin WebRing Member |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 02/01/2006 : 12:47:53 PM
|
Turns out there is a method called GetASCIMP for reading ASCII options from wks. I don't believe it has been documented in the programming guide yet but it's discussed in this forum topic... http://www.originlab.com/forum/topic.asp?TOPIC_ID=4029
So you can also try this...void test() { string strFile = GetOpenBox("*.els"); if( strFile.IsEmpty() ) { out_str("No file was selected!"); return; } Worksheet wks; wks.Create("EL.OTW"); ASCIMP ascimp; wks.GetASCIMP(ascimp); // you can change any settings here if necessary BOOL bRet = wks.ImportASCII(strFile, ascimp); if( !bRet ) { out_str("Failed to import file!"); // Destroy newly created worksheet wks.Destroy(); return; } }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 02/01/2006 1:07:06 PM |
 |
|
winflowers
USA
34 Posts |
Posted - 02/03/2006 : 03:05:46 AM
|
This is exactly what I was looking for! I also found it at "Origin C Programming Examples" section on OriginLab website. |
 |
|
Leo.C
Brazil
Posts |
Posted - 02/09/2006 : 4:23:21 PM
|
Hi
I just found Mike´s suggestion in how to implement the multiple ascii import code. My point is that mine files (csv) use the ";" separator, like in the following example:
; 0.500000 ; 0.180406 ; -0.000682 ; 0.001922 ; -0.000279 ; -0.006552 ; 0.600000 ; 0.180406 ; -0.000444 ; 0.002252 ; -0.000303 ; -0.006761 ; 0.700000 ; 0.180406 ; -0.000133 ; 0.002557 ; -0.000293 ; -0.006993 ; 0.800000 ; 0.180406 ; 0.000239 ; 0.002835 ; -0.000245 ; -0.007243
I changed the basic code to look like this:
// Get current ascimp settings from worksheet ASCIMP ascimp; wks.GetASCIMP(ascimp); // Set header lines ascimp.iHeaderLines = 4; ascimp.iDelimited = 0; ascimp.iDelimiter = 4; ascimp.iCharacter$ = ";"; ascimp.iLabels = 0;
my problem is that Origin won´t recognize ascimp.iCharacter$ as a valid variable. I come through the following error:
C:\Program Files\OriginLab\OriginPro75\Samples\Programming\Automation\Leo.c(34) :Error, data member not found:iCharacter$
What is going on and how could I import files with those unusual separators?
thanks very much in advance!
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 02/09/2006 : 5:15:36 PM
|
Hi Leo,
Use ascimp.cChar = ';' instead of ascimp.iCharacter$ = ";". You'll also need ascimp.iDelimited = 1 or Origin will expect a fixed-width format. See OC_types.h for a complete list of ASCIMP tags.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 02/09/2006 5:28:35 PM |
 |
|
Leo.C
Brazil
Posts |
Posted - 02/10/2006 : 06:38:13 AM
|
Mike, thanks very much! I couldn´t find any references on the ascimp command... I am new to Origin programming and still getting used to it.
by the way, you are also right about the delimit :) |
 |
|
|
Topic  |
|