/* FPACK * R. Seaman, NOAO * uses fits_img_compress by W. Pence, HEASARC */ #include "fitsio.h" #include "fpack.h" int main(int argc, char *argv[]) { fpstate fpvar; if (argc <= 1) { fp_usage (); fp_hint (); exit (-1); } fp_init (&fpvar); fp_get_param (argc, argv, &fpvar); if (fpvar.listonly) { fp_list (argc, argv, fpvar); } else { fp_preflight (argc, argv, &fpvar); fp_loop (argc, argv, FPACK, fpvar); } exit (0); } fp_get_param (int argc, char *argv[], fpstate *fpptr) { int gottype=0, gottile=0, wholetile=0, iarg, len, ndim, ii; char tmp[SZ_STR], tile[SZ_STR]; if (fpptr->initialized != FP_INIT_MAGIC) { fp_msg ("internal initialization error\n"); exit (-1); } tile[0] = (char) NULL; /* flags must come first and be separately specified */ for (iarg = 1; iarg < argc; iarg++) { if (argv[iarg][0] == '-' && strlen (argv[iarg]) == 2) { /* Rice is the default, so -r is superfluous */ if (argv[iarg][1] == 'r') { fpptr->comptype = RICE_1; if (gottype) { fp_msg ("multiple compression flags\n"); fp_usage (); exit (-1); } else gottype++; } else if (argv[iarg][1] == 'p') { fpptr->comptype = PLIO_1; if (gottype) { fp_msg ("multiple compression flags\n"); fp_usage (); exit (-1); } else gottype++; } else if (argv[iarg][1] == 'g') { fpptr->comptype = GZIP_1; if (gottype) { fp_msg ("multiple compression flags\n"); fp_usage (); exit (-1); } else gottype++; } else if (argv[iarg][1] == 'h') { fpptr->comptype = HCOMPRESS_1; if (gottype) { fp_msg ("multiple compression flags\n"); fp_usage (); exit (-1); } else gottype++; } else if (argv[iarg][1] == 'n') { if (++iarg >= argc) { fp_usage (); exit (-1); } else { fpptr->noise = atoi (argv[iarg]); if (fpptr->noise < 0 || fpptr->noise > 16) { fp_msg ("noise must be between 0 and 16 bits\n"); fp_usage (); exit (-1); } } } else if (argv[iarg][1] == 's') { if (++iarg >= argc) { fp_usage (); exit (-1); } else { fpptr->scale = atoi (argv[iarg]); if (fpptr->scale < 0) { fp_msg ("scale factor must be non-negative\n"); fp_usage (); exit (-1); } } } else if (argv[iarg][1] == 't') { if (gottile) { fp_msg ("multiple tile specifications\n"); fp_usage (); exit (-1); } else gottile++; if (++iarg >= argc) { fp_usage (); exit (-1); } else strncpy (tile, argv[iarg], SZ_STR); /* checked below */ } else if (argv[iarg][1] == 'w') { wholetile++; if (gottile) { fp_msg ("multiple tile specifications\n"); fp_usage (); exit (-1); } else gottile++; } else if (argv[iarg][1] == 'F') { fpptr->clobber++; } else if (argv[iarg][1] == 'P') { if (++iarg >= argc) { fp_usage (); fp_hint (); exit (-1); } else strncpy (fpptr->prefix, argv[iarg], SZ_STR); /* } else if (argv[iarg][1] == 'v') { * fpptr->verbose++; */ } else if (argv[iarg][1] == 'S') { fpptr->to_stdout++; } else if (argv[iarg][1] == 'L') { fpptr->listonly++; } else if (argv[iarg][1] == 'C') { fpptr->do_checksums = 0; } else if (argv[iarg][1] == 'H') { fp_help (); exit (0); } else if (argv[iarg][1] == 'V') { fp_version (); exit (0); } else { fp_msg ("unknown command line flag `"); fp_msg (argv[iarg]); fp_msg ("'\n"); fp_usage (); fp_hint (); exit (-1); } } else break; } if (! fpptr->listonly && ! fpptr->to_stdout && ! fpptr->clobber && ! fpptr->prefix[0]) { fp_msg ("to overwrite input files, must specify `-F'\n"); fp_msg (" otherwise specify output prefix with `-P'\n\n"); fp_usage (); fp_hint (); exit (-1); } if (fpptr->scale != 0 && fpptr->comptype != HCOMPRESS_1) { fp_msg ("`-s' requires `-h'\n"); exit (-1); } if (wholetile) { for (ndim=0; ndim < MAX_COMPRESS_DIM; ndim++) fpptr->ntile[ndim] = (long) 0; } else if (gottile) { len = strlen (tile); for (ii=0, ndim=0; ii < len; ) { if (! (isdigit (tile[ii]) || tile[ii] == ',')) { fp_msg ("`-t' requires comma separated tile dims, "); fp_msg ("e.g., `-t 100,100'\n"); exit (-1); } if (tile[ii] == ',') { ii++; continue; } fpptr->ntile[ndim] = atol (&tile[ii]); for ( ; isdigit(tile[ii]); ii++); if (++ndim > MAX_COMPRESS_DIM) { fp_msg ("too many dimensions for `-t', max="); sprintf (tmp, "%d\n", MAX_COMPRESS_DIM); fp_msg (tmp); exit (-1); } } } if (iarg >= argc) { fp_msg ("no FITS files to compress\n"); fp_usage (); exit (-1); } else fpptr->firstfile = iarg; } fp_usage () { fp_msg ("usage: fpack "); fp_msg ( "[-r|-p|-g|-h] [-w|-t ] [-n ] [-s ] \n"); fp_msg ("more: [-F|-P
] [-L] [-C] [-H] [-V]\n");
}

fp_hint () { fp_msg ("      `fpack -H' for help\n"); }

fp_help ()
{
fp_msg ("fpack, a FITS tile-compression engine.  Version ");
fp_version ();
fp_usage ();
fp_msg ("\n");

fp_msg ("Flags must be separate and appear before filenames:\n");
fp_msg ("   -r          Rice compression [default], or\n");
fp_msg ("   -p          PLIO compression, or\n");
fp_msg ("   -g          GZIP (per-tile) compression\n");
fp_msg ("   -h          Hcompress compression\n");

fp_msg ("   -w          override tile size to be whole image, or\n");
fp_msg ("   -t    comma separated list of tile sizes [default=row]\n");
fp_msg ("   -n    noise bits to preserve for real pixels [default=4]\n");
fp_msg ("   -s   scale factor for lossy Hcompress [default=0]\n");

fp_msg ("\nkeywords shared with funpack:\n");
/* fp_msg ("   -v          verbose\n");
 */

fp_msg ("   -F          clobber output [required to overwrite in-place]\n");
fp_msg ("   -P 
    prepend 
 to create new output filenames\n");
fp_msg ("   -S          output to STDOUT\n");
fp_msg ("   -L          list contents, files unchanged\n");
/* fp_msg ("   -L          list and validate contents, files unchanged\n");
 */

fp_msg ("   -C          don't update FITS checksum keywords\n");

fp_msg ("   -H          print this message\n");
fp_msg ("   -V          print version number\n");

fp_msg ("         FITS files to pack\n");
}