

Dáithí Stone's Climate Site

A Library of IDL Programs


This page lists a compilation of IDL code made available for public use.
Please report any bugs to dastone@runbox.com.
We welcome any modified or new routines you would like to add.
We would like to know if you have found any of these routines useful.
Maintained by: Dáithí Stone (dastone@runbox.com)
Last modified: 23 March 2020 by idl_lib_html.pro.
Number of routines: 171
Contributors: Myles Allen, Benjamin Grandey, Daithi Stone, Edward Wiebe
Licence: The IDL routines available from this page are free for noncommercial use under the terms of this Creative Commons License unless otherwise noted in the routine.





Complete packages

The following packages are available with all required files contained in a single archive file.

Full IDL routine library
The full collection of code provided in this library, omitting the Optimal Detection Package v2.1 code.
Click here for a .tar archive.
Click here for a .zip archive.
These dependencies external to IDL are also required: https://github.com/axismaps/colorbrewer/tree/master/export/gpl, ;gauss_fit_eqn.pro, ;gev_fit_eqn.pro, ;gpd_fit_eqn.pro, ncdump, cdo, ncks, wget, c20c_dtos_v2_map_institute.xml', date.

Optimal Detection v3.1.2
This is the current version of the optimal detection code, which performs optimal fingerprinting in a multiple linear regression. This code works in both IDL and GDL.
Click here for a .tar archive.
Click here for a .zip archive.

Optimal Detection v2.1
This is on old version of the optimal detection, which performs optimal fingerprinting in a multiple linear regression. This code works in both IDL and PVWAVE, and is the last version to work in PVWAVE.
Click here for a .tar archive.
Click here for a .zip archive.

C20C dtos v2
The collection of code used for generating the sea surface temperature and sea ice concentration input data used in the C20C+ D&A project simulations.
Click here for a .tar archive.
Click here for a .zip archive.
These dependencies external to IDL are also required: cdo, ncdump, ncks, wget, c20c_dtos_v2_map_institute.xml', date.




News

 20170609: This library of IDL routines was permanently moved from http://www.csag.uct.ac.za/~daithi/idl_lib.
 See bottom for more update information.

Recent updates





Array


add_dim
This function returns an array with extra dimensions added, filled with copies of the original array.
Modified 20180813

ARRAY_TOTAL
This function does more flexible array integration than IDL's total.
Modified 20180828

DIMENSION
This function returns the dimension of an array. It returns 0 if the input variable is scalar.
Written 20000705

INTERVAL_CALC
This function calculates a convenient maximum value for a data set.
Modified 20010111

ISIN
This function will tell you whether or not a token is contained in an array.
Modified 20110222

LENGTH
Find the length of a vector (or the longest dimension of an array).
Written 20020609

Nearest_Index
Search for the index of the value nearest to x in the vector mx.
Written 20021129

NONUNIQ
Return the subscripts of the nonunique elements in an array.
Written 20020723

shuffle
This function shuffles the values in an array.
Modified 20191031

Slice
Slice a two dimensional array out of a three dimensional array.
Written 20000609




C20C dtos v2


c20c_dtos_v2_adjust_sic
This procedure adjusts the sea ice coverage from an input data set by interpreting the effect of a deltaseasurfacetemperature field on input coverage and sea surface temperature.
Modified 20181126

c20c_dtos_v2_adjust_sic_diag
This procedure produces a postscript set of plots which report on the sea ice adjustments performed in c20c_dtos_adjust_sic.pro.
Modified 20171122

c20c_dtos_v2_adjust_sic_pall2007
This procedure returns the sea ice concentration versus sea surface temperature function used in Pall (2007) and Pall et alii (2011).
Modified 20171013

c20c_dtos_v2_adjust_sic_stonepall2018
This procedure returns the sea ice concentration versus sea surface temperature function used in Stone and Pall (2018) and used in the C20C+ D&A project NatHist/CMIP5est1 estimate of a world without human interference with the climate system.
Modified 20180817

c20c_dtos_v2_download_obs
This procedure downloads observational data from an ftp or html address and converts nonNetCDF data to NetCDF format.
Modified 20181112

c20c_dtos_v2_make_delta
This procedure produces the deltaSST fields for use in the C20C+ Detection and Attribution Project experiments and the Weather Risk Attribution Forecast.
Modified 20190918

c20c_dtos_v2_make_delta_driver
This procedure runs the specific calls of c20c_dtos_v2_make_delta.pro required to produce deltaSST fields used by the C20C+ Detection and Attribution Project, the Weather Risk Attribution Forecast, and the HAPPI project..
Modified 20190417

c20c_dtos_v2_make_delta_driver_scripts.txt
This file contains scripts for generating C20C+ D&A deltaSST attributable warming estimates using the c20c_dtos_v2_make_delta_* collection of routines.
Written 20181212

c20c_dtos_v2_make_tossic
This procedure generates sea surface temperature and sea ice concentration data for use in the C20C+ Detection and Attribution project.
Modified 20190318

c20c_dtos_v2_make_tossic_driver
This procedure runs c20c_dtos_v2_make_tossic.pro to generate standard versions of sea surface temperature and sea ice concentration data for use in the C20C+ Detection and Attribution project.
Modified 20190318

c20c_dtos_v2_make_tossic_driver_scripts.txt
This file contains scripts for generating sea surface temperature and sea ice concentration files for use in the C20C+ D&A project.
Modified 20190318

c20c_dtos_v2_map_delta_scenario.xml
This library contains settings for default attributable warming estimates used in the C20C+ Detection and Attribution project.
Modified 20190424

c20c_dtos_v2_map_experiment.xml
This library contains lists of details concerning the various experiments performed under the C20C+ Detection and Attribution project.
Modified 20181116

c20c_dtos_v2_map_institute.xml
This library contains lists of institutions contributing to the C20C+ Detection and Attribution project as well as various properties of those institutions.
Modified 20180302

c20c_dtos_v2_map_model.xml
This library contains lists of models contributed to the C20C+ Detection and Attribution project as well as various properties of those models.
Modified 20190315

c20c_dtos_v2_map_scenario.xml
This library contains lists of scenarios contributed to the C20C+ and Attribution project from various models.
Modified 20190318

c20c_dtos_v2_unnan
This procedure fills in NaNs in a 2dimensional spatial field, contained in a 2dimensional or 3dimensional array, with the value of the spatially nearest nonNaN neighbours.
Modified 20170920




Calendar


convert_time_format
This function converts a time vector from one format to another.
Modified 20190829

CORRECT_DATE
This function returns a corrected version of the input date, when the days are out of the range for the month.
Modified 20171010

MONTH_DAY
This function returns the first and last days of the month.
Modified 20100205

MONTH_NAME
This function returns the name of the desired calendar month.
Modified 20100810

MONTH_NUM
This function returns the month number given the name.
Written 19991014

MONTHS_TO_SEASONS
This function extracts seasonal data from monthly data.
Modified 20080318

SEASON_NAME
This function returns the initials of the months contained in a given season.
Modified 20100105




File system


LS
This procedure runs the UNIX ls (list files) command.
Modified 20000629

PathTo
Find a file in the $IDL_PATH search tree.
Modified 20020306




Geographical


convert_rotated_grid
The functions transforms data from a rotated polar grid to an unrotated polar grid, from unrotated to rotated, or from rotated to rotated.
Written 20191217

EXTRACT_REGION
This function extracts regional data from a [longitude,latitude,time] data file.
Modified 20100309

GEO_DIST
This function returns the great circle distance (in km) between two geographical points.
Modified 20020812

GEO_MEAN
This function returns the coordinates of the central geographical point of the input points.
Written 20150115

GEO_MID
This function returns the coordinates of the geographical point midway between the two input points.
Modified 20020812

ipcc_regions
This function returns the coordinates of the boxes defining the requested geographical regions selected for use in the IPCC AR4 of WG1.
Modified 20090930

LAND_MASK
This function creates and returns a global gridded land mask of the desired resolution.
Modified 20060725

MASK_LONLATMONTH
This procedure returns a version of the input lonlatmonth data set Data which has been masked according to Mask and other selected criteria. It will also do some area and time averaging.
Modified 20070122

MASK_LONLATTIME
This procedure returns a version of the input lonlattime data set Data which has been interpolated to the grid of Mask and/or masked according to Mask.
Modified 20110330

plot_compass
The procedure plots a compass for use in maps.
Written 20191218

PROCESS_LONLATMONTH
This procedure returns a processed version of the input lonlatmonth data set. Processing includes lonlat interpolation masking, taking anomalies, and taking averages.
Modified 20110330

ROTATE_POLE
Convert geographical coordinates to a new polar coordinate system with a different North Pole.
Written 20150114




Graphics


ARROWS
This function plots arrows onto the current window.
Modified 20180906

B_PLOT
This procedure contours a data by drawing each element of an array as a rectangular box.
Modified 20091208

BAR_GRAPH
This procedure plots bar graphs.
Modified 20030616

BLOCK_CELL
This procedure draws a boxed contour plot, where boxes are assigned a level instead of calculating smooth boundaries for the levels.
Modified 20200224

BOX
This procedure draws a rectangular box on the screen.
Modified 20091208

BULLET_LEGEND
This procedure plots a legend for bullet plots.
Modified 20000912

BULLET_PLOT
This procedure draws bullet plots with bullets whose sizes are scaled to values in an input vector.
Modified 20010306

CHOOSE_LEVELS
This function chooses convenient values for contour levels.
Modified 20020602

CIRCLE
This function returns the x and y coordinates of a circle.
Modified 20041126

COLORBREWER
This procedure implements the colour palettes suggested at http://colorbrewer2.org.
Modified 20180815

contour_legend
This procedure plots a legend for colourcontour plots.
Modified 20191218

CONTOUR_WORLD
This procedure draws a colour contour of a data field over a world map.
Modified 20181008

ERROR_BARS.pro
This procedure plots error bars over plotted data.
Modified 20060217

Fill_Regions
Fill regions with a colour on a plot of data from the UVic Climate Model.
Written 19990212

LINE_LEGEND
This procedure plots a legend for line plots.
Modified 20150108

Outline_Regions
Draw a line around regions on a contour plot.
Written 19990212

PIE.pro
This procedure plots a pie chart.
Modified 20050805

PNG_START
Prepare IDL to create a .png file using the zbuffer device.
Modified 20020328

PNG_WRITE
Write out the contents of the currently active window as a .png file. If PNG_START is called before the graphics are generated the current device will be the zbuffer.
Modified 20020429

tek_color_spectrum
This function returns colour indices that make a spectrum out of the TEK_COLOR colours.
Modified 20040721

TIFF_START
Prepare IDL to create a .tiff file using the zbuffer device.
Written 20020429

TIFF_WRITE
Write out the contents of the currently active window as a .tiff file. If TIFF_START is called before the graphics are generated the current device will be the zbuffer.
Written 20020429

TRUECOL_ROTATE
This a wrapper for the rotate function. Rotate doesn't like arrays from true colour images.
Written 20001218

TWO_AXES
Demonstrates how to make a plot with two different yaxes.
Modified 20020110

windrose
This function plots a wind rose given twodimensional data.
Modified 20181008




Input/Output


CLEAR
This procedure clears the active IDL display window.
Modified 20000714

CLS
This procedure clears the IDL terminal window.
Modified 20000714

LANDSCAPE
This procedure sets the plotting output to landscape orientation.
Written 20000613

markup_read
This procedure reads entries from an input file following a markup language format.
Modified 20190114

NCDF_FILEINQ
Print a table of the contents of an ncdf file to the terminal and/or save the structure of the file in a structure!
Modified 20020809

netcdf_read.pro
This function reads and returns the desired data variable from the desired NetCDF file.
Modified 20181128

netcdf_read_geo.pro
This function reads and returns the desired geographical data variable from a NetCDF file. It also returns dimension variables and can do some data manipulation, thus acting as a driver of netcdf_read.pro for geographical data.
Modified 20200316

netcdf_read_geo_multitime.pro
This function reads and returns the desired geographical data variable from a collection of NetCDF files which differ only in the time period included. It also returns dimension variables and can do some data manipulation, thus acting as a driver of netcdf_read.pro for geographical data.
Modified 20190917

netcdf_read_geo_varinfo.xml
This library contains lists of alternate names and standard units for various variables and dimensions.
Modified 20200312

netcdf_read_metadata.pro
This function reads and returns the list of variables stored in the requested NetCDF file.
Written 20171130

netcdf_write
This procedure writes data from one or more variables and their associated dimensions and metadata to a NetCDF file.
Modified 20190517

netcdf_write_metadata.pro
This procedure returns default NetCDF attribute values for a requested list of variables.
Modified 20171224

PORTRAIT
This procedure sets the plotting output to portrait orientation.
Written 20000613

PS_CLOSE
This procedure closes a postscript file for plotting output.
Written 20000613

PS_OPEN
This procedure opens a postscript file for plotting output.
Written 20000613

READ
This function extracts column delimited data (whitespace between columns) from a file and loads it into an array It is intended to work with integer or floating point data but will always read the data as if it were floating point.
Modified 20090929

SREAD
This function extracts column delimited data (whitespace between columns) of data from a file and loads it into an string array.
Modified 20180528

TEE
Mimics the Unix tee command allowing output to go to the terminal and to a file.
Written 20000829

W_CLOSE
This procedure closes an existing plotting window.
Written 20000613

W_OPEN
This procedure opens a new plotting window.
Written 20000613




Mathematics


DECIMAL_PLACE
This function returns the decimal place of the first significant digit.
Modified 20020206

FACTORS
This function calculates the prime factors of natural number.
Written 20000824

FIRST_DIGIT
This function returns the first significant digit.
Modified 20010111

IMAG
This function returns the imaginary component of a complex number.
Written 20000609

ODD
This function returns 1 if the input is odd, 0 otherwise.
Modified 20000823

partial_factorial
This function calculates the partial factorial n!/(nm)!.
Written 20041122

PLUS
This function returns 1 if the input is positive, 0 otherwise.
Modified 20000710

REAL
This function returns the real component of a complex number.
Written 20000609

SIGN
This function returns the sign of the input variable.
Modified 20111106




Miscellaneous


BREAKLINE
This function breaks a line of text into pieces less than or equal to a maximum length. Text is broken on whitespace.
Written 20020508

CONSTANTS
This procedure returns the values of some absolute constants.
Modified 20020809

HMAN
Play the "Hangman" word guessing game. Each time you issue the hman command a single game is played (guess one word).
Written 20010430

IDL_LIB_HTML
This procedure creates the web page listing of a library's IDL utilities.
Modified 20190313

PRINTP
Print text to the terminal and suppress the carriage return at the end of the line. This allows more characters to be added to the same line.
Written 19990929

SET_EDGE
Fill the boundary of a two dimensional array with a value.
Written 20020411

SWAP
This procedure will swap the values of two variables.
Written 20020212

trace_dependency
This procedure plots a diagram showing the dependency tree of the requested IDL programs and returns the list of dependencies.
Modified 20180810

VAR_TYPE
This function returns the IDL code of the variable type.
Modified 20111106




Optimal Detection Package v2.1


CPAR_OLS
This function computes 1D and mD parametric confidence intervals from ordinary least squares regression.
Modified 20040628

CPAR_TLS
This function computes 1D and mD parametric confidence intervals from total least squares regression.
Modified 20040628

FCDF
This function does not do anything but its existence allows the GENDETEC family of programs to be compatible with PV_Wave.
Modified 20040628

GENDETEC
This procedure computes confidence intervals on undetermined model parameters by multiple regression using observational constraints.
Modified 20040628

INVERT1K
This function computes the inverse of a real square symmetric matrix and checks the solution.
Modified 20040628

LINMOD
This function performs multiple linear regression given an optional prewhitening operator, externally specified noise realisation, and optional noise on the independent variables.
Modified 20040628

REGOLS
This function performs multiple ordinary least squares regression.
Modified 20040628

REGTLS
This function performs multiple total least squares regression.
Modified 20040628

SVDPVW
This procedure is a singular value decomposition (SVD) routine for PVWave.
Modified 20040628

TOTAL_1D
This function is a manual implementation of the IDL total function to get around the fact that PVWave cannot cope with totalling along a dimension.
Modified 20040628




Optimal Detection Package v3.1.2


algebra_to_matrix
This function parses algebraic statements into a matrix for use in matrix algebra.
Modified 20120215

BETAS_HIST
This function produces ndimensional histograms of the beta scaling factors from the gendetec Optimal Detection Package.
Modified 20120124

CPAR_OLS
This function computes 1D and mD parametric confidence intervals from ordinary least squares regression.
Modified 20120214

CPAR_TLS
This function computes 1D and mD parametric confidence intervals from total least squares regression.
Modified 20120926

DEMO_GENDETEC
This function is a simple example demonstration of how to use the Optimal Detection Package. All inputs are optional.
Modified 20120124

GENDETEC
This procedure computes confidence intervals on undetermined model parameters by multiple regression using observational constraints.
Modified 20120315

GENDETEC_COMPATIBILITY
This procedure is a wrapper for gendetec.pro v3.1.0 which allows simultaneous use of the v3.0.0 and v3.1.0 input/output keyword parameter names.
Modified 20120315

LINMOD
This function performs multiple linear regression given an optional prewhitening operator, externally specified noise realisation, and optional noise on the independent variables.
Modified 20120215

REGOLS
This function performs multiple ordinary least squares regression.
Modified 20111106

REGTLS
This function performs multiple total least squares (TLS) regression, including the extension of the errorinvariables (EIV) approach.
Modified 20120926

SPHERE_SAMPLING
This function determines the number of points to sample along the surface of a multidimensional sphere based on a suggestion.
Written 20111014




Physics


POTEM
Compute the potential temperature of a parcel of seawater at a reference pressure using the Bryden 1973 polynomial for adiabatic lapse rate and Runge=Kutta 4th order integration algorithm.
Written 19990331

STANDARD_ATM
This function calculates the pressure at a given altitude in the troposphere, assuming a uniform, dry atmosphere.
Modified 20020812




Statistics


dbinom
This function computes the density of the binomial distribution.
Written 20191011

gauss_fit
This function estimates the parameters of the Gaussian distribution given a set of data.
Written 20200117

gev_cdf
This function calculates the cumulative distribution function of the Generalised Extreme Value distribution for a given set of parameters.
Written 20191106

gev_fit
This function estimates the parameters of the Generalised Extreme Value distribution for a set of block maxima.
Written 20191106

gev_pdf
This function calculates the probability density function of the Generalised Extreme Value distribution for a given set of parameters.
Written 20191106

gpd_cdf
This function calculates the cumulative distribution function of the Generalised Pareto distribution for a given set of parameters.
Written 20191106

gpd_fit
This function estimates the parameters of the Generalised Pareto Distribution for a set of values exceeding a threshold.
Written 20191105

gpd_pdf
This function calculates the probability density function of the Generalised Pareto distribution for a given set of parameters.
Written 20191106

MODE
This function calculates the mode of an input array.
Written 20161020

PDF
This procedure estimates the one or two dimensional probability density function of a given data set.
Modified 20120124

PDF_TO_CDF
This function estimates a cumulative distribution function from a given probability density function.
Modified 20110413

QUANTILE_THRESHOLD
This function estimates the thresholds in the input data array corresponding to the specified quantiles.
Modified 20120705

SAMPLE_PDF
This function randomly samples a given probability density function.
Modified 20110413

THRESHOLD_QUANTILE
This function estimates the quantiles of the given thresholds in the input data array.
Modified 20120705




Strings


EXPAND_TABS
Replace tab characters in a text string with spaces.
Written 20010402

latex_char.pro
This function substitutes LaTeX character codes for nonEnglish characters.
Written 20180603

ORDINAL
This function returns the ordinal value of the input number.
Modified 20010215

str
This function converts an integer or floating point number to a string.
Modified 20191011

STRING_FROM_VECTOR
This function converts a vector to a single string containing the vector's entries separated by commas.
Modified 20040616

string_substitute
This function substitutes a character sequence within an input string.
Written 20180603

STRMERGE
Merge two string arrays.
Modified 20020723

WRITTEN_NUMBER
This function returns the written form of the input number.
Written 20010215




Time series analysis


CROSS_SPEC
This function estimates the power crossspectrum of two vectors.
Written 20040713

EMD
This function estimates the empirical mode decomposition of a given data vector.
Modified 20050805

EXTREMA
This function returns the locations of the local extrema in a given time series.
Written 20031009

FILTER
This function returns a smoothed version of the input vector.
Modified 20190913

FILTER_ND
This function returns a smoothed version of an Ndimensional input array.
Modified 20050805

filter_window
This function returns a desired filter window of desired width.
Modified 20051021

FIRST_DIFF
This function returns the first difference vector of the input.
Modified 20000710

HILBERT_SPEC
This function estimates the HilbertHuang amplitude spectrum of an input matrix of time series (e.g. intrinsic mode functions).
Modified 20050805

MONTE_CARLO_AR1
This function returns a Monte Carlo generated time series which preserves the distributional and AR(1) properties of the original series.
Modified 20051023

PCA
This procedure calculates the principal components and empirical orthogonal functions of a given data set.
Modified 20120123

shengzwiers.pro
This function applies the Sheng and Zwiers method for adjusting averaged data such that the original averaged values are reobtained upon averaging of higher frequency data themselves calculated through linear interpolation from the adjusted data. See Sheng and Zwiers (1998) and http://wwwpcmdi.llnl.gov/projects/amip/AMIP2EXPDSN/BCS/amip2bcs.php for more details.
Modified 20180913

shengzwiers_weights.pro
This function returns the interpolation weighting matrix used in the Sheng and Zwiers (1998) algorithm for variance adjustment for interpolation.
Modified 20170920

TREND
This function calculates the leastsquares linear trend in the input vector.
Modified 20150915

UNWRAP
This function unwraps angular time series such that is it continuous.
Written 20041025

zero_cross
This function returns the number of zero crossings in a given time series.
Written 20031009



News

 mask_lonlatmonth.pro has been superceded by mask_lonlattime.pro and process_lonlatmonth.pro. It was removed from the library on 20080425.
 A .tar archive file containing the entire routine library was added on 20070524; see above to download it.
 giorgi_regions.pro was replaced with ipcc_regions.pro on 20060112.
 A separate webpage for the Optimal Detection Package was created on 20050902 here.
 A separate webpage for the Optimal Detection Package was created on 20050902 here.
 SUM and SUM_ROW were removed on 20050805 as they are superceded by IDL's TOTAL function.
 A number of routines were removed from the library on 20031119 because they were too system specific. These are CDIAC_PLOT, CDIAC_READ, CRU_PLOT, EDIT_REGIONS, GLOBETOPOG, PLOT_PRECIP, PLOT_WEATHER, READ_GLOBE_TOPOG, READ_PARTICLES, READ_REGION_MASK, READ_TERM, SSTOPOG, VANCOUVER_ISLAND, WRITE_HORZ_REGIONS. PRODUCT was also removed as it is superceded by IDL's PRODUCT function.



Maintained by: dastone@runbox.com
Last updated: 23 March 2020

© Copyright 20172020 Dáithí Stone


