/* FILE: img_open.c * PURPOSE: Open a qdphot5_ImageS. * AUTHOR: Kenneth J. Mighell (mighell@noao.edu) * LANGUAGE: ANSI C * DATE: 2001JUL03 * COPYRIGHT: (C) 2001 Assoc. of Universities for Research in Astronomy Inc. */ #include "mx.h" #include "qdphot.h" int qdphot5_ImageS_Open_f3 ( qdphot5_ParS *ParS, int index, qdphot5_ImageS *Image ){ char mxfunc[] = "qdphot5_ImageS_Open_f3"; int status; double addend; int isNullFile; int isNullPointer; int j; double gain; double bias; double ron; double mnsnr; char ifn[MX_IRAF_SZ_FNAME+1]; char ofn[MX_IRAF_SZ_FNAME+1]; double mnpeak_dn; double mxpeak_dn; int compute_minmax; int reset; int out2_is_out1; Image->index = index; j = index; strncpy(ifn, ParS->image[j], sizeof(ifn)); strncpy(ofn, ParS->out[j], sizeof(ofn)); Image->ofp = ParS->ofp[j]; out2_is_out1 = ParS->out2_is_out1; gain = ParS->gain[j]; bias = ParS->bias[j]; ron = ParS->ron[j]; mnsnr = ParS->mnsnr; Image->idint = ParS->idint[j]; Image->rejects = ParS->rejects; strncpy(Image->ifn, ifn, sizeof(Image->ifn)); strncpy(Image->ofn, ofn, sizeof(Image->ofn)); Image->ofp = ParS->ofp[j]; Image->gain = gain; Image->bias = bias; Image->ron = ron; Image->mnsnr = mnsnr; status = mxiraf_image_s_open_f3 (&Image->mxIrafImage, ifn, IRAF_READ_ONLY); if (status) {status = 1; goto mx_error;} Image->matrixd = Image->mxIrafImage->data->matrixd; Image->llx0i = Image->mxIrafImage->data->llx0i; Image->lly0i = Image->mxIrafImage->data->lly0i; Image->xdimi = Image->mxIrafImage->data->nxi; Image->ydimi = Image->mxIrafImage->data->nyi; Image->nxi = Image->xdimi; Image->nyi = Image->ydimi; if (fabs(bias)>0.0001) { /* non-zero bias */ addend = -bias; status = mxip_image_s_const_add_f2 (Image->mxIrafImage->data, addend); if (status) {status = 3; goto mx_error;} } status = qdphot5_ImageS_MinMax_f1 (Image); if (status) {status = 100; goto mx_error;} #ifdef DEBUG printf ("matrixd_minimum is %g\n",Image->matrixd_minimum); printf ("matrixd_maximum is %g\n",Image->matrixd_maximum); #endif reset = (ParS->mnpeak_is_INDEF[1] || ParS->mxpeak_is_INDEF[1]); mnpeak_dn = ParS->mnpeak[j]; mxpeak_dn = ParS->mxpeak[j]; if (reset) { if (ParS->mnpeak_is_INDEF[1]) { mnpeak_dn = Image->matrixd_minimum; ParS->mnpeak[j] = mnpeak_dn; } if (ParS->mxpeak_is_INDEF[1]) { mxpeak_dn = Image->matrixd_maximum; ParS->mxpeak[j] = mxpeak_dn; } } Image->mnpeak = mnpeak_dn * gain; Image->mxpeak = mxpeak_dn * gain; #ifdef DEBUG printf ("Image->mnpeak is %g\n",Image->mnpeak); printf ("Image->mxpeak is %g\n",Image->mxpeak); #endif status = mxip_image_s_const_mul_f2 (Image->mxIrafImage->data, gain); if (status) {status = 2; goto mx_error;} Image->dxd = ParS->dx[j]; Image->dyd = ParS->dy[j]; if ( (index==2) && (ParS->out2_is_out1) ) Image->ofp = ParS->ofp[1]; if ( (FILE *)NULL != (Image->ofp) ) goto out_is_opened; /* * Has no output been requested? */ isNullFile = (strcmp(ofn,"NULL")) == 0; if (isNullFile) { Image->ofp = (FILE *)NULL; Image->print = MX_FALSE; goto ok; } if (ofn[0]!='\0') { Image->ofp = fopen (ofn, "w"); if ((FILE *)NULL==Image->ofp) { status = 4; sprintf ( MX.tmpmsg, "# Could not open this output file:\n" "# \"%s\"\n" "# Does this file already exist?\n", ofn ); goto mx_error2; } } else { Image->ofp = stdout; } out_is_opened: ParS->ofp[j] = Image->ofp; Image->ofp_is_STDOUT = ((FILE *)stdout==Image->ofp); ParS->out_is_STDOUT[j] = Image->ofp_is_STDOUT; Image->mnround = ParS->mnround; Image->mxround = ParS->mxround; Image->mnangle = ParS->mnangle; Image->mxangle = ParS->mxangle; Image->mnsharp = ParS->mnsharp; Image->mxsharp = ParS->mxsharp; Image->mnkappa = ParS->mnkappa; Image->mxkappa = ParS->mxkappa; ok: status = 0; goto bye; mx_error: mxp_errmsg_append_f3 (mxfunc, status, ""); goto bye; mx_error2: mxp_errmsg_append_f3 (mxfunc, status, MX.tmpmsg); goto bye; bye: return(status); } /* end-of-file */