From list_email at icloud.com Mon Oct 8 22:48:17 2018
From: list_email at icloud.com (list_email at icloud.com)
Date: Mon, 08 Oct 2018 22:48:17 -0700


Subject: Writing Igor experiment from Python?
In-Reply-To: <18BA2F58-C30B-448C-9EA5-40245F456AA7@anl.gov>
References: <18BA2F58-C30B-448C-9EA5-40245F456AA7@anl.gov>
Message-ID: <23F4A4D4-D229-4D6E-A92A-6711565638C1@icloud.com>


> On Sep 2, 2018, at 6:33 PM, Ilavsky, Jan <ilavsky at aps.anl.gov> wrote:
>
> Hello,
>
> colleague of mine would like to write Igor experiment with data and graph recreation macro - the type of Igor Experiment you get when you run ?Save Graph Copy??. From his python package. To provide better plotting tool for users - I think he does not want to provide more graphing support in it.
>
> Anyone has done something similar? Any chance there is available solution?
>
> Search on web and Wavemetrics web site did not help, missed something?
>
> Note:
> 1. I personally would prefer dump data in HDF5 and write Igor support to load and graph that. More flexible, but requires install of that support in Igor.
> 2. I know about http://blog.tremily.us/posts/igor/, but that is read data FROM Igor TO Python, I need the other way around.
> 3. I read the PTN003 on format of pxp file. One of the reasons I am asking for help ;-)
>
> Sincerely
>
> Jan
>
Sorry for the late reply.

I was faced with this problem a while back and found that the ?Igor text file? approach suggested by others did not suit my needs?it has limitations that I did not like. Here are the salient facts relating to my solution:

(1) Igor can accept commands from the command line.

(2) Many languages including C and Python can execute command-line instructions from within the language.

So here is what I did:

(A) Locate the Igor executable in your file system.

(B) Construct the desired Igor command as a text string which starts with the path to the executable and ends with the desired Igor command, and use your language?s ability as in (2) to send the command to Igor relying on (1).

That?s it. It?s really easy. The hardest part is trying to figure out how to pass quotes through your language into the command string and into Igor, but you can do that. Now you can control Igor from your language and make it do anything you want at any time.

I wrote some utility programs in my language to handle redundant stuff and to take away the pain of the quotes mentioned above, including high-level commands for making plots. I also wrote some functions in Igor to handle some of the work of making plots, numbering the plots, tiling the plots, etc.

So a typical usage from my language looks like this:

(a) Compute some data.

(b) Call (in my case) the function Simple_Plot_Igor, written in my language.

That?s it.

Simple_Plot_Igor does two things. (Let?s assume we?re doing an x-y plot):

(i) Writes the x and y data to a disk file using any format that Igor can read. Binary is good. Text is good. Headers are good. Whatever.

(ii) Issue a command to Igor using (2) that tells Igor to read the data and plot it.

That?s all. You can add bells and whistles to your heart?s desire, including numbering the plots, tiling windows, etc.

I have written my version in Ada which you will not because you don?t like Ada. That?s OK. Use Python or C or whatever you like. This approach is fast and flexible. It doesn?t require learning any third-party APIs or whatever. You can send Igor any command you like at any time, not just plotting commands. You could even use Igor as an external computational engine, returning results to your program. It just works.

I would be happy to share my code.

FWIW, you can also make Igor issue commands as though they were typed on the command line. See ExecuteScriptText; on MacOS it might look like this:

Function Execute_Shell(Unix_Command)
String Unix_Command
String Igor_Command = "do shell script \"" + Unix_Command + "\""
ExecuteScriptText Igor_Command
End // Execute_Shell

Jerry