/*------------------------------------------------------------------------------* * File Name: IntegrateColumnsAndCreateReport.c * * Creation: ER, 01/24/05 * * Purpose: Programming Example * * Copyright (c) OriginLab Corp.2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #include ///////////////////////////////////////////////////////////////////////////////// // This example shows how to integrate the data in all Y columns of a worksheet // and create a report worksheet with the results. // void integrate_columns_and_create_report() { // Declare worksheet using active layer and check validity Worksheet wksData = Project.ActiveLayer(); if(!wksData){ out_str("Active layer is not a worksheet!"); return; } // Create a results worksheet Worksheet wksResult; wksResult.Create(); // Get the page for this worksheet and set its label and show the label WorksheetPage wpg = wksResult.GetPage(); wpg.Label = "Integration results for '" + wksData.GetPage().GetName() + "' worksheet"; wpg.TitleShow = WIN_TITLE_SHOW_BOTH; //Declare datasets in results worksheet and set column names and widths // First delete all columns in result worksheet and start adding new columns while(wksResult.DeleteCol(0)); int nIndex; int nWidth = 15; // 1st column: name of Y column from data worksheet nIndex = wksResult.AddCol(); wksResult.Columns(nIndex).SetLabel("Source Col Name"); wksResult.Columns(nIndex).SetWidth(nWidth); // 2nd column: peak x location nIndex = wksResult.AddCol(); wksResult.Columns(nIndex).SetLabel("Peak X Location"); wksResult.Columns(nIndex).SetWidth(nWidth); // 3rd column: peak y value nIndex = wksResult.AddCol(); wksResult.Columns(nIndex).SetLabel("Peak Y Value"); wksResult.Columns(nIndex).SetWidth(nWidth); // 4th column: integrated area nIndex = wksResult.AddCol(); wksResult.Columns(nIndex).SetLabel("Integrated Area"); wksResult.Columns(nIndex).SetWidth(nWidth); // Turn on column label display wksResult.ShowLabels(); // Set designation of 1st col to label wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_L); // Loop over all columns of data worksheet and integrate y columns int nCount = 0; foreach(Column ColData in wksData.Columns) { if( OKDATAOBJ_DESIGNATION_Y == ColData.GetType() ) { // Get name of data column and store in result wks at current row, 1st col wksResult.SetCell(nCount, 0, ColData.GetName()); // Declare curve object from data column Curve crvData(wksData, ColData.GetIndex()); // Perform integration and store results at current row in subsequent cols IntegrationResult irResult; BOOL bRet = Curve_integrate(&crvData, &irResult); if(bRet) { wksResult.SetCell(nCount, 1, irResult.xPeak); wksResult.SetCell(nCount, 2, irResult.yPeak); wksResult.SetCell(nCount, 3, irResult.Area); } nCount++; } } // If no y columns were processed, delete the report worksheet and quit if( 0 == nCount ) { out_str("Did not find any Y columns in data worksheet!"); wksResult.Destroy(); return; } else printf("%d columns were processed\n", nCount); } /*int iCol = 0; iCol < iNumCols; iCol++) { Dataset dsData(wksData, iCol + iBegin - 1); if(!dsData) { printf("invalid data column!\n"); return; } // Get name of data column and store in result wks string strColName = dsData.GetName(); dsLabel.SetText(iCol, strColName); // Loop thru each element in data column and do the math int iSize = dsData.GetSize(); for(int iRow = 0; iRow < iSize; iRow++) { dsData[iRow] = ( 10^( dsData[iRow] / 10.0 ) * 0.001) ^ 0.5; } // Perform integration and store result Curve crvMyCurve(strColName); // Create Curve object to integrate if(!crvMyCurve) { printf("invalid curve object!\n"); return; } IntegrationResult irMyResults; // Origin C structure to store integration results bool bErr = Curve_integrate( &crvMyCurve, &irMyResults ); // Perform integration dsValue[iCol] = irMyResults.Area; } // Set 1st col of result worksheet to type label wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_L); } /////////////////////////////////////////////////////////////////////////////////ur functions here.