From a8b2b0a86b124537178b8a3c43df31876ccbaae0 Mon Sep 17 00:00:00 2001 From: Michael Galloy Date: Thu, 7 Mar 2013 18:48:27 -0700 Subject: [PATCH] Adding Interactive Data Language (IDL) support. --- lib/linguist/languages.yml | 6 ++++++ samples/IDL/mg_acosh.pro | 29 +++++++++++++++++++++++++ samples/IDL/mg_analysis.dlm | 9 ++++++++ samples/IDL/mg_gcd.pro | 35 +++++++++++++++++++++++++++++++ samples/IDL/mg_trunc.pro | 42 +++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 samples/IDL/mg_acosh.pro create mode 100644 samples/IDL/mg_analysis.dlm create mode 100644 samples/IDL/mg_gcd.pro create mode 100644 samples/IDL/mg_trunc.pro diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 4a64d603..483f85a2 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -589,6 +589,12 @@ Haxe: extensions: - .hxsl +IDL: + type: programming + lexer: Text only + color: "#e3592c" + primary_extension: .pro + INI: type: data extensions: diff --git a/samples/IDL/mg_acosh.pro b/samples/IDL/mg_acosh.pro new file mode 100644 index 00000000..1510f09f --- /dev/null +++ b/samples/IDL/mg_acosh.pro @@ -0,0 +1,29 @@ +; docformat = 'rst' + +;+ +; Inverse hyperbolic cosine. Uses the formula: +; +; $$\text{acosh}(z) = \ln(z + \sqrt{z + 1} \sqrt{z - 1})$$ +; +; :Examples: +; The arc hyperbolic sine function looks like:: +; +; IDL> x = 2.5 * findgen(1000) / 999. + 1. +; IDL> plot, x, mg_acosh(x), xstyle=1 +; +; This should look like: +; +; .. image:: acosh.png +; +; :Returns: +; float, double, complex, or double complex depending on the input +; +; :Params: +; z : in, required, type=numeric +; input +;- +function mg_acosh, z + compile_opt strictarr + + return, alog(z + sqrt(z + 1) * sqrt(z - 1)) +end \ No newline at end of file diff --git a/samples/IDL/mg_analysis.dlm b/samples/IDL/mg_analysis.dlm new file mode 100644 index 00000000..6cb7881f --- /dev/null +++ b/samples/IDL/mg_analysis.dlm @@ -0,0 +1,9 @@ +MODULE mg_analysis +DESCRIPTION Tools for analysis +VERSION 1.0 +SOURCE mgalloy +BUILD_DATE January 18, 2011 + +FUNCTION MG_ARRAY_EQUAL 2 2 KEYWORDS +FUNCTION MG_TOTAL 1 1 + diff --git a/samples/IDL/mg_gcd.pro b/samples/IDL/mg_gcd.pro new file mode 100644 index 00000000..2287723f --- /dev/null +++ b/samples/IDL/mg_gcd.pro @@ -0,0 +1,35 @@ +; docformat = 'rst' + +;+ +; Find the greatest common denominator (GCD) for two positive integers. +; +; :Returns: +; integer +; +; :Params: +; a : in, required, type=integer +; first integer +; b : in, required, type=integer +; second integer +;- +function mg_gcd, a, b + compile_opt strictarr + on_error, 2 + + if (n_params() ne 2) then message, 'incorrect number of arguments' + if (~mg_isinteger(a) || ~mg_isinteger(b)) then begin + message, 'integer arguments required' + endif + + _a = abs(a) + _b = abs(b) + minArg = _a < _b + maxArg = _a > _b + + if (minArg eq 0) then return, maxArg + + remainder = maxArg mod minArg + if (remainder eq 0) then return, minArg + + return, mg_gcd(minArg, remainder) +end diff --git a/samples/IDL/mg_trunc.pro b/samples/IDL/mg_trunc.pro new file mode 100644 index 00000000..c5288908 --- /dev/null +++ b/samples/IDL/mg_trunc.pro @@ -0,0 +1,42 @@ +; docformat = 'rst' + +;+ +; Truncate argument towards 0.0, i.e., takes the `FLOOR` of positive values +; and the `CEIL` of negative values. +; +; :Examples: +; Try the main-level program at the end of this file. It does:: +; +; IDL> print, mg_trunc([1.2, -1.2, 0.0]) +; 1 -1 0 +; IDL> print, floor([1.2, -1.2, 0.0]) +; 1 -2 0 +; IDL> print, ceil([1.2, -1.2, 0.0]) +; 2 -1 0 +; +; :Returns: +; array of same type as argument +; +; :Params: +; x : in, required, type=float/double +; array containing values to truncate +;- +function mg_trunc, x + compile_opt strictarr + + result = ceil(x) + posInd = where(x gt 0, nposInd) + + if (nposInd gt 0L) then begin + result[posInd] = floor(x[posInd]) + endif + + return, result +end + + +; main-level example program + +print, mg_trunc([1.2, -1.2, 0.0]) + +end