aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/imgibf.x
blob: 9155ae780cb70507d3bd267c69862f3a0f9e1b18 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<imhdr.h>
include	<imio.h>

# IMGIBF -- Get an input buffer.

pointer procedure imgibf (im, vs, ve, ndim, dtype)

pointer	im
long	vs[ARB], ve[ARB]
int	dtype, ndim

pointer	bdes
int	i
long	nget, nchars, totpix

long	imcssz()
errchk	imopsf, calloc, realloc, mfree, malloc

begin
	# If first input transfer, allocate and initialize array of
	# input buffer descriptors.

	if (IM_IBDES(im) == NULL) {
	    call imopsf (im)
	    call calloc (IM_IBDES(im), LEN_BDES * IM_VNBUFS(im), TY_STRUCT)
	}

	# Compute pointer to the next input buffer descriptor.
	# Increment NGET, the count of the number of GETPIX calls.

	nget = IM_NGET(im)
	bdes = IM_IBDES(im) + mod (nget, IM_VNBUFS(im)) * LEN_BDES
	IM_NGET(im) = nget + 1

	# Compute the size of the buffer needed.  Check buffer
	# descriptor to see if the old buffer is the right size.
	# If so, use it, otherwise make a new one.

	nchars = imcssz (im, vs, ve, ndim, dtype, totpix, IM_READ)

	if (nchars < BD_BUFSIZE(bdes))
	    call realloc (BD_BUFPTR(bdes), nchars, TY_CHAR)
	else if (nchars > BD_BUFSIZE(bdes)) {
	    call mfree (BD_BUFPTR(bdes), TY_CHAR)
	    call malloc (BD_BUFPTR(bdes), nchars, TY_CHAR)
	}

	# Save section coordinates, datatype in buffer descriptor, and
	# return buffer pointer to calling program.

	IM_LASTBDES(im) = bdes
	BD_BUFSIZE(bdes) = nchars
	BD_DTYPE(bdes) = dtype
	BD_NPIX(bdes) = totpix
	BD_NDIM(bdes) = ndim

	do i = 1, ndim {
	    BD_VS(bdes,i) = vs[i]
	    BD_VE(bdes,i) = ve[i]
	}

	return (BD_BUFPTR(bdes))		# return ptr to CHAR
end