The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 extracting single columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Sams83

6 Posts

Posted - 10/28/2009 :  07:26:15 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

my problem is: I import several ASCI-files (of wavelength spectra), each one consisting of two columns (x- and y-values). x-values are the same in each file, y-values differ. The problem is, only about every fourth or fifth ASCI-file contains real y-data, rest is background/data which should be deleted.
The goal is to have one worksheet with first column x-values, then the y-data from all "good" columns.

Until now, my procedure is like this: I mark all the columns, which shall be included in the new worksheet, and copy-paste them to a new worksheet. But this is very time-consuming, as one has to pick out every column by hand.


So I'm looking for a faster method.

A condition to pick out the "good" data can be found, if one looks in a certain row (e.g. row 153) and ask this value e.g. to be over 300.
Is there a possiblity to extract columns whose value in row 153 is over 300?



Another idea would be to "sort by row" (e.g. the upper mentioned row 153), so all columns with values over 300 are lying next to each other and could be more easily copy-pasted...(instead of picking out every tenth column)

But I only found to sort by row. Of course, I could transpose, sort by column and transpose back. But this is very time-consuming as well (data amount is quite big (~ 3600 rows x 1000 columns))

Maybe someone has a nice and preferably easy idea?

Thank you,
Sams83

greg

USA
1379 Posts

Posted - 10/28/2009 :  11:11:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You don't mention what version you have, but this is easily handled by a script in version 8:

// Prompt for files
dlgfile gr:=*.* mu:=1;
string strFile;
// Import first file - both X and Y
strFile$ = fname.GetToken(1,CRLF)$;
impasc fname:=strFile$;
// Check if Y OK for row=153, value>=300
if(wcol(wks.ncols)[153]<300) del wcol(wks.ncols);
// Now import only Y from remaining files as new columns
loop(ii,2,fname.GetNumTokens(CRLF))
{
strFile$ = fname.GetToken(ii,CRLF)$;
impasc fname:=strFile$
options.ImpMode:=1
options.PartImp.Partial:=1
options.PartImp.FirstCol:=2;
if(wcol(wks.ncols)[153]<300) del wcol(wks.ncols);
}

This can also be done in earlier versions with a bit more work using the ascimport structure, but I leave that as an exercise .. ;)
Go to Top of Page

Sams83

6 Posts

Posted - 11/05/2009 :  03:17:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you,

today I will measure some new data and try this then ....
I have version 7.0, but I hope I'll manage that (first time that I programm in origin, but I know at least some programming basics...)
If not, I'll call again for help :)

Thanks a lot, great to have this forum and people who help!

Sams83
Go to Top of Page

Sams83

6 Posts

Posted - 11/10/2009 :  07:13:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
So, here I am again . Maybe my question is now more about Origin C, but I continue with my thread here.

I wrote now a simple program to delete those columns in worksheet 'A400500', which do not fulfill the condition (value in line 1981 must be bigger than 1000.

I used the datasheet s2. First I read in the values from worksheet column cc, then I look in the datasheet if the condition is fulfilled. If not, I want to delete the column in the worksheet.

Here is my code and the error messages which occur when running it. In principle it seems to work, it deletes the first column which is "wrong", but I think it has then the problem with the missing column to continue... -> runtime error

Maybe I have to introduce another (run) variable than cc so that the program does not get confused whenn column cc is missing after deleting? I think my problem is easy to solve, but I don't get the point...

Thank you,
Sams83

//line 25
void deletecolumns()
{
Worksheet wks("A400500");
for (int cc = 0; cc < 1000; cc++)
{
Dataset s2("A400500",cc);
if(s2[1981]<1000)
wks.DeleteCol(cc);
}
}
//line 36

C:\Programme\OriginLab\OriginPro70\OriginC\deletecolumns.c(32) :Origin C Function Runtime Error, Vector operation dimension check error
C:\Programme\OriginLab\OriginPro70\OriginC\deletecolumns.c(31) :Origin C Function Runtime Error, general operation failure
C:\Programme\OriginLab\OriginPro70\OriginC\deletecolumns.c(27) :Origin C Function Runtime Error, general operation failure

Go to Top of Page

greg

USA
1379 Posts

Posted - 11/10/2009 :  4:23:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
A couple of things to point out ..

Deleting column will affect index so the solution is to delete from right to left. You can make the function general by passing in the name of the Workbook/Worksheet. You can also pass in variables for the row to test and the value to test for. The function can be defined with default values that match your row/test values so you do not have to pass those values unless they change.

More important is that row and column index in OriginC is zero-based while in LabTalk, these are 1-based.

Putting all this together - along with a method to get the number of columns - I came up with this:

void deletecolumns(string strBook,uint iTestRow = 1980, double dTestVal = 1000)
{
Worksheet wks(strBook);
for (int cc = wks.GetNumCols() - 1; cc >= 0; cc--)
{
Dataset s2(strBook,cc);
if(s2[iTestRow] < dTestVal)
wks.DeleteCol(cc);
}
}

which can be called with
deletecolumns([Book1]Sheet1)
to delete all columns where the value in row 1981 is less than 1000.
Go to Top of Page

Sams83

6 Posts

Posted - 11/11/2009 :  4:55:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks again, greg!

Good idea to start in the last column to skip the problem with deleted rows...
Well, I have to learn a lot more about programming, just had a basic course in C++
The modified program works well, I already used it several times today, thank you for that!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000