Fanning Software Consulting

Coyote Library Utility Programs

The utility programs perform a variety of useful tasks for other programs in the Coyote Library. As such, they really belong in almost every category of programs.

***

ADJUSTPOSITION

This utility program allows the user to interactively adjust the plot position coordinates by resizing and moving a plot representation in a window. The return value from this function can be used to position almost any IDL graphic in a graphics window via the Position keyword. This program requires FSC_Field and FSC_PlotWindow from the Coyote program library.

The AdjustPosition program.

***

ARCSAMPLE

This small utility program re-samples a closed curve with a specified number of points at approximately equally-spaced arc intervals. I've had occasion to use it in a number of different (and strange) applications, so I've become convinced it is generally useful. :-)

***

BELL

This is a Windows-only set of programs for ringing the bell (or--more generally--for playing a sound on Windows machines. Standard sounds (ding, bells, chimes, etc.) are available in your Windows installation. More interesting (and fun) sounds are provided with the Bell program.

***

BINARY

This small utility program is used to print a binary representation of an integer. See Converting Between 8-Bit and 24-Bit Numbers for more information on how it can be used.

***

BITGET

This utility routine returns the bit value (0 or 1) of a specified bit in a number.

***

CAPFIRSTLETTER

This utility routine simply capitalizes the first letter in each word of a given string. All other letters are set to lowercase.

***

cgREVERSEINDICES

Given the reverse indices vector obtained from the Histogram command and an index number, this routine will return the indices as a result of the function. A COUNT keyword will tell you how many indices are available. The function makes it much easier to use the reverse indices vector.
   IDL> h = Histogram(cgDemoData(7), REVERSE_INDICES=ri)
   IDL> bin5Indices = cgReverseIndices(ri, 5, COUNT=count)

***

cgSCALEVECTOR

This simple utility routine allows you to scale all the points in a vector between a minimum and maximun value. The minimum value of the vector (or array) is set equal to the minimun data range. And the maximun value of the vector (or array) is set equal to the maximun data range. The program is useful for scaling latitude and longitude vectors for contour plots on map projections, for example.

***

cgSETDIFFERENCE

This utility program finds the difference between two sets of integers. In other words, it return the integers that are found in set A, but are missing from set B.
   IDL> set_a = [1,2,3,4,5]
   IDL> set_b = [4,5,6,7,8,9,10,11]
   IDL> Print, cgSetDifference(set_a, set_b)
          1  2  3

***

cgSETINTERSECTION

This utility program finds the intersection between two sets of integers. In other words, it return the integers that are found in both set A and set B.
   IDL> set_a = [1,2,3,4,5]
   IDL> set_b = [4,5,6,7,8,9,10,11]
   IDL> Print, cgSetIntersection(set_a, set_b)
          4  5

***

cgSETUNION

This utility program finds the union between two sets of integers. In other words, it return the integers that are found in set A and set B combined.
   IDL> set_a = [1,2,3,4,5]
   IDL> set_b = [4,5,6,7,8,9,10,11]
   IDL> Print, cgSetUnion(set_a, set_b)
          1  2  3  4  5  6  7  8  9  10  11

***

CLIPBOARD

This utility routine copies the contents of an IDL graphics window to the clipboard for subsequent pasting into other applications. I've successfully pasted IDL graphics windows into Framemaker, Powerpoint, Photoshop, Excel, and Word documents.

***

CONVERT_TO_TYPE

This utility program allows the user to convert input to a particular data type at run-time. It is particularly useful in preserving the data type of input data that needs to be scaled or otherwise manipulated in a data type other than its native type.

***

COUNT_ROWS

Counts the number of rows in an ASCII file. Replaced by FILE_LINES in IDL 5.6.

***

ERRORLOGGER

The purpose of this utility routine is to be able to log program errors and other textual messages to a log file during program execution. User alerts can be issued and program status monitored via methods to this object. Text can be added to the logger while simultaneously being printed in the IDL console window.

***

FIND_BOUNDARY

The purpose of this utility routine is to find the pixel boundary (or contour, if you like) about a region of interest in an image. The region of interest is given as a one-dimensional vector of image indices, such as those that are returned from the Where function. Optional keywords allow you to return the perimeter length and the area enclosed within the boundary as well. The program uses a chain-code algorithm for calculaing the boundary pixels.

A region of interest.The calculated boundary about the ROI.

***

FLOATS_EQUAL

This utility program compares to floating-point or double-precision values or arrays for equality. Arrays are equal if they contain the same number of elements, and each element is equal to the matching element in the other array.

***

FPUFIX

This utility program fixes problems with numerical data that might cause floating point underflow warning messages. Basically, values that are very close to zero (within the MACHAR XMIN limit) are set to zero.

***

GEOCOORD

This utility program converts a GeoTIFF structure containing geotags from a GeoTIFF image file (obtained by calling Query_TIFF or Read_TIFF), to a Catalyst Library map coordinate object, MapCoord. With the map coordinate object in hand, GeoTIFF images can be displayed in a completely georegistered form. Map overlays, annotation, and so forth can then be place on the image using latitude and longitude coordinates.

***

GET_OBJECT_ID

This is a simple utility program that returns a unique string identifier for a heap variable (object or pointer).

***

HELP_VAR

The purpose of this utility routine is to allow the user to display help for variables only, without the additional compiled procedures and functions given by the normal HELP command. It uses the undocumented and unsupported IDL routine Routine_Names, so it may not work for you. :-)

***

IMAGE_DIMENSIONS

The purpose of this utility routine is to have a simple way of obtaining the size and dimensions of both 8-bit and 24-bit images without a lot of fooling around. It is especially useful if you are writing device-independent image display routines.

***

INSIDE

This is a simple utility program that returns a 1 if a specified 2D point is inside a specified 2D polygon. The algorithm used is discussed in this article.

***

JD2TIME

This function converts a Julian Day Number (in the range 1 to 366) and a year into a well-formatted time string of the form 16 Mar 2008. Input can be a scalar or an array of Julian Day Numbers.

***

LEFTJUSTIFY

This utility routine will left-justify a string with respect to a specified string width. Useful for aligning columns of text in text widgets.

***

LINKEDLIST

This program creates a doubly linked list object. The items stored in the list can be any type of IDL variable. Methods are available to add, delete, count, inquire about, and move list items from one location in the list to another. I like to use the linked list to implement a multiple UNDO or "history" feature in my programs.

***

LIST_SELECTOR

This utility routine is a pop-up dialog widget that allows the user to select one or more "names" from a string array of names. I use it to give the user a list of scientific data sets inside an HDF file. This program is similar to Name_Selector, but I find it easier to use and make selections when you have a large number of selections.

The Name_Selector program.

***

MAXWINDOWSIZE

This utility program allows you to obtain the maximum size of an unobstructed graphics window in a device independent way. A graphics window constructed of this size is about as large as the display, but is not obstructed by tool bars, task bars, start bars, etc.

***

MAXMIN

This utility program allows the user to to print the maximum and minimum of a variable.

***

NAME_SELECTOR

This utility routine is a pop-up dialog widget that allows the user to select one or more "names" from a string array of names. I use it to give the user a list of scientific data sets inside an HDF file. I will read and display the selected scientific data sets from the file. This program is similar to List_Selector.

The Name_Selector program.

***

PRINTWINDOW

This simple utility just copies the contents of an IDL direct graphics window and sends it directly to the default printer, represented by the PRINTER device. Care is taken to preserve the aspect ratio of the window and to create as large an image as possible on the output page.

***

cgPROGRESSBAR

This simple object implements a "progress bar". If you compile the program, you will find an example program, named Progressbar_Example, that will show you how to operate the cgProgressBar object.

The Progressbar program.

***

RandomNumberGenerator

Unless you are careful in IDL, your random numbers may not be all that random. (See Random Numbers Are...Uh, Repeating.) This RandomNumberGenerator object will protect your random number seed so that you can continue to generate random number sequences from any of your program modules. Perhaps the best way to make random numbers available to your IDL programs is to make this random number generator object a system variable that can be accessed by any IDL program module.
   IDL> DefSysV, '!RNG', Obj_New('RandomNumberGenerator')
   IDL> randomNumbers = !RNG -> GetRandomNumbers(3)
   IDL> Print, randomNumbers
        0.089239137      0.77428782     0.069180504

Any keywords and parameters appropriate for the IDL RandomU function can be used with this object.

***

RANGEOF

This utility program returns the range ([minimum, maximum]) of a vector or array.

***

REPMAT

This utility program replicates or tiles a 2D matrix or array by an integer number of colums and rows. It is similar to the MatLab RepMat command.

***

RESOLVE_OBJECT

When save objects are restored, they are almost always restored without their methods. That is to say, the object code has not yet been compiled when an object is restored, so it is not possible to call a method on a restored object without encountering an error. This Resolve_Object program solves the problem in an efficient way by compiling object and superclass object methods only if they need to be compiled. Simply restore your object, and then pass it to Resolve_Object and you are ready to use your object normally.

***

SAVETOMAIN

This utility program allows the user to save or export a variable to the main IDL level (normally where IDL commands are typed) from within a procedure or function. I use it when debugging code and I want to save an image to the main IDL level for further inspection with other interactive programming tools.

***

SCROLLWINDOW

This program is more or less a drop-in replacement for the Window command in IDL, with this significant difference: if the requested graphics window size is larger than the display size, the graphics window is returned in a scrollable base widget so the user can scroll around in the larger graphics window. I find this program useful when I need to create large windows on my desktop machine, but still want to be able to see the full-resolution output on my laptop, which has a lower resolution display.

***

SETDEFAULTVALUE

This utility program sets the default values for positional and keyword arguments to IDL commands.

***

SORT_ND

The purpose of this program is to provide an efficient algorithm for sorting an array by individual rows. The program, described by JD Smith, the author, “as a friend to HIST_ND”, was the result of a long discussion on this topic on the IDL newsgroup. This was the most efficient algorithm of several that were offered and discussed. It is offered here with JD's permission.

***

STR_SIZE

This function allows you to calculate a character size for a particular string, so that the string width is close to a specified target width in the current graphics window. The function is particularly useful with respect to sizing strings in resizeable graphics windows. The target width is specified in normalized units.

***

TEXTLINEFORMAT

This small utility program can take a long line of text and break it into a string array at some arbitrary maximum length. I find it useful for breaking up a long error message produced with MESSAGE into a string array suitable for display in DIALOG_MESSAGE.

***

TRANSFORM_VOLUME

There has been extensive discussion lately on the IDL newsgroup about the most efficient method for rotating volumetric data. Several algorithms were tried and discussed. This algorithm, by Martin Downing in the UK, is the current favorite. It processes the volume in "chunks", which could, in theory, make it suitable for parallelization.

***

UNDEFINE

This is a simple utility program to delete or undefine a variable from within an IDL program. It is a more powerful version of DelVar, which can only be used at the main IDL level.

***

WINDOWAVAILABLE

This small utility program can determine if a specified IDL graphics window is currently open and available to receive graphics commands.

***

XCD

This simple utility routine for changing directories is written by Paul Sorenson and included here with his permission. It works on VMS and Windows machines only. This is one of those incredibly useful programs that make you think: "Now how come I didn't think of that!" It is an excellent example of how to write a widget program with an object-oriented design. All the programs you need are available in this zip file.

The XCD program.

Version of IDL used to prepare this article: IDL 7.0.1.

Last Updated: 21 March 2011