Search code examples
pythonpython-2.7idlidl-programming-language

Runnning an IDL code with text file output in Python


I have a number of different codes which all take a text file with data as input and write to a different one as output. Three of these codes are written in Python 2.7, but one is written in IDL. My goal is to create one "master" python program which can run all of these codes, by typing "python master.py". However, because of the limitations of my system, I am unable to use the 'pyIDL' or 'pyIDLy' modules referred to in this question. Not sure if it matters, but this is using a linux command prompt.

Currently my 'master.py' code looks like this:

import os
os.system("python pycode_1.py")

os.system("idl")
os.system(".com idlcode.pro")
os.system(".r idlcode,"imputfile.dat"")
os.system("exit")

os.system("python pycode_2.py")
os.system("python pycode_3.py")

This code runs the first python code and enters IDL fine. However, it does not enter the later comands into IDL. This means that the IDL command prompt comes up, but I cannot run the IDL code that follows.

I would be very appreciative about any advice to solve this issue. Thanks in advance!


Solution

  • If you have IDL 8.5 or later, it ships with the IDL-Python bridge built in. Then your code would look something like:

    from idlpy import *
    IDL.idlcode()
    

    Hope this helps.