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
 [Q] Problem plotting/creating a graph
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cowsclaw

USA
Posts

Posted - 05/24/2004 :  1:48:19 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
This is my very first time using Origin, much less program in Origin C, so please bare with me.

I am trying to import data from an ASCII file and then plot one column vs. another. I can input and manipulate the data (it shows up in the worksheet, at least). Whenever I try to create a plot, however, it does not show. I finally managed to get the graph template to show up (i apparently had to create the GraphPage earlier in my program), but no line shows up. I tried using the code examples that I have found, but still have found no luck. If you could help me, I would greatly appreciate it. Thanks

p.s. I hope my code is not too sloppy. I tried to comment it to make it easier to read.
p.p.s. I am not sure if I created and implemented the Datasets and Columns correctly (even though the data shows up in the sheet), so that might be the problem. what is the difference between a Dataset and a Column anyways? is the Dataset contained within a Column and a COlumn is just used to set the physical appearance?

MY CODE
------------------------------------------------------------------

#include <origin.h>
// this file include most of the other header files except the NAG header, which takes longer to compile
// NAG routines
//#include <OC_nag.h> // this contains all the NAG headers,
#include <stdio.h>
#include <graph.h>

////////////////////////////////////////////////////////////////////////////////////

void test(string strFileName)

{
//get input from user
string strInitWave = InputBox("Enter the initial wavelength");
int intInitWave = atof(strInitWave);

string strFinalWave = InputBox("Enter the final wavelength");
int intFinalWave = atof(strFinalWave);

string strPlotType = InputBox("What would you like to plot?\n 1) wavelength vs. log PL\n 2) wavelength vs. linear PL\n 3) E vs. log PL 4) E vs. linear PL");
int intPlotType = atoi(strPlotType);
//determine path
int iLen = strFileName.GetLength();
int iSlash = strFileName.ReverseFind('\\');
int iDot = strFileName.ReverseFind('.');
string strSampleName = strFileName.Mid( iSlash + 1, iDot - iSlash - 1);
printf("Processing file: %s .......", strSampleName);

// Declare root folder of PE for the current project
Folder fldRootFolder = Project.RootFolder;

// Make this folder active
fldRootFolder.Activate();

// Get file path of current project
string strProjectPath;
strProjectPath = Project.GetPath();

// Open file and read data into worksheet
stdioFile ffDataFile;
ffDataFile.Open(strFileName, file::modeRead);
int i = 0; //count number
string pmt, laser, strTemp;
ffDataFile.ReadString(strTemp) ;
while (strTemp.GetLength() != 0)
{ //get number of data points (rows)
if (i != 0){
pmt = strTemp.GetToken(0); // read PMT - column 1
laser = strTemp.GetToken(7); // read LASER - column 8
} //end if
i = i + 1;
ffDataFile.ReadString(strTemp);
} //end while
i = i - 1;
float itotal = i;
// Close data file
ffDataFile.Close();

// Create a graph using custom template
GraphPage grph;
string strTemplate = "Y:\Origin_script_templates\wave_vs_logPL.OTP";
if(intPlotType == 1)
strTemplate = "Y:\Origin_script_templates\wave_vs_logPL.OTP";
else if(intPlotType == 3)
strTemplate = "Y:\Origin_script_templates\energy_vs_logPL.OTP";
else if(intPlotType == 2)
strTemplate = "Y:\Origin_script_templates\wave_vs_linPL.OTP";
else if(intPlotType == 4)
strTemplate = "Y:\Origin_script_templates\energy_vs_linPL.OTP";
BOOL bOK = grph.Create(strTemplate, CREATE_VISIBLE);
if (!bOK)
return;
// Get the first layer:
bOK = grph.RemoveTemplatePict();
//grph.Rename(strSampName);
GraphLayer grlay = grph.Layers(0);
ASSERT(grlay.IsValid());

// Create a worksheet using custom template
Worksheet wksData;
string strWksTemplate = "Y:\Origin_script_templates\pmt3.otw";
int nOptionW = CREATE_VISIBLE_SAME;
bool bRetW = wksData.Create(strWksTemplate, nOptionW);

//Set column widths to fit text name
wksData.Columns(4).SetWidth(10);
wksData.Columns(3).SetWidth(14);
wksData.Columns(5).SetWidth(13);
wksData.Columns(6).SetWidth(16);
wksData.Columns(7).SetWidth(13);

//Set column names
wksData.Columns(0).SetName("A");
wksData.Columns(1).SetName("PMT");
wksData.Columns(2).SetName("Laser");
wksData.Columns(3).SetName("B");
wksData.Columns(4).SetName("C");
wksData.Columns(5).SetName("D");
wksData.Columns(6).SetName("E");
wksData.Columns(7).SetName("F");

//Set column types
wksData.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
wksData.Columns(1).SetType(OKDATAOBJ_DESIGNATION_Y);
wksData.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Y);
wksData.Columns(3).SetType(OKDATAOBJ_DESIGNATION_Y);
wksData.Columns(4).SetType(OKDATAOBJ_DESIGNATION_Y);
wksData.Columns(5).SetType(OKDATAOBJ_DESIGNATION_X);
wksData.Columns(6).SetType(OKDATAOBJ_DESIGNATION_X);
wksData.Columns(7).SetType(OKDATAOBJ_DESIGNATION_Y);

//Set column labels
wksData.Columns(0).SetLabel("Index");
wksData.Columns(1).SetLabel("PMT");
wksData.Columns(2).SetLabel("Laser");
wksData.Columns(3).SetLabel("Avg. X Points");
wksData.Columns(4).SetLabel("No Noise");
wksData.Columns(5).SetLabel("Air Lambda (nm)");
wksData.Columns(6).SetLabel("Vacuum Lambda (nm)");
wksData.Columns(7).SetLabel("Energy (eV)");


// Declare datasets in worksheet to copy data from file
Dataset dsIndex(wksData,0);
Dataset dsPMT(wksData,1);
Dataset dsLaser(wksData,2);
Dataset dsNoNoise(wksData,3);
Dataset dsAvg(wksData,4);
Dataset dsAir(wksData,5);
Dataset dsVacuum(wksData,6);
Dataset dsEnergy(wksData,7);

//Set size to match number of rows (itotal)
dsIndex.SetSize(i);
dsPMT.SetSize(i);
dsLaser.SetSize(i);
dsNoNoise.SetSize(i);
dsAvg.SetSize(i);
dsAir.SetSize(i);
dsVacuum.SetSize(i);
dsEnergy.SetSize(i);

//reread data from file and put into dataset
i = 0; //reset i to initial index
ffDataFile.Open(strFileName, file::modeRead);
ffDataFile.ReadString(strTemp) ;
while (i < itotal)
{
ffDataFile.ReadString(strTemp);
pmt = strTemp.GetToken(0); // read PMT
dsPMT[i] = atoi(pmt); // set PMT data
laser = strTemp.GetToken(7); // read LASER
dsLaser[i] = atoi(laser); // set LASER data
dsAir[i] = (i + 1.00000)/((itotal - 1.00000)/(intFinalWave - intInitWave)) + intInitWave; // set Air data
dsVacuum[i] = 0.01655+1.00023*dsAir[i]+(3.52033/100000000*(dsAir[i]*dsAir[i])); // set Vacuum data
dsEnergy[i] = 1239.85804/dsVacuum[i]; //set energy data
dsIndex[i] = i + 1; //set index number
i = i + 1;
} //end while

// plot Vacuum (X3) vs. Energy (Y3)
string strTempName, strTempName2;
dsVacuum.GetName(strTempName);
dsEnergy.GetName(strTempName2);
Curve cv(dsVacuum, dsEnergy);
ASSERT(cv.IsValid());
int blab = grlay.AddPlot(cv);

// Close data file
ffDataFile.Close();

}

Edited by - cowsclaw on 05/24/2004 4:07:33 PM

easwar

USA
1965 Posts

Posted - 05/24/2004 :  2:12:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

Could be a simple rescale issue? Try adding
...
int blab = grlay.AddPlot(cv);
grlay.Rescale();

Easwar
OriginLab

Go to Top of Page

cowsclaw

USA
Posts

Posted - 05/24/2004 :  4:06:35 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, easwar, but I've already tried adding the rescale and it still doesn't work.

can someone check how i've declared the datasets and implemented their values to make sure I am doing it correctly? it might not be able to plot because it thinks that the datasets are empty?
Go to Top of Page

easwar

USA
1965 Posts

Posted - 05/24/2004 :  4:29:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think the problem is in the curve constructor... a proper curve is not being constructed even though IsValid is true.

If this is the case, you can fix this in your version (which I presume is version 7), by changing the curve constructor to use name rather than dataset:
Curve cv(dsVacuum.GetName(), dsEnergy.GetName());

Note that for this to work correctly, the column type for vacuum should be set to X and for Energy to be set to Y, which you are already doing in your code.

Easwar
OriginLab




Edited by - easwar on 05/24/2004 4:31:13 PM
Go to Top of Page

cowsclaw

USA
Posts

Posted - 05/24/2004 :  4:35:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thanks, easwar, that seems to work! i think i've tried that before, too! argh!


thansk again
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