41 int gottype=0, gottile=0, wholetile=0, iarg, len, ndim, ii, doffset;
45 fp_msg (
"Error: internal initialization error\n"); exit (-1);
52 for (iarg = 1; iarg < argc; iarg++) {
53 if ((argv[iarg][0] ==
'-' && strlen (argv[iarg]) == 2) ||
54 !strncmp(argv[iarg],
"-q", 2) || !strncmp(argv[iarg],
"-qz", 3) ||
55 !strncmp(argv[iarg],
"-g1", 3) || !strncmp(argv[iarg],
"-g2", 3) ||
56 !strncmp(argv[iarg],
"-i2f", 4) ||
57 !strncmp(argv[iarg],
"-n3ratio", 8) || !strncmp(argv[iarg],
"-n3min", 6) ||
58 !strncmp(argv[iarg],
"-tableonly", 10) || !strncmp(argv[iarg],
"-table", 6) )
62 if ( argv[iarg][1] ==
'r') {
65 fp_msg (
"Error: multiple compression flags\n");
70 }
else if (argv[iarg][1] ==
'p') {
73 fp_msg (
"Error: multiple compression flags\n");
78 }
else if (argv[iarg][1] ==
'g') {
80 if (argv[iarg][2] ==
'2')
86 fp_msg (
"Error: multiple compression flags\n");
99 }
else if (argv[iarg][1] ==
'h') {
102 fp_msg (
"Error: multiple compression flags\n");
107 }
else if (argv[iarg][1] ==
'd') {
110 fp_msg (
"Error: multiple compression flags\n");
115 }
else if (!strcmp(argv[iarg],
"-i2f")) {
124 }
else if (!strcmp(argv[iarg],
"-n3ratio")) {
128 if (++iarg >= argc) {
131 fpptr->
n3ratio = (float) atof (argv[iarg]);
133 }
else if (!strcmp(argv[iarg],
"-n3min")) {
136 if (++iarg >= argc) {
139 fpptr->
n3min = (float) atof (argv[iarg]);
141 }
else if (argv[iarg][1] ==
'q') {
144 if (argv[iarg][2] ==
'z') {
147 if (argv[iarg][3] ==
't') {
150 }
else if (isdigit(argv[iarg][3])) {
151 doffset = atoi(argv[iarg]+3);
155 }
else if (doffset > 0 && doffset <= 10000) {
158 fp_msg (
"Error: invalid q suffix\n");
163 if (argv[iarg][2] ==
't') {
166 }
else if (isdigit(argv[iarg][2])) {
167 doffset = atoi(argv[iarg]+2);
171 }
else if (doffset > 0 && doffset <= 10000) {
174 fp_msg (
"Error: invalid q suffix\n");
180 if (++iarg >= argc) {
185 }
else if (argv[iarg][1] ==
'n') {
186 if (++iarg >= argc) {
191 }
else if (argv[iarg][1] ==
's') {
192 if (++iarg >= argc) {
195 fpptr->
scale = (float) atof (argv[iarg]);
197 }
else if (!strcmp(argv[iarg],
"-tableonly")) {
200 fp_msg (
"Note: -tableonly is intended for feasibility studies, not general use.\n");
202 }
else if (!strcmp(argv[iarg],
"-table")) {
204 fp_msg (
"Note: -table is intended for feasibility studies, not general use.\n");
206 }
else if (argv[iarg][1] ==
't') {
208 fp_msg (
"Error: multiple tile specifications\n");
213 if (++iarg >= argc) {
216 strncpy (tile, argv[iarg],
SZ_STR);
218 }
else if (argv[iarg][1] ==
'v') {
221 }
else if (argv[iarg][1] ==
'w') {
224 fp_msg (
"Error: multiple tile specifications\n");
229 }
else if (argv[iarg][1] ==
'F') {
232 }
else if (argv[iarg][1] ==
'D') {
235 }
else if (argv[iarg][1] ==
'Y') {
238 }
else if (argv[iarg][1] ==
'S') {
241 }
else if (argv[iarg][1] ==
'L') {
244 }
else if (argv[iarg][1] ==
'C') {
247 }
else if (argv[iarg][1] ==
'T') {
250 }
else if (argv[iarg][1] ==
'R') {
251 if (++iarg >= argc) {
256 }
else if (argv[iarg][1] ==
'H') {
259 }
else if (argv[iarg][1] ==
'V') {
263 fp_msg (
"Error: unknown command line flag `");
272 if (fpptr->
scale != 0. &&
275 fp_msg (
"Error: `-s' requires `-h or -T'\n"); exit (-1);
281 fp_msg (
"Error: `-q 0' only allowed with GZIP\n"); exit (-1);
285 fp_msg (
"Error: `-q 0' not allowed with -i2f\n"); exit (-1);
290 for (ndim=0; ndim < MAX_COMPRESS_DIM; ndim++)
291 fpptr->
ntile[ndim] = (
long) -1;
293 }
else if (gottile) {
295 for (ii=0, ndim=0; ii < len; ) {
296 if (! (isdigit (tile[ii]) || tile[ii] ==
',')) {
297 fp_msg (
"Error: `-t' requires comma separated tile dims, ");
298 fp_msg (
"e.g., `-t 100,100'\n"); exit (-1);
301 if (tile[ii] ==
',') { ii++;
continue; }
303 fpptr->
ntile[ndim] = atol (&tile[ii]);
304 for ( ; isdigit(tile[ii]); ii++);
306 if (++ndim > MAX_COMPRESS_DIM) {
307 fp_msg (
"Error: too many dimensions for `-t', max=");
308 snprintf (tmp,
SZ_STR,
"%d\n", MAX_COMPRESS_DIM);
fp_msg (tmp);
315 fp_msg (
"Error: no FITS files to compress\n");
328 "[-r|-h|-g|-p] [-w|-t <axes>] [-q <level>] [-s <scale>] [-n <noise>] -v <FITS>\n");
329 fp_msg (
"more: [-T] [-R] [-F] [-D] [-Y] [-S] [-L] [-C] [-H] [-V] [-i2f]\n");
335 {
fp_msg (
" `fpack -H' for help\n");
342 fp_msg (
"fpack, a FITS image compression program. Version ");
346 fp_msg (
"NOTE: the compression parameters specified on the fpack command line may\n");
347 fp_msg (
"be over-ridden by compression directive keywords in the header of each HDU\n");
348 fp_msg (
"of the input file(s). See the fpack User's Guide for more details\n");
351 fp_msg (
"Flags must be separate and appear before filenames:\n");
352 fp_msg (
" -r Rice compression [default], or\n");
353 fp_msg (
" -h Hcompress compression, or\n");
354 fp_msg (
" -g or -g1 GZIP_1 (per-tile) compression, or\n");
355 fp_msg (
" -g2 GZIP_2 (per-tile) compression (with byte shuffling), or\n");
359 fp_msg (
" -p PLIO compression (only for positive 8 or 16-bit integer images).\n");
360 fp_msg (
" -d Tile the image without compression (debugging mode).\n");
362 fp_msg (
" -w Compress the whole image as a single large tile.\n");
363 fp_msg (
" -t <axes> Comma separated list of tile dimensions [default is row by row].\n");
365 fp_msg (
" -q <level> Quantized level spacing when converting floating point images to\n");
366 fp_msg (
" scaled integers. (+value relative to sigma of background noise;\n");
367 fp_msg (
" -value is absolute). Default q value of 4 gives a compression ratio\n");
368 fp_msg (
" of about 6 with very high fidelity (only 0.26% increase in noise).\n");
369 fp_msg (
" Using q values of 2, or 1 will give compression ratios of\n");
370 fp_msg (
" about 8, or 10, respectively (with 1.0% or 4.1% noise increase).\n");
371 fp_msg (
" The scaled quantized values are randomly dithered using a seed \n");
372 fp_msg (
" value determined from the system clock at run time.\n");
373 fp_msg (
" Use -q0 instead of -q to suppress random dithering.\n");
374 fp_msg (
" Use -qz instead of -q to not dither zero-valued pixels.\n");
375 fp_msg (
" Use -qt or -qzt to compute random dithering seed from first tile checksum.\n");
376 fp_msg (
" Use -qN or -qzN, (N in range 1 to 10000) to use a specific dithering seed.\n");
377 fp_msg (
" Floating-point images can be losslessly compressed by selecting\n");
378 fp_msg (
" the GZIP algorithm and specifying -q 0, but this is slower and often\n");
379 fp_msg (
" produces much less compression than the default quantization method.\n");
380 fp_msg (
" -i2f Convert integer images to floating point, then quantize and compress\n");
381 fp_msg (
" using the specified q level. When used appropriately, this lossy\n");
382 fp_msg (
" compression method can give much better compression than the normal\n");
383 fp_msg (
" lossless compression methods without significant loss of information.\n");
384 fp_msg (
" The -n3ratio and -n3min flags control the minimum noise thresholds;\n");
385 fp_msg (
" Images below these thresholds will be losslessly compressed.\n");
386 fp_msg (
" -n3ratio Minimum ratio of background noise sigma divided by q. Default = 2.0.\n");
387 fp_msg (
" -n3min Minimum background noise sigma. Default = 6. The -i2f flag will be ignored\n");
388 fp_msg (
" if the noise level in the image does not exceed both thresholds.\n");
389 fp_msg (
" -s <scale> Scale factor for lossy Hcompress [default = 0 = lossless]\n");
390 fp_msg (
" (+values relative to RMS noise; -value is absolute)\n");
391 fp_msg (
" -n <noise> Rescale scaled-integer images to reduce noise and improve compression.\n");
392 fp_msg (
" -v Verbose mode; list each file as it is processed.\n");
393 fp_msg (
" -T Show compression algorithm comparison test statistics; files unchanged.\n");
394 fp_msg (
" -R <file> Write the comparison test report (above) to a text file.\n");
395 fp_msg (
" -table Compress FITS binary tables as well as compress any image HDUs.\n");
396 fp_msg (
" -tableonly Compress only FITS binary tables; do not compress any image HDUs.\n");
399 fp_msg (
"\nkeywords shared with funpack:\n");
401 fp_msg (
" -F Overwrite input file by output file with same name.\n");
402 fp_msg (
" -D Delete input file after writing output.\n");
403 fp_msg (
" -Y Suppress prompts to confirm -F or -D options.\n");
405 fp_msg (
" -S Output compressed FITS files to STDOUT.\n");
406 fp_msg (
" -L List contents; files unchanged.\n");
408 fp_msg (
" -C Don't update FITS checksum keywords.\n");
410 fp_msg (
" -H Show this message.\n");
411 fp_msg (
" -V Show version number.\n");
413 fp_msg (
"\n <FITS> FITS files to pack; enter '-' (a hyphen) to read input from stdin stream.\n");
414 fp_msg (
" Refer to the fpack User's Guide for more extensive help.\n");
int fp_get_param(int argc, char *argv[], fpstate *fpptr)
int _fp_msg(const char *msg)
long ntile[MAX_COMPRESS_DIM]