/* MX LIBRARY FUNCTION: mxip_image_s_open_f7 * * PURPOSE: Open a mxip_image_s structure. * * USAGE EXAMPLE: * * struct mxip_image_s *image=NULL; * int nx = 9; ! number of rows (width) * int ny = 13; ! number of columns (height) * int idx0 = 0; ! true X coordinate of lower left pixel * int idy0 = 0; ! true Y coordinate of lower left pixel * int mpx = 1; ! number of subpixels per pixel * int status; * * status = mxip_image_s_open_f7 (&image, nx, ny, idx0, idy0, mpx, "image"); * * 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 mxip_image_s_open_f7( struct mxip_image_s **out, int nx, int ny, int idx0, int idy0, int mpx_, char *comment ) { char mxfunc[] = "mxip_image_s_open_f7"; int status; struct mxip_image_s *image=NULL; int npix; int mpx = mpx_; int ix0; int iy0; int ix1; int iy1; int j0; status = 0; image = (struct mxip_image_s *)malloc(sizeof(struct mxip_image_s)); if ((struct mxip_image_s *)NULL==image) { status=1; sprintf (MX.tmpmsg, "# could not allocate mxip_image_s structure!\n"); goto error; } /* * Initilize structure with dummy values */ image->openedi = 0; image->nxi = 0; image->nyi = 0; image->npxi = 0; image->llx0i = 0; image->lly0i = 0; image->mpxi = 0; image->comment[0] = '\0'; image->vectord = (double *)NULL; image->matrixd = (double **)NULL; /* * Set the number of pixels in the X direction (X -> columns) */ if (nx>0) { image->nxi = nx; } else { status = 2; sprintf (MX.tmpmsg, "# nx=%d < minimum=1 \n", nx); goto error; } /* * Set the number of pixels in the Y direction (Y -> rows) */ if (ny>0) { image->nyi = ny; } else { status = 3; sprintf (MX.tmpmsg, "# ny=%d < minimum=1 \n", ny); goto error; } /* * Set the total number of pixels */ image->npxi = nx * ny; /* * Set the offset in the X direction */ image->llx0i = idx0; /* * Set the offset in the Y direction */ image->lly0i = idy0; /* * Set the super/sub pixel sampling * normal case: 1 -> 1x1 * mpx < -1 : negative value indicates subsampling * mpx > +1 : postive value indicates supersampling * special case: 0 -> 1x1 * special case: -1 -> 1x1 */ if (0==mpx) mpx = 1; if (-1==mpx) mpx = 1; image->mpxi = mpx; /* * Set the comment of this data set */ strncpy (image->comment, comment, sizeof(image->comment)); /* * Allocate the data vector */ npix = image->npxi; image->vectord = (double *)calloc (npix, sizeof(double)); if ((double *)NULL==image->vectord) { status = 4; sprintf ( MX.tmpmsg, "# Could not allocate data vector with %d pixels!\n", npix ); goto error; } /* * and initialize it */ for (j0=0; j0vectord[j0] = (double)0.0; } /* * Allocate the data matrix */ image->matrixd = (double **)calloc (ny, sizeof(double)); if ((double **)NULL==image->matrixd) { status = 5; sprintf (MX.tmpmsg, "# Could not allocate data matrix!\n"); goto error; } /* * and initialize it */ for (iy0=0; iy0matrixd[iy0] = &image->vectord[j0]; if (image->matrixd[iy0][ix0]!=image->vectord[j0]) { status = 6; sprintf ( MX.tmpmsg, "# image->matrixd[%d][%d] = %g !=" "image->vectord[%d] = %g <-- F77:(%d,%d)\n", iy0, ix0, image->matrixd[iy0][ix0], j0, image->vectord[j0], ix1, iy1 ); goto error; } } image->openedi = MX_OPENED; ok: status = 0; goto bye; error: mxp_errmsg_set_f3 (mxfunc, status, MX.tmpmsg); goto bye; bye: *out = &*image; return (status); } /* end-of-file */