Commit 90385513 authored by Emmanuel Bertin's avatar Emmanuel Bertin
Browse files

Fixed issue with output Check-image headers when reading individual extensions...

Fixed issue with output Check-image headers when reading individual extensions from MEFs (thanks to user Lantern for the bug report).
parent ec2f0c6f
.TH SEXTRACTOR "1" "November 2010" "SExtractor 2.13.1" "User Commands" .TH SEXTRACTOR "1" "December 2010" "SExtractor 2.13.1" "User Commands"
.SH NAME .SH NAME
sex \- extract a source catalogue from an astronomical FITS image sex \- extract a source catalogue from an astronomical FITS image
.SH SYNOPSIS .SH SYNOPSIS
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>. * along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
* *
* Last modified: 11/10/2010 * Last modified: 12/02/2010
* *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...@@ -155,32 +155,28 @@ initialize check-image. ...@@ -155,32 +155,28 @@ initialize check-image.
checkstruct *initcheck(char *filename, checkenum check_type, int next) checkstruct *initcheck(char *filename, checkenum check_type, int next)
{ {
catstruct *fitscat; catstruct *cat;
checkstruct *check; checkstruct *check;
QCALLOC(check, checkstruct, 1); QCALLOC(check, checkstruct, 1);
strcpy(check->filename, filename);
check->type = check_type; check->type = check_type;
check->next = next;
cat = check->cat = new_cat(1);
strcpy(cat->filename, filename);
if (next>1) if (next>1)
/*-- Create a "pure" primary HDU */ /*-- Create a "pure" primary HDU */
{ {
fitscat = new_cat(1); init_cat(cat);
init_cat(fitscat); addkeywordto_head(cat->tab, "NEXTEND ", "Number of extensions");
strcpy(fitscat->filename, filename); fitswrite(cat->tab->headbuf, "NEXTEND ", &next, H_INT, T_LONG);
fitsadd(fitscat->tab->headbuf, "NEXTEND ", "Number of extensions"); if (open_cat(cat, WRITE_ONLY) != RETURN_OK)
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); error(EXIT_FAILURE,"*Error*: cannot open for writing ", filename);
save_tab(fitscat, fitscat->tab); save_head(cat, cat->tab);
check->file = fitscat->file; remove_tabs(cat);
fitscat->file = NULL;
free_cat(&fitscat, 1);
} }
else else
if (!(check->file = fopen(check->filename, "wb"))) open_cat(cat, WRITE_ONLY);
error(EXIT_FAILURE, "*Error*: Cannot open for output ", check->filename);
return check; return check;
} }
...@@ -193,25 +189,37 @@ initialize check-image (for subsequent writing). ...@@ -193,25 +189,37 @@ initialize check-image (for subsequent writing).
void reinitcheck(picstruct *field, checkstruct *check) void reinitcheck(picstruct *field, checkstruct *check)
{ {
catstruct *cat;
tabstruct *tab;
wcsstruct *wcs; wcsstruct *wcs;
char *buf; char *fitshead;
int i, ival;
size_t padsize;
double dval;
ULONG *ptri;
PIXTYPE *ptrf; PIXTYPE *ptrf;
double dval;
int i;
cat = check->cat;
/* Inherit the field FITS header */ /* Inherit the field FITS header */
check->fitsheadsize = field->tab->headnblock*FBSIZE; remove_tabs(cat);
QMEMCPY(field->tab->headbuf, check->fitshead, char, check->fitsheadsize); copy_tab_fromptr(field->tab, cat, 0);
tab = cat->tab;
tab->cat = cat;
if (check->next<=1)
prim_head(tab);
check->y = 0; check->y = 0;
fitshead = tab->headbuf;
/* Neutralize possible scaling factors */ /* Neutralize possible scaling factors */
dval = 1.0;fitswrite(check->fitshead, "BSCALE ", &dval, H_FLOAT, T_DOUBLE); tab->bytepix = 4;
dval = 0.0;fitswrite(check->fitshead, "BZERO ", &dval, H_FLOAT, T_DOUBLE); tab->bscale = 1.0;
ival = 1;fitswrite(check->fitshead, "BITSGN ", &ival, H_INT, T_LONG); tab->bzero = 0.0;
if (field->tab->compress_type != COMPRESS_NONE) fitswrite(fitshead, "BSCALE ", &tab->bscale, H_FLOAT, T_DOUBLE);
fitswrite(check->fitshead, "IMAGECOD", "NONE", H_STRING, T_STRING); fitswrite(fitshead, "BZERO ", &tab->bzero, H_FLOAT, T_DOUBLE);
fitswrite(check->fitshead, "ORIGIN ", BANNER, H_STRING, T_STRING); fitswrite(fitshead, "BITSGN ", &tab->bitsgn, H_INT, T_LONG);
if (tab->compress_type != COMPRESS_NONE)
{
tab->compress_type = COMPRESS_NONE;
fitswrite(fitshead, "IMAGECOD", "NONE", H_STRING, T_STRING);
}
fitswrite(fitshead, "ORIGIN ", BANNER, H_STRING, T_STRING);
switch(check->type) switch(check->type)
{ {
...@@ -219,28 +227,25 @@ void reinitcheck(picstruct *field, checkstruct *check) ...@@ -219,28 +227,25 @@ void reinitcheck(picstruct *field, checkstruct *check)
case CHECK_BACKGROUND: case CHECK_BACKGROUND:
case CHECK_FILTERED: case CHECK_FILTERED:
case CHECK_SUBTRACTED: case CHECK_SUBTRACTED:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
check->width = field->width; tab->naxisn[0] = check->width = field->width;
check->height = field->height; tab->naxisn[1] = check->height = field->height;
check->npix = field->npix; check->npix = field->npix;
QMALLOC(ptrf, PIXTYPE, check->width); QMALLOC(ptrf, PIXTYPE, check->width);
check->pix = (void *)ptrf; check->pix = (void *)ptrf;
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); save_head(cat, cat->tab);
free(check->fitshead);
break; break;
case CHECK_BACKRMS: case CHECK_BACKRMS:
case CHECK_SUBOBJECTS: case CHECK_SUBOBJECTS:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
check->width = field->width; tab->naxisn[0] = check->width = field->width;
check->height = field->height; tab->naxisn[1] = check->height = field->height;
check->npix = field->npix; check->npix = field->npix;
QMALLOC(ptrf, PIXTYPE, check->width); QMALLOC(check->pix, PIXTYPE, check->width);
check->pix = (void *)ptrf; save_head(cat, cat->tab);
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename);
free(check->fitshead);
/*---- Allocate memory for replacing the blanked pixels by 0 */ /*---- Allocate memory for replacing the blanked pixels by 0 */
if (!check->line) if (!check->line)
QMALLOC(check->line, PIXTYPE, field->width); QMALLOC(check->line, PIXTYPE, field->width);
...@@ -260,123 +265,97 @@ void reinitcheck(picstruct *field, checkstruct *check) ...@@ -260,123 +265,97 @@ void reinitcheck(picstruct *field, checkstruct *check)
case CHECK_DISKS: case CHECK_DISKS:
case CHECK_SUBDISKS: case CHECK_SUBDISKS:
case CHECK_PATTERNS: case CHECK_PATTERNS:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
check->width = field->width; tab->naxisn[0] = check->width = field->width;
check->height = field->height; tab->naxisn[1] = check->height = field->height;
check->npix = field->npix; check->npix = field->npix;
check->overlay = 30*field->backsig; check->overlay = 30*field->backsig;
QCALLOC(ptrf, PIXTYPE, check->npix); QCALLOC(check->pix, PIXTYPE, check->npix);
check->pix = (void *)ptrf; save_head(cat, cat->tab);
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename);
free(check->fitshead);
break; break;
case CHECK_SEGMENTATION: case CHECK_SEGMENTATION:
ival = 32; tab->bitpix = 32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 1;
check->width = field->width; tab->naxisn[0] = check->width = field->width;
check->height = field->height; tab->naxisn[1] = check->height = field->height;
check->npix = field->npix; check->npix = field->npix;
QCALLOC(ptri, ULONG, check->npix); QCALLOC(check->pix, ULONG, check->npix);
check->pix = (void *)ptri; save_head(cat, cat->tab);
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename);
free(check->fitshead);
break; break;
case CHECK_ASSOC: case CHECK_ASSOC:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
check->width = field->width; tab->naxisn[0] = check->width = field->width;
check->height = field->height; tab->naxisn[1] = check->height = field->height;
check->npix = field->npix; check->npix = field->npix;
QMALLOC(ptrf, PIXTYPE, check->npix); QMALLOC(check->pix, PIXTYPE, check->npix);
check->pix = (void *)ptrf;
/*---- Initialize the pixmap to IEEE NaN */ /*---- Initialize the pixmap to IEEE NaN */
memset(ptrf, 0xFF, check->npix*sizeof(LONG)); memset(check->pix, 0xFF, check->npix*sizeof(LONG));
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); save_head(cat, cat->tab);
free(check->fitshead);
break; break;
case CHECK_MINIBACKGROUND: case CHECK_MINIBACKGROUND:
case CHECK_MINIBACKRMS: case CHECK_MINIBACKRMS:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
check->width = field->nbackx; tab->naxisn[0] = check->width = field->nbackx;
fitswrite(check->fitshead, "NAXIS1 ", &check->width, H_INT, T_LONG); tab->naxisn[1] = check->height = field->nbacky;
check->height = field->nbacky;
fitswrite(check->fitshead, "NAXIS2 ", &check->height, H_INT, T_LONG);
/*---- Scale the WCS information if present */ /*---- Scale the WCS information if present */
if ((wcs=field->wcs)) if ((wcs=field->wcs))
{ {
dval = wcs->cdelt[0]*field->backw; dval = wcs->cdelt[0]*field->backw;
fitswrite(check->fitshead, "CDELT1 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CDELT1 ", &dval, H_EXPO, T_DOUBLE);
dval = wcs->cdelt[1]*field->backh; dval = wcs->cdelt[1]*field->backh;
fitswrite(check->fitshead, "CDELT2 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CDELT2 ", &dval, H_EXPO, T_DOUBLE);
dval = (wcs->crpix[0]-0.5)/field->backw + 0.5; dval = (wcs->crpix[0]-0.5)/field->backw + 0.5;
fitswrite(check->fitshead, "CRPIX1 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CRPIX1 ", &dval, H_EXPO, T_DOUBLE);
dval = (wcs->crpix[1]-0.5)/field->backh + 0.5; dval = (wcs->crpix[1]-0.5)/field->backh + 0.5;
fitswrite(check->fitshead, "CRPIX2 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CRPIX2 ", &dval, H_EXPO, T_DOUBLE);
dval = wcs->cd[0]*field->backw; dval = wcs->cd[0]*field->backw;
fitswrite(check->fitshead, "CD1_1 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CD1_1 ", &dval, H_EXPO, T_DOUBLE);
dval = wcs->cd[1]*field->backh; dval = wcs->cd[1]*field->backh;
fitswrite(check->fitshead, "CD1_2 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CD1_2 ", &dval, H_EXPO, T_DOUBLE);
dval = wcs->cd[wcs->naxis]*field->backw; dval = wcs->cd[wcs->naxis]*field->backw;
fitswrite(check->fitshead, "CD2_1 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CD2_1 ", &dval, H_EXPO, T_DOUBLE);
dval = wcs->cd[wcs->naxis+1]*field->backh; dval = wcs->cd[wcs->naxis+1]*field->backh;
fitswrite(check->fitshead, "CD2_2 ", &dval, H_EXPO, T_DOUBLE); fitswrite(fitshead, "CD2_2 ", &dval, H_EXPO, T_DOUBLE);
} }
check->npix = check->width*check->height; check->npix = check->width*check->height;
QMALLOC(ptrf, PIXTYPE, check->npix); QMALLOC(check->pix, PIXTYPE, check->npix);
check->pix = (void *)ptrf;
if (check->type==CHECK_MINIBACKRMS) if (check->type==CHECK_MINIBACKRMS)
memcpy(check->pix, field->sigma, check->npix*sizeof(float)); memcpy(check->pix, field->sigma, check->npix*sizeof(float));
else else
memcpy(check->pix, field->back, check->npix*sizeof(float)); memcpy(check->pix, field->back, check->npix*sizeof(float));
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); save_head(cat, cat->tab);
free(check->fitshead); write_body(cat->tab, check->pix, check->npix);
if (bswapflag)
swapbytes(check->pix, sizeof(float), (int)check->npix);
QFWRITE(check->pix,check->npix*sizeof(float),check->file,
check->filename);
/*---- Put the buffer back to its original state */
if (bswapflag)
swapbytes(check->pix, sizeof(float), (int)check->npix);
free(check->pix); free(check->pix);
QCALLOC(buf, char, FBSIZE);
padsize = (FBSIZE -((check->npix*sizeof(PIXTYPE))%FBSIZE))% FBSIZE;
if (padsize)
QFWRITE (buf, padsize, check->file, check->filename);
free(buf);
break; break;
case CHECK_MAPSOM: case CHECK_MAPSOM:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
check->width = field->width; tab->naxisn[0] = check->width = field->width;
check->height = field->height; tab->naxisn[1] = check->height = field->height;
check->npix = field->npix; check->npix = field->npix;
QMALLOC(ptrf, PIXTYPE, check->npix); QMALLOC(ptrf, PIXTYPE, check->npix);
check->pix = (void *)ptrf; check->pix = (void *)ptrf;
for (i=check->npix; i--;) for (i=check->npix; i--;)
*(ptrf++) = -10.0; *(ptrf++) = -10.0;
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); save_head(cat, cat->tab);
free(check->fitshead);
break; break;
case CHECK_OTHER: case CHECK_OTHER:
ival = -32; tab->bitpix = -32;
fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); tab->bitsgn = 0;
fitswrite(check->fitshead, "NAXIS1 ", &check->width, H_INT, T_LONG); tab->naxisn[0] = check->width;
fitswrite(check->fitshead, "NAXIS2 ", &check->height, H_INT, T_LONG); tab->naxisn[1] = check->height;
check->npix = check->width*check->height; check->npix = check->width*check->height;
QMALLOC(ptrf, PIXTYPE, check->npix); QCALLOC(check->pix, PIXTYPE, check->npix);
check->pix = (void *)ptrf; save_head(cat, cat->tab);
for (i=check->npix; i--;)
*(ptrf++) = 0.0;
QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename);
free(check->fitshead);
break; break;
default: default:
...@@ -413,12 +392,7 @@ void writecheck(checkstruct *check, PIXTYPE *data, int w) ...@@ -413,12 +392,7 @@ void writecheck(checkstruct *check, PIXTYPE *data, int w)
data = check->line; data = check->line;
} }
if (bswapflag) write_body(check->cat->tab, data, w);
swapbytes(data, sizeof(PIXTYPE), w);
QFWRITE(data, w*sizeof(PIXTYPE), check->file, check->filename);
if (bswapflag)
/*-- Put the buffer back to its original state */
swapbytes(data, sizeof(PIXTYPE), w);
return; return;
} }
...@@ -430,10 +404,10 @@ Finish current check-image. ...@@ -430,10 +404,10 @@ Finish current check-image.
*/ */
void reendcheck(picstruct *field, checkstruct *check) void reendcheck(picstruct *field, checkstruct *check)
{ {
catstruct *cat;
char *buf; char *buf;
size_t padsize;
padsize = 0; /* To avoid gcc -Wall warnings */ cat = check->cat;
switch(check->type) switch(check->type)
{ {
case CHECK_MINIBACKGROUND: case CHECK_MINIBACKGROUND:
...@@ -448,7 +422,7 @@ void reendcheck(picstruct *field, checkstruct *check) ...@@ -448,7 +422,7 @@ void reendcheck(picstruct *field, checkstruct *check)
free(check->pix); free(check->pix);
free(check->line); free(check->line);
check->line = NULL; check->line = NULL;
padsize = (FBSIZE -((check->npix*sizeof(PIXTYPE))%FBSIZE)) % FBSIZE; pad_tab(cat, check->npix*sizeof(PIXTYPE));
break; break;
case CHECK_OBJECTS: case CHECK_OBJECTS:
...@@ -468,21 +442,15 @@ void reendcheck(picstruct *field, checkstruct *check) ...@@ -468,21 +442,15 @@ void reendcheck(picstruct *field, checkstruct *check)
case CHECK_PATTERNS: case CHECK_PATTERNS:
case CHECK_MAPSOM: case CHECK_MAPSOM:
case CHECK_OTHER: case CHECK_OTHER:
if (bswapflag) write_body(cat->tab, check->pix, check->npix);
swapbytes(check->pix, sizeof(PIXTYPE), (int)check->npix);
QFWRITE(check->pix,check->npix*sizeof(PIXTYPE),
check->file,check->filename);
free(check->pix); free(check->pix);
padsize = (FBSIZE-((check->npix*sizeof(PIXTYPE))%FBSIZE)) % FBSIZE; pad_tab(cat, check->npix*sizeof(PIXTYPE));
break; break;
case CHECK_SEGMENTATION: case CHECK_SEGMENTATION:
if (bswapflag) write_ibody(cat->tab, check->pix, check->npix);
swapbytes(check->pix, sizeof(ULONG), (int)check->npix);
QFWRITE(check->pix,check->npix*sizeof(ULONG),
check->file,check->filename);
free(check->pix); free(check->pix);
padsize = (FBSIZE -((check->npix*sizeof(ULONG))%FBSIZE)) % FBSIZE; pad_tab(cat, check->npix*sizeof(FLAGTYPE));
break; break;
case CHECK_SUBOBJECTS: case CHECK_SUBOBJECTS:
...@@ -494,7 +462,7 @@ void reendcheck(picstruct *field, checkstruct *check) ...@@ -494,7 +462,7 @@ void reendcheck(picstruct *field, checkstruct *check)
free(check->pix); free(check->pix);
free(check->line); free(check->line);
check->line = NULL; check->line = NULL;
padsize = (FBSIZE -((check->npix*sizeof(PIXTYPE))%FBSIZE)) % FBSIZE; pad_tab(cat, check->npix*sizeof(PIXTYPE));
break; break;
} }
...@@ -502,11 +470,6 @@ void reendcheck(picstruct *field, checkstruct *check) ...@@ -502,11 +470,6 @@ void reendcheck(picstruct *field, checkstruct *check)
error(EXIT_FAILURE, "*Internal Error* in ", "endcheck()!"); error(EXIT_FAILURE, "*Internal Error* in ", "endcheck()!");
} }
QCALLOC(buf, char, FBSIZE);
if (padsize)
QFWRITE (buf, padsize, check->file, check->filename);
free(buf);
return; return;
} }
...@@ -516,8 +479,7 @@ close check-image. ...@@ -516,8 +479,7 @@ close check-image.
*/ */
void endcheck(checkstruct *check) void endcheck(checkstruct *check)
{ {
free_cat(&check->cat,1);
fclose(check->file);
free(check); free(check);
return; return;
......
...@@ -22,18 +22,20 @@ ...@@ -22,18 +22,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>. * along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
* *
* Last modified: 11/10/2010 * Last modified: 02/12/2010
* *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#ifndef _FITSCAT_H_
#include "fits/fitscat.h"
#endif
/*--------------------------------- structures ------------------------------*/ /*--------------------------------- structures ------------------------------*/
/* Check-image parameters */ /* Check-image parameters */
typedef struct structcheck typedef struct structcheck
{ {
char filename[MAXCHAR]; /* ptr to check-image filename */ int next; /* Number of extensions */
FILE *file; /* ptr to check-image file structure */ catstruct *cat; /* FITS file structure */
char *fitshead; /* ptr to check-image FITS header */
int fitsheadsize; /* size of check-image FITS header */
void *pix; /* ptr to check-image pixmap */ void *pix; /* ptr to check-image pixmap */
int width, height, depth; /* size of check-image */ int width, height, depth; /* size of check-image */
size_t npix; /* number of pixels in check-image */ size_t npix; /* number of pixels in check-image */
......
...@@ -729,7 +729,7 @@ void write_body(tabstruct *tab, PIXTYPE *ptr, size_t size) ...@@ -729,7 +729,7 @@ void write_body(tabstruct *tab, PIXTYPE *ptr, size_t size)
{ {
unsigned char *bufdata = (unsigned char *)cbufdata0; unsigned char *bufdata = (unsigned char *)cbufdata0;
for (i=spoonful; i--;) for (i=spoonful; i--;)
*(bufdata++) = (unsigned char)((*(ptr++)-bz)/bs+0.49999);; *(bufdata++) = (unsigned char)((*(ptr++)-bz)/bs+0.49999);
} }
break; break;
...@@ -830,6 +830,158 @@ void write_body(tabstruct *tab, PIXTYPE *ptr, size_t size) ...@@ -830,6 +830,158 @@ void write_body(tabstruct *tab, PIXTYPE *ptr, size_t size)
} }
/******* write_ibody ***********************************************************
PROTO write_ibody(tabstruct *tab, FLAGTYPE *ptr, long size)
PURPOSE Write integer values to a FITS body.
INPUT A pointer to the tab structure,
a pointer to the array in memory,
the number of elements to be written.
OUTPUT -.
NOTES .
AUTHOR E. Bertin (IAP)
VERSION 02/12/2010
***/
void write_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size)
{
static FLAGTYPE bufdata0[DATA_BUFSIZE/sizeof(FLAGTYPE)];
catstruct *cat;
char *cbufdata0;
size_t i, bowl, spoonful;
double bs,bz;
bs = tab->bscale;
bz = tab->bzero;
cat = tab->cat;
if (!cat)
error(EXIT_FAILURE, "*Internal Error*: no parent cat structure for table ",
tab->extname);
cbufdata0 = (char *)bufdata0; /* A trick to remove gcc aliasing warnings */
switch(tab->compress_type)
{
/*-- Uncompressed image */
case COMPRESS_NONE:
bowl = DATA_BUFSIZE/tab->bytepix;
spoonful = size<bowl?size:bowl;
for(; size>0; size -= spoonful)
{
if (spoonful>size)
spoonful = size;
switch(tab->bitpix)
{
case BP_BYTE:
if (tab->bitsgn)
{
char *bufdata = (char *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (char)*(ptr++);
}
else
{
unsigned char *bufdata = (unsigned char *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (unsigned char)*(ptr++);
}
break;
case BP_SHORT:
if (tab->bitsgn)
{
short *bufdata = (short *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (short)*(ptr++);
}
else
{
unsigned short *bufdata = (unsigned short *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (unsigned short)*(ptr++);
}
if (bswapflag)
swapbytes(cbufdata0, 2, spoonful);
break;
case BP_LONG:
if (tab->bitsgn)
{
int *bufdata = (int *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (int)*(ptr++);
}
else
{
unsigned int *bufdata = (unsigned int *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (unsigned int)*(ptr++);
}
if (bswapflag)
swapbytes(cbufdata0, 4, spoonful);
break;
#ifdef HAVE_LONG_LONG_INT
case BP_LONGLONG:
if (tab->bitsgn)
{
LONGLONG *bufdata = (LONGLONG *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (LONGLONG)*(ptr++);
}
else
{
ULONGLONG *bufdata = (ULONGLONG *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (ULONGLONG)*(ptr++);
}
if (bswapflag)
swapbytes(cbufdata0, 8, spoonful);
break;
#endif
case BP_FLOAT:
{
float *bufdata = (float *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = (float)((double)*(ptr++)-bz)/bs;
if (bswapflag)
swapbytes(cbufdata0, 4, spoonful);
}
break;
case BP_DOUBLE:
{
double *bufdata = (double *)cbufdata0;
for (i=spoonful; i--;)
*(bufdata++) = ((double)*(ptr++)-bz)/bs;
if (bswapflag)
swapbytes(cbufdata0, 8, spoonful);
}
break;
default:
error(EXIT_FAILURE,"*FATAL ERROR*: unknown BITPIX type in ",
"read_body()");
break;
}
QFWRITE(cbufdata0, spoonful*tab->bytepix, cat->file, cat->filename);
}
break;
/*-- Compressed image */
case COMPRESS_BASEBYTE:
break;
case COMPRESS_PREVPIX:
break;
default:
error(EXIT_FAILURE,"*Internal Error*: unknown compression mode in ",
"read_body()");
}
return;
}
/******* set_maxram *********************************************************** /******* set_maxram ***********************************************************
PROTO int set_maxram(size_t maxram) PROTO int set_maxram(size_t maxram)
PURPOSE Set the maximum amount of silicon memory that can be allocated for PURPOSE Set the maximum amount of silicon memory that can be allocated for
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* along with AstrOmatic software. * along with AstrOmatic software.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
* *
* Last modified: 09/10/2010 * Last modified: 02/12/2010
* *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...@@ -247,6 +247,7 @@ extern void add_cleanupfilename(char *filename), ...@@ -247,6 +247,7 @@ extern void add_cleanupfilename(char *filename),
voprint_obj(FILE *stream, tabstruct *tab), voprint_obj(FILE *stream, tabstruct *tab),
warning(char *, char *), warning(char *, char *),
write_body(tabstruct *tab, PIXTYPE *ptr, size_t size), write_body(tabstruct *tab, PIXTYPE *ptr, size_t size),
write_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size),
write_checksum(tabstruct *tab); write_checksum(tabstruct *tab);
extern char *tdisptoprintf(char *tdisp, char *str), extern char *tdisptoprintf(char *tdisp, char *str),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment