/* MX LIBRARY FUNCTION: mxiraf_image_s_close_f1 * * PURPOSE: Close a IRAF image (close a mxiraf_image_s structure). * * USAGE EXAMPLE: * * struct mxiraf_image_s *old=NULL; * * ! N.B. old must be opened and *old!=NULL * * status = mxiraf_image_s_close_f1 (&old); * * AUTHOR: K. J. Mighell (mighell@noao.edu) * * LANGUAGE: ANSI C * * DOCUMENTATION: http://www.noao.edu/staff/mighell/mx * * DATE: 20000313 * * MOD: 3 * * Copyleft (L) 2000 Kenneth John Mighell */ #include "mx.h" int mxiraf_image_s_close_f1( struct mxiraf_image_s **old ) { char mxfunc[] = "mxiraf_image_s_close_f1"; int status; struct mxiraf_image_s *image; IRAFIOMode iomode; int nx; int ny; int iy0; int ix0; int iy1; int ix1; int pxi; int offset; float *r4px; image = *old; if ( mxiraf_image_s_ok_f1 (image) ) { status = 1; goto error; } iomode = image->iomode; if (IRAF_READ_WRITE!=iomode) goto shut_down; nx = image->data->nxi; ny = image->data->nyi; for (iy0 = 0; iy0 < ny; ++iy0) { iy1 = iy0 + 1; r4px = c_impl2r (image->ptr, iy1); /* get the pointer to the row */ /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 2; goto error;} offset = iy0*nx; for (ix0 = 0; ix0 < nx; ++ix0) { pxi = offset + ix0; /* calculate offset */ r4px[ix0] = (float) image->data->vectord[pxi]; /* save the pixels one by one */ } } shut_down: /* * Unmap the IRAF pointer */ c_imunmap (image->ptr); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 3; goto error;} /* * Close mxip_image_s structure image->data */ if ( mxip_image_s_close_f1 (&image->data) ) { status = 3; goto error; } /* * Free up memory allocated to image */ free (image); image = (struct mxiraf_image_s *)NULL; ok: status = 0; goto bye; error: mxp_errmsg_append_f3 (mxfunc, status, ""); goto bye; bye: *old = &*image; return (status); } /* end-of-file */