Instrument Neutral Distributed Interface INDI 2.2.5
fpack.h
Go to the documentation of this file.
1/* used by FPACK and FUNPACK
2 SPDX-FileCopyrightText: William D. Pence <https://heasarc.gsfc.nasa.gov/fitsio/>
3 SPDX-FileCopyrightText: R. Seaman
4
5 SPDX-License-Identifier: LicenseRef-NASA-FV-License-Agreement
6*/
7
8#pragma once
9
10#include <string.h>
11#include <stdio.h>
12#include <stdlib.h>
13
14/* not needed any more */
15/* #include <unistd.h> */
16/* #include <sys/stat.h> */
17/* #include <sys/types.h> */
18
19#define FPACK_VERSION "1.7.0 (Dec 2013)"
20/*
21VERSION History
22
231.7.0 (Dec 2013)
24 - extensive changes to the binary table compression method. All types
25 of binary table columns, including variable length array columns are
26 now supported. The command line table compression flag has been changed
27 to "-table" instead of "-BETAtable", and a new "-tableonly" flag has
28 been introduced to only compress the binary tables in the input files(s)
29 and not the image HDUs.
301.6.1 (Mar 2013)
31 - numerous changes to the BETAtable compression method used to compress
32 binary tables
33 - added support for compression 'steering' keywords that specify the
34 desired compression parameters that should be used when compressing
35 that particular HDU, thus overriding the fpack command line parameter
36 values.
37
381.6.0 (June 2012)
39 - Fixed behavior of the "rename" function on Windows platforms so that
40 it will clobber/delete an existing file before renaming a file to
41 that name (the rename command behaves differently on POSIX and non-POSIX
42 environments).
43
441.6.0 (February 2011)
45 - Added full support for compressing and uncompressing FITS binary tables
46 using a newly proposed format convention. This is intended only for
47 further feasibility studies, and is not recommended for use with publicly
48 distributed FITS files.
49 - Use the minimum of the MAD 2nd, 3rd, and 5th order values as a more
50 conservative estimate of the noise when quantizing floating point images.
51 - Enhanced the tile compression routines so that a tile that contains all
52 NaN pixel values will be compressed.
53 - When uncompressing an image that was originally in a FITS primary array,
54 funpack will also append any new keywords that were written into the
55 primary array of the compressed FITS file after the file was compressed.
56 - Added support for the GZIP_2 algorithm, which shuffles the bytes in the
57 pixel values prior to compressing them with gzip.
581.5.1 (December 2010) Added prototype, mainly hidden, support for compressing
59 binary tables.
601.5.0 (August 2010) Added the -i2f option to lossy compress integer images.
611.4.0 (Jan 2010) Reduced the default value for the q floating point image
62 quantization parameter from 16 to 4. This results in about 50% better
63 compression (from about 4.6x to 6.4) with no lost of significant information
64 (with the new subtractive dithering enhancement). Replaced the code for
65 generating temporary filenames to make the code more portable (to Windows).
66 Replaced calls to the unix 'access' and 'stat' functions with more portable
67 code. When unpacking a file, write it first to a temporary file, then
68 rename it when finished, so that other tasks cannot try to read the file
69 before it is complete.
701.3.0 (Oct 2009) added randomization to the dithering pattern so that
71 the same pattern is not used for every image; also added an option
72 for losslessly compressing floating point images with GZIP for test
73 purposes (not recommended for general use). Also added support for
74 reading the input FITS file from the stdin file streams.
751.2.0 (Sept 2009) added subtractive dithering feature (in CFITSIO) when
76 quantizing floating point images; When packing an IRAF .imh + .pix image,
77 the file name is changed to FILE.fits.fz, and if the original file is
78 deleted, then both the .imh and .pix files are deleted.
791.1.4 (May 2009) added -E option to funpack to unpack a list of HDUs
801.1.3 (March 2009) minor modifications to the content and format of the -T report
811.1.2 (September 2008)
82*/
83
84#define FP_INIT_MAGIC 42
85#define FPACK 0
86#define FUNPACK 1
87
88/* changed from 16 in Jan. 2010 */
89#define DEF_QLEVEL 4.
90
91#define DEF_HCOMP_SCALE 0.
92#define DEF_HCOMP_SMOOTH 0
93#define DEF_RESCALE_NOISE 0
94
95#define SZ_STR 513
96#define SZ_CARD 81
97
98
99typedef struct
100{
106 float scale;
110 float n3ratio;
111 float n3min;
112 long ntile[MAX_COMPRESS_DIM];
113
125
126 char prefix[SZ_STR];
127 char extname[SZ_STR];
129 char outfile[SZ_STR];
131
134} fpstate;
135
136typedef struct
137{
139 double minval;
140 double maxval;
141 double mean;
142 double sigma;
143 double noise1;
144 double noise2;
145 double noise3;
146 double noise5;
147} imgstats;
148
149#ifdef __cplusplus
150extern "C" {
151#endif
152
153int fp_get_param (int argc, char *argv[], fpstate *fpptr);
154void abort_fpack(int sig);
155void fp_abort_output (fitsfile *infptr, fitsfile *outfptr, int stat);
156int fp_usage (void);
157int fp_help (void);
158int fp_hint (void);
159int fp_init (fpstate *fpptr);
160int fp_list (int argc, char *argv[], fpstate fpvar);
161int fp_info (char *infits);
162int fp_info_hdu (fitsfile *infptr);
163int fp_preflight (int argc, char *argv[], int unpack, fpstate *fpptr);
164int fp_loop (int argc, char *argv[], int unpack, char *output_filename, fpstate fpvar);
165
166/* Core pack function */
167/* Unpack input file to outfile file on disk */
168int fp_pack (char *infits, char *outfits, fpstate fpvar, int *islossless);
169/* Unpack input data to output FITS file in memory */
170int fp_pack_data_to_fits (const char *inputBuffer, size_t inputBufferSize, fitsfile **outfits, fpstate fpvar,
171 int *islossless);
172/* Unpack input data to output data in memory */
173int fp_pack_data_to_data (const char *inputBuffer, size_t inputBufferSize, unsigned char **outputBuffer,
174 size_t *outputBufferSize,
175 fpstate fpvar,
176 int *islossless);
177/* Pack input fits file to in-memory fits file */
178int fp_pack_fits_to_fits (fitsfile *infptr, fitsfile **outfits, fpstate fpvar, int *islossless);
179
180/* Core unpark functions */
181
182/* Unpack on disk file to output on disk file */
183int fp_unpack (char *infits, char *outfits, fpstate fpvar);
184/* Unpack input compressed input file to uncompressed output in-memory fits file */
185int fp_unpack_file_to_fits (char *infits, fitsfile **outfits, fpstate fpvar);
186/* Unpack input compressed data to uncompressed output in-memory fits file */
187int fp_unpack_data_to_fits (const char *inputBuffer, size_t inputBufferSize, fitsfile **outfptr, fpstate fpvar);
188
189int fp_test (char *infits, char *outfits, char *outfits2, fpstate fpvar);
190int fp_pack_hdu (fitsfile *infptr, fitsfile *outfptr, fpstate fpvar,
191 int *islossless, int *status);
192int fp_unpack_hdu (fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, int *status);
193int fits_read_image_speed (fitsfile *infptr, float *whole_elapse,
194 float *whole_cpu, float *row_elapse, float *row_cpu, int *status);
195int fp_test_hdu (fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2,
196 fpstate fpvar, int *status);
197int fp_test_table (fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2,
198 fpstate fpvar, int *status);
199int marktime(int *status);
200int gettime(float *elapse, float *elapscpu, int *status);
201int fits_read_image_speed (fitsfile *infptr, float *whole_elapse,
202 float *whole_cpu, float *row_elapse, float *row_cpu, int *status);
203
204int fp_i2stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status);
205int fp_i4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status);
206int fp_r4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status);
207int fp_i2rescale(fitsfile *infptr, int naxis, long *naxes, double rescale,
208 fitsfile *outfptr, int *status);
209int fp_i4rescale(fitsfile *infptr, int naxis, long *naxes, double rescale,
210 fitsfile *outfptr, int *status);
211
212#define fp_msg(msg) _fp_msg((const char *)msg)
213int _fp_msg (const char *msg);
214int fp_version (void);
215int fp_noop (void);
216
217int fu_get_param (int argc, char *argv[], fpstate *fpptr);
218int fu_usage (void);
219int fu_hint (void);
220int fu_help (void);
221
222#ifdef __cplusplus
223}
224#endif
int fp_pack_data_to_data(const char *inputBuffer, size_t inputBufferSize, unsigned char **outputBuffer, size_t *outputBufferSize, fpstate fpvar, int *islossless)
Definition fpackutil.c:1027
void abort_fpack(int sig)
Definition fpackutil.c:2864
int fp_loop(int argc, char *argv[], int unpack, char *output_filename, fpstate fpvar)
Definition fpackutil.c:573
int fp_usage(void)
Definition fpack.c:324
int fp_preflight(int argc, char *argv[], int unpack, fpstate *fpptr)
Definition fpackutil.c:361
int fits_read_image_speed(fitsfile *infptr, float *whole_elapse, float *whole_cpu, float *row_elapse, float *row_cpu, int *status)
Definition fpackutil.c:2115
int fp_get_param(int argc, char *argv[], fpstate *fpptr)
Definition fpack.c:39
int fp_pack_hdu(fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, int *islossless, int *status)
Definition fpackutil.c:1902
int fp_noop(void)
Definition fpackutil.c:58
int fp_pack_fits_to_fits(fitsfile *infptr, fitsfile **outfits, fpstate fpvar, int *islossless)
Definition fpackutil.c:1096
int fp_pack_data_to_fits(const char *inputBuffer, size_t inputBufferSize, fitsfile **outfits, fpstate fpvar, int *islossless)
Definition fpackutil.c:955
int _fp_msg(const char *msg)
Definition fpack.c:33
int marktime(int *status)
Definition fpackutil.c:2452
void fp_abort_output(fitsfile *infptr, fitsfile *outfptr, int stat)
Definition fpackutil.c:64
#define SZ_STR
Definition fpack.h:95
int fp_info_hdu(fitsfile *infptr)
Definition fpackutil.c:260
int fu_hint(void)
int fp_i2rescale(fitsfile *infptr, int naxis, long *naxes, double rescale, fitsfile *outfptr, int *status)
Definition fpackutil.c:2742
int fp_hint(void)
Definition fpack.c:334
int fp_unpack_hdu(fitsfile *infptr, fitsfile *outfptr, fpstate fpvar, int *status)
Definition fpackutil.c:2076
int fp_i4rescale(fitsfile *infptr, int naxis, long *naxes, double rescale, fitsfile *outfptr, int *status)
Definition fpackutil.c:2802
int fp_test_table(fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2, fpstate fpvar, int *status)
Definition fpackutil.c:2408
int fp_test(char *infits, char *outfits, char *outfits2, fpstate fpvar)
Definition fpackutil.c:1607
int fp_init(fpstate *fpptr)
Definition fpackutil.c:160
int fp_i2stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status)
Definition fpackutil.c:2504
int fp_version(void)
Definition fpackutil.c:94
int fp_list(int argc, char *argv[], fpstate fpvar)
Definition fpackutil.c:209
int fp_unpack(char *infits, char *outfits, fpstate fpvar)
Definition fpackutil.c:1159
int fu_usage(void)
int fp_i4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status)
Definition fpackutil.c:2585
int fp_help(void)
Definition fpack.c:340
int fp_test_hdu(fitsfile *infptr, fitsfile *outfptr, fitsfile *outfptr2, fpstate fpvar, int *status)
Definition fpackutil.c:2285
int fp_unpack_data_to_fits(const char *inputBuffer, size_t inputBufferSize, fitsfile **outfptr, fpstate fpvar)
Definition fpackutil.c:1456
int fp_pack(char *infits, char *outfits, fpstate fpvar, int *islossless)
Definition fpackutil.c:887
int fu_help(void)
int fp_unpack_file_to_fits(char *infits, fitsfile **outfits, fpstate fpvar)
Definition fpackutil.c:1306
int fp_r4stat(fitsfile *infptr, int naxis, long *naxes, imgstats *imagestats, int *status)
Definition fpackutil.c:2666
int gettime(float *elapse, float *elapscpu, int *status)
Definition fpackutil.c:2475
int fp_info(char *infits)
int fu_get_param(int argc, char *argv[], fpstate *fpptr)
int comptype
Definition fpack.h:101
int no_dither
Definition fpack.h:103
int listonly
Definition fpack.h:115
int do_images
Definition fpack.h:121
int delete_suffix
Definition fpack.h:128
int test_all
Definition fpack.h:123
int to_stdout
Definition fpack.h:114
int do_tables
Definition fpack.h:122
int initialized
Definition fpack.h:132
int clobber
Definition fpack.h:116
int dither_offset
Definition fpack.h:104
float rescale_noise
Definition fpack.h:107
int do_checksums
Definition fpack.h:119
int dither_method
Definition fpack.h:105
int do_gzip_file
Definition fpack.h:120
int delete_input
Definition fpack.h:117
float quantize_level
Definition fpack.h:102
int int_to_float
Definition fpack.h:109
int firstfile
Definition fpack.h:130
int smooth
Definition fpack.h:108
float scale
Definition fpack.h:106
int verbose
Definition fpack.h:124
int preflight_checked
Definition fpack.h:133
int do_not_prompt
Definition fpack.h:118
float n3ratio
Definition fpack.h:110
float n3min
Definition fpack.h:111
double sigma
Definition fpack.h:142
double noise2
Definition fpack.h:144
double minval
Definition fpack.h:139
double noise5
Definition fpack.h:146
double noise1
Definition fpack.h:143
double noise3
Definition fpack.h:145
int n_nulls
Definition fpack.h:138
double mean
Definition fpack.h:141
double maxval
Definition fpack.h:140