| Author |
Topic  |
|
|
Dominik Paulkowski
Germany
Posts |
Posted - 01/29/2007 : 04:01:10 AM
|
Origin Version (Select Help-->About Origin): Origin7.5G SR6 (v7.5886) Operating System: Windows XP
Hi there!
To solve my binary import problem http://www.originlab.com/forum/topic.asp?TOPIC_ID=5402, I tried my own import routine. The columns of my raw data seem to be permutated. The first columns is permutated to the last columns. To get this right, I wrote a sorting routine.
This sorting mechanism copies the worksheet data to a matrix. Sort the columns in the matrix. But when I copy the sorted data back to the worksheet, the worksheet lost all its data. I don't know why. (When I don't copy back to worksheet, the wks have the old unsorted data.) Compiling is fine. The empty worksheet couldn't set to datasets, when running script.
My script:
// Length of header int iHeaderLength = 2478;
// Set file name string strFileName; file fActualFile;
if( fActualFile.Open(strFileName, file::modeRead | file::typeBinary) ) { int iStartRow = 0; int iStartCol = 0; int nRowIndex = iStartRow; int nCols = 4; // Number of Cols to import double dblTemp; // Set read position at the end of the header fActualFile.Seek(iHeaderLength, file::begin);
LONG iFileLength = fActualFile.GetLength(); while( fActualFile.GetPosition() < iFileLength ) {
// read data from file, fill in one row in worksheet for( int ii = iStartCol; ii < nCols; ii++ ) { fActualFile.Read(&dblTemp, sizeof(double)); // position for the cell in the worksheet // Row : nRowIndex; // Col : ii; wks.SetCell(nRowIndex, ii, dblTemp);
} nRowIndex++; } // ende while fActualFile.Close();
// --------------------------------------------------------------------------------------------- // -------------- Sort the binary data at the columns // -------------- (The first col is permutated to the last col) // ---------------------------------------------------------------------------------------------
string strMatrixName = "RawDataSort"; MatrixPage mpTemp; // Define MatrixPage mpTemp.Create("origin"); // Create MatrixPage with origin template mpTemp.Rename(strMatrixName); //label MatrixPage MatrixLayer mlTemp = mpTemp.Layers(0); Matrix matTemp(mlTemp);
//Matrix<double> matTemp(strMatrixName); int nSize = wks.GetNumRows(); matTemp.SetSize(nSize, nCols);
//int c1; //int c2; //int r1; //int r2;
BOOL bRet = TRUE; bRet = matTemp.CopyFromWks(wks);
vector<double> vecTemp(nSize); // Save last col in the temporary vector matTemp.GetColumn( vecTemp, nCols-1); // Move three vectors one col ahead vector vecTempDragNDrop; for( int iDragNDropCol = 0; iDragNDropCol < nCols-1; iDragNDropCol++ ) { matTemp.GetColumn(vecTempDragNDrop, nCols-2 -iDragNDropCol); matTemp.SetColumn(vecTempDragNDrop, nCols-1 -iDragNDropCol); } // Copy vector to first column matTemp.SetColumn(vecTemp, 0);
printf("Before Vector nSize = %d\n", nSize); // 100021 (there are empty cells at the end) nSize = vecTemp.GetSize(); printf("Behind Vector nSize = %d\n", nSize); // 100001
wks.SetSize(nSize, nCols); // Copy Matrix to worksheet /** double dblWriteBack; string strWriteBack; for( int iFormating = 0; iFormating < nCols; iFormating++ ) { wks.Columns(iFormating).SetFormat(OKCOLTYPE_TEXT); for( int jWriteBack = 0; jWriteBack < nSize; jWriteBack++ ) { dblWriteBack = matTemp[jWriteBack][iFormating]; //DoubleToStr(dblWriteBack, strWriteBack, 30, "*3"); //DoubleToStr(double dbVal, LPSTR lpszOutput, int nOutputSize, LPCTSTR lpcszFormat) strWriteBack = ftoa(dblWriteBack); wks.SetCell(jWriteBack,iFormating,strWriteBack); } wks.Columns(iFormating).SetFormat(OKCOLTYPE_NUMERIC); } */ matTemp.CopyTo(wks, 0, 0, -1, -1);
Dataset colZeit(wks, 0); // Warning, Parameter error Datatyp
------------------- :-Dipl.-Phys. Dominik Paulkowski Fraunhofer Institute for Surface Engineering and Thin Films (IST) Braunschweig Germany
Edited by - Dominik Paulkowski on 01/29/2007 04:03:42 AM |
|
|
Mike Buess
USA
3037 Posts |
Posted - 01/29/2007 : 04:44:13 AM
|
Hi Dominik,
Why not do it the easy way? Replace all lines starting with string strMatrixName = "RawDataSort"; with the following...
int nCols = wks.GetNumCols(); string ColNameCreated; wks.InsertCol(0, "A", ColNameCreated); Dataset ds1(wks, nCols); Dataset ds2(wks, 0); ds2 = ds1; wks.DeleteCol(nCols);
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/29/2007 04:47:38 AM |
 |
|
|
Dominik Paulkowski
Germany
Posts |
Posted - 01/29/2007 : 11:58:45 AM
|
Hi Mike!
Basicly that's a very nice idea. But when I use
int nCols = wks.GetNumCols(); int nRows = wks.GetNumRows(); string strColNameCreated; wks.InsertCol(0, "A", strColNameCreated); wks.SetSize(0,nRows); Dataset dsTemp1(wks, nCols+1); Dataset dsTemp2(wks, 0); dsTemp2 = dsTemp1; wks.DeleteCol(nCols+1);
each cell will be copied seperatly from last to the first column.
By 100 000 cells it takes too much time. The matrix method copies the whole worksheet (four columns) in a few seconds. The ds2=ds1 method takes several minutes. And: after a cup of coffee there was a warning displayed, that my 1 GB RAM wouldn't be enough memory.
So, I prefer the matrix method. Any idea, why mat.CopyTo(wks) causes an empty worksheet? What header files do I have to load in the c-header? My help files don't contain the command CopyTo.
------------------- :-Dipl.-Phys. Dominik Paulkowski Fraunhofer Institute for Surface Engineering and Thin Films (IST) Braunschweig Germany
Edited by - Dominik Paulkowski on 01/29/2007 12:01:29 PM |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 01/29/2007 : 2:28:24 PM
|
Shouldn't take that long to duplicate a column. Try this first...
int nCols = wks.GetNumCols(); // int nRows = wks.GetNumRows(); // don't need this string strColNameCreated; wks.InsertCol(0, "A", strColNameCreated); //wks.SetSize(0,nRows); // don't need this and may be why it took so long //Dataset dsTemp1(wks, nCols+1); Dataset dsTemp1(wks,nCols); // inserted a column so nCols is last index (OC indices start with zero) Dataset dsTemp2(wks, 0); dsTemp2 = dsTemp1; //wks.DeleteCol(nCols+1); wks.DeleteCol(nCols); // nCols is last index
Mike Buess Origin WebRing Member |
 |
|
|
Dominik Paulkowski
Germany
Posts |
Posted - 01/30/2007 : 03:36:23 AM
|
Thank you, Mike!
I don't understand, why wks.SetSize causes that problem. But it works very well now. 
------------------- :-Dipl.-Phys. Dominik Paulkowski Fraunhofer Institute for Surface Engineering and Thin Films (IST) Braunschweig Germany |
 |
|
| |
Topic  |
|
|
|