aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/ranges/rgmerge.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 /pkg/xtools/ranges/rgmerge.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'pkg/xtools/ranges/rgmerge.x')
-rw-r--r--pkg/xtools/ranges/rgmerge.x38
1 files changed, 38 insertions, 0 deletions
diff --git a/pkg/xtools/ranges/rgmerge.x b/pkg/xtools/ranges/rgmerge.x
new file mode 100644
index 00000000..2cb5034a
--- /dev/null
+++ b/pkg/xtools/ranges/rgmerge.x
@@ -0,0 +1,38 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <pkg/rg.h>
+
+# RG_MERGE -- Merge overlapping ranges in set of ordered ranges.
+
+procedure rg_merge (rg)
+
+pointer rg # Ranges
+
+int new, old
+
+begin
+ # Error check the range pointer.
+
+ if (rg == NULL)
+ call error (0, "Range descriptor undefined")
+ if (RG_NRGS(rg) == 0)
+ return
+
+ # Eliminate overlapping ranges and count the number of new ranges.
+
+ new = 1
+ do old = 2, RG_NRGS(rg)
+ if (RG_X1(rg, old) > RG_X2(rg, new) + 1) {
+ new = new + 1
+ RG_X1(rg, new) = RG_X1(rg, old)
+ RG_X2(rg, new) = RG_X2(rg, old)
+ } else
+ RG_X2(rg, new) = max (RG_X2(rg, old), RG_X2(rg, new))
+
+ call realloc (rg, LEN_RG + 2 * new, TY_STRUCT)
+
+ RG_NPTS(rg) = 0
+ RG_NRGS(rg) = new
+ do new = 1, RG_NRGS(rg)
+ RG_NPTS(rg) = RG_NPTS(rg) + RG_X2(rg, new) - RG_X1(rg, new) + 1
+end