aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/ranges/rgindices.x
blob: 48f1ec8f7fe1b6b6729b3ee63b93759e073c9935 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<pkg/rg.h>

# RG_INDICES -- Return the indices in the ranges.

procedure rg_indices (rg, indices, npts, type)

pointer	rg				# Ranges
pointer	indices				# Indices
int	npts				# Number of indices
int	type				# Data type of points

int	i, j, k, step

begin
	# Error check the range pointer.

	if (rg == NULL)
	    call error (0, "Range descriptor undefined")

	# Determine the number of range points.

	indices = NULL
	npts = 0
	if (RG_NRGS (rg) == 0)
	    return

	do i = 1, RG_NRGS(rg) {
	    if (RG_X1(rg, i) > RG_X2(rg, i))
		npts = npts + RG_X1(rg, i) - RG_X2(rg, i) + 1
	    else
		npts = npts + RG_X2(rg, i) - RG_X1(rg, i) + 1
	}

	# Allocate the range points array.

	call malloc (indices, npts, type)

	# Set the range points.

	k = indices
	do i = 1, RG_NRGS(rg) {
	    if (RG_X1(rg, i) > RG_X2(rg, i))
		step = -1
	    else
		step = 1

	    switch (type) {
	    case TY_SHORT:
	    	do j = RG_X1(rg, i), RG_X2(rg, i), step {
		    Mems[k] = j
		    k = k + 1
		}
	    case TY_INT:
	    	do j = RG_X1(rg, i), RG_X2(rg, i), step {
		    Memi[k] = j
		    k = k + 1
		}
	    case TY_LONG:
	    	do j = RG_X1(rg, i), RG_X2(rg, i), step {
		    Meml[k] = j
		    k = k + 1
		}
	    case TY_REAL:
	    	do j = RG_X1(rg, i), RG_X2(rg, i), step {
		    Memr[k] = j
		    k = k + 1
		}
	    case TY_DOUBLE:
	    	do j = RG_X1(rg, i), RG_X2(rg, i), step {
		    Memd[k] = j
		    k = k + 1
		}
	    default:
		call error (0, "rg_indices:  Datatype not available")
	    }
	}

	return
end