Previous Application Programming: Creating and Running Programs in IDL Next

Creating a Simple Program

In this section, we'll create a simple "Hello World" program consisting of two .pro files. Start the IDLDE and complete the following steps:

  1. Open a new Editor window. Start the IDL Editor by selecting File New or clicking the New File button on the toolbar.
  2.  

  3. Create a procedure. Type the following in the IDL Editor window:
  4. PRO hello_main  
       name = ''  
       READ, name, PROMPT='Enter Name: '  
       str = HELLO_WHO(name)  
       PRINT, str  
    END  
    

     

  5. Save the procedure. To save the file, select File Save or click Save button on the toolbar. Save the file with the name hello_main.pro in the main IDL directory (which the Save As dialog should already show).
  6.  

  7. Create a function. Open a new Editor window by selecting File New, and enter the following code:
  8. FUNCTION hello_who, who  
       RETURN, 'Hello ' + who  
    END  
    

     

  9. Save the function. Save the file as hello_who.pro in the main IDL directory. This simple program, consisting of a user-defined procedure, calls a user-defined function.
  10.  

  11. Compile the programs. Compile hello_main.pro and hello_who.pro programs by selecting Run Compile All.
  12.  


    Note
    You can also type .COMPILE hello_who.pro, hello_main.pro at the IDL command prompt to compile the files. With functions, the compilation order does matter. See Compiling Your Program for details.

     

  13. Run the program. Select Run Run hello_main.
  14.  

  15. Enter a name. Type a name at the IDL command line, which now reads "Enter Name" and press the Enter key. This passes the text to the function hello_who. The "Hello name" string is returned to the procedure and printed in the Output window.

  IDL Online Help (March 06, 2007)