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
 Copy Text Datasets

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
peter.cook Posted - 05/04/2004 : 04:22:34 AM
Hi,

Can anyone please suggest the best (any?!) way to copy text datasets using Origin C.

Case in point is simply to copy eg all of text format column Col(1) to text column Col(2).

I have no problems with text and numeric but I tend to use text datasets.

I think the problems stem from being unable to assign an Origin C Dataset or vector to an Origin text column.

Thanks,

Cheers,

pete

9   L A T E S T    R E P L I E S    (Newest First)
peter.cook Posted - 05/10/2004 : 09:05:58 AM
Hi Mike, Ruthven,

Thanks for your thoughts.

I really would like to see text datasets better handled generally!

I don't believe the changing format to text and numeric is always appropriate as I'm then back to the old problem of numeric formatting and missing values which is why I often use text datasets.

Cheers,

Pete

Mike Buess Posted - 05/05/2004 : 11:22:15 AM
I think that the Dataset class should be fixed to handle Text formatted columns or else this limitation should be pointed out more clearly in the documentation. For example, Dataset::GetStringArray speaks of "Text Datasets" which can be miscontrued as allowing datasets attached to Text formatted columns. Granted, the Dataset entry includes this line...
quote:
Dataset is a template class with a default type of double but a Dataset of any basic data type (including char, byte, short, word, int, and uint but not string) can be constructed using the syntax Dataset<type>.
but I believe the matter requires more emphasis.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/05/2004 11:28:57 AM
rlewis Posted - 05/05/2004 : 12:47:02 AM
Yup ... The following "pure OriginC" approach seems to work quite well ...
 
bool CopyTextNumericColumn(Column source, Column Dest)
{
// Callable from OriginC
if(source.GetFormat()==OKCOLTYPE_TEXT_NUMERIC)
{
Dest.SetFormat(OKCOLTYPE_TEXT_NUMERIC);
Dest.SetNumRows(source.GetNumRows());
string dsSource=source.GetDatasetName();
string dsDest=Dest.GetDatasetName();
Dataset sourceD, DestD;
if(sourceD.Attach(dsSource) && DestD.Attach(dsDest))
{
StringArray sa;
sourceD.GetStringArray(sa);
DestD.PutStringArray(sa);
return (true);
}
}
return (false);
}


bool CopyWksColumn(string wksName, int SourceCol, int DestCol)
{
//Callable from LabTalk and OriginC
if(SourceCol!=DestCol)
{
Worksheet wks;
if(wks.Attach(wksName))
{
int SourceFormat=wks.Columns(SourceCol).GetFormat();
wks.Columns(SourceCol).SetFormat(OKCOLTYPE_TEXT_NUMERIC);
wks.Columns(DestCol).SetFormat(OKCOLTYPE_TEXT_NUMERIC);
Column source, Dest;
if(source.Attach(wks, SourceCol) && Dest.Attach(wks, DestCol))
{
if(CopyTextNumericColumn(source, Dest))
{
source.SetFormat(SourceFormat);
Dest.SetFormat(SourceFormat);
return (true);
}
}
}
}
return (false);
}
Mike Buess Posted - 05/04/2004 : 1:12:11 PM
I see what you mean. So the real solution to Pete's problem is to set the Format for both columns to Text&Numeric (OKCOLTYPE_TEXT_NUMERIC) first, copy using any method that works for datasets and changing them back to OKCOLTYPE_TEXT (if necessary) when done.

Mike Buess
Origin WebRing Member
rlewis Posted - 05/04/2004 : 12:31:21 PM
I just tried Mike's approach using the following ...

bool CopyTextColumn(Column source, Column Dest)
{
if(source.GetFormat()==OKCOLTYPE_TEXT)
{
Dest.SetFormat(OKCOLTYPE_TEXT);
Dest.SetNumRows(source.GetNumRows());
string dsSource=source.GetDatasetName();
string dsDest=Dest.GetDatasetName();
Dataset sourceD, DestD;
if(sourceD.Attach(dsSource) && DestD.Attach(dsDest))
{
StringArray sa;
sourceD.GetStringArray(sa);
DestD.PutStringArray(sa);
return (true);
}
}
return (false);
}


However this approach fails because the test condition ..
"if(sourceD.Attach(dsSource) && DestD.Attach(dsDest))"
always fails when the Worksheet column is set as "Text". However, it works when the Worksheet column is set as "Text and Numeric" (i.e Peter's Original concern)
Mike Buess Posted - 05/04/2004 : 11:57:15 AM
This should work but I haven't actually tried it...

Worksheet wks = Project.ActiveLayer();
Dataset ds1(wks,0);
Dataset ds2(wks,1);
StringArray sa;
ds1.GetStringArray(sa);
ds2.PutStringArray(sa);

Mike Buess
Origin WebRing Member
rlewis Posted - 05/04/2004 : 11:21:05 AM
One can also use the a combination of Worksheet.GetCell() and Worksheet.SetCell() function calls within a loop to do the same thing.
However, the above approach is faster (at least on my machine)
peter.cook Posted - 05/04/2004 : 11:01:14 AM
Hi Ruthven,

Thanks for reply.

Essentially then you have to use the labtalk copy command..

Is there no 'pure C' way to do this?

Cheers,

pete

rlewis Posted - 05/04/2004 : 10:27:18 AM
Hi Peter ...

The combination of the OriginC functions listed below seems to work. Perhaps it might do what you want.

bool CopyTextColumn(Column source, Column Dest)
{
// Callable form OriginC
if(source.GetFormat()==OKCOLTYPE_TEXT)
{
Dest.SetFormat(OKCOLTYPE_TEXT);
Dest.SetNumRows(source.GetNumRows());
string dsSource=source.GetDatasetName();
string dsDest=Dest.GetDatasetName();
string strLTCommand;
strLTCommand.Format("copy "+dsSource+" "+dsDest);
LT_execute(strLTCommand);
return (true);
}
return (false);
}

bool CopyWksTextCol(string wksName, int SourceCol, int DestCol)
{
//Callable from LabTalk and OriginC
if(SourceCol!=DestCol)
{
Worksheet wks;
if(wks.Attach(wksName))
{
Column source, Dest;
if(source.Attach(wks, SourceCol) && Dest.Attach(wks, DestCol))
{
if(CopyTextColumn(source, Dest))
{
return (true);
}
}
}
}
return (false);
}

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