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 for Programming
 Forum for Origin C
 Empty wks by use of mat.CopyTo(wks)

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
Dominik Paulkowski 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
4   L A T E S T    R E P L I E S    (Newest First)
Dominik Paulkowski 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
Mike Buess 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 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 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

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