aboutsummaryrefslogtreecommitdiff
path: root/sys/etc/gen/nmireadr.x
blob: e83384003cb3ca8bb498757f6693e6a7407b9120 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <nmi.h>

# NMI_READ -- Read a block of data stored externally in NMI format.
# Data is returned in the format of the local host machine.

int procedure nmi_readr (fd, spp, maxelem)

int	fd			#I input file
real	spp[ARB]		#O receives data
int	maxelem			# max number of data elements to be read

pointer	sp, bp
int	pksize, nchars, nelem
int	nmipksize(), nminelem(), read()
errchk	read()

long	note()

begin
	pksize = nmipksize (maxelem, NMI_REAL)
	nelem  = EOF

	if (pksize > maxelem * SZ_REAL) {
	    # Read data into local buffer and unpack into user buffer.

	    call smark (sp)
	    call salloc (bp, pksize, TY_CHAR)

	    nchars = read (fd, Memc[bp], pksize)
	    if (nchars != EOF) {
		nelem = min (maxelem, nminelem (nchars, NMI_REAL))
		call nmiupkr (Memc[bp], spp, nelem, TY_REAL)
	    }

	    call sfree (sp)
	
	} else {
	    # Read data into user buffer and unpack in place.

	    nchars = read (fd, spp, pksize)
	    if (nchars != EOF) {
		nelem = min (maxelem, nminelem (nchars, NMI_REAL))
		call nmiupkr (spp, spp, nelem, TY_REAL)
	    }
	}

	return (nelem)
end