X

NV5 Geospatial Blog

Each month, NV5 Geospatial posts new blog content across a variety of categories. Browse our latest posts below to learn about important geospatial information or use the search bar to find a specific topic or author. Stay informed of the latest blog posts, events, and technologies by joining our email list!



Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

6/3/2025

Rethinking the Reliability of Type 1a Supernovae   How do astronomers measure the universe? It all starts with distance. From gauging the size of a galaxy to calculating how fast the universe is expanding, measuring cosmic distances is essential to understanding everything in the sky. For nearby stars, astronomers use... Read More >

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

5/26/2025

Whether you’re new to remote sensing or a seasoned expert, there is no doubt that large language models (LLMs) like OpenAI’s ChatGPT or Google’s Gemini can be incredibly useful in many aspects of research. From exploring the electromagnetic spectrum to creating object detection models using the latest deep learning... Read More >

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

4/28/2025

When every second counts, the ability to process geospatial data rapidly and accurately isn’t just helpful, it’s critical. Geospatial Intelligence (GEOINT) has always played a pivotal role in defense, security, and disaster response. But in high-tempo operations, traditional workflows are no longer fast enough. Analysts are... Read More >

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

4/24/2025

This blog was written by Eli Dwek, Emeritus, NASA Goddard Space Flight Center, Greenbelt, MD and Research Fellow, Center for Astrophysics, Harvard & Smithsonian, Cambridge, MA. It is the fifth blog in a series showcasing our IDL® Fellows program which supports passionate retired IDL users who may need support to continue their work... Read More >

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

2/25/2025

This blog was written in collaboration with Adam O’Connor from Wyvern.   As hyperspectral imaging (HSI) continues to grow in importance, access to high-quality satellite data is key to unlocking new insights in environmental monitoring, agriculture, forestry, mining, security, energy infrastructure management, and more.... Read More >

1345678910Last
10808 Rate this article:
No rating

Quick IDL Tricks

Anonym

In this edition of IDL Data Point, I will outline a few quick tips that I have learned throughout my experience of IDL programming.

KEYWORD_SET checks for empty strings

Although the main purpose of the KEYWORD_SET function is to check input parameters of a routine, it is also very useful for checking that a value is defined and nonzero. For example, KEYWORD_SET conveniently replaces the following two-expression line:

IF N_ELEMENTS(var) GT 0 && var NE 0 THEN ...

with one single expression:

IF KEYWORD_SET(var) THEN ...

Additionally, KEYWORD_SET will return 0 if a variable is an empty string. Similar to the expression above, the following two-line expression:

IF N_ELEMENTS(str) GT 0 && STRLEN(str) GT 0 THEN ...

can be replaced with this single expression:

IF KEYWORD_SET(str) THEN ...

!NULL to throw away a function result

Occasionally, you may want to use a function to make use of input-output parameters, but you may not care about the result. A good example is with the WHERE function:

result = WHERE(arr EQ 1, count)

In this expression, perhaps you don’t care about the actual position of the value 1, but instead you just want to know whether or not the value 1 is contained in the array; therefore, you will use the count but will never use the variable result again. Rather than carry this variable around, it can simply be thrown away by using !NULL, and IDL will never store it:

!NULL = WHERE(arr EQ 1, count)

This can also be used with the TEMPORARY function to dispose of an existing variable:

var = 1

!NULL = TEMPORARY(var)

help, var

VAR             UNDEFINED = <Undefined>

Not only is this useful for freeing memory, especially if the variable is very memory-intensive, this also helps debugging by temporarily capturing results from multiple functions in order to break expressions into multiple lines. For instance, the following line is difficult to debug because IDL will only step into one function; stepping out of the first function will return to the next line, and IDL will not step into the second function.

IF func1(var) && func2(var) THEN BEGIN

  ...

ENDIF

…and the following line has the same problem:

IF func1(func2(var)) THEN BEGIN

  ...

ENDIF

Instead, you can create a couple of temporary variables:

temp1 = func1(var)

temp2 = func2(var)

IF temp1 && temp2 THEN BEGIN

  ...

ENDIF

!NULL = TEMPORARY(temp1) & !NULL =TEMPORARY(temp2)

…and

temp1 = func2(var)

temp2 = func1(temp1)

IF temp2 THEN BEGIN

  ...

ENDIF

!NULL = TEMPORARY(temp1) & !NULL =TEMPORARY(temp2)

(Note that this is similar to DELVAR, but DELVAR is only a main-level routine and cannot be used within a routine).

 

Use RETURN or CONTINUE in place of an IF block

Sometimes code can be simplified by immediately leaving the current section of code rather than using a large conditional statement. Here are a couple of examples.

If the conditional statement is at the end of aroutine, like this

PRO myroutine

  ...

  IF(condition) THEN BEGIN

    ...

  ENDIF

END

you can simply return out of the procedure once the condition is determined to be untrue:

PRO myroutine

  ...

  IF(~condition) THEN RETURN

  ...

END

Similarly, CONTINUE can eliminate conditional blocks in loops:

FOR i=0,10 DO BEGIN

  IF(condition) THEN BEGIN

    ....

  ENDIF

ENDFOR

Instead:

FOR i=0,10 DO BEGIN

  IF(~condition) THEN CONTINUE

  ...

ENDFOR

 

Use SWITCH instead of multiple OR checks

Sometimes you may have a statement like this:

IF var EQ 1 || var EQ 5 || var EQ 8 || var EQ 11 THEN BEGIN

  ...

ENDIF ELSE IF var EQ 12 || var EQ 13 THEN BEGIN

  ...

ENDIF ELSE BEGIN

  ...

ENDELSE

Making use of SWITCH can avoid typing "var EQ" multiple times:

SWITCH var OF

  1:

  5:

  8:

  11: BEGIN

    ...

    BREAK

  END

  12:

  13: BEGIN

    ...

    BREAK

  END

  ELSE: BEGIN

    ...

  END

ENDSWITCH

Additional IDL tips

Additional tips for efficient programming can be found here:
Tips & Tricks for Efficient IDL Programming

Please login or register to post comments.