43 #include "vircam_utils.h"
44 #include "vircam_stats.h"
45 #include "vircam_fits.h"
46 #include "vircam_pfits.h"
47 #include "catalogue/imcore.h"
55 static const char *illcor_cols[NI_COLS] = {
"xmin",
"xmax",
"ymin",
"ymax",
60 static float madfunc(
int npts,
float *xt,
float *yt,
float b);
93 const char *vircam_license =
94 "This file is part of the VIRCAM Instrument Pipeline\n"
95 "Copyright (C) 2006 Cambridge Astronomy Survey Unit\n"
97 "This program is free software; you can redistribute it and/or modify\n"
98 "it under the terms of the GNU General Public License as published by\n"
99 "the Free Software Foundation; either version 2 of the License, or\n"
100 "(at your option) any later version.\n"
102 "This program is distributed in the hope that it will be useful,\n"
103 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
104 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
105 "GNU General Public License for more details.\n"
107 "You should have received a copy of the GNU General Public License\n"
108 "along with this program; if not, write to the Free Software\n"
109 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, \n"
111 return(vircam_license);
142 const cpl_frame *frame2) {
147 if (frame1 == NULL || frame2 == NULL)
152 if ((v1 = (
char *)cpl_frame_get_tag(frame1)) == NULL)
154 if ((v2 = (
char *)cpl_frame_get_tag(frame2)) == NULL)
194 cpl_size *labels, cpl_size nlab,
197 cpl_frameset *cur_set,*ret_set;
198 cpl_frame *cur_frame;
203 for (i = 0; i < nlab; i++) {
204 cur_set = cpl_frameset_extract(frameset,labels,(cpl_size)i);
207 cur_frame = cpl_frameset_get_frame(cur_set,0);
208 cur_tag = (
char *)cpl_frame_get_tag(cur_frame);
209 if (!strcmp(cur_tag,tag)) {
213 cpl_frameset_delete(cur_set);
248 cpl_size *labels, cpl_size nlab,
250 cpl_frameset *cur_set;
251 cpl_frame *cur_frame,*new_frame;
256 cur_frame = cpl_frameset_get_frame(cur_set,0);
257 new_frame = cpl_frame_duplicate(cur_frame);
258 cpl_frameset_delete(cur_set);
289 const char *fctid =
"vircam_frameset_fexists";
293 if (frameset == NULL) {
294 cpl_msg_error(fctid,
"Input frameset is NULL");
300 nf = cpl_frameset_get_size(frameset);
302 cpl_msg_error(fctid,
"Input frameset has size of zero");
309 for (i = 0; i < nf; i++) {
310 cur = cpl_frameset_get_frame(frameset,i);
311 fname = cpl_frame_get_filename(cur);
312 if (access(fname,F_OK) != 0) {
313 cpl_msg_error(fctid,
"File: %s doesn't exist",fname);
355 int nvircam = 16,n,nmax;
356 const char *fctid =
"vircam_exten_range";
360 n = cpl_frame_get_nextensions(fr);
366 cpl_msg_warning(fctid,
367 "Only %" CPL_SIZE_FORMAT
" extensions out of %" CPL_SIZE_FORMAT
" are present",
368 (cpl_size)n,(cpl_size)nvircam);
385 if (inexten > nmax) {
387 "Requested extension %" CPL_SIZE_FORMAT
" is not present",
428 float *intercept,
float *slope) {
430 float sx,sy,sxx,sxy,det,aa,bb,temp,chisq,sigb,b1,f1,b2,f2,f;
438 for (j = 0; j < npts; j++) {
441 sxx += xdata[j]*xdata[j];
442 sxy += xdata[j]*ydata[j];
444 det = (float)npts*sxx - sx*sx;
450 aa = (sxx*sy - sx*sxy)/det;
451 bb = ((float)npts*sxy - sx*sy)/det;
453 for (j = 0; j < npts; j++) {
454 temp = ydata[j] - (aa + bb*xdata[j]);
457 sigb = sqrt(chisq/det);
467 f1 = madfunc(npts,xdata,ydata,b1);
468 b2 = bb + ((f1 > 0.0) ? fabs(3.0*sigb) : -fabs(3.0*sigb));
469 f2 = madfunc(npts,xdata,ydata,b2);
470 while (f1*f2 > 0.0) {
475 f2 = madfunc(npts,xdata,ydata,b2);
481 while (fabs(b2 - b1) > sigb) {
483 if (bb == b1 || bb == b2)
485 f = madfunc(npts,xdata,ydata,bb);
524 static float madfunc(
int npts,
float *xt,
float *yt,
float b) {
528 arr = cpl_malloc(npts*
sizeof(*arr));
529 for (j = 0; j < npts; j++)
530 arr[j] = yt[j] - b*xt[j];
533 for (j = 0; j < npts; j++) {
534 d = yt[j] - (b*xt[j] + aa);
535 sum += d > 0.0 ? xt[j] : -xt[j];
571 double *intercept,
double *slope,
double *sig) {
573 double sx,sy,sxx,sxy,det,aa,bb,temp,sum,sumsq;
581 for (j = 0; j < npts; j++) {
584 sxx += xdata[j]*xdata[j];
585 sxy += xdata[j]*ydata[j];
587 det = (double)npts*sxx - sx*sx;
597 aa = (sxx*sy - sx*sxy)/det;
598 bb = ((double)npts*sxy - sx*sy)/det;
604 for (j = 0; j < npts; j++) {
605 temp = ydata[j] - (aa + bb*xdata[j]);
613 *sig = sqrt(sumsq/(
double)npts - sum*sum);
645 double temp,big,pivot,rmax;
646 int i,iu,j,k,jl,ib,ir;
650 for (i = 0; i < iu; i++) {
655 for (k = i; k < m; k++) {
656 rmax = fabs(a[i][k]);
666 for (ib = 0; ib < m; ib++)
668 cpl_msg_error(
"vircam_solve_gauss",
"Zero Determinant\n");
676 for (j = 0; j < m; j++) {
692 for (j = jl; j < m; j++) {
693 temp = a[i][j]/pivot;
695 for (k = i; k < m; k++)
696 a[k][j] -= temp*a[k][i];
702 for (i = 0; i < m; i++) {
704 if (a[ir][ir] != 0.0) {
707 for (j = 1; j <= i; j++) {
709 temp -= a[k][ir]*b[k];
712 b[ir] = temp/a[ir][ir];
760 int ncoefs,
int ilim,
int niter,
float lclip,
761 float hclip, cpl_array **polycf,
double *sigfit) {
762 const char *fctid =
"vircam_polyfit";
763 int npts,iter,i,j,nnew,k,retval,n;
764 double *xdata,*ydata,*pdata,*res,**a,*b,temp,sum,sumsq,val;
775 npts = (int)cpl_array_get_size(xarray);
780 cpl_msg_warning(fctid,
781 "Not data for fit, Npts = %" CPL_SIZE_FORMAT
", Ncoefs = %" CPL_SIZE_FORMAT,
782 (cpl_size)npts,(cpl_size)ncoefs);
788 a = cpl_malloc(ncoefs*
sizeof(
double *));
789 b = cpl_calloc(ncoefs,
sizeof(
double));
790 for (i = 0; i < ncoefs; i++)
791 a[i] = cpl_calloc(ncoefs,
sizeof(
double));
792 pm = cpl_calloc(npts,
sizeof(
unsigned char));
793 res = cpl_malloc(npts*
sizeof(
double));
797 xdata = (
double *)cpl_array_get_data_double_const(xarray);
798 ydata = (
double *)cpl_array_get_data_double_const(yarray);
802 *polycf = cpl_array_new((cpl_size)ncoefs,CPL_TYPE_DOUBLE);
803 pdata = cpl_array_get_data_double(*polycf);
807 for (iter = 0; iter <= niter; iter++) {
811 for (i = 0; i < ncoefs; i++) {
812 for (j = 0; j < ncoefs; j++)
820 for (i = 0; i < npts; i++) {
823 for (k = 0; k < ncoefs; k++) {
826 temp = pow(xdata[i],(
double)(k+ilim));
827 b[k] += ydata[i]*temp;
828 for (j = 0; j <= k; j++) {
830 if (k + j + 2*ilim != 0)
831 temp = pow(xdata[i],(
double)(k+j+2*ilim));
836 for (k = 1; k < ncoefs; k++)
837 for (j = 0; j < k; j++)
843 if (retval != VIR_OK) {
844 cpl_msg_warning(fctid,
"Fit failed");
846 freespace2(a,ncoefs);
855 for (i = 0; i < ncoefs; i++)
863 for (i = 0; i < npts; i++) {
867 for (j = 0; j < ncoefs; j++)
868 val += pdata[j]*pow(xdata[i],(
double)j+ilim);
869 res[i] = val - ydata[i];
871 sumsq += pow(res[i],2.0);
875 *sigfit = sqrt(sumsq/(
double)n - sum*sum);
879 lcut = sum - lclip*(*sigfit);
880 hcut = sum + hclip*(*sigfit);
882 for (i = 0; i < npts; i++) {
885 if (res[i] > hcut || res[i] < lcut) {
900 freespace2(a,ncoefs);
951 unsigned char *bpm, cpl_table *chantab,
952 int ncells,
int oper,
float *global_diff,
953 float *global_rms, cpl_image **diffim,
954 cpl_table **diffimstats) {
955 float *ddata,*work,mean,sig,med,mad;
957 int nrows,i,nc1,nc2,nr,ixmin,ixmax,iymin,iymax,cnum,cx,cy,idx,idy;
958 int icx,icy,indy1,indy2,indx1,indx2,jp,jcx,jj,jcy,ii,ncx,ncy;
959 const char *fctid =
"vircam_difference_image";
970 if (prog == NULL || master == NULL)
977 *diffim = cpl_image_subtract_create(prog,master);
980 *diffim = cpl_image_divide_create(prog,master);
984 cpl_msg_error(fctid,
"Invalid operation requested %" CPL_SIZE_FORMAT,
993 ddata = cpl_image_get_data_float(*diffim);
994 nx = (int)cpl_image_get_size_x(*diffim);
995 ny = (int)cpl_image_get_size_y(*diffim);
1002 if (chantab == NULL)
1008 if (! cpl_table_has_column(chantab,
"ixmin") ||
1009 ! cpl_table_has_column(chantab,
"ixmax") ||
1010 ! cpl_table_has_column(chantab,
"iymin") ||
1011 ! cpl_table_has_column(chantab,
"iymax") ||
1012 ! cpl_table_has_column(chantab,
"channum")) {
1013 cpl_msg_error(fctid,
"Channel table is missing one of the required columns");
1057 nrows = (int)cpl_table_count_selected(chantab);
1063 for (i = 0; i < nrows; i++) {
1064 ixmin = cpl_table_get_int(chantab,
"ixmin",(cpl_size)i,NULL);
1065 ixmax = cpl_table_get_int(chantab,
"ixmax",(cpl_size)i,NULL);
1066 iymin = cpl_table_get_int(chantab,
"iymin",(cpl_size)i,NULL);
1067 iymax = cpl_table_get_int(chantab,
"iymax",(cpl_size)i,NULL);
1068 cnum = cpl_table_get_int(chantab,
"channum",(cpl_size)i,NULL);
1075 cx = ixmax - ixmin + 1;
1076 cy = iymax - iymin + 1;
1080 }
else if (cx < cy) {
1092 work = cpl_malloc(idx*idy*
sizeof(*work));
1096 for (icy = 0; icy < ncy; icy++) {
1098 indy2 = min(iymax,indy1+idy-1);
1099 for (icx = 0; icx < ncx; icx++) {
1101 indx2 = min(ixmax,indx1+idx-1);
1103 for (jcy = indy1; jcy < indy2; jcy++) {
1105 for (jcx = indx1; jcx < indx2; jcx++) {
1107 if (bpm != NULL && bpm[ii] == 0)
1108 work[jp++] = ddata[ii];
1113 cpl_table_set_int(*diffimstats,
"xmin",(cpl_size)nr,indx1+1);
1114 cpl_table_set_int(*diffimstats,
"xmax",(cpl_size)nr,indx2+1);
1115 cpl_table_set_int(*diffimstats,
"ymin",(cpl_size)nr,indy1+1);
1116 cpl_table_set_int(*diffimstats,
"ymax",(cpl_size)nr,indy2+1);
1117 cpl_table_set_int(*diffimstats,
"chan",(cpl_size)nr,cnum);
1118 cpl_table_set_float(*diffimstats,
"mean",(cpl_size)nr,mean);
1119 cpl_table_set_float(*diffimstats,
"median",(cpl_size)nr,med);
1120 cpl_table_set_float(*diffimstats,
"variance",(cpl_size)nr,
1122 cpl_table_set_float(*diffimstats,
"mad",(cpl_size)(nr++),mad);
1149 cpl_table *diffimstats;
1151 diffimstats = cpl_table_new((cpl_size)nrows);
1152 cpl_table_new_column(diffimstats,
"xmin",CPL_TYPE_INT);
1153 cpl_table_set_column_unit(diffimstats,
"xmin",
"pixels");
1154 cpl_table_new_column(diffimstats,
"xmax",CPL_TYPE_INT);
1155 cpl_table_set_column_unit(diffimstats,
"xmax",
"pixels");
1156 cpl_table_new_column(diffimstats,
"ymin",CPL_TYPE_INT);
1157 cpl_table_set_column_unit(diffimstats,
"ymin",
"pixels");
1158 cpl_table_new_column(diffimstats,
"ymax",CPL_TYPE_INT);
1159 cpl_table_set_column_unit(diffimstats,
"ymax",
"pixels");
1160 cpl_table_new_column(diffimstats,
"chan",CPL_TYPE_INT);
1161 cpl_table_set_column_unit(diffimstats,
"chan",
"pixels");
1162 cpl_table_new_column(diffimstats,
"mean",CPL_TYPE_FLOAT);
1163 cpl_table_set_column_unit(diffimstats,
"mean",
"ADU");
1164 cpl_table_new_column(diffimstats,
"median",CPL_TYPE_FLOAT);
1165 cpl_table_set_column_unit(diffimstats,
"median",
"ADU");
1166 cpl_table_new_column(diffimstats,
"variance",CPL_TYPE_FLOAT);
1167 cpl_table_set_column_unit(diffimstats,
"variance",
"ADU**2");
1168 cpl_table_new_column(diffimstats,
"mad",CPL_TYPE_FLOAT);
1169 cpl_table_set_column_unit(diffimstats,
"mad",
"ADU");
1170 return(diffimstats);
1201 int increment,i,j,k;
1204 t = cpl_malloc(m*
sizeof(*t));
1207 while (increment > 0) {
1208 for (i = increment; i < n; i++) {
1210 for (k = 0; k < m; k++)
1212 while ((j >= increment) && (a[0][j-increment] > t[0])) {
1213 for (k = 0; k < m; k++)
1214 a[k][j] = a[k][j-increment];
1217 for (k = 0; k < m; k++)
1223 increment = (int)((
float)increment/2.2);
1250 const char *fctid =
"vircam_getnpts";
1252 if ((nx = (
int)cpl_image_get_size_x(in)) == -1) {
1253 cpl_msg_error(fctid,
"NULL image input");
1256 if ((ny = (
int)cpl_image_get_size_y(in)) == -1) {
1257 cpl_msg_error(fctid,
"NULL image input");
1298 int nlist,
float err) {
1300 float errsq,errmin,dx,dy,poserr;
1307 indx = (isp + ifp)/2;
1308 while (ifp-isp >= 2) {
1309 if (ylist[indx] < y - err) {
1311 indx = (indx+ifp)/2;
1312 }
else if (ylist[indx] > y - err) {
1314 indx = (indx+isp)/2;
1325 for (i = isp; i < nlist; i++) {
1326 if (ylist[i] > y+err)
1330 poserr = dx*dx + dy*dy;
1331 if (poserr < errsq) {
1332 if (poserr <= errmin) {
1365 cdata = cpl_malloc(n*
sizeof(*cdata));
1366 for (i = 0; i < n; i++)
1398 if (cpl_image_get_size_x(im1) != cpl_image_get_size_x(im2) ||
1399 cpl_image_get_size_y(im1) != cpl_image_get_size_y(im2))
1428 extern void vircam_prov(cpl_propertylist *p, vir_fits **inlist,
int n) {
1430 char keyword[SZKEY],value[SZVAL],*fn,*base;
1434 cpl_propertylist_erase_regexp(p,
"ESO DRS PROV*",0);
1438 for (i = 0; i < n; i++) {
1439 (void)snprintf(keyword,SZKEY,
"ESO DRS PROV%04d",i+1);
1441 base = basename(fn);
1442 (void)snprintf(value,SZVAL,
"%s",base);
1444 cpl_propertylist_update_string(p,keyword,value);
1445 (void)snprintf(value,SZVAL,
"Input file # %d",i+1);
1446 cpl_propertylist_set_comment(p,keyword,value);
1471 cpl_propertylist *p2) {
1477 if (p1 == NULL || p2 == NULL)
1484 for (i = 0; i < cpl_propertylist_get_size(p2); i++) {
1485 name = cpl_property_get_name(cpl_propertylist_get(p2,i));
1486 if (cpl_propertylist_has(p1,name))
1487 cpl_propertylist_erase(p1,name);
1489 cpl_propertylist_append(p1,p2);
1523 cpl_propertylist_update_bool(p,
"ESO DRS IMADUMMY",TRUE);
1524 cpl_propertylist_set_comment(p,
"ESO DRS IMADUMMY",
1525 "This is a dummy product");
1556 return(cpl_propertylist_has(p,
"ESO DRS IMADUMMY"));
1600 float hthr,
int ditch,
float *minv,
float *maxv,
1604 double val,dndit,sum;
1608 dndit = (double)ndit;
1613 for (i = 0; i < *n; i++) {
1615 val = cpl_image_get_median_window(im,500,500,1000,1000);
1617 *minv = min(*minv,val);
1618 *maxv = max(*maxv,val);
1620 if (val > lthr && val < hthr) {
1621 fitslist[m++] = fitslist[i];
1627 for (i = m; i < *n; i++)
1629 *avev = sum/(double)*n;
1661 cpl_image_multiply_scalar(im,0.0);
1720 illcor = cpl_table_new((cpl_size)nrows);
1721 for (i = 0; i < NI_COLS; i++)
1722 cpl_table_new_column(illcor,illcor_cols[i],CPL_TYPE_FLOAT);
1759 (void)gettimeofday(&tv,NULL);
1760 tm = gmtime(&(tv.tv_sec));
1761 sec = (float)tm->tm_sec + 1.0e-6*(
float)tv.tv_usec;
1765 (void)snprintf(out,n,
"%04d-%02d-%02dT%02d:%02d:%07.4f",1900+tm->tm_year,
1766 tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,sec);
1801 cpl_image **out,
float *med) {
1802 int i,j,nx,ny,ifracx,ifracy,nbsizx,nbsizy,nbx,nby,*nps,jx,jy;
1803 int jy1,jy2,np,nout,jyp1,jxp1,jz1,jz2,jz3,jz4,nbsize2;
1804 float fracx,fracy,*bmap,**rowpoints,*data,*ptr,dely,delx,t1,t2;
1811 fracx = ((float)nx)/((float)nbsize);
1812 fracy = ((float)ny)/((float)nbsize);
1813 ifracx = (int)(fracx + 0.1);
1814 ifracy = (int)(fracy + 0.1);
1817 nbsize = max(vircam_nint(0.9*nbsize),min(nbsize,min(nbsizx,nbsizy)));
1818 nbsize = min(nx,min(ny,nbsize));
1828 bmap = cpl_malloc(nbx*nby*
sizeof(
float));
1829 rowpoints = cpl_malloc(nbx*
sizeof(
float *));
1830 nps = cpl_malloc(nbx*
sizeof(
int));
1845 for (i = 0; i < nbx; i++)
1846 rowpoints[i] = cpl_malloc(nbsize*nbsize*
sizeof(
float));
1851 for (jy = 0; jy < nby; jy++) {
1853 jy2 = min((jy+1)*nbsize - 1,ny-1);
1857 for (jx = 0; jx < nbx; jx++)
1864 for (j = jy1; j <= jy2; j++) {
1865 for (i = 0; i < nx; i++) {
1866 jx = min(nbx-1,i/nbsize);
1867 if (bpm[j*nx + i] == 0) {
1868 ptr = rowpoints[jx];
1870 ptr[np++] = data[j*nx + i];
1878 for (jx = 0; jx < nbx; jx++) {
1879 bmap[jy*nbx+jx] =
vircam_med(rowpoints[jx],NULL,(
long)(nps[jx]));
1880 if (bmap[jy*nbx+jx] != CX_MAXFLOAT) {
1881 bmap[jy*nbx+jx] -= *med;
1883 bmap[jy*nbx+jx] = 0.0;
1890 for (jx = 0; jx < nbx; jx++)
1891 freespace(rowpoints[jx]);
1892 freespace(rowpoints);
1897 *out = cpl_image_new((cpl_size)nx,(cpl_size)ny,CPL_TYPE_FLOAT);
1898 ptr = cpl_image_get_data_float(*out);
1904 for (j = 1; j <= ny; j++) {
1905 jy = (j + nbsize2)/nbsize;
1907 jy = min(nby,max(1,jy));
1908 jyp1 = min(nby,jyp1);
1909 dely = (float)(j - nbsize*jy + nbsize2)/(float)nbsize;
1910 dely = max(0.0,min(1.0,dely));
1911 for (i = 1; i <= nx; i++) {
1912 jx = (i + nbsize2)/nbsize;
1914 jx = min(nbx,max(1,jx));
1915 jxp1 = min(nbx,jxp1);
1916 delx = (float)(i - nbsize*jx + nbsize2)/(float)nbsize;
1917 delx = max(0.0,min(1.0,delx));
1918 jz1 = (jy - 1)*nbx + jx;
1919 jz2 = (jyp1 - 1)*nbx + jx;
1927 t1 = (1.0 - delx)*bmap[jz1-1] + delx*bmap[jz3-1];
1928 t2 = (1.0 - delx)*bmap[jz2-1] + delx*bmap[jz4-1];
1929 ptr[nout++] = (1.0 - dely)*t1 + dely*t2;
1963 if (!strcmp(col,
"X")) {
1964 if (cpl_propertylist_has(p,
"ESO DRS XCOL"))
1965 return(cpl_propertylist_get_int(p,
"ESO DRS XCOL"));
1968 }
else if (!strcmp(col,
"Y")) {
1969 if (cpl_propertylist_has(p,
"ESO DRS YCOL"))
1970 return(cpl_propertylist_get_int(p,
"ESO DRS YCOL"));
2002 cpl_propertylist *temp;
2003 cpl_property *property;
2010 if (! cpl_propertylist_has(p,oldname))
2012 temp = cpl_propertylist_new();
2013 cpl_propertylist_copy_property(temp,p,oldname);
2014 property = cpl_propertylist_get(temp,0);
2018 cpl_property_set_name(property,newname);
2022 cpl_propertylist_append(p,temp);
2023 cpl_propertylist_erase(p,oldname);
2024 cpl_propertylist_delete(temp);
2058 cpl_propertylist *p;
2061 const char *fctid =
"vircam_catpars",*unk =
"unknown";
2070 fname = cpl_strdup(cpl_frame_get_filename(indx));
2071 if (access((
const char *)fname,R_OK) != 0) {
2072 cpl_msg_error(fctid,
"Can't access index file %s",fname);
2076 *catpath = cpl_strdup(dirname(fname));
2081 if ((p = cpl_propertylist_load(cpl_frame_get_filename(indx),0)) == NULL) {
2082 freespace(*catpath);
2083 cpl_msg_error(fctid,
"Can't load index file header %s",
2084 cpl_frame_get_filename(indx));
2092 if (cpl_propertylist_has(p,
"CATNAME")) {
2093 *catname = cpl_strdup(cpl_propertylist_get_string(p,
"CATNAME"));
2096 *catname = cpl_strdup(unk);
2097 cpl_msg_warning(fctid,
"Property CATNAME not in index file header %s",
2098 cpl_frame_get_filename(indx));
2102 freepropertylist(p);
2146 unsigned char *iflag;
2147 cpl_propertylist *p;
2151 if (*status != VIR_OK)
2158 *n = cpl_frame_get_nextensions(frame);
2159 *cors = cpl_malloc(*n*
sizeof(
float));
2160 iflag = cpl_calloc(*n,
sizeof(iflag));
2166 for (i = 0; i < *n; i++) {
2167 p = cpl_propertylist_load(cpl_frame_get_filename(frame),(cpl_size)(i+1));
2168 if (cpl_propertylist_has(p,
"ESO DRS IMADUMMY")) {
2170 }
else if (! cpl_propertylist_has(p,
"ESO DRS MEDFLAT")) {
2173 val = cpl_propertylist_get_double(p,
"ESO DRS MEDFLAT");
2182 cpl_propertylist_delete(p);
2191 sum /= (float)ngood;
2192 for (i = 0; i < *n; i++) {
2193 if (iflag[i] == 0) {
2194 (*cors)[i] = sum/(*cors)[i];
2235 double crval1,crval2;
2253 if (fabs(crval1) < 1.0e-6 && fabs(crval2) < 1.0e-6) {
2257 p = cpl_propertylist_get_property(ehu,
"CRVAL1");
2258 cpl_property_set_name(p,
"OLDCR1");
2259 p = cpl_propertylist_get_property(ehu,
"CRVAL2");
2260 cpl_property_set_name(p,
"OLDCR2");
2261 cpl_propertylist_insert_after_double(ehu,
"OLDCR2",
"CRVAL1",crval1);
2262 cpl_propertylist_insert_after_double(ehu,
"CRVAL1",
"CRVAL2",crval2);
2263 cpl_propertylist_erase(ehu,
"OLDCR1");
2264 cpl_propertylist_erase(ehu,
"OLDCR2");