Author |
Topic  |
|
lboyer
Posts |
Posted - 10/05/2007 : 06:12:34 AM
|
Origin Version (Select Help-->About Origin): 7.5 Operating System: WinXP
Origin Version (Select Help-->About Origin): 7.5 Operating System: WinXp
Hi,
I want to do some automations for collected data.
I want to import data (*.dat) files in Origin and apply some changes to the data.
Here is a sample of one the data files:
300e-3 0.005 -21.728515625 -21.66748046875 -21.6064453125 -21.66748046875 -21.66748046875 -21.66748046875 -21.6064453125 -21.66748046875
The first line is not used. The second line is a step. I want to create an X column in which the first row contains 1*0.005, the second 2*0.005 and so on. The remaining lines (from -21.728515625 to the end) will be placed on an Y column. I also want to perform other tasks on the data files. I have managed to do this using Labtalk scripts in the import wizard an OriginC function :
Labtalk script
wks.addcol(Offset); del col(b);
%z=E:\**\Prog_MOT.c;
// Now load, compile and build the file iErr = run.LoadOC("%z");
// If compile/build failed, report and quit if(0 != iErr) { type -b Could not load and compile Origni C file to perform post-processing.; break; }
// Compile/build was successful - call the main OC function to perform post-processing hello1();
OriginC function :
void hello1() { // Get active page and declare worksheet page object WorksheetPage wpg = Project.Pages();
// Delcare worksheet object and datasets from 1st two columns of the worksheet Worksheet wks(wpg.GetName()); Dataset dsX(wks, 0); Dataset dsY(wks, 1); Dataset dsZ(wks, 2);
wks.Columns(1).SetWidth(10); wks.Columns(2).SetWidth(10);
// Copy ColA in ColB dsY = dsX; // Convert current in ColB from A to pA dsY = dsY*0.000000000001;
// Set Timeline in ColA dsX=0.005; for (int ii = 0; ii < dsX.GetSize();ii++) { dsX[ii] = ii*0.005;
}
// Cancel the offset of the measurement // Get the first 5 points of the measurement, determine an average value of the first 5 points float ave_point = 0, sum = 0; ii = 0; for( ii = 0; ii < 5; ii++) sum = sum + dsY[ii]; ave_point = sum / ii; //printf(" Courant de fuite : %e \n", ave_point);
// Substract this average value from all the measured points ii = 0; for( ii = 0; ii < dsY.GetSize(); ii++) dsY[ii] = dsY[ii] - ave_point; //Create a new column containing the offset value dsZ = ave_point;
}
These scripts work, but is there a way to do this more efficiently? |
|
Mike Buess
USA
3037 Posts |
Posted - 10/06/2007 : 2:18:10 PM
|
If the script works then good enough. However, if you want tips I suggest you either perform all of your manipulations in LabTalk or (except for compiling) in Origin C. Here's a LabTalk script that turns the top Data2 (containing the data you posted) into the bottom Data2 (which I think is what you want)...
xinc = col(1)[2]; // save X increment mark -d col(1) -b 1 -e 2; // delete first two rows col(2) = col(1); // copy data to col(2) col(1) = data(xinc,xinc*wks.maxrows,xinc); // create X values tmp = ave(col(2),5); // average data 5 rows at a time ave_point = tmp[1]; // get average of first 5 rows del tmp; // delete temporary dataset wks.AddCol(Offset); // create Offset column col(3) = col(2); // initialize Offset column col(3) = ave_point; // set all values to ave_point col(2) -= ave_point; // subtract ave_point from col(2) wks.col2.width = 10; wks.col3.width = 10;
Before:

After:

Mike Buess Origin WebRing Member |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/06/2007 : 2:56:04 PM
|
This is the equivalent Origin C function. (Of course you must compile in LabTalk.)
Note: I left out the picoamp conversion in both cases but that should be easy to fix.
#LabTalk script %z=E:\**\Prog_MOT.c; // Now load, compile and build the file iErr = run.LoadOC("%z"); // If compile/build failed, report and quit if(0 != iErr) { type -b Could not load and compile Origni C file to perform post-processing.; break; } // Compile/build was successful - call the main OC function to perform post-processing hello1();
#Origin C function
void hello1() { Worksheet wks = Project.ActiveLayer(); double xinc = wks.Cell(1,0); wks.DeleteRow(0); wks.DeleteRow(0); Dataset dsX(wks,0); Dataset dsY(wks,1); int nRows = dsX.GetSize(); dsY = dsX; dsX.Data(xinc, xinc*nRows, xinc); double ave_point = 0; for(int i=0; i<5; i++) ave_point += dsY[i]; ave_point /= 5.0; wks.AddCol("Offset"); Dataset dsZ(wks,2); dsZ = dsY; dsZ = ave_point; dsY -= ave_point; wks.Columns(1).SetWidth(10); wks.Columns(2).SetWidth(10); }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/06/2007 3:09:39 PM |
 |
|
lboyer
Posts |
Posted - 10/07/2007 : 1:15:24 PM
|
Thank you for your answer Mike Buess.
I have learned a lot through your posts. I still have a problem.
All my files have a name in which the polarization voltage of the sample is specified. After all files are imported (using the previous codes in this post), I need to get the highest (absolute) current value, i.e |Imax| of col_B. Note that the worksheets have the same name than the imported files. I need to get the voltage polarization from the worksheets name, i.e Vg.
All |Imax| have to be copied to ColB of a new worksheet and all Vg have to be copied to ColA.
I just don't know how to perform these tasks. Can you help me? |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/07/2007 : 10:37:19 PM
|
Since you don't actually give the structure of the file and worksheet name I'll have to assume something arbitrary, namely, 1000Vg when the voltage polarization is 1000 volts. Look for substring notation in the index of the programming guide to learn how to extract Vg from the real worksheet name, %H.
%Z=""; nn=0; doc -e W {%Z=%Z %H; nn++}; // list all worksheets win -t D; // create new worksheet %W=%H; // save its name loop(i,1,nn) { win -a %[%Z,#i]; // activate ith worksheet sum(col(B)); %W_B[i] = sum.max; // Imax %W_A[i] = %[%H, "Vg" ]; // obtain Vg value from worksheet name, %H };
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/07/2007 10:39:19 PM |
 |
|
|
Topic  |
|
|
|