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
 header line -> Column name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

nbo10

USA
Posts

Posted - 12/09/2005 :  7:02:33 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: XP

quick question, new to origin lab.

I have a data file that has one line that is header info. I want to parse that line and use parts of it to label the columns. Thanks

Mike Buess

USA
3037 Posts

Posted - 12/10/2005 :  10:03:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If the header line is first line you can read it like this...

string str,sFile = "C:\\Temp\\Data.dat";
stdioFile ff(sFile, file::modeRead);
ff.ReadString(str); // read line into str
ff.Close();
out_str(str); // print str

You'll find all you need for the parsing strings under string Class in the programming guide.

This will label the second column of active worksheet...

string str = "Label Text";
Worksheet wks = Project.ActiveLayer();
wks.Columns(1).SetLabel(str);

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 12/10/2005 10:13:54 AM
Go to Top of Page

nbo10

USA
Posts

Posted - 12/10/2005 :  9:39:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I need some more help. What is the difference between dataset and column? I'm able to read my data but having some problems, below is the code that I'm using

Worksheet wksData;
bool bRetW = wksData.Create();
Column colA(wksData,0);
Column colB(wksData,1);
// Declare datasets in worksheet to copy data from file
Dataset dsX(colA);
Dataset dsY(colB);
wksData.Columns(1).SetLabel(TempK);

I have to say that the help files aren't very helpfull if you don't already know all the functions. I'm trying to find all the methods for Worksheet, or any other class and I can't.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 12/11/2005 :  07:41:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
What problems? There is nothing wrong with your code. However, I rarely find it necessary to declare Columns. This will work just as well.

Worksheet wksData;
bool bRetW = wksData.Create();
Dataset dsX(wksData,0);
Dataset dsY(wksData,1);
wksData.Columns(1).SetLabel(TempK);

...You'll find some useful examples at http://www.originlab.com/index.aspx?s=8&lm=243

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 12/11/2005 12:07:39 PM
Go to Top of Page

nbo10

USA
Posts

Posted - 12/13/2005 :  12:47:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The code that you posed was the orginal code that I used. But the Column name doesn't change. Below is the entire funcion That I'm using. I can't seem to add more than 2 datasets, if I add
Dataset zs(wksData,1);
zs.SetSize(10);
zs = 12;
to the code a third column isn't added. If zs(wksData,2) is used a run times error is produced.

Also how do I change the name of the worksheet? I can have mulitple worksheets in one project? Thanks

void Process()
{
string FN = "C:\\Documents and Settings\\JMD\\Desktop\\data\\12-7-2005\\12-7-2005\\BB532.up";
// Open file for processing
stdioFile ffDataFile;
bool bRet = ffDataFile.Open(FN, file::modeRead);
if(!bRet)
{
printf("File not found!\n");
return;
}
printf("Processing file: %s...\n",FN);

// Create a worksheet
Worksheet wksData;
bool bRetW = wksData.Create();

// Declare datasets in worksheet to copy data from file
Dataset dsX(wksData,0);
Dataset dsY(wksData,1);
//Dataset zs(wksData,2);
//zs.SetSize(10);
//zs = 12;

// Read and discard header lines in file
string strHdr;
string TempK, TempnF,Gain,Field,sample,CC;
ffDataFile.ReadString(strHdr);
TempK = strHdr;
printf("Temp K = %s",TempK+"\n");
ffDataFile.ReadString(strHdr);
printf(strHdr+"\n");
ffDataFile.ReadString(strHdr);
TempnF = strHdr;
printf("temp nF = %s",TempnF+"\n");
ffDataFile.ReadString(strHdr);
CC = strHdr;
printf("Cc = %s",CC+"\n");
ffDataFile.ReadString(strHdr);
Field = strHdr;
printf("Fiels = %s",Field+"\n");
ffDataFile.ReadString(strHdr);
Gain = strHdr;
printf("Gain = %s",Gain+"\n");
ffDataFile.ReadString(strHdr);
sample = strHdr;
printf("Sample = %s",sample+"\n");
ffDataFile.ReadString(strHdr);
printf(strHdr+"\n");
ffDataFile.ReadString(strHdr);
printf(strHdr+"\n");
ffDataFile.ReadString(strHdr);
printf(strHdr+"\n");

\\Test Column name change
\\Doesn't Change name of Column
\ wksData.Columns(0).SetLabel("sdasd");
// Loop thru and read all lines from file, and fill data into worksheet columns
bool bRead;
do
{
bRead = ffDataFile.ReadString(strHdr);
if(bRead)
{
int ii = dsX.GetSize();
dsX.SetSize(ii+1); // increment size of datasets
dsY.SetSize(ii+1);
string str1 = strHdr.GetToken(0); // break string into tokens
dsX[ii] = atof(str1); // convert string to number
str1 = strHdr.GetToken(1);
dsY[ii] = atof(str1);
}
}while (bRead);

// Create a graph
//GraphPage grphData;
//bool bRetG = grphData.Create("Origin"); // use the "Origin" template for graph
//
//// Point to active layer in current graph page
//GraphLayer grphLayer = grphData.Layers();
//
//// Declare a curve object using x,y columns of worksheet
//Curve crvData(wksData, 0, 1);
//
//// Plot data curve to active layer
//int nPlot = grphLayer.AddPlot(crvData, IDM_PLOT_SCATTER);
//grphLayer.Rescale();
//
//// Get name of curve
//string strYDataName;
//crvData.GetName(strYDataName);

printf("done!\n");
}
Go to Top of Page

nbo10

USA
Posts

Posted - 12/13/2005 :  2:05:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok, I think I've got the extra columns, but editing th names of the columns and worksheet are still problems

Edited by - nbo10 on 12/13/2005 2:07:50 PM
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