From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/imio/imgobf.x | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 sys/imio/imgobf.x (limited to 'sys/imio/imgobf.x') diff --git a/sys/imio/imgobf.x b/sys/imio/imgobf.x new file mode 100644 index 00000000..8dc5f3a1 --- /dev/null +++ b/sys/imio/imgobf.x @@ -0,0 +1,62 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include +include + +# IMGOBF -- Get output buffer. + +pointer procedure imgobf (im, vs, ve, ndim, dtype) + +pointer im, bdes +int ndim, dtype, i +long vs[ndim], ve[ndim] +long nchars, totpix, imcssz(), clktime() +int sizeof() + +errchk imopsf, malloc, realloc, calloc + +include + +begin + # If first write, and if new image, create pixel storage file, + # otherwise open pixel storage file. Allocate and initialize + # output buffer descriptor. + + if (IM_OBDES(im) == NULL) { + call imopsf (im) + call calloc (IM_OBDES(im), LEN_BDES, TY_STRUCT) + IM_MTIME(im) = clktime (long(0)) + IM_SVMTIME(im) = IM_MTIME(im) + } + + bdes = IM_OBDES(im) + + # Compute the size of buffer needed. A few extra chars are added + # to guarantee that there won't be a memory violation when + # writing a full physical length line. + + nchars = imcssz (im, vs, ve, ndim, dtype, totpix, IM_WRITE) + + 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 of pixels 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) - 1) / sizeof(dtype) + 1) +end -- cgit