X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



3638 Rate this article:
No rating

Implementing "Macros-like" in the IDL Workbench Development Environment for versions 7.0 to 8.2

Topic

Some users of the IDL Development Environment prior to version 7.0 may be wondering how they will be able to replace the functionality of Macros in the new Eclipse-based IDL Workbench (versions 7.0 to 8.2). The new Workbench has neither a Macros menu, a Macros toolbar nor Macros hotkeys. Nevertheless, there is functionality for a new tool called "Templates", which, in some cases, can provide the kind of functionality given by IDLDE's Macros tools with about the same small number of mouse clicks or keystrokes.

This Help Article is designed to show a workflow for the creation and execution of these Macro-like Templates. It uses as examples all the Macros that are built into the pre-7.0 development environment.

Note: This Help Article was written with IDL 7.0 in mind, though it can be used in any newer version of IDL Workbench as well.


Discussion

The new IDL Workbench approach is based on a utility called "Templates" in the Eclipse vernacular. The main use of Templates is not for building Macros. Rather, they are first and foremost an important tool for speeding up coding in the Workbench Editor window. They have one interesting property, however, which has made them a viable substitute for the old IDLDE Macros utility. Namely, if they are just one line in length, they will appear as the first options when a user enters CTRL-Space on the keyboard when the Command Line is in focus. Here is a screenshot of how my own one-line Templates look on IDL 7.0:

Fig 1: Result of a CTRL-Space Entry at a blank IDL> command line after "macros" have been created

CommandLineContentAssist.png

It is important to note that only one-line Templates appear in the Content Assist pop-up list when the focus is on the command line. (Multiline templates are deliberately blocked from display in the Command Line View because the syntax for the most important Templates - IF, FOR, WHILE, CASE - is incompatible with command line programming.)

Now I can show how the Templates shown in the above image were created. The work is done in the IDL Workbench's Preferences module. Click on 'Window -> Preferences...' to open the Preferences dialog window . To quickly find the right preference page, type the search word "templates" in the 'type filter text' textbox. This will take you straight to the relevant page 'IDL->Templates'.

Entering the set of Macros that IDL by default built into every DE prior to 7.0 is easy. Except for the 'Print Var' and 'Help on Var' macros, which we discuss in the 'Limitations' section below, the built-in Macros have all been one-line calls to argument-free procedures. Thus, when you click on the Preferences dialog's 'New...' button, entering the old built-in Macros is as easy as the screenshot below:

Fig 2: The New Template Creation Dialog, where "macros" can be defined

NewTemplate.png

The following are the entries I made to replace the old IDLDE built-in Macros:

    Import ASCII:

    Name: IMPORT_ASCII
    Description: Import ASCII Datafile
    Pattern: import_ascii


    Import Binary:

    Name: IMPORT_BINARY
    Description: Import Binary Datafile
    Pattern: import_binary


    Import HDF:

    Name: IMPORT_HDF
    Description: Import HDF Datafile
    Pattern: import_hdf



    Import Image:

    Name: IMPORT_IMAGE
    Description: Import Image Datafile
    Pattern: import_image



    Demo:

    Name: DEMO
    Description: IDL Demo Program
    Pattern: demo



    Export Bridge Assistant:

    Name: IDLEXBR_ASSISTANT
    Description: IDL Export Bridge Assistant Wizard
    Pattern: idlexbr_assistant

Note that the format of the names and descriptions, e.g. the choice of lower- vs. upper-case spelling, are my own personal formatting convention; you can use your own text and capitalization routines.

LIMITATIONS: We spoke of one already; the "Pattern" may only have one line. If a Template's pattern were to have even just one carriage return at the end of its code line, that Template would not appear in the Command Line's pop-up Content Assistant. This does not mean that you cannot have multi-command templates; they just all have to be called with the IDL '&' token, as in:

print, 'Font Information:' & help, /DEVICE, OUTPUT=text & print, text[n_elements(text)-2]

which could be the pattern for a Template called "PRINT_SYSTEM_FONT_INFO". (Remember that the above must be entered on one line, not two, in the 'Preferences' dialog's 'Pattern' textbox.)

A second limitation to the Command Line Templates/Macros is that they cannot take advantage of the 'Insert Variable...' options that are available on the New Template dialog to insert "selected" text items. Those "selected" text items are not in the right focus at the moment when programmers trigger a Content Assisted Template in the Command Line window. They can, however, use user-defined variables to some advantage, if the user first highlights and copies a variable name (or other code string/substring) into their system clipboard. The PRINT_DATE example displayed in figure 1 above demonstrates. Its stored Pattern is:

print, FORMAT='(C(CDwA, X, CMoA, X, CDI2.2, X, CHI2.2, ":", CMI2.2, ":", CSI2.2, CYI5))', ${Insert_Julian_Date_var_here}

(on one line). The string token "
${Insert_Julian_Date_var_here}" is an example of a user-defined variable. When the PRINT_DATE template is selected and inserted on the IDL> command line, the substring is highlighted and ready-to-overwrite with your next Paste action. I could reuse the same user-defined variable name several times in the same Template code line, and one paste action would overwrite every instance of my user-defined variable substring. For example, this variation of PRINT_DATE:

print, 'Julian date: ', ${varname} & print, FORMAT='("Calendar Date: ",C(CDwA, X, CMoA, X, CDI2.2, X, CHI2.2, ":", CMI2.2, ":", CSI2.2, CYI5))', ${varname}

would display just one instance of "${varname}" highlighted, but the paste action overwrites both instances instantaneously. The above line, by the way can produce the below output using just a few mouse-clicks and keyboard events:

    Julian Date: 2454433.2
    Calendar Date: Wed Nov 28 17:57:52 2007

Two known small bugs: There are two known small bugs in how the selection of items in the Command Line Content Assist pop-up list window works in IDL 7.0. First, If you use your mouse to click in the pop-up list, then to complete the execution of the command it takes not one, but two, 'Enter' key presses after the template pattern has been inserted in the Command Line textbox. Second, unlike other items in Content Assist, Template items will only insert at the very beginning of a command line or after an equal sign character. These misbehaviors has been repaired in newer versions of the Workbench.

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »