T O P I C R E V I E W |
lboyer |
Posted - 10/04/2007 : 5:14:55 PM Origin Version (Select Help-->About Origin): 7.5 Operating System: WinXp
Hi,
I want to do some automations for collected data. I have never used Labtalk nor OriginC before but I know a few about C language.
I want to import data (*.dat) files in Origin, make some changes in the files then plot them.
Here is an 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?
Also, I want to generate a graph for these data in the following way: After being imported, I will manually place the worksheets in subfolders. Then I want to generate a graph containing all the data from a subfolder into this subfolder. Below is a function I have made:
void all_curves_in_a_graph() { // Set up name of custom template to be used for creating a graph string strGraphTemplateName = LabTalk.System.Path.Program$ + "E:\\**\\Graph_template_MOT.otp";
// Create a graph using custom template GraphPage grphData; int nOptionG = CREATE_VISIBLE_SAME; // visibility is that of the source worksheet bool bRetG = grphData.Create(strGraphTemplateName, nOptionG); // Declare active layer in current graph page GraphLayer grphLayer = grphData.Layers();
// Count worksheets pages in the project int nCount = 0; foreach(WorksheetPage wp in Project.WorksheetPages) { nCount++; } printf("\n total number of worksheets: %d",nCount); // Get the WorksheetPages name: for(int bb = 0; bb< nCount; bb++) { WorksheetPage pg = Project.WorksheetPages(bb); Worksheet wks(pg.GetName()); // Declare a curve object using x,y columns of worksheet Curve crvData(wks, 0, 1); // Plot data curve to active layer int nPlot = grphLayer.AddPlot(crvData, IDM_PLOT_LINE); grphLayer.Rescale(); } grphLayer.LT_execute("legend"); // Group all the plots in the layer into one group. // the graph layer needs to be initialized: printf("\n"); printf("%d Courbes tracees", bb); grphLayer.GroupPlots(0); out_str(grphLayer.GetName());
printf("done"); // }
The problem is that this function always generates a graph for all datasheets in the project.
Can you please help me? |
1 L A T E S T R E P L I E S (Newest First) |
lboyer |
Posted - 10/05/2007 : 06:06:44 AM I have managed to solve my problem.
The following code generates a graph for each worksheets in the active subfolder.
void graph2() {
Folder fld = Project.ActiveFolder(); string str; int i; // Set up name of custom template to be used for creating a graph string strGraphTemplateName = LabTalk.System.Path.Program$ + "E:\**\\Graph_template_MOT.otp";
// Create a graph using custom template GraphPage grphData; int nOptionG = CREATE_VISIBLE_SAME; // visibility is that of the source worksheet bool bRetG = grphData.Create(strGraphTemplateName, nOptionG); // Declare active layer in current graph page GraphLayer grphLayer = grphData.Layers(); foreach(PageBase pb in fld.Pages) { str = pb.GetName(); if( pb.GetType()==EXIST_WKS ) { i++; printf("\n nom du wks: %s", str); Worksheet wks(pb.GetName()); // Declare a curve object using x,y columns of worksheet Curve crvData(wks, 0, 1); // Plot data curve to active layer int nPlot = grphLayer.AddPlot(crvData, IDM_PLOT_LINE); } } grphLayer.Rescale(); grphLayer.LT_execute("legend"); grphLayer.GroupPlots(0);
}
Note that the path of the graph template has been suppressed for privacy purposes. |
|
|