[SciPy-User] Porting code from IDL to Python - 'Common block' equivalent?

Gökhan Sever gokhansever at gmail.com
Wed Jul 21 11:47:00 EDT 2010


On Wed, Jul 21, 2010 at 3:18 AM, David Andrews <irbdavid at gmail.com> wrote:

> Hi All,
>
> I suppose this might not strictly be a scipy type question, but I'll
> ask here as I expect some of you might understand what I'm getting at!
>
> I'm in the process of porting some code from IDL (Interactive Data
> Language - popular in some fields of science, but largely nowhere
> else) to Python.  Essentially it's just plotting and analyzing time
> series data, and so most of the porting is relatively simple.  The one
> stumbling block - is there an equivalent or useful replacement for the
> "common block" concept in IDL available in Python?
>
> Common blocks are areas of shared memory held by IDL that can be
> accessed easily from within sub-routines.  So for example, in our IDL
> code, we load data into these common blocks at the start of a session,
> and then perform whatever analysis on it.  In this manner, we do not
> have to continually re-load data every time we re-perform a piece of
> analysis.  They store their contents persistently, for the duration of
> the IDL session.  It's all for academic research purposes, so it's
> very much 'try this / see what happens / alter it, try again' kind of
> work.  The loading and initial processing of data is fairly time
> intensive, so having to reload at each step is a bit frustrating and
> not very productive.
>
> So, does anyone have any suggestions as to the best way to go about
> porting this sort of behavior?  Pickle seems to be one option, but
> that would involve read/write to disk operations anyway?  Any others?
>
> Kind Regards,
>
> David
>
> ---------------------------------------
> David Andrews
> Postgraduate Student, Radio & Space Plasma Physics Group
> University of Leicester, UK
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>

Hello,

I was once dealing porting some IDL code into Python. My simple solution was
the following:

Consider this sample IDL piece:

myconst   = {a: 1, b: 2}

function myfunc, x
common myconst
return myconst.a * x + myconst.b * x
end

in Python I would define a dictionary like:
myconst = {'a':1, 'b':2}

then in the function:
def myfunc(x):
      return myconst['a']*x + myconst['b']*x

saving me typing a "common myconst" and an extra "end"



-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100721/8d2b3955/attachment.html>


More information about the SciPy-User mailing list