Author |
Topic  |
|
markus2k
Germany
Posts |
Posted - 05/05/2004 : 09:02:12 AM
|
Hello NG,
I want use Origin C in order to get an automatization for integrating about 30 Current/Time Curve at once. The problem is that the code I write brings origin to loading the tek0000n.csv files, integrates but it doesnt't take the data files from the folder, I've placed them before C:\O7\*.* ! I don't know the sources orgin c is using, but in fact it does something. This means I get an worksheet (wksArea) with #"Anzahl" entries . The code is compiled with intrenals.c and is in the Folder C:\O7\, the project name is import.opj. I'm using Origin 7.0 Further Questions: How can I write the Integration data from my worksheet wksArea directly into an ASCII file and close the worksheets. I tried LT_execute command, but just an empty file was created.
#include <origin.h>
void Automation(int Anzahl) { // Declare root folder of PE for the current project Folder fldRootFolder = Project.RootFolder;
// Get file path of current project string strProjectPath; strProjectPath = Project.GetPath(); // Create a worksheet using custom template for Area //Worksheet wksArea; Worksheet wksArea; string strWksTemplate = strProjectPath + "csv2ascii.otw"; int nOptionW = CREATE_VISIBLE_SAME; bool bRetA = wksArea.Create(strWksTemplate,nOptionW);
// Declare datasets in worksheet to copy data from file Dataset dtX(wksArea,0); Dataset dtY(wksArea,1);
// Declare a curve object using x,y columns of worksheet Curve crvArea(wksArea, 0, 1);
// Get name of curve string strYAreaName; crvArea.GetName(strYAreaName);
dtX.SetSize(Anzahl); dtY.SetSize(Anzahl);
string strFileName; for(int nn = 0; nn<Anzahl;nn++){ string testi; string convoy; convoy.Format("%d",nn); int wg = lstrlen(convoy); if(wg == 1){testi.Format("Tek0000%d.csv",nn); } if(wg == 2){testi.Format("Tek000%d.csv",nn); } if(wg == 3){testi.Format("Tek00%d.csv",nn); } strFileName = testi; // Extract just the name of the file passed, from the full file name with path
int iLen = strFileName.GetLength(); int iSlash = strFileName.ReverseFind('\\'); int iDot = strFileName.ReverseFind('.'); string strSampleName = strFileName.Mid( iSlash + 1, iDot - iSlash - 1); printf("Processing file: %s .......", strSampleName); printf("\n"); // Create subfolder with same name as file Folder fldSubFolder = fldRootFolder.AddSubfolder(strSampleName); // Make this subfolder active fldSubFolder.MakeActive();
// Create a worksheet using custom template Worksheet wksData; bool bRetW = wksData.Create(strWksTemplate, nOptionW);
// Declare datasets in worksheet to copy data from file Dataset dsX(wksData,0); Dataset dsY(wksData,1);
// Declare a curve object using x,y columns of worksheet Curve crvData(wksData, 0, 1);
// Get name of curve string strYDataName; crvData.GetName(strYDataName);
// Open file and read data into worksheet stdioFile ffDataFile; ffDataFile.Open(strFileName, file::modeRead); // Set dataset length appropriately dsX.SetSize(500); dsY.SetSize(500); string strTemp; ffDataFile.ReadString(strTemp); string str1 = strTemp.GetToken(0,','); string str2 = strTemp.GetToken(1,',');
// Loop thru and read all data points - generate x and read in y from file for(int ii = 0; ii < 500; ii++) { ffDataFile.ReadString(strTemp); string str1 = strTemp.GetToken(0,','); string str2 = strTemp.GetToken(1,','); dsX[ii] = /*10^9*/atof(str1); dsY[ii] = /*10^4*/atof(str2); } Curve cc(dsX, dsY); IntegrationResult result; Curve_integrate(&cc, &result); double a; double b; int c; a = result.Area; b = result.xPeak; c = result.iPeak; //printf("The area is %.1f\n", result.Area); //printf("The peak position is %d\n", result.iPeak); // Eintrag an leerer Zelle in Spalte 2 fortsetzen fldRootFolder.MakeActive(); for(int findex = 0; findex < Anzahl; findex++){ string findit; wksArea.GetCell(findex, 1, findit); string leer = "--"; int res = lstrcmp(leer,findit); if(res == 0) {dtY[findex]=a;dtX[findex]=b;break;} } ffDataFile.Close(); // Set PE folder path back to root fodler, for processing next file if any fldRootFolder.MakeActive();
} printf("done!\n"); } // end
|
|
Mike Buess
USA
3037 Posts |
Posted - 05/05/2004 : 10:48:20 AM
|
A couple of quick comments about your code...
1. I can't find where you've added the path to strFileName. ...It looks like you've placed the data files in your Origin program folder. OriginC's stdiofile does not automatically look there so ffDataFile should be declared as shown in #2.
2. You are mixing up the stdiofile and file classes. ffDataFile should be declared like this
stdioFile ffDataFile(GetAppPath()+strFileName, file::modeRead); // assuming datafiles are in Origin's program folder
Neither ffDataFile.Open(...) or ffDataFile.Close() belong in your code.
As for exporting the worksheet to file... I have used LT_execute("save -w wksName \"file path\\name\"") successfully in Origin 7.0. (It's usually safer to quote file path\name.)
I hope that helps,
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 05/05/2004 10:51:43 AM
Edited by - Mike Buess on 05/05/2004 11:05:32 AM
Edited by - Mike Buess on 05/05/2004 12:19:23 PM |
 |
|
|
Topic  |
|
|
|