Author |
Topic  |
|
Steve_t
Germany
Posts |
Posted - 07/08/2005 : 06:12:49 AM
|
Origin Version (Select Help-->About Origin): 7.5SR4 Operating System: Win XP SP2
Hello, i've got a bigger number of files (several hundred *.txt) here. Each has 2 Columns, X-Y, space-seperated.
I have to smooth them using Savitzky-Golay. Is this possible somehow from Origin? I'd like to do the smoothing (if possible on a selected number of files) before importing the data... (or do i have to use Matlab or something like that?)
Thanks in advance for the trouble. Bye, Steffen |
|
Mike Buess
USA
3037 Posts |
Posted - 07/08/2005 : 07:09:46 AM
|
Hi Steffen,
Savitzky-Golay smoothing is available in both LabTalk and Origin C but I don't understand why you want to smooth before importing. Here's an example for smoothing data in a worksheet...
http://www.originlab.com/forum/topic.asp?TOPIC_ID=3432
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 07/08/2005 07:10:30 AM |
 |
|
Steve_t
Germany
Posts |
Posted - 07/08/2005 : 07:54:05 AM
|
quote:
...but I don't understand why you want to smooth before importing.
The reason is that i have about 600 files files (each 5MB in Size) and i would like to have done this in an automatic process. I hoped, there would be an easy way (for a newbie ;-) ).
Thanks for the script (i found that also yesterday evening), but i tried to do it without importing the data.
Steffen
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 07/08/2005 : 08:57:01 AM
|
If you intend to import the data to Origin there is no advantage to smoothing first. Batch processing is done frequently in Origin (I do a lot myself). For example, see the following sample project in your Origin folder...
\Samples\Programming\Automation\AutomationExample.opj
Mike Buess Origin WebRing Member |
 |
|
Leo_Li
China
Posts |
Posted - 07/08/2005 : 08:57:42 AM
|
Hi Steffen,
Try to following automating routine: 1. In Origin7.5, open "Code Builder" 2. File->New a C file, copy and paste codes (in below) into it, then File->Add to Workspace 3. Tools->Compile 4. In Origin7.5, Open "Script Window" 5. Type "dosmooth", and then press "Enter" 6. In the "Open ASCII" dialog, select multiple files (e.g. 600)... 7. The program will import, smooth, close your ASCII files one by one...
void dosmooth() { // Open file dialog box int iNumSelFiles; StringArray saFiletypes, saFilePaths; saFiletypes.SetSize(2); saFiletypes[0]="[All Files (*.*)] *.*"; saFiletypes[1]="[ASCII Text (*.DAT)] *.DAT";
iNumSelFiles = GetMultiOpenBox(saFilePaths, saFiletypes, "", "", "Import ASCII"); // Hanle ASCII files one by one for (int i = 0; i < saFilePaths.GetSize(); i++) { ASCIMP ascimp; if(AscImpReadFileStruct(saFilePaths[i], &ascimp)==0) { // Read to worksheets Worksheet wks; wks.Create("Origin"); wks.ImportASCII(saFilePaths[i], ascimp); // Smooth it Curve cv(wks, 0, 1); // BOOL smooth(Curve &cc, int method, int leftpts , int rightpts, int polydeg) // mothed = 2: Savitzky-Golay; ileftpts = 3; irightpts = 3; ipolydeg = 2; smooth(cv, 2); // Save wks.ExportASCII(saFilePaths[i], WKS_EXPORT_ALL); // Close wks.Destroy(); } } }
Note that X must be equi-spaced, or Origin will report run time error.
Edited by - Leo_Li on 07/08/2005 09:01:58 AM |
 |
|
Steve_t
Germany
Posts |
Posted - 07/08/2005 : 09:01:38 AM
|
Thanks to you both,
I'll try both ways. Thank you.
I'm not too experienced in programming in Origin, but i think i've gotta change that in the nearest future...
Steffen |
 |
|
Steve_t
Germany
Posts |
Posted - 07/08/2005 : 10:37:58 AM
|
Hello,
Script worked fine (just changed it to: smooth(cv, 2, 20,20,1 ); ). Thanks alot!
But i have another problem: The script will overwrite the original files (okay, backup is possible), but would it be possible to save the new files in a way like that (e.g. insert string "_smooth"): test.txt --> test_smooth.txt
I tried around with lstrcat, but didn't get a working solution. I also couldn't find something like String-split...
Does anyone have another idea?
Thanks and sorry for the trouble. Greets, Steffen
Edited by - Steve_t on 07/08/2005 10:40:17 AM |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 07/08/2005 : 11:33:46 AM
|
Try this...
string strPath,strName; strPath = GetFilePath(saFilePaths[i]); strName = GetFileName(saFilePaths[i],true); // strip extension wks.ExportASCII(strPath + strName + "_smooth.txt", WKS_EXPORT_ALL);
Mike Buess Origin WebRing Member |
 |
|
Steve_t
Germany
Posts |
Posted - 07/08/2005 : 7:12:41 PM
|
Hello,
thank you for the fast Answer. I'll try it Monday morning when i'm back in office.
Have a nice Weekend!
Bye, Steffen |
 |
|
|
Topic  |
|
|
|