diff --git a/Docs/doxygen/html.doxygen b/Docs/doxygen/html.doxygen index 950525ff..602350f3 100644 --- a/Docs/doxygen/html.doxygen +++ b/Docs/doxygen/html.doxygen @@ -983,7 +983,7 @@ EXCLUDE_SYMLINKS = YES # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = CMakeLists.txt # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -1373,15 +1373,6 @@ HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to YES can help to show when doxygen was last run and thus if the -# documentation is up to date. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = NO - # If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML # documentation will contain a main index with vertical navigation menus that # are dynamically created via JavaScript. If disabled, the navigation index will @@ -2044,14 +2035,6 @@ LATEX_HIDE_INDICES = NO LATEX_BIB_STYLE = plain -# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_TIMESTAMP = NO - # The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute) # path from which the emoji images will be read. If a relative path is entered, # it will be relative to the LATEX_OUTPUT directory. If left blank the diff --git a/SKIRT/fitsio/fitsio2.h b/SKIRT/fitsio/fitsio2.h index 1adb17b6..4d619773 100644 --- a/SKIRT/fitsio/fitsio2.h +++ b/SKIRT/fitsio/fitsio2.h @@ -1,13 +1,13 @@ #ifndef _FITSIO2_H #define _FITSIO2_H - + #include "fitsio.h" -/* +/* Threading support using POSIX threads programming interface - (supplied by Bruce O'Neel) + (supplied by Bruce O'Neel) - All threaded programs MUST have the + All threaded programs MUST have the -D_REENTRANT @@ -50,10 +50,10 @@ extern int Fitsio_Pthread_Status; #define DBUFFSIZE 28800 /* size of data buffer in bytes */ -#define NMAXFILES 10000 /* maximum number of FITS files that can be opened */ +#define NMAXFILES 1000 /* maximum number of FITS files that can be opened */ /* CFITSIO will allocate (NMAXFILES * 80) bytes of memory */ - /* plus each file that is opened will use NIOBUF * 2880 bytes of memeory */ - /* where NIOBUF is defined in fitio.h and has a default value of 40 */ + /* plus each file that is opened will use NIOBUF * 2880 bytes of memeory */ + /* where NIOBUF is defined in fitio.h and has a default value of 40 */ #define MINDIRECT 8640 /* minimum size for direct reads and writes */ /* MINDIRECT must have a value >= 8640 */ @@ -87,9 +87,9 @@ extern int Fitsio_Pthread_Status; /* SUN Solaris7 in 64-bit mode */ #define BYTESWAPPED FALSE #define MACHINE NATIVE -#define LONGSIZE 64 +#define LONGSIZE 64 - /* IBM System z mainframe support */ + /* IBM System z mainframe support */ #elif defined(__s390x__) #define BYTESWAPPED FALSE #define LONGSIZE 64 @@ -101,7 +101,7 @@ extern int Fitsio_Pthread_Status; #elif defined(__ia64__) || defined(__x86_64__) || defined(__AARCH64EL__) /* Intel itanium 64-bit PC, or AMD opteron 64-bit PC */ #define BYTESWAPPED TRUE -#define LONGSIZE 64 +#define LONGSIZE 64 #elif defined(_SX) /* Nec SuperUx */ @@ -155,10 +155,10 @@ extern int Fitsio_Pthread_Status; /* the following are all 32-bit byteswapped platforms */ #elif defined(vax) && defined(VMS) - + #define MACHINE VAXVMS #define BYTESWAPPED TRUE - + #elif defined(__alpha) && defined(__VMS) #if (__D_FLOAT == TRUE) @@ -166,16 +166,16 @@ extern int Fitsio_Pthread_Status; /* this float option is the same as for VAX/VMS machines. */ #define MACHINE VAXVMS #define BYTESWAPPED TRUE - + #elif (__G_FLOAT == TRUE) - + /* G_FLOAT is the default for ALPHA VMS systems */ #define MACHINE ALPHAVMS #define BYTESWAPPED TRUE #define FLOATTYPE GFLOAT - + #elif (__IEEE_FLOAT == TRUE) - + #define MACHINE ALPHAVMS #define BYTESWAPPED TRUE #define FLOATTYPE IEEEFLOAT @@ -185,7 +185,7 @@ extern int Fitsio_Pthread_Status; #elif defined(ultrix) && defined(unix) /* old Dec ultrix machines */ #define BYTESWAPPED TRUE - + #elif defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) \ || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TURBOC__) \ || defined(_NI_mswin_) || defined(__EMX__) @@ -201,7 +201,7 @@ extern int Fitsio_Pthread_Status; /* (__ARMEL__ would be defined on little-endian, but not on big-endian). */ #define BYTESWAPPED TRUE - + #elif defined(__tile__) /* 64-core 8x8-architecture Tile64 platform */ @@ -225,7 +225,7 @@ extern int Fitsio_Pthread_Status; #define MACHINE NATIVE #define BYTESWAPPED FALSE - + #endif #ifndef MACHINE @@ -237,15 +237,15 @@ extern int Fitsio_Pthread_Status; #define LONGSIZE 32 #endif -/* end of block that determine long size and byte swapping */ +/* end of block that determine long size and byte swapping */ /* ==================================================================== */ - + #define IGNORE_EOF 1 #define REPORT_EOF 0 #define DATA_UNDEFINED -1 #define NULL_UNDEFINED 1234554321 #define ASCII_NULL_UNDEFINED 1 /* indicate no defined null value */ - + #define maxvalue(A,B) ((A) > (B) ? (A) : (B)) #define minvalue(A,B) ((A) < (B) ? (A) : (B)) @@ -254,20 +254,20 @@ extern int Fitsio_Pthread_Status; #define FSTRNCMP(a,b,n) ((a)[0]<(b)[0]?-1:(a)[0]>(b)[0]?1:strncmp((a),(b),(n))) #if defined(__VMS) || defined(VMS) - + #define FNANMASK 0xFFFF /* mask all bits */ #define DNANMASK 0xFFFF /* mask all bits */ - + #else - + #define FNANMASK 0x7F80 /* mask bits 1 - 8; all set on NaNs */ /* all 0 on underflow or 0. */ - + #define DNANMASK 0x7FF0 /* mask bits 1 - 11; all set on NaNs */ /* all 0 on underflow or 0. */ - + #endif - + #if MACHINE == CRAY /* Cray machines: the large negative integer corresponds @@ -276,23 +276,23 @@ extern int Fitsio_Pthread_Status; a reserved value (i.e., a NaN) */ #define fnan(L) ( (L) >= 0xE000000000000000 ? 1 : 0) ) - + #else /* these functions work for both big and little endian machines */ /* that use the IEEE floating point format for internal numbers */ - + /* These functions tests whether the float value is a reserved IEEE */ /* value such as a Not-a-Number (NaN), or underflow, overflow, or */ /* infinity. The functions returns 1 if the value is a NaN, overflow */ /* or infinity; it returns 2 if the value is an denormalized underflow */ /* value; otherwise it returns 0. fnan tests floats, dnan tests doubles */ - + #define fnan(L) \ ( (L & FNANMASK) == FNANMASK ? 1 : (L & FNANMASK) == 0 ? 2 : 0) - + #define dnan(L) \ ( (L & DNANMASK) == DNANMASK ? 1 : (L & DNANMASK) == 0 ? 2 : 0) - + #endif #define DSCHAR_MAX 127.49 /* max double value that fits in an signed char */ @@ -384,13 +384,13 @@ int ffgphd(fitsfile *fptr, int maxdim, int *simple, int *bitpix, int *naxis, double *bzero, LONGLONG *blank, int *nspace, int *status); int ffgttb(fitsfile *fptr, LONGLONG *rowlen, LONGLONG *nrows, LONGLONG *pcount, long *tfield, int *status); - + int ffmkey(fitsfile *fptr, const char *card, int *status); - + /* ffmbyt has been moved to fitsio.h */ int ffgbyt(fitsfile *fptr, LONGLONG nbytes, void *buffer, int *status); int ffpbyt(fitsfile *fptr, LONGLONG nbytes, void *buffer, int *status); -int ffgbytoff(fitsfile *fptr, long gsize, long ngroups, long offset, +int ffgbytoff(fitsfile *fptr, long gsize, long ngroups, long offset, void *buffer, int *status); int ffpbytoff(fitsfile *fptr, long gsize, long ngroups, long offset, void *buffer, int *status); @@ -407,12 +407,12 @@ int ffoptplt(fitsfile *fptr, const char *tempname, int *status); int fits_is_this_a_copy(char *urltype); int fits_store_Fptr(FITSfile *Fptr, int *status); int fits_clear_Fptr(FITSfile *Fptr, int *status); -int fits_already_open(fitsfile **fptr, char *url, +int fits_already_open(fitsfile **fptr, char *url, char *urltype, char *infile, char *extspec, char *rowfilter, char *binspec, char *colspec, int mode, int noextsyn, int *isopen, int *status); int ffedit_columns(fitsfile **fptr, char *outfile, char *expr, int *status); -int fits_get_col_minmax(fitsfile *fptr, int colnum, double *datamin, +int fits_get_col_minmax(fitsfile *fptr, int colnum, double *datamin, double *datamax, int *status); int ffwritehisto(long totaln, long offset, long firstn, long nvalues, int narrays, iteratorCol *imagepars, void *userPointer); @@ -433,13 +433,13 @@ int ffgtbp(fitsfile *fptr, char *name, char *value, int *status); int ffiblk(fitsfile *fptr, long nblock, int headdata, int *status); int ffshft(fitsfile *fptr, LONGLONG firstbyte, LONGLONG nbytes, LONGLONG nshift, int *status); - + int ffgcprll(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, LONGLONG nelem, int writemode, double *scale, double *zero, char *tform, long *twidth, int *tcode, int *maxelem, LONGLONG *startpos, LONGLONG *elemnum, long *incre, LONGLONG *repeat, LONGLONG *rowlen, int *hdutype, LONGLONG *tnull, char *snull, int *status); - + int ffflushx(FITSfile *fptr); int ffseek(FITSfile *fptr, LONGLONG position); int ffread(FITSfile *fptr, long nbytes, void *buffer, @@ -450,7 +450,7 @@ int fftrun(fitsfile *fptr, LONGLONG filesize, int *status); int ffpcluc(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, LONGLONG nelem, int *status); - + int ffgcll(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, LONGLONG nelem, int nultyp, char nulval, char *array, char *nularray, int *anynul, int *status); @@ -476,10 +476,10 @@ int ffgcluj(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, LONGLONG nelem, long elemincre, int nultyp, unsigned long nulval, unsigned long *array, char *nularray, int *anynul, int *status); int ffgclujj(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, - LONGLONG nelem, long elemincre, int nultyp, ULONGLONG nulval, + LONGLONG nelem, long elemincre, int nultyp, ULONGLONG nulval, ULONGLONG *array, char *nularray, int *anynul, int *status); int ffgcljj(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, - LONGLONG nelem, long elemincre, int nultyp, LONGLONG nulval, + LONGLONG nelem, long elemincre, int nultyp, LONGLONG nulval, LONGLONG *array, char *nularray, int *anynul, int *status); int ffgclj(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, LONGLONG nelem, long elemincre, int nultyp, long nulval, long *array, @@ -496,7 +496,7 @@ int ffgcle(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, int ffgcld(fitsfile *fptr, int colnum, LONGLONG firstrow, LONGLONG firstelem, LONGLONG nelem, long elemincre, int nultyp, double nulval, double *array, char *nularray, int *anynul, int *status); - + int ffpi1b(fitsfile *fptr, long nelem, long incre, unsigned char *buffer, int *status); int ffpi2b(fitsfile *fptr, long nelem, long incre, short *buffer, int *status); @@ -505,7 +505,7 @@ int ffpi4b(fitsfile *fptr, long nelem, long incre, INT32BIT *buffer, int ffpi8b(fitsfile *fptr, long nelem, long incre, long *buffer, int *status); int ffpr4b(fitsfile *fptr, long nelem, long incre, float *buffer, int *status); int ffpr8b(fitsfile *fptr, long nelem, long incre, double *buffer, int *status); - + int ffgi1b(fitsfile *fptr, LONGLONG pos, long nelem, long incre, unsigned char *buffer, int *status); int ffgi2b(fitsfile *fptr, LONGLONG pos, long nelem, long incre, short *buffer, @@ -518,14 +518,14 @@ int ffgr4b(fitsfile *fptr, LONGLONG pos, long nelem, long incre, float *buffer, int *status); int ffgr8b(fitsfile *fptr, LONGLONG pos, long nelem, long incre, double *buffer, int *status); - + int ffcins(fitsfile *fptr, LONGLONG naxis1, LONGLONG naxis2, LONGLONG nbytes, LONGLONG bytepos, int *status); int ffcdel(fitsfile *fptr, LONGLONG naxis1, LONGLONG naxis2, LONGLONG nbytes, LONGLONG bytepos, int *status); int ffkshf(fitsfile *fptr, int firstcol, int tfields, int nshift, int *status); int fffvcl(fitsfile *fptr, int *nvarcols, int *colnums, int *status); - + int fffi1i1(unsigned char *input, long ntodo, double scale, double zero, int nullcheck, unsigned char tnull, unsigned char nullval, char *nullarray, int *anynull, unsigned char *output, int *status); @@ -548,7 +548,7 @@ int fffstri1(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, unsigned char nullval, char *nullarray, int *anynull, unsigned char *output, int *status); - + int fffi1s1(unsigned char *input, long ntodo, double scale, double zero, int nullcheck, unsigned char tnull, signed char nullval, char *nullarray, int *anynull, signed char *output, int *status); @@ -573,7 +573,7 @@ int fffstrs1(char *input, long ntodo, double scale, double zero, signed char *output, int *status); int fffi1u2(unsigned char *input, long ntodo, double scale, double zero, - int nullcheck, unsigned char tnull, unsigned short nullval, + int nullcheck, unsigned char tnull, unsigned short nullval, char *nullarray, int *anynull, unsigned short *output, int *status); int fffi2u2(short *input, long ntodo, double scale, double zero, @@ -593,7 +593,7 @@ int fffr8u2(double *input, long ntodo, double scale, double zero, int *anynull, unsigned short *output, int *status); int fffstru2(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, - unsigned short nullval, char *nullarray, int *anynull, + unsigned short nullval, char *nullarray, int *anynull, unsigned short *output, int *status); int fffi1i2(unsigned char *input, long ntodo, double scale, double zero, @@ -642,7 +642,7 @@ int fffstru4(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, unsigned long nullval, char *nullarray, int *anynull, unsigned long *output, int *status); - + int fffi1i4(unsigned char *input, long ntodo, double scale, double zero, int nullcheck, unsigned char tnull, long nullval, char *nullarray, int *anynull, long *output, int *status); @@ -665,7 +665,7 @@ int fffstri4(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, long nullval, char *nullarray, int *anynull, long *output, int *status); - + int fffi1int(unsigned char *input, long ntodo, double scale, double zero, int nullcheck, unsigned char tnull, int nullval, char *nullarray, int *anynull, int *output, int *status); @@ -688,7 +688,7 @@ int fffstrint(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, int nullval, char *nullarray, int *anynull, int *output, int *status); - + int fffi1uint(unsigned char *input, long ntodo, double scale, double zero, int nullcheck, unsigned char tnull, unsigned int nullval, char *nullarray, int *anynull, unsigned int *output, int *status); @@ -711,9 +711,9 @@ int fffstruint(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, unsigned int nullval, char *nullarray, int *anynull, unsigned int *output, int *status); - + int fffi1i8(unsigned char *input, long ntodo, double scale, double zero, - int nullcheck, unsigned char tnull, LONGLONG nullval, + int nullcheck, unsigned char tnull, LONGLONG nullval, char *nullarray, int *anynull, LONGLONG *output, int *status); int fffi2i8(short *input, long ntodo, double scale, double zero, int nullcheck, short tnull, LONGLONG nullval, char *nullarray, @@ -736,7 +736,7 @@ int fffstri8(char *input, long ntodo, double scale, double zero, int *status); int fffi1u8(unsigned char *input, long ntodo, double scale, double zero, - int nullcheck, unsigned char tnull, ULONGLONG nullval, + int nullcheck, unsigned char tnull, ULONGLONG nullval, char *nullarray, int *anynull, ULONGLONG *output, int *status); int fffi2u8(short *input, long ntodo, double scale, double zero, int nullcheck, short tnull, ULONGLONG nullval, char *nullarray, @@ -781,7 +781,7 @@ int fffstrr4(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, float nullval, char *nullarray, int *anynull, float *output, int *status); - + int fffi1r8(unsigned char *input, long ntodo, double scale, double zero, int nullcheck, unsigned char tnull, double nullval, char *nullarray, int *anynull, double *output, int *status); @@ -804,7 +804,7 @@ int fffstrr8(char *input, long ntodo, double scale, double zero, long twidth, double power, int nullcheck, char *snull, double nullval, char *nullarray, int *anynull, double *output, int *status); - + int ffi1fi1(unsigned char *array, long ntodo, double scale, double zero, unsigned char *buffer, int *status); int ffs1fi1(signed char *array, long ntodo, double scale, double zero, @@ -829,7 +829,7 @@ int ffr4fi1(float *array, long ntodo, double scale, double zero, unsigned char *buffer, int *status); int ffr8fi1(double *array, long ntodo, double scale, double zero, unsigned char *buffer, int *status); - + int ffi1fi2(unsigned char *array, long ntodo, double scale, double zero, short *buffer, int *status); int ffs1fi2(signed char *array, long ntodo, double scale, double zero, @@ -854,7 +854,7 @@ int ffr4fi2(float *array, long ntodo, double scale, double zero, short *buffer, int *status); int ffr8fi2(double *array, long ntodo, double scale, double zero, short *buffer, int *status); - + int ffi1fi4(unsigned char *array, long ntodo, double scale, double zero, INT32BIT *buffer, int *status); int ffs1fi4(signed char *array, long ntodo, double scale, double zero, @@ -929,7 +929,7 @@ int ffr4fr4(float *array, long ntodo, double scale, double zero, float *buffer, int *status); int ffr8fr4(double *array, long ntodo, double scale, double zero, float *buffer, int *status); - + int ffi1fr8(unsigned char *array, long ntodo, double scale, double zero, double *buffer, int *status); int ffs1fr8(signed char *array, long ntodo, double scale, double zero, @@ -989,16 +989,16 @@ void ieevur(float *inarray, float *outarray, long *nvals); /* routines related to the lexical parser */ int ffselect_table(fitsfile **fptr, char *outfile, char *expr, int *status); int ffiprs( fitsfile *fptr, int compressed, char *expr, int maxdim, - int *datatype, long *nelem, int *naxis, long *naxes, - int *status ); + int *datatype, long *nelem, int *naxis, long *naxes, + int *status ); void ffcprs( void ); int ffcvtn( int inputType, void *input, char *undef, long ntodo, - int outputType, void *nulval, void *output, - int *anynull, int *status ); + int outputType, void *nulval, void *output, + int *anynull, int *status ); int parse_data( long totalrows, long offset, long firstrow, long nrows, int nCols, iteratorCol *colData, void *userPtr ); -int uncompress_hkdata( fitsfile *fptr, long ntimes, +int uncompress_hkdata( fitsfile *fptr, long ntimes, double *times, int *status ); int ffffrw_work( long totalrows, long offset, long firstrow, long nrows, int nCols, iteratorCol *colData, @@ -1009,17 +1009,17 @@ int fits_translate_pixkeyword(char *inrec, char *outrec,char *patterns[][2], int *j, int *n, int *m, int *l, int *status); /* image compression routines */ -int fits_write_compressed_img(fitsfile *fptr, - int datatype, long *fpixel, long *lpixel, +int fits_write_compressed_img(fitsfile *fptr, + int datatype, long *fpixel, long *lpixel, int nullcheck, void *array, void *nulval, int *status); -int fits_write_compressed_pixels(fitsfile *fptr, - int datatype, LONGLONG fpixel, LONGLONG npixels, +int fits_write_compressed_pixels(fitsfile *fptr, + int datatype, LONGLONG fpixel, LONGLONG npixels, int nullcheck, void *array, void *nulval, int *status); -int fits_write_compressed_img_plane(fitsfile *fptr, int datatype, - int bytesperpixel, long nplane, long *firstcoord, long *lastcoord, - long *naxes, int nullcheck, +int fits_write_compressed_img_plane(fitsfile *fptr, int datatype, + int bytesperpixel, long nplane, long *firstcoord, long *lastcoord, + long *naxes, int nullcheck, void *array, void *nullval, long *nread, int *status); int imcomp_init_table(fitsfile *outfptr, @@ -1028,12 +1028,12 @@ int imcomp_calc_max_elem (int comptype, int nx, int zbitpix, int blocksize); int imcomp_copy_imheader(fitsfile *infptr, fitsfile *outfptr, int *status); int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status); -int imcomp_copy_comp2img(fitsfile *infptr, fitsfile *outfptr, +int imcomp_copy_comp2img(fitsfile *infptr, fitsfile *outfptr, int norec, int *status); int imcomp_copy_prime2img(fitsfile *infptr, fitsfile *outfptr, int *status); int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status); -int imcomp_compress_tile (fitsfile *outfptr, long row, +int imcomp_compress_tile (fitsfile *outfptr, long row, int datatype, void *tiledata, long tilelen, long nx, long ny, int nullcheck, void *nullval, int *status); int imcomp_nullscale(int *idata, long tilelen, int nullflagval, int nullval, @@ -1042,30 +1042,30 @@ int imcomp_nullvalues(int *idata, long tilelen, int nullflagval, int nullval, int * status); int imcomp_scalevalues(int *idata, long tilelen, double scale, double zero, int * status); -int imcomp_nullscalefloats(float *fdata, long tilelen, int *idata, +int imcomp_nullscalefloats(float *fdata, long tilelen, int *idata, double scale, double zero, int nullcheck, float nullflagval, int nullval, int *status); int imcomp_nullfloats(float *fdata, long tilelen, int *idata, int nullcheck, float nullflagval, int nullval, int *status); -int imcomp_nullscaledoubles(double *fdata, long tilelen, int *idata, +int imcomp_nullscaledoubles(double *fdata, long tilelen, int *idata, double scale, double zero, int nullcheck, double nullflagval, int nullval, int *status); int imcomp_nulldoubles(double *fdata, long tilelen, int *idata, int nullcheck, double nullflagval, int nullval, int *status); - - + + /* image decompression routines */ -int fits_read_compressed_img(fitsfile *fptr, - int datatype, LONGLONG *fpixel,LONGLONG *lpixel,long *inc, +int fits_read_compressed_img(fitsfile *fptr, + int datatype, LONGLONG *fpixel,LONGLONG *lpixel,long *inc, int nullcheck, void *nulval, void *array, char *nullarray, int *anynul, int *status); -int fits_read_compressed_pixels(fitsfile *fptr, - int datatype, LONGLONG fpixel, LONGLONG npixels, +int fits_read_compressed_pixels(fitsfile *fptr, + int datatype, LONGLONG fpixel, LONGLONG npixels, int nullcheck, void *nulval, void *array, char *nullarray, int *anynul, int *status); -int fits_read_compressed_img_plane(fitsfile *fptr, int datatype, - int bytesperpixel, long nplane, LONGLONG *firstcoord, LONGLONG *lastcoord, - long *inc, long *naxes, int nullcheck, void *nullval, +int fits_read_compressed_img_plane(fitsfile *fptr, int datatype, + int bytesperpixel, long nplane, LONGLONG *firstcoord, LONGLONG *lastcoord, + long *inc, long *naxes, int nullcheck, void *nullval, void *array, char *nullarray, int *anynul, long *nread, int *status); int imcomp_get_compressed_image_par(fitsfile *infptr, int *status); @@ -1077,7 +1077,7 @@ int imcomp_copy_overlap (char *tile, int pixlen, int ndim, long *tfpixel, long *tlpixel, char *bnullarray, char *image, long *fpixel, long *lpixel, long *inc, int nullcheck, char *nullarray, int *status); -int imcomp_test_overlap (int ndim, long *tfpixel, long *tlpixel, +int imcomp_test_overlap (int ndim, long *tfpixel, long *tlpixel, long *fpixel, long *lpixel, long *inc, int *status); int imcomp_merge_overlap (char *tile, int pixlen, int ndim, long *tfpixel, long *tlpixel, char *bnullarray, char *image, @@ -1085,7 +1085,7 @@ int imcomp_merge_overlap (char *tile, int pixlen, int ndim, int imcomp_decompress_img(fitsfile *infptr, fitsfile *outfptr, int datatype, int *status); int fits_quantize_float (long row, float fdata[], long nx, long ny, int nullcheck, - float in_null_value, float quantize_level, + float in_null_value, float quantize_level, int dither_method, int idata[], double *bscale, double *bzero, int *iminval, int *imaxval); int fits_quantize_double (long row, double fdata[], long nx, long ny, int nullcheck, @@ -1116,22 +1116,22 @@ void fits_dwnld_prog_bar(int flag); int fits_net_timeout(int sec); int fits_register_driver( char *prefix, - int (*init)(void), - int (*fitsshutdown)(void), - int (*setoptions)(int option), - int (*getoptions)(int *options), - int (*getversion)(int *version), - int (*checkfile) (char *urltype, char *infile, char *outfile), - int (*fitsopen)(char *filename, int rwmode, int *driverhandle), - int (*fitscreate)(char *filename, int *driverhandle), - int (*fitstruncate)(int driverhandle, LONGLONG filesize), - int (*fitsclose)(int driverhandle), - int (*fremove)(char *filename), + int (*init)(void), + int (*fitsshutdown)(void), + int (*setoptions)(int option), + int (*getoptions)(int *options), + int (*getversion)(int *version), + int (*checkfile) (char *urltype, char *infile, char *outfile), + int (*fitsopen)(char *filename, int rwmode, int *driverhandle), + int (*fitscreate)(char *filename, int *driverhandle), + int (*fitstruncate)(int driverhandle, LONGLONG filesize), + int (*fitsclose)(int driverhandle), + int (*fremove)(char *filename), int (*size)(int driverhandle, LONGLONG *sizex), - int (*flush)(int driverhandle), - int (*seek)(int driverhandle, LONGLONG offset), - int (*fitsread) (int driverhandle, void *buffer, long nbytes), - int (*fitswrite)(int driverhandle, void *buffer, long nbytes)); + int (*flush)(int driverhandle), + int (*seek)(int driverhandle, LONGLONG offset), + int (*fitsread) (int driverhandle, void *buffer, long nbytes), + int (*fitswrite)(int driverhandle, void *buffer, long nbytes)); /* file driver I/O routines */ @@ -1198,7 +1198,7 @@ int mem_read(int hdl, void *buffer, long nbytes); int mem_write(int hdl, void *buffer, long nbytes); int mem_uncompress2mem(char *filename, FILE *diskfile, int hdl); -int iraf2mem(char *filename, char **buffptr, size_t *buffsize, +int iraf2mem(char *filename, char **buffptr, size_t *buffsize, size_t *filesize, int *status); /* root driver I/O routines */ @@ -1248,33 +1248,33 @@ int uncompress2mem(char *filename, FILE *diskfile, void *(*mem_realloc)(void *p, size_t newsize), size_t *filesize, int *status); -int uncompress2mem_from_mem( - char *inmemptr, - size_t inmemsize, - char **buffptr, - size_t *buffsize, - void *(*mem_realloc)(void *p, size_t newsize), - size_t *filesize, +int uncompress2mem_from_mem( + char *inmemptr, + size_t inmemsize, + char **buffptr, + size_t *buffsize, + void *(*mem_realloc)(void *p, size_t newsize), + size_t *filesize, int *status); -int uncompress2file(char *filename, - FILE *indiskfile, - FILE *outdiskfile, +int uncompress2file(char *filename, + FILE *indiskfile, + FILE *outdiskfile, int *status); -int compress2mem_from_mem( - char *inmemptr, - size_t inmemsize, - char **buffptr, - size_t *buffsize, - void *(*mem_realloc)(void *p, size_t newsize), - size_t *filesize, +int compress2mem_from_mem( + char *inmemptr, + size_t inmemsize, + char **buffptr, + size_t *buffsize, + void *(*mem_realloc)(void *p, size_t newsize), + size_t *filesize, int *status); -int compress2file_from_mem( - char *inmemptr, - size_t inmemsize, - FILE *outdiskfile, +int compress2file_from_mem( + char *inmemptr, + size_t inmemsize, + FILE *outdiskfile, size_t *filesize, /* O - size of file, in bytes */ int *status); diff --git a/SKIRT/fitsio/imcompress.c b/SKIRT/fitsio/imcompress.c index 6db36614..0cadcc21 100644 --- a/SKIRT/fitsio/imcompress.c +++ b/SKIRT/fitsio/imcompress.c @@ -17,11 +17,11 @@ #define NO_QUANTIZE 9999 /* string array for storing the individual column compression stats */ -char results[999][30]; +char results[500][30]; float *fits_rand_value = 0; -int imcomp_write_nocompress_tile(fitsfile *outfptr, long row, int datatype, +int imcomp_write_nocompress_tile(fitsfile *outfptr, long row, int datatype, void *tiledata, long tilelen, int nullcheck, void *nullflagval, int *status); int imcomp_convert_tile_tshort(fitsfile *outfptr, void *tiledata, long tilelen, int nullcheck, void *nullflagval, int nullval, int zbitpix, double scale, @@ -45,7 +45,7 @@ int imcomp_convert_tile_tfloat(fitsfile *outfptr, long row, void *tiledata, long long tilenx, long tileny, int nullcheck, void *nullflagval, int nullval, int zbitpix, double scale, double zero, int *intlength, int *flag, double *bscale, double *bzero,int *status); int imcomp_convert_tile_tdouble(fitsfile *outfptr, long row, void *tiledata, long tilelen, - long tilenx, long tileny, int nullcheck, void *nullflagval, int nullval, int zbitpix, + long tilenx, long tileny, int nullcheck, void *nullflagval, int nullval, int zbitpix, double scale, double zero, int *intlength, int *flag, double *bscale, double *bzero, int *status); static int unquantize_i1r4(long row, @@ -141,7 +141,7 @@ static int unquantize_i4r8(long row, static int imcomp_float2nan(float *indata, long tilelen, int *outdata, float nullflagval, int *status); static int imcomp_double2nan(double *indata, long tilelen, LONGLONG *outdata, - double nullflagval, int *status); + double nullflagval, int *status); static int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ int datatype, /* I - datatype of the array to be returned */ LONGLONG *infpixel, /* I - 'bottom left corner' of the subsection */ @@ -167,10 +167,10 @@ static int fits_ushort_to_int_inplace(unsigned short *intarray, long length, int static int fits_sbyte_to_int_inplace(signed char *intarray, long length, int *status); static int fits_ubyte_to_int_inplace(unsigned char *intarray, long length, int *status); -static int fits_calc_tile_rows(long *tlpixel, long *tfpixel, int ndim, long *trowsize, long *ntrows, int *status); +static int fits_calc_tile_rows(long *tlpixel, long *tfpixel, int ndim, long *trowsize, long *ntrows, int *status); /* only used for diagnoitic purposes */ -/* int fits_get_case(int *c1, int*c2, int*c3); */ +/* int fits_get_case(int *c1, int*c2, int*c3); */ /*---------------------------------------------------------------------------*/ int fits_init_randoms(void) { @@ -182,7 +182,7 @@ int fits_init_randoms(void) { double temp, seed; FFLOCK; - + if (fits_rand_value) { FFUNLOCK; return(0); /* array is already initialized */ @@ -194,34 +194,34 @@ int fits_init_randoms(void) { if (!fits_rand_value) { FFUNLOCK; - return(MEMORY_ALLOCATION); + return(MEMORY_ALLOCATION); } - + /* We need a portable algorithm that anyone can use to generate this exact same sequence of random number. The C 'rand' function is not - suitable because it is not available to Fortran or Java programmers. - Instead, use a well known simple algorithm published here: - "Random number generators: good ones are hard to find", Communications of the ACM, - Volume 31 , Issue 10 (October 1988) Pages: 1192 - 1201 - */ + suitable because it is not available to Fortran or Java programmers. + Instead, use a well known simple algorithm published here: + "Random number generators: good ones are hard to find", Communications of the ACM, + Volume 31 , Issue 10 (October 1988) Pages: 1192 - 1201 + */ /* initialize the random numbers */ seed = 1; for (ii = 0; ii < N_RANDOM; ii++) { temp = a * seed; - seed = temp -m * ((int) (temp / m) ); - fits_rand_value[ii] = (float) (seed / m); + seed = temp -m * ((int) (temp / m) ); + fits_rand_value[ii] = (float) (seed / m); } FFUNLOCK; - /* - IMPORTANT NOTE: the 10000th seed value must have the value 1043618065 if the + /* + IMPORTANT NOTE: the 10000th seed value must have the value 1043618065 if the algorithm has been implemented correctly */ - + if ( (int) seed != 1043618065) { ffpmsg("fits_init_randoms generated incorrect random number sequence"); - return(1); + return(1); } else { return(0); } @@ -248,17 +248,17 @@ int fits_set_compression_type(fitsfile *fptr, /* I - FITS file pointer */ table column. */ - if (ctype != RICE_1 && - ctype != GZIP_1 && - ctype != GZIP_2 && - ctype != PLIO_1 && - ctype != HCOMPRESS_1 && - ctype != BZIP2_1 && + if (ctype != RICE_1 && + ctype != GZIP_1 && + ctype != GZIP_2 && + ctype != PLIO_1 && + ctype != HCOMPRESS_1 && + ctype != BZIP2_1 && ctype != NOCOMPRESS && - ctype != 0) + ctype != 0) { - ffpmsg("unknown compression algorithm (fits_set_compression_type)"); - *status = DATA_COMPRESSION_ERR; + ffpmsg("unknown compression algorithm (fits_set_compression_type)"); + *status = DATA_COMPRESSION_ERR; } else { (fptr->Fptr)->request_compress_type = ctype; } @@ -282,7 +282,7 @@ int fits_set_tile_dim(fitsfile *fptr, /* I - FITS file pointer */ if (ndim < 0 || ndim > MAX_COMPRESS_DIM) { *status = BAD_DIMEN; - ffpmsg("illegal number of tile dimensions (fits_set_tile_dim)"); + ffpmsg("illegal number of tile dimensions (fits_set_tile_dim)"); return(*status); } @@ -307,7 +307,7 @@ int fits_set_quantize_level(fitsfile *fptr, /* I - FITS file pointer */ if (qlevel == 0.) { /* this means don't quantize the floating point values. Instead, */ - /* the floating point values will be losslessly compressed */ + /* the floating point values will be losslessly compressed */ (fptr->Fptr)->request_quantize_level = NO_QUANTIZE; } else { @@ -331,10 +331,10 @@ int fits_set_quantize_method(fitsfile *fptr, /* I - FITS file pointer */ if (method < -1 || method > 2) { - ffpmsg("illegal dithering value (fits_set_quantize_method)"); - *status = DATA_COMPRESSION_ERR; + ffpmsg("illegal dithering value (fits_set_quantize_method)"); + *status = DATA_COMPRESSION_ERR; } else { - + if (method == 0) method = 1; (fptr->Fptr)->request_quantize_method = method; } @@ -362,11 +362,11 @@ int fits_set_dither_seed(fitsfile *fptr, /* I - FITS file pointer */ /* This routine specifies the value of the offset that should be applied when calculating the random dithering when quantizing floating point iamges. - A random offset should be applied to each image to avoid quantization + A random offset should be applied to each image to avoid quantization effects when taking the difference of 2 images, or co-adding a set of images. Without this random offset, the corresponding pixel in every image will have exactly the same dithering. - + offset = 0 means use the default random dithering based on system time offset = negative means randomly chose dithering based on 1st tile checksum offset = [1 - 10000] means use that particular dithering pattern @@ -374,12 +374,12 @@ int fits_set_dither_seed(fitsfile *fptr, /* I - FITS file pointer */ */ /* if positive, ensure that the value is in the range 1 to 10000 */ if (seed > 10000) { - ffpmsg("illegal dithering seed value (fits_set_dither_seed)"); - *status = DATA_COMPRESSION_ERR; + ffpmsg("illegal dithering seed value (fits_set_dither_seed)"); + *status = DATA_COMPRESSION_ERR; } else { - (fptr->Fptr)->request_dither_seed = seed; + (fptr->Fptr)->request_dither_seed = seed; } - + return(*status); } /*--------------------------------------------------------------------------*/ @@ -422,13 +422,13 @@ int fits_set_noise_bits(fitsfile *fptr, /* I - FITS file pointer */ if (noisebits < 1 || noisebits > 16) { *status = DATA_COMPRESSION_ERR; - ffpmsg("illegal number of noise bits (fits_set_noise_bits)"); + ffpmsg("illegal number of noise bits (fits_set_noise_bits)"); return(*status); } qlevel = (float) pow (2., (double)noisebits); fits_set_quantize_level(fptr, qlevel, status); - + return(*status); } /*--------------------------------------------------------------------------*/ @@ -447,10 +447,10 @@ int fits_set_hcomp_scale(fitsfile *fptr, /* I - FITS file pointer */ int fits_set_hcomp_smooth(fitsfile *fptr, /* I - FITS file pointer */ int smooth, /* hcompress smooth parameter value */ /* if scale > 1 and smooth != 0, then */ - /* the image will be smoothed when it is */ - /* decompressed to remove some of the */ - /* 'blockiness' in the image produced */ - /* by the lossy compression */ + /* the image will be smoothed when it is */ + /* decompressed to remove some of the */ + /* 'blockiness' in the image produced */ + /* by the lossy compression */ int *status) /* IO - error status */ { /* @@ -494,7 +494,7 @@ int fits_set_huge_hdu(fitsfile *fptr, /* I - FITS file pointer */ int fits_get_compression_type(fitsfile *fptr, /* I - FITS file pointer */ int *ctype, /* image compression type code; */ /* allowed values: */ - /* RICE_1, GZIP_1, GZIP_2, PLIO_1, HCOMPRESS_1, BZIP2_1 */ + /* RICE_1, GZIP_1, GZIP_2, PLIO_1, HCOMPRESS_1, BZIP2_1 */ int *status) /* IO - error status */ { /* @@ -505,20 +505,20 @@ int fits_get_compression_type(fitsfile *fptr, /* I - FITS file pointer */ */ *ctype = (fptr->Fptr)->request_compress_type; - if (*ctype != RICE_1 && - *ctype != GZIP_1 && - *ctype != GZIP_2 && - *ctype != PLIO_1 && - *ctype != HCOMPRESS_1 && - *ctype != BZIP2_1 && + if (*ctype != RICE_1 && + *ctype != GZIP_1 && + *ctype != GZIP_2 && + *ctype != PLIO_1 && + *ctype != HCOMPRESS_1 && + *ctype != BZIP2_1 && *ctype != NOCOMPRESS && - *ctype != 0 ) + *ctype != 0 ) { - ffpmsg("unknown compression algorithm (fits_get_compression_type)"); - *status = DATA_COMPRESSION_ERR; + ffpmsg("unknown compression algorithm (fits_get_compression_type)"); + *status = DATA_COMPRESSION_ERR; } - + return(*status); } /*--------------------------------------------------------------------------*/ @@ -539,7 +539,7 @@ int fits_get_tile_dim(fitsfile *fptr, /* I - FITS file pointer */ if (ndim < 0 || ndim > MAX_COMPRESS_DIM) { *status = BAD_DIMEN; - ffpmsg("illegal number of tile dimensions (fits_get_tile_dim)"); + ffpmsg("illegal number of tile dimensions (fits_get_tile_dim)"); return(*status); } @@ -553,14 +553,14 @@ int fits_get_tile_dim(fitsfile *fptr, /* I - FITS file pointer */ /*--------------------------------------------------------------------------*/ int fits_unset_compression_param( fitsfile *fptr, - int *status) + int *status) { int ii; (fptr->Fptr)->compress_type = 0; (fptr->Fptr)->quantize_level = 0; (fptr->Fptr)->quantize_method = 0; - (fptr->Fptr)->dither_seed = 0; + (fptr->Fptr)->dither_seed = 0; (fptr->Fptr)->hcomp_scale = 0; for (ii = 0; ii < MAX_COMPRESS_DIM; ii++) @@ -573,14 +573,14 @@ int fits_unset_compression_param( /*--------------------------------------------------------------------------*/ int fits_unset_compression_request( fitsfile *fptr, - int *status) + int *status) { int ii; (fptr->Fptr)->request_compress_type = 0; (fptr->Fptr)->request_quantize_level = 0; (fptr->Fptr)->request_quantize_method = 0; - (fptr->Fptr)->request_dither_seed = 0; + (fptr->Fptr)->request_dither_seed = 0; (fptr->Fptr)->request_hcomp_scale = 0; (fptr->Fptr)->request_lossy_int_compress = 0; (fptr->Fptr)->request_huge_hdu = 0; @@ -596,7 +596,7 @@ int fits_unset_compression_request( int fits_set_compression_pref( fitsfile *infptr, fitsfile *outfptr, - int *status) + int *status) { /* Set the preference for various compression options, based @@ -611,7 +611,7 @@ int fits_set_compression_pref( char card[FLEN_CARD], value[FLEN_VALUE]; double qvalue; float hscale; - LONGLONG datastart, dataend; + LONGLONG datastart, dataend; if (*status > 0) return(*status); @@ -624,122 +624,122 @@ int fits_set_compression_pref( } fits_get_hdrspace(infptr, &nkeys, NULL, status); - + /* look for a image compression directive keywords (begin with 'FZ') */ for (ii = 2; ii <= nkeys; ii++) { - - fits_read_record(infptr, ii, card, status); - if (!strncmp(card, "FZ", 2) ){ - + fits_read_record(infptr, ii, card, status); + + if (!strncmp(card, "FZ", 2) ){ + /* get the keyword value string */ fits_parse_value(card, value, NULL, status); - - if (!strncmp(card+2, "ALGOR", 5) ) { - /* set the desired compression algorithm */ + if (!strncmp(card+2, "ALGOR", 5) ) { + + /* set the desired compression algorithm */ /* allowed values: RICE_1, GZIP_1, GZIP_2, PLIO_1, */ /* HCOMPRESS_1, BZIP2_1, and NOCOMPRESS */ if (!fits_strncasecmp(value, "'RICE_1", 7) ) { - comptype = RICE_1; + comptype = RICE_1; } else if (!fits_strncasecmp(value, "'GZIP_1", 7) ) { - comptype = GZIP_1; + comptype = GZIP_1; } else if (!fits_strncasecmp(value, "'GZIP_2", 7) ) { - comptype = GZIP_2; + comptype = GZIP_2; } else if (!fits_strncasecmp(value, "'PLIO_1", 7) ) { - comptype = PLIO_1; + comptype = PLIO_1; } else if (!fits_strncasecmp(value, "'HCOMPRESS_1", 12) ) { - comptype = HCOMPRESS_1; + comptype = HCOMPRESS_1; } else if (!fits_strncasecmp(value, "'NONE", 5) ) { - comptype = NOCOMPRESS; - } else { - ffpmsg("Unknown FZALGOR keyword compression algorithm:"); - ffpmsg(value); - return(*status = DATA_COMPRESSION_ERR); - } + comptype = NOCOMPRESS; + } else { + ffpmsg("Unknown FZALGOR keyword compression algorithm:"); + ffpmsg(value); + return(*status = DATA_COMPRESSION_ERR); + } - fits_set_compression_type (outfptr, comptype, status); + fits_set_compression_type (outfptr, comptype, status); - } else if (!strncmp(card+2, "TILE ", 6) ) { + } else if (!strncmp(card+2, "TILE ", 6) ) { if (!fits_strncasecmp(value, "'row", 4) ) { tiledim[0] = -1; - } else if (!fits_strncasecmp(value, "'whole", 6) ) { + } else if (!fits_strncasecmp(value, "'whole", 6) ) { tiledim[0] = -1; tiledim[1] = -1; tiledim[2] = -1; } else { - ffdtdm(infptr, value, 0,6, &naxis, tiledim, status); + ffdtdm(infptr, value, 0,6, &naxis, tiledim, status); } - /* set the desired tile size */ - fits_set_tile_dim (outfptr, 6, tiledim, status); + /* set the desired tile size */ + fits_set_tile_dim (outfptr, 6, tiledim, status); - } else if (!strncmp(card+2, "QVALUE", 6) ) { + } else if (!strncmp(card+2, "QVALUE", 6) ) { - /* set the desired Q quantization value */ - qvalue = atof(value); - fits_set_quantize_level (outfptr, (float) qvalue, status); + /* set the desired Q quantization value */ + qvalue = atof(value); + fits_set_quantize_level (outfptr, (float) qvalue, status); - } else if (!strncmp(card+2, "QMETHD", 6) ) { + } else if (!strncmp(card+2, "QMETHD", 6) ) { if (!fits_strncasecmp(value, "'no_dither", 10) ) { ivalue = -1; /* just quantize, with no dithering */ - } else if (!fits_strncasecmp(value, "'subtractive_dither_1", 21) ) { + } else if (!fits_strncasecmp(value, "'subtractive_dither_1", 21) ) { ivalue = SUBTRACTIVE_DITHER_1; /* use subtractive dithering */ - } else if (!fits_strncasecmp(value, "'subtractive_dither_2", 21) ) { + } else if (!fits_strncasecmp(value, "'subtractive_dither_2", 21) ) { ivalue = SUBTRACTIVE_DITHER_2; /* dither, except preserve zero-valued pixels */ - } else { - ffpmsg("Unknown value for FZQUANT keyword: (set_compression_pref)"); - ffpmsg(value); + } else { + ffpmsg("Unknown value for FZQUANT keyword: (set_compression_pref)"); + ffpmsg(value); return(*status = DATA_COMPRESSION_ERR); - } + } + + fits_set_quantize_method(outfptr, ivalue, status); - fits_set_quantize_method(outfptr, ivalue, status); - - } else if (!strncmp(card+2, "DTHRSD", 6) ) { + } else if (!strncmp(card+2, "DTHRSD", 6) ) { if (!fits_strncasecmp(value, "'checksum", 9) ) { ivalue = -1; /* use checksum of first tile */ - } else if (!fits_strncasecmp(value, "'clock", 6) ) { + } else if (!fits_strncasecmp(value, "'clock", 6) ) { ivalue = 0; /* set dithering seed based on system clock */ - } else { /* read integer value */ - if (*value == '\'') + } else { /* read integer value */ + if (*value == '\'') ivalue = (int) atol(value+1); /* allow for leading quote character */ - else - ivalue = (int) atol(value); + else + ivalue = (int) atol(value); if (ivalue < 1 || ivalue > 10000) { - ffpmsg("Invalid value for FZDTHRSD keyword: (set_compression_pref)"); - ffpmsg(value); + ffpmsg("Invalid value for FZDTHRSD keyword: (set_compression_pref)"); + ffpmsg(value); return(*status = DATA_COMPRESSION_ERR); } - } + } - /* set the desired dithering */ - fits_set_dither_seed(outfptr, ivalue, status); + /* set the desired dithering */ + fits_set_dither_seed(outfptr, ivalue, status); - } else if (!strncmp(card+2, "I2F", 3) ) { + } else if (!strncmp(card+2, "I2F", 3) ) { - /* set whether to convert integers to float then use lossy compression */ + /* set whether to convert integers to float then use lossy compression */ if (!fits_strcasecmp(value, "t") ) { - fits_set_lossy_int (outfptr, 1, status); - } else if (!fits_strcasecmp(value, "f") ) { - fits_set_lossy_int (outfptr, 0, status); - } else { - ffpmsg("Unknown value for FZI2F keyword: (set_compression_pref)"); - ffpmsg(value); + fits_set_lossy_int (outfptr, 1, status); + } else if (!fits_strcasecmp(value, "f") ) { + fits_set_lossy_int (outfptr, 0, status); + } else { + ffpmsg("Unknown value for FZI2F keyword: (set_compression_pref)"); + ffpmsg(value); return(*status = DATA_COMPRESSION_ERR); } - } else if (!strncmp(card+2, "HSCALE ", 6) ) { + } else if (!strncmp(card+2, "HSCALE ", 6) ) { - /* set the desired Hcompress scale value */ - hscale = (float) atof(value); - fits_set_hcomp_scale (outfptr, hscale, status); + /* set the desired Hcompress scale value */ + hscale = (float) atof(value); + fits_set_hcomp_scale (outfptr, hscale, status); } - } + } } return(*status); } @@ -766,9 +766,9 @@ int fits_get_noise_bits(fitsfile *fptr, /* I - FITS file pointer */ Feb 2008: code changed to use the more general "quantize level" parameter rather than the "noise bits" parameter. If quantize level is greater than zero, then the previous noisebits parameter is approximately given by - + noise bits = natural logarithm (quantize level) / natural log (2) - + This result is rounded to the nearest integer. */ double qlevel; @@ -777,7 +777,7 @@ int fits_get_noise_bits(fitsfile *fptr, /* I - FITS file pointer */ if (qlevel > 0. && qlevel < 65537. ) *noisebits = (int) ((log(qlevel) / log(2.0)) + 0.5); - else + else *noisebits = 0; return(*status); @@ -850,7 +850,7 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ This routine initializes the output table, copies all the keywords, and loops through the input image, compressing the data and writing the compressed tiles to the output table. - + This is a high level routine that is called by the fpack and funpack FITS compression utilities. */ @@ -864,7 +864,7 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ /* get datatype and size of input image */ - if (fits_get_img_param(infptr, MAX_COMPRESS_DIM, &bitpix, + if (fits_get_img_param(infptr, MAX_COMPRESS_DIM, &bitpix, &naxis, naxes, status) > 0) return(*status); @@ -878,7 +878,7 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ /* compression preferences. This HDU will become a binary table that */ /* contains the compressed image. If necessary, create a dummy primary */ /* array, which much precede the binary table extension. */ - + ffcrhd(outfptr, status); /* this does nothing if the output file is empty */ if ((outfptr->Fptr)->curhdu == 0) /* have to create dummy primary array */ @@ -890,7 +890,7 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ set when closing the previous HDU in the output file */ fits_unset_compression_param(outfptr, status); } - + /* set any compress parameter preferences as given in the input file */ fits_set_compression_pref(infptr, outfptr, status); @@ -905,21 +905,21 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ /* Then the pixels will be quantized (lossy algorithm) to achieve */ /* higher amounts of compression than with lossless algorithms */ - if ( (outfptr->Fptr)->request_lossy_int_compress != 0 && bitpix > 0) - bitpix = FLOAT_IMG; /* compress integer images as if float */ + if ( (outfptr->Fptr)->request_lossy_int_compress != 0 && bitpix > 0) + bitpix = FLOAT_IMG; /* compress integer images as if float */ /* initialize output table */ if (imcomp_init_table(outfptr, bitpix, naxis, naxes, 0, status) > 0) - return (*status); + return (*status); /* Copy the image header keywords to the table header. */ if (imcomp_copy_img2comp(infptr, outfptr, status) > 0) - return (*status); + return (*status); /* turn off any intensity scaling (defined by BSCALE and BZERO */ /* keywords) so that unscaled values will be read by CFITSIO */ /* (except if quantizing an int image, same as a float image) */ - if ( (outfptr->Fptr)->request_lossy_int_compress == 0 && bitpix > 0) + if ( (outfptr->Fptr)->request_lossy_int_compress == 0 && bitpix > 0) ffpscl(infptr, 1.0, 0.0, status); /* force a rescan of the output file keywords, so that */ @@ -930,7 +930,7 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ /* turn off any intensity scaling (defined by BSCALE and BZERO */ /* keywords) so that unscaled values will be written by CFITSIO */ /* (except if quantizing an int image, same as a float image) */ - if ( (outfptr->Fptr)->request_lossy_int_compress == 0 && bitpix > 0) + if ( (outfptr->Fptr)->request_lossy_int_compress == 0 && bitpix > 0) ffpscl(outfptr, 1.0, 0.0, status); /* Read each image tile, compress, and write to a table row. */ @@ -945,7 +945,7 @@ int fits_img_compress(fitsfile *infptr, /* pointer to image to be compressed */ /* fits_get_case(&c1, &c2, &c3); - printf("c1, c2, c3 = %d, %d, %d\n", c1, c2, c3); + printf("c1, c2, c3 = %d, %d, %d\n", c1, c2, c3); */ return (*status); @@ -955,9 +955,9 @@ int imcomp_init_table(fitsfile *outfptr, int inbitpix, int naxis, long *naxes, - int writebitpix, /* write the ZBITPIX, ZNAXIS, and ZNAXES keyword? */ + int writebitpix, /* write the ZBITPIX, ZNAXIS, and ZNAXES keyword? */ int *status) -/* +/* create a BINTABLE extension for the output compressed image. */ { @@ -975,7 +975,7 @@ int imcomp_init_table(fitsfile *outfptr, int noHigherDims=1; /* Set to true if all tile dims other than x are size 1. */ int firstDim=-1, secondDim=-1; /* Indices of first and second tiles dimensions with width > 1 */ - + if (*status > 0) return(*status); @@ -988,28 +988,28 @@ int imcomp_init_table(fitsfile *outfptr, return(*status = DATA_COMPRESSION_ERR); } } - + /* set default compression parameter values, if undefined */ - + if ( (outfptr->Fptr)->request_compress_type == 0) { - /* use RICE_1 by default */ - (outfptr->Fptr)->request_compress_type = RICE_1; + /* use RICE_1 by default */ + (outfptr->Fptr)->request_compress_type = RICE_1; } - if (inbitpix < 0 && (outfptr->Fptr)->request_quantize_level != NO_QUANTIZE) { - /* set defaults for quantizing floating point images */ - if ( (outfptr->Fptr)->request_quantize_method == 0) { - /* set default dithering method */ + if (inbitpix < 0 && (outfptr->Fptr)->request_quantize_level != NO_QUANTIZE) { + /* set defaults for quantizing floating point images */ + if ( (outfptr->Fptr)->request_quantize_method == 0) { + /* set default dithering method */ (outfptr->Fptr)->request_quantize_method = SUBTRACTIVE_DITHER_1; - } - - if ( (outfptr->Fptr)->request_quantize_level == 0) { - if ((outfptr->Fptr)->request_quantize_method == NO_DITHER) { - /* must use finer quantization if no dithering is done */ - (outfptr->Fptr)->request_quantize_level = 16; - } else { - (outfptr->Fptr)->request_quantize_level = 4; - } + } + + if ( (outfptr->Fptr)->request_quantize_level == 0) { + if ((outfptr->Fptr)->request_quantize_method == NO_DITHER) { + /* must use finer quantization if no dithering is done */ + (outfptr->Fptr)->request_quantize_level = 16; + } else { + (outfptr->Fptr)->request_quantize_level = 4; + } } } @@ -1027,21 +1027,21 @@ int imcomp_init_table(fitsfile *outfptr, bitpix = LONG_IMG; else if (inbitpix == SBYTE_IMG) bitpix = BYTE_IMG; - else + else bitpix = inbitpix; /* reset default tile dimensions too if required */ memcpy(actual_tilesize, outfptr->Fptr->request_tilesize, MAX_COMPRESS_DIM * sizeof(long)); if ((outfptr->Fptr)->request_compress_type == HCOMPRESS_1) { - + /* Tiles must ultimately have 2 (and only 2) dimensions, each with at least 4 pixels. First catch the case where the image itself won't allow this. */ if (naxis < 2 ) { ffpmsg("Hcompress cannot be used with 1-dimensional images (imcomp_init_table)"); return(*status = DATA_COMPRESSION_ERR); - } + } for (ii=0; ii= 4) @@ -1050,12 +1050,12 @@ int imcomp_init_table(fitsfile *outfptr, if (nQualifyDims < 2) { ffpmsg("Hcompress minimum image dimension is 4 pixels (imcomp_init_table)"); - return(*status = DATA_COMPRESSION_ERR); + return(*status = DATA_COMPRESSION_ERR); } /* Handle 2 special cases for backwards compatibility. 1) If both X and Y tile dims are set to full size, ignore - any other requested dimensions and just set their sizes to 1. + any other requested dimensions and just set their sizes to 1. 2) If X is full size and all the rest are size 1, attempt to find a reasonable size for Y. All other 1-D tile specifications will be rejected. */ @@ -1068,59 +1068,59 @@ int imcomp_init_table(fitsfile *outfptr, if ((actual_tilesize[0] <= 0) && (actual_tilesize[1] == -1) ){ - - /* compress the whole image as a single tile */ + + /* compress the whole image as a single tile */ actual_tilesize[0] = naxes[0]; actual_tilesize[1] = naxes[1]; for (ii = 2; ii < naxis; ii++) { - /* set all higher tile dimensions = 1 */ + /* set all higher tile dimensions = 1 */ actual_tilesize[ii] = 1; - } + } } else if ((actual_tilesize[0] <= 0) && noHigherDims) { - + /* The Hcompress algorithm is inherently 2D in nature, so the row by row - tiling that is used for other compression algorithms is not appropriate. - If the image has less than 30 rows, then the entire image will be compressed - as a single tile. Otherwise the tiles will consist of 16 rows of the image. - This keeps the tiles to a reasonable size, and it also includes enough rows - to allow good compression efficiency. If the last tile of the image - happens to contain less than 4 rows, then find another tile size with - between 14 and 30 rows (preferably even), so that the last tile has - at least 4 rows - */ - + tiling that is used for other compression algorithms is not appropriate. + If the image has less than 30 rows, then the entire image will be compressed + as a single tile. Otherwise the tiles will consist of 16 rows of the image. + This keeps the tiles to a reasonable size, and it also includes enough rows + to allow good compression efficiency. If the last tile of the image + happens to contain less than 4 rows, then find another tile size with + between 14 and 30 rows (preferably even), so that the last tile has + at least 4 rows + */ + /* 1st tile dimension is the row length of the image */ actual_tilesize[0] = naxes[0]; if (naxes[1] <= 30) { /* use whole image if it is small */ actual_tilesize[1] = naxes[1]; - } else { + } else { /* look for another good tile dimension */ - if (naxes[1] % 16 == 0 || naxes[1] % 16 > 3) { + if (naxes[1] % 16 == 0 || naxes[1] % 16 > 3) { actual_tilesize[1] = 16; - } else if (naxes[1] % 24 == 0 || naxes[1] % 24 > 3) { + } else if (naxes[1] % 24 == 0 || naxes[1] % 24 > 3) { actual_tilesize[1] = 24; - } else if (naxes[1] % 20 == 0 || naxes[1] % 20 > 3) { + } else if (naxes[1] % 20 == 0 || naxes[1] % 20 > 3) { actual_tilesize[1] = 20; - } else if (naxes[1] % 30 == 0 || naxes[1] % 30 > 3) { + } else if (naxes[1] % 30 == 0 || naxes[1] % 30 > 3) { actual_tilesize[1] = 30; - } else if (naxes[1] % 28 == 0 || naxes[1] % 28 > 3) { + } else if (naxes[1] % 28 == 0 || naxes[1] % 28 > 3) { actual_tilesize[1] = 28; - } else if (naxes[1] % 26 == 0 || naxes[1] % 26 > 3) { + } else if (naxes[1] % 26 == 0 || naxes[1] % 26 > 3) { actual_tilesize[1] = 26; - } else if (naxes[1] % 22 == 0 || naxes[1] % 22 > 3) { + } else if (naxes[1] % 22 == 0 || naxes[1] % 22 > 3) { actual_tilesize[1] = 22; - } else if (naxes[1] % 18 == 0 || naxes[1] % 18 > 3) { + } else if (naxes[1] % 18 == 0 || naxes[1] % 18 > 3) { actual_tilesize[1] = 18; - } else if (naxes[1] % 14 == 0 || naxes[1] % 14 > 3) { + } else if (naxes[1] % 14 == 0 || naxes[1] % 14 > 3) { actual_tilesize[1] = 14; - } else { + } else { actual_tilesize[1] = 17; - } - } + } + } } else { if (actual_tilesize[0] <= 0) actual_tilesize[0] = naxes[0]; @@ -1132,7 +1132,7 @@ int imcomp_init_table(fitsfile *outfptr, actual_tilesize[ii] = 1; } } - + for (ii=0; ii 1) @@ -1153,25 +1153,25 @@ int imcomp_init_table(fitsfile *outfptr, ffpmsg("Hcompress tiles must have 2 dimensions (imcomp_init_table)"); return(*status = DATA_COMPRESSION_ERR); } - + if (actual_tilesize[firstDim] < 4 || actual_tilesize[secondDim] < 4) { ffpmsg("Hcompress minimum tile dimension is 4 pixels (imcomp_init_table)"); return (*status = DATA_COMPRESSION_ERR); } - + /* check if requested tile size causes the last tile to to have less than 4 pixels */ remain = naxes[firstDim] % (actual_tilesize[firstDim]); /* 1st dimension */ if (remain > 0 && remain < 4) { ndiv = naxes[firstDim]/actual_tilesize[firstDim]; /* integer truncation is intentional */ addToDim = ceil((double)remain/ndiv); (actual_tilesize[firstDim]) += addToDim; /* increase tile size */ - + remain = naxes[firstDim] % (actual_tilesize[firstDim]); if (remain > 0 && remain < 4) { ffpmsg("Last tile along 1st dimension has less than 4 pixels (imcomp_init_table)"); - return(*status = DATA_COMPRESSION_ERR); - } + return(*status = DATA_COMPRESSION_ERR); + } } remain = naxes[secondDim] % (actual_tilesize[secondDim]); /* 2nd dimension */ @@ -1179,28 +1179,28 @@ int imcomp_init_table(fitsfile *outfptr, ndiv = naxes[secondDim]/actual_tilesize[secondDim]; /* integer truncation is intentional */ addToDim = ceil((double)remain/ndiv); (actual_tilesize[secondDim]) += addToDim; /* increase tile size */ - + remain = naxes[secondDim] % (actual_tilesize[secondDim]); if (remain > 0 && remain < 4) { ffpmsg("Last tile along 2nd dimension has less than 4 pixels (imcomp_init_table)"); - return(*status = DATA_COMPRESSION_ERR); - } + return(*status = DATA_COMPRESSION_ERR); + } } } /* end, if HCOMPRESS_1 */ - + for (ii = 0; ii < naxis; ii++) { - if (ii == 0) { /* first axis is different */ - if (actual_tilesize[ii] <= 0) { - actual_tilesize[ii] = naxes[ii]; - } - } else { - if (actual_tilesize[ii] < 0) { + if (ii == 0) { /* first axis is different */ + if (actual_tilesize[ii] <= 0) { + actual_tilesize[ii] = naxes[ii]; + } + } else { + if (actual_tilesize[ii] < 0) { actual_tilesize[ii] = naxes[ii]; /* negative value maean use whole length */ - } else if (actual_tilesize[ii] == 0) { + } else if (actual_tilesize[ii] == 0) { actual_tilesize[ii] = 1; /* zero value means use default value = 1 */ - } - } + } + } } /* ---- set up array of TFORM strings -------------------------------*/ @@ -1224,7 +1224,7 @@ int imcomp_init_table(fitsfile *outfptr, } /* determine the default number of columns in the output table */ - if (bitpix < 0 && (outfptr->Fptr)->request_quantize_level != NO_QUANTIZE) + if (bitpix < 0 && (outfptr->Fptr)->request_quantize_level != NO_QUANTIZE) ncols = 3; /* quantized and scaled floating point image */ else ncols = 1; /* default table has just one 'COMPRESSED_DATA' column */ @@ -1262,7 +1262,7 @@ int imcomp_init_table(fitsfile *outfptr, else if ((outfptr->Fptr)->request_compress_type == NOCOMPRESS) { strcpy(zcmptype, "NOCOMPRESS"); - } + } else { ffpmsg("unknown compression type (imcomp_init_table)"); @@ -1274,91 +1274,91 @@ int imcomp_init_table(fitsfile *outfptr, we need to test now for setting is_primary */ is_primary = (outfptr->Fptr->curhdu == 0); /* create the bintable extension to contain the compressed image */ - ffcrtb(outfptr, BINARY_TBL, nrows, ncols, ttype, + ffcrtb(outfptr, BINARY_TBL, nrows, ncols, ttype, tform, tunit, 0, status); /* Add standard header keywords. */ - ffpkyl (outfptr, "ZIMAGE", 1, - "extension contains compressed image", status); + ffpkyl (outfptr, "ZIMAGE", 1, + "extension contains compressed image", status); if (writebitpix) { /* write the keywords defining the datatype and dimensions of */ - /* the uncompressed image. If not, these keywords will be */ + /* the uncompressed image. If not, these keywords will be */ /* copied later from the input uncompressed image */ - - if (is_primary) + + if (is_primary) ffpkyl (outfptr, "ZSIMPLE", 1, - "file does conform to FITS standard", status); + "file does conform to FITS standard", status); ffpkyj (outfptr, "ZBITPIX", bitpix, - "data type of original image", status); + "data type of original image", status); ffpkyj (outfptr, "ZNAXIS", naxis, - "dimension of original image", status); + "dimension of original image", status); for (ii = 0; ii < naxis; ii++) { snprintf (keyname, FLEN_KEYWORD,"ZNAXIS%d", ii+1); ffpkyj (outfptr, keyname, naxes[ii], - "length of original image axis", status); + "length of original image axis", status); } } - + for (ii = 0; ii < naxis; ii++) { snprintf (keyname, FLEN_KEYWORD,"ZTILE%d", ii+1); ffpkyj (outfptr, keyname, actual_tilesize[ii], - "size of tiles to be compressed", status); + "size of tiles to be compressed", status); } if (bitpix < 0) { - - if ((outfptr->Fptr)->request_quantize_level == NO_QUANTIZE) { - ffpkys(outfptr, "ZQUANTIZ", "NONE", - "Lossless compression without quantization", status); - } else { - - /* Unless dithering has been specifically turned off by setting */ - /* request_quantize_method = -1, use dithering by default */ - /* when quantizing floating point images. */ - - if ( (outfptr->Fptr)->request_quantize_method == 0) + + if ((outfptr->Fptr)->request_quantize_level == NO_QUANTIZE) { + ffpkys(outfptr, "ZQUANTIZ", "NONE", + "Lossless compression without quantization", status); + } else { + + /* Unless dithering has been specifically turned off by setting */ + /* request_quantize_method = -1, use dithering by default */ + /* when quantizing floating point images. */ + + if ( (outfptr->Fptr)->request_quantize_method == 0) (outfptr->Fptr)->request_quantize_method = SUBTRACTIVE_DITHER_1; - - if ((outfptr->Fptr)->request_quantize_method == SUBTRACTIVE_DITHER_1) { - ffpkys(outfptr, "ZQUANTIZ", "SUBTRACTIVE_DITHER_1", - "Pixel Quantization Algorithm", status); - - /* also write the associated ZDITHER0 keyword with a default value */ - /* which may get updated later. */ - ffpky(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->request_dither_seed), - "dithering offset when quantizing floats", status); - + + if ((outfptr->Fptr)->request_quantize_method == SUBTRACTIVE_DITHER_1) { + ffpkys(outfptr, "ZQUANTIZ", "SUBTRACTIVE_DITHER_1", + "Pixel Quantization Algorithm", status); + + /* also write the associated ZDITHER0 keyword with a default value */ + /* which may get updated later. */ + ffpky(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->request_dither_seed), + "dithering offset when quantizing floats", status); + } else if ((outfptr->Fptr)->request_quantize_method == SUBTRACTIVE_DITHER_2) { - ffpkys(outfptr, "ZQUANTIZ", "SUBTRACTIVE_DITHER_2", - "Pixel Quantization Algorithm", status); - - /* also write the associated ZDITHER0 keyword with a default value */ - /* which may get updated later. */ - ffpky(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->request_dither_seed), - "dithering offset when quantizing floats", status); - - if (!strcmp(zcmptype, "RICE_1")) { - /* when using this new dithering method, change the compression type */ - /* to an alias, so that old versions of funpack will not be able to */ - /* created a corrupted uncompressed image. */ - /* ******* can remove this cludge after about June 2015, after most old versions of fpack are gone */ - strcpy(zcmptype, "RICE_ONE"); - } + ffpkys(outfptr, "ZQUANTIZ", "SUBTRACTIVE_DITHER_2", + "Pixel Quantization Algorithm", status); + + /* also write the associated ZDITHER0 keyword with a default value */ + /* which may get updated later. */ + ffpky(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->request_dither_seed), + "dithering offset when quantizing floats", status); + + if (!strcmp(zcmptype, "RICE_1")) { + /* when using this new dithering method, change the compression type */ + /* to an alias, so that old versions of funpack will not be able to */ + /* created a corrupted uncompressed image. */ + /* ******* can remove this cludge after about June 2015, after most old versions of fpack are gone */ + strcpy(zcmptype, "RICE_ONE"); + } } else if ((outfptr->Fptr)->request_quantize_method == NO_DITHER) { - ffpkys(outfptr, "ZQUANTIZ", "NO_DITHER", - "No dithering during quantization", status); - } + ffpkys(outfptr, "ZQUANTIZ", "NO_DITHER", + "No dithering during quantization", status); + } - } + } } ffpkys (outfptr, "ZCMPTYPE", zcmptype, - "compression algorithm", status); + "compression algorithm", status); /* write any algorithm-specific keywords */ if ((outfptr->Fptr)->request_compress_type == RICE_1) @@ -1368,20 +1368,20 @@ int imcomp_init_table(fitsfile *outfptr, /* for now at least, the block size is always 32 */ ffpkyj (outfptr, "ZVAL1", 32, - "pixels per block", status); + "pixels per block", status); ffpkys (outfptr, "ZNAME2", "BYTEPIX", "bytes per pixel (1, 2, 4, or 8)", status); if (bitpix == BYTE_IMG) ffpkyj (outfptr, "ZVAL2", 1, - "bytes per pixel (1, 2, 4, or 8)", status); + "bytes per pixel (1, 2, 4, or 8)", status); else if (bitpix == SHORT_IMG) ffpkyj (outfptr, "ZVAL2", 2, - "bytes per pixel (1, 2, 4, or 8)", status); - else + "bytes per pixel (1, 2, 4, or 8)", status); + else ffpkyj (outfptr, "ZVAL2", 4, - "bytes per pixel (1, 2, 4, or 8)", status); + "bytes per pixel (1, 2, 4, or 8)", status); } else if ((outfptr->Fptr)->request_compress_type == HCOMPRESS_1) @@ -1389,12 +1389,12 @@ int imcomp_init_table(fitsfile *outfptr, ffpkys (outfptr, "ZNAME1", "SCALE", "HCOMPRESS scale factor", status); ffpkye (outfptr, "ZVAL1", (outfptr->Fptr)->request_hcomp_scale, - 7, "HCOMPRESS scale factor", status); + 7, "HCOMPRESS scale factor", status); ffpkys (outfptr, "ZNAME2", "SMOOTH", "HCOMPRESS smooth option", status); ffpkyj (outfptr, "ZVAL2", (long) (outfptr->Fptr)->request_hcomp_smooth, - "HCOMPRESS smooth option", status); + "HCOMPRESS smooth option", status); } /* Write the BSCALE and BZERO keywords, if an unsigned integer image */ @@ -1431,12 +1431,12 @@ int imcomp_calc_max_elem (int comptype, int nx, int zbitpix, int blocksize) nx = maximum number of pixels in a tile blocksize is only relevant for RICE compression */ -{ +{ if (comptype == RICE_1) { if (zbitpix == 16) return (sizeof(short) * nx + nx / blocksize + 2 + 4); - else + else return (sizeof(float) * nx + nx / blocksize + 2 + 4); } else if ((comptype == GZIP_1) || (comptype == GZIP_2)) @@ -1446,31 +1446,31 @@ int imcomp_calc_max_elem (int comptype, int nx, int zbitpix, int blocksize) /* If this size turns out to be too small, then the gzip */ /* compression routine will allocate more space as required */ /* to be on the safe size, allocate buffer same size as input */ - + if (zbitpix == 16) return(nx * 2); - else if (zbitpix == 8) + else if (zbitpix == 8) return(nx); - else + else return(nx * 4); } else if (comptype == BZIP2_1) { /* To guarantee that the compressed data will fit, allocate an output - buffer of size 1% larger than the uncompressed data, plus 600 bytes */ + buffer of size 1% larger than the uncompressed data, plus 600 bytes */ return((int) (nx * 1.01 * zbitpix / 8. + 601.)); } else if (comptype == HCOMPRESS_1) { - /* Imperical evidence suggests in the worst case, - the compressed stream could be up to 10% larger than the original - image. Add 26 byte overhead, only significant for very small tiles - + /* Imperical evidence suggests in the worst case, + the compressed stream could be up to 10% larger than the original + image. Add 26 byte overhead, only significant for very small tiles + Possible improvement: may need to allow a larger size for 32-bit images */ if (zbitpix == 16 || zbitpix == 8) - + return( (int) (nx * 2.2 + 26)); /* will be compressing 16-bit int array */ else return( (int) (nx * 4.4 + 26)); /* will be compressing 32-bit int array */ @@ -1486,9 +1486,9 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) - if it is a float or double image, then it tries to quantize the pixels into scaled integers. - it then compressess the integer pixels, or if the it was not - possible to quantize the floating point pixels, then it losslessly - compresses them with gzip - - writes the compressed byte stream to the output FITS file + possible to quantize the floating point pixels, then it losslessly + compresses them with gzip + - writes the compressed byte stream to the output FITS file */ { double *tiledata; @@ -1509,8 +1509,8 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) maxtilelen = (outfptr->Fptr)->maxtilelen; - /* - Allocate buffer to hold 1 tile of data; size depends on which compression + /* + Allocate buffer to hold 1 tile of data; size depends on which compression algorithm is used: Rice and GZIP will compress byte, short, or int arrays without conversion. @@ -1518,17 +1518,17 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) HCompress internally converts byte or short values to ints, and converts int values to 8-byte longlong integers. */ - + if ((outfptr->Fptr)->zbitpix == FLOAT_IMG) { datatype = TFLOAT; if ( (outfptr->Fptr)->compress_type == HCOMPRESS_1) { - /* need twice as much scratch space (8 bytes per pixel) */ - tiledata = (double*) malloc (maxtilelen * 2 *sizeof (float)); - } else { + /* need twice as much scratch space (8 bytes per pixel) */ + tiledata = (double*) malloc (maxtilelen * 2 *sizeof (float)); + } else { tiledata = (double*) malloc (maxtilelen * sizeof (float)); - } + } } else if ((outfptr->Fptr)->zbitpix == DOUBLE_IMG) { @@ -1539,15 +1539,15 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) { datatype = TSHORT; if ( (outfptr->Fptr)->compress_type == RICE_1 || - (outfptr->Fptr)->compress_type == GZIP_1 || - (outfptr->Fptr)->compress_type == GZIP_2 || - (outfptr->Fptr)->compress_type == BZIP2_1 || + (outfptr->Fptr)->compress_type == GZIP_1 || + (outfptr->Fptr)->compress_type == GZIP_2 || + (outfptr->Fptr)->compress_type == BZIP2_1 || (outfptr->Fptr)->compress_type == NOCOMPRESS) { - /* only need buffer of I*2 pixels for gzip, bzip2, and Rice */ + /* only need buffer of I*2 pixels for gzip, bzip2, and Rice */ - tiledata = (double*) malloc (maxtilelen * sizeof (short)); - } else { - /* need buffer of I*4 pixels for Hcompress and PLIO */ + tiledata = (double*) malloc (maxtilelen * sizeof (short)); + } else { + /* need buffer of I*4 pixels for Hcompress and PLIO */ tiledata = (double*) malloc (maxtilelen * sizeof (int)); } } @@ -1556,14 +1556,14 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) datatype = TBYTE; if ( (outfptr->Fptr)->compress_type == RICE_1 || - (outfptr->Fptr)->compress_type == BZIP2_1 || - (outfptr->Fptr)->compress_type == GZIP_1 || - (outfptr->Fptr)->compress_type == GZIP_2) { - /* only need buffer of I*1 pixels for gzip, bzip2, and Rice */ - - tiledata = (double*) malloc (maxtilelen); - } else { - /* need buffer of I*4 pixels for Hcompress and PLIO */ + (outfptr->Fptr)->compress_type == BZIP2_1 || + (outfptr->Fptr)->compress_type == GZIP_1 || + (outfptr->Fptr)->compress_type == GZIP_2) { + /* only need buffer of I*1 pixels for gzip, bzip2, and Rice */ + + tiledata = (double*) malloc (maxtilelen); + } else { + /* need buffer of I*4 pixels for Hcompress and PLIO */ tiledata = (double*) malloc (maxtilelen * sizeof (int)); } } @@ -1571,25 +1571,25 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) { datatype = TINT; if ( (outfptr->Fptr)->compress_type == HCOMPRESS_1) { - /* need twice as much scratch space (8 bytes per pixel) */ + /* need twice as much scratch space (8 bytes per pixel) */ - tiledata = (double*) malloc (maxtilelen * 2 * sizeof (int)); - } else { - /* only need buffer of I*4 pixels for gzip, bzip2, Rice, and PLIO */ + tiledata = (double*) malloc (maxtilelen * 2 * sizeof (int)); + } else { + /* only need buffer of I*4 pixels for gzip, bzip2, Rice, and PLIO */ tiledata = (double*) malloc (maxtilelen * sizeof (int)); } } else { - ffpmsg("Bad image datatype. (imcomp_compress_image)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Bad image datatype. (imcomp_compress_image)"); + return (*status = MEMORY_ALLOCATION); } - + if (tiledata == NULL) { - ffpmsg("Out of memory. (imcomp_compress_image)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory. (imcomp_compress_image)"); + return (*status = MEMORY_ALLOCATION); } /* calculate size of tile in each dimension */ @@ -1649,33 +1649,33 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) } /* read next tile of data from image */ - anynul = 0; + anynul = 0; if (datatype == TFLOAT) { - ffgsve(infptr, 1, naxis, naxes, fpixel, lpixel, incre, + ffgsve(infptr, 1, naxis, naxes, fpixel, lpixel, incre, FLOATNULLVALUE, (float *) tiledata, &anynul, status); } else if (datatype == TDOUBLE) { - ffgsvd(infptr, 1, naxis, naxes, fpixel, lpixel, incre, + ffgsvd(infptr, 1, naxis, naxes, fpixel, lpixel, incre, DOUBLENULLVALUE, tiledata, &anynul, status); } else if (datatype == TINT) { - ffgsvk(infptr, 1, naxis, naxes, fpixel, lpixel, incre, + ffgsvk(infptr, 1, naxis, naxes, fpixel, lpixel, incre, 0, (int *) tiledata, &anynul, status); } else if (datatype == TSHORT) { - ffgsvi(infptr, 1, naxis, naxes, fpixel, lpixel, incre, + ffgsvi(infptr, 1, naxis, naxes, fpixel, lpixel, incre, 0, (short *) tiledata, &anynul, status); } else if (datatype == TBYTE) { - ffgsvb(infptr, 1, naxis, naxes, fpixel, lpixel, incre, + ffgsvb(infptr, 1, naxis, naxes, fpixel, lpixel, incre, 0, (unsigned char *) tiledata, &anynul, status); } - else + else { ffpmsg("Error bad datatype of image tile to compress"); free(tiledata); @@ -1684,13 +1684,13 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) /* now compress the tile, and write to row of binary table */ /* NOTE: we don't have to worry about the presence of null values in the - array if it is an integer array: the null value is simply encoded - in the compressed array just like any other pixel value. - - If it is a floating point array, then we need to check for null - only if the anynul parameter returned a true value when reading the tile - */ - + array if it is an integer array: the null value is simply encoded + in the compressed array just like any other pixel value. + + If it is a floating point array, then we need to check for null + only if the anynul parameter returned a true value when reading the tile + */ + /* Collapse sizes of higher dimension tiles into 2 dimensional equivalents needed by the quantizing algorithms for floating point types */ @@ -1720,7 +1720,7 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) return (*status); } - row++; + row++; } } } @@ -1734,7 +1734,7 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) if (gotnulls) { ffgcrd(outfptr, "ZCMPTYPE", card, status); - ffikyj(outfptr, "ZBLANK", COMPRESS_NULL_VALUE, + ffikyj(outfptr, "ZBLANK", COMPRESS_NULL_VALUE, "null value in the compressed integer array", status); } @@ -1743,8 +1743,8 @@ int imcomp_compress_image (fitsfile *infptr, fitsfile *outfptr, int *status) /*--------------------------------------------------------------------------*/ int imcomp_compress_tile (fitsfile *outfptr, long row, /* tile number = row in the binary table that holds the compressed data */ - int datatype, - void *tiledata, + int datatype, + void *tiledata, long tilelen, long tilenx, long tileny, @@ -1762,9 +1762,9 @@ int imcomp_compress_tile (fitsfile *outfptr, If the tile cannot be quantized than the raw float or double values are losslessly compressed with gzip and then written to the output table. - + This input array may be modified by this routine. If the array is of type TINT - or TFLOAT, and the compression type is HCOMPRESS, then it must have been + or TFLOAT, and the compression type is HCOMPRESS, then it must have been allocated to be twice as large (8 bytes per pixel) to provide scratch space. Note that this routine does not fully support the implicit datatype conversion that @@ -1818,12 +1818,12 @@ int imcomp_compress_tile (fitsfile *outfptr, /* calculate the column bin of the compressed tile */ tilecol = (row - 1) % ((long)(((outfptr->Fptr)->znaxis[0] - 1) / ((outfptr->Fptr)->tilesize[0])) + 1); - + if ((outfptr->Fptr)->tilerow[tilecol] == row) { if (((outfptr->Fptr)->tiledata)[tilecol]) { free(((outfptr->Fptr)->tiledata)[tilecol]); } - + if (((outfptr->Fptr)->tilenullarray)[tilecol]) { free(((outfptr->Fptr)->tilenullarray)[tilecol]); } @@ -1839,8 +1839,8 @@ int imcomp_compress_tile (fitsfile *outfptr, if ( (outfptr->Fptr)->compress_type == NOCOMPRESS) { /* Special case when using NOCOMPRESS for diagnostic purposes in fpack */ - if (imcomp_write_nocompress_tile(outfptr, row, datatype, tiledata, tilelen, - nullcheck, nullflagval, status) > 0) { + if (imcomp_write_nocompress_tile(outfptr, row, datatype, tiledata, tilelen, + nullcheck, nullflagval, status) > 0) { return(*status); } return(*status); @@ -1870,7 +1870,7 @@ int imcomp_compress_tile (fitsfile *outfptr, /* if the BSCALE and BZERO keywords exist, then the input values must */ /* be inverse scaled by this factor, before the values are compressed. */ /* (The program may have turned off scaling, which over rides the keywords) */ - + scale = (outfptr->Fptr)->cn_bscale; zero = (outfptr->Fptr)->cn_bzero; actual_bzero = (outfptr->Fptr)->cn_actual_bzero; @@ -1924,31 +1924,31 @@ int imcomp_compress_tile (fitsfile *outfptr, if (cbuf == NULL) { ffpmsg("Memory allocation failure. (imcomp_compress_tile)"); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } /* =========================================================================== */ if ( (outfptr->Fptr)->compress_type == RICE_1) { if (intlength == 2) { - nelem = fits_rcomp_short ((short *)idata, tilelen, (unsigned char *) cbuf, + nelem = fits_rcomp_short ((short *)idata, tilelen, (unsigned char *) cbuf, clen, (outfptr->Fptr)->rice_blocksize); } else if (intlength == 1) { - nelem = fits_rcomp_byte ((signed char *)idata, tilelen, (unsigned char *) cbuf, + nelem = fits_rcomp_byte ((signed char *)idata, tilelen, (unsigned char *) cbuf, clen, (outfptr->Fptr)->rice_blocksize); } else { - nelem = fits_rcomp (idata, tilelen, (unsigned char *) cbuf, + nelem = fits_rcomp (idata, tilelen, (unsigned char *) cbuf, clen, (outfptr->Fptr)->rice_blocksize); } - if (nelem < 0) /* data compression error condition */ + if (nelem < 0) /* data compression error condition */ { - free (cbuf); + free (cbuf); ffpmsg("error Rice compressing image tile (imcomp_compress_tile)"); return (*status = DATA_COMPRESSION_ERR); } - /* Write the compressed byte stream. */ + /* Write the compressed byte stream. */ ffpclb(outfptr, (outfptr->Fptr)->cn_compressed, row, 1, nelem, (unsigned char *) cbuf, status); } @@ -1965,16 +1965,16 @@ int imcomp_compress_tile (fitsfile *outfptr, } } - nelem = pl_p2li (idata, 1, cbuf, tilelen); + nelem = pl_p2li (idata, 1, cbuf, tilelen); - if (nelem < 0) /* data compression error condition */ + if (nelem < 0) /* data compression error condition */ { - free (cbuf); + free (cbuf); ffpmsg("error PLIO compressing image tile (imcomp_compress_tile)"); return (*status = DATA_COMPRESSION_ERR); } - /* Write the compressed byte stream. */ + /* Write the compressed byte stream. */ ffpcli(outfptr, (outfptr->Fptr)->cn_compressed, row, 1, nelem, cbuf, status); } @@ -1983,47 +1983,47 @@ int imcomp_compress_tile (fitsfile *outfptr, else if ( ((outfptr->Fptr)->compress_type == GZIP_1) || ((outfptr->Fptr)->compress_type == GZIP_2) ) { - if ((outfptr->Fptr)->quantize_level == NO_QUANTIZE && datatype == TFLOAT) { - /* Special case of losslessly compressing floating point pixels with GZIP */ - /* In this case we compress the input tile array directly */ + if ((outfptr->Fptr)->quantize_level == NO_QUANTIZE && datatype == TFLOAT) { + /* Special case of losslessly compressing floating point pixels with GZIP */ + /* In this case we compress the input tile array directly */ #if BYTESWAPPED - ffswap4((int*) tiledata, tilelen); + ffswap4((int*) tiledata, tilelen); #endif if ( (outfptr->Fptr)->compress_type == GZIP_2 ) - fits_shuffle_4bytes((char *) tiledata, tilelen, status); + fits_shuffle_4bytes((char *) tiledata, tilelen, status); compress2mem_from_mem((char *) tiledata, tilelen * sizeof(float), (char **) &cbuf, &clen, realloc, &gzip_nelem, status); - } else if ((outfptr->Fptr)->quantize_level == NO_QUANTIZE && datatype == TDOUBLE) { - /* Special case of losslessly compressing double pixels with GZIP */ - /* In this case we compress the input tile array directly */ + } else if ((outfptr->Fptr)->quantize_level == NO_QUANTIZE && datatype == TDOUBLE) { + /* Special case of losslessly compressing double pixels with GZIP */ + /* In this case we compress the input tile array directly */ #if BYTESWAPPED - ffswap8((double *) tiledata, tilelen); + ffswap8((double *) tiledata, tilelen); #endif if ( (outfptr->Fptr)->compress_type == GZIP_2 ) - fits_shuffle_8bytes((char *) tiledata, tilelen, status); + fits_shuffle_8bytes((char *) tiledata, tilelen, status); compress2mem_from_mem((char *) tiledata, tilelen * sizeof(double), (char **) &cbuf, &clen, realloc, &gzip_nelem, status); - } else { + } else { - /* compress the integer idata array */ + /* compress the integer idata array */ #if BYTESWAPPED - if (intlength == 2) - ffswap2((short *) idata, tilelen); - else if (intlength == 4) - ffswap4(idata, tilelen); + if (intlength == 2) + ffswap2((short *) idata, tilelen); + else if (intlength == 4) + ffswap4(idata, tilelen); #endif if (intlength == 2) { if ( (outfptr->Fptr)->compress_type == GZIP_2 ) - fits_shuffle_2bytes((char *) tiledata, tilelen, status); + fits_shuffle_2bytes((char *) tiledata, tilelen, status); compress2mem_from_mem((char *) idata, tilelen * sizeof(short), (char **) &cbuf, &clen, realloc, &gzip_nelem, status); @@ -2036,14 +2036,14 @@ int imcomp_compress_tile (fitsfile *outfptr, } else { if ( (outfptr->Fptr)->compress_type == GZIP_2 ) - fits_shuffle_4bytes((char *) tiledata, tilelen, status); + fits_shuffle_4bytes((char *) tiledata, tilelen, status); compress2mem_from_mem((char *) idata, tilelen * sizeof(int), (char **) &cbuf, &clen, realloc, &gzip_nelem, status); } } - /* Write the compressed byte stream. */ + /* Write the compressed byte stream. */ ffpclb(outfptr, (outfptr->Fptr)->cn_compressed, row, 1, gzip_nelem, (unsigned char *) cbuf, status); @@ -2051,74 +2051,74 @@ int imcomp_compress_tile (fitsfile *outfptr, } else if ( (outfptr->Fptr)->compress_type == BZIP2_1) { #if BYTESWAPPED - if (intlength == 2) - ffswap2((short *) idata, tilelen); - else if (intlength == 4) - ffswap4(idata, tilelen); + if (intlength == 2) + ffswap2((short *) idata, tilelen); + else if (intlength == 4) + ffswap4(idata, tilelen); #endif bzlen = (unsigned int) clen; - + /* call bzip2 with blocksize = 900K, verbosity = 0, and default workfactor */ /* bzip2 is not supported in the public release. This is only for test purposes. if (BZ2_bzBuffToBuffCompress( (char *) cbuf, &bzlen, - (char *) idata, (unsigned int) (tilelen * intlength), 9, 0, 0) ) + (char *) idata, (unsigned int) (tilelen * intlength), 9, 0, 0) ) */ - { + { ffpmsg("bzip2 compression error"); return(*status = DATA_COMPRESSION_ERR); } - /* Write the compressed byte stream. */ + /* Write the compressed byte stream. */ ffpclb(outfptr, (outfptr->Fptr)->cn_compressed, row, 1, bzlen, (unsigned char *) cbuf, status); /* =========================================================================== */ } else if ( (outfptr->Fptr)->compress_type == HCOMPRESS_1) { - /* - if hcompscale is positive, then we have to multiply - the value by the RMS background noise to get the - absolute scale value. If negative, then it gives the - absolute scale value directly. - */ + /* + if hcompscale is positive, then we have to multiply + the value by the RMS background noise to get the + absolute scale value. If negative, then it gives the + absolute scale value directly. + */ hcompscale = (outfptr->Fptr)->hcomp_scale; - if (hcompscale > 0.) { - fits_img_stats_int(idata, tilenx, tileny, nullcheck, - nullval, 0,0,0,0,0,0,&noise2,&noise3,&noise5,status); + if (hcompscale > 0.) { + fits_img_stats_int(idata, tilenx, tileny, nullcheck, + nullval, 0,0,0,0,0,0,&noise2,&noise3,&noise5,status); + + /* use the minimum of the 3 noise estimates */ + if (noise2 != 0. && noise2 < noise3) noise3 = noise2; + if (noise5 != 0. && noise5 < noise3) noise3 = noise5; - /* use the minimum of the 3 noise estimates */ - if (noise2 != 0. && noise2 < noise3) noise3 = noise2; - if (noise5 != 0. && noise5 < noise3) noise3 = noise5; - - hcompscale = (float) (hcompscale * noise3); + hcompscale = (float) (hcompscale * noise3); - } else if (hcompscale < 0.) { + } else if (hcompscale < 0.) { - hcompscale = hcompscale * -1.0F; - } + hcompscale = hcompscale * -1.0F; + } - ihcompscale = (int) (hcompscale + 0.5); + ihcompscale = (int) (hcompscale + 0.5); hcomp_len = clen; /* allocated size of the buffer */ - + if (zbitpix == BYTE_IMG || zbitpix == SHORT_IMG) { - fits_hcompress(idata, tilenx, tileny, - ihcompscale, (char *) cbuf, &hcomp_len, status); + fits_hcompress(idata, tilenx, tileny, + ihcompscale, (char *) cbuf, &hcomp_len, status); } else { /* have to convert idata to an I*8 array, in place */ /* idata must have been allocated large enough to do this */ fits_int_to_longlong_inplace(idata, tilelen, status); - lldata = (LONGLONG *) idata; + lldata = (LONGLONG *) idata; - fits_hcompress64(lldata, tilenx, tileny, - ihcompscale, (char *) cbuf, &hcomp_len, status); + fits_hcompress64(lldata, tilenx, tileny, + ihcompscale, (char *) cbuf, &hcomp_len, status); } - /* Write the compressed byte stream. */ + /* Write the compressed byte stream. */ ffpclb(outfptr, (outfptr->Fptr)->cn_compressed, row, 1, hcomp_len, (unsigned char *) cbuf, status); } @@ -2127,9 +2127,9 @@ int imcomp_compress_tile (fitsfile *outfptr, if ((outfptr->Fptr)->cn_zscale > 0) { /* write the linear scaling parameters for this tile */ - ffpcld (outfptr, (outfptr->Fptr)->cn_zscale, row, 1, 1, + ffpcld (outfptr, (outfptr->Fptr)->cn_zscale, row, 1, 1, bscale, status); - ffpcld (outfptr, (outfptr->Fptr)->cn_zzero, row, 1, 1, + ffpcld (outfptr, (outfptr->Fptr)->cn_zzero, row, 1, 1, bzero, status); } @@ -2138,7 +2138,7 @@ int imcomp_compress_tile (fitsfile *outfptr, /* =========================================================================== */ } else { /* if flag == 0., floating point data couldn't be quantized */ - /* losslessly compress the data with gzip. */ + /* losslessly compress the data with gzip. */ /* if gzip2 compressed data column doesn't exist, create it */ if ((outfptr->Fptr)->cn_gzip_data < 1) { @@ -2155,24 +2155,24 @@ int imcomp_compress_tile (fitsfile *outfptr, if (datatype == TFLOAT) { /* allocate buffer for the compressed tile bytes */ - /* make it 10% larger than the original uncompressed data */ + /* make it 10% larger than the original uncompressed data */ clen = (size_t) (tilelen * sizeof(float) * 1.1); cbuf = (short *) calloc (clen, sizeof (unsigned char)); if (cbuf == NULL) { ffpmsg("Memory allocation error. (imcomp_compress_tile)"); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } - /* convert null values to NaNs in place, if necessary */ - if (nullcheck == 1) { - imcomp_float2nan((float *) tiledata, tilelen, (int *) tiledata, - *(float *) (nullflagval), status); - } + /* convert null values to NaNs in place, if necessary */ + if (nullcheck == 1) { + imcomp_float2nan((float *) tiledata, tilelen, (int *) tiledata, + *(float *) (nullflagval), status); + } #if BYTESWAPPED - ffswap4((int*) tiledata, tilelen); + ffswap4((int*) tiledata, tilelen); #endif compress2mem_from_mem((char *) tiledata, tilelen * sizeof(float), (char **) &cbuf, &clen, realloc, &gzip_nelem, status); @@ -2180,30 +2180,30 @@ int imcomp_compress_tile (fitsfile *outfptr, } else { /* datatype == TDOUBLE */ /* allocate buffer for the compressed tile bytes */ - /* make it 10% larger than the original uncompressed data */ + /* make it 10% larger than the original uncompressed data */ clen = (size_t) (tilelen * sizeof(double) * 1.1); cbuf = (short *) calloc (clen, sizeof (unsigned char)); if (cbuf == NULL) { ffpmsg("Memory allocation error. (imcomp_compress_tile)"); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } - /* convert null values to NaNs in place, if necessary */ - if (nullcheck == 1) { - imcomp_double2nan((double *) tiledata, tilelen, (LONGLONG *) tiledata, - *(double *) (nullflagval), status); - } + /* convert null values to NaNs in place, if necessary */ + if (nullcheck == 1) { + imcomp_double2nan((double *) tiledata, tilelen, (LONGLONG *) tiledata, + *(double *) (nullflagval), status); + } #if BYTESWAPPED - ffswap8((double*) tiledata, tilelen); + ffswap8((double*) tiledata, tilelen); #endif compress2mem_from_mem((char *) tiledata, tilelen * sizeof(double), (char **) &cbuf, &clen, realloc, &gzip_nelem, status); } - /* Write the compressed byte stream. */ + /* Write the compressed byte stream. */ ffpclb(outfptr, (outfptr->Fptr)->cn_gzip_data, row, 1, gzip_nelem, (unsigned char *) cbuf, status); @@ -2216,8 +2216,8 @@ int imcomp_compress_tile (fitsfile *outfptr, /*--------------------------------------------------------------------------*/ int imcomp_write_nocompress_tile(fitsfile *outfptr, long row, - int datatype, - void *tiledata, + int datatype, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2226,20 +2226,20 @@ int imcomp_write_nocompress_tile(fitsfile *outfptr, char coltype[4]; /* Write the uncompressed image tile pixels to the tile-compressed image file. */ - /* This is a special case when using NOCOMPRESS for diagnostic purposes in fpack. */ + /* This is a special case when using NOCOMPRESS for diagnostic purposes in fpack. */ /* Currently, this only supports a limited number of data types and */ /* does not fully support null-valued pixels in the image. */ if ((outfptr->Fptr)->cn_uncompressed < 1) { /* uncompressed data column doesn't exist, so append new column to table */ if (datatype == TSHORT) { - strcpy(coltype, "1PI"); - } else if (datatype == TINT) { - strcpy(coltype, "1PJ"); - } else if (datatype == TFLOAT) { - strcpy(coltype, "1QE"); + strcpy(coltype, "1PI"); + } else if (datatype == TINT) { + strcpy(coltype, "1PJ"); + } else if (datatype == TFLOAT) { + strcpy(coltype, "1QE"); } else { - ffpmsg("NOCOMPRESSION option only supported for int*2, int*4, and float*4 images"); + ffpmsg("NOCOMPRESSION option only supported for int*2, int*4, and float*4 images"); return(*status = DATA_COMPRESSION_ERR); } @@ -2248,7 +2248,7 @@ int imcomp_write_nocompress_tile(fitsfile *outfptr, fits_get_colnum(outfptr, CASEINSEN, "UNCOMPRESSED_DATA", &(outfptr->Fptr)->cn_uncompressed, status); /* save col. num. */ - + fits_write_col(outfptr, datatype, (outfptr->Fptr)->cn_uncompressed, row, 1, tilelen, tiledata, status); /* write the tile data */ return (*status); @@ -2256,7 +2256,7 @@ int imcomp_write_nocompress_tile(fitsfile *outfptr, /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tshort( fitsfile *outfptr, - void *tiledata, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2277,31 +2277,31 @@ int imcomp_convert_tile_tshort( short *sbuff; int flagval, *idata; long ii; - - /* We only support writing this integer*2 tile data to a FITS image with + + /* We only support writing this integer*2 tile data to a FITS image with BITPIX = 16 and with BZERO = 0 and BSCALE = 1. */ - + if (zbitpix != SHORT_IMG || scale != 1.0 || zero != 0.0) { ffpmsg("Datatype conversion/scaling is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } sbuff = (short *) tiledata; idata = (int *) tiledata; - + if ( (outfptr->Fptr)->compress_type == RICE_1 || (outfptr->Fptr)->compress_type == GZIP_1 - || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1 ) + || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1 ) { /* don't have to convert to int if using gzip, bzip2 or Rice compression */ *intlength = 2; - + if (nullcheck == 1) { /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(short *) (nullflagval); if (flagval != nullval) { for (ii = tilelen - 1; ii >= 0; ii--) { - if (sbuff[ii] == (short) flagval) - sbuff[ii] = (short) nullval; + if (sbuff[ii] == (short) flagval) + sbuff[ii] = (short) nullval; } } } @@ -2313,9 +2313,9 @@ int imcomp_convert_tile_tshort( /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(short *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (sbuff[ii] == (short) flagval) - idata[ii] = nullval; - else + if (sbuff[ii] == (short) flagval) + idata[ii] = nullval; + else idata[ii] = (int) sbuff[ii]; } } else { /* just do the data type conversion to int */ @@ -2328,33 +2328,33 @@ int imcomp_convert_tile_tshort( *intlength = 4; if (zero == 0. && actual_bzero == 32768.) { /* Here we are compressing unsigned 16-bit integers that have */ - /* been offset by -32768 using the standard FITS convention. */ - /* Since PLIO cannot deal with negative values, we must apply */ - /* the shift of 32786 to the values to make them all positive. */ - /* The inverse negative shift will be applied in */ - /* imcomp_decompress_tile when reading the compressed tile. */ + /* been offset by -32768 using the standard FITS convention. */ + /* Since PLIO cannot deal with negative values, we must apply */ + /* the shift of 32786 to the values to make them all positive. */ + /* The inverse negative shift will be applied in */ + /* imcomp_decompress_tile when reading the compressed tile. */ if (nullcheck == 1) { /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(short *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (sbuff[ii] == (short) flagval) - idata[ii] = nullval; + if (sbuff[ii] == (short) flagval) + idata[ii] = nullval; else idata[ii] = (int) sbuff[ii] + 32768; } - } else { + } else { /* have to convert sbuff to an I*4 array, in place */ /* sbuff must have been allocated large enough to do this */ fits_short_to_int_inplace(sbuff, tilelen, 32768, status); } } else { - /* This is not an unsigned 16-bit integer array, so process normally */ + /* This is not an unsigned 16-bit integer array, so process normally */ if (nullcheck == 1) { /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(short *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (sbuff[ii] == (short) flagval) - idata[ii] = nullval; + if (sbuff[ii] == (short) flagval) + idata[ii] = nullval; else idata[ii] = (int) sbuff[ii]; } @@ -2370,7 +2370,7 @@ int imcomp_convert_tile_tshort( /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tushort( fitsfile *outfptr, - void *tiledata, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2391,41 +2391,41 @@ int imcomp_convert_tile_tushort( short *sbuff; int flagval, *idata; long ii; - + /* datatype of input array is unsigned short. We only support writing this datatype to a FITS image with BITPIX = 16 and with BZERO = 0 and BSCALE = 32768. */ if (zbitpix != SHORT_IMG || scale != 1.0 || zero != 32768.) { ffpmsg("Implicit datatype conversion is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } usbuff = (unsigned short *) tiledata; sbuff = (short *) tiledata; idata = (int *) tiledata; if ((outfptr->Fptr)->compress_type == RICE_1 || (outfptr->Fptr)->compress_type == GZIP_1 - || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1) + || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1) { /* don't have to convert to int if using gzip, bzip2, or Rice compression */ *intlength = 2; /* offset the unsigned value by -32768 to a signed short value. */ - /* It is more efficient to do this by just flipping the most significant of the 16 bits */ + /* It is more efficient to do this by just flipping the most significant of the 16 bits */ if (nullcheck == 1) { /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(unsigned short *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (usbuff[ii] == (unsigned short) flagval) - sbuff[ii] = (short) nullval; + if (usbuff[ii] == (unsigned short) flagval) + sbuff[ii] = (short) nullval; else - usbuff[ii] = (usbuff[ii]) ^ 0x8000; + usbuff[ii] = (usbuff[ii]) ^ 0x8000; } } else { /* just offset the pixel values by 32768 (by flipping the MSB */ for (ii = tilelen - 1; ii >= 0; ii--) - usbuff[ii] = (usbuff[ii]) ^ 0x8000; + usbuff[ii] = (usbuff[ii]) ^ 0x8000; } } else { /* have to convert to int if using HCOMPRESS or PLIO */ @@ -2436,10 +2436,10 @@ int imcomp_convert_tile_tushort( /* reset pixels equal to flagval to nullval */ flagval = *(unsigned short *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (usbuff[ii] == (unsigned short) flagval) - idata[ii] = nullval; + if (usbuff[ii] == (unsigned short) flagval) + idata[ii] = nullval; else - idata[ii] = ((int) usbuff[ii]) - 32768; + idata[ii] = ((int) usbuff[ii]) - 32768; } } else { /* just do the data type conversion to int */ /* for HCOMPRESS we need to simply subtract 32768 */ @@ -2459,7 +2459,7 @@ int imcomp_convert_tile_tushort( /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tint( fitsfile *outfptr, - void *tiledata, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2473,31 +2473,31 @@ int imcomp_convert_tile_tint( /* Prepare the input tile array of pixels for compression. */ /* Convert input integer tile array in place to 4 or 8-byte ints for compression, */ /* If needed, do null value substitution. */ - + int flagval, *idata; long ii; - - + + /* datatype of input array is int. We only support writing this datatype to a FITS image with BITPIX = 32 and with BZERO = 0 and BSCALE = 1. */ if (zbitpix != LONG_IMG || scale != 1.0 || zero != 0.) { ffpmsg("Implicit datatype conversion is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } idata = (int *) tiledata; *intlength = 4; if (nullcheck == 1) { /* no datatype conversion is required for any of the compression algorithms, - except possibly for HCOMPRESS (to I*8), which is handled later. - Just reset pixels equal to flagval to the FITS null value */ + except possibly for HCOMPRESS (to I*8), which is handled later. + Just reset pixels equal to flagval to the FITS null value */ flagval = *(int *) (nullflagval); if (flagval != nullval) { for (ii = tilelen - 1; ii >= 0; ii--) { - if (idata[ii] == flagval) - idata[ii] = nullval; + if (idata[ii] == flagval) + idata[ii] = nullval; } } } @@ -2507,7 +2507,7 @@ int imcomp_convert_tile_tint( /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tuint( fitsfile *outfptr, - void *tiledata, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2526,14 +2526,14 @@ int imcomp_convert_tile_tuint( int *idata; unsigned int *uintbuff, uintflagval; long ii; - + /* datatype of input array is unsigned int. We only support writing this datatype to a FITS image with BITPIX = 32 and with BZERO = 0 and BSCALE = 2147483648. */ if (zbitpix != LONG_IMG || scale != 1.0 || zero != 2147483648.) { ffpmsg("Implicit datatype conversion is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } *intlength = 4; idata = (int *) tiledata; @@ -2547,15 +2547,15 @@ int imcomp_convert_tile_tuint( /* offset the other pixel values (by flipping the MSB) */ uintflagval = *(unsigned int *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (uintbuff[ii] == uintflagval) - idata[ii] = nullval; + if (uintbuff[ii] == uintflagval) + idata[ii] = nullval; else - uintbuff[ii] = (uintbuff[ii]) ^ 0x80000000; + uintbuff[ii] = (uintbuff[ii]) ^ 0x80000000; } } else { /* just offset the pixel values (by flipping the MSB) */ for (ii = tilelen - 1; ii >= 0; ii--) - uintbuff[ii] = (uintbuff[ii]) ^ 0x80000000; + uintbuff[ii] = (uintbuff[ii]) ^ 0x80000000; } return(*status); @@ -2563,7 +2563,7 @@ int imcomp_convert_tile_tuint( /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tbyte( fitsfile *outfptr, - void *tiledata, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2583,31 +2583,31 @@ int imcomp_convert_tile_tbyte( int flagval, *idata; long ii; unsigned char *usbbuff; - + /* datatype of input array is unsigned byte. We only support writing this datatype to a FITS image with BITPIX = 8 and with BZERO = 0 and BSCALE = 1. */ if (zbitpix != BYTE_IMG || scale != 1.0 || zero != 0.) { ffpmsg("Implicit datatype conversion is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } idata = (int *) tiledata; usbbuff = (unsigned char *) tiledata; if ( (outfptr->Fptr)->compress_type == RICE_1 || (outfptr->Fptr)->compress_type == GZIP_1 - || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1 ) + || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1 ) { /* don't have to convert to int if using gzip, bzip2, or Rice compression */ *intlength = 1; - + if (nullcheck == 1) { /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(unsigned char *) (nullflagval); if (flagval != nullval) { for (ii = tilelen - 1; ii >= 0; ii--) { - if (usbbuff[ii] == (unsigned char) flagval) - usbbuff[ii] = (unsigned char) nullval; + if (usbbuff[ii] == (unsigned char) flagval) + usbbuff[ii] = (unsigned char) nullval; } } } @@ -2619,8 +2619,8 @@ int imcomp_convert_tile_tbyte( /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(unsigned char *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (usbbuff[ii] == (unsigned char) flagval) - idata[ii] = nullval; + if (usbbuff[ii] == (unsigned char) flagval) + idata[ii] = nullval; else idata[ii] = (int) usbbuff[ii]; } @@ -2636,7 +2636,7 @@ int imcomp_convert_tile_tbyte( /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tsbyte( fitsfile *outfptr, - void *tiledata, + void *tiledata, long tilelen, int nullcheck, void *nullflagval, @@ -2669,24 +2669,24 @@ int imcomp_convert_tile_tsbyte( sbbuff = (signed char *) tiledata; if ( (outfptr->Fptr)->compress_type == RICE_1 || (outfptr->Fptr)->compress_type == GZIP_1 - || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1 ) + || (outfptr->Fptr)->compress_type == GZIP_2 || (outfptr->Fptr)->compress_type == BZIP2_1 ) { /* don't have to convert to int if using gzip, bzip2 or Rice compression */ *intlength = 1; - + if (nullcheck == 1) { /* reset pixels equal to flagval to the FITS null value, prior to compression */ /* offset the other pixel values (by flipping the MSB) */ flagval = *(signed char *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (sbbuff[ii] == (signed char) flagval) - sbbuff[ii] = (signed char) nullval; + if (sbbuff[ii] == (signed char) flagval) + sbbuff[ii] = (signed char) nullval; else - sbbuff[ii] = (sbbuff[ii]) ^ 0x80; } + sbbuff[ii] = (sbbuff[ii]) ^ 0x80; } } else { /* just offset the pixel values (by flipping the MSB) */ - for (ii = tilelen - 1; ii >= 0; ii--) - sbbuff[ii] = (sbbuff[ii]) ^ 0x80; + for (ii = tilelen - 1; ii >= 0; ii--) + sbbuff[ii] = (sbbuff[ii]) ^ 0x80; } } else { @@ -2697,8 +2697,8 @@ int imcomp_convert_tile_tsbyte( /* reset pixels equal to flagval to the FITS null value, prior to compression */ flagval = *(signed char *) (nullflagval); for (ii = tilelen - 1; ii >= 0; ii--) { - if (sbbuff[ii] == (signed char) flagval) - idata[ii] = nullval; + if (sbbuff[ii] == (signed char) flagval) + idata[ii] = nullval; else idata[ii] = ((int) sbbuff[ii]) + 128; } @@ -2708,14 +2708,14 @@ int imcomp_convert_tile_tsbyte( fits_sbyte_to_int_inplace(sbbuff, tilelen, status); } } - + return(*status); } /*--------------------------------------------------------------------------*/ int imcomp_convert_tile_tfloat( fitsfile *outfptr, long row, - void *tiledata, + void *tiledata, long tilelen, long tilenx, long tileny, @@ -2746,12 +2746,12 @@ int imcomp_convert_tile_tfloat( /* datatype of input array is double. We only support writing this datatype to a FITS image with BITPIX = -64 or -32, except we also support the special case where - BITPIX = 32 and BZERO = 0 and BSCALE = 1. */ + BITPIX = 32 and BZERO = 0 and BSCALE = 1. */ if ((zbitpix != LONG_IMG && zbitpix != DOUBLE_IMG && zbitpix != FLOAT_IMG) || scale != 1.0 || zero != 0.) { ffpmsg("Implicit datatype conversion is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } *intlength = 4; idata = (int *) tiledata; @@ -2760,62 +2760,62 @@ int imcomp_convert_tile_tfloat( /* then scale and quantize the input floating point data. */ if ((outfptr->Fptr)->cn_zscale > 0) { - /* quantize the float values into integers */ + /* quantize the float values into integers */ if (nullcheck == 1) - floatnull = *(float *) (nullflagval); - else - floatnull = FLOATNULLVALUE; /* NaNs are represented by this, by default */ + floatnull = *(float *) (nullflagval); + else + floatnull = FLOATNULLVALUE; /* NaNs are represented by this, by default */ if ((outfptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_1 || - (outfptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { - - /* see if the dithering offset value needs to be initialized */ - if ((outfptr->Fptr)->request_dither_seed == 0 && (outfptr->Fptr)->dither_seed == 0) { - - /* This means randomly choose the dithering offset based on the system time. */ - /* The offset will have a value between 1 and 10000, inclusive. */ - /* The time function returns an integer value that is incremented each second. */ - /* The clock function returns the elapsed CPU time, in integer CLOCKS_PER_SEC units. */ - /* The CPU time returned by clock is typically (on linux PC) only good to 0.01 sec */ - /* Summing the 2 quantities may help avoid cases where 2 executions of the program */ - /* (perhaps in a multithreaded environoment) end up with exactly the same dither seed */ - /* value. The sum is incremented by the current HDU number in the file to provide */ - /* further randomization. This randomization is desireable if multiple compressed */ - /* images will be summed (or differenced). In such cases, the benefits of dithering */ - /* may be lost if all the images use exactly the same sequence of random numbers when */ - /* calculating the dithering offsets. */ - - (outfptr->Fptr)->dither_seed = - (( (int)time(NULL) + ( (int) clock() / (int) (CLOCKS_PER_SEC / 100)) + (outfptr->Fptr)->curhdu) % 10000) + 1; - + (outfptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { + + /* see if the dithering offset value needs to be initialized */ + if ((outfptr->Fptr)->request_dither_seed == 0 && (outfptr->Fptr)->dither_seed == 0) { + + /* This means randomly choose the dithering offset based on the system time. */ + /* The offset will have a value between 1 and 10000, inclusive. */ + /* The time function returns an integer value that is incremented each second. */ + /* The clock function returns the elapsed CPU time, in integer CLOCKS_PER_SEC units. */ + /* The CPU time returned by clock is typically (on linux PC) only good to 0.01 sec */ + /* Summing the 2 quantities may help avoid cases where 2 executions of the program */ + /* (perhaps in a multithreaded environoment) end up with exactly the same dither seed */ + /* value. The sum is incremented by the current HDU number in the file to provide */ + /* further randomization. This randomization is desireable if multiple compressed */ + /* images will be summed (or differenced). In such cases, the benefits of dithering */ + /* may be lost if all the images use exactly the same sequence of random numbers when */ + /* calculating the dithering offsets. */ + + (outfptr->Fptr)->dither_seed = + (( (int)time(NULL) + ( (int) clock() / (int) (CLOCKS_PER_SEC / 100)) + (outfptr->Fptr)->curhdu) % 10000) + 1; + /* update the header keyword with this new value */ - fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), - NULL, status); + fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), + NULL, status); - } else if ((outfptr->Fptr)->request_dither_seed < 0 && (outfptr->Fptr)->dither_seed < 0) { + } else if ((outfptr->Fptr)->request_dither_seed < 0 && (outfptr->Fptr)->dither_seed < 0) { - /* this means randomly choose the dithering offset based on some hash function */ - /* of the first input tile of data to be quantized and compressed. This ensures that */ + /* this means randomly choose the dithering offset based on some hash function */ + /* of the first input tile of data to be quantized and compressed. This ensures that */ /* the same offset value is used for a given image every time it is compressed. */ - usbbuff = (unsigned char *) tiledata; - dithersum = 0; - for (ii = 0; ii < 4 * tilelen; ii++) { - dithersum += usbbuff[ii]; /* doesn't matter if there is an integer overflow */ - } - (outfptr->Fptr)->dither_seed = ((int) (dithersum % 10000)) + 1; - + usbbuff = (unsigned char *) tiledata; + dithersum = 0; + for (ii = 0; ii < 4 * tilelen; ii++) { + dithersum += usbbuff[ii]; /* doesn't matter if there is an integer overflow */ + } + (outfptr->Fptr)->dither_seed = ((int) (dithersum % 10000)) + 1; + /* update the header keyword with this new value */ - fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), - NULL, status); - } + fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), + NULL, status); + } /* subtract 1 to convert from 1-based to 0-based element number */ - irow = row + (outfptr->Fptr)->dither_seed - 1; /* dither the quantized values */ + irow = row + (outfptr->Fptr)->dither_seed - 1; /* dither the quantized values */ - } else if ((outfptr->Fptr)->quantize_method == -1) { - irow = 0; /* do not dither the quantized values */ + } else if ((outfptr->Fptr)->quantize_method == -1) { + irow = 0; /* do not dither the quantized values */ } else { ffpmsg("Unknown dithering method."); ffpmsg("May need to install a newer version of CFITSIO."); @@ -2823,30 +2823,30 @@ int imcomp_convert_tile_tfloat( } *flag = fits_quantize_float (irow, (float *) tiledata, tilenx, tileny, - nullcheck, floatnull, (outfptr->Fptr)->quantize_level, - (outfptr->Fptr)->quantize_method, idata, bscale, bzero, &iminval, &imaxval); + nullcheck, floatnull, (outfptr->Fptr)->quantize_level, + (outfptr->Fptr)->quantize_method, idata, bscale, bzero, &iminval, &imaxval); if (*flag > 1) - return(*status = *flag); + return(*status = *flag); } else if ((outfptr->Fptr)->quantize_level != NO_QUANTIZE) - { - /* if floating point pixels are not being losslessly compressed, then */ - /* input float data is implicitly converted (truncated) to integers */ + { + /* if floating point pixels are not being losslessly compressed, then */ + /* input float data is implicitly converted (truncated) to integers */ if ((scale != 1. || zero != 0.)) /* must scale the values */ - imcomp_nullscalefloats((float *) tiledata, tilelen, idata, scale, zero, - nullcheck, *(float *) (nullflagval), nullval, status); + imcomp_nullscalefloats((float *) tiledata, tilelen, idata, scale, zero, + nullcheck, *(float *) (nullflagval), nullval, status); else - imcomp_nullfloats((float *) tiledata, tilelen, idata, - nullcheck, *(float *) (nullflagval), nullval, status); + imcomp_nullfloats((float *) tiledata, tilelen, idata, + nullcheck, *(float *) (nullflagval), nullval, status); } else if ((outfptr->Fptr)->quantize_level == NO_QUANTIZE) - { - /* just convert null values to NaNs in place, if necessary, then do lossless gzip compression */ - if (nullcheck == 1) { - imcomp_float2nan((float *) tiledata, tilelen, (int *) tiledata, - *(float *) (nullflagval), status); - } + { + /* just convert null values to NaNs in place, if necessary, then do lossless gzip compression */ + if (nullcheck == 1) { + imcomp_float2nan((float *) tiledata, tilelen, (int *) tiledata, + *(float *) (nullflagval), status); + } } return(*status); @@ -2855,7 +2855,7 @@ int imcomp_convert_tile_tfloat( int imcomp_convert_tile_tdouble( fitsfile *outfptr, long row, - void *tiledata, + void *tiledata, long tilelen, long tilenx, long tileny, @@ -2886,12 +2886,12 @@ int imcomp_convert_tile_tdouble( /* datatype of input array is double. We only support writing this datatype to a FITS image with BITPIX = -64 or -32, except we also support the special case where - BITPIX = 32 and BZERO = 0 and BSCALE = 1. */ + BITPIX = 32 and BZERO = 0 and BSCALE = 1. */ if ((zbitpix != LONG_IMG && zbitpix != DOUBLE_IMG && zbitpix != FLOAT_IMG) || scale != 1.0 || zero != 0.) { ffpmsg("Implicit datatype conversion is not supported when writing to compressed images"); return(*status = DATA_COMPRESSION_ERR); - } + } *intlength = 4; idata = (int *) tiledata; @@ -2903,42 +2903,42 @@ int imcomp_convert_tile_tdouble( if ((outfptr->Fptr)->cn_zscale > 0) { if (nullcheck == 1) - doublenull = *(double *) (nullflagval); - else - doublenull = DOUBLENULLVALUE; + doublenull = *(double *) (nullflagval); + else + doublenull = DOUBLENULLVALUE; /* quantize the double values into integers */ if ((outfptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_1 || - (outfptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { + (outfptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { - /* see if the dithering offset value needs to be initialized (see above) */ - if ((outfptr->Fptr)->request_dither_seed == 0 && (outfptr->Fptr)->dither_seed == 0) { + /* see if the dithering offset value needs to be initialized (see above) */ + if ((outfptr->Fptr)->request_dither_seed == 0 && (outfptr->Fptr)->dither_seed == 0) { + + (outfptr->Fptr)->dither_seed = + (( (int)time(NULL) + ( (int) clock() / (int) (CLOCKS_PER_SEC / 100)) + (outfptr->Fptr)->curhdu) % 10000) + 1; - (outfptr->Fptr)->dither_seed = - (( (int)time(NULL) + ( (int) clock() / (int) (CLOCKS_PER_SEC / 100)) + (outfptr->Fptr)->curhdu) % 10000) + 1; - /* update the header keyword with this new value */ - fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), - NULL, status); - - } else if ((outfptr->Fptr)->request_dither_seed < 0 && (outfptr->Fptr)->dither_seed < 0) { - - usbbuff = (unsigned char *) tiledata; - dithersum = 0; - for (ii = 0; ii < 8 * tilelen; ii++) { - dithersum += usbbuff[ii]; - } - (outfptr->Fptr)->dither_seed = ((int) (dithersum % 10000)) + 1; - + fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), + NULL, status); + + } else if ((outfptr->Fptr)->request_dither_seed < 0 && (outfptr->Fptr)->dither_seed < 0) { + + usbbuff = (unsigned char *) tiledata; + dithersum = 0; + for (ii = 0; ii < 8 * tilelen; ii++) { + dithersum += usbbuff[ii]; + } + (outfptr->Fptr)->dither_seed = ((int) (dithersum % 10000)) + 1; + /* update the header keyword with this new value */ - fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), - NULL, status); - } + fits_update_key(outfptr, TINT, "ZDITHER0", &((outfptr->Fptr)->dither_seed), + NULL, status); + } - irow = row + (outfptr->Fptr)->dither_seed - 1; /* dither the quantized values */ + irow = row + (outfptr->Fptr)->dither_seed - 1; /* dither the quantized values */ - } else if ((outfptr->Fptr)->quantize_method == -1) { - irow = 0; /* do not dither the quantized values */ + } else if ((outfptr->Fptr)->quantize_method == -1) { + irow = 0; /* do not dither the quantized values */ } else { ffpmsg("Unknown subtractive dithering method."); ffpmsg("May need to install a newer version of CFITSIO."); @@ -2946,38 +2946,38 @@ int imcomp_convert_tile_tdouble( } *flag = fits_quantize_double (irow, (double *) tiledata, tilenx, tileny, - nullcheck, doublenull, (outfptr->Fptr)->quantize_level, - (outfptr->Fptr)->quantize_method, idata, + nullcheck, doublenull, (outfptr->Fptr)->quantize_level, + (outfptr->Fptr)->quantize_method, idata, bscale, bzero, &iminval, &imaxval); if (*flag > 1) - return(*status = *flag); + return(*status = *flag); } else if ((outfptr->Fptr)->quantize_level != NO_QUANTIZE) - { - /* if floating point pixels are not being losslessly compressed, then */ - /* input float data is implicitly converted (truncated) to integers */ + { + /* if floating point pixels are not being losslessly compressed, then */ + /* input float data is implicitly converted (truncated) to integers */ if ((scale != 1. || zero != 0.)) /* must scale the values */ - imcomp_nullscaledoubles((double *) tiledata, tilelen, idata, scale, zero, - nullcheck, *(double *) (nullflagval), nullval, status); + imcomp_nullscaledoubles((double *) tiledata, tilelen, idata, scale, zero, + nullcheck, *(double *) (nullflagval), nullval, status); else - imcomp_nulldoubles((double *) tiledata, tilelen, idata, - nullcheck, *(double *) (nullflagval), nullval, status); + imcomp_nulldoubles((double *) tiledata, tilelen, idata, + nullcheck, *(double *) (nullflagval), nullval, status); } else if ((outfptr->Fptr)->quantize_level == NO_QUANTIZE) - { - /* just convert null values to NaNs in place, if necessary, then do lossless gzip compression */ - if (nullcheck == 1) { - imcomp_double2nan((double *) tiledata, tilelen, (LONGLONG *) tiledata, - *(double *) (nullflagval), status); - } + { + /* just convert null values to NaNs in place, if necessary, then do lossless gzip compression */ + if (nullcheck == 1) { + imcomp_double2nan((double *) tiledata, tilelen, (LONGLONG *) tiledata, + *(double *) (nullflagval), status); + } } - + return(*status); } /*---------------------------------------------------------------------------*/ int imcomp_nullscale( - int *idata, + int *idata, long tilelen, int nullflagval, int nullval, @@ -2992,13 +2992,13 @@ int imcomp_nullscale( { long ii; double dvalue; - + for (ii=0; ii < tilelen; ii++) { if (idata[ii] == nullflagval) - idata[ii] = nullval; - else - { + idata[ii] = nullval; + else + { dvalue = (idata[ii] - zero) / scale; if (dvalue < DINT_MIN) @@ -3024,7 +3024,7 @@ int imcomp_nullscale( } /*---------------------------------------------------------------------------*/ int imcomp_nullvalues( - int *idata, + int *idata, long tilelen, int nullflagval, int nullval, @@ -3035,17 +3035,17 @@ int imcomp_nullvalues( */ { long ii; - + for (ii=0; ii < tilelen; ii++) { if (idata[ii] == nullflagval) - idata[ii] = nullval; + idata[ii] = nullval; } return(*status); } /*---------------------------------------------------------------------------*/ int imcomp_scalevalues( - int *idata, + int *idata, long tilelen, double scale, double zero, @@ -3056,7 +3056,7 @@ int imcomp_scalevalues( { long ii; double dvalue; - + for (ii=0; ii < tilelen; ii++) { dvalue = (idata[ii] - zero) / scale; @@ -3083,7 +3083,7 @@ int imcomp_scalevalues( } /*---------------------------------------------------------------------------*/ int imcomp_nullscalei2( - short *idata, + short *idata, long tilelen, short nullflagval, short nullval, @@ -3098,13 +3098,13 @@ int imcomp_nullscalei2( { long ii; double dvalue; - + for (ii=0; ii < tilelen; ii++) { if (idata[ii] == nullflagval) - idata[ii] = nullval; - else - { + idata[ii] = nullval; + else + { dvalue = (idata[ii] - zero) / scale; if (dvalue < DSHRT_MIN) @@ -3130,7 +3130,7 @@ int imcomp_nullscalei2( } /*---------------------------------------------------------------------------*/ int imcomp_nullvaluesi2( - short *idata, + short *idata, long tilelen, short nullflagval, short nullval, @@ -3141,17 +3141,17 @@ int imcomp_nullvaluesi2( */ { long ii; - + for (ii=0; ii < tilelen; ii++) { if (idata[ii] == nullflagval) - idata[ii] = nullval; + idata[ii] = nullval; } return(*status); } /*---------------------------------------------------------------------------*/ int imcomp_scalevaluesi2( - short *idata, + short *idata, long tilelen, double scale, double zero, @@ -3162,7 +3162,7 @@ int imcomp_scalevaluesi2( { long ii; double dvalue; - + for (ii=0; ii < tilelen; ii++) { dvalue = (idata[ii] - zero) / scale; @@ -3191,7 +3191,7 @@ int imcomp_scalevaluesi2( int imcomp_nullfloats( float *fdata, long tilelen, - int *idata, + int *idata, int nullcheck, float nullflagval, int nullval, @@ -3203,15 +3203,15 @@ int imcomp_nullfloats( { long ii; double dvalue; - + if (nullcheck == 1) /* must check for null values */ { for (ii=0; ii < tilelen; ii++) { if (fdata[ii] == nullflagval) - idata[ii] = nullval; - else - { + idata[ii] = nullval; + else + { dvalue = fdata[ii]; if (dvalue < DINT_MIN) @@ -3265,7 +3265,7 @@ int imcomp_nullfloats( int imcomp_nullscalefloats( float *fdata, long tilelen, - int *idata, + int *idata, double scale, double zero, int nullcheck, @@ -3280,15 +3280,15 @@ int imcomp_nullscalefloats( { long ii; double dvalue; - + if (nullcheck == 1) /* must check for null values */ { for (ii=0; ii < tilelen; ii++) { if (fdata[ii] == nullflagval) - idata[ii] = nullval; - else - { + idata[ii] = nullval; + else + { dvalue = (fdata[ii] - zero) / scale; if (dvalue < DINT_MIN) @@ -3342,7 +3342,7 @@ int imcomp_nullscalefloats( int imcomp_nulldoubles( double *fdata, long tilelen, - int *idata, + int *idata, int nullcheck, double nullflagval, int nullval, @@ -3355,15 +3355,15 @@ int imcomp_nulldoubles( { long ii; double dvalue; - + if (nullcheck == 1) /* must check for null values */ { for (ii=0; ii < tilelen; ii++) { if (fdata[ii] == nullflagval) - idata[ii] = nullval; - else - { + idata[ii] = nullval; + else + { dvalue = fdata[ii]; if (dvalue < DINT_MIN) @@ -3417,7 +3417,7 @@ int imcomp_nulldoubles( int imcomp_nullscaledoubles( double *fdata, long tilelen, - int *idata, + int *idata, double scale, double zero, int nullcheck, @@ -3432,15 +3432,15 @@ int imcomp_nullscaledoubles( { long ii; double dvalue; - + if (nullcheck == 1) /* must check for null values */ { for (ii=0; ii < tilelen; ii++) { if (fdata[ii] == nullflagval) - idata[ii] = nullval; - else - { + idata[ii] = nullval; + else + { dvalue = (fdata[ii] - zero) / scale; if (dvalue < DINT_MIN) @@ -3519,7 +3519,7 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ void *buffer; char *bnullarray = 0, card[FLEN_CARD]; - if (*status > 0) + if (*status > 0) return(*status); if (!fits_is_compressed_image(fptr, status) ) @@ -3534,7 +3534,7 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ /* rescan header if data structure is undefined */ else if ((fptr->Fptr)->datastart == DATA_UNDEFINED) - if ( ffrdef(fptr, status) > 0) + if ( ffrdef(fptr, status) > 0) return(*status); @@ -3575,13 +3575,13 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ /* allocate scratch space for processing one tile of the image */ buffpixsiz = pixlen; /* this is the minimum pixel size */ - + if ( (fptr->Fptr)->compress_type == HCOMPRESS_1) { /* need 4 or 8 bytes per pixel */ if ((fptr->Fptr)->zbitpix == BYTE_IMG || - (fptr->Fptr)->zbitpix == SHORT_IMG ) + (fptr->Fptr)->zbitpix == SHORT_IMG ) buffpixsiz = maxvalue(buffpixsiz, 4); else - buffpixsiz = 8; + buffpixsiz = 8; } else if ( (fptr->Fptr)->compress_type == PLIO_1) { /* need 4 bytes per pixel */ buffpixsiz = maxvalue(buffpixsiz, 4); @@ -3594,7 +3594,7 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ buffpixsiz = maxvalue(buffpixsiz, 1); else if ((fptr->Fptr)->zbitpix == SHORT_IMG) buffpixsiz = maxvalue(buffpixsiz, 2); - else + else buffpixsiz = maxvalue(buffpixsiz, 4); } else @@ -3602,14 +3602,14 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ ffpmsg("unsupported image compression algorithm"); return(*status = BAD_DATATYPE); } - + /* cast to double to force alignment on 8-byte addresses */ buffer = (double *) calloc ((fptr->Fptr)->maxtilelen, buffpixsiz); if (buffer == NULL) { - ffpmsg("Out of memory (fits_write_compress_img)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory (fits_write_compress_img)"); + return (*status = MEMORY_ALLOCATION); } /* ===================================================================== */ @@ -3644,7 +3644,7 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ tilesize[ii] = (fptr->Fptr)->tilesize[ii]; tiledim[ii] = (naxis[ii] - 1) / tilesize[ii] + 1; ftile[ii] = (fpixel[ii] - 1) / tilesize[ii] + 1; - ltile[ii] = minvalue((lpixel[ii] - 1) / tilesize[ii] + 1, + ltile[ii] = minvalue((lpixel[ii] - 1) / tilesize[ii] + 1, tiledim[ii]); rowdim[ii] = ntemp; /* total tiles in each dimension */ ntemp *= tiledim[ii]; @@ -3656,42 +3656,42 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ for (i5 = ftile[5]; i5 <= ltile[5]; i5++) { tfpixel[5] = (i5 - 1) * tilesize[5] + 1; - tlpixel[5] = minvalue(tfpixel[5] + tilesize[5] - 1, + tlpixel[5] = minvalue(tfpixel[5] + tilesize[5] - 1, naxis[5]); thistilesize[5] = tlpixel[5] - tfpixel[5] + 1; offset[5] = (i5 - 1) * rowdim[5]; for (i4 = ftile[4]; i4 <= ltile[4]; i4++) { tfpixel[4] = (i4 - 1) * tilesize[4] + 1; - tlpixel[4] = minvalue(tfpixel[4] + tilesize[4] - 1, + tlpixel[4] = minvalue(tfpixel[4] + tilesize[4] - 1, naxis[4]); thistilesize[4] = thistilesize[5] * (tlpixel[4] - tfpixel[4] + 1); offset[4] = (i4 - 1) * rowdim[4] + offset[5]; for (i3 = ftile[3]; i3 <= ltile[3]; i3++) { tfpixel[3] = (i3 - 1) * tilesize[3] + 1; - tlpixel[3] = minvalue(tfpixel[3] + tilesize[3] - 1, + tlpixel[3] = minvalue(tfpixel[3] + tilesize[3] - 1, naxis[3]); thistilesize[3] = thistilesize[4] * (tlpixel[3] - tfpixel[3] + 1); offset[3] = (i3 - 1) * rowdim[3] + offset[4]; for (i2 = ftile[2]; i2 <= ltile[2]; i2++) { tfpixel[2] = (i2 - 1) * tilesize[2] + 1; - tlpixel[2] = minvalue(tfpixel[2] + tilesize[2] - 1, + tlpixel[2] = minvalue(tfpixel[2] + tilesize[2] - 1, naxis[2]); thistilesize[2] = thistilesize[3] * (tlpixel[2] - tfpixel[2] + 1); offset[2] = (i2 - 1) * rowdim[2] + offset[3]; for (i1 = ftile[1]; i1 <= ltile[1]; i1++) { tfpixel[1] = (i1 - 1) * tilesize[1] + 1; - tlpixel[1] = minvalue(tfpixel[1] + tilesize[1] - 1, + tlpixel[1] = minvalue(tfpixel[1] + tilesize[1] - 1, naxis[1]); thistilesize[1] = thistilesize[2] * (tlpixel[1] - tfpixel[1] + 1); offset[1] = (i1 - 1) * rowdim[1] + offset[2]; for (i0 = ftile[0]; i0 <= ltile[0]; i0++) { tfpixel[0] = (i0 - 1) * tilesize[0] + 1; - tlpixel[0] = minvalue(tfpixel[0] + tilesize[0] - 1, + tlpixel[0] = minvalue(tfpixel[0] + tilesize[0] - 1, naxis[0]); thistilesize[0] = thistilesize[1] * (tlpixel[0] - tfpixel[0] + 1); /* calculate row of table containing this tile */ @@ -3712,9 +3712,9 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ } /* copy the intersecting pixels to this tile from the input */ - imcomp_merge_overlap(buffer, pixlen, ndim, tfpixel, tlpixel, + imcomp_merge_overlap(buffer, pixlen, ndim, tfpixel, tlpixel, bnullarray, array, fpixel, lpixel, nullcheck, status); - + /* Collapse sizes of higher dimension tiles into 2 dimensional equivalents needed by the quantizing algorithms for floating point types */ @@ -3722,12 +3722,12 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ &ntrows, status); /* compress the tile again, and write it back to the FITS file */ - imcomp_compress_tile (fptr, irow, datatype, buffer, + imcomp_compress_tile (fptr, irow, datatype, buffer, thistilesize[0], - trowsize, - ntrows, - nullcheck, nullval, - status); + trowsize, + ntrows, + nullcheck, nullval, + status); } } } @@ -3735,32 +3735,32 @@ int fits_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ } } free(buffer); - - if ((fptr->Fptr)->zbitpix < 0 && nullcheck != 0) { + + if ((fptr->Fptr)->zbitpix < 0 && nullcheck != 0) { /* This is a floating point FITS image with possible null values. - It is too messy to test if any null values are actually written, so + It is too messy to test if any null values are actually written, so just assume so. We need to make sure that the ZBLANK keyword is present in the compressed image header. If it is not - there then we need to insert the keyword. -*/ + there then we need to insert the keyword. +*/ tstatus = 0; ffgcrd(fptr, "ZBLANK", card, &tstatus); - if (tstatus) { /* have to insert the ZBLANK keyword */ + if (tstatus) { /* have to insert the ZBLANK keyword */ ffgcrd(fptr, "ZCMPTYPE", card, status); - ffikyj(fptr, "ZBLANK", COMPRESS_NULL_VALUE, + ffikyj(fptr, "ZBLANK", COMPRESS_NULL_VALUE, "null value in the compressed integer array", status); - + /* set this value into the internal structure; it is used if */ - /* the program reads back the values from the array */ - + /* the program reads back the values from the array */ + (fptr->Fptr)->zblank = COMPRESS_NULL_VALUE; (fptr->Fptr)->cn_zblank = -1; /* flag for a constant ZBLANK */ - } - } - + } + } + return(*status); } /*--------------------------------------------------------------------------*/ @@ -3777,13 +3777,13 @@ int fits_write_compressed_pixels(fitsfile *fptr, /* I - FITS file pointer */ int *status) /* IO - error status */ /* Write a consecutive set of pixels to a compressed image. This routine - interpretes the n-dimensional image as a long one-dimensional array. + interpretes the n-dimensional image as a long one-dimensional array. This is actually a rather inconvenient way to write compressed images in general, and could be rather inefficient if the requested pixels to be - written are located in many different image compression tiles. + written are located in many different image compression tiles. The general strategy used here is to write the requested pixels in blocks - that correspond to rectangular image sections. + that correspond to rectangular image sections. */ { int naxis, ii, bytesperpixel; @@ -3931,7 +3931,7 @@ int fits_write_compressed_img_plane(fitsfile *fptr, /* I - FITS file */ */ { /* bottom left coord. and top right coord. */ - long blc[MAX_COMPRESS_DIM], trc[MAX_COMPRESS_DIM]; + long blc[MAX_COMPRESS_DIM], trc[MAX_COMPRESS_DIM]; char *arrayptr; *nread = 0; @@ -3942,11 +3942,11 @@ int fits_write_compressed_img_plane(fitsfile *fptr, /* I - FITS file */ trc[2] = nplane + 1; if (firstcoord[0] != 0) - { + { /* have to read a partial first row */ blc[0] = firstcoord[0] + 1; blc[1] = firstcoord[1] + 1; - trc[1] = blc[1]; + trc[1] = blc[1]; if (lastcoord[1] == firstcoord[1]) trc[0] = lastcoord[0] + 1; /* 1st and last pixels in same row */ else @@ -4025,7 +4025,7 @@ int fits_img_decompress (fitsfile *infptr, /* image (bintable) to uncompress */ fitsfile *outfptr, /* empty HDU for output uncompressed image */ int *status) /* IO - error status */ -/* +/* This routine decompresses the whole image and writes it to the output file. */ @@ -4040,7 +4040,7 @@ int fits_img_decompress (fitsfile *infptr, /* image (bintable) to uncompress */ if (fits_img_decompress_header(infptr, outfptr, status) > 0) { - return (*status); + return (*status); } /* force a rescan of the output header keywords, then reset the scaling */ @@ -4096,7 +4096,7 @@ int fits_img_decompress (fitsfile *infptr, /* image (bintable) to uncompress */ /* uncompress the input image and write to output image, one tile at a time */ - fits_read_write_compressed_img(infptr, datatype, fpixel, lpixel, inc, + fits_read_write_compressed_img(infptr, datatype, fpixel, lpixel, inc, nullcheck, nulladdr, &anynul, outfptr, status); return (*status); @@ -4106,9 +4106,9 @@ int fits_decompress_img (fitsfile *infptr, /* image (bintable) to uncompress */ fitsfile *outfptr, /* empty HDU for output uncompressed image */ int *status) /* IO - error status */ -/* +/* THIS IS AN OBSOLETE ROUTINE. USE fits_img_decompress instead!!! - + This routine decompresses the whole image and writes it to the output file. */ @@ -4132,17 +4132,17 @@ int fits_decompress_img (fitsfile *infptr, /* image (bintable) to uncompress */ } /* create an empty output image with the correct dimensions */ - if (ffcrim(outfptr, (infptr->Fptr)->zbitpix, (infptr->Fptr)->zndim, + if (ffcrim(outfptr, (infptr->Fptr)->zbitpix, (infptr->Fptr)->zndim, (infptr->Fptr)->znaxis, status) > 0) { ffpmsg("error creating output decompressed image HDU"); - return (*status); + return (*status); } /* Copy the table header to the image header. */ if (imcomp_copy_imheader(infptr, outfptr, status) > 0) { ffpmsg("error copying header of compressed image"); - return (*status); + return (*status); } /* force a rescan of the output header keywords, then reset the scaling */ @@ -4207,7 +4207,7 @@ int fits_decompress_img (fitsfile *infptr, /* image (bintable) to uncompress */ /* allocate memory for the image */ data = (double*) calloc (memsize, sizeof(double)); if (!data) - { + { ffpmsg("Couldn't allocate memory for the uncompressed image"); return(*status = MEMORY_ALLOCATION); } @@ -4215,12 +4215,12 @@ int fits_decompress_img (fitsfile *infptr, /* image (bintable) to uncompress */ /* uncompress the entire image into memory */ /* This routine should be enhanced sometime to only need enough */ /* memory to uncompress one tile at a time. */ - fits_read_compressed_img(infptr, datatype, fpixel, lpixel, inc, + fits_read_compressed_img(infptr, datatype, fpixel, lpixel, inc, nullcheck, nulladdr, data, NULL, &anynul, status); /* write the image to the output file */ if (anynul) - fits_write_imgnull(outfptr, datatype, 1, imgsize, data, nulladdr, + fits_write_imgnull(outfptr, datatype, 1, imgsize, data, nulladdr, status); else fits_write_img(outfptr, datatype, 1, imgsize, data, status); @@ -4233,8 +4233,8 @@ int fits_img_decompress_header(fitsfile *infptr, /* image (bintable) to uncompre fitsfile *outfptr, /* empty HDU for output uncompressed image */ int *status) /* IO - error status */ -/* - This routine reads the header of the input tile compressed image and +/* + This routine reads the header of the input tile compressed image and converts it to that of a standard uncompress FITS image. */ @@ -4250,7 +4250,7 @@ int fits_img_decompress_header(fitsfile *infptr, /* image (bintable) to uncompre return(*status); else if (*status == -1) { *status = 0; - writeprime = 1; + writeprime = 1; } if (!fits_is_compressed_image(infptr, status) ) @@ -4267,34 +4267,34 @@ int fits_img_decompress_header(fitsfile *infptr, /* image (bintable) to uncompre /* Was the input compressed HDU originally the primary array image? */ tstatus = 0; - if (!fits_read_card(infptr, "ZSIMPLE", card, &tstatus)) { + if (!fits_read_card(infptr, "ZSIMPLE", card, &tstatus)) { /* yes, input HDU was a primary array (not an IMAGE extension) */ /* Now determine if we can uncompress it into the primary array of */ /* the output file. This is only possible if the output file */ /* currently only contains a null primary array, with no addition */ /* header keywords and with no following extension in the FITS file. */ - + if (hdupos == 1) { /* are we positioned at the primary array? */ if (numkeys == 0) { /* primary HDU is completely empty */ - nullprime = 1; + nullprime = 1; } else { fits_get_img_param(outfptr, MAX_COMPRESS_DIM, &bitpix, &naxis, naxes, status); - - if (naxis == 0) { /* is this a null image? */ + + if (naxis == 0) { /* is this a null image? */ nullprime = 1; - if (inhdupos == 2) /* must be at the first extension */ - copyprime = 1; - } + if (inhdupos == 2) /* must be at the first extension */ + copyprime = 1; + } } } - } + } - if (nullprime) { + if (nullprime) { /* We will delete the existing keywords in the null primary array and uncompress the input image into the primary array of the output. - Some of these keywords may be added back to the uncompressed image - header later. + Some of these keywords may be added back to the uncompressed image + header later. */ for (ii = numkeys; ii > 0; ii--) @@ -4302,59 +4302,59 @@ int fits_img_decompress_header(fitsfile *infptr, /* image (bintable) to uncompre } else { - /* if the ZTENSION keyword doesn't exist, then we have to + /* if the ZTENSION keyword doesn't exist, then we have to write the required keywords manually */ tstatus = 0; if (fits_read_card(infptr, "ZTENSION", card, &tstatus)) { /* create an empty output image with the correct dimensions */ - if (ffcrim(outfptr, (infptr->Fptr)->zbitpix, (infptr->Fptr)->zndim, + if (ffcrim(outfptr, (infptr->Fptr)->zbitpix, (infptr->Fptr)->zndim, (infptr->Fptr)->znaxis, status) > 0) { ffpmsg("error creating output decompressed image HDU"); - return (*status); + return (*status); } - norec = 1; /* the required keywords have already been written */ + norec = 1; /* the required keywords have already been written */ } else { /* the input compressed image does have ZTENSION keyword */ - + if (writeprime) { /* convert the image extension to a primary array */ - /* have to write the required keywords manually */ + /* have to write the required keywords manually */ /* create an empty output image with the correct dimensions */ - if (ffcrim(outfptr, (infptr->Fptr)->zbitpix, (infptr->Fptr)->zndim, + if (ffcrim(outfptr, (infptr->Fptr)->zbitpix, (infptr->Fptr)->zndim, (infptr->Fptr)->znaxis, status) > 0) { ffpmsg("error creating output decompressed image HDU"); - return (*status); + return (*status); } - norec = 1; /* the required keywords have already been written */ + norec = 1; /* the required keywords have already been written */ } else { /* write the input compressed image to an image extension */ if (numkeys == 0) { /* the output file is currently completely empty */ - - /* In this case, the input is a compressed IMAGE extension. */ - /* Since the uncompressed output file is currently completely empty, */ - /* we need to write a null primary array before uncompressing the */ + + /* In this case, the input is a compressed IMAGE extension. */ + /* Since the uncompressed output file is currently completely empty, */ + /* we need to write a null primary array before uncompressing the */ /* image extension */ - + ffcrim(outfptr, 8, 0, naxes, status); /* naxes is not used */ - - /* now create the empty extension to uncompress into */ + + /* now create the empty extension to uncompress into */ if (fits_create_hdu(outfptr, status) > 0) { ffpmsg("error creating output decompressed image HDU"); - return (*status); + return (*status); } - - } else { + + } else { /* just create a new empty extension, then copy all the required */ - /* keywords into it. */ + /* keywords into it. */ fits_create_hdu(outfptr, status); - } + } } } @@ -4362,7 +4362,7 @@ int fits_img_decompress_header(fitsfile *infptr, /* image (bintable) to uncompre if (*status > 0) { ffpmsg("error creating output decompressed image HDU"); - return (*status); + return (*status); } /* Copy the table header to the image header. */ @@ -4372,16 +4372,16 @@ int fits_img_decompress_header(fitsfile *infptr, /* image (bintable) to uncompre ffpmsg("error copying header keywords from compressed image"); } - if (copyprime) { - /* append any unexpected keywords from the primary array. - This includes any keywords except SIMPLE, BITPIX, NAXIS, - EXTEND, COMMENT, HISTORY, CHECKSUM, and DATASUM. - */ + if (copyprime) { + /* append any unexpected keywords from the primary array. + This includes any keywords except SIMPLE, BITPIX, NAXIS, + EXTEND, COMMENT, HISTORY, CHECKSUM, and DATASUM. + */ fits_movabs_hdu(infptr, 1, NULL, status); /* move to primary array */ - + /* do this so that any new keywords get written before any blank - keywords that may have been appended by imcomp_copy_comp2img */ + keywords that may have been appended by imcomp_copy_comp2img */ fits_set_hdustruc(outfptr, status); if (imcomp_copy_prime2img(infptr, outfptr, status) > 0) @@ -4409,7 +4409,7 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ int *anynul, /* O - set to 1 if any values are null; else 0 */ int *status) /* IO - error status */ /* - Read a section of a compressed image; Note: lpixel may be larger than the + Read a section of a compressed image; Note: lpixel may be larger than the size of the uncompressed image. Only the pixels within the image will be returned. */ @@ -4427,7 +4427,7 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ char *bnullarray = 0; double testnullval = 0.; - if (*status > 0) + if (*status > 0) return(*status); if (!fits_is_compressed_image(fptr, status) ) @@ -4439,7 +4439,7 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ /* get temporary space for uncompressing one image tile */ if (datatype == TSHORT) { - buffer = malloc ((fptr->Fptr)->maxtilelen * sizeof (short)); + buffer = malloc ((fptr->Fptr)->maxtilelen * sizeof (short)); pixlen = sizeof(short); if (nullval) testnullval = *(short *) nullval; @@ -4513,10 +4513,10 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ if (buffer == NULL) { - ffpmsg("Out of memory (fits_read_compress_img)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory (fits_read_compress_img)"); + return (*status = MEMORY_ALLOCATION); } - + /* allocate memory for a null flag array, if needed */ if (nullcheck == 2) { @@ -4524,9 +4524,9 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ if (bnullarray == NULL) { - ffpmsg("Out of memory (fits_read_compress_img)"); + ffpmsg("Out of memory (fits_read_compress_img)"); free(buffer); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } } @@ -4575,7 +4575,7 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ tilesize[ii] = (fptr->Fptr)->tilesize[ii]; tiledim[ii] = (naxis[ii] - 1) / tilesize[ii] + 1; ftile[ii] = (fpixel[ii] - 1) / tilesize[ii] + 1; - ltile[ii] = minvalue((lpixel[ii] - 1) / tilesize[ii] + 1, + ltile[ii] = minvalue((lpixel[ii] - 1) / tilesize[ii] + 1, tiledim[ii]); rowdim[ii] = ntemp; /* total tiles in each dimension */ ntemp *= tiledim[ii]; @@ -4590,42 +4590,42 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ for (i5 = ftile[5]; i5 <= ltile[5]; i5++) { tfpixel[5] = (i5 - 1) * tilesize[5] + 1; - tlpixel[5] = minvalue(tfpixel[5] + tilesize[5] - 1, + tlpixel[5] = minvalue(tfpixel[5] + tilesize[5] - 1, naxis[5]); thistilesize[5] = tlpixel[5] - tfpixel[5] + 1; offset[5] = (i5 - 1) * rowdim[5]; for (i4 = ftile[4]; i4 <= ltile[4]; i4++) { tfpixel[4] = (i4 - 1) * tilesize[4] + 1; - tlpixel[4] = minvalue(tfpixel[4] + tilesize[4] - 1, + tlpixel[4] = minvalue(tfpixel[4] + tilesize[4] - 1, naxis[4]); thistilesize[4] = thistilesize[5] * (tlpixel[4] - tfpixel[4] + 1); offset[4] = (i4 - 1) * rowdim[4] + offset[5]; for (i3 = ftile[3]; i3 <= ltile[3]; i3++) { tfpixel[3] = (i3 - 1) * tilesize[3] + 1; - tlpixel[3] = minvalue(tfpixel[3] + tilesize[3] - 1, + tlpixel[3] = minvalue(tfpixel[3] + tilesize[3] - 1, naxis[3]); thistilesize[3] = thistilesize[4] * (tlpixel[3] - tfpixel[3] + 1); offset[3] = (i3 - 1) * rowdim[3] + offset[4]; for (i2 = ftile[2]; i2 <= ltile[2]; i2++) { tfpixel[2] = (i2 - 1) * tilesize[2] + 1; - tlpixel[2] = minvalue(tfpixel[2] + tilesize[2] - 1, + tlpixel[2] = minvalue(tfpixel[2] + tilesize[2] - 1, naxis[2]); thistilesize[2] = thistilesize[3] * (tlpixel[2] - tfpixel[2] + 1); offset[2] = (i2 - 1) * rowdim[2] + offset[3]; for (i1 = ftile[1]; i1 <= ltile[1]; i1++) { tfpixel[1] = (i1 - 1) * tilesize[1] + 1; - tlpixel[1] = minvalue(tfpixel[1] + tilesize[1] - 1, + tlpixel[1] = minvalue(tfpixel[1] + tilesize[1] - 1, naxis[1]); thistilesize[1] = thistilesize[2] * (tlpixel[1] - tfpixel[1] + 1); offset[1] = (i1 - 1) * rowdim[1] + offset[2]; for (i0 = ftile[0]; i0 <= ltile[0]; i0++) { tfpixel[0] = (i0 - 1) * tilesize[0] + 1; - tlpixel[0] = minvalue(tfpixel[0] + tilesize[0] - 1, + tlpixel[0] = minvalue(tfpixel[0] + tilesize[0] - 1, naxis[0]); thistilesize[0] = thistilesize[1] * (tlpixel[0] - tfpixel[0] + 1); /* calculate row of table containing this tile */ @@ -4634,10 +4634,10 @@ int fits_read_compressed_img(fitsfile *fptr, /* I - FITS file pointer */ /* printf("row %d, %d %d, %d %d, %d %d; %d\n", irow, tfpixel[0],tlpixel[0],tfpixel[1],tlpixel[1],tfpixel[2],tlpixel[2], - thistilesize[0]); -*/ + thistilesize[0]); +*/ /* test if there are any intersecting pixels in this tile and the output image */ - if (imcomp_test_overlap(ndim, tfpixel, tlpixel, + if (imcomp_test_overlap(ndim, tfpixel, tlpixel, fpixel, lpixel, inc, status)) { /* read and uncompress this row (tile) of the table */ /* also do type conversion and undefined pixel substitution */ @@ -4655,8 +4655,8 @@ printf(" pixlen=%d, ndim=%d, %d %d %d, %d %d %d, %d %d %d\n", fpixel[2],lpixel[2],inc[2]); */ /* copy the intersecting pixels from this tile to the output */ - imcomp_copy_overlap(buffer, pixlen, ndim, tfpixel, tlpixel, - bnullarray, array, fpixel, lpixel, inc, nullcheck, + imcomp_copy_overlap(buffer, pixlen, ndim, tfpixel, tlpixel, + bnullarray, array, fpixel, lpixel, inc, nullcheck, nullarray, status); } } @@ -4704,7 +4704,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer char *bnullarray = 0, *cnull; LONGLONG firstelem; - if (*status > 0) + if (*status > 0) return(*status); if (!fits_is_compressed_image(fptr, status) ) @@ -4714,17 +4714,17 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer } cnull = (char *) nullval; /* used to test if the nullval = 0 */ - + /* get temporary space for uncompressing one image tile */ /* If nullval == 0, then this means that the */ /* calling routine does not want to check for null pixels in the array */ if (datatype == TSHORT) { - buffer = malloc ((fptr->Fptr)->maxtilelen * sizeof (short)); + buffer = malloc ((fptr->Fptr)->maxtilelen * sizeof (short)); if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 ) { nullcheck = 0; - } + } } } else if (datatype == TINT) @@ -4733,7 +4733,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 && cnull[2] == 0 && cnull[3] == 0 ) { nullcheck = 0; - } + } } } else if (datatype == TLONG) @@ -4742,7 +4742,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 && cnull[2] == 0 && cnull[3] == 0 ) { nullcheck = 0; - } + } } } else if (datatype == TFLOAT) @@ -4751,7 +4751,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 && cnull[2] == 0 && cnull[3] == 0 ) { nullcheck = 0; - } + } } } else if (datatype == TDOUBLE) @@ -4759,9 +4759,9 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer buffer = malloc ((fptr->Fptr)->maxtilelen * sizeof (double)); if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 && cnull[2] == 0 && cnull[3] == 0 && - cnull[4] == 0 && cnull[5] == 0 && cnull[6] == 0 && cnull[7] == 0 ) { + cnull[4] == 0 && cnull[5] == 0 && cnull[6] == 0 && cnull[7] == 0 ) { nullcheck = 0; - } + } } } else if (datatype == TUSHORT) @@ -4770,7 +4770,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 ){ nullcheck = 0; - } + } } } else if (datatype == TUINT) @@ -4779,7 +4779,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 && cnull[2] == 0 && cnull[3] == 0 ){ nullcheck = 0; - } + } } } else if (datatype == TULONG) @@ -4788,7 +4788,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0 && cnull[1] == 0 && cnull[2] == 0 && cnull[3] == 0 ){ nullcheck = 0; - } + } } } else if (datatype == TBYTE || datatype == TSBYTE) @@ -4797,7 +4797,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (cnull) { if (cnull[0] == 0){ nullcheck = 0; - } + } } } else @@ -4808,8 +4808,8 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer if (buffer == NULL) { - ffpmsg("Out of memory (fits_read_compress_img)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory (fits_read_compress_img)"); + return (*status = MEMORY_ALLOCATION); } /* initialize all the arrays */ @@ -4853,7 +4853,7 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer tilesize[ii] = (fptr->Fptr)->tilesize[ii]; tiledim[ii] = (naxis[ii] - 1) / tilesize[ii] + 1; ftile[ii] = (fpixel[ii] - 1) / tilesize[ii] + 1; - ltile[ii] = minvalue((lpixel[ii] - 1) / tilesize[ii] + 1, + ltile[ii] = minvalue((lpixel[ii] - 1) / tilesize[ii] + 1, tiledim[ii]); rowdim[ii] = ntemp; /* total tiles in each dimension */ ntemp *= tiledim[ii]; @@ -4870,47 +4870,47 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer for (i5 = ftile[5]; i5 <= ltile[5]; i5++) { tfpixel[5] = (i5 - 1) * tilesize[5] + 1; - tlpixel[5] = minvalue(tfpixel[5] + tilesize[5] - 1, + tlpixel[5] = minvalue(tfpixel[5] + tilesize[5] - 1, naxis[5]); thistilesize[5] = tlpixel[5] - tfpixel[5] + 1; offset[5] = (i5 - 1) * rowdim[5]; for (i4 = ftile[4]; i4 <= ltile[4]; i4++) { tfpixel[4] = (i4 - 1) * tilesize[4] + 1; - tlpixel[4] = minvalue(tfpixel[4] + tilesize[4] - 1, + tlpixel[4] = minvalue(tfpixel[4] + tilesize[4] - 1, naxis[4]); thistilesize[4] = thistilesize[5] * (tlpixel[4] - tfpixel[4] + 1); offset[4] = (i4 - 1) * rowdim[4] + offset[5]; for (i3 = ftile[3]; i3 <= ltile[3]; i3++) { tfpixel[3] = (i3 - 1) * tilesize[3] + 1; - tlpixel[3] = minvalue(tfpixel[3] + tilesize[3] - 1, + tlpixel[3] = minvalue(tfpixel[3] + tilesize[3] - 1, naxis[3]); thistilesize[3] = thistilesize[4] * (tlpixel[3] - tfpixel[3] + 1); offset[3] = (i3 - 1) * rowdim[3] + offset[4]; for (i2 = ftile[2]; i2 <= ltile[2]; i2++) { tfpixel[2] = (i2 - 1) * tilesize[2] + 1; - tlpixel[2] = minvalue(tfpixel[2] + tilesize[2] - 1, + tlpixel[2] = minvalue(tfpixel[2] + tilesize[2] - 1, naxis[2]); thistilesize[2] = thistilesize[3] * (tlpixel[2] - tfpixel[2] + 1); offset[2] = (i2 - 1) * rowdim[2] + offset[3]; for (i1 = ftile[1]; i1 <= ltile[1]; i1++) { tfpixel[1] = (i1 - 1) * tilesize[1] + 1; - tlpixel[1] = minvalue(tfpixel[1] + tilesize[1] - 1, + tlpixel[1] = minvalue(tfpixel[1] + tilesize[1] - 1, naxis[1]); thistilesize[1] = thistilesize[2] * (tlpixel[1] - tfpixel[1] + 1); offset[1] = (i1 - 1) * rowdim[1] + offset[2]; for (i0 = ftile[0]; i0 <= ltile[0]; i0++) { tfpixel[0] = (i0 - 1) * tilesize[0] + 1; - tlpixel[0] = minvalue(tfpixel[0] + tilesize[0] - 1, + tlpixel[0] = minvalue(tfpixel[0] + tilesize[0] - 1, naxis[0]); thistilesize[0] = thistilesize[1] * (tlpixel[0] - tfpixel[0] + 1); /* calculate row of table containing this tile */ irow = i0 + offset[1]; - + /* read and uncompress this row (tile) of the table */ /* also do type conversion and undefined pixel substitution */ /* at this point */ @@ -4921,19 +4921,19 @@ int fits_read_write_compressed_img(fitsfile *fptr, /* I - FITS file pointer /* write the image to the output file */ - if (tilenul && anynul) { + if (tilenul && anynul) { /* this assumes that the tiled pixels are in the same order - as in the uncompressed FITS image. This is not necessarily - the case, but it almost alway is in practice. - Note that null checking is not performed for integer images, - so this could only be a problem for tile compressed floating - point images that use an unconventional tiling pattern. - */ + as in the uncompressed FITS image. This is not necessarily + the case, but it almost alway is in practice. + Note that null checking is not performed for integer images, + so this could only be a problem for tile compressed floating + point images that use an unconventional tiling pattern. + */ fits_write_imgnull(outfptr, datatype, firstelem, thistilesize[0], - buffer, nullval, status); + buffer, nullval, status); } else { - fits_write_subset(outfptr, datatype, tfpixel, tlpixel, - buffer, status); + fits_write_subset(outfptr, datatype, tfpixel, tlpixel, + buffer, status); } firstelem += thistilesize[0]; @@ -4964,13 +4964,13 @@ int fits_read_compressed_pixels(fitsfile *fptr, /* I - FITS file pointer */ int *status) /* IO - error status */ /* Read a consecutive set of pixels from a compressed image. This routine - interpretes the n-dimensional image as a long one-dimensional array. + interpretes the n-dimensional image as a long one-dimensional array. This is actually a rather inconvenient way to read compressed images in general, and could be rather inefficient if the requested pixels to be - read are located in many different image compression tiles. + read are located in many different image compression tiles. The general strategy used here is to read the requested pixels in blocks - that correspond to rectangular image sections. + that correspond to rectangular image sections. */ { int naxis, ii, bytesperpixel, planenul; @@ -5133,7 +5133,7 @@ int fits_read_compressed_img_plane(fitsfile *fptr, /* I - FITS file */ */ { /* bottom left coord. and top right coord. */ - LONGLONG blc[MAX_COMPRESS_DIM], trc[MAX_COMPRESS_DIM]; + LONGLONG blc[MAX_COMPRESS_DIM], trc[MAX_COMPRESS_DIM]; char *arrayptr, *nullarrayptr; int tnull; @@ -5149,11 +5149,11 @@ int fits_read_compressed_img_plane(fitsfile *fptr, /* I - FITS file */ trc[2] = nplane + 1; if (firstcoord[0] != 0) - { + { /* have to read a partial first row */ blc[0] = firstcoord[0] + 1; blc[1] = firstcoord[1] + 1; - trc[1] = blc[1]; + trc[1] = blc[1]; if (lastcoord[1] == firstcoord[1]) trc[0] = lastcoord[0] + 1; /* 1st and last pixels in same row */ else @@ -5237,8 +5237,8 @@ int fits_read_compressed_img_plane(fitsfile *fptr, /* I - FITS file */ } /*--------------------------------------------------------------------------*/ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) - -/* + +/* This routine reads keywords from a BINTABLE extension containing a compressed image. */ @@ -5280,10 +5280,10 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) { ffpmsg("Unknown image compression type:"); ffpmsg(value); - return (*status = DATA_DECOMPRESSION_ERR); + return (*status = DATA_DECOMPRESSION_ERR); } - - if (ffgky (infptr, TINT, "ZBITPIX", &(infptr->Fptr)->zbitpix, + + if (ffgky (infptr, TINT, "ZBITPIX", &(infptr->Fptr)->zbitpix, NULL, status) > 0) { ffpmsg("required ZBITPIX compression keyword not found"); @@ -5297,10 +5297,10 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) tstatus2=0; if ((infptr->Fptr->zbitpix < 0) && (fits_get_colnum(infptr,CASEINSEN,"ZZERO",&colNum,&tstatus) - == COL_NOT_FOUND) && + == COL_NOT_FOUND) && (fits_get_colnum(infptr,CASEINSEN,"ZSCALE",&colNum,&tstatus2) - == COL_NOT_FOUND)) { - (infptr->Fptr)->quantize_level = NO_QUANTIZE; + == COL_NOT_FOUND)) { + (infptr->Fptr)->quantize_level = NO_QUANTIZE; } else { /* get the floating point to integer quantization type, if present. */ @@ -5314,7 +5314,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) if (!FSTRCMP(value, "NONE") ) { (infptr->Fptr)->quantize_level = NO_QUANTIZE; - } else if (!FSTRCMP(value, "SUBTRACTIVE_DITHER_1") ) + } else if (!FSTRCMP(value, "SUBTRACTIVE_DITHER_1") ) (infptr->Fptr)->quantize_method = SUBTRACTIVE_DITHER_1; else if (!FSTRCMP(value, "SUBTRACTIVE_DITHER_2") ) (infptr->Fptr)->quantize_method = SUBTRACTIVE_DITHER_2; @@ -5330,8 +5330,8 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) tstatus = 0; if (ffgky(infptr, TINT, "ZDITHER0", &doffset, NULL, &tstatus) > 0) { - /* by default start with 1st element of random sequence */ - (infptr->Fptr)->dither_seed = 1; + /* by default start with 1st element of random sequence */ + (infptr->Fptr)->dither_seed = 1; } else { (infptr->Fptr)->dither_seed = doffset; } @@ -5345,7 +5345,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) if ((infptr->Fptr)->zndim < 1) { ffpmsg("Compressed image has no data (ZNAXIS < 1)"); - return (*status = BAD_NAXIS); + return (*status = BAD_NAXIS); } if ((infptr->Fptr)->zndim > MAX_COMPRESS_DIM) @@ -5360,7 +5360,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) { /* get image size */ snprintf (keyword, FLEN_KEYWORD,"ZNAXIS%d", ii+1); - ffgky (infptr, TLONG,keyword, &(infptr->Fptr)->znaxis[ii],NULL,status); + ffgky (infptr, TLONG,keyword, &(infptr->Fptr)->znaxis[ii],NULL,status); if (*status > 0) { @@ -5369,7 +5369,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) } /* get compression tile size */ - snprintf (keyword, FLEN_KEYWORD,"ZTILE%d", ii+1); + snprintf (keyword, FLEN_KEYWORD,"ZTILE%d", ii+1); /* set default tile size in case keywords are not present */ if (ii == 0) @@ -5378,10 +5378,10 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) (infptr->Fptr)->tilesize[ii] = 1; tstatus = 0; - ffgky (infptr, TLONG, keyword, &(infptr->Fptr)->tilesize[ii], NULL, + ffgky (infptr, TLONG, keyword, &(infptr->Fptr)->tilesize[ii], NULL, &tstatus); - expect_nrows *= (((infptr->Fptr)->znaxis[ii] - 1) / + expect_nrows *= (((infptr->Fptr)->znaxis[ii] - 1) / (infptr->Fptr)->tilesize[ii]+ 1); maxtilelen *= (infptr->Fptr)->tilesize[ii]; } @@ -5412,7 +5412,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) { oldFormat = 1; } - + tstatus = 0; if (oldFormat || ffgky(infptr, TINT,"ZVAL2", &(infptr->Fptr)->rice_bytepix, NULL, &tstatus) > 0) @@ -5421,11 +5421,11 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) } if ((infptr->Fptr)->rice_blocksize < 16 && - (infptr->Fptr)->rice_bytepix > 8) { - /* values are reversed */ - tstatus = (infptr->Fptr)->rice_bytepix; - (infptr->Fptr)->rice_bytepix = (infptr->Fptr)->rice_blocksize; - (infptr->Fptr)->rice_blocksize = tstatus; + (infptr->Fptr)->rice_bytepix > 8) { + /* values are reversed */ + tstatus = (infptr->Fptr)->rice_bytepix; + (infptr->Fptr)->rice_bytepix = (infptr->Fptr)->rice_blocksize; + (infptr->Fptr)->rice_blocksize = tstatus; } } else if ((infptr->Fptr)->compress_type == HCOMPRESS_1 ) { @@ -5439,14 +5439,14 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) tstatus = 0; ffgky(infptr, TINT,"ZVAL2", &(infptr->Fptr)->hcomp_smooth, NULL, &tstatus); - } + } /* store number of pixels in each compression tile, */ /* and max size of the compressed tile buffer */ (infptr->Fptr)->maxtilelen = maxtilelen; - (infptr->Fptr)->maxelem = - imcomp_calc_max_elem ((infptr->Fptr)->compress_type, maxtilelen, + (infptr->Fptr)->maxelem = + imcomp_calc_max_elem ((infptr->Fptr)->compress_type, maxtilelen, (infptr->Fptr)->zbitpix, (infptr->Fptr)->rice_blocksize); /* Get Column numbers. */ @@ -5473,7 +5473,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) { /* CMPSCALE column doesn't exist; see if there is a keyword */ tstatus = 0; - if (ffgky(infptr, TDOUBLE, "ZSCALE", &(infptr->Fptr)->zscale, NULL, + if (ffgky(infptr, TDOUBLE, "ZSCALE", &(infptr->Fptr)->zscale, NULL, &tstatus) <= 0) (infptr->Fptr)->cn_zscale = -1; /* flag for a constant ZSCALE */ } @@ -5484,7 +5484,7 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) { /* CMPZERO column doesn't exist; see if there is a keyword */ tstatus = 0; - if (ffgky(infptr, TDOUBLE, "ZZERO", &(infptr->Fptr)->zzero, NULL, + if (ffgky(infptr, TDOUBLE, "ZZERO", &(infptr->Fptr)->zzero, NULL, &tstatus) <= 0) (infptr->Fptr)->cn_zzero = -1; /* flag for a constant ZZERO */ } @@ -5503,21 +5503,21 @@ int imcomp_get_compressed_image_par(fitsfile *infptr, int *status) /* ZBLANK keyword doesn't exist; see if there is a BLANK keyword */ tstatus = 0; if (ffgky(infptr, TINT, "BLANK", &(infptr->Fptr)->zblank, NULL, - &tstatus) <= 0) + &tstatus) <= 0) (infptr->Fptr)->cn_zblank = -1; /* flag for a constant ZBLANK */ } } /* read the conventional BSCALE and BZERO scaling keywords, if present */ tstatus = 0; - if (ffgky (infptr, TDOUBLE, "BSCALE", &(infptr->Fptr)->cn_bscale, + if (ffgky (infptr, TDOUBLE, "BSCALE", &(infptr->Fptr)->cn_bscale, NULL, &tstatus) > 0) { (infptr->Fptr)->cn_bscale = 1.0; } tstatus = 0; - if (ffgky (infptr, TDOUBLE, "BZERO", &(infptr->Fptr)->cn_bzero, + if (ffgky (infptr, TDOUBLE, "BZERO", &(infptr->Fptr)->cn_bzero, NULL, &tstatus) > 0) { (infptr->Fptr)->cn_bzero = 0.0; @@ -5556,17 +5556,17 @@ int imcomp_copy_imheader(fitsfile *infptr, fitsfile *outfptr, int *status) { ffgrec(infptr, ii, card, status); - keyclass = ffgkcl(card); /* Get the type/class of keyword */ + keyclass = ffgkcl(card); /* Get the type/class of keyword */ /* don't copy structural keywords or checksum keywords */ if ((keyclass <= TYP_CMPRS_KEY) || (keyclass == TYP_CKSUM_KEY)) - continue; + continue; if (FSTRNCMP(card, "DATE ", 5) == 0) /* write current date */ { ffpdat(outfptr, status); } - else if (FSTRNCMP(card, "EXTNAME ", 8) == 0) + else if (FSTRNCMP(card, "EXTNAME ", 8) == 0) { /* don't copy default EXTNAME keyword from a compressed image */ if (FSTRNCMP(card, "EXTNAME = 'COMPRESSED_IMAGE'", 28)) @@ -5579,7 +5579,7 @@ int imcomp_copy_imheader(fitsfile *infptr, fitsfile *outfptr, int *status) else { /* just copy the keyword to the output header */ - ffprec (outfptr, card, status); + ffprec (outfptr, card, status); } if (*status > 0) @@ -5590,8 +5590,8 @@ int imcomp_copy_imheader(fitsfile *infptr, fitsfile *outfptr, int *status) /*--------------------------------------------------------------------------*/ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) /* - This routine copies the header keywords from the uncompressed input image - and to the compressed image (in a binary table) + This routine copies the header keywords from the uncompressed input image + and to the compressed image (in a binary table) */ { char card[FLEN_CARD], card2[FLEN_CARD]; /* a header record */ @@ -5600,20 +5600,20 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) /* tile compressed image keyword translation table */ /* INPUT OUTPUT */ /* 01234567 01234567 */ - char *patterns[][2] = {{"SIMPLE", "ZSIMPLE" }, - {"XTENSION", "ZTENSION" }, - {"BITPIX", "ZBITPIX" }, - {"NAXIS", "ZNAXIS" }, - {"NAXISm", "ZNAXISm" }, - {"EXTEND", "ZEXTEND" }, - {"BLOCKED", "ZBLOCKED"}, - {"PCOUNT", "ZPCOUNT" }, - {"GCOUNT", "ZGCOUNT" }, - - {"CHECKSUM","ZHECKSUM"}, /* save original checksums */ - {"DATASUM", "ZDATASUM"}, - - {"*", "+" }}; /* copy all other keywords */ + char *patterns[][2] = {{"SIMPLE", "ZSIMPLE" }, + {"XTENSION", "ZTENSION" }, + {"BITPIX", "ZBITPIX" }, + {"NAXIS", "ZNAXIS" }, + {"NAXISm", "ZNAXISm" }, + {"EXTEND", "ZEXTEND" }, + {"BLOCKED", "ZBLOCKED"}, + {"PCOUNT", "ZPCOUNT" }, + {"GCOUNT", "ZGCOUNT" }, + + {"CHECKSUM","ZHECKSUM"}, /* save original checksums */ + {"DATASUM", "ZDATASUM"}, + + {"*", "+" }}; /* copy all other keywords */ int npat; if (*status > 0) @@ -5621,7 +5621,7 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) /* write a default EXTNAME keyword if it doesn't exist in input file*/ fits_read_card(infptr, "EXTNAME", card, status); - + if (*status) { *status = 0; strcpy(card, "EXTNAME = 'COMPRESSED_IMAGE'"); @@ -5631,28 +5631,28 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) /* copy all the keywords from the input file to the output */ npat = sizeof(patterns)/sizeof(patterns[0][0])/2; fits_translate_keywords(infptr, outfptr, 1, patterns, npat, - 0, 0, 0, status); + 0, 0, 0, status); - if ( (outfptr->Fptr)->request_lossy_int_compress != 0) { + if ( (outfptr->Fptr)->request_lossy_int_compress != 0) { - /* request was made to compress integer images as if they had float pixels. */ - /* If input image has positive bitpix value, then reset the output ZBITPIX */ - /* value to -32. */ + /* request was made to compress integer images as if they had float pixels. */ + /* If input image has positive bitpix value, then reset the output ZBITPIX */ + /* value to -32. */ - fits_read_key(infptr, TINT, "BITPIX", &bitpix, NULL, status); + fits_read_key(infptr, TINT, "BITPIX", &bitpix, NULL, status); - if (*status <= 0 && bitpix > 0) { - fits_modify_key_lng(outfptr, "ZBITPIX", -32, NULL, status); + if (*status <= 0 && bitpix > 0) { + fits_modify_key_lng(outfptr, "ZBITPIX", -32, NULL, status); - /* also delete the BSCALE, BZERO, and BLANK keywords */ - tstatus = 0; - fits_delete_key(outfptr, "BSCALE", &tstatus); - tstatus = 0; - fits_delete_key(outfptr, "BZERO", &tstatus); - tstatus = 0; - fits_delete_key(outfptr, "BLANK", &tstatus); - } + /* also delete the BSCALE, BZERO, and BLANK keywords */ + tstatus = 0; + fits_delete_key(outfptr, "BSCALE", &tstatus); + tstatus = 0; + fits_delete_key(outfptr, "BZERO", &tstatus); + tstatus = 0; + fits_delete_key(outfptr, "BLANK", &tstatus); + } } /* @@ -5664,7 +5664,7 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) In principle this should not be necessary once all software has upgraded to a newer version of CFITSIO (version number greater than 3.181, newer than August 2009). - + Do the same for the new ZDITHER0 keyword. */ @@ -5676,17 +5676,17 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) /* rewrite the deleted keyword at the end of the header */ fits_write_record(outfptr, card, status); - /* write some associated HISTORY keywords */ + /* write some associated HISTORY keywords */ fits_parse_value(card, card2, NULL, status); - if (fits_strncasecmp(card2, "'NONE", 5) ) { - /* the value is not 'NONE' */ - fits_write_history(outfptr, - "Image was compressed by CFITSIO using scaled integer quantization:", status); - snprintf(card2, FLEN_CARD," q = %f / quantized level scaling parameter", - (outfptr->Fptr)->request_quantize_level); - fits_write_history(outfptr, card2, status); - fits_write_history(outfptr, card+10, status); - } + if (fits_strncasecmp(card2, "'NONE", 5) ) { + /* the value is not 'NONE' */ + fits_write_history(outfptr, + "Image was compressed by CFITSIO using scaled integer quantization:", status); + snprintf(card2, FLEN_CARD," q = %f / quantized level scaling parameter", + (outfptr->Fptr)->request_quantize_level); + fits_write_history(outfptr, card2, status); + fits_write_history(outfptr, card+10, status); + } } tstatus = 0; @@ -5702,9 +5702,9 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) ffghsp(infptr, &nkeys, &nmore, status); /* get number of keywords in image */ nmore = nmore / 36; /* how many completely empty header blocks are there? */ - + /* preserve the same number of spare header blocks in the output header */ - + for (jj = 0; jj < nmore; jj++) for (ii = 0; ii < 36; ii++) fits_write_record(outfptr, " ", status); @@ -5712,11 +5712,11 @@ int imcomp_copy_img2comp(fitsfile *infptr, fitsfile *outfptr, int *status) return (*status); } /*--------------------------------------------------------------------------*/ -int imcomp_copy_comp2img(fitsfile *infptr, fitsfile *outfptr, +int imcomp_copy_comp2img(fitsfile *infptr, fitsfile *outfptr, int norec, int *status) /* - This routine copies the header keywords from the compressed input image - and to the uncompressed image (in a binary table) + This routine copies the header keywords from the compressed input image + and to the uncompressed image (in a binary table) */ { char card[FLEN_CARD]; /* a header record */ @@ -5724,55 +5724,55 @@ int imcomp_copy_comp2img(fitsfile *infptr, fitsfile *outfptr, char negative[] = "-"; int ii,jj, npat, nreq, nsp, tstatus = 0; int nkeys, nmore; - + /* tile compressed image keyword translation table */ /* INPUT OUTPUT */ /* 01234567 01234567 */ /* only translate these if required keywords not already written */ - char *reqkeys[][2] = { - {"ZSIMPLE", "SIMPLE" }, - {"ZTENSION", "XTENSION"}, - {"ZBITPIX", "BITPIX" }, - {"ZNAXIS", "NAXIS" }, - {"ZNAXISm", "NAXISm" }, - {"ZEXTEND", "EXTEND" }, - {"ZBLOCKED", "BLOCKED"}, - {"ZPCOUNT", "PCOUNT" }, - {"ZGCOUNT", "GCOUNT" }, - {"ZHECKSUM", "CHECKSUM"}, /* restore original checksums */ - {"ZDATASUM", "DATASUM"}}; + char *reqkeys[][2] = { + {"ZSIMPLE", "SIMPLE" }, + {"ZTENSION", "XTENSION"}, + {"ZBITPIX", "BITPIX" }, + {"ZNAXIS", "NAXIS" }, + {"ZNAXISm", "NAXISm" }, + {"ZEXTEND", "EXTEND" }, + {"ZBLOCKED", "BLOCKED"}, + {"ZPCOUNT", "PCOUNT" }, + {"ZGCOUNT", "GCOUNT" }, + {"ZHECKSUM", "CHECKSUM"}, /* restore original checksums */ + {"ZDATASUM", "DATASUM"}}; /* other special keywords */ char *spkeys[][2] = { - {"XTENSION", "-" }, - {"BITPIX", "-" }, - {"NAXIS", "-" }, - {"NAXISm", "-" }, - {"PCOUNT", "-" }, - {"GCOUNT", "-" }, - {"TFIELDS", "-" }, - {"TTYPEm", "-" }, - {"TFORMm", "-" }, - {"THEAP", "-" }, - {"ZIMAGE", "-" }, - {"ZQUANTIZ", "-" }, - {"ZDITHER0", "-" }, - {"ZTILEm", "-" }, - {"ZCMPTYPE", "-" }, - {"ZBLANK", "-" }, - {"ZNAMEm", "-" }, - {"ZVALm", "-" }, - - {"CHECKSUM","-" }, /* delete checksums */ - {"DATASUM", "-" }, - {"EXTNAME", "+" }, /* we may change this, below */ - {"*", "+" }}; + {"XTENSION", "-" }, + {"BITPIX", "-" }, + {"NAXIS", "-" }, + {"NAXISm", "-" }, + {"PCOUNT", "-" }, + {"GCOUNT", "-" }, + {"TFIELDS", "-" }, + {"TTYPEm", "-" }, + {"TFORMm", "-" }, + {"THEAP", "-" }, + {"ZIMAGE", "-" }, + {"ZQUANTIZ", "-" }, + {"ZDITHER0", "-" }, + {"ZTILEm", "-" }, + {"ZCMPTYPE", "-" }, + {"ZBLANK", "-" }, + {"ZNAMEm", "-" }, + {"ZVALm", "-" }, + + {"CHECKSUM","-" }, /* delete checksums */ + {"DATASUM", "-" }, + {"EXTNAME", "+" }, /* we may change this, below */ + {"*", "+" }}; if (*status > 0) return(*status); - + nreq = sizeof(reqkeys)/sizeof(reqkeys[0][0])/2; nsp = sizeof(spkeys)/sizeof(spkeys[0][0])/2; @@ -5780,38 +5780,38 @@ int imcomp_copy_comp2img(fitsfile *infptr, fitsfile *outfptr, for (ii = 0; ii < nreq; ii++) { patterns[ii][0] = reqkeys[ii][0]; - - if (norec) + + if (norec) patterns[ii][1] = negative; else patterns[ii][1] = reqkeys[ii][1]; } - + for (ii = 0; ii < nsp; ii++) { patterns[ii+nreq][0] = spkeys[ii][0]; patterns[ii+nreq][1] = spkeys[ii][1]; } npat = nreq + nsp; - + /* see if the EXTNAME keyword should be copied or not */ fits_read_card(infptr, "EXTNAME", card, &tstatus); if (tstatus == 0) { - if (!strncmp(card, "EXTNAME = 'COMPRESSED_IMAGE'", 28)) + if (!strncmp(card, "EXTNAME = 'COMPRESSED_IMAGE'", 28)) patterns[npat-2][1] = negative; } - + /* translate and copy the keywords from the input file to the output */ fits_translate_keywords(infptr, outfptr, 1, patterns, npat, - 0, 0, 0, status); + 0, 0, 0, status); ffghsp(infptr, &nkeys, &nmore, status); /* get number of keywords in image */ nmore = nmore / 36; /* how many completely empty header blocks are there? */ - + /* preserve the same number of spare header blocks in the output header */ - + for (jj = 0; jj < nmore; jj++) for (ii = 0; ii < 36; ii++) fits_write_record(outfptr, " ", status); @@ -5824,35 +5824,35 @@ int imcomp_copy_prime2img(fitsfile *infptr, fitsfile *outfptr, int *status) /* This routine copies any unexpected keywords from the primary array of the compressed input image into the header of the uncompressed image - (which is the primary array of the output file). + (which is the primary array of the output file). */ { int nsp; /* keywords that will not be copied */ char *spkeys[][2] = { - {"SIMPLE", "-" }, - {"BITPIX", "-" }, - {"NAXIS", "-" }, - {"NAXISm", "-" }, - {"PCOUNT", "-" }, - {"EXTEND", "-" }, - {"GCOUNT", "-" }, - {"CHECKSUM","-" }, - {"DATASUM", "-" }, - {"EXTNAME", "-" }, - {"HISTORY", "-" }, - {"COMMENT", "-" }, - {"*", "+" }}; + {"SIMPLE", "-" }, + {"BITPIX", "-" }, + {"NAXIS", "-" }, + {"NAXISm", "-" }, + {"PCOUNT", "-" }, + {"EXTEND", "-" }, + {"GCOUNT", "-" }, + {"CHECKSUM","-" }, + {"DATASUM", "-" }, + {"EXTNAME", "-" }, + {"HISTORY", "-" }, + {"COMMENT", "-" }, + {"*", "+" }}; if (*status > 0) return(*status); - + nsp = sizeof(spkeys)/sizeof(spkeys[0][0])/2; /* translate and copy the keywords from the input file to the output */ fits_translate_keywords(infptr, outfptr, 1, spkeys, nsp, - 0, 0, 0, status); + 0, 0, 0, status); return (*status); } @@ -5909,7 +5909,7 @@ int imcomp_decompress_tile (fitsfile *infptr, (infptr->Fptr)->tileanynull = (int *) calloc (ntilebins, sizeof(int)); } } - + /* **************************************************************** */ /* check if this tile was cached; if so, just copy it out */ if ((infptr->Fptr)->tilerow) { @@ -5919,8 +5919,8 @@ int imcomp_decompress_tile (fitsfile *infptr, if (nrow == (infptr->Fptr)->tilerow[tilecol] && datatype == (infptr->Fptr)->tiletype[tilecol] ) { memcpy(buffer, ((infptr->Fptr)->tiledata)[tilecol], (infptr->Fptr)->tiledatasize[tilecol]); - - if (nullcheck == 2) + + if (nullcheck == 2) memcpy(bnullarray, (infptr->Fptr)->tilenullarray[tilecol], tilelen); *anynul = (infptr->Fptr)->tileanynull[tilecol]; @@ -5931,30 +5931,30 @@ int imcomp_decompress_tile (fitsfile *infptr, /* **************************************************************** */ /* get length of the compressed byte stream */ - ffgdesll (infptr, (infptr->Fptr)->cn_compressed, nrow, &nelemll, &offset, + ffgdesll (infptr, (infptr->Fptr)->cn_compressed, nrow, &nelemll, &offset, status); /* EOF error here indicates that this tile has not yet been written */ if (*status == END_OF_FILE) return(*status = NO_COMPRESSED_TILE); - + /* **************************************************************** */ if (nelemll == 0) /* special case: tile was not compressed normally */ { if ((infptr->Fptr)->cn_uncompressed >= 1 ) { - /* This option of writing the uncompressed floating point data */ - /* to the tile compressed file was used until about May 2011. */ - /* This was replaced by the more efficient option of gzipping the */ - /* floating point data before writing it to the tile-compressed file */ - + /* This option of writing the uncompressed floating point data */ + /* to the tile compressed file was used until about May 2011. */ + /* This was replaced by the more efficient option of gzipping the */ + /* floating point data before writing it to the tile-compressed file */ + /* no compressed data, so simply read the uncompressed data */ - /* directly from the UNCOMPRESSED_DATA column */ + /* directly from the UNCOMPRESSED_DATA column */ ffgdesll (infptr, (infptr->Fptr)->cn_uncompressed, nrow, &nelemll, &offset, status); if (nelemll == 0 && offset == 0) /* this should never happen */ - return (*status = NO_COMPRESSED_TILE); + return (*status = NO_COMPRESSED_TILE); if (nullcheck <= 1) { /* set any null values in the array = nulval */ fits_read_col(infptr, datatype, (infptr->Fptr)->cn_uncompressed, @@ -5967,41 +5967,41 @@ int imcomp_decompress_tile (fitsfile *infptr, /* This is the newer option, that was introduced in May 2011 */ /* floating point data was not quantized, so read the losslessly */ - /* compressed data from the GZIP_COMPRESSED_DATA column */ + /* compressed data from the GZIP_COMPRESSED_DATA column */ ffgdesll (infptr, (infptr->Fptr)->cn_gzip_data, nrow, &nelemll, &offset, status); if (nelemll == 0 && offset == 0) /* this should never happen */ - return (*status = NO_COMPRESSED_TILE); + return (*status = NO_COMPRESSED_TILE); - /* allocate memory for the compressed tile of data */ - cbuf = (unsigned char *) malloc ((long) nelemll); + /* allocate memory for the compressed tile of data */ + cbuf = (unsigned char *) malloc ((long) nelemll); if (cbuf == NULL) { - ffpmsg("error allocating memory for gzipped tile (imcomp_decompress_tile)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("error allocating memory for gzipped tile (imcomp_decompress_tile)"); + return (*status = MEMORY_ALLOCATION); } /* read array of compressed bytes */ if (fits_read_col(infptr, TBYTE, (infptr->Fptr)->cn_gzip_data, nrow, 1, (long) nelemll, &charnull, cbuf, NULL, status) > 0) { ffpmsg("error reading compressed byte stream from binary table"); - free (cbuf); + free (cbuf); return (*status); } /* size of the returned (uncompressed) data buffer, in bytes */ if ((infptr->Fptr)->zbitpix == FLOAT_IMG) { - idatalen = tilelen * sizeof(float); + idatalen = tilelen * sizeof(float); } else if ((infptr->Fptr)->zbitpix == DOUBLE_IMG) { - idatalen = tilelen * sizeof(double); + idatalen = tilelen * sizeof(double); } else { /* this should never happen! */ ffpmsg("incompatible data type in gzipped floating-point tile-compressed image"); free (cbuf); return (*status = DATA_DECOMPRESSION_ERR); } - + /* Do not allow image float/doubles into int arrays */ if (datatype != TFLOAT && datatype != TDOUBLE) { @@ -6014,9 +6014,9 @@ int imcomp_decompress_tile (fitsfile *infptr, { tempdouble = (double*)malloc(idatalen); if (tempdouble == NULL) { - ffpmsg("Memory allocation failure for tempdouble. (imcomp_decompress_tile)"); + ffpmsg("Memory allocation failure for tempdouble. (imcomp_decompress_tile)"); free (cbuf); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } /* uncompress the data into temp buffer */ @@ -6028,15 +6028,15 @@ int imcomp_decompress_tile (fitsfile *infptr, return (*status); } } - else if (datatype == TDOUBLE && (infptr->Fptr)->zbitpix == FLOAT_IMG) { + else if (datatype == TDOUBLE && (infptr->Fptr)->zbitpix == FLOAT_IMG) { /* have to allocat a temporary buffer for the uncompressed data in the */ /* case where a gzipped "float" tile is returned as a "double" array */ - tempfloat = (float*) malloc (idatalen); + tempfloat = (float*) malloc (idatalen); if (tempfloat == NULL) { - ffpmsg("Memory allocation failure for tempfloat. (imcomp_decompress_tile)"); + ffpmsg("Memory allocation failure for tempfloat. (imcomp_decompress_tile)"); free (cbuf); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } /* uncompress the data into temp buffer */ @@ -6071,21 +6071,21 @@ int imcomp_decompress_tile (fitsfile *infptr, #endif if (datatype == TFLOAT) { if (nulval) { - fnulval = *(float *) nulval; - } + fnulval = *(float *) nulval; + } - fffr4r4((float *) buffer, (long) tilelen, 1., 0., nullcheck, + fffr4r4((float *) buffer, (long) tilelen, 1., 0., nullcheck, fnulval, bnullarray, anynul, (float *) buffer, status); } else if (datatype == TDOUBLE) { if (nulval) { - dnulval = *(double *) nulval; - } + dnulval = *(double *) nulval; + } /* note that the R*4 data are in the tempfloat array in this case */ - fffr4r8((float *) tempfloat, (long) tilelen, 1., 0., nullcheck, + fffr4r8((float *) tempfloat, (long) tilelen, 1., 0., nullcheck, dnulval, bnullarray, anynul, - (double *) buffer, status); + (double *) buffer, status); free(tempfloat); } else { @@ -6102,34 +6102,34 @@ int imcomp_decompress_tile (fitsfile *infptr, #endif if (datatype == TFLOAT) { if (nulval) { - fnulval = *(float *) nulval; - } + fnulval = *(float *) nulval; + } - fffr8r4((double *) tempdouble, (long) tilelen, 1., 0., nullcheck, + fffr8r4((double *) tempdouble, (long) tilelen, 1., 0., nullcheck, fnulval, bnullarray, anynul, (float *) buffer, status); free(tempdouble); tempdouble=0; } else if (datatype == TDOUBLE) { if (nulval) { - dnulval = *(double *) nulval; - } + dnulval = *(double *) nulval; + } - fffr8r8((double *) buffer, (long) tilelen, 1., 0., nullcheck, + fffr8r8((double *) buffer, (long) tilelen, 1., 0., nullcheck, dnulval, bnullarray, anynul, - (double *) buffer, status); + (double *) buffer, status); } else { ffpmsg("implicit data type conversion is not supported in tile-compressed images"); return (*status = DATA_DECOMPRESSION_ERR); } - } else { + } else { ffpmsg("error: uncompressed tile has wrong size"); return (*status = DATA_DECOMPRESSION_ERR); } /* end of special case of losslessly gzipping a floating-point image tile */ } else { /* this should never happen */ - *status = NO_COMPRESSED_TILE; + *status = NO_COMPRESSED_TILE; } return(*status); @@ -6156,10 +6156,10 @@ int imcomp_decompress_tile (fitsfile *infptr, bzero = (infptr->Fptr)->zzero; } else { /* read the linear scale and offset values for this row */ - ffgcvd (infptr, (infptr->Fptr)->cn_zscale, nrow, 1, 1, 0., - &bscale, NULL, status); - ffgcvd (infptr, (infptr->Fptr)->cn_zzero, nrow, 1, 1, 0., - &bzero, NULL, status); + ffgcvd (infptr, (infptr->Fptr)->cn_zscale, nrow, 1, 1, 0., + &bscale, NULL, status); + ffgcvd (infptr, (infptr->Fptr)->cn_zzero, nrow, 1, 1, 0., + &bzero, NULL, status); if (*status > 0) { ffpmsg("error reading scaling factor and offset for compressed tile"); @@ -6167,17 +6167,17 @@ int imcomp_decompress_tile (fitsfile *infptr, } /* test if floating-point FITS image also has non-default BSCALE and */ - /* BZERO keywords. If so, we have to combine the 2 linear scaling factors. */ - - if ( ((infptr->Fptr)->zbitpix == FLOAT_IMG || - (infptr->Fptr)->zbitpix == DOUBLE_IMG ) - && - ((infptr->Fptr)->cn_bscale != 1.0 || - (infptr->Fptr)->cn_bzero != 0.0 ) ) - { - bscale = bscale * (infptr->Fptr)->cn_bscale; - bzero = bzero * (infptr->Fptr)->cn_bscale + (infptr->Fptr)->cn_bzero; - } + /* BZERO keywords. If so, we have to combine the 2 linear scaling factors. */ + + if ( ((infptr->Fptr)->zbitpix == FLOAT_IMG || + (infptr->Fptr)->zbitpix == DOUBLE_IMG ) + && + ((infptr->Fptr)->cn_bscale != 1.0 || + (infptr->Fptr)->cn_bzero != 0.0 ) ) + { + bscale = bscale * (infptr->Fptr)->cn_bscale; + bzero = bzero * (infptr->Fptr)->cn_bscale + (infptr->Fptr)->cn_bzero; + } } if (bscale == 1.0 && bzero == 0.0 ) { @@ -6196,8 +6196,8 @@ int imcomp_decompress_tile (fitsfile *infptr, tnull = (infptr->Fptr)->zblank; /* use the the ZBLANK keyword */ } else { /* read the null value for this row */ - ffgcvk (infptr, (infptr->Fptr)->cn_zblank, nrow, 1, 1, 0, - &tnull, NULL, status); + ffgcvk (infptr, (infptr->Fptr)->cn_zblank, nrow, 1, 1, 0, + &tnull, NULL, status); if (*status > 0) { ffpmsg("error reading null value for compressed tile"); return (*status); @@ -6207,16 +6207,16 @@ int imcomp_decompress_tile (fitsfile *infptr, /* ************************************************************* */ /* allocate memory for the uncompressed array of tile integers */ /* The size depends on the datatype and the compression type. */ - + if ((infptr->Fptr)->compress_type == HCOMPRESS_1 && ((infptr->Fptr)->zbitpix != BYTE_IMG && - (infptr->Fptr)->zbitpix != SHORT_IMG) ) { + (infptr->Fptr)->zbitpix != SHORT_IMG) ) { idatalen = tilelen * sizeof(LONGLONG); /* 8 bytes per pixel */ } else if ( (infptr->Fptr)->compress_type == RICE_1 && - (infptr->Fptr)->zbitpix == BYTE_IMG && - (infptr->Fptr)->rice_bytepix == 1) { + (infptr->Fptr)->zbitpix == BYTE_IMG && + (infptr->Fptr)->rice_bytepix == 1) { idatalen = tilelen * sizeof(char); /* 1 byte per pixel */ } else if ( ( (infptr->Fptr)->compress_type == GZIP_1 || @@ -6226,8 +6226,8 @@ int imcomp_decompress_tile (fitsfile *infptr, idatalen = tilelen * sizeof(char); /* 1 byte per pixel */ } else if ( (infptr->Fptr)->compress_type == RICE_1 && - (infptr->Fptr)->zbitpix == SHORT_IMG && - (infptr->Fptr)->rice_bytepix == 2) { + (infptr->Fptr)->zbitpix == SHORT_IMG && + (infptr->Fptr)->rice_bytepix == 2) { idatalen = tilelen * sizeof(short); /* 2 bytes per pixel */ } else if ( ( (infptr->Fptr)->compress_type == GZIP_1 || @@ -6246,10 +6246,10 @@ int imcomp_decompress_tile (fitsfile *infptr, idatalen = tilelen * sizeof(int); /* all other cases have int pixels */ } - idata = (int*) malloc (idatalen); + idata = (int*) malloc (idatalen); if (idata == NULL) { - ffpmsg("Memory allocation failure for idata. (imcomp_decompress_tile)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Memory allocation failure for idata. (imcomp_decompress_tile)"); + return (*status = MEMORY_ALLOCATION); } /* ************************************************************* */ @@ -6261,11 +6261,11 @@ int imcomp_decompress_tile (fitsfile *infptr, cbuf = (unsigned char *) malloc ((long) nelemll); } if (cbuf == NULL) { - ffpmsg("Out of memory for cbuf. (imcomp_decompress_tile)"); + ffpmsg("Out of memory for cbuf. (imcomp_decompress_tile)"); free(idata); - return (*status = MEMORY_ALLOCATION); + return (*status = MEMORY_ALLOCATION); } - + /* ************************************************************* */ /* read the compressed bytes from the FITS file */ @@ -6279,7 +6279,7 @@ int imcomp_decompress_tile (fitsfile *infptr, if (*status > 0) { ffpmsg("error reading compressed byte stream from binary table"); - free (cbuf); + free (cbuf); free(idata); return (*status); } @@ -6312,12 +6312,12 @@ int imcomp_decompress_tile (fitsfile *infptr, if ( ((infptr->Fptr)->zbitpix == BYTE_IMG || (infptr->Fptr)->zbitpix == SHORT_IMG)) { *status = fits_hdecompress(cbuf, smooth, idata, &nx, &ny, - &scale, status); + &scale, status); } else { /* zbitpix = LONG_IMG (32) */ /* idata must have been allocated twice as large for this to work */ *status = fits_hdecompress64(cbuf, smooth, (LONGLONG *) idata, &nx, &ny, - &scale, status); - } + &scale, status); + } tiledatatype = TINT; @@ -6335,42 +6335,42 @@ int imcomp_decompress_tile (fitsfile *infptr, (char **) &idata, &idatalen, realloc, &tilebytesize, status); /* determine the data type of the uncompressed array, and */ - /* do byte unshuffling and unswapping if needed */ - if (tilebytesize == (size_t) (tilelen * 2)) { - /* this is a short I*2 array */ + /* do byte unshuffling and unswapping if needed */ + if (tilebytesize == (size_t) (tilelen * 2)) { + /* this is a short I*2 array */ tiledatatype = TSHORT; if ( (infptr->Fptr)->compress_type == GZIP_2 ) - fits_unshuffle_2bytes((char *) idata, tilelen, status); + fits_unshuffle_2bytes((char *) idata, tilelen, status); #if BYTESWAPPED ffswap2((short *) idata, tilelen); #endif - } else if (tilebytesize == (size_t) (tilelen * 4)) { - /* this is a int I*4 array (or maybe R*4) */ + } else if (tilebytesize == (size_t) (tilelen * 4)) { + /* this is a int I*4 array (or maybe R*4) */ tiledatatype = TINT; if ( (infptr->Fptr)->compress_type == GZIP_2 ) - fits_unshuffle_4bytes((char *) idata, tilelen, status); + fits_unshuffle_4bytes((char *) idata, tilelen, status); #if BYTESWAPPED ffswap4(idata, tilelen); #endif - } else if (tilebytesize == (size_t) (tilelen * 8)) { - /* this is a R*8 double array */ + } else if (tilebytesize == (size_t) (tilelen * 8)) { + /* this is a R*8 double array */ tiledatatype = TDOUBLE; if ( (infptr->Fptr)->compress_type == GZIP_2 ) - fits_unshuffle_8bytes((char *) idata, tilelen, status); + fits_unshuffle_8bytes((char *) idata, tilelen, status); #if BYTESWAPPED ffswap8((double *) idata, tilelen); #endif } else if (tilebytesize == (size_t) tilelen) { - - /* this is an unsigned char I*1 array */ + + /* this is an unsigned char I*1 array */ tiledatatype = TBYTE; } else { @@ -6382,10 +6382,10 @@ int imcomp_decompress_tile (fitsfile *infptr, /* ************************************************************* */ } else if ((infptr->Fptr)->compress_type == BZIP2_1) { -/* BZIP2 is not supported in the public release; this is only for test purposes +/* BZIP2 is not supported in the public release; this is only for test purposes - if (BZ2_bzBuffToBuffDecompress ((char *) idata, &idatalen, - (char *)cbuf, (unsigned int) nelemll, 0, 0) ) + if (BZ2_bzBuffToBuffDecompress ((char *) idata, &idatalen, + (char *)cbuf, (unsigned int) nelemll, 0, 0) ) */ { ffpmsg("bzip2 decompression error"); @@ -6395,18 +6395,18 @@ int imcomp_decompress_tile (fitsfile *infptr, } if ((infptr->Fptr)->zbitpix == BYTE_IMG) { - tiledatatype = TBYTE; + tiledatatype = TBYTE; } else if ((infptr->Fptr)->zbitpix == SHORT_IMG) { - tiledatatype = TSHORT; + tiledatatype = TSHORT; #if BYTESWAPPED ffswap2((short *) idata, tilelen); #endif - } else { - tiledatatype = TINT; + } else { + tiledatatype = TINT; #if BYTESWAPPED ffswap4(idata, tilelen); #endif - } + } /* ************************************************************* */ } else { @@ -6432,23 +6432,23 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(short); - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4i2((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4i2((float *) idata, tilelen, bscale, bzero, nullcheck, *(short *) nulval, bnullarray, anynul, (short *) buffer, status); } else { - fffr8i2((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8i2((double *) idata, tilelen, bscale, bzero, nullcheck, *(short *) nulval, bnullarray, anynul, (short *) buffer, status); } } else if (tiledatatype == TINT) { if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4i2(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, *(short *) nulval, bnullarray, anynul, (short *) buffer, status); @@ -6458,14 +6458,14 @@ int imcomp_decompress_tile (fitsfile *infptr, (short *) buffer, status); /* - Hcompress is a special case: ignore any numerical overflow - errors that may have occurred during the integer*4 to integer*2 - convertion. Overflows can happen when a lossy Hcompress algorithm - is invoked (with a non-zero scale factor). The fffi4i2 routine - clips the returned values to be within the legal I*2 range, so - all we need to is to reset the error status to zero. - */ - + Hcompress is a special case: ignore any numerical overflow + errors that may have occurred during the integer*4 to integer*2 + convertion. Overflows can happen when a lossy Hcompress algorithm + is invoked (with a non-zero scale factor). The fffi4i2 routine + clips the returned values to be within the legal I*2 range, so + all we need to is to reset the error status to zero. + */ + if ((infptr->Fptr)->compress_type == HCOMPRESS_1) { if ((*status == NUM_OVERFLOW) || (*status == OVERFLOW_ERR)) *status = 0; @@ -6485,23 +6485,23 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(int); - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4int((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4int((float *) idata, tilelen, bscale, bzero, nullcheck, *(int *) nulval, bnullarray, anynul, (int *) buffer, status); } else { - fffr8int((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8int((double *) idata, tilelen, bscale, bzero, nullcheck, *(int *) nulval, bnullarray, anynul, (int *) buffer, status); } } else if (tiledatatype == TINT) if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4int(idata, (long) tilelen, bscale, bzero - 32768., nullcheck, tnull, *(int *) nulval, bnullarray, anynul, (int *) buffer, status); @@ -6509,7 +6509,7 @@ int imcomp_decompress_tile (fitsfile *infptr, fffi4int(idata, (long) tilelen, bscale, bzero, nullcheck, tnull, *(int *) nulval, bnullarray, anynul, (int *) buffer, status); - } + } else if (tiledatatype == TSHORT) fffi2int((short *)idata, tilelen, bscale, bzero, nullcheck, (short) tnull, *(int *) nulval, bnullarray, anynul, @@ -6523,23 +6523,23 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(long); - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4i4((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4i4((float *) idata, tilelen, bscale, bzero, nullcheck, *(long *) nulval, bnullarray, anynul, (long *) buffer, status); } else { - fffr8i4((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8i4((double *) idata, tilelen, bscale, bzero, nullcheck, *(long *) nulval, bnullarray, anynul, (long *) buffer, status); } } else if (tiledatatype == TINT) if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4i4(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, *(long *) nulval, bnullarray, anynul, (long *) buffer, status); @@ -6561,41 +6561,41 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(float); if (nulval) { - fnulval = *(float *) nulval; - } - - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + fnulval = *(float *) nulval; + } + + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4r4((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4r4((float *) idata, tilelen, bscale, bzero, nullcheck, fnulval, bnullarray, anynul, (float *) buffer, status); } else { - fffr8r4((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8r4((double *) idata, tilelen, bscale, bzero, nullcheck, fnulval, bnullarray, anynul, (float *) buffer, status); } - + } else if ((infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_1 || - (infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { + (infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { /* use the new dithering algorithm (introduced in July 2009) */ if (tiledatatype == TINT) - unquantize_i4r4(nrow + (infptr->Fptr)->dither_seed - 1, idata, - tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, tnull, + unquantize_i4r4(nrow + (infptr->Fptr)->dither_seed - 1, idata, + tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, tnull, fnulval, bnullarray, anynul, (float *) buffer, status); else if (tiledatatype == TSHORT) - unquantize_i2r4(nrow + (infptr->Fptr)->dither_seed - 1, (short *)idata, - tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (short) tnull, + unquantize_i2r4(nrow + (infptr->Fptr)->dither_seed - 1, (short *)idata, + tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (short) tnull, fnulval, bnullarray, anynul, (float *) buffer, status); else if (tiledatatype == TBYTE) - unquantize_i1r4(nrow + (infptr->Fptr)->dither_seed - 1, (unsigned char *)idata, - tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (unsigned char) tnull, + unquantize_i1r4(nrow + (infptr->Fptr)->dither_seed - 1, (unsigned char *)idata, + tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (unsigned char) tnull, fnulval, bnullarray, anynul, (float *) buffer, status); @@ -6603,64 +6603,64 @@ int imcomp_decompress_tile (fitsfile *infptr, if (tiledatatype == TINT) if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4r4(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, fnulval, bnullarray, anynul, (float *) buffer, status); } else { - fffi4r4(idata, tilelen, bscale, bzero, nullcheck, tnull, + fffi4r4(idata, tilelen, bscale, bzero, nullcheck, tnull, fnulval, bnullarray, anynul, (float *) buffer, status); } else if (tiledatatype == TSHORT) - fffi2r4((short *)idata, tilelen, bscale, bzero, nullcheck, (short) tnull, + fffi2r4((short *)idata, tilelen, bscale, bzero, nullcheck, (short) tnull, fnulval, bnullarray, anynul, (float *) buffer, status); else if (tiledatatype == TBYTE) fffi1r4((unsigned char *)idata, tilelen, bscale, bzero, nullcheck, (unsigned char) tnull, fnulval, bnullarray, anynul, (float *) buffer, status); - } + } } else if (datatype == TDOUBLE) { pixlen = sizeof(double); if (nulval) { - dnulval = *(double *) nulval; - } + dnulval = *(double *) nulval; + } - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ if (tiledatatype == TINT) { - fffr4r8((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4r8((float *) idata, tilelen, bscale, bzero, nullcheck, dnulval, bnullarray, anynul, (double *) buffer, status); } else { - fffr8r8((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8r8((double *) idata, tilelen, bscale, bzero, nullcheck, dnulval, bnullarray, anynul, (double *) buffer, status); } - - } else if ((infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_1 || - (infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { + + } else if ((infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_1 || + (infptr->Fptr)->quantize_method == SUBTRACTIVE_DITHER_2) { /* use the new dithering algorithm (introduced in July 2009) */ if (tiledatatype == TINT) unquantize_i4r8(nrow + (infptr->Fptr)->dither_seed - 1, idata, - tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, tnull, + tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, tnull, dnulval, bnullarray, anynul, (double *) buffer, status); else if (tiledatatype == TSHORT) unquantize_i2r8(nrow + (infptr->Fptr)->dither_seed - 1, (short *)idata, - tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (short) tnull, + tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (short) tnull, dnulval, bnullarray, anynul, (double *) buffer, status); else if (tiledatatype == TBYTE) unquantize_i1r8(nrow + (infptr->Fptr)->dither_seed - 1, (unsigned char *)idata, - tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (unsigned char) tnull, + tilelen, bscale, bzero, (infptr->Fptr)->quantize_method, nullcheck, (unsigned char) tnull, dnulval, bnullarray, anynul, (double *) buffer, status); @@ -6668,8 +6668,8 @@ int imcomp_decompress_tile (fitsfile *infptr, if (tiledatatype == TINT) { if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4r8(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, dnulval, bnullarray, anynul, (double *) buffer, status); @@ -6686,7 +6686,7 @@ int imcomp_decompress_tile (fitsfile *infptr, fffi1r8((unsigned char *)idata, tilelen, bscale, bzero, nullcheck, (unsigned char) tnull, dnulval, bnullarray, anynul, (double *) buffer, status); - } + } } else if (datatype == TBYTE) { @@ -6724,23 +6724,23 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(short); - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4u2((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4u2((float *) idata, tilelen, bscale, bzero, nullcheck, *(unsigned short *) nulval, bnullarray, anynul, (unsigned short *) buffer, status); } else { - fffr8u2((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8u2((double *) idata, tilelen, bscale, bzero, nullcheck, *(unsigned short *) nulval, bnullarray, anynul, (unsigned short *) buffer, status); } } else if (tiledatatype == TINT) if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4u2(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, *(unsigned short *) nulval, bnullarray, anynul, (unsigned short *) buffer, status); @@ -6762,24 +6762,24 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(int); - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4uint((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4uint((float *) idata, tilelen, bscale, bzero, nullcheck, *(unsigned int *) nulval, bnullarray, anynul, (unsigned int *) buffer, status); } else { - fffr8uint((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8uint((double *) idata, tilelen, bscale, bzero, nullcheck, *(unsigned int *) nulval, bnullarray, anynul, (unsigned int *) buffer, status); } } else if (tiledatatype == TINT) if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4uint(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, *(unsigned int *) nulval, bnullarray, anynul, (unsigned int *) buffer, status); @@ -6801,38 +6801,38 @@ int imcomp_decompress_tile (fitsfile *infptr, { pixlen = sizeof(long); - if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { - /* the floating point pixels were losselessly compressed with GZIP */ - /* Just have to copy the values to the output array */ - + if ((infptr->Fptr)->quantize_level == NO_QUANTIZE) { + /* the floating point pixels were losselessly compressed with GZIP */ + /* Just have to copy the values to the output array */ + if (tiledatatype == TINT) { - fffr4u4((float *) idata, tilelen, bscale, bzero, nullcheck, + fffr4u4((float *) idata, tilelen, bscale, bzero, nullcheck, *(unsigned long *) nulval, bnullarray, anynul, (unsigned long *) buffer, status); } else { - fffr8u4((double *) idata, tilelen, bscale, bzero, nullcheck, + fffr8u4((double *) idata, tilelen, bscale, bzero, nullcheck, *(unsigned long *) nulval, bnullarray, anynul, (unsigned long *) buffer, status); } } else if (tiledatatype == TINT) if ((infptr->Fptr)->compress_type == PLIO_1 && actual_bzero == 32768.) { - /* special case where unsigned 16-bit integers have been */ - /* offset by +32768 when using PLIO */ + /* special case where unsigned 16-bit integers have been */ + /* offset by +32768 when using PLIO */ fffi4u4(idata, tilelen, bscale, bzero - 32768., nullcheck, tnull, *(unsigned long *) nulval, bnullarray, anynul, (unsigned long *) buffer, status); } else { fffi4u4(idata, tilelen, bscale, bzero, nullcheck, tnull, - *(unsigned long *) nulval, bnullarray, anynul, + *(unsigned long *) nulval, bnullarray, anynul, (unsigned long *) buffer, status); } else if (tiledatatype == TSHORT) fffi2u4((short *)idata, tilelen, bscale, bzero, nullcheck, (short) tnull, - *(unsigned long *) nulval, bnullarray, anynul, + *(unsigned long *) nulval, bnullarray, anynul, (unsigned long *) buffer, status); else if (tiledatatype == TBYTE) fffi1u4((unsigned char *)idata, tilelen, bscale, bzero, nullcheck, (unsigned char) tnull, - *(unsigned long *) nulval, bnullarray, anynul, + *(unsigned long *) nulval, bnullarray, anynul, (unsigned long *) buffer, status); } else @@ -6843,11 +6843,11 @@ int imcomp_decompress_tile (fitsfile *infptr, /* **************************************************************** */ /* cache the tile, in case the application wants it again */ - /* Don't cache the tile if tile is a single row of the image; + /* Don't cache the tile if tile is a single row of the image; it is less likely that the cache will be used in this cases, - so it is not worth the time and the memory overheads. + so it is not worth the time and the memory overheads. */ - + if ((infptr->Fptr)->tilerow) { /* make sure cache has been allocated */ if ((infptr->Fptr)->znaxis[0] != (infptr->Fptr)->tilesize[0] || (infptr->Fptr)->tilesize[1] != 1 ) @@ -6859,28 +6859,28 @@ int imcomp_decompress_tile (fitsfile *infptr, datatype != (infptr->Fptr)->tiletype[tilecol] ) { if (((infptr->Fptr)->tiledata)[tilecol]) { - free(((infptr->Fptr)->tiledata)[tilecol]); + free(((infptr->Fptr)->tiledata)[tilecol]); } - + if (((infptr->Fptr)->tilenullarray)[tilecol]) { free(((infptr->Fptr)->tilenullarray)[tilecol]); } - + ((infptr->Fptr)->tilenullarray)[tilecol] = 0; ((infptr->Fptr)->tilerow)[tilecol] = 0; ((infptr->Fptr)->tiledatasize)[tilecol] = 0; ((infptr->Fptr)->tiletype)[tilecol] = 0; /* allocate new array(s) */ - ((infptr->Fptr)->tiledata)[tilecol] = malloc(tilesize); + ((infptr->Fptr)->tiledata)[tilecol] = malloc(tilesize); - if (((infptr->Fptr)->tiledata)[tilecol] == 0) - return (*status); + if (((infptr->Fptr)->tiledata)[tilecol] == 0) + return (*status); if (nullcheck == 2) { /* also need array of null pixel flags */ - (infptr->Fptr)->tilenullarray[tilecol] = malloc(tilelen); - if ((infptr->Fptr)->tilenullarray[tilecol] == 0) - return (*status); + (infptr->Fptr)->tilenullarray[tilecol] = malloc(tilelen); + if ((infptr->Fptr)->tilenullarray[tilecol] == 0) + return (*status); } (infptr->Fptr)->tiledatasize[tilecol] = tilesize; @@ -6891,8 +6891,8 @@ int imcomp_decompress_tile (fitsfile *infptr, memcpy((infptr->Fptr)->tiledata[tilecol], buffer, tilesize); if (nullcheck == 2) { - if ((infptr->Fptr)->tilenullarray == 0) { - (infptr->Fptr)->tilenullarray[tilecol] = malloc(tilelen); + if ((infptr->Fptr)->tilenullarray == 0) { + (infptr->Fptr)->tilenullarray[tilecol] = malloc(tilelen); } memcpy((infptr->Fptr)->tilenullarray[tilecol], bnullarray, tilelen); } @@ -6913,9 +6913,9 @@ int imcomp_test_overlap ( long *ininc, /* I - increment to be applied in each image dimen. */ int *status) -/* +/* test if there are any intersecting pixels between this tile and the section - of the image defined by fixel, lpixel, ininc. + of the image defined by fixel, lpixel, ininc. */ { long imgdim[MAX_COMPRESS_DIM]; /* product of preceding dimensions in the */ @@ -6940,7 +6940,7 @@ int imcomp_test_overlap ( /* calc amount of overlap in each dimension; if there is zero */ /* overlap in any dimension then just return */ /* ------------------------------------------------------------ */ - + for (ii = 0; ii < ndim; ii++) { if (tlpixel[ii] < fpixel[ii] || tfpixel[ii] > lpixel[ii]) @@ -7016,12 +7016,12 @@ int imcomp_copy_overlap ( long *lpixel, /* I - last pixel number in each dim. of the image */ long *ininc, /* I - increment to be applied in each image dimen. */ int nullcheck, /* I - 0, 1: do nothing; 2: set nullarray for nulls */ - char *nullarray, + char *nullarray, int *status) -/* - copy the intersecting pixels from a decompressed tile to the output image. - Both the tile and the image must have the same number of dimensions. +/* + copy the intersecting pixels from a decompressed tile to the output image. + Both the tile and the image must have the same number of dimensions. */ { long imgdim[MAX_COMPRESS_DIM]; /* product of preceding dimensions in the */ @@ -7061,7 +7061,7 @@ int imcomp_copy_overlap ( /* calc amount of overlap in each dimension; if there is zero */ /* overlap in any dimension then just return */ /* ------------------------------------------------------------ */ - + for (ii = 0; ii < ndim; ii++) { if (tlpixel[ii] < fpixel[ii] || tfpixel[ii] > lpixel[ii]) @@ -7256,7 +7256,7 @@ int imcomp_merge_overlap ( int nullcheck, /* I - 0, 1: do nothing; 2: set nullarray for nulls */ int *status) -/* +/* Similar to imcomp_copy_overlap, except it copies the overlapping pixels from the 'image' to the 'tile'. */ @@ -7298,7 +7298,7 @@ int imcomp_merge_overlap ( /* calc amount of overlap in each dimension; if there is zero */ /* overlap in any dimension then just return */ /* ------------------------------------------------------------ */ - + for (ii = 0; ii < ndim; ii++) { if (tlpixel[ii] < fpixel[ii] || tfpixel[ii] > lpixel[ii]) @@ -7493,7 +7493,7 @@ static int unquantize_i1r4(long row, /* tile number = row number in table */ long ii; int nextrand, iseed; - if (!fits_rand_value) + if (!fits_rand_value) if (fits_init_randoms()) return(MEMORY_ALLOCATION); /* initialize the index to the next random number in the list */ @@ -7505,18 +7505,18 @@ static int unquantize_i1r4(long row, /* tile number = row number in table */ for (ii = 0; ii < ntodo; ii++) { /* - if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) + output[ii] = 0.0; + else */ output[ii] = (float) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } else /* must check for null values */ @@ -7534,18 +7534,18 @@ static int unquantize_i1r4(long row, /* tile number = row number in table */ else { /* - if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) + output[ii] = 0.0; + else */ output[ii] = (float) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - } + } - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); } } } @@ -7575,7 +7575,7 @@ static int unquantize_i2r4(long row, /* seed for random values */ long ii; int nextrand, iseed; - if (!fits_rand_value) + if (!fits_rand_value) if (fits_init_randoms()) return(MEMORY_ALLOCATION); /* initialize the index to the next random number in the list */ @@ -7587,18 +7587,18 @@ static int unquantize_i2r4(long row, /* seed for random values */ for (ii = 0; ii < ntodo; ii++) { /* - if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) + output[ii] = 0.0; + else */ output[ii] = (float) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } else /* must check for null values */ @@ -7617,18 +7617,18 @@ static int unquantize_i2r4(long row, /* seed for random values */ { /* if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else */ output[ii] = (float) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); } - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } @@ -7657,7 +7657,7 @@ static int unquantize_i4r4(long row, /* tile number = row number in table */ long ii; int nextrand, iseed; - if (fits_rand_value == 0) + if (fits_rand_value == 0) if (fits_init_randoms()) return(MEMORY_ALLOCATION); /* initialize the index to the next random number in the list */ @@ -7669,16 +7669,16 @@ static int unquantize_i4r4(long row, /* tile number = row number in table */ for (ii = 0; ii < ntodo; ii++) { if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else output[ii] = (float) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } else /* must check for null values */ @@ -7696,17 +7696,17 @@ static int unquantize_i4r4(long row, /* tile number = row number in table */ else { if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else output[ii] = (float) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); } - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } @@ -7735,7 +7735,7 @@ static int unquantize_i1r8(long row, /* tile number = row number in table */ long ii; int nextrand, iseed; - if (!fits_rand_value) + if (!fits_rand_value) if (fits_init_randoms()) return(MEMORY_ALLOCATION); /* initialize the index to the next random number in the list */ @@ -7748,17 +7748,17 @@ static int unquantize_i1r8(long row, /* tile number = row number in table */ { /* if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else */ output[ii] = (double) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } else /* must check for null values */ @@ -7777,18 +7777,18 @@ static int unquantize_i1r8(long row, /* tile number = row number in table */ { /* if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else */ output[ii] = (double) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); } - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } @@ -7817,7 +7817,7 @@ static int unquantize_i2r8(long row, /* tile number = row number in table */ long ii; int nextrand, iseed; - if (!fits_rand_value) + if (!fits_rand_value) if (fits_init_randoms()) return(MEMORY_ALLOCATION); /* initialize the index to the next random number in the list */ @@ -7830,17 +7830,17 @@ static int unquantize_i2r8(long row, /* tile number = row number in table */ { /* if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else */ output[ii] = (double) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } else /* must check for null values */ @@ -7858,18 +7858,18 @@ static int unquantize_i2r8(long row, /* tile number = row number in table */ else { /* if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else */ output[ii] = (double) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); } - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } @@ -7898,7 +7898,7 @@ static int unquantize_i4r8(long row, /* tile number = row number in table */ long ii; int nextrand, iseed; - if (fits_rand_value == 0) + if (fits_rand_value == 0) if (fits_init_randoms()) return(MEMORY_ALLOCATION); /* initialize the index to the next random number in the list */ @@ -7910,16 +7910,16 @@ static int unquantize_i4r8(long row, /* tile number = row number in table */ for (ii = 0; ii < ntodo; ii++) { if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else output[ii] = (double) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } else /* must check for null values */ @@ -7937,27 +7937,27 @@ static int unquantize_i4r8(long row, /* tile number = row number in table */ else { if (dither_method == SUBTRACTIVE_DITHER_2 && input[ii] == ZERO_VALUE) - output[ii] = 0.0; - else + output[ii] = 0.0; + else output[ii] = (double) (((double) input[ii] - fits_rand_value[nextrand] + 0.5) * scale + zero); } - nextrand++; - if (nextrand == N_RANDOM) { - iseed++; - if (iseed == N_RANDOM) iseed = 0; - nextrand = (int) (fits_rand_value[iseed] * 500); - } + nextrand++; + if (nextrand == N_RANDOM) { + iseed++; + if (iseed == N_RANDOM) iseed = 0; + nextrand = (int) (fits_rand_value[iseed] * 500); + } } } return(*status); } /*--------------------------------------------------------------------------*/ -static int imcomp_float2nan(float *indata, +static int imcomp_float2nan(float *indata, long tilelen, int *outdata, - float nullflagval, + float nullflagval, int *status) /* convert pixels that are equal to nullflag to NaNs. @@ -7965,7 +7965,7 @@ static int imcomp_float2nan(float *indata, */ { int ii; - + for (ii = 0; ii < tilelen; ii++) { if (indata[ii] == nullflagval) @@ -7975,10 +7975,10 @@ static int imcomp_float2nan(float *indata, return(*status); } /*--------------------------------------------------------------------------*/ -static int imcomp_double2nan(double *indata, +static int imcomp_double2nan(double *indata, long tilelen, LONGLONG *outdata, - double nullflagval, + double nullflagval, int *status) /* convert pixels that are equal to nullflag to NaNs. @@ -7986,7 +7986,7 @@ static int imcomp_double2nan(double *indata, */ { int ii; - + for (ii = 0; ii < tilelen; ii++) { if (indata[ii] == nullflagval) @@ -8005,32 +8005,32 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* Compress the input FITS Binary Table. - + First divide the table into equal sized chunks (analogous to image tiles) where all the contain the same number of rows (except perhaps for the last chunk which may contain fewer rows). The chunks should not be too large to copy into memory (currently, about 100 MB max seems a reasonable size). - + Then, on a chunk by piece basis, do the following: - + 1. Transpose the table from its original row-major order, into column-major order. All the bytes for each column are then continuous. In addition, the bytes within each table element may be shuffled so that the most significant byte of every element occurs first in the array, followed by the next most significant byte, and so on to the least significant byte. Byte shuffling often improves the gzip compression of floating-point arrays. - + 2. Compress the contiguous array of bytes in each column using the specified compression method. If no method is specifed, then a default method for that - data type is chosen. - + data type is chosen. + 3. Store the compressed stream of bytes into a column that has the same name as in the input table, but which has a variable-length array data type (1QB). The output table will contain one row for each piece of the original table. - + 4. If the input table contain variable-length arrays, then each VLA is compressed individually, and written to the heap in the output table. - Note that the output table will contain 2 sets of pointers for each VLA column. + Note that the output table will contain 2 sets of pointers for each VLA column. The first set contains the pointers to the uncompressed VLAs from the input table and the second is the set of pointers to the compressed VLAs in the output table. The latter set of pointers is used to reconstruct table when it is uncompressed, @@ -8038,12 +8038,12 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) sets of pointers are concatinated together, compressed with gzip, and written to the output table. When reading the compressed table, the only VLA that is directly visible is this compressed array of descriptors. One has to uncompress this array - to be able to to read all the descriptors to the individual VLAs in the column. + to be able to to read all the descriptors to the individual VLAs in the column. */ -{ +{ long maxchunksize = 10000000; /* default value for the size of each chunk of the table */ - char *cm_buffer; /* memory buffer for the transposed, Column-Major, chunk of the table */ + char *cm_buffer; /* memory buffer for the transposed, Column-Major, chunk of the table */ LONGLONG cm_colstart[1000]; /* starting offset of each column in the cm_buffer */ LONGLONG rm_repeat[1000]; /* repeat count of each column in the input row-major table */ LONGLONG rm_colwidth[999]; /* width in bytes of each column in the input row-major table */ @@ -8069,7 +8069,7 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* ================================================================================== */ /* perform initial sanity checks */ /* ================================================================================== */ - + /* special input flag value that means print out diagnostics */ if (*status == -999) { print_report = 1; @@ -8078,7 +8078,7 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) if (*status > 0) return(*status); - + fits_get_hdu_type(infptr, &hdutype, status); if (hdutype != BINARY_TBL) { *status = NOT_BTABLE; @@ -8105,40 +8105,40 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) tstatus = 0; if (!fits_read_key(infptr, TSTRING, "FZALGOR", tempstring, NULL, &tstatus)) { - if (!fits_strcasecmp(tempstring, "NONE")) { - default_algor = NOCOMPRESS; - } else if (!fits_strcasecmp(tempstring, "GZIP") || !fits_strcasecmp(tempstring, "GZIP_1")) { - default_algor = GZIP_1; - } else if (!fits_strcasecmp(tempstring, "GZIP_2")) { - default_algor = GZIP_2; - } else if (!fits_strcasecmp(tempstring, "RICE_1")) { - default_algor = RICE_1; - } else { - ffpmsg("FZALGOR specifies unsupported table compression algorithm:"); - ffpmsg(tempstring); - *status = DATA_COMPRESSION_ERR; - return(*status); - } + if (!fits_strcasecmp(tempstring, "NONE")) { + default_algor = NOCOMPRESS; + } else if (!fits_strcasecmp(tempstring, "GZIP") || !fits_strcasecmp(tempstring, "GZIP_1")) { + default_algor = GZIP_1; + } else if (!fits_strcasecmp(tempstring, "GZIP_2")) { + default_algor = GZIP_2; + } else if (!fits_strcasecmp(tempstring, "RICE_1")) { + default_algor = RICE_1; + } else { + ffpmsg("FZALGOR specifies unsupported table compression algorithm:"); + ffpmsg(tempstring); + *status = DATA_COMPRESSION_ERR; + return(*status); + } } /* just copy the HDU verbatim if the table has 0 columns or rows or if the table */ /* is less than 5760 bytes (2 blocks) in size, or compression directive keyword = "NONE" */ if (nrows < 1 || ncols < 1 || (dataend - datastart) < 5760 || default_algor == NOCOMPRESS) { - fits_copy_hdu (infptr, outfptr, 0, status); - return(*status); + fits_copy_hdu (infptr, outfptr, 0, status); + return(*status); } - + /* Check if the chunk size has been specified with the FZTILELN keyword. */ /* If not, calculate a default number of rows per chunck, */ tstatus = 0; if (fits_read_key(infptr, TLONG, "FZTILELN", &rowspertile, NULL, &tstatus)) { - rowspertile = (long) (maxchunksize / naxis1); + rowspertile = (long) (maxchunksize / naxis1); } - if (rowspertile < 1) rowspertile = 1; + if (rowspertile < 1) rowspertile = 1; if (rowspertile > nrows) rowspertile = (long) nrows; - + nchunks = (long) ((nrows - 1) / rowspertile + 1); /* total number of chunks */ lastrows = (long) (nrows - ((nchunks - 1) * rowspertile)); /* number of rows in last chunk */ @@ -8161,7 +8161,7 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) fits_read_card(outfptr, "NAXIS1", card, status); /* copy NAXIS1 to ZNAXIS1 */ strncpy(card, "ZNAXIS1", 7); fits_write_record(outfptr, card, status); - + fits_read_card(outfptr, "NAXIS2", card, status); /* copy NAXIS2 to ZNAXIS2 */ strncpy(card, "ZNAXIS2", 7); fits_write_record(outfptr, card, status); @@ -8173,7 +8173,7 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) fits_modify_key_lng(outfptr, "NAXIS2", nchunks, "&", status); /* 1 row per chunk */ fits_modify_key_lng(outfptr, "NAXIS1", ncols * 16, "&", status); /* 16 bytes for each 1QB column */ fits_modify_key_lng(outfptr, "PCOUNT", 0L, "&", status); /* reset PCOUNT to 0 */ - + /* rename the Checksum keywords, if they exist */ tstatus = 0; fits_modify_name(outfptr, "CHECKSUM", "ZHECKSUM", &tstatus); @@ -8188,90 +8188,90 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* ================================================================================== */ cm_colstart[0] = 0; - for (ii = 0; ii < ncols; ii++) { + for (ii = 0; ii < ncols; ii++) { - /* get the structural parameters of the original uncompressed column */ - fits_make_keyn("TFORM", ii+1, keyname, status); - fits_read_key(outfptr, TSTRING, keyname, tform, comm, status); + /* get the structural parameters of the original uncompressed column */ + fits_make_keyn("TFORM", ii+1, keyname, status); + fits_read_key(outfptr, TSTRING, keyname, tform, comm, status); fits_binary_tform(tform, coltype+ii, &repeat, &width, status); /* get the repeat count and the width */ - /* preserve the original TFORM value and comment string in a ZFORMn keyword */ - fits_read_card(outfptr, keyname, card, status); - card[0] = 'Z'; - fits_write_record(outfptr, card, status); - + /* preserve the original TFORM value and comment string in a ZFORMn keyword */ + fits_read_card(outfptr, keyname, card, status); + card[0] = 'Z'; + fits_write_record(outfptr, card, status); + /* All columns in the compressed table will have a variable-length array type. */ - fits_modify_key_str(outfptr, keyname, "1QB", "&", status); /* Use 'Q' pointers (64-bit) */ - - /* deal with special cases: bit, string, and variable length array columns */ - if (coltype[ii] == TBIT) { - repeat = (repeat + 7) / 8; /* convert from bits to equivalent number of bytes */ - } else if (coltype[ii] == TSTRING) { - width = 1; /* ignore the optional 'w' in 'rAw' format */ - } else if (coltype[ii] < 0) { /* pointer to variable length array */ - if (strchr(tform,'Q') ) { - width = 16; /* 'Q' descriptor has 64-bit pointers */ - } else { - width = 8; /* 'P' descriptor has 32-bit pointers */ - } - repeat = 1; - } - - rm_repeat[ii] = repeat; - rm_colwidth[ii] = repeat * width; /* column width (in bytes)in the input table */ - - /* starting offset of each field in the OUTPUT transposed column-major table */ - cm_colstart[ii + 1] = cm_colstart[ii] + rm_colwidth[ii] * rowspertile; - /* total number of elements in each column of the transposed column-major table */ - cm_repeat[ii] = rm_repeat[ii] * rowspertile; - - compalgor[ii] = default_algor; /* initialize the column compression algorithm to the default */ - - /* check if a compression method has been specified for this column */ - fits_make_keyn("FZALG", ii+1, keyname, status); - tstatus = 0; - if (!fits_read_key(outfptr, TSTRING, keyname, tempstring, NULL, &tstatus)) { - - if (!fits_strcasecmp(tempstring, "GZIP") || !fits_strcasecmp(tempstring, "GZIP_1")) { - compalgor[ii] = GZIP_1; - } else if (!fits_strcasecmp(tempstring, "GZIP_2")) { - compalgor[ii] = GZIP_2; - } else if (!fits_strcasecmp(tempstring, "RICE_1")) { - compalgor[ii] = RICE_1; - } else { - ffpmsg("Unsupported table compression algorithm specification."); - ffpmsg(keyname); - ffpmsg(tempstring); - *status = DATA_COMPRESSION_ERR; - free(cm_buffer); - return(*status); - } - } - - /* do sanity check of the requested algorithm and override if necessary */ - if ( abs(coltype[ii]) == TLOGICAL || abs(coltype[ii]) == TBIT || abs(coltype[ii]) == TSTRING) { - if (compalgor[ii] != GZIP_1) { - compalgor[ii] = GZIP_1; - } - } else if ( abs(coltype[ii]) == TCOMPLEX || abs(coltype[ii]) == TDBLCOMPLEX || - abs(coltype[ii]) == TFLOAT || abs(coltype[ii]) == TDOUBLE || - abs(coltype[ii]) == TLONGLONG ) { - if (compalgor[ii] != GZIP_1 && compalgor[ii] != GZIP_2) { - compalgor[ii] = GZIP_2; /* gzip_2 usually works better gzip_1 */ - } - } else if ( abs(coltype[ii]) == TSHORT ) { - if (compalgor[ii] != GZIP_1 && compalgor[ii] != GZIP_2 && compalgor[ii] != RICE_1) { - compalgor[ii] = GZIP_2; /* gzip_2 usually works better rice_1 */ - } - } else if ( abs(coltype[ii]) == TLONG ) { - if (compalgor[ii] != GZIP_1 && compalgor[ii] != GZIP_2 && compalgor[ii] != RICE_1) { - compalgor[ii] = RICE_1; - } - } else if ( abs(coltype[ii]) == TBYTE ) { - if (compalgor[ii] != GZIP_1 && compalgor[ii] != RICE_1 ) { - compalgor[ii] = GZIP_1; - } - } + fits_modify_key_str(outfptr, keyname, "1QB", "&", status); /* Use 'Q' pointers (64-bit) */ + + /* deal with special cases: bit, string, and variable length array columns */ + if (coltype[ii] == TBIT) { + repeat = (repeat + 7) / 8; /* convert from bits to equivalent number of bytes */ + } else if (coltype[ii] == TSTRING) { + width = 1; /* ignore the optional 'w' in 'rAw' format */ + } else if (coltype[ii] < 0) { /* pointer to variable length array */ + if (strchr(tform,'Q') ) { + width = 16; /* 'Q' descriptor has 64-bit pointers */ + } else { + width = 8; /* 'P' descriptor has 32-bit pointers */ + } + repeat = 1; + } + + rm_repeat[ii] = repeat; + rm_colwidth[ii] = repeat * width; /* column width (in bytes)in the input table */ + + /* starting offset of each field in the OUTPUT transposed column-major table */ + cm_colstart[ii + 1] = cm_colstart[ii] + rm_colwidth[ii] * rowspertile; + /* total number of elements in each column of the transposed column-major table */ + cm_repeat[ii] = rm_repeat[ii] * rowspertile; + + compalgor[ii] = default_algor; /* initialize the column compression algorithm to the default */ + + /* check if a compression method has been specified for this column */ + fits_make_keyn("FZALG", ii+1, keyname, status); + tstatus = 0; + if (!fits_read_key(outfptr, TSTRING, keyname, tempstring, NULL, &tstatus)) { + + if (!fits_strcasecmp(tempstring, "GZIP") || !fits_strcasecmp(tempstring, "GZIP_1")) { + compalgor[ii] = GZIP_1; + } else if (!fits_strcasecmp(tempstring, "GZIP_2")) { + compalgor[ii] = GZIP_2; + } else if (!fits_strcasecmp(tempstring, "RICE_1")) { + compalgor[ii] = RICE_1; + } else { + ffpmsg("Unsupported table compression algorithm specification."); + ffpmsg(keyname); + ffpmsg(tempstring); + *status = DATA_COMPRESSION_ERR; + free(cm_buffer); + return(*status); + } + } + + /* do sanity check of the requested algorithm and override if necessary */ + if ( abs(coltype[ii]) == TLOGICAL || abs(coltype[ii]) == TBIT || abs(coltype[ii]) == TSTRING) { + if (compalgor[ii] != GZIP_1) { + compalgor[ii] = GZIP_1; + } + } else if ( abs(coltype[ii]) == TCOMPLEX || abs(coltype[ii]) == TDBLCOMPLEX || + abs(coltype[ii]) == TFLOAT || abs(coltype[ii]) == TDOUBLE || + abs(coltype[ii]) == TLONGLONG ) { + if (compalgor[ii] != GZIP_1 && compalgor[ii] != GZIP_2) { + compalgor[ii] = GZIP_2; /* gzip_2 usually works better gzip_1 */ + } + } else if ( abs(coltype[ii]) == TSHORT ) { + if (compalgor[ii] != GZIP_1 && compalgor[ii] != GZIP_2 && compalgor[ii] != RICE_1) { + compalgor[ii] = GZIP_2; /* gzip_2 usually works better rice_1 */ + } + } else if ( abs(coltype[ii]) == TLONG ) { + if (compalgor[ii] != GZIP_1 && compalgor[ii] != GZIP_2 && compalgor[ii] != RICE_1) { + compalgor[ii] = RICE_1; + } + } else if ( abs(coltype[ii]) == TBYTE ) { + if (compalgor[ii] != GZIP_1 && compalgor[ii] != RICE_1 ) { + compalgor[ii] = GZIP_1; + } + } } /* end of loop over columns */ /* ================================================================================== */ @@ -8284,78 +8284,78 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) for (ll = 0; ll < nchunks; ll++) { if (ll == nchunks - 1) { /* the last chunk may have fewer rows */ - rowspertile = lastrows; - for (ii = 0; ii < ncols; ii++) { - cm_colstart[ii + 1] = cm_colstart[ii] + (rm_colwidth[ii] * rowspertile); - cm_repeat[ii] = rm_repeat[ii] * rowspertile; - } - } + rowspertile = lastrows; + for (ii = 0; ii < ncols; ii++) { + cm_colstart[ii + 1] = cm_colstart[ii] + (rm_colwidth[ii] * rowspertile); + cm_repeat[ii] = rm_repeat[ii] * rowspertile; + } + } /* move to the start of the chunk in the input table */ ffmbyt(infptr, datastart, 0, status); /* ================================================================================*/ /* First, transpose this chunck from row-major order to column-major order */ - /* At the same time, shuffle the bytes in each datum, if doing GZIP_2 compression */ + /* At the same time, shuffle the bytes in each datum, if doing GZIP_2 compression */ /* ================================================================================*/ for (jj = 0; jj < rowspertile; jj++) { /* loop over rows */ for (ii = 0; ii < ncols; ii++) { /* loop over columns */ - + if (rm_repeat[ii] > 0) { /* skip virtual columns that have 0 elements */ - kk = 0; - - /* if the GZIP_2 compression algorithm is used, shuffle the bytes */ - if (coltype[ii] == TSHORT && compalgor[ii] == GZIP_2) { - while(kk < rm_colwidth[ii]) { - cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_repeat[ii]) + kk/2); - ffgbyt(infptr, 1, cptr, status); /* get 1st byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 2nd byte */ - kk += 2; - } - } else if ((coltype[ii] == TFLOAT || coltype[ii] == TLONG) && compalgor[ii] == GZIP_2) { - while(kk < rm_colwidth[ii]) { - cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_repeat[ii]) + kk/4); - ffgbyt(infptr, 1, cptr, status); /* get 1st byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 2nd byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 3rd byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 4th byte */ - kk += 4; - } - } else if ( (coltype[ii] == TDOUBLE || coltype[ii] == TLONGLONG) && compalgor[ii] == GZIP_2) { - while(kk < rm_colwidth[ii]) { - cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_repeat[ii]) + kk/8); - ffgbyt(infptr, 1, cptr, status); /* get 1st byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 2nd byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 3rd byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 4th byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 5th byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 6th byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 7th byte */ - cptr += cm_repeat[ii]; - ffgbyt(infptr, 1, cptr, status); /* get 8th byte */ - kk += 8; - } - } else { /* all other cases: don't shuffle the bytes; simply transpose the column */ - cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_colwidth[ii])); /* addr to copy to */ - startbyte = (infptr->Fptr)->bytepos; /* save the starting byte location */ - ffgbyt(infptr, rm_colwidth[ii], cptr, status); /* copy all the bytes */ - - if (rm_colwidth[ii] >= MINDIRECT) { /* have to explicitly move to next byte */ - ffmbyt(infptr, startbyte + rm_colwidth[ii], 0, status); - } - } /* end of test of coltypee */ + kk = 0; + + /* if the GZIP_2 compression algorithm is used, shuffle the bytes */ + if (coltype[ii] == TSHORT && compalgor[ii] == GZIP_2) { + while(kk < rm_colwidth[ii]) { + cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_repeat[ii]) + kk/2); + ffgbyt(infptr, 1, cptr, status); /* get 1st byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 2nd byte */ + kk += 2; + } + } else if ((coltype[ii] == TFLOAT || coltype[ii] == TLONG) && compalgor[ii] == GZIP_2) { + while(kk < rm_colwidth[ii]) { + cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_repeat[ii]) + kk/4); + ffgbyt(infptr, 1, cptr, status); /* get 1st byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 2nd byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 3rd byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 4th byte */ + kk += 4; + } + } else if ( (coltype[ii] == TDOUBLE || coltype[ii] == TLONGLONG) && compalgor[ii] == GZIP_2) { + while(kk < rm_colwidth[ii]) { + cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_repeat[ii]) + kk/8); + ffgbyt(infptr, 1, cptr, status); /* get 1st byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 2nd byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 3rd byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 4th byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 5th byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 6th byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 7th byte */ + cptr += cm_repeat[ii]; + ffgbyt(infptr, 1, cptr, status); /* get 8th byte */ + kk += 8; + } + } else { /* all other cases: don't shuffle the bytes; simply transpose the column */ + cptr = cm_buffer + (cm_colstart[ii] + (jj * rm_colwidth[ii])); /* addr to copy to */ + startbyte = (infptr->Fptr)->bytepos; /* save the starting byte location */ + ffgbyt(infptr, rm_colwidth[ii], cptr, status); /* copy all the bytes */ + + if (rm_colwidth[ii] >= MINDIRECT) { /* have to explicitly move to next byte */ + ffmbyt(infptr, startbyte + rm_colwidth[ii], 0, status); + } + } /* end of test of coltypee */ } /* end of not virtual column */ } /* end of loop over columns */ @@ -8366,302 +8366,302 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* ================================================================================*/ fits_set_hdustruc(outfptr, status); /* initialize structures in the output table */ - + for (ii = 0; ii < ncols; ii++) { /* loop over columns */ - /* initialize the diagnostic compression results string */ - snprintf(results[ii],30,"%3d %3d %3d ", ii+1, coltype[ii], compalgor[ii]); + /* initialize the diagnostic compression results string */ + snprintf(results[ii],30,"%3d %3d %3d ", ii+1, coltype[ii], compalgor[ii]); cratio[ii] = 0; - + if (rm_repeat[ii] > 0) { /* skip virtual columns with zero width */ - if (coltype[ii] < 0) { /* this is a variable length array (VLA) column */ + if (coltype[ii] < 0) { /* this is a variable length array (VLA) column */ + + /*=========================================================================*/ + /* variable-length array columns are a complicated special case */ + /*=========================================================================*/ - /*=========================================================================*/ - /* variable-length array columns are a complicated special case */ - /*=========================================================================*/ + /* allocate memory to hold all the VLA descriptors from the input table, plus */ + /* room to hold the descriptors to the compressed VLAs in the output table */ + /* In total, there will be 2 descriptors for each row in this chunk */ - /* allocate memory to hold all the VLA descriptors from the input table, plus */ - /* room to hold the descriptors to the compressed VLAs in the output table */ - /* In total, there will be 2 descriptors for each row in this chunk */ + uncompressed_size = 0.; + compressed_size = 0; - uncompressed_size = 0.; - compressed_size = 0; - - datasize = (size_t) (cm_colstart[ii + 1] - cm_colstart[ii]); /* size of input descriptors */ + datasize = (size_t) (cm_colstart[ii + 1] - cm_colstart[ii]); /* size of input descriptors */ - cdescript = calloc(datasize + (rowspertile * 16), 1); /* room for both descriptors */ - if (!cdescript) { + cdescript = calloc(datasize + (rowspertile * 16), 1); /* room for both descriptors */ + if (!cdescript) { ffpmsg("Could not allocate buffer for descriptors"); *status = MEMORY_ALLOCATION; - free(cm_buffer); - return(*status); - } + free(cm_buffer); + return(*status); + } - /* copy the input descriptors to this array */ - memcpy(cdescript, &cm_buffer[cm_colstart[ii]], datasize); + /* copy the input descriptors to this array */ + memcpy(cdescript, &cm_buffer[cm_colstart[ii]], datasize); #if BYTESWAPPED - /* byte-swap the integer values into the native machine representation */ - if (rm_colwidth[ii] == 16) { - ffswap8((double *) cdescript, rowspertile * 2); - } else { - ffswap4((int *) cdescript, rowspertile * 2); - } + /* byte-swap the integer values into the native machine representation */ + if (rm_colwidth[ii] == 16) { + ffswap8((double *) cdescript, rowspertile * 2); + } else { + ffswap4((int *) cdescript, rowspertile * 2); + } #endif - descriptors = (LONGLONG *) cdescript; /* use this for Q type descriptors */ - pdescriptors = (int *) cdescript; /* use this instead for or P type descriptors */ - /* pointer to the 2nd set of descriptors */ - outdescript = (LONGLONG *) (cdescript + datasize); /* this is a LONGLONG pointer */ - - for (jj = 0; jj < rowspertile; jj++) { /* loop to compress each VLA in turn */ - - if (rm_colwidth[ii] == 16) { /* if Q pointers */ - vlalen = descriptors[jj * 2]; - vlastart = descriptors[(jj * 2) + 1]; - } else { /* if P pointers */ - vlalen = (LONGLONG) pdescriptors[jj * 2]; - vlastart = (LONGLONG) pdescriptors[(jj * 2) + 1]; - } - - if (vlalen > 0) { /* skip zero-length VLAs */ - - vlamemlen = vlalen * (int) (-coltype[ii] / 10); - vlamem = (LONGLONG *) malloc((size_t) vlamemlen); /* memory for the input uncompressed VLA */ - if (!vlamem) { - ffpmsg("Could not allocate buffer for VLA"); - *status = MEMORY_ALLOCATION; - free(cdescript); free(cm_buffer); - return(*status); - } - - compmemlen = (size_t) (vlalen * ((LONGLONG) (-coltype[ii] / 10)) * 1.5); - if (compmemlen < 100) compmemlen = 100; - cvlamem = malloc(compmemlen); /* memory for the output compressed VLA */ - if (!cvlamem) { - ffpmsg("Could not allocate buffer for compressed data"); - *status = MEMORY_ALLOCATION; - free(vlamem); free(cdescript); free(cm_buffer); - return(*status); - } - - /* read the raw bytes directly from the heap, without any byte-swapping or null value detection */ - bytepos = (infptr->Fptr)->datastart + (infptr->Fptr)->heapstart + vlastart; - ffmbyt(infptr, bytepos, REPORT_EOF, status); - ffgbyt(infptr, vlamemlen, vlamem, status); /* read the bytes */ - uncompressed_size += vlamemlen; /* total size of the uncompressed VLAs */ - tot_uncompressed_size += vlamemlen; /* total size of the uncompressed file */ - - /* compress the VLA with the appropriate algorithm */ - if (compalgor[ii] == RICE_1) { - - if (-coltype[ii] == TSHORT) { + descriptors = (LONGLONG *) cdescript; /* use this for Q type descriptors */ + pdescriptors = (int *) cdescript; /* use this instead for or P type descriptors */ + /* pointer to the 2nd set of descriptors */ + outdescript = (LONGLONG *) (cdescript + datasize); /* this is a LONGLONG pointer */ + + for (jj = 0; jj < rowspertile; jj++) { /* loop to compress each VLA in turn */ + + if (rm_colwidth[ii] == 16) { /* if Q pointers */ + vlalen = descriptors[jj * 2]; + vlastart = descriptors[(jj * 2) + 1]; + } else { /* if P pointers */ + vlalen = (LONGLONG) pdescriptors[jj * 2]; + vlastart = (LONGLONG) pdescriptors[(jj * 2) + 1]; + } + + if (vlalen > 0) { /* skip zero-length VLAs */ + + vlamemlen = vlalen * (int) (-coltype[ii] / 10); + vlamem = (LONGLONG *) malloc((size_t) vlamemlen); /* memory for the input uncompressed VLA */ + if (!vlamem) { + ffpmsg("Could not allocate buffer for VLA"); + *status = MEMORY_ALLOCATION; + free(cdescript); free(cm_buffer); + return(*status); + } + + compmemlen = (size_t) (vlalen * ((LONGLONG) (-coltype[ii] / 10)) * 1.5); + if (compmemlen < 100) compmemlen = 100; + cvlamem = malloc(compmemlen); /* memory for the output compressed VLA */ + if (!cvlamem) { + ffpmsg("Could not allocate buffer for compressed data"); + *status = MEMORY_ALLOCATION; + free(vlamem); free(cdescript); free(cm_buffer); + return(*status); + } + + /* read the raw bytes directly from the heap, without any byte-swapping or null value detection */ + bytepos = (infptr->Fptr)->datastart + (infptr->Fptr)->heapstart + vlastart; + ffmbyt(infptr, bytepos, REPORT_EOF, status); + ffgbyt(infptr, vlamemlen, vlamem, status); /* read the bytes */ + uncompressed_size += vlamemlen; /* total size of the uncompressed VLAs */ + tot_uncompressed_size += vlamemlen; /* total size of the uncompressed file */ + + /* compress the VLA with the appropriate algorithm */ + if (compalgor[ii] == RICE_1) { + + if (-coltype[ii] == TSHORT) { #if BYTESWAPPED - ffswap2((short *) (vlamem), (long) vlalen); + ffswap2((short *) (vlamem), (long) vlalen); #endif - dlen = fits_rcomp_short ((short *)(vlamem), (int) vlalen, (unsigned char *) cvlamem, - (int) compmemlen, 32); - } else if (-coltype[ii] == TLONG) { + dlen = fits_rcomp_short ((short *)(vlamem), (int) vlalen, (unsigned char *) cvlamem, + (int) compmemlen, 32); + } else if (-coltype[ii] == TLONG) { #if BYTESWAPPED - ffswap4((int *) (vlamem), (long) vlalen); + ffswap4((int *) (vlamem), (long) vlalen); #endif - dlen = fits_rcomp ((int *)(vlamem), (int) vlalen, (unsigned char *) cvlamem, + dlen = fits_rcomp ((int *)(vlamem), (int) vlalen, (unsigned char *) cvlamem, (int) compmemlen, 32); - } else if (-coltype[ii] == TBYTE) { - dlen = fits_rcomp_byte ((signed char *)(vlamem), (int) vlalen, (unsigned char *) cvlamem, + } else if (-coltype[ii] == TBYTE) { + dlen = fits_rcomp_byte ((signed char *)(vlamem), (int) vlalen, (unsigned char *) cvlamem, (int) compmemlen, 32); - } else { - /* this should not happen */ - ffpmsg(" Error: cannot compress this column type with the RICE algorithm"); - free(vlamem); free(cdescript); free(cm_buffer); free(cvlamem); - *status = DATA_COMPRESSION_ERR; - return(*status); - } - } else if (compalgor[ii] == GZIP_1 || compalgor[ii] == GZIP_2){ - if (compalgor[ii] == GZIP_2 ) { /* shuffle the bytes before gzipping them */ - if ( (int) (-coltype[ii] / 10) == 2) { - fits_shuffle_2bytes((char *) vlamem, vlalen, status); - } else if ( (int) (-coltype[ii] / 10) == 4) { - fits_shuffle_4bytes((char *) vlamem, vlalen, status); - } else if ( (int) (-coltype[ii] / 10) == 8) { - fits_shuffle_8bytes((char *) vlamem, vlalen, status); - } - } - /*: gzip compress the array of bytes */ - compress2mem_from_mem( (char *) vlamem, (size_t) vlamemlen, - &cvlamem, &compmemlen, realloc, &dlen, status); - } else { - /* this should not happen */ - ffpmsg(" Error: unknown compression algorithm"); - free(vlamem); free(cdescript); free(cm_buffer); free(cvlamem); - *status = DATA_COMPRESSION_ERR; - return(*status); - } - - /* write the compressed array to the output table, but... */ - /* We use a trick of always writing the array to the same row of the output table */ - /* and then copy the descriptor into the array of descriptors that we allocated. */ - - /* First, reset the descriptor */ - fits_write_descript(outfptr, ii+1, ll+1, 0, 0, status); - - /* write the compressed VLA if it is smaller than the original, else write */ - /* the uncompressed array */ - fits_set_tscale(outfptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ - if (dlen < vlamemlen) { - fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, dlen, cvlamem, status); - compressed_size += dlen; /* total size of the compressed VLAs */ - tot_compressed_size += dlen; /* total size of the compressed file */ - } else { - if ( -coltype[ii] != TBYTE && compalgor[ii] != GZIP_1) { - /* it is probably faster to reread the raw bytes, rather than unshuffle or unswap them */ - bytepos = (infptr->Fptr)->datastart + (infptr->Fptr)->heapstart + vlastart; - ffmbyt(infptr, bytepos, REPORT_EOF, status); - ffgbyt(infptr, vlamemlen, vlamem, status); /* read the bytes */ - } - fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, vlamemlen, vlamem, status); - compressed_size += vlamemlen; /* total size of the compressed VLAs */ - tot_compressed_size += vlamemlen; /* total size of the compressed file */ - } - - /* read back the descriptor and save it in the array of descriptors */ - fits_read_descriptll(outfptr, ii + 1, ll + 1, outdescript+(jj*2), outdescript+(jj*2)+1, status); - free(cvlamem); free(vlamem); - - } /* end of vlalen > 0 */ - } /* end of loop over rows */ - - if (compressed_size != 0) - cratio[ii] = uncompressed_size / compressed_size; - - snprintf(tempstring,FLEN_VALUE," r=%6.2f",cratio[ii]); - strncat(results[ii],tempstring, 29-strlen(results[ii])); - - /* now we just have to compress the array of descriptors (both input and output) */ - /* and write them to the output table. */ - - /* allocate memory for the compressed descriptors */ - cvlamem = malloc(datasize + (rowspertile * 16) ); - if (!cvlamem) { - ffpmsg("Could not allocate buffer for compressed data"); - *status = MEMORY_ALLOCATION; - free(cdescript); free(cm_buffer); - return(*status); - } + } else { + /* this should not happen */ + ffpmsg(" Error: cannot compress this column type with the RICE algorithm"); + free(vlamem); free(cdescript); free(cm_buffer); free(cvlamem); + *status = DATA_COMPRESSION_ERR; + return(*status); + } + } else if (compalgor[ii] == GZIP_1 || compalgor[ii] == GZIP_2){ + if (compalgor[ii] == GZIP_2 ) { /* shuffle the bytes before gzipping them */ + if ( (int) (-coltype[ii] / 10) == 2) { + fits_shuffle_2bytes((char *) vlamem, vlalen, status); + } else if ( (int) (-coltype[ii] / 10) == 4) { + fits_shuffle_4bytes((char *) vlamem, vlalen, status); + } else if ( (int) (-coltype[ii] / 10) == 8) { + fits_shuffle_8bytes((char *) vlamem, vlalen, status); + } + } + /*: gzip compress the array of bytes */ + compress2mem_from_mem( (char *) vlamem, (size_t) vlamemlen, + &cvlamem, &compmemlen, realloc, &dlen, status); + } else { + /* this should not happen */ + ffpmsg(" Error: unknown compression algorithm"); + free(vlamem); free(cdescript); free(cm_buffer); free(cvlamem); + *status = DATA_COMPRESSION_ERR; + return(*status); + } + + /* write the compressed array to the output table, but... */ + /* We use a trick of always writing the array to the same row of the output table */ + /* and then copy the descriptor into the array of descriptors that we allocated. */ + + /* First, reset the descriptor */ + fits_write_descript(outfptr, ii+1, ll+1, 0, 0, status); + + /* write the compressed VLA if it is smaller than the original, else write */ + /* the uncompressed array */ + fits_set_tscale(outfptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ + if (dlen < vlamemlen) { + fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, dlen, cvlamem, status); + compressed_size += dlen; /* total size of the compressed VLAs */ + tot_compressed_size += dlen; /* total size of the compressed file */ + } else { + if ( -coltype[ii] != TBYTE && compalgor[ii] != GZIP_1) { + /* it is probably faster to reread the raw bytes, rather than unshuffle or unswap them */ + bytepos = (infptr->Fptr)->datastart + (infptr->Fptr)->heapstart + vlastart; + ffmbyt(infptr, bytepos, REPORT_EOF, status); + ffgbyt(infptr, vlamemlen, vlamem, status); /* read the bytes */ + } + fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, vlamemlen, vlamem, status); + compressed_size += vlamemlen; /* total size of the compressed VLAs */ + tot_compressed_size += vlamemlen; /* total size of the compressed file */ + } + + /* read back the descriptor and save it in the array of descriptors */ + fits_read_descriptll(outfptr, ii + 1, ll + 1, outdescript+(jj*2), outdescript+(jj*2)+1, status); + free(cvlamem); free(vlamem); + + } /* end of vlalen > 0 */ + } /* end of loop over rows */ + + if (compressed_size != 0) + cratio[ii] = uncompressed_size / compressed_size; + + snprintf(tempstring,FLEN_VALUE," r=%6.2f",cratio[ii]); + strncat(results[ii],tempstring, 29-strlen(results[ii])); + + /* now we just have to compress the array of descriptors (both input and output) */ + /* and write them to the output table. */ + + /* allocate memory for the compressed descriptors */ + cvlamem = malloc(datasize + (rowspertile * 16) ); + if (!cvlamem) { + ffpmsg("Could not allocate buffer for compressed data"); + *status = MEMORY_ALLOCATION; + free(cdescript); free(cm_buffer); + return(*status); + } #if BYTESWAPPED - /* byte swap the input and output descriptors */ - if (rm_colwidth[ii] == 16) { - ffswap8((double *) cdescript, rowspertile * 2); - } else { - ffswap4((int *) cdescript, rowspertile * 2); - } - ffswap8((double *) outdescript, rowspertile * 2); + /* byte swap the input and output descriptors */ + if (rm_colwidth[ii] == 16) { + ffswap8((double *) cdescript, rowspertile * 2); + } else { + ffswap4((int *) cdescript, rowspertile * 2); + } + ffswap8((double *) outdescript, rowspertile * 2); #endif - /* compress the array contain both sets of descriptors */ - compress2mem_from_mem((char *) cdescript, datasize + (rowspertile * 16), - &cvlamem, &datasize, realloc, &dlen, status); - - free(cdescript); - - /* write the compressed descriptors to the output column */ - fits_set_tscale(outfptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ - fits_write_descript(outfptr, ii+1, ll+1, 0, 0, status); /* First, reset the descriptor */ - fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, dlen, cvlamem, status); - free(cvlamem); - - if (ll == 0) { /* only write the ZCTYPn keyword once, while processing the first column */ - fits_make_keyn("ZCTYP", ii+1, keyname, status); - - if (compalgor[ii] == RICE_1) { - strcpy(keyvalue, "RICE_1"); - } else if (compalgor[ii] == GZIP_2) { - strcpy(keyvalue, "GZIP_2"); - } else { - strcpy(keyvalue, "GZIP_1"); - } - - fits_write_key(outfptr, TSTRING, keyname, keyvalue, - "compression algorithm for column", status); - } - - continue; /* jump to end of loop, to go to next column */ - } /* end of VLA case */ - - /* ================================================================================*/ - /* deal with all the normal fixed-length columns here */ - /* ================================================================================*/ - - /* allocate memory for the compressed data */ - datasize = (size_t) (cm_colstart[ii + 1] - cm_colstart[ii]); - cvlamem = malloc(datasize*2); - tot_uncompressed_size += datasize; - - if (!cvlamem) { + /* compress the array contain both sets of descriptors */ + compress2mem_from_mem((char *) cdescript, datasize + (rowspertile * 16), + &cvlamem, &datasize, realloc, &dlen, status); + + free(cdescript); + + /* write the compressed descriptors to the output column */ + fits_set_tscale(outfptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ + fits_write_descript(outfptr, ii+1, ll+1, 0, 0, status); /* First, reset the descriptor */ + fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, dlen, cvlamem, status); + free(cvlamem); + + if (ll == 0) { /* only write the ZCTYPn keyword once, while processing the first column */ + fits_make_keyn("ZCTYP", ii+1, keyname, status); + + if (compalgor[ii] == RICE_1) { + strcpy(keyvalue, "RICE_1"); + } else if (compalgor[ii] == GZIP_2) { + strcpy(keyvalue, "GZIP_2"); + } else { + strcpy(keyvalue, "GZIP_1"); + } + + fits_write_key(outfptr, TSTRING, keyname, keyvalue, + "compression algorithm for column", status); + } + + continue; /* jump to end of loop, to go to next column */ + } /* end of VLA case */ + + /* ================================================================================*/ + /* deal with all the normal fixed-length columns here */ + /* ================================================================================*/ + + /* allocate memory for the compressed data */ + datasize = (size_t) (cm_colstart[ii + 1] - cm_colstart[ii]); + cvlamem = malloc(datasize*2); + tot_uncompressed_size += datasize; + + if (!cvlamem) { ffpmsg("Could not allocate buffer for compressed data"); *status = MEMORY_ALLOCATION; - free(cm_buffer); - return(*status); - } + free(cm_buffer); + return(*status); + } - if (compalgor[ii] == RICE_1) { - if (coltype[ii] == TSHORT) { + if (compalgor[ii] == RICE_1) { + if (coltype[ii] == TSHORT) { #if BYTESWAPPED - ffswap2((short *) (cm_buffer + cm_colstart[ii]), datasize / 2); + ffswap2((short *) (cm_buffer + cm_colstart[ii]), datasize / 2); #endif - dlen = fits_rcomp_short ((short *)(cm_buffer + cm_colstart[ii]), datasize / 2, (unsigned char *) cvlamem, + dlen = fits_rcomp_short ((short *)(cm_buffer + cm_colstart[ii]), datasize / 2, (unsigned char *) cvlamem, datasize * 2, 32); - } else if (coltype[ii] == TLONG) { + } else if (coltype[ii] == TLONG) { #if BYTESWAPPED - ffswap4((int *) (cm_buffer + cm_colstart[ii]), datasize / 4); + ffswap4((int *) (cm_buffer + cm_colstart[ii]), datasize / 4); #endif - dlen = fits_rcomp ((int *)(cm_buffer + cm_colstart[ii]), datasize / 4, (unsigned char *) cvlamem, + dlen = fits_rcomp ((int *)(cm_buffer + cm_colstart[ii]), datasize / 4, (unsigned char *) cvlamem, datasize * 2, 32); - } else if (coltype[ii] == TBYTE) { + } else if (coltype[ii] == TBYTE) { - dlen = fits_rcomp_byte ((signed char *)(cm_buffer + cm_colstart[ii]), datasize, (unsigned char *) cvlamem, + dlen = fits_rcomp_byte ((signed char *)(cm_buffer + cm_colstart[ii]), datasize, (unsigned char *) cvlamem, datasize * 2, 32); - } else { /* this should not happen */ + } else { /* this should not happen */ ffpmsg(" Error: cannot compress this column type with the RICE algorthm"); - free(cvlamem); free(cm_buffer); - *status = DATA_COMPRESSION_ERR; - return(*status); - } - } else { - /* all other cases: gzip compress the column (bytes may have been shuffled previously) */ - compress2mem_from_mem(cm_buffer + cm_colstart[ii], datasize, - &cvlamem, &datasize, realloc, &dlen, status); - } - - if (ll == 0) { /* only write the ZCTYPn keyword once, while processing the first column */ - fits_make_keyn("ZCTYP", ii+1, keyname, status); - - if (compalgor[ii] == RICE_1) { - strcpy(keyvalue, "RICE_1"); - } else if (compalgor[ii] == GZIP_2) { - strcpy(keyvalue, "GZIP_2"); - } else { - strcpy(keyvalue, "GZIP_1"); - } - - fits_write_key(outfptr, TSTRING, keyname, keyvalue, - "compression algorithm for column", status); - } - - /* write the compressed data to the output column */ - fits_set_tscale(outfptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ - fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, dlen, cvlamem, status); - tot_compressed_size += dlen; - - free(cvlamem); /* don't need the compressed data any more */ + free(cvlamem); free(cm_buffer); + *status = DATA_COMPRESSION_ERR; + return(*status); + } + } else { + /* all other cases: gzip compress the column (bytes may have been shuffled previously) */ + compress2mem_from_mem(cm_buffer + cm_colstart[ii], datasize, + &cvlamem, &datasize, realloc, &dlen, status); + } + + if (ll == 0) { /* only write the ZCTYPn keyword once, while processing the first column */ + fits_make_keyn("ZCTYP", ii+1, keyname, status); + + if (compalgor[ii] == RICE_1) { + strcpy(keyvalue, "RICE_1"); + } else if (compalgor[ii] == GZIP_2) { + strcpy(keyvalue, "GZIP_2"); + } else { + strcpy(keyvalue, "GZIP_1"); + } + + fits_write_key(outfptr, TSTRING, keyname, keyvalue, + "compression algorithm for column", status); + } + + /* write the compressed data to the output column */ + fits_set_tscale(outfptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ + fits_write_col(outfptr, TBYTE, ii + 1, ll+1, 1, dlen, cvlamem, status); + tot_compressed_size += dlen; + + free(cvlamem); /* don't need the compressed data any more */ /* create diagnostic messages */ - if (dlen != 0) - cratio[ii] = (float) datasize / (float) dlen; /* compression ratio of the column */ + if (dlen != 0) + cratio[ii] = (float) datasize / (float) dlen; /* compression ratio of the column */ + + snprintf(tempstring,FLEN_VALUE," r=%6.2f",cratio[ii]); + strncat(results[ii],tempstring,29-strlen(results[ii])); - snprintf(tempstring,FLEN_VALUE," r=%6.2f",cratio[ii]); - strncat(results[ii],tempstring,29-strlen(results[ii])); - } /* end of not a virtual column */ } /* end of loop over columns */ @@ -8669,12 +8669,12 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) firstrow += rowspertile; /* increment first row in next chunk */ if (print_report) { - printf("\nChunk = %d\n",ll+1); - for (ii = 0; ii < ncols; ii++) { - printf("%s\n", results[ii]); - } - } - + printf("\nChunk = %d\n",ll+1); + for (ii = 0; ii < ncols; ii++) { + printf("%s\n", results[ii]); + } + } + } /* end of loop over chunks of the table */ /* =================================================================================*/ @@ -8683,12 +8683,12 @@ int fits_compress_table(fitsfile *infptr, fitsfile *outfptr, int *status) free(cm_buffer); fits_set_hdustruc(outfptr, status); /* reset internal structures */ - + if (print_report) { if (tot_compressed_size != 0) - printf("\nTotal data size (MB) %.3f -> %.3f, ratio = %.3f\n", tot_uncompressed_size/1000000., - tot_compressed_size/1000000., tot_uncompressed_size/tot_compressed_size); + printf("\nTotal data size (MB) %.3f -> %.3f, ratio = %.3f\n", tot_uncompressed_size/1000000., + tot_compressed_size/1000000., tot_uncompressed_size/tot_compressed_size); } return(*status); } @@ -8698,11 +8698,11 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* Uncompress the table that was compressed with fits_compress_table */ -{ +{ char colcode[999]; /* column data type code character */ char coltype[999]; /* column data type numeric code value */ - char *cm_buffer; /* memory buffer for the transposed, Column-Major, chunk of the table */ - char *rm_buffer; /* memory buffer for the original, Row-Major, chunk of the table */ + char *cm_buffer; /* memory buffer for the transposed, Column-Major, chunk of the table */ + char *rm_buffer; /* memory buffer for the original, Row-Major, chunk of the table */ LONGLONG nrows, rmajor_colwidth[999], rmajor_colstart[1000], cmajor_colstart[1000]; LONGLONG cmajor_repeat[999], rmajor_repeat[999], cmajor_bytespan[999], kk; LONGLONG headstart, datastart = 0, dataend, rowsremain, *descript, *qdescript = 0; @@ -8720,7 +8720,7 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* ================================================================================== */ if (*status > 0) return(*status); - + fits_get_hdu_type(infptr, &hdutype, status); if (hdutype != BINARY_TBL) { ffpmsg("This is not a binary table, so cannot uncompress it!"); @@ -8729,22 +8729,22 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) } if (fits_read_key(infptr, TLOGICAL, "ZTABLE", &tstatus, NULL, status)) { - /* just copy the HDU if the table is not compressed */ - if (infptr != outfptr) { - fits_copy_hdu (infptr, outfptr, 0, status); - } - return(*status); + /* just copy the HDU if the table is not compressed */ + if (infptr != outfptr) { + fits_copy_hdu (infptr, outfptr, 0, status); } - + return(*status); + } + fits_get_num_rowsll(infptr, &nrows, status); fits_get_num_cols(infptr, &ncols, status); if ((ncols < 1)) { - /* just copy the HDU if the table does not have more than 0 columns */ - if (infptr != outfptr) { - fits_copy_hdu (infptr, outfptr, 0, status); - } - return(*status); + /* just copy the HDU if the table does not have more than 0 columns */ + if (infptr != outfptr) { + fits_copy_hdu (infptr, outfptr, 0, status); + } + return(*status); } fits_read_key(infptr, TLONG, "ZTILELEN", &rowspertile, comm, status); @@ -8794,11 +8794,11 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) fits_read_card(outfptr, "ZNAXIS1", card, status); strncpy(card, "NAXIS1 ", 7); fits_update_card(outfptr, "NAXIS1", card, status); - + fits_read_card(outfptr, "ZNAXIS2", card, status); strncpy(card, "NAXIS2 ", 7); fits_update_card(outfptr, "NAXIS2", card, status); - + fits_read_card(outfptr, "ZPCOUNT", card, status); strncpy(card, "PCOUNT ", 7); fits_update_card(outfptr, "PCOUNT", card, status); @@ -8809,9 +8809,9 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) fits_delete_key(outfptr, "ZNAXIS2", status); fits_delete_key(outfptr, "ZPCOUNT", status); tstatus = 0; - fits_delete_key(outfptr, "CHECKSUM", &tstatus); + fits_delete_key(outfptr, "CHECKSUM", &tstatus); tstatus = 0; - fits_delete_key(outfptr, "DATASUM", &tstatus); + fits_delete_key(outfptr, "DATASUM", &tstatus); /* restore the Checksum keywords, if they exist */ tstatus = 0; fits_modify_name(outfptr, "ZHECKSUM", "CHECKSUM", &tstatus); @@ -8823,69 +8823,69 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* ================================================================================== */ for (ii = 0; ii < ncols; ii++) { - /* get the original column type, repeat count, and unit width */ - fits_make_keyn("ZFORM", ii+1, keyname, status); - fits_read_key(infptr, TSTRING, keyname, tform, comm, status); + /* get the original column type, repeat count, and unit width */ + fits_make_keyn("ZFORM", ii+1, keyname, status); + fits_read_key(infptr, TSTRING, keyname, tform, comm, status); - /* restore the original TFORM value and comment */ - fits_read_card(outfptr, keyname, card, status); - card[0] = 'T'; - keyname[0] = 'T'; - fits_update_card(outfptr, keyname, card, status); + /* restore the original TFORM value and comment */ + fits_read_card(outfptr, keyname, card, status); + card[0] = 'T'; + keyname[0] = 'T'; + fits_update_card(outfptr, keyname, card, status); - /* now delete the ZFORM keyword */ + /* now delete the ZFORM keyword */ keyname[0] = 'Z'; - fits_delete_key(outfptr, keyname, status); + fits_delete_key(outfptr, keyname, status); - cptr = tform; - while(isdigit(*cptr)) cptr++; - colcode[ii] = *cptr; /* save the column type code */ + cptr = tform; + while(isdigit(*cptr)) cptr++; + colcode[ii] = *cptr; /* save the column type code */ fits_binary_tform(tform, &inttype, &repeat, &width, status); coltype[ii] = inttype; - /* deal with special cases */ - if (abs(coltype[ii]) == TBIT) { - repeat = (repeat + 7) / 8 ; /* convert from bits to bytes */ - } else if (abs(coltype[ii]) == TSTRING) { - width = 1; - } else if (coltype[ii] < 0) { /* pointer to variable length array */ - if (colcode[ii] == 'P') - width = 8; /* this is a 'P' column */ - else - width = 16; /* this is a 'Q' not a 'P' column */ + /* deal with special cases */ + if (abs(coltype[ii]) == TBIT) { + repeat = (repeat + 7) / 8 ; /* convert from bits to bytes */ + } else if (abs(coltype[ii]) == TSTRING) { + width = 1; + } else if (coltype[ii] < 0) { /* pointer to variable length array */ + if (colcode[ii] == 'P') + width = 8; /* this is a 'P' column */ + else + width = 16; /* this is a 'Q' not a 'P' column */ addspace += 16; /* need space for a second set of Q pointers for this column */ - } + } - rmajor_repeat[ii] = repeat; + rmajor_repeat[ii] = repeat; - /* width (in bytes) of each field in the row-major table */ - rmajor_colwidth[ii] = rmajor_repeat[ii] * width; + /* width (in bytes) of each field in the row-major table */ + rmajor_colwidth[ii] = rmajor_repeat[ii] * width; - /* construct the ZCTYPn keyword name then read the keyword */ - fits_make_keyn("ZCTYP", ii+1, keyname, status); - tstatus = 0; + /* construct the ZCTYPn keyword name then read the keyword */ + fits_make_keyn("ZCTYP", ii+1, keyname, status); + tstatus = 0; fits_read_key(infptr, TSTRING, keyname, zvalue, NULL, &tstatus); - if (tstatus) { + if (tstatus) { zctype[ii] = GZIP_2; - } else { - if (!strcmp(zvalue, "GZIP_2")) { + } else { + if (!strcmp(zvalue, "GZIP_2")) { zctype[ii] = GZIP_2; - } else if (!strcmp(zvalue, "GZIP_1")) { + } else if (!strcmp(zvalue, "GZIP_1")) { zctype[ii] = GZIP_1; - } else if (!strcmp(zvalue, "RICE_1")) { + } else if (!strcmp(zvalue, "RICE_1")) { zctype[ii] = RICE_1; - } else { - ffpmsg("Unrecognized ZCTYPn keyword compression code:"); - ffpmsg(zvalue); - *status = DATA_DECOMPRESSION_ERR; - return(*status); - } - - /* delete this keyword from the uncompressed header */ - fits_delete_key(outfptr, keyname, status); - } + } else { + ffpmsg("Unrecognized ZCTYPn keyword compression code:"); + ffpmsg(zvalue); + *status = DATA_DECOMPRESSION_ERR; + return(*status); + } + + /* delete this keyword from the uncompressed header */ + fits_delete_key(outfptr, keyname, status); + } } /* rescan header keywords to reset internal table structure parameters */ @@ -8931,398 +8931,398 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) cmajor_colstart[0] = 0; for (ii = 0; ii < ncols; ii++) { - cmajor_repeat[ii] = rmajor_repeat[ii] * rowspertile; + cmajor_repeat[ii] = rmajor_repeat[ii] * rowspertile; - /* starting offset of each field in the column-major table */ + /* starting offset of each field in the column-major table */ if (coltype[ii] > 0) { /* normal fixed length column */ - cmajor_colstart[ii + 1] = cmajor_colstart[ii] + rmajor_colwidth[ii] * rowspertile; - } else { /* VLA column: reserve space for the 2nd set of Q pointers */ - cmajor_colstart[ii + 1] = cmajor_colstart[ii] + (rmajor_colwidth[ii] + 16) * rowspertile; - } - /* length of each sequence of bytes, after sorting them in signicant order */ - cmajor_bytespan[ii] = (rmajor_repeat[ii] * rowspertile); + cmajor_colstart[ii + 1] = cmajor_colstart[ii] + rmajor_colwidth[ii] * rowspertile; + } else { /* VLA column: reserve space for the 2nd set of Q pointers */ + cmajor_colstart[ii + 1] = cmajor_colstart[ii] + (rmajor_colwidth[ii] + 16) * rowspertile; + } + /* length of each sequence of bytes, after sorting them in signicant order */ + cmajor_bytespan[ii] = (rmajor_repeat[ii] * rowspertile); - /* starting offset of each field in the row-major table */ - rmajor_colstart[ii + 1] = rmajor_colstart[ii] + rmajor_colwidth[ii]; + /* starting offset of each field in the row-major table */ + rmajor_colstart[ii + 1] = rmajor_colstart[ii] + rmajor_colwidth[ii]; if (rmajor_repeat[ii] > 0) { /* ignore columns with 0 elements */ - - /* read compressed bytes from input table */ - fits_read_descript(infptr, ii + 1, ntile, &vla_repeat, &vla_address, status); - - /* allocate memory and read in the compressed bytes */ - ptr = malloc(vla_repeat); - if (!ptr) { + + /* read compressed bytes from input table */ + fits_read_descript(infptr, ii + 1, ntile, &vla_repeat, &vla_address, status); + + /* allocate memory and read in the compressed bytes */ + ptr = malloc(vla_repeat); + if (!ptr) { ffpmsg("Could not allocate buffer for uncompressed bytes"); *status = MEMORY_ALLOCATION; free(rm_buffer); free(cm_buffer); return(*status); - } + } - fits_set_tscale(infptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ - fits_read_col_byt(infptr, ii + 1, ntile, 1, vla_repeat, 0, (unsigned char *) ptr, &anynull, status); + fits_set_tscale(infptr, ii + 1, 1.0, 0.0, status); /* turn off any data scaling, first */ + fits_read_col_byt(infptr, ii + 1, ntile, 1, vla_repeat, 0, (unsigned char *) ptr, &anynull, status); cptr = cm_buffer + cmajor_colstart[ii]; - - /* size in bytes of the uncompressed column of bytes */ - fullsize = (size_t) (cmajor_colstart[ii+1] - cmajor_colstart[ii]); - switch (colcode[ii]) { + /* size in bytes of the uncompressed column of bytes */ + fullsize = (size_t) (cmajor_colstart[ii+1] - cmajor_colstart[ii]); + + switch (colcode[ii]) { - case 'I': + case 'I': - if (zctype[ii] == RICE_1) { - dlen = fits_rdecomp_short((unsigned char *)ptr, vla_repeat, (unsigned short *)cptr, - fullsize / 2, 32); + if (zctype[ii] == RICE_1) { + dlen = fits_rdecomp_short((unsigned char *)ptr, vla_repeat, (unsigned short *)cptr, + fullsize / 2, 32); #if BYTESWAPPED - ffswap2((short *) cptr, fullsize / 2); + ffswap2((short *) cptr, fullsize / 2); #endif - } else { /* gunzip the data into the correct location */ - uncompress2mem_from_mem(ptr, vla_repeat, &cptr, &fullsize, realloc, &dlen, status); - } - break; + } else { /* gunzip the data into the correct location */ + uncompress2mem_from_mem(ptr, vla_repeat, &cptr, &fullsize, realloc, &dlen, status); + } + break; - case 'J': + case 'J': - if (zctype[ii] == RICE_1) { - dlen = fits_rdecomp ((unsigned char *) ptr, vla_repeat, (unsigned int *)cptr, - fullsize / 4, 32); + if (zctype[ii] == RICE_1) { + dlen = fits_rdecomp ((unsigned char *) ptr, vla_repeat, (unsigned int *)cptr, + fullsize / 4, 32); #if BYTESWAPPED - ffswap4((int *) cptr, fullsize / 4); + ffswap4((int *) cptr, fullsize / 4); #endif - } else { /* gunzip the data into the correct location */ - uncompress2mem_from_mem(ptr, vla_repeat, &cptr, &fullsize, realloc, &dlen, status); - } - break; - - case 'B': - - if (zctype[ii] == RICE_1) { - dlen = fits_rdecomp_byte ((unsigned char *) ptr, vla_repeat, (unsigned char *)cptr, - fullsize, 32); - } else { /* gunzip the data into the correct location */ - uncompress2mem_from_mem(ptr, vla_repeat, &cptr, &fullsize, realloc, &dlen, status); - } - break; - - default: - /* all variable length array columns are included in this case */ - /* gunzip the data into the correct location in the full table buffer */ - uncompress2mem_from_mem(ptr, vla_repeat, - &cptr, &fullsize, realloc, &dlen, status); - - } /* end of switch block */ - - free(ptr); - } /* end of rmajor_repeat > 0 */ + } else { /* gunzip the data into the correct location */ + uncompress2mem_from_mem(ptr, vla_repeat, &cptr, &fullsize, realloc, &dlen, status); + } + break; + + case 'B': + + if (zctype[ii] == RICE_1) { + dlen = fits_rdecomp_byte ((unsigned char *) ptr, vla_repeat, (unsigned char *)cptr, + fullsize, 32); + } else { /* gunzip the data into the correct location */ + uncompress2mem_from_mem(ptr, vla_repeat, &cptr, &fullsize, realloc, &dlen, status); + } + break; + + default: + /* all variable length array columns are included in this case */ + /* gunzip the data into the correct location in the full table buffer */ + uncompress2mem_from_mem(ptr, vla_repeat, + &cptr, &fullsize, realloc, &dlen, status); + + } /* end of switch block */ + + free(ptr); + } /* end of rmajor_repeat > 0 */ } /* end of loop over columns */ - + /* now transpose the rows and columns (from cm_buffer to rm_buffer) */ /* move each byte, in turn, from the cm_buffer to the appropriate place in the rm_buffer */ for (ii = 0; ii < ncols; ii++) { /* loop over columns */ - ptr = (char *) (cm_buffer + cmajor_colstart[ii]); /* initialize ptr to start of the column in the cm_buffer */ + ptr = (char *) (cm_buffer + cmajor_colstart[ii]); /* initialize ptr to start of the column in the cm_buffer */ if (rmajor_repeat[ii] > 0) { /* skip columns with zero elements */ if (coltype[ii] > 0) { /* normal fixed length array columns */ if (zctype[ii] == GZIP_2) { /* need to unshuffle the bytes */ - /* recombine the byte planes for the 2-byte, 4-byte, and 8-byte numeric columns */ - switch (colcode[ii]) { - - case 'I': - /* get the 1st byte of each I*2 value */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols])); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 2; - } - } - /* get the 2nd byte of each I*2 value */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 1); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 2; - } - } - break; - - case 'J': - case 'E': - /* get the 1st byte of each 4-byte value */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols])); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 4; - } - } - /* get the 2nd byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 1); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 4; - } - } - /* get the 3rd byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 2); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 4; - } - } - /* get the 4th byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 3); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 4; - } - } - break; - - case 'D': - case 'K': - /* get the 1st byte of each 8-byte value */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols])); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 2nd byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 1); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 3rd byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 2); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 4th byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 3); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 5th byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 4); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 6th byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 5); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 7th byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 6); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - /* get the 8th byte */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 7); - for (kk = 0; kk < rmajor_repeat[ii]; kk++) { - *cptr = *ptr; /* copy 1 byte */ - ptr++; - cptr += 8; - } - } - break; - - default: /* should never get here */ - ffpmsg("Error: unexpected attempt to use GZIP_2 to compress a column unsuitable data type"); - *status = DATA_DECOMPRESSION_ERR; + /* recombine the byte planes for the 2-byte, 4-byte, and 8-byte numeric columns */ + switch (colcode[ii]) { + + case 'I': + /* get the 1st byte of each I*2 value */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols])); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 2; + } + } + /* get the 2nd byte of each I*2 value */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 1); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 2; + } + } + break; + + case 'J': + case 'E': + /* get the 1st byte of each 4-byte value */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols])); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 4; + } + } + /* get the 2nd byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 1); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 4; + } + } + /* get the 3rd byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 2); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 4; + } + } + /* get the 4th byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 3); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 4; + } + } + break; + + case 'D': + case 'K': + /* get the 1st byte of each 8-byte value */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols])); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 2nd byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 1); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 3rd byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 2); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 4th byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 3); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 5th byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 4); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 6th byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 5); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 7th byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 6); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + /* get the 8th byte */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + (jj * rmajor_colstart[ncols]) + 7); + for (kk = 0; kk < rmajor_repeat[ii]; kk++) { + *cptr = *ptr; /* copy 1 byte */ + ptr++; + cptr += 8; + } + } + break; + + default: /* should never get here */ + ffpmsg("Error: unexpected attempt to use GZIP_2 to compress a column unsuitable data type"); + *status = DATA_DECOMPRESSION_ERR; free(rm_buffer); free(cm_buffer); - return(*status); + return(*status); - } /* end of switch for shuffling the bytes*/ + } /* end of switch for shuffling the bytes*/ } else { /* not GZIP_2, don't have to shuffle bytes, so just transpose the rows and columns */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ - cptr = rm_buffer + (rmajor_colstart[ii] + jj * rmajor_colstart[ncols]); /* addr to copy to */ - memcpy(cptr, ptr, (size_t) rmajor_colwidth[ii]); - - ptr += (rmajor_colwidth[ii]); - } - } + for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output table */ + cptr = rm_buffer + (rmajor_colstart[ii] + jj * rmajor_colstart[ncols]); /* addr to copy to */ + memcpy(cptr, ptr, (size_t) rmajor_colwidth[ii]); + + ptr += (rmajor_colwidth[ii]); + } + } } else { /* transpose the variable length array pointers */ for (jj = 0; jj < rowspertile; jj++) { /* loop over number of rows in the output uncompressed table */ - cptr = rm_buffer + (rmajor_colstart[ii] + jj * rmajor_colstart[ncols]); /* addr to copy to */ - memcpy(cptr, ptr, (size_t) rmajor_colwidth[ii]); - - ptr += (rmajor_colwidth[ii]); - } - - if (rmajor_colwidth[ii] == 8 ) { /* these are P-type descriptors */ - pdescript = (int *) (cm_buffer + cmajor_colstart[ii]); + cptr = rm_buffer + (rmajor_colstart[ii] + jj * rmajor_colstart[ncols]); /* addr to copy to */ + memcpy(cptr, ptr, (size_t) rmajor_colwidth[ii]); + + ptr += (rmajor_colwidth[ii]); + } + + if (rmajor_colwidth[ii] == 8 ) { /* these are P-type descriptors */ + pdescript = (int *) (cm_buffer + cmajor_colstart[ii]); #if BYTESWAPPED - ffswap4((int *) pdescript, rowspertile * 2); /* byte-swap the descriptor */ + ffswap4((int *) pdescript, rowspertile * 2); /* byte-swap the descriptor */ #endif - } else if (rmajor_colwidth[ii] == 16 ) { /* these are Q-type descriptors */ - qdescript = (LONGLONG *) (cm_buffer + cmajor_colstart[ii]); + } else if (rmajor_colwidth[ii] == 16 ) { /* these are Q-type descriptors */ + qdescript = (LONGLONG *) (cm_buffer + cmajor_colstart[ii]); #if BYTESWAPPED - ffswap8((double *) qdescript, rowspertile * 2); /* byte-swap the descriptor */ + ffswap8((double *) qdescript, rowspertile * 2); /* byte-swap the descriptor */ #endif - } else { /* this should never happen */ - ffpmsg("Error: Descriptor column is neither 8 nor 16 bytes wide"); + } else { /* this should never happen */ + ffpmsg("Error: Descriptor column is neither 8 nor 16 bytes wide"); free(rm_buffer); free(cm_buffer); - *status = DATA_DECOMPRESSION_ERR; - return(*status); - } - - /* First, set pointer to the Q descriptors, and byte-swap them, if needed */ - descript = (LONGLONG*) (cm_buffer + cmajor_colstart[ii] + (rmajor_colwidth[ii] * rowspertile)); + *status = DATA_DECOMPRESSION_ERR; + return(*status); + } + + /* First, set pointer to the Q descriptors, and byte-swap them, if needed */ + descript = (LONGLONG*) (cm_buffer + cmajor_colstart[ii] + (rmajor_colwidth[ii] * rowspertile)); #if BYTESWAPPED - /* byte-swap the descriptor */ - ffswap8((double *) descript, rowspertile * 2); + /* byte-swap the descriptor */ + ffswap8((double *) descript, rowspertile * 2); #endif - /* now uncompress all the individual VLAs, and */ - /* write them to their original location in the uncompressed file */ + /* now uncompress all the individual VLAs, and */ + /* write them to their original location in the uncompressed file */ - for (jj = 0; jj < rowspertile; jj++) { /* loop over rows */ + for (jj = 0; jj < rowspertile; jj++) { /* loop over rows */ /* get the size and location of the compressed VLA in the compressed table */ - cvlalen = descript[jj * 2]; - cvlastart = descript[(jj * 2) + 1]; - if (cvlalen > 0 ) { - - /* get the size and location to write the uncompressed VLA in the uncompressed table */ - if (rmajor_colwidth[ii] == 8 ) { - vlalen = pdescript[jj * 2]; - vlastart = pdescript[(jj * 2) + 1]; - } else { - vlalen = qdescript[jj * 2]; - vlastart = qdescript[(jj * 2) + 1]; - } - vlamemlen = (size_t) (vlalen * (-coltype[ii] / 10)); /* size of the uncompressed VLA, in bytes */ - - /* allocate memory for the compressed vla */ - compressed_vla = malloc( (size_t) cvlalen); - if (!compressed_vla) { - ffpmsg("Could not allocate buffer for compressed VLA"); - free(rm_buffer); free(cm_buffer); - *status = MEMORY_ALLOCATION; - return(*status); - } - - /* read the compressed VLA from the heap in the input compressed table */ - bytepos = (size_t) ((infptr->Fptr)->datastart + (infptr->Fptr)->heapstart + cvlastart); - ffmbyt(infptr, bytepos, REPORT_EOF, status); - ffgbyt(infptr, cvlalen, compressed_vla, status); /* read the bytes */ - /* if the VLA couldn't be compressed, just copy it directly to the output uncompressed table */ - if (cvlalen == vlamemlen ) { - bytepos = (size_t) ((outfptr->Fptr)->datastart + (outfptr->Fptr)->heapstart + vlastart); - ffmbyt(outfptr, bytepos, IGNORE_EOF, status); - ffpbyt(outfptr, cvlalen, compressed_vla, status); /* write the bytes */ - } else { /* uncompress the VLA */ - - /* allocate memory for the uncompressed VLA */ - uncompressed_vla = malloc(vlamemlen); - if (!uncompressed_vla) { - ffpmsg("Could not allocate buffer for uncompressed VLA"); - *status = MEMORY_ALLOCATION; - free(compressed_vla); free(rm_buffer); free(cm_buffer); - return(*status); - } - /* uncompress the VLA with the appropriate algorithm */ - if (zctype[ii] == RICE_1) { - - if (-coltype[ii] == TSHORT) { - dlen = fits_rdecomp_short((unsigned char *) compressed_vla, (int) cvlalen, (unsigned short *)uncompressed_vla, - (int) vlalen, 32); + cvlalen = descript[jj * 2]; + cvlastart = descript[(jj * 2) + 1]; + if (cvlalen > 0 ) { + + /* get the size and location to write the uncompressed VLA in the uncompressed table */ + if (rmajor_colwidth[ii] == 8 ) { + vlalen = pdescript[jj * 2]; + vlastart = pdescript[(jj * 2) + 1]; + } else { + vlalen = qdescript[jj * 2]; + vlastart = qdescript[(jj * 2) + 1]; + } + vlamemlen = (size_t) (vlalen * (-coltype[ii] / 10)); /* size of the uncompressed VLA, in bytes */ + + /* allocate memory for the compressed vla */ + compressed_vla = malloc( (size_t) cvlalen); + if (!compressed_vla) { + ffpmsg("Could not allocate buffer for compressed VLA"); + free(rm_buffer); free(cm_buffer); + *status = MEMORY_ALLOCATION; + return(*status); + } + + /* read the compressed VLA from the heap in the input compressed table */ + bytepos = (size_t) ((infptr->Fptr)->datastart + (infptr->Fptr)->heapstart + cvlastart); + ffmbyt(infptr, bytepos, REPORT_EOF, status); + ffgbyt(infptr, cvlalen, compressed_vla, status); /* read the bytes */ + /* if the VLA couldn't be compressed, just copy it directly to the output uncompressed table */ + if (cvlalen == vlamemlen ) { + bytepos = (size_t) ((outfptr->Fptr)->datastart + (outfptr->Fptr)->heapstart + vlastart); + ffmbyt(outfptr, bytepos, IGNORE_EOF, status); + ffpbyt(outfptr, cvlalen, compressed_vla, status); /* write the bytes */ + } else { /* uncompress the VLA */ + + /* allocate memory for the uncompressed VLA */ + uncompressed_vla = malloc(vlamemlen); + if (!uncompressed_vla) { + ffpmsg("Could not allocate buffer for uncompressed VLA"); + *status = MEMORY_ALLOCATION; + free(compressed_vla); free(rm_buffer); free(cm_buffer); + return(*status); + } + /* uncompress the VLA with the appropriate algorithm */ + if (zctype[ii] == RICE_1) { + + if (-coltype[ii] == TSHORT) { + dlen = fits_rdecomp_short((unsigned char *) compressed_vla, (int) cvlalen, (unsigned short *)uncompressed_vla, + (int) vlalen, 32); #if BYTESWAPPED - ffswap2((short *) uncompressed_vla, (long) vlalen); + ffswap2((short *) uncompressed_vla, (long) vlalen); #endif - } else if (-coltype[ii] == TLONG) { - dlen = fits_rdecomp((unsigned char *) compressed_vla, (int) cvlalen, (unsigned int *)uncompressed_vla, - (int) vlalen, 32); + } else if (-coltype[ii] == TLONG) { + dlen = fits_rdecomp((unsigned char *) compressed_vla, (int) cvlalen, (unsigned int *)uncompressed_vla, + (int) vlalen, 32); #if BYTESWAPPED - ffswap4((int *) uncompressed_vla, (long) vlalen); + ffswap4((int *) uncompressed_vla, (long) vlalen); #endif - } else if (-coltype[ii] == TBYTE) { - dlen = fits_rdecomp_byte((unsigned char *) compressed_vla, (int) cvlalen, (unsigned char *) uncompressed_vla, - (int) vlalen, 32); - } else { - /* this should not happen */ - ffpmsg(" Error: cannot uncompress this column type with the RICE algorithm"); - - *status = DATA_DECOMPRESSION_ERR; - free(uncompressed_vla); free(compressed_vla); free(rm_buffer); free(cm_buffer); - return(*status); - } - - } else if (zctype[ii] == GZIP_1 || zctype[ii] == GZIP_2){ - - /*: gzip uncompress the array of bytes */ - uncompress2mem_from_mem( compressed_vla, (size_t) cvlalen, &uncompressed_vla, &vlamemlen, realloc, &vlamemlen, status); - - if (zctype[ii] == GZIP_2 ) { - /* unshuffle the bytes after ungzipping them */ - if ( (int) (-coltype[ii] / 10) == 2) { - fits_unshuffle_2bytes((char *) uncompressed_vla, vlalen, status); - } else if ( (int) (-coltype[ii] / 10) == 4) { - fits_unshuffle_4bytes((char *) uncompressed_vla, vlalen, status); - } else if ( (int) (-coltype[ii] / 10) == 8) { - fits_unshuffle_8bytes((char *) uncompressed_vla, vlalen, status); - } - } - - } else { - /* this should not happen */ - ffpmsg(" Error: unknown compression algorithm"); - free(uncompressed_vla); free(compressed_vla); free(rm_buffer); free(cm_buffer); - *status = DATA_COMPRESSION_ERR; - return(*status); - } - - bytepos = (size_t) ((outfptr->Fptr)->datastart + (outfptr->Fptr)->heapstart + vlastart); - ffmbyt(outfptr, bytepos, IGNORE_EOF, status); - ffpbyt(outfptr, vlamemlen, uncompressed_vla, status); /* write the bytes */ - - free(uncompressed_vla); - } /* end of uncompress VLA */ - - free(compressed_vla); - - } /* end of vlalen > 0 */ - } /* end of loop over rowspertile */ + } else if (-coltype[ii] == TBYTE) { + dlen = fits_rdecomp_byte((unsigned char *) compressed_vla, (int) cvlalen, (unsigned char *) uncompressed_vla, + (int) vlalen, 32); + } else { + /* this should not happen */ + ffpmsg(" Error: cannot uncompress this column type with the RICE algorithm"); + + *status = DATA_DECOMPRESSION_ERR; + free(uncompressed_vla); free(compressed_vla); free(rm_buffer); free(cm_buffer); + return(*status); + } + + } else if (zctype[ii] == GZIP_1 || zctype[ii] == GZIP_2){ + + /*: gzip uncompress the array of bytes */ + uncompress2mem_from_mem( compressed_vla, (size_t) cvlalen, &uncompressed_vla, &vlamemlen, realloc, &vlamemlen, status); + + if (zctype[ii] == GZIP_2 ) { + /* unshuffle the bytes after ungzipping them */ + if ( (int) (-coltype[ii] / 10) == 2) { + fits_unshuffle_2bytes((char *) uncompressed_vla, vlalen, status); + } else if ( (int) (-coltype[ii] / 10) == 4) { + fits_unshuffle_4bytes((char *) uncompressed_vla, vlalen, status); + } else if ( (int) (-coltype[ii] / 10) == 8) { + fits_unshuffle_8bytes((char *) uncompressed_vla, vlalen, status); + } + } + + } else { + /* this should not happen */ + ffpmsg(" Error: unknown compression algorithm"); + free(uncompressed_vla); free(compressed_vla); free(rm_buffer); free(cm_buffer); + *status = DATA_COMPRESSION_ERR; + return(*status); + } + + bytepos = (size_t) ((outfptr->Fptr)->datastart + (outfptr->Fptr)->heapstart + vlastart); + ffmbyt(outfptr, bytepos, IGNORE_EOF, status); + ffpbyt(outfptr, vlamemlen, uncompressed_vla, status); /* write the bytes */ + + free(uncompressed_vla); + } /* end of uncompress VLA */ + + free(compressed_vla); + + } /* end of vlalen > 0 */ + } /* end of loop over rowspertile */ } /* end of variable length array section*/ } /* end of if column repeat > 0 */ @@ -9330,22 +9330,22 @@ int fits_uncompress_table(fitsfile *infptr, fitsfile *outfptr, int *status) /* copy the buffer of data to the output data unit */ - if (datastart == 0) fits_get_hduaddrll(outfptr, &headstart, &datastart, &dataend, status); + if (datastart == 0) fits_get_hduaddrll(outfptr, &headstart, &datastart, &dataend, status); ffmbyt(outfptr, datastart, 1, status); ffpbyt(outfptr, naxis1 * rowspertile, rm_buffer, status); - /* increment pointers for next tile */ - rowstart += rowspertile; + /* increment pointers for next tile */ + rowstart += rowspertile; rowsremain -= rowspertile; - datastart += (naxis1 * rowspertile); - if (rowspertile > rowsremain) rowspertile = (long) rowsremain; + datastart += (naxis1 * rowspertile); + if (rowspertile > rowsremain) rowspertile = (long) rowsremain; } /* end of while rows still remain */ free(rm_buffer); free(cm_buffer); - + /* reset internal table structure parameters */ fits_set_hdustruc(outfptr, status); return(*status); @@ -9358,11 +9358,11 @@ static int fits_shuffle_2bytes(char *heap, LONGLONG length, int *status) { LONGLONG ii; char *ptr, *cptr, *heapptr; - + ptr = malloc((size_t) (length * 2)); heapptr = heap; cptr = ptr; - + for (ii = 0; ii < length; ii++) { *cptr = *heapptr; heapptr++; @@ -9370,7 +9370,7 @@ static int fits_shuffle_2bytes(char *heap, LONGLONG length, int *status) heapptr++; cptr++; } - + memcpy(heap, ptr, (size_t) (length * 2)); free(ptr); return(*status); @@ -9383,7 +9383,7 @@ static int fits_shuffle_4bytes(char *heap, LONGLONG length, int *status) { LONGLONG ii; char *ptr, *cptr, *heapptr; - + ptr = malloc((size_t) (length * 4)); if (!ptr) { ffpmsg("malloc failed\n"); @@ -9392,7 +9392,7 @@ static int fits_shuffle_4bytes(char *heap, LONGLONG length, int *status) heapptr = heap; cptr = ptr; - + for (ii = 0; ii < length; ii++) { *cptr = *heapptr; heapptr++; @@ -9404,7 +9404,7 @@ static int fits_shuffle_4bytes(char *heap, LONGLONG length, int *status) heapptr++; cptr++; } - + memcpy(heap, ptr, (size_t) (length * 4)); free(ptr); @@ -9418,14 +9418,14 @@ static int fits_shuffle_8bytes(char *heap, LONGLONG length, int *status) { LONGLONG ii; char *ptr, *cptr, *heapptr; - + ptr = calloc(1, (size_t) (length * 8)); heapptr = heap; - + /* for some bizarre reason this loop fails to compile under OpenSolaris using the proprietary SunStudioExpress C compiler; use the following equivalent loop instead. - + cptr = ptr; for (ii = 0; ii < length; ii++) { @@ -9483,10 +9483,10 @@ static int fits_shuffle_8bytes(char *heap, LONGLONG length, int *status) heapptr++; } - + memcpy(heap, ptr, (size_t) (length * 8)); free(ptr); - + return(*status); } /*--------------------------------------------------------------------------*/ @@ -9497,11 +9497,11 @@ static int fits_unshuffle_2bytes(char *heap, LONGLONG length, int *status) { LONGLONG ii; char *ptr, *cptr, *heapptr; - + ptr = malloc((size_t) (length * 2)); heapptr = heap + (2 * length) - 1; cptr = ptr + (2 * length) - 1; - + for (ii = 0; ii < length; ii++) { *cptr = *heapptr; cptr--; @@ -9509,7 +9509,7 @@ static int fits_unshuffle_2bytes(char *heap, LONGLONG length, int *status) cptr--; heapptr--; } - + memcpy(heap, ptr, (size_t) (length * 2)); free(ptr); return(*status); @@ -9522,11 +9522,11 @@ static int fits_unshuffle_4bytes(char *heap, LONGLONG length, int *status) { LONGLONG ii; char *ptr, *cptr, *heapptr; - + ptr = malloc((size_t) (length * 4)); heapptr = heap + (4 * length) -1; cptr = ptr + (4 * length) -1; - + for (ii = 0; ii < length; ii++) { *cptr = *heapptr; cptr--; @@ -9538,7 +9538,7 @@ static int fits_unshuffle_4bytes(char *heap, LONGLONG length, int *status) cptr--; heapptr--; } - + memcpy(heap, ptr, (size_t) (length * 4)); free(ptr); return(*status); @@ -9551,11 +9551,11 @@ static int fits_unshuffle_8bytes(char *heap, LONGLONG length, int *status) { LONGLONG ii; char *ptr, *cptr, *heapptr; - + ptr = malloc((size_t) (length * 8)); heapptr = heap + (8 * length) - 1; cptr = ptr + (8 * length) -1; - + for (ii = 0; ii < length; ii++) { *cptr = *heapptr; cptr--; @@ -9575,7 +9575,7 @@ static int fits_unshuffle_8bytes(char *heap, LONGLONG length, int *status) cptr--; heapptr--; } - + memcpy(heap, ptr, (size_t) (length * 8)); free(ptr); return(*status); @@ -9585,7 +9585,7 @@ static int fits_int_to_longlong_inplace(int *intarray, long length, int *status) /* convert the input array of 32-bit integers into an array of 64-bit integers, in place. This will overwrite the input array with the new longer array starting -at the same memory location. +at the same memory location. Note that aliasing the same memory location with pointers of different datatypes is not allowed in strict ANSI C99, however it is used here for efficency. In principle, @@ -9599,45 +9599,45 @@ the longer datatype values back to the original array. { LONGLONG *longlongarray, *aliasarray; long ii, ntodo, firstelem, nmax = 10000; - - if (*status > 0) + + if (*status > 0) return(*status); ntodo = nmax; if (length < nmax) ntodo = length; - + firstelem = length - ntodo; /* first element to be converted */ - + longlongarray = (LONGLONG *) malloc(ntodo * sizeof(LONGLONG)); - + if (longlongarray == NULL) { - ffpmsg("Out of memory. (fits_int_to_longlong_inplace)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory. (fits_int_to_longlong_inplace)"); + return (*status = MEMORY_ALLOCATION); } aliasarray = (LONGLONG *) intarray; /* alias pointer to the input array */ while (ntodo > 0) { - - /* do datatype conversion into temp array */ - for (ii = 0; ii < ntodo; ii++) { - longlongarray[ii] = intarray[ii + firstelem]; + + /* do datatype conversion into temp array */ + for (ii = 0; ii < ntodo; ii++) { + longlongarray[ii] = intarray[ii + firstelem]; } /* copy temp array back to alias */ memcpy(&(aliasarray[firstelem]), longlongarray, ntodo * 8); - + if (firstelem == 0) { /* we are all done */ - ntodo = 0; - } else { /* recalculate ntodo and firstelem for next loop */ - if (firstelem > nmax) { - firstelem -= nmax; - } else { - ntodo = firstelem; - firstelem = 0; - } - } + ntodo = 0; + } else { /* recalculate ntodo and firstelem for next loop */ + if (firstelem > nmax) { + firstelem -= nmax; + } else { + ntodo = firstelem; + firstelem = 0; + } + } } free(longlongarray); @@ -9648,7 +9648,7 @@ static int fits_short_to_int_inplace(short *shortarray, long length, int shift, /* convert the input array of 16-bit integers into an array of 32-bit integers, in place. This will overwrite the input array with the new longer array starting -at the same memory location. +at the same memory location. Note that aliasing the same memory location with pointers of different datatypes is not allowed in strict ANSI C99, however it is used here for efficency. In principle, @@ -9662,57 +9662,57 @@ the longer datatype values back to the original array. { int *intarray, *aliasarray; long ii, ntodo, firstelem, nmax = 10000; - - if (*status > 0) + + if (*status > 0) return(*status); ntodo = nmax; if (length < nmax) ntodo = length; - + firstelem = length - ntodo; /* first element to be converted */ - + intarray = (int *) malloc(ntodo * sizeof(int)); - + if (intarray == NULL) { - ffpmsg("Out of memory. (fits_short_to_int_inplace)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory. (fits_short_to_int_inplace)"); + return (*status = MEMORY_ALLOCATION); } aliasarray = (int *) shortarray; /* alias pointer to the input array */ while (ntodo > 0) { - - /* do datatype conversion into temp array */ - for (ii = 0; ii < ntodo; ii++) { - intarray[ii] = (int)(shortarray[ii + firstelem]) + shift; + + /* do datatype conversion into temp array */ + for (ii = 0; ii < ntodo; ii++) { + intarray[ii] = (int)(shortarray[ii + firstelem]) + shift; } /* copy temp array back to alias */ memcpy(&(aliasarray[firstelem]), intarray, ntodo * 4); - + if (firstelem == 0) { /* we are all done */ - ntodo = 0; - } else { /* recalculate ntodo and firstelem for next loop */ - if (firstelem > nmax) { - firstelem -= nmax; - } else { - ntodo = firstelem; - firstelem = 0; - } - } + ntodo = 0; + } else { /* recalculate ntodo and firstelem for next loop */ + if (firstelem > nmax) { + firstelem -= nmax; + } else { + ntodo = firstelem; + firstelem = 0; + } + } } free(intarray); return(*status); } /*--------------------------------------------------------------------------*/ -static int fits_ushort_to_int_inplace(unsigned short *ushortarray, long length, +static int fits_ushort_to_int_inplace(unsigned short *ushortarray, long length, int shift, int *status) /* convert the input array of 16-bit unsigned integers into an array of 32-bit integers, in place. This will overwrite the input array with the new longer array starting -at the same memory location. +at the same memory location. Note that aliasing the same memory location with pointers of different datatypes is not allowed in strict ANSI C99, however it is used here for efficency. In principle, @@ -9726,57 +9726,57 @@ the longer datatype values back to the original array. { int *intarray, *aliasarray; long ii, ntodo, firstelem, nmax = 10000; - - if (*status > 0) + + if (*status > 0) return(*status); ntodo = nmax; if (length < nmax) ntodo = length; - + firstelem = length - ntodo; /* first element to be converted */ - + intarray = (int *) malloc(ntodo * sizeof(int)); - + if (intarray == NULL) { - ffpmsg("Out of memory. (fits_ushort_to_int_inplace)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory. (fits_ushort_to_int_inplace)"); + return (*status = MEMORY_ALLOCATION); } aliasarray = (int *) ushortarray; /* alias pointer to the input array */ while (ntodo > 0) { - - /* do datatype conversion into temp array */ - for (ii = 0; ii < ntodo; ii++) { - intarray[ii] = (int)(ushortarray[ii + firstelem]) + shift; + + /* do datatype conversion into temp array */ + for (ii = 0; ii < ntodo; ii++) { + intarray[ii] = (int)(ushortarray[ii + firstelem]) + shift; } /* copy temp array back to alias */ memcpy(&(aliasarray[firstelem]), intarray, ntodo * 4); - + if (firstelem == 0) { /* we are all done */ - ntodo = 0; - } else { /* recalculate ntodo and firstelem for next loop */ - if (firstelem > nmax) { - firstelem -= nmax; - } else { - ntodo = firstelem; - firstelem = 0; - } - } + ntodo = 0; + } else { /* recalculate ntodo and firstelem for next loop */ + if (firstelem > nmax) { + firstelem -= nmax; + } else { + ntodo = firstelem; + firstelem = 0; + } + } } free(intarray); return(*status); } /*--------------------------------------------------------------------------*/ -static int fits_ubyte_to_int_inplace(unsigned char *ubytearray, long length, +static int fits_ubyte_to_int_inplace(unsigned char *ubytearray, long length, int *status) /* convert the input array of 8-bit unsigned integers into an array of 32-bit integers, in place. This will overwrite the input array with the new longer array starting -at the same memory location. +at the same memory location. Note that aliasing the same memory location with pointers of different datatypes is not allowed in strict ANSI C99, however it is used here for efficency. In principle, @@ -9790,57 +9790,57 @@ the longer datatype values back to the original array. { int *intarray, *aliasarray; long ii, ntodo, firstelem, nmax = 10000; - - if (*status > 0) + + if (*status > 0) return(*status); ntodo = nmax; if (length < nmax) ntodo = length; - + firstelem = length - ntodo; /* first element to be converted */ - + intarray = (int *) malloc(ntodo * sizeof(int)); - + if (intarray == NULL) { - ffpmsg("Out of memory. (fits_ubyte_to_int_inplace)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory. (fits_ubyte_to_int_inplace)"); + return (*status = MEMORY_ALLOCATION); } aliasarray = (int *) ubytearray; /* alias pointer to the input array */ while (ntodo > 0) { - - /* do datatype conversion into temp array */ - for (ii = 0; ii < ntodo; ii++) { - intarray[ii] = ubytearray[ii + firstelem]; + + /* do datatype conversion into temp array */ + for (ii = 0; ii < ntodo; ii++) { + intarray[ii] = ubytearray[ii + firstelem]; } /* copy temp array back to alias */ memcpy(&(aliasarray[firstelem]), intarray, ntodo * 4); - + if (firstelem == 0) { /* we are all done */ - ntodo = 0; - } else { /* recalculate ntodo and firstelem for next loop */ - if (firstelem > nmax) { - firstelem -= nmax; - } else { - ntodo = firstelem; - firstelem = 0; - } - } + ntodo = 0; + } else { /* recalculate ntodo and firstelem for next loop */ + if (firstelem > nmax) { + firstelem -= nmax; + } else { + ntodo = firstelem; + firstelem = 0; + } + } } free(intarray); return(*status); } /*--------------------------------------------------------------------------*/ -static int fits_sbyte_to_int_inplace(signed char *sbytearray, long length, +static int fits_sbyte_to_int_inplace(signed char *sbytearray, long length, int *status) /* convert the input array of 8-bit signed integers into an array of 32-bit integers, in place. This will overwrite the input array with the new longer array starting -at the same memory location. +at the same memory location. Note that aliasing the same memory location with pointers of different datatypes is not allowed in strict ANSI C99, however it is used here for efficency. In principle, @@ -9860,45 +9860,45 @@ NOTE THAT THIS IS A SPECIALIZED ROUTINE THAT ADDS AN OFFSET OF 128 TO THE ARRAY { int *intarray, *aliasarray; long ii, ntodo, firstelem, nmax = 10000; - - if (*status > 0) + + if (*status > 0) return(*status); ntodo = nmax; if (length < nmax) ntodo = length; - + firstelem = length - ntodo; /* first element to be converted */ - + intarray = (int *) malloc(ntodo * sizeof(int)); - + if (intarray == NULL) { - ffpmsg("Out of memory. (fits_sbyte_to_int_inplace)"); - return (*status = MEMORY_ALLOCATION); + ffpmsg("Out of memory. (fits_sbyte_to_int_inplace)"); + return (*status = MEMORY_ALLOCATION); } aliasarray = (int *) sbytearray; /* alias pointer to the input array */ while (ntodo > 0) { - - /* do datatype conversion into temp array */ - for (ii = 0; ii < ntodo; ii++) { - intarray[ii] = sbytearray[ii + firstelem] + 128; /* !! Note the offset !! */ + + /* do datatype conversion into temp array */ + for (ii = 0; ii < ntodo; ii++) { + intarray[ii] = sbytearray[ii + firstelem] + 128; /* !! Note the offset !! */ } /* copy temp array back to alias */ memcpy(&(aliasarray[firstelem]), intarray, ntodo * 4); - + if (firstelem == 0) { /* we are all done */ - ntodo = 0; - } else { /* recalculate ntodo and firstelem for next loop */ - if (firstelem > nmax) { - firstelem -= nmax; - } else { - ntodo = firstelem; - firstelem = 0; - } - } + ntodo = 0; + } else { /* recalculate ntodo and firstelem for next loop */ + if (firstelem > nmax) { + firstelem -= nmax; + } else { + ntodo = firstelem; + firstelem = 0; + } + } } free(intarray); @@ -9912,19 +9912,19 @@ int fits_calc_tile_rows(long *tlpixel, long *tfpixel, int ndim, long *trowsize, were 2 dimensions (trowsize * ntrows). This sets trowsize to the first dimensional size encountered that's > 1 (typically the X dimension). ntrows will then be the product of the remaining dimensional sizes. - + Examples: Tile = (5,4,1,3): trowsize=5, ntrows=12 Tile = (1,1,5): trowsize=5, ntrows=1 */ int ii; long np; - + if (*status) return (*status); - - *trowsize = 0; - *ntrows = 1; + + *trowsize = 0; + *ntrows = 1; for (ii=0; ii