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
 difficulty with global toggle of data mask
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ericharley

USA
Posts

Posted - 07/26/2005 :  11:42:32 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): OrignPro 7.5 SR5 v7.5870 (B870)
Operating System: Windows XP SP2

I'm trying to write (or more accurately, copy, paste, and edit) some very simple Origin C routines that allow me to normalize and distribute data appropriately for the way I typically graph them. My problem is, if I have some of the data on the worksheet masked, the Y-values are not shifted along with the rest of the data.

I would like to use something like this:
void zero_norm_y_cols()
{

Worksheet wks = Project.ActiveLayer();
if( !wks )
{
out_str("Active layer is not a worksheet!");
return;
}

foreach( Column col in wks.Columns )
{
if( OKDATAOBJ_DESIGNATION_Y == col.GetType() )
{
Dataset ds(col);
double dMin, dMax;
ds.GetMinMax(dMin, dMax);
LT_execute("@MM=1"); //disable masking globally
ds -= dMin;
ds /= (dMax-dMin);
LT_execute("@MM=0"); //enable masking globally
}
}
}

This way I don't use the masked data to determine Min and Max, but the masked data are still zeroed and normalized along with everything else.

Unfortunately this doesn't work for me. In fact, even if I use the "disable/enable masking" button on the mask toolbar to disable the mask first and then run the above code (without the LT_execute lines), the masked data are not included in the renormalization.

Any suggestions?

Mike Buess

USA
3037 Posts

Posted - 07/26/2005 :  12:29:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
After setting @MM you need to update the worksheet with 'mark -u'...

Dataset ds(col);
double dMin, dMax;
ds.GetMinMax(dMin, dMax);
LT_execute("@MM=1; mark -u"); //disable masking globally
ds -= dMin;
ds /= (dMax-dMin);
LT_execute("@MM=0; mark -u"); //enable masking globally

Mike Buess
Origin WebRing Member
Go to Top of Page

ericharley

USA
Posts

Posted - 07/26/2005 :  1:17:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike, thanks for the suggestion and the quick response.

Unfortunately that doesn't seem to solve my problem. In fact, even when I use the toggle button manually to disable the mask (and I verify visually that the color on the worksheet cells disappears), my Origin C code still doesn't operate on those data points.

Any other thoughts?
Go to Top of Page

greg

USA
1379 Posts

Posted - 07/26/2005 :  2:12:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here's the LabTalk version :

@mm=1;
for( jj = 1 ; jj <= wks.ncols ; jj++ )
{
if( 1 == wks.col$(jj).type )
{
sum(wcol(jj));
wcol(jj) -= sum.min;
wcol(jj) /= (sum.max - sum.min);
}
}
@mm=0;

which seems to do what you want.

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 07/26/2005 :  2:47:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here's a slightly more complicated OC version that does not use the global variable but swaps the mask states instead. I haven't tested it in detail, but at least it affects the masked points..
void zero_norm_y_cols() 
{
Dataset ds;
double dMin, dMin2, dMax, dMax2;
Worksheet wks = Project.ActiveLayer();
if( !wks )
{
out_str("Active layer is not a worksheet!");
return;
}

foreach( Column col in wks.Columns )
{
if( OKDATAOBJ_DESIGNATION_Y == col.GetType() )
{
ds.Attach(col);
// get min/max for unmasked points
ds.GetMinMax(dMin, dMax);
LT_execute("mark -sw col(" + col.GetName() + ")"); // swap masks
// get min/max for previously masked points
ds.GetMinMax(dMin2, dMax2);
// find overall min/max
if( dMin2<dMin ) dMin = dMin2;
if( dMax2>dMax ) dMax = dMax2;
// correct previously masked points
ds -= dMin;
ds /= (dMax-dMin);
LT_execute("mark -sw col(" + col.GetName() + ")"); // swap masks
// correct unmasked points
ds -= dMin;
ds /= (dMax-dMin);
}
}
}


Mike Buess
Origin WebRing Member
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/26/2005 :  3:19:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is a bug, thanks for finding this.
Looks like internal Origin C access to Dataset is ignoring global @MM setting. I have created bug tracking number 7934 to fix this in the next version.

CP


Go to Top of Page

ericharley

USA
Posts

Posted - 07/27/2005 :  4:37:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Greg and Mike for the helpful code.

greg - it's useful for me to see these things in LabTalk, especially so when I want to type something directly into the script window on the fly I can do it.

mike - I can make some adjustments so that your OC code does exactly what I want. Hadn't thought about swapping the mask state, but that is a good workaround. I was afraid I'd have to do something complicated like loop through all the cells, store the mask state, unmask, calculate, restore mask... that would have been irritating.

Glad to see this bug will be taken care of. Kind of unsettling to find a bug like this on my second day using Origin. Very happy that this seems to be a responsive forum, though.
Go to Top of Page

ericharley

USA
Posts

Posted - 07/28/2005 :  10:47:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hopefully this should be my last post on this topic!

Found another problem:
if you run
mark -sw col(d)

and column d has no mask, this actually causes Origin to crash entirely. This would be a problem if trying to loop through an entire sheet using the LabTalk code, if not all y columns contained masked data. Origin people - let me know if you need any more details about the error message I get when Origin crashes.

Here's what I have finally ended up with, in case anyone is interested in the code. At least in Origin C it is possible to catch the error so it doesn't do any damage:


int swap_mask(string scol)
{
try // Protected code...
{
LT_execute("mark -sw " + scol); // swap masks
}
catch(int iErr) // Error handler...
{
/*if( iErr==288 )
printf("Column " + scol + " has no mask\n");
else
printf("error code = %d\n", iErr);
*/
return iErr;
}
return 0;
}

void zero_norm_y_cols()
{
Worksheet wks = Project.ActiveLayer();
if( !wks )
{
out_str("Active layer is not a worksheet!");
return;
}
foreach( Column col in wks.Columns )
{
if( OKDATAOBJ_DESIGNATION_Y == col.GetType() )
{
Dataset ds(col);
double dMin, dMax;
ds.GetMinMax(dMin, dMax);
//shift unmasked data
ds -= dMin;
ds /= (dMax-dMin);
//get column name
string colName;
if( !col.GetName(colName))
{
printf("Failed to get column name.\n");
return;
}
//only shift if swap_mask doesn't return an error
//this prevents shifting a column twice if the column
//has no mask
if( !swap_mask("col(" + colName + ")") )
{
//shift formerly masked data
ds -= dMin;
ds /= (dMax-dMin);
//put mask back in original state
swap_mask("col(" + colName + ")");
}
}
}
}
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