/* initialize check-image. */ checkstruct *initcheck(char *filename, checkenum check_type, int next) { catstruct *fitscat; checkstruct *check; QCALLOC(check, checkstruct, 1); strcpy(check->filename, filename); check->type = check_type; if (next>1) /*-- Create a "pure" primary HDU */ { fitscat = new_cat(1); init_cat(fitscat); strcpy(fitscat->filename, filename); fitsadd(fitscat->tab->headbuf, "NEXTEND ", "Number of extensions"); fitswrite(fitscat->tab->headbuf, "NEXTEND ", &next, H_INT, T_LONG); if (open_cat(fitscat, WRITE_ONLY) != RETURN_OK) error(EXIT_FAILURE,"*Error*: cannot open for writing ", filename); save_tab(fitscat, fitscat->tab); check->file = fitscat->file; fitscat->file = NULL; free_cat(&fitscat, 1); } else if (!(check->file = fopen(check->filename, "wb"))) error(EXIT_FAILURE, "*Error*: Cannot open for output ", check->filename); return check; }
/****** check_write ******************************************************** PROTO void check_write(fieldstruct *field, char *checkname, checkenum checktype, int ext, int next, int cubeflag) PURPOSE Write a FITS image for check. INPUT Pointer to the field, Pointer to the set, Check-image filename, Check-image type, Extension number, Number of extensions, Datacube flag. OUTPUT -. NOTES Check-image is written as a datacube if cubeflag!=0. AUTHOR E. Bertin (IAP) VERSION 21/09/2015 ***/ void check_write(fieldstruct *field, setstruct *set, char *checkname, checkenum checktype, int ext, int next, int cubeflag) { psfstruct *psf; catstruct *cat; tabstruct *tab; samplestruct **gridsample, *sample,*osample; char filename[MAXCHAR], str[82], *head, *pstr,*pstr2; static double dpos[POLY_MAXDIM], *dpost; double dstep,dstart, dval1,dval2, scalefac, dstepx,dstepy; float *pix,*pix0, *vig,*vig0, *fpix,*fpixsym, val; int i,g,j,l,x,y, w,h,n, npc,nt, nw,nh,np, npos,npos2, step,step2, ipos, inpos, ival1,ival2, npix; /* Create the new cat (well it is not a "cat", but simply a FITS table */ if (!ext) { cat = new_cat(1); init_cat(cat); strcpy(cat->filename, checkname); if (!(pstr = strrchr(cat->filename, '.'))) pstr = cat->filename+strlen(cat->filename); strcpy(filename, field->rcatname); if (!(pstr2 = strrchr(filename, '.'))) pstr2 = filename+strlen(filename); *pstr2 = '\0'; sprintf(pstr, "_%s.fits", filename); if (open_cat(cat, WRITE_ONLY) != RETURN_OK) error(EXIT_FAILURE, "*Error*: cannot open for writing ", cat->filename); if (next>1) { addkeywordto_head(cat->tab, "NEXTEND ", "Number of extensions"); fitswrite(cat->tab->headbuf, "NEXTEND", &next, H_INT, T_LONG); save_tab(cat, cat->tab); } field->ccat[checktype] = cat; } else cat = field->ccat[checktype]; sprintf(str, "chip%02d", ext+1); psf = field->psf[ext]; tab = new_tab(str); head = tab->headbuf; tab->bitpix = BP_FLOAT; tab->bytepix = t_size[T_FLOAT]; switch(checktype) { case PSF_BASIS: /*---- View basis vectors as small vignets */ if (cubeflag) { tab->naxis = 3; QREALLOC(tab->naxisn, int, tab->naxis); tab->naxisn[0] = psf->size[0]; tab->naxisn[1] = psf->size[1]; tab->naxisn[2] = psf->nbasis; npix = tab->naxisn[0]*tab->naxisn[1]*tab->naxisn[2]; tab->tabsize = tab->bytepix*npix; QCALLOC(pix0, float, tab->tabsize); tab->bodybuf = (char *)pix0; pix = pix0; fpix = psf->basis; for (i=npix; i--;) *(pix++) = *(fpix++); } else { nw = (int)sqrt((double)psf->nbasis); nw = ((nw-1)/10+1)*10; nh = (psf->nbasis-1)/nw + 1; w = psf->size[0]; h = psf->dim>1? psf->size[1] : 1; tab->naxisn[0] = nw*w; tab->naxisn[1] = nh*h; step = (nw-1)*w; tab->tabsize = tab->bytepix*tab->naxisn[0]*tab->naxisn[1]; QCALLOC(pix0, float, tab->tabsize); tab->bodybuf = (char *)pix0; fpix = psf->basis; for (n=0; n<psf->nbasis; n++) { pix = pix0 + ((n%nw) + (n/nw)*nw*h)*w; for (y=h; y--; pix += step) for (x=w; x--;) *(pix++) = *(fpix++); } } break; case PSF_CHI: /*---- sqrt(chi2) map in PSF pixel-space nw = 1; nh = 1; w = psf->size[0]; h = psf->size[1]; tab->naxisn[0] = nw*w; tab->naxisn[1] = nh*h; tab->tabsize = tab->bytepix*tab->naxisn[0]*tab->naxisn[1]; QCALLOC(pix0, float, tab->tabsize); tab->bodybuf = (char *)pix0; pix = pix0; fpix = psf->resi; for (i=w*h; i--;) *(pix++) = *(fpix++); break; */ if (cubeflag) { tab->naxis = 3; QREALLOC(tab->naxisn, int, tab->naxis); tab->naxisn[0] = set->vigsize[0]; tab->naxisn[1] = set->vigsize[1]; tab->naxisn[2] = set->ngood? set->ngood : 1; npix = tab->naxisn[0]*tab->naxisn[1]; tab->tabsize = tab->bytepix*npix*tab->naxisn[2]; QCALLOC(pix0, float, tab->tabsize); tab->bodybuf = (char *)pix0; pix = pix0; sample = set->sample; for (n=set->nsample; n--; sample++) { if (sample->badflag) continue; fpix = sample->vigchi; for (i=npix; i--;) *(pix++) = *(fpix++); } } else {