Gnu Data Language GDL

© Fernando Caracena, 2015

The Gnu Data Language (GDL) is an emulation of the commercial scripting language called IDLTM. This was my favorite software tool when I was doing weather research. The IDLTM language was developed at LASP of the University of Colorado. It is used extensively by Astronomers who have quite a user’s group. There are many tips on using IDL and routines available, for example in Coyote’s Guide to IDL Programming. If you have some experience using BASIC/FORTRAN type programming, then IDL could be fun to play around with, and perhaps, use. Unfortunately, IDL is très cher to buy. Perhaps if you are Warren Buffet that is no obstacle, but you might have other interests and important matters to attend to. For the rest of us, the cost, in kilo-bucks is a big obstacle for a mind appliance. This is where GDL comes to the rescue. It is open source and available for easy download on most Linux distributions through the package distribution’s package manager. However, GDL is not a complete emulation of IDL. Some nifty IDL built in commands are missing in GDL. So, if you read IDL literature and try to reproduce results given in examples and tutorials, you might find that some straightforward commands just do not work.

The purpose of this post is not to document a bunch of commands or to give the user a tutorial on the subject. Rather, its purpose is to motivate the reader by giving that person some idea of what is possible to do with GDL. But, before doing that let us fill in some definitions.

IDLTM stands for Interactive Data Language. Like Python, it is a scripted-interpreted, computer programming language. I like using such a language because I can get instant gratification from firing commands into the command line. Sometimes, when I am working on an idea and I am hot on its trail, pausing to compile the source code and link it to object files is such a drag! Also in the past, the problem in using a variation of BASIC, such as Quick Basic, was that it was slow.

IDLTM is optimized for vector operations, so that if you configure your computations in a vectorized form, you get both speed of a compiled language and the instant gratification of an interpreted language. GDL shares operating characteristics with IDLTM.

Subroutines and function written by the user in the script are compiled into a byte code, which give them a fast execution. Also, outside subprograms and routines can be brought into the operating environment so that they can be called alongside the system routines. In this way, one can bring in Numerical Recipes and gain the power of man years of coding.

Another major advantage of IDLTM and GDL in my book are the way that they handle the housekeeping functions of programming, which allow the developer/programmer to plow ahead with coding his ideas undistracted by housekeeping details, which the operating system handles for him.

The discussion below continues in terms of GDL, although it applies to IDL as well.

Mechanics of Running GDL

First, bring up a console window to enter you command lines. If you are in a Linux system, you will get a prompt in that window that looks like the following:

USER@Your_Computer:/$ .

Assumming that you have already installed GDL, then at the prompt, type gdl. In that case, you will get a message and a new prompt, something like the following:

GDL - GNU Data Language, Version 0.9.6

- For basic information type HELP,/INFO
- Default library routine search path used (GDL_PATH/IDL_PATH env. var. not set):
+/usr/share/gnudatalanguage/lib
- No startup file read (GDL_STARTUP/IDL_STARTUP env. var. not set).
- Please report bugs, feature or help requests and patches at:
http://sourceforge.net/projects/gnudatalanguage/

GDL>

.

You are now ready to do computations.

Examples of GDL code

A simple example of the speed and convenience of GDL is to generate a thousand (and one) element array along the x-axis; use this array as a variable in a function, which gives an array of equal size, y ; and plot y against x by entering the following lines after the GDL prompt, each line followed by your keyboard ‘enter’:

x = 0.01*(findgen(1001)-500.)

y = sin(10.*!pi*x)*exp(-x*x/2.)
plot, x, y
.--

Listing 1

The simple three line program (Listing 1) displays a mathematically constructed wave packet, which is of interest in applications of quantum physics. The results, however automatically produced, are rather austere looking—a white wavy line against a black background. Also, you had no control over the size of the plot. A few simple tricks can vastly improve the product.

Simplification

Some very simple but useful routines simplify the details of plotting and customization.

The GDL "window" routine defines a blank output window having a black background, which is identified by a number and has a pixel specified width-hight size. The command is long for what it does and requires typing out the proper details in absolutely correct punctuation. This is great for left-brained people, but intuitive types want a simpler code, such as the one I show below:

pro win,n,sx,sy
window,n,xsize=sx,ysize=sy
end

The results of applying win, still gives a window numbered n and pixel sized sx by sy. It is a much shorter command, and all that is required is to enter three numbers after "win" in the proper order. Unfortunately, the win[dow] still has a black background. I like to simplify functions that are frequently used, in this case both for creating windows, and plotting on them. A couple of handy rountines that I like to use are zip and flameit, which are defined as follows:

pro flameit, clr
polyfill,[0,1,1,0,0],[0,0,1,1,0],color=clr,/normal
plots,[0,1,1,0,0],[0,0,1,1,0],color=0,/normal,thick=5
end

Listing 2

pro zip
flameit,rgbc(255,255,255)
end

Listing 3

These two routines (Listings 2 and 3) give the program a very simple appearance in code, as follows (Listing 4) :

Fig. The graphic output of the listed program--A Wave Packet.

 win, 0, 800, 400

zip


plot, [min(x), max(x)], [min(y),max(y)],color=0,thick=2,charsize=2,charthick=2,/noerase,/nod
ata, xstyle=1,ystyle=1, title='Wave Packet'


oplot, x, y, color=0, thick=2

.

Listing 4


Explanation of Listing 4

The first line creates a window, numbered zero, which is 800 pixels across by 400 pixels high.

The second line clears the black screen to white.

The third line, long and continued, creates the x and y axes and labels the plot, 'Wave Packet'. A similar command could have labeled both the x and y axes.

The fourth line plots the graph on the same scale as the declared axes. Note that the program uses ‘oplot’ rather than ‘plot’. The command ‘plot’ would have just ignored all the previous defining commands redefining all these values to some defaults; cleared the screen to black; and plotted the graph to the real color selected, which is computed by the RBGc function.

A Final Simplification

Let’s say that you saved your main program (Listing 4) as ‘WavePacket.pro’. Note that GDL is expecting saved and called routouines to end in the suffix ‘.pro’. You can then bring up the wave packet plot at any time from the command line by using the following statement at the command line:

GDL> @WavePacket

. That’s it! All your work is wrapped up in one command.

What is Possible

What is shown above is a very simple task. I have used IDL to solve partial differential equations by techniques such as relaxation methods, the results of which I have displayed as color against geographic map backgrounds. A simpler task, of contouring data from sources irregularly distributed in space is presented as an example (Fig. 2).

Fig. 2 An analysis of the height contours (black), Temperature (°C) contours red lines (dashed below 0°C), and dew point temperature depression (DD) on the 500 mb pressure surface. DD less than 6°C is shaded light green, and less than 3°C dark green.

I generate figures, such as Fig.2, daily to follow the weather. The example presented here is for the morning of a day when a significant weather event affected the Front Range area of Colorado. Colorado Springs for example, had heavy rain, hail and flooding on that day (see here). Further, the storms continued northward to envelope the Boulder area later in the evening and brought us the second significant rain in all of August.  The storms came up almost like a bolt out of the blue. Also note in the figure the surge of moist air associated with a tropical wave moving westward into the Gulf of Mexico, which spawned Hurricane Hermine.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *