T O P I C R E V I E W |
klunz |
Posted - 10/07/2008 : 06:28:30 AM A while ago I wrote a program in Origin 7.5, which included the following part to import data from a ascii-file:
string strFile = GetOpenBox("*.*", NULL, "", "Bitte Datensatz auswählen");
if( strFile.IsEmpty() )
{
out_str("Bitte einen Datensatz auswählen!");
return;
}
Worksheet tabelleDaten("Daten"); // Erstellen der Daten-Tabelle
tabelleDaten.Create("Origin.OTW");
tabelleDaten.GetPage().Rename("Daten");
WorksheetPage PageDaten = Project.Pages();
PageDaten.Label = (fileName);
PageDaten.TitleShow = WIN_TITLE_SHOW_BOTH;
BOOL bRet = tabelleDaten.ImportASCII(strFile); // Kontrolle ob Datei importiert werden konnte
if( !bRet )
{
out_str("Datei konnte nicht importiert werden!");
tabelleDaten.Destroy(); // Wenn nicht -> zerstören der Tabelle
return;
}
So far, the highlited part worked fine to import the Ascii-files used by the people here, which almost allways have 1 or 2 Header-Lines and then consist of two columns of data. The tricky thing is, that as decimal-point some here use Points and some use Commas.
This never was a Problem with Origin 7.5, and Commas are still working fine, however, when I run this in Origin8, with a file that uses Points as Decimal-Point, I get completly messed up results. When using the importwizzard directly from Origin all is working just fine.
I played around with ASCIMP a bit now, but I cant seem to find a setting or anything to fix this simple problem :/
Sorry about the bad readability, but I guess it helps understand the problem if I attach an example:
This is the File thats to be imported:
time Y
0.000000 0.000000
0.008333 -81.000000
0.016667 -100.000000
0.025000 -116.000000
0.033333 -130.000000
0.041667 -141.000000
0.050000 -151.000000
0.058333 -160.000000
0.066667 -167.000000
0.075000 -164.000000
0.083333 -152.000000
0.091667 -137.000000
0.100000 -126.000000
0.108333 -120.000000
0.116667 -113.000000
0.125000 -102.000000
0.133333 -92.000000
0.141667 -81.000000
0.150000 -66.000000
0.158333 -47.000000
0.166667 -26.000000
0.175000 -5.000000
0.183333 17.000000
0.191667 37.000000
0.200000 52.000000
0.208333 61.000000
0.216667 61.000000
0.225000 49.000000
0.233333 24.000000
0.241667 -9.000000
0.250000 -34.000000
0.258333 -47.000000
0.266667 -45.000000
0.275000 -25.000000
0.283333 11.000000
0.291667 55.000000
0.300000 99.000000
0.308333 137.000000
0.316667 163.000000
0.325000 176.000000
0.333333 177.000000
0.341667 166.000000
0.350000 136.000000
0.358333 89.000000
0.366667 39.000000
0.375000 -1.000000
0.383333 -28.000000
0.391667 -39.000000
0.400000 -36.000000
0.408333 -22.000000
0.416667 -3.000000
0.425000 20.000000
0.433333 44.000000
0.441667 65.000000
0.450000 84.000000
0.458333 104.000000
0.466667 122.000000
0.475000 141.000000
0.483333 163.000000
0.491667 185.000000
0.500000 205.000000
0.508333 220.000000
0.516667 229.000000
0.525000 236.000000
0.533333 244.000000
0.541667 258.000000
0.550000 271.000000
0.558333 282.000000
0.566667 285.000000
0.575000 284.000000
0.583333 286.000000
0.591667 293.000000
0.600000 302.000000
0.608333 315.000000
0.616667 328.000000
0.625000 338.000000
0.633333 342.000000
0.641667 343.000000
0.650000 337.000000
0.658333 324.000000
0.666667 307.000000
0.675000 297.000000
0.683333 302.000000
0.691667 325.000000
0.700000 360.000000
0.708333 396.000000
0.716667 421.000000
0.725000 433.000000
0.733333 441.000000
0.741667 455.000000
0.750000 476.000000
0.758333 498.000000
0.766667 519.000000
0.775000 538.000000
0.783333 552.000000
0.791667 561.000000
0.800000 564.000000
0.808333 559.000000
0.816667 545.000000
0.825000 521.000000
0.833333 495.000000
0.841667 471.000000
0.850000 451.000000
0.858333 437.000000
0.866667 433.000000
0.875000 445.000000
0.883333 479.000000
0.891667 528.000000
0.900000 586.000000
0.908333 646.000000
0.916667 702.000000
0.925000 749.000000
0.933333 788.000000
0.941667 820.000000
0.950000 844.000000
0.958333 860.000000
0.966667 873.000000
0.975000 887.000000
0.983333 904.000000
0.991667 924.000000
1.000000 943.000000
1.008333 960.000000
1.016667 973.000000
1.025000 980.000000
1.033333 975.000000
1.041667 958.000000
1.050000 931.000000
1.058333 897.000000
1.066667 856.000000
1.075000 809.000000
1.083333 754.000000
1.091667 694.000000
1.100000 642.000000
1.108333 604.000000
1.116667 580.000000
1.125000 569.000000
1.133333 561.000000
1.141667 551.000000
1.150000 538.000000
1.158333 523.000000
1.166667 510.000000
1.175000 499.000000
1.183333 486.000000
1.191667 476.000000
1.200000 471.000000
1.208333 466.000000
1.216667 454.000000
1.225000 439.000000
1.233333 429.000000
1.241667 427.000000
1.250000 435.000000
1.258333 453.000000
1.266667 477.000000
1.275000 507.000000
1.283333 537.000000
1.291667 562.000000
1.300000 583.000000
1.308333 593.000000
1.316667 596.000000
1.325000 595.000000
1.333333 595.000000
1.341667 590.000000
1.350000 584.000000
1.358333 576.000000
1.366667 565.000000
1.375000 552.000000
1.383333 540.000000
1.391667 530.000000
1.400000 522.000000
1.408333 518.000000
1.416667 516.000000
1.425000 517.000000
1.433333 523.000000
1.441667 531.000000
1.450000 540.000000
1.458333 548.000000
1.466667 555.000000
1.475000 558.000000
1.483333 554.000000
1.491667 541.000000
1.500000 517.000000
And here is the table that Origin gives me:
time excerpt.dat (Langname)
0.000000 (Units)
(Comments)
0.008333 -2700
0.016667 -3333,33333
0.025000 -3866,66667
0.033333 -4333,33333
0.041667 -4700
0.050000 -5033,33333
0.058333 -5333,33333
0.066667 -5566,66667
0.075000 -5466,66667
0.083333 -5066,66667
0.091667 -4566,66667
0.100000 -4200
0.108333 -4000
0.116667 -3766,66667
0.125000 -3400
0.133333 -3066,66667
0.141667 -2700
0.150000 -2200
0.158333 -1566,66667
0.166667 -866,66667
0.175000 -166,66667
0.183333 566,66667
0.191667 1233,33333
0.200000 1733,33333
0.208333 2033,33333
0.216667 2033,33333
0.225000 1633,33333
0.233333 800
0.241667 -300
0.250000 -1133,33333
0.258333 -1566,66667
0.266667 -1500
0.275000 -833,33333
0.283333 366,66667
0.291667 1833,33333
0.300000 3300
0.308333 4566,66667
0.316667 5433,33333
0.325000 5866,66667
0.333333 5900
0.341667 5533,33333
0.350000 4533,33333
0.358333 2966,66667
0.366667 1300
0.375000 -33,33333
0.383333 -933,33333
0.391667 -1300
0.400000 -1200
0.408333 -733,33333
0.416667 -100
0.425000 666,66667
0.433333 1466,66667
0.441667 2166,66667
0.450000 2800
0.458333 3466,66667
0.466667 4066,66667
0.475000 4700
0.483333 5433,33333
0.491667 6166,66667
0.500000 6833,33333
0.508333 7333,33333
0.516667 7633,33333
0.525000 7866,66667
0.533333 8133,33333
0.541667 8600
0.550000 9033,33333
0.558333 9400
0.566667 9500
0.575000 9466,66667
0.583333 9533,33333
0.591667 9766,66667
0.600000 10066,66667
0.608333 10500
0.616667 10933,33333
0.625000 11266,66667
0.633333 11400
0.641667 11433,33333
0.650000 11233,33333
0.658333 10800
0.666667 10233,33333
0.675000 9900
0.683333 10066,66667
0.691667 10833,33333
0.700000 12000
0.708333 13200
0.716667 14033,33333
0.725000 14433,33333
0.733333 14700
0.741667 15166,66667
0.750000 15866,66667
0.758333 16600
0.766667 17300
0.775000 17933,33333
0.783333 18400
0.791667 18700
0.800000 18800
0.808333 18633,33333
0.816667 18166,66667
0.825000 17366,66667
0.833333 16500
0.841667 15700
0.850000 15033,33333
0.858333 14566,66667
0.866667 14433,33333
0.875000 14833,33333
0.883333 15966,66667
0.891667 17600
0.900000 19533,33333
0.908333 21533,33333
0.916667 23400
0.925000 24966,66667
0.933333 26266,66667
0.941667 27333,33333
0.950000 28133,33333
0.958333 28666,66667
0.966667 29100
0.975000 29566,66667
0.983333 30133,33333
0.991667 30800
1000000 31433,33333
1,00833E6 32000
1,01667E6 32433,33333
1,025E6 32666,66667
1,03333E6 32500
1,04167E6 31933,33333
1,05E6 31033,33333
1,05833E6 29900
1,06667E6 28533,33333
1,075E6 26966,66667
1,08333E6 25133,33333
1,09167E6 23133,33333
1,1E6 21400
1,10833E6 20133,33333
1,11667E6 19333,33333
1,125E6 18966,66667
1,13333E6 18700
1,14167E6 18366,66667
1,15E6 17933,33333
1,15833E6 17433,33333
1,16667E6 17000
1,175E6 16633,33333
1,18333E6 16200
1,19167E6 15866,66667
1,2E6 15700
1,20833E6 15533,33333
1,21667E6 15133,33333
1,225E6 14633,33333
1,23333E6 14300
1,24167E6 14233,33333
1,25E6 14500
1,25833E6 15100
1,26667E6 15900
1,275E6 16900
1,28333E6 17900
1,29167E6 18733,33333
1,3E6 19433,33333
1,30833E6 19766,66667
1,31667E6 19866,66667
1,325E6 19833,33333
1,33333E6 19833,33333
1,34167E6 19666,66667
1,35E6 19466,66667
1,35833E6 19200
1,36667E6 18833,33333
1,375E6 18400
1,38333E6 18000
1,39167E6 17666,66667
1,4E6 17400
1,40833E6 17266,66667
1,41667E6 17200
1,425E6 17233,33333
1,43333E6 17433,33333
1,44167E6 17700
1,45E6 18000
1,45833E6 18266,66667
1,46667E6 18500
1,475E6 18600
1,48333E6 18466,66667
1,49167E6 18033,33333
1,5E6 17233,33333
As you can see, the jump from "0.xx" to "1.xx" contains the problem in column 1, and I have absolutly no idea whats happening to column 2....
Thanks in advance and a nice day everyone
Tobi |
5 L A T E S T R E P L I E S (Newest First) |
klunz |
Posted - 10/10/2008 : 07:25:01 AM Awsome, thank you very much, that was exactly what I was looking for. nNumSep was the missing property, I had seen it in the OC_types.h but didnt know if it was what I was looking for and if so, how to use it.
Maybe you could integrate this in the help-file? But as long as the support here in the forum is so great, its fine with me the way it is ;)
Thanks a lot again.
Tobi |
eparent |
Posted - 10/09/2008 : 11:46:35 AM quote: Originally posted by klunz
Thank you for your answer. So, what could I do know? I havent found an option to set decimal-separators at all. Comma seems to work without any problems, but how can I set my import-function to import those files with points as decimal-separators correctly? I know that its working in Origin, because the manual import does it correctly, I just dont know how to implement it in OriginC.
I read the entire OC_types.h, but while there is a lot about delimiters, there seems to be nothing about decimal-separators.
Thanks again ;)
Tobi
Hello, My previous post showed you how to use the ASCIMP nNumSep property to import your two file types. This post I want to show you how we can automate the setting of the nNumSep property by doing a simple test on the file before the import.
I wrote a new function named test_numeric_separator that will use the ReadFileLines function to read in the first 10 lines of a file. After reading the lines, the remaining code will count the periods and commas in those 10 lines. Based on the two counts the code decides if the file is American or European. This is of course a very crude test but will work for your files if they are indeed as simple as you described them. I have also included the previous function modified to call this new function.
I hope these functions and changes help you. If you have any questions about any of the code please do not hesitate to ask.
int test_numeric_separator(const char* pszFileName, int nNumTestLines = 10)
{
int nCommas = 0, nPeriods = 0;
StringArray saTestLines;
if( 0 == ReadFileLines(saTestLines, pszFileName, nNumTestLines) )
{
for( int nLine = 0; nLine < saTestLines.GetSize(); nLine++ )
{
nCommas += saTestLines[nLine].Count(',');
nPeriods += saTestLines[nLine].Count('.');
}
}
if( nCommas > nPeriods )
return NF_IS_EUROPEAN;
if( nCommas < nPeriods )
return NF_IS_AMERICAN;
return NF_IS_UNKNOWN; // can not determine file type
}
void test_ascii_import()
{
string strFile = GetOpenBox("*.*", NULL, "", "Bitte Datensatz auswählen");
if( strFile.IsEmpty() )
{
out_str("Bitte einen Datensatz auswählen!");
return;
}
Worksheet tabelleDaten("Daten"); // Erstellen der Daten-Tabelle
tabelleDaten.Create("Origin.OTW");
tabelleDaten.GetPage().Rename("Daten");
WorksheetPage PageDaten = Project.Pages();
PageDaten.Label = (strFile);
PageDaten.TitleShow = WIN_TITLE_SHOW_BOTH;
ASCIMP ai;
if( AscImpReadFileStruct(strFile, &ai) == 0 )
{
///ai.nNumSep = 1; // 1=American, 2=European
ai.nNumSep = test_numeric_separator(strFile);
}
int err = tabelleDaten.ImportASCII(strFile, ai);
if( err )
{
printf("Datei konnte nicht importiert werden!\nError == %d\n", err);
tabelleDaten.Destroy();
}
}
|
eparent |
Posted - 10/09/2008 : 10:38:28 AM quote: Originally posted by klunz
Thank you for your answer. So, what could I do know? I havent found an option to set decimal-separators at all. Comma seems to work without any problems, but how can I set my import-function to import those files with points as decimal-separators correctly? I know that its working in Origin, because the manual import does it correctly, I just dont know how to implement it in OriginC.
I read the entire OC_types.h, but while there is a lot about delimiters, there seems to be nothing about decimal-separators.
Thanks again ;)
Tobi
The following Origin C code will show you how to import your two file types. The code is similar to what you posted but makes some important changes. The key part is the line setting the ai.nNumSep property. This property needs to be set according to the type of file you are importing. Also notice that the ImportASCII method returns an integer error code not a boolean as your code treated it.
void test_ascii_import()
{
string strFile = GetOpenBox("*.*", NULL, "", "Bitte Datensatz auswählen");
if( strFile.IsEmpty() )
{
out_str("Bitte einen Datensatz auswählen!");
return;
}
Worksheet tabelleDaten("Daten"); // Erstellen der Daten-Tabelle
tabelleDaten.Create("Origin.OTW");
tabelleDaten.GetPage().Rename("Daten");
WorksheetPage PageDaten = Project.Pages();
PageDaten.Label = (strFile);
PageDaten.TitleShow = WIN_TITLE_SHOW_BOTH;
ASCIMP ai;
if( AscImpReadFileStruct(strFile, &ai) == 0 )
ai.nNumSep = 1; // 1=American, 2=European
int err = tabelleDaten.ImportASCII(strFile, ai);
if( err )
{
printf("Datei konnte nicht importiert werden!\nError == %d\n", err);
tabelleDaten.Destroy();
}
}
|
klunz |
Posted - 10/09/2008 : 03:18:44 AM quote: Originally posted by cpyang
We have looked and found the reason 75 can handle such cases was purely accidental, not by design. We will need to add an Auto option for decimal separator to handle the situation you described, hopefully in the next SR (SR5).
CP
Thank you for your answer. So, what could I do know? I havent found an option to set decimal-separators at all. Comma seems to work without any problems, but how can I set my import-function to import those files with points as decimal-separators correctly? I know that its working in Origin, because the manual import does it correctly, I just dont know how to implement it in OriginC.
I read the entire OC_types.h, but while there is a lot about delimiters, there seems to be nothing about decimal-separators.
Thanks again ;)
Tobi |
cpyang |
Posted - 10/08/2008 : 11:21:44 AM We have looked and found the reason 75 can handle such cases was purely accidental, not by design. We will need to add an Auto option for decimal separator to handle the situation you described, hopefully in the next SR (SR5).
CP
|
|
|