From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- pkg/xtools/ranges/rgintersect.x | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 pkg/xtools/ranges/rgintersect.x (limited to 'pkg/xtools/ranges/rgintersect.x') diff --git a/pkg/xtools/ranges/rgintersect.x b/pkg/xtools/ranges/rgintersect.x new file mode 100644 index 00000000..5e4e4390 --- /dev/null +++ b/pkg/xtools/ranges/rgintersect.x @@ -0,0 +1,58 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include + +# RG_INTERSECT -- Intersect two sets of ordered and merged ranges. + +pointer procedure rg_intersect (rg1, rg2) + +pointer rg1 # First set of ranges +pointer rg2 # Second set of ranges + +pointer rg3 # Pointer to intersection + +int i, j, k + +begin + # Error check the range pointers. + + if ((rg1 == NULL) || (rg2 == NULL)) + call error (0, "Range descriptor(s) undefined") + + # Allocate the range points array. + + k = RG_NRGS(rg1) + RG_NRGS(rg2) - 1 + call malloc (rg3, LEN_RG + 2 * max (1, k), TY_STRUCT) + + # Set the ranges. + + i = 1 + j = 1 + k = 0 + + while (i <= RG_NRGS(rg1) && j <= RG_NRGS(rg2)) { + if (RG_X2(rg1, i) < RG_X1(rg2, j)) + i = i + 1 + else if (RG_X2(rg2, j) < RG_X1(rg1, i)) + j = j + 1 + else { + k = k + 1 + RG_X1(rg3, k) = max (RG_X1(rg1, i), RG_X1(rg2, j)) + RG_X2(rg3, k) = min (RG_X2(rg1, i), RG_X2(rg2, j)) + + if (RG_X2(rg1, i) < RG_X2(rg2, j)) + i = i + 1 + else + j = j + 1 + } + } + + call realloc (rg3, LEN_RG + 2 * max (1, k), TY_STRUCT) + + RG_NRGS(rg3) = k + RG_NPTS(rg3) = 0 + do i = 1, RG_NRGS(rg3) + RG_NPTS(rg3) = RG_NPTS(rg3) + RG_X2(rg3, i) - RG_X1(rg3, i) + 1 + + return (rg3) +end -- cgit