File indexing completed on 2024-04-21 14:45:54
0001 /* used by FPACK and FUNPACK 0002 SPDX-FileCopyrightText: William D. Pence <https:xheasarc.gsfc.nasa.gov/fitsio/> 0003 SPDX-FileCopyrightText: R. Seaman 0004 0005 SPDX-License-Identifier: LicenseRef-NASA-FV-License-Agreement 0006 */ 0007 0008 #pragma once 0009 0010 #include <string.h> 0011 #include <stdio.h> 0012 #include <stdlib.h> 0013 0014 /* not needed any more */ 0015 /* #include <unistd.h> */ 0016 /* #include <sys/stat.h> */ 0017 /* #include <sys/types.h> */ 0018 0019 #define FPACK_VERSION "1.7.0 (Dec 2013)" 0020 /* 0021 VERSION History 0022 0023 1.7.0 (Dec 2013) 0024 - extensive changes to the binary table compression method. All types 0025 of binary table columns, including variable length array columns are 0026 now supported. The command line table compression flag has been changed 0027 to "-table" instead of "-BETAtable", and a new "-tableonly" flag has 0028 been introduced to only compress the binary tables in the input files(s) 0029 and not the image HDUs. 0030 1.6.1 (Mar 2013) 0031 - numerous changes to the BETAtable compression method used to compress 0032 binary tables 0033 - added support for compression 'steering' keywords that specify the 0034 desired compression parameters that should be used when compressing 0035 that particular HDU, thus overriding the fpack command line parameter 0036 values. 0037 0038 1.6.0 (June 2012) 0039 - Fixed behavior of the "rename" function on Windows platforms so that 0040 it will clobber/delete an existing file before renaming a file to 0041 that name (the rename command behaves differently on POSIX and non-POSIX 0042 environments). 0043 0044 1.6.0 (February 2011) 0045 - Added full support for compressing and uncompressing FITS binary tables 0046 using a newly proposed format convention. This is intended only for 0047 further feasibility studies, and is not recommended for use with publicly 0048 distributed FITS files. 0049 - Use the minimum of the MAD 2nd, 3rd, and 5th order values as a more 0050 conservative estimate of the noise when quantizing floating point images. 0051 - Enhanced the tile compression routines so that a tile that contains all 0052 NaN pixel values will be compressed. 0053 - When uncompressing an image that was originally in a FITS primary array, 0054 funpack will also append any new keywords that were written into the 0055 primary array of the compressed FITS file after the file was compressed. 0056 - Added support for the GZIP_2 algorithm, which shuffles the bytes in the 0057 pixel values prior to compressing them with gzip. 0058 1.5.1 (December 2010) Added prototype, mainly hidden, support for compressing 0059 binary tables. 0060 1.5.0 (August 2010) Added the -i2f option to lossy compress integer images. 0061 1.4.0 (Jan 2010) Reduced the default value for the q floating point image 0062 quantization parameter from 16 to 4. This results in about 50% better 0063 compression (from about 4.6x to 6.4) with no lost of significant information 0064 (with the new subtractive dithering enhancement). Replaced the code for 0065 generating temporary filenames to make the code more portable (to Windows). 0066 Replaced calls to the unix 'access' and 'stat' functions with more portable 0067 code. When unpacking a file, write it first to a temporary file, then 0068 rename it when finished, so that other tasks cannot try to read the file 0069 before it is complete. 0070 1.3.0 (Oct 2009) added randomization to the dithering pattern so that 0071 the same pattern is not used for every image; also added an option 0072 for losslessly compressing floating point images with GZIP for test 0073 purposes (not recommended for general use). Also added support for 0074 reading the input FITS file from the stdin file streams. 0075 1.2.0 (Sept 2009) added subtractive dithering feature (in CFITSIO) when 0076 quantizing floating point images; When packing an IRAF .imh + .pix image, 0077 the file name is changed to FILE.fits.fz, and if the original file is 0078 deleted, then both the .imh and .pix files are deleted. 0079 1.1.4 (May 2009) added -E option to funpack to unpack a list of HDUs 0080 1.1.3 (March 2009) minor modifications to the content and format of the -T report 0081 1.1.2 (September 2008) 0082 */ 0083 0084 #define FP_INIT_MAGIC 42 0085 #define FPACK 0 0086 #define FUNPACK 1 0087 0088 /* changed from 16 in Jan. 2010 */ 0089 #define DEF_QLEVEL 4. 0090 0091 #define DEF_HCOMP_SCALE 0. 0092 #define DEF_HCOMP_SMOOTH 0 0093 #define DEF_RESCALE_NOISE 0 0094 0095 #define SZ_STR 513 0096 #define SZ_CARD 81 0097 0098 0099 typedef struct 0100 { 0101 int comptype; 0102 float quantize_level; 0103 int no_dither; 0104 int dither_offset; 0105 int dither_method; 0106 float scale; 0107 float rescale_noise; 0108 int smooth; 0109 int int_to_float; 0110 float n3ratio; 0111 float n3min; 0112 long ntile[MAX_COMPRESS_DIM]; 0113 0114 int to_stdout; 0115 int listonly; 0116 int clobber; 0117 int delete_input; 0118 int do_not_prompt; 0119 int do_checksums; 0120 int do_gzip_file; 0121 int do_images; 0122 int do_tables; 0123 int test_all; 0124 int verbose; 0125 0126 char prefix[SZ_STR]; 0127 char extname[SZ_STR]; 0128 int delete_suffix; 0129 char outfile[SZ_STR]; 0130 int firstfile; 0131 0132 int initialized; 0133 int preflight_checked; 0134 } fpstate; 0135 0136 typedef struct 0137 { 0138 int n_nulls; 0139 double minval; 0140 double maxval; 0141 double mean; 0142 double sigma; 0143 double noise1; 0144 double noise2; 0145 double noise3; 0146 double noise5; 0147 } imgstats; 0148 0149 #ifdef __cplusplus 0150 extern "C" { 0151 #endif 0152 0153 int fp_get_param (int argc, char *argv[], fpstate *fpptr); 0154 void abort_fpack(int sig); 0155 void fp_abort_output (fitsfile *infptr, fitsfile *outfptr, int stat); 0156 int fp_usage (void); 0157 int fp_help (void); 0158 int fp_hint (void); 0159 int fp_init (fpstate *fpptr); 0160 int fp_list (int argc, char *argv[], fpstate fpvar); 0161 int fp_info (char *infits); 0162 int fp_info_hdu (fitsfile *infptr); 0163 int fp_preflight (int argc, char *argv[], int unpack, fpstate *fpptr); 0164 int fp_loop (int argc, char *argv[], int unpack, char *output_filename, fpstate fpvar); 0165 0166 /* Core pack function */ 0167 /* Unpack input file to outfile file on disk */ 0168 int fp_pack (char *infits, char *outfits, fpstate fpvar, int *islossless); 0169 /* Unpack input data to output FITS file in memory */ 0170 /*int fp_pack_data_to_fits (const char *inputBuffer, size_t inputBufferSize, fitsfile **outfits, fpstate fpvar, 0171 int *islossless);*/ 0172 /* Unpack input data to output data in memory */ 0173 /*int fp_pack_data_to_data (const char *inputBuffer, size_t inputBufferSize, unsigned char **outputBuffer, 0174 size_t *outputBufferSize, 0175 fpstate fpvar, 0176 int *islossless);*/ 0177 /* Pack input fits file to in-memory fits file */ 0178 int fp_pack_fits_to_fits (fitsfile *infptr, fitsfile **outfits, fpstate fpvar, int *islossless); 0179 0180 /* Core unpark functions */ 0181 0182 /* Unpack on disk file to output on disk file */ 0183 int fp_unpack (char *infits, char *outfits, fpstate fpvar); 0184 /* Unpack input compressed input file to uncompressed output in-memory fits file */ 0185 int fp_unpack_file_to_fits (char *infits, fitsfile **outfits, fpstate fpvar); 0186 /* Unpack input compressed data to uncompressed output in-memory fits file */ 0187 /*int fp_unpack_data_to_fits (const char *inputBuffer, size_t inputBufferSize, fitsfile **outfptr, fpstate fpvar);*/ 0188 /* Unpack input compressed data to uncompressed output uncompressed data */ 0189 int fp_unpack_data_to_data (const char *inputBuffer, size_t inputBufferSize, unsigned char **outputBuffer, 0190 size_t *outputBufferSize, fpstate fpvar); 0191 0192 int fp_test (char *infits, char *outfits, char *outfits2, fpstate fpvar); 0193 int fp_pack_hdu (fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, 0194 int *islossless, int *status); 0195 int fp_unpack_hdu (fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, int *status); 0196 int fits_read_image_speed (fitsfile *infptr, float *whole_elapse, 0197 float *whole_cpu, float *row_elapse, float *row_cpu, int *status); 0198 int fp_test_hdu (fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2, 0199 fpstate fpvar, int *status); 0200 int fp_test_table (fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2, 0201 fpstate fpvar, int *status); 0202 int marktime(int *status); 0203 int gettime(float *elapse, float *elapscpu, int *status); 0204 int fits_read_image_speed (fitsfile *infptr, float *whole_elapse, 0205 float *whole_cpu, float *row_elapse, float *row_cpu, int *status); 0206 0207 int fp_i2stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status); 0208 int fp_i4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status); 0209 int fp_r4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status); 0210 int fp_i2rescale(fitsfile *infptr, int naxis, long *naxes, double rescale, 0211 fitsfile *outfptr, int *status); 0212 int fp_i4rescale(fitsfile *infptr, int naxis, long *naxes, double rescale, 0213 fitsfile *outfptr, int *status); 0214 0215 #define fp_msg(msg) _fp_msg((const char *)msg) 0216 int _fp_msg (const char *msg); 0217 int fp_version (void); 0218 int fp_noop (void); 0219 0220 int fu_get_param (int argc, char *argv[], fpstate *fpptr); 0221 int fu_usage (void); 0222 int fu_hint (void); 0223 int fu_help (void); 0224 0225 #ifdef __cplusplus 0226 } 0227 #endif