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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Copy Text Datasets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 05/04/2004 :  04:22:34 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

rlewis

Canada
253 Posts

Posted - 05/04/2004 :  10:27:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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);
}
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 05/04/2004 :  11:01:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

rlewis

Canada
253 Posts

Posted - 05/04/2004 :  11:21:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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)
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 05/04/2004 :  11:57:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 05/04/2004 :  12:31:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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)
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 05/04/2004 :  1:12:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 05/05/2004 :  12:47:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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);
}
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 05/05/2004 :  11:22:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 05/10/2004 :  09:05:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000