From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/vops/lz/amedc.x | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 sys/vops/lz/amedc.x (limited to 'sys/vops/lz/amedc.x') diff --git a/sys/vops/lz/amedc.x b/sys/vops/lz/amedc.x new file mode 100644 index 00000000..09dcf10c --- /dev/null +++ b/sys/vops/lz/amedc.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. + +char procedure amedc (a, npix) + +char a[ARB] +int npix + +pointer sp, aa +char median +char asokc() # 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_CHAR) + call amovc (a, Memc[aa], npix) + median = asokc (Memc[aa], npix, (npix + 1) / 2) + call sfree (sp) + + return (median) + } +end -- cgit