programming with Igor: missing features
michele.zaffalon
I know it is rude for a newcomer to complain but I hope to find an answer from more experienced users.
I have been using Igor for a couple of weeks to do data acquisition. Igor was chosen because some other people down the corridor had written most of the programs. It turned out that their programs weren't sufficient for our needs, and we tried to change them.
1) It was a surprise for instance to discover that structures cannot be defined as global. What is the way to pass around compound data, say a string, and a number? Data folders seem to much of a complexity for small compound data structures.
2) Igor looks very much like C but there is no way to cast into a data type. Suppose I want to following:
my_struct.func((generic_type) my_struct)
3) There is no array of heterogeneous elements. I understand there is no fundamental need for it, but makes programming much easier
4) I would say that for rapid prototyping, a dynamic typed language suits the situation best. Declaration of variables is always in the way and it is an interruption to the flow of thoughts.
5) The good thing is that there is the possibility of passing functions around.
The real annoyance is 1).
As a disclaimer, I have been spoiled by years of Python and Matlab, and I find it hard to use Igor.
True. You may or may not already know this, but while structures cannot be global in the sense that the structure and its data values stay in memory when a function is not executing, it is possible to pass structures from one function to another. If you don't want to use structures but want to pass around one object that contains data of different types, the typical way to do that in Igor is to use a string containing key-value pairs. You can use the NumberByKey() and StringByKey() functions to pull out values from that string. If you have such a string already and need to change the data values in it, use ReplaceNumberbyKey() and ReplaceStringByKey(). See the command help for those functions for some examples.
If your structure contains only fixed size numeric data types, such as integers and floating point values, you can use StructPut and StructGet to store a binary representation of the structure into a global string.
It's possible to use global variables, strings, etc. for data storage but then to create a structure that contains those objects which makes passing things between functions easier. For an example of how to do this, do the following (assuming you are using Igor 6 or greater):
1. Choose the Misc->Graph Browser menu item.
2. On Igor's command line, execute the following:
SetIgorOption IndependentModuleDev=1
3. Choose the Windows->Procedure Windows->Graph Browser.ipf
At the top of that file is a structure named grfBrowserGlobals and below it a function named GetGrfBrowserGlobals() that creates the global objects in their own data folder and then puts them into the structure. Functions that need access to these panel global variables can easily get them, such as is done in the function FillWListncol() at the top.
Personally, I find Python rather difficult to use. To each his own, I guess :)
September 26, 2009 at 09:51 am - Permalink
Oh. This is strange. How long have you been using Python and Igor? Programming in Igor feels worse than programming in C. And how large programs do you usually write?
September 29, 2009 at 03:37 pm - Permalink
I used Python for about a year starting around 4 years ago, but haven't used it since. At that time I had been using Igor for about 1 or 1.5 years. I had not used C at the time. Some of my Igor programs are enormous (somewhere around 100,000 lines of code). The python stuff I did was must smaller, though I was writing code that used a toolkit/module/whatever they're called which was much larger.
My dislike of python stems from two main things: 1. I don't like the idea that whitespace is part of the syntax of the language. 2. I didn't like that to do almost anything you had to import multiple modules, and I usually didn't know which ones I needed to import and so wasted a lot of time trying to do things like divide a number or something like that.
Python does have very nice object oriented features, which of course Igor lacks. I think Igor is great for people who want to be able to do some serious data analysis but who do not have extensive programming backgrounds. It gives you enough power for most things you'd want to do, but makes it unnecessary to worry about things that are really confusing and/or often cause crashes, such as providing the string object and not requiring pointers and stuff like that. For experienced programmers that are accustomed to using lower level languages such as C/C++, Igor's language can feel limiting since it's not possible to do these things. So I suspect that people's impression of the language is strongly influenced by their experience with other languages.
September 29, 2009 at 06:54 pm - Permalink