[slang-users] push array structure into slang
John E. Davis
davis at space.mit.edu
Thu Aug 25 13:28:29 EDT 2005
Joe Miller <lpe540 at yahoo.com> 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
More information about the slang-users-l
mailing list