Loading src/fits/fitsbody.c +69 −35 Original line number Diff line number Diff line Loading @@ -85,8 +85,6 @@ PIXTYPE *alloc_body(tabstruct *tab, void (*func)(PIXTYPE *ptr, int npix)) tab->extname); /* Decide if the data will go in physical memory or on swap-space */ //npix = tab->tabsize/tab->bytepix; npix = tab->naxisn[0] * tab->naxisn[1]; size = npix*sizeof(PIXTYPE); Loading Loading @@ -300,6 +298,61 @@ void free_body(tabstruct *tab) } void readTileCompressed(tabstruct *tab, size_t spoonful, double* bufdata0) { int status, hdutype; // first of all, move to correct HDU status = 0; fits_movabs_hdu(tab->infptr, tab->hdunum, &hdutype, &status); if (status != 0) { printf("Error moving to HDU %d\n", tab->hdunum); fits_report_error(stderr, status); } // pixels count from 1 if (tab->currentElement == 0) tab->currentElement = 1; // now read section of image int datatype; switch(tab->bitpix){ case BYTE_IMG: datatype = TBYTE; break; case SHORT_IMG: datatype = TSHORT; break; case LONG_IMG: datatype = TLONG; break; case FLOAT_IMG: datatype = TFLOAT; break; case DOUBLE_IMG: datatype = TDOUBLE; break; } int anynul; double bscale = 1.0, bzero = 0.0, nulval = 0.; // turn off any scaling so that we copy raw pixel values status = 0; fits_set_bscale(tab->infptr, bscale, bzero, &status); // now read the image status = 0; fits_read_img(tab->infptr, datatype, tab->currentElement, spoonful, &nulval, bufdata0, &anynul, &status); // report reading error if (status != 0) { printf("CFITSIO ERROR reading start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1])); fits_report_error(stderr, status); } // update file 'pointer' tab->currentElement += spoonful; } /******* read_body ************************************************************ PROTO read_body(tabstruct *tab, PIXTYPE *ptr, long size) PURPOSE Read floating point values from the body of a FITS table. Loading Loading @@ -357,38 +410,11 @@ void read_body(tabstruct *tab, PIXTYPE *ptr, size_t size) bufdata = (char *)bufdata0; // CFITSIO if (tab->isTileCompressed) { int status, hdutype; // first of all, move to correct HDU status = 0; fits_movabs_hdu(tab->infptr, tab->hdunum, &hdutype, &status); if (status != 0) { printf("Error moving to HDU %d\n", tab->hdunum); fits_report_error(stderr, status); } // pixels count from 1 if (tab->currentElement == 0) tab->currentElement = 1; // now read section of image status = 0; fits_read_img(tab->infptr, TFLOAT, tab->currentElement, spoonful, NULL, bufdata, NULL, &status); //printf("CFITSIO OK reading start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1])); // report reading error if (status != 0) { printf("CFITSIO ERROR reading start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1])); fits_report_error(stderr, status); } // update file 'pointer' tab->currentElement += spoonful; } if (tab->isTileCompressed) readTileCompressed(tab, spoonful, bufdata0); else QFREAD(bufdata, spoonful*tab->bytepix, cat->file, cat->filename); switch(tab->bitpix) { case BP_BYTE: Loading Loading @@ -666,8 +692,6 @@ void read_body(tabstruct *tab, PIXTYPE *ptr, size_t size) "read_body()"); } //printf("SSSS %f %f %f %f %f\n", bufdata[0], bufdata[10], bufdata[100], bufdata[1000], bufdata[spoonful-1]); return; } Loading Loading @@ -706,7 +730,13 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) if (spoonful>size) spoonful = size; bufdata = (char *)bufdata0; // CFITSIO if (tab->isTileCompressed) readTileCompressed(tab, spoonful, bufdata0); else QFREAD(bufdata, spoonful*tab->bytepix, cat->file, cat->filename); switch(tab->bitpix) { case BP_BYTE: Loading @@ -716,6 +746,7 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) break; case BP_SHORT: if (!tab->isTileCompressed) if (bswapflag) swapbytes(bufdata, 2, spoonful); #pragma ivdep Loading @@ -724,6 +755,7 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) break; case BP_LONG: if (!tab->isTileCompressed) if (bswapflag) swapbytes(bufdata, 4, spoonful); #pragma ivdep Loading @@ -733,6 +765,7 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) #ifdef HAVE_LONG_LONG_INT case BP_LONGLONG: if (!tab->isTileCompressed) if (bswapflag) swapbytes(bufdata, 8, spoonful); #pragma ivdep Loading Loading @@ -974,7 +1007,8 @@ void write_body(tabstruct *tab, PIXTYPE *ptr, size_t size) for (i=spoonful; i--;) *(bufdata++) = (*(ptr++)-bz)/bs; // CFITSIO - only perform byte-swap if we are NOT writing a tile-compressed format using cfitsio // TODO not yet writing CFitsIO from SExtractor. CFITSIO - only perform byte-swap if we are NOT writing a tile-compressed format using cfitsio if (0 && tab->infptr == NULL) // TODO if (bswapflag) swapbytes(cbufdata0, 4, spoonful); Loading src/fits/fitscat.c +22 −1 Original line number Diff line number Diff line Loading @@ -166,6 +166,25 @@ int close_cat(catstruct *cat) } int close_cfitsio(catstruct *cat) { if (cat->tab->infptr) { int status = 0; fits_close_file(cat->tab->infptr, &status); if (status != 0) { fits_report_error(stderr, status); printf("ERROR could not close FITS file with cfitsio: %s\n", cat->filename); } else { //printf("SUCCESS CFITSIO CLOSE\n\n"); cat->tab->infptr == NULL; } } //printf("NO CFITSIO FILE TO CLOSE\n"); } /****** free_cat *************************************************************** PROTO void free_cat(catstruct **cat, int ncat) PURPOSE Free all structures allocated for one or several FITS catalog. Loading Loading @@ -346,7 +365,9 @@ int map_cat(catstruct *cat) tab->infptr = infptr; status = 0; fits_movabs_hdu(tab->infptr, tab->hdunum, &hdutype, &status); if (status != 0) printf("ERROR could not move to hdu %d in file %s\n", tab->hdunum, cat->filename); tab->tabsize = infptr->Fptr->rowlength; //tab->tabsize = infptr->Fptr->rowlength; //printf("TABSIZE = %ld\n", tab->tabsize); if (tab->tabsize) { Loading src/fits/fitscat.h +1 −0 Original line number Diff line number Diff line Loading @@ -282,6 +282,7 @@ extern int about_cat(catstruct *cat, FILE *stream), add_tab(tabstruct *tab, catstruct *cat, int pos), blank_keys(tabstruct *tab), close_cat(catstruct *cat), close_cfitsio(catstruct *cat), copy_key(tabstruct *tabin, char *keyname, tabstruct *tabout, int pos), copy_tab(catstruct *catin, char *tabname, int seg, Loading src/fits/fitshead.c +4 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,10 @@ void readbasic_head(tabstruct *tab) /*random groups parameters (optional)*/ tab->pcount = 0; fitsread(tab->headbuf, "PCOUNT ", &tab->pcount, H_INT, T_LONG); // CFITSIO TODO HACK if (tab->isTileCompressed) tab->pcount = 0; tab->gcount = 1; fitsread(tab->headbuf, "GCOUNT ", &tab->gcount, H_INT, T_LONG); Loading Loading
src/fits/fitsbody.c +69 −35 Original line number Diff line number Diff line Loading @@ -85,8 +85,6 @@ PIXTYPE *alloc_body(tabstruct *tab, void (*func)(PIXTYPE *ptr, int npix)) tab->extname); /* Decide if the data will go in physical memory or on swap-space */ //npix = tab->tabsize/tab->bytepix; npix = tab->naxisn[0] * tab->naxisn[1]; size = npix*sizeof(PIXTYPE); Loading Loading @@ -300,6 +298,61 @@ void free_body(tabstruct *tab) } void readTileCompressed(tabstruct *tab, size_t spoonful, double* bufdata0) { int status, hdutype; // first of all, move to correct HDU status = 0; fits_movabs_hdu(tab->infptr, tab->hdunum, &hdutype, &status); if (status != 0) { printf("Error moving to HDU %d\n", tab->hdunum); fits_report_error(stderr, status); } // pixels count from 1 if (tab->currentElement == 0) tab->currentElement = 1; // now read section of image int datatype; switch(tab->bitpix){ case BYTE_IMG: datatype = TBYTE; break; case SHORT_IMG: datatype = TSHORT; break; case LONG_IMG: datatype = TLONG; break; case FLOAT_IMG: datatype = TFLOAT; break; case DOUBLE_IMG: datatype = TDOUBLE; break; } int anynul; double bscale = 1.0, bzero = 0.0, nulval = 0.; // turn off any scaling so that we copy raw pixel values status = 0; fits_set_bscale(tab->infptr, bscale, bzero, &status); // now read the image status = 0; fits_read_img(tab->infptr, datatype, tab->currentElement, spoonful, &nulval, bufdata0, &anynul, &status); // report reading error if (status != 0) { printf("CFITSIO ERROR reading start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1])); fits_report_error(stderr, status); } // update file 'pointer' tab->currentElement += spoonful; } /******* read_body ************************************************************ PROTO read_body(tabstruct *tab, PIXTYPE *ptr, long size) PURPOSE Read floating point values from the body of a FITS table. Loading Loading @@ -357,38 +410,11 @@ void read_body(tabstruct *tab, PIXTYPE *ptr, size_t size) bufdata = (char *)bufdata0; // CFITSIO if (tab->isTileCompressed) { int status, hdutype; // first of all, move to correct HDU status = 0; fits_movabs_hdu(tab->infptr, tab->hdunum, &hdutype, &status); if (status != 0) { printf("Error moving to HDU %d\n", tab->hdunum); fits_report_error(stderr, status); } // pixels count from 1 if (tab->currentElement == 0) tab->currentElement = 1; // now read section of image status = 0; fits_read_img(tab->infptr, TFLOAT, tab->currentElement, spoonful, NULL, bufdata, NULL, &status); //printf("CFITSIO OK reading start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1])); // report reading error if (status != 0) { printf("CFITSIO ERROR reading start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1])); fits_report_error(stderr, status); } // update file 'pointer' tab->currentElement += spoonful; } if (tab->isTileCompressed) readTileCompressed(tab, spoonful, bufdata0); else QFREAD(bufdata, spoonful*tab->bytepix, cat->file, cat->filename); switch(tab->bitpix) { case BP_BYTE: Loading Loading @@ -666,8 +692,6 @@ void read_body(tabstruct *tab, PIXTYPE *ptr, size_t size) "read_body()"); } //printf("SSSS %f %f %f %f %f\n", bufdata[0], bufdata[10], bufdata[100], bufdata[1000], bufdata[spoonful-1]); return; } Loading Loading @@ -706,7 +730,13 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) if (spoonful>size) spoonful = size; bufdata = (char *)bufdata0; // CFITSIO if (tab->isTileCompressed) readTileCompressed(tab, spoonful, bufdata0); else QFREAD(bufdata, spoonful*tab->bytepix, cat->file, cat->filename); switch(tab->bitpix) { case BP_BYTE: Loading @@ -716,6 +746,7 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) break; case BP_SHORT: if (!tab->isTileCompressed) if (bswapflag) swapbytes(bufdata, 2, spoonful); #pragma ivdep Loading @@ -724,6 +755,7 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) break; case BP_LONG: if (!tab->isTileCompressed) if (bswapflag) swapbytes(bufdata, 4, spoonful); #pragma ivdep Loading @@ -733,6 +765,7 @@ void read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size) #ifdef HAVE_LONG_LONG_INT case BP_LONGLONG: if (!tab->isTileCompressed) if (bswapflag) swapbytes(bufdata, 8, spoonful); #pragma ivdep Loading Loading @@ -974,7 +1007,8 @@ void write_body(tabstruct *tab, PIXTYPE *ptr, size_t size) for (i=spoonful; i--;) *(bufdata++) = (*(ptr++)-bz)/bs; // CFITSIO - only perform byte-swap if we are NOT writing a tile-compressed format using cfitsio // TODO not yet writing CFitsIO from SExtractor. CFITSIO - only perform byte-swap if we are NOT writing a tile-compressed format using cfitsio if (0 && tab->infptr == NULL) // TODO if (bswapflag) swapbytes(cbufdata0, 4, spoonful); Loading
src/fits/fitscat.c +22 −1 Original line number Diff line number Diff line Loading @@ -166,6 +166,25 @@ int close_cat(catstruct *cat) } int close_cfitsio(catstruct *cat) { if (cat->tab->infptr) { int status = 0; fits_close_file(cat->tab->infptr, &status); if (status != 0) { fits_report_error(stderr, status); printf("ERROR could not close FITS file with cfitsio: %s\n", cat->filename); } else { //printf("SUCCESS CFITSIO CLOSE\n\n"); cat->tab->infptr == NULL; } } //printf("NO CFITSIO FILE TO CLOSE\n"); } /****** free_cat *************************************************************** PROTO void free_cat(catstruct **cat, int ncat) PURPOSE Free all structures allocated for one or several FITS catalog. Loading Loading @@ -346,7 +365,9 @@ int map_cat(catstruct *cat) tab->infptr = infptr; status = 0; fits_movabs_hdu(tab->infptr, tab->hdunum, &hdutype, &status); if (status != 0) printf("ERROR could not move to hdu %d in file %s\n", tab->hdunum, cat->filename); tab->tabsize = infptr->Fptr->rowlength; //tab->tabsize = infptr->Fptr->rowlength; //printf("TABSIZE = %ld\n", tab->tabsize); if (tab->tabsize) { Loading
src/fits/fitscat.h +1 −0 Original line number Diff line number Diff line Loading @@ -282,6 +282,7 @@ extern int about_cat(catstruct *cat, FILE *stream), add_tab(tabstruct *tab, catstruct *cat, int pos), blank_keys(tabstruct *tab), close_cat(catstruct *cat), close_cfitsio(catstruct *cat), copy_key(tabstruct *tabin, char *keyname, tabstruct *tabout, int pos), copy_tab(catstruct *catin, char *tabname, int seg, Loading
src/fits/fitshead.c +4 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,10 @@ void readbasic_head(tabstruct *tab) /*random groups parameters (optional)*/ tab->pcount = 0; fitsread(tab->headbuf, "PCOUNT ", &tab->pcount, H_INT, T_LONG); // CFITSIO TODO HACK if (tab->isTileCompressed) tab->pcount = 0; tab->gcount = 1; fitsread(tab->headbuf, "GCOUNT ", &tab->gcount, H_INT, T_LONG); Loading