- Subject: Re: [slang-users] push array structure into slang
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Thu, 25 Aug 2005 13:28:29 -0400
Joe Miller <lpe540@xxxxxxxxx> wrote:
>I have a c function that returns an array of C
>structures and I'd like to push onto slang. I've tried
>to do this a bunch of different ways and have to find
>a way that works. I was wondering if anyone had any
>suggestions.
I will try to followup with an example of how to do this when time
permits. However, in your case I think it is more important to
reconsider your approach.
Obviously, in C scope you have a set of (x,y) points stored as an
array of structs. I strongly urge you not to use this representation
in S-Lang scope because it will defeat the purpose of slang's array
handling. Instead I recommend that you return a single struct with
with two array-valued x, y fields. With such a representation,
filtering would be trivial, e.g.,
pnts = your_function (...);
i = where ((pnts.x < xmin) or (pnts.x >= xmax));
bad_x = pnts.x[i];
.
.
Also it would be possible to trivally pass such data to functions that
expect arrays, e.g.,
mean_x = sum (pnts.x)/length(pnts.x);
or even
require ("gsl");
% Add some noise
sigma = sqrt (pnts.y);
pnts.y += ran_gaussian (sigma, length (pnts.y));
None of the above operations would be simple in your array-of-structs
approach.
I hope this helps.
Good luck,
--John
_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html
[2005 date index]
[2005 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]