/* MX LIBRARY FUNCTION: mxiraf_image_s_open_f3 * * PURPOSE: Open a IRAF image (open a mxiraf_image_s structure). * * USAGE EXAMPLES: * * struct mxiraf_image_s *m31=NULL; * struct mxiraf_image_s *m33=NULL; * int status; * * status = mxiraf_image_s_open_f3 (&m31, "m31.fits", IRAF_READ_WRITE); * status = mxiraf_image_s_open_f3 (&m33, "m33.fits", IRAF_READ_ONLY); * * 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_open_f3( struct mxiraf_image_s **out, char *name, IRAFIOMode iomode ) { char mxfunc[] = "mxiraf_image_s_open_f3"; int status; struct mxiraf_image_s *image=NULL; int magic_offset; int ix; int ix0; int iy; int iy0; int iy1; int pxi; int mpx; int offset; int nx; int ny; int idx0; int idy0; float *r4px; /* * Allocate memory for new mxiraf_image_s structure */ image = (struct mxiraf_image_s *)malloc(sizeof(struct mxiraf_image_s)); /* * any errors? */ if ((struct mxiraf_image_s *)NULL==image) { status = 1; sprintf (MX.tmpmsg, "# could not allocate mxiraf_image_s structure!\n" ); goto error; } /* * Set image-> name to name */ strncpy (image->name, name, sizeof(image->name)); /* * Set image->iomode to iomode */ image->iomode = iomode; /* * Open the input IRAF image */ image->ptr = c_immap (image->name, image->iomode, 0); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 2; goto error2;} /* * Get image section */ c_imgsection (image->name, image->section, sizeof(image->name)); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 3; goto error2;} /* * Get the image dimensions */ image->ndimi = c_imgndim (image->ptr); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 4; goto error2;} /* only 2 dimensions are currently supported */ if (image->ndimi != 2) { status = 5; sprintf ( MX.tmpmsg, "# image->ndimi=%d != 2 <-- Only 2 dimensions currently supported\n", image->ndimi ); goto error; } /* * Get the size of the X dimension (width) */ nx = c_imglen (image->ptr, 1); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 6; goto error2;} /* * Set image->NXI to nx; */ image->NXI = nx; /* * Get the size of the Y dimension (height) */ ny = c_imglen (image->ptr, 2); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 7; goto error2;} /* * Set image->NYI to ny; */ image->NYI = ny; /* * Get the pixel type */ image->pxtype = (IRAFType) c_imgtypepix (image->ptr); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 8; goto error2;} /* only IRAF_REAL (TY_REAL) data is currently supported */ if (image->pxtype != IRAF_REAL) { status = 9; sprintf ( MX.tmpmsg, "# image->pxtype=%d != %d " "<-- Only IRAF_REAL (TY_REAL) currently supported\n", image->pxtype, (IRAF_REAL) ); goto error; } /* * Get offsets */ /* HACK ALERT: begin ======================================================== */ magic_offset = 49 - 208; /* IM_VOFF - IM_LEN */ idx0 = c_imglen (image->ptr, (1+magic_offset) ); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 10; goto error2;} /* * Set image->LLX0I to idx0 */ image->LLX0I = idx0; idy0 = c_imglen (image->ptr, (2+magic_offset) ); /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 11; goto error2;} /* * Set image->LLY0I to idy0 */ image->LLY0I = idy0; /* * Use of magic_offset is a temporary hack until such time * that CVOS truely becomes a full C implementation of VOS * * HACK ALERT: end ========================================================== */ /* * Open mxip_image_s structure */ mpx = 1; status = mxip_image_s_open_f7( &image->data, image->NXI, image->NYI, image->LLX0I, image->LLY0I, mpx, image->name ); if (status) { status = 12; goto error2; } /* * The image->data->vectord has been initialized to zero. * Now copy the pixel data. */ for (iy0 = 0; iy0 < ny; ++iy0) { iy1 = iy0 + 1; r4px = c_imgl2r (image->ptr, iy1); /* get data row by row */ /* CVOS error? */ if ( mxiraf_cvos_error_check_f0() ) {status = 13; goto error2;} offset = iy0*nx; for (ix0 = 0; ix0 < nx; ++ix0) { pxi = offset + ix0; /* calculate offset */ image->data->vectord[pxi] = (double) r4px[ix0]; /* get pixels one by one */ } } image->openedi = MX_OPENED; ok: status = 0; goto bye; error: mxp_errmsg_set_f3 (mxfunc, status, MX.tmpmsg); goto bye; error2: mxp_errmsg_append_f3 (mxfunc, status, ""); goto bye; bye: *out = &*image; return (status); } /* end-of-file */