Author |
Topic  |
|
ericharley
USA
Posts |
Posted - 09/29/2005 : 12:46:39 PM
|
Origin Version (Select Help-->About Origin): OriginPro 7.5 SR5 Operating System: Windows XP SP2
I'd like to correct ccd artifacts in my spectra. I envision code that should go something like this:
//usage corrected_data = ccd_corr( data, flat, dark, scale )
Dataset ccd_corr( Dataset dataIn, Dataset flat, Dataset dark, const double scale ) { Dataset dataOut; dataOut = (dataIn - dark) / (flat - dark) / scale; return dataOut; }
Unfortunately, if I run this from the script window, the corrected_data worksheet column remains empty. Hey, at least it compiled!
Clearly my code must be a little simplistic (but I just had to try the easy way). Perhaps to perform mathematical operations in OriginC I need to somehow copy the Datasets to vectors? Can I divide Datasets or vectors by scalars, or do I have to loop through element by element? Perhaps the problem is that a Dataset always needs to be associated with a worksheet column in the Origin project, so my Dataset dataOut; constructor isn't really doing anythying. If that is necessary, I suppose I could always pass in the string name of the dataset as an argument to the function, write to the dataset in the function, and not have the function itself return anything. What am I missing here? I poked around a bit in the help and on the forum, but I haven't seen an example that answers these questions directly (probably just missed it).
Thanks, Eric Harley |
|
ericharley
USA
Posts |
Posted - 09/29/2005 : 1:59:43 PM
|
OK, fixed my own problem.
For those who are interested, it seems that things work if you pass a string into the OriginC function and use that in the Dataset constructor.
Here's some code that works:
//usage ccd_corr( data, flat, dark, corrected data, scale ) void ccd_corr( string sdataIn, string sflat, string sdark, string sdataOut, const double scale ) { Dataset dataIn(sdataIn); Dataset flat(sflat); Dataset dark(sdark); Dataset dataOut(sdataOut); dataOut = (dataIn - dark) / (flat - dark) / scale; }
Not quite as nice to use as it might have been to say new_data = ccd_corr(arguments), but it works. Well, at least the first thing that I tried seemed to work. I'll post again with corrections if there turns out to be a problem...
Eric Harley |
 |
|
easwar
USA
1965 Posts |
Posted - 09/29/2005 : 3:11:44 PM
|
Hi Eric Harley,
LabTalk supports double and string variable types and these can be passed to Origin C. Dataset is an Origin C class object.
For your particular function however, it looks like you are basically computing column values based on other columns. So you could rewrite it as follows:
double ccd_corr(double dIn, double dFlat, double dDark, const double dScale) { return (dIn - dDark) / (dFlat - dDark) / dScale; }
Then you could call it from script window with command such as: data1_e = ccd_corr(data1_a, data1_b, data1_c, 0.1);
or using command: col(e) = ccd_corr(col(a), col(b), col(c), 0.1);
With functions that accept and return double, when you call them with LabTalk dataset names such as data1_a, Origin the repatedly calls the function for each row of the dataset and this is why the above will work.
Such a function could be added to the System branch of your Code Builder workspace, or be attached to a specific Project, in which case the function will be available (in all sessions if attached to System branch) and can be used to set column values of a result column. You could then also turn on auto update so the result updates when input column data changes.
Easwar OriginLab
|
 |
|
|
Topic  |
|
|
|