aboutsummaryrefslogtreecommitdiff
path: root/sys/plio/zzsum.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/plio/zzsum.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/plio/zzsum.x')
-rw-r--r--sys/plio/zzsum.x50
1 files changed, 50 insertions, 0 deletions
diff --git a/sys/plio/zzsum.x b/sys/plio/zzsum.x
new file mode 100644
index 00000000..2e6097f9
--- /dev/null
+++ b/sys/plio/zzsum.x
@@ -0,0 +1,50 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <pmset.h>
+
+task sum = t_sum
+
+# SUM -- Sum the image pixels lying within the given mask.
+
+procedure t_sum()
+
+char image[SZ_FNAME] # input data image
+char mask[SZ_FNAME] # image mask
+
+int npix, mval, totpix, m_flags
+long v[PM_MAXDIM]
+pointer im, mp, pp
+real sum
+
+bool clgetb()
+real asumr()
+int mio_glsegr()
+pointer immap(), mio_open()
+
+begin
+ call clgstr ("image", image, SZ_FNAME)
+ call clgstr ("mask", mask, SZ_FNAME)
+ m_flags = 0
+ if (clgetb ("invert"))
+ m_flags = INVERT_MASK
+
+ im = immap (image, READ_ONLY, 0)
+ mp = mio_open (mask, m_flags, im)
+
+ sum = 0; totpix = 0
+ while (mio_glsegr (mp, pp, mval, v, npix) != EOF) {
+ sum = sum + asumr (Memr[pp], npix)
+ totpix = totpix + npix
+ }
+
+ call mio_close (mp)
+ call imunmap (im)
+
+ call printf ("%d pixels, sum=%g, mean=%g\n")
+ call pargi (totpix)
+ call pargr (sum)
+ if (totpix > 0)
+ call pargr (sum / totpix)
+ else
+ call pargr (INDEF)
+end