GDL: Beginner Code Examples

This entry is part 3 of 4 in the series GDL Gnu Data Language

The Gnu Data Language is an interactive interpreter/incremental compiler for the GNU Data Language, which is primarily used in scientific, astronomical, medical and geo-science data processing applications. It supports graphical output and is intentionally designed to be highly compatible with the commercial IDL language. GDL is a free IDL (Interactive Data Language) compatible incremental compiler (ie. runs IDL programs). For a list of functions / compatability try this list.

After installation and choosing an editor it is time to delve in to some code. In the “Beginner Code Examples” below, I am the beginner so no questions about programming please!

Example 1 – Command Line
Open a terminal (e.g. Applications > Accessories > Terminal ) and start GDL with command gdl on the command line.
A simple plot is displayed with the following GDL commands:

GDL> orig = sin((findgen(200)/35)^2.5)
GDL> plot,orig
GDL> exit

GDL Code Example Plot

Example 2

GDL> a=2
GDL> b=a*2
GDL> print, b
4

Example 3

In this example we are first going to get an image file from Wikipedia to use in our example, then create a .pro file using a simple text editor and finally compile and run the .pro file:

GDL> .COMPILE get_image.pro
% Compiled module: GET_IMAGE.
GDL> get_image

A window should be displayed possibly not displaying much of the moon image but I don’t yet know the purpose of loadct except that it accepts values from 0 to 40 so you could try a few of these to see what they do – I’m on the steeper end of a learning curve here.

Example 3

It is also possible to run .pro files in batch mode without compiling. Just omit the .pro extension and prefix with the @ symbol:

GDL> @get_image

Example 4

Now at the bash command line try:

gdl < circle_area.pro | grep -v “^%”

Here we are feeding the .pro file into GDL and grepping to remove (-v) any lines beginning(^) with the % sign to avoid getting lines like:

Potential Pitfalls

Not all IDL functionality is available yet in GDL. For example, I had issues with the following:

  • % Function not found: QUERY_IMAGE –  I could not get my example code to use this function: Query_image
  • Function not found: DIALOG_PICKFILE  – The function for a GUI to choose a file. I couldn’t find this so it is possibly not part of GDL.
  • GDLFFDICOM__ASSOC::ASSOC: No pixeldata tag found – I received this error when trying to read a dicom file I was given e.g. dicom_obj -> Read(‘Sagittal_slice’) . However, when I used a dicom image downloaded online it worked fine. Possibly some header metadata missing on this dicom image?

 

Series NavigationGDL Editors on LinuxGDL: Taking It Further

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">