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
 Trouble adding data to datarange
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

JLG

3 Posts

Posted - 07/28/2010 :  10:13:39 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Using OriginPro 8.0.63.988 SR6 on Windows Vista

I'm working on an OriginC script to reprocess some data stored in origin project files. These files have subfolders which typically contain a workbook and two graph pages. One of the workbook pages has three columns, two of which I would like to access. Interestingly I am able to add the first column (and the third column, which I don't actually need) without any problem. However, the second column, for some reason, I can only properly add the data after I either display the graph in the subfolder that plots the data from that column, or look at the workbook's properties. Simply opening the workbook to that page and clicking in it does not do the trick after a fresh load of the project file. When the values are not imported properly, I get values of -1.234568E-300.

This may very well be a mistake on my part, but I have spent quite a bit of time trying to resolve the issue, and would like to see if anyone else has had a similar issue, or if anyone else can point out my mistake. Below is the code I am using:


void Testing123( double dPulseTime = 0 )
{
    Folder fldSub;
    PageBase pb;
    Layer layer;
    WorksheetPage wpCurrent;
    GraphPage gp;
    Worksheet wksCurrent;
    DataRange drCurrent;
    vector vI, vT;
	
    fldSub = Project.ActiveFolder();  //  Get the active folder
	
    // Search each page to find desired workbook
    foreach( pb in fldSub.Pages) 
    {
    	if( pb.GetType() == 2 && atof( pb.GetLongName() ) == dPulseTime ) wpCurrent = pb;  //  get worksheet page of interest
    }
	
    // get the desired worksheet from that page
    foreach( layer in wpCurrent.Layers )
    {
    	if( layer.GetName() == "Data" ) wksCurrent = layer;
    }
    
    drCurrent.BreakUp(); //  Clear out previous data range entries
    drCurrent.Add(wksCurrent, 0, "X");  //  Add time column to datarange as X
    drCurrent.Add(wksCurrent, 1, "Y");  //  Add current column to datarange as Y
	
    //  Clear data out from vector's previous use
    vT.RemoveAll();
    vI.RemoveAll();
	
    //  Populate Voltage and Time vectors
    drCurrent.GetData(vT, 0);  //  Time data
    drCurrent.GetData(vI, 1);  //  Current Data
}

JLG

3 Posts

Posted - 07/29/2010 :  01:11:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I've uploaded a sample project file which can be used to test the above function on:

http://www.mediafire.com/file/q52tmnb6q1y2oa9/Sample.opj

If I open the above file and enter a subfolder and immediately run the command "Testing123(0.05)", the data is not added to the datarange correctly for the second column in the data worksheet in the workbook contained in that folder. This can be seen using the slightly modified function below which outputs one of the values from that column which has been added to a vector. However, if I look at the workbooks properties or open up the graph in the subfolder labeled "0.0500 - Fit" and run the function again, the code works perfectly. Once it works once, it continues to work until the project is closed and reopened.


void Testing124( double dPulseTime = 0 )
{
    Folder fldSub;
    PageBase pb;
    Layer layer;
    WorksheetPage wpCurrent;
    GraphPage gp;
    Worksheet wksCurrent;
    DataRange drCurrent;
    vector vI, vT;
	
    fldSub = Project.ActiveFolder();  //  Get the active folder
	
    // Search each page to find desired workbook
    foreach( pb in fldSub.Pages) 
    {
    	if( pb.GetType() == 2 && atof( pb.GetLongName() ) == dPulseTime ) wpCurrent = pb;  //  get worksheet page of interest
    }
	
    // get the desired worksheet from that page
    foreach( layer in wpCurrent.Layers )
    {
    	if( layer.GetName() == "Data" ) wksCurrent = layer;
    }
    
    drCurrent.BreakUp(); //  Clear out previous data range entries
    drCurrent.Add(wksCurrent, 0, "X");  //  Add time column to datarange as X
    drCurrent.Add(wksCurrent, 1, "Y");  //  Add current column to datarange as Y
	
    //  Clear data out from vector's previous use
    vT.RemoveAll();
    vI.RemoveAll();
	
    //  Populate Voltage and Time vectors
    drCurrent.GetData(vT, 0);  //  Time data
    drCurrent.GetData(vI, 1);  //  Current Data
    printf("%d, %E\n", vI.GetSize(), vI[50]);
}
Go to Top of Page

Penn

China
644 Posts

Posted - 07/29/2010 :  06:12:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

It is a bug. We will try to fix it. Please try the following code.

void Testing124( double dPulseTime = 0 )
{
    Folder fldSub;
    PageBase pb;
    Layer layer;
    WorksheetPage wpCurrent;
    GraphPage gp;
    Worksheet wksCurrent;
    // DataRange drCurrent;
    XYRange xyCurrent;
    vector vI, vT;
	
    fldSub = Project.ActiveFolder();  //  Get the active folder
	
    // Search each page to find desired workbook
    foreach( pb in fldSub.Pages) 
    {
    	if( pb.GetType() == 2 && atof( pb.GetLongName() ) == dPulseTime ) wpCurrent = pb;  //  get worksheet page of interest
    	//if( pb.GetType() == 2 && pb.GetLongName() == dPulseTime ) wpCurrent = pb;  //  get worksheet page of interest
    }
	
    // get the desired worksheet from that page
    foreach( layer in wpCurrent.Layers )
    {
    	if( layer.GetName() == "Data" ) wksCurrent = layer;
    	//if( layer.GetName() == "Sheet1" ) wksCurrent = layer;
    }
    
    //drCurrent.BreakUp(); //  Clear out previous data range entries
    //drCurrent.Add(wksCurrent, 0, "X");  //  Add time column to datarange as X
    //drCurrent.Add(wksCurrent, 1, "Y");  //  Add current column to datarange as Y
    xyCurrent.Add(wksCurrent, 0, "X");
    xyCurrent.Add(wksCurrent, 1, "Y");
	
    //  Clear data out from vector's previous use
    vT.RemoveAll();
    vI.RemoveAll();
	
    //  Populate Voltage and Time vectors
    //drCurrent.GetData(vT, 0);  //  Time data
    //drCurrent.GetData(vI, 1);  //  Current Data
    xyCurrent.GetData(vI, vT);
    printf("%d, %E\n", vI.GetSize(), vI[50]);
}


Penn
Go to Top of Page

JLG

3 Posts

Posted - 07/29/2010 :  1:32:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks! Your workaround works perfectly. Is my understanding correct that XYRange is essentially a more constrained DataRange? Also, in light of this bug, should one use XYRanges instead of DataRanges where possible?
Go to Top of Page

Penn

China
644 Posts

Posted - 07/29/2010 :  9:58:40 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The XYRange class is derived from the DataRange class, you can see the inheritance relationships here. XYRange is for datasets with X and Y ranges, and sometimes together with Y Error. In your issue, it is fine to use XYRange.

Penn
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