aboutsummaryrefslogtreecommitdiff
path: root/sys/vops/lz/amedr.x
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /sys/vops/lz/amedr.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/vops/lz/amedr.x')
-rw-r--r--sys/vops/lz/amedr.x48
1 files changed, 48 insertions, 0 deletions
diff --git a/sys/vops/lz/amedr.x b/sys/vops/lz/amedr.x
new file mode 100644
index 00000000..e459b22a
--- /dev/null
+++ b/sys/vops/lz/amedr.x
@@ -0,0 +1,48 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+# AMED -- Vector median selection. The selection is carried out in a temporary
+# array, leaving the input vector unmodified. Especially demanding applications
+# may wish to call the asok routine directory to avoid the call to the memory
+# allocator.
+
+real procedure amedr (a, npix)
+
+real a[ARB]
+int npix
+
+pointer sp, aa
+real median
+real asokr() # select the Kth smallest element from A
+
+begin
+ switch (npix) {
+ case 1, 2:
+ return (a[1])
+
+ case 3:
+ if (a[1] < a[2]) {
+ if (a[2] < a[3])
+ return (a[2])
+ else if (a[1] < a[3])
+ return (a[3])
+ else
+ return (a[1])
+ } else {
+ if (a[2] > a[3])
+ return (a[2])
+ else if (a[1] < a[3])
+ return (a[1])
+ else
+ return (a[3])
+ }
+
+ default:
+ call smark (sp)
+ call salloc (aa, npix, TY_REAL)
+ call amovr (a, Memr[aa], npix)
+ median = asokr (Memr[aa], npix, (npix + 1) / 2)
+ call sfree (sp)
+
+ return (median)
+ }
+end