Debian Codegraph @

cextern/cfitsio/utilities/funpack.c

raw
1 /* FUNPACK
2 * R. Seaman, NOAO
3 * uses fits_img_compress by W. Pence, HEASARC
4 */
5
6 #include "fitsio.h"
7 #include "fpack.h"
8
9 int main (int argc, char *argv[])
10 {
11 fpstate fpvar;
12
13 if (argc <= 1) { fu_usage (); fu_hint (); exit (-1); }
14
15 fp_init (&fpvar);
16 fu_get_param (argc, argv, &fpvar);
17
18 if (fpvar.listonly) {
19 fp_list (argc, argv, fpvar);
20
21 } else {
22 fp_preflight (argc, argv, FUNPACK, &fpvar);
23 fp_loop (argc, argv, FUNPACK, fpvar);
24 }
25
26 exit (0);
27 }
28
29 int fu_get_param (int argc, char *argv[], fpstate *fpptr)
30 {
31 int iarg;
32 char tile[SZ_STR];
33
34 if (fpptr->initialized != FP_INIT_MAGIC) {
35 fp_msg ("Error: internal initialization error\n"); exit (-1);
36 }
37
38 tile[0] = 0;
39
40 /* by default, .fz suffix characters to be deleted from compressed file */
41 fpptr->delete_suffix = 1;
42
43 /* flags must come first and be separately specified
44 */
45 for (iarg = 1; iarg < argc; iarg++) {
46 if (argv[iarg][0] == '-' && strlen (argv[iarg]) == 2) {
47
48 if (argv[iarg][1] == 'F') {
49 fpptr->clobber++;
50 fpptr->delete_suffix = 0; /* no suffix in this case */
51
52 } else if (argv[iarg][1] == 'D') {
53 fpptr->delete_input++;
54
55 } else if (argv[iarg][1] == 'P') {
56 if (++iarg >= argc) {
57 fu_usage (); fu_hint (); exit (-1);
58 } else {
59 strncpy (fpptr->prefix, argv[iarg], SZ_STR-1);
60 fpptr->prefix[SZ_STR-1] = 0;
61 }
62
63 } else if (argv[iarg][1] == 'E') {
64 if (++iarg >= argc) {
65 fu_usage (); fu_hint (); exit (-1);
66 } else {
67 strncpy (fpptr->extname, argv[iarg], SZ_STR-1);
68 fpptr->extname[SZ_STR-1]=0;
69 }
70
71 } else if (argv[iarg][1] == 'S') {
72 fpptr->to_stdout++;
73
74 } else if (argv[iarg][1] == 'L') {
75 fpptr->listonly++;
76
77 } else if (argv[iarg][1] == 'C') {
78 fpptr->do_checksums = 0;
79
80 } else if (argv[iarg][1] == 'H') {
81 fu_help (); exit (0);
82
83 } else if (argv[iarg][1] == 'V') {
84 fp_version (); exit (0);
85
86 } else if (argv[iarg][1] == 'Z') {
87 fpptr->do_gzip_file++;
88
89 } else if (argv[iarg][1] == 'v') {
90 fpptr->verbose = 1;
91
92 } else if (argv[iarg][1] == 'O') {
93 if (++iarg >= argc) {
94 fu_usage (); fu_hint (); exit (-1);
95 } else {
96 strncpy (fpptr->outfile, argv[iarg], SZ_STR-1);
97 fpptr->outfile[SZ_STR-1]=0;
98 }
99
100 } else {
101 fp_msg ("Error: unknown command line flag `");
102 fp_msg (argv[iarg]); fp_msg ("'\n");
103 fu_usage (); fu_hint (); exit (-1);
104 }
105
106 } else
107 break;
108 }
109
110 if (fpptr->extname[0] && (fpptr->clobber || fpptr->delete_input)) {
111 fp_msg ("Error: -E option may not be used with -F or -D\n");
112 fu_usage (); exit (-1);
113 }
114
115 if (fpptr->to_stdout && (fpptr->outfile[0] || fpptr->prefix[0]) ) {
116
117 fp_msg ("Error: -S option may not be used with -P or -O\n");
118 fu_usage (); exit (-1);
119 }
120
121 if (fpptr->outfile[0] && fpptr->prefix[0] ) {
122 fp_msg ("Error: -P and -O options may not be used together\n");
123 fu_usage (); exit (-1);
124 }
125
126 if (iarg >= argc) {
127 fp_msg ("Error: no FITS files to uncompress\n");
128 fu_usage (); exit (-1);
129 } else
130 fpptr->firstfile = iarg;
131
132 return(0);
133 }
134
135 int fu_usage (void)
136 {
137 fp_msg ("usage: funpack [-E <HDUlist>] [-P <pre>] [-O <name>] [-Z] -v <FITS>\n");
138 fp_msg ("more: [-F] [-D] [-S] [-L] [-C] [-H] [-V] \n");
139 return(0);
140 }
141
142 int fu_hint (void)
143 {
144 fp_msg (" `funpack -H' for help\n");
145 return(0);
146 }
147
148 int fu_help (void)
149 {
150 fp_msg ("funpack, decompress fpacked files. Version ");
151 fp_version ();
152 fu_usage ();
153 fp_msg ("\n");
154
155 fp_msg ("Flags must be separate and appear before filenames:\n");
156 fp_msg (" -E <HDUlist> Unpack only the list of HDU names or numbers in the file.\n");
157 fp_msg (" -P <pre> Prepend <pre> to create new output filenames.\n");
158 fp_msg (" -O <name> Specify full output file name.\n");
159 fp_msg (" -Z Recompress the output file with host GZIP program.\n");
160 fp_msg (" -F Overwrite input file by output file with same name.\n");
161 fp_msg (" -D Delete input file after writing output.\n");
162 fp_msg (" -S Output uncompressed file to STDOUT file stream.\n");
163 fp_msg (" -L List contents, files unchanged.\n");
164
165 fp_msg (" -C Don't update FITS checksum keywords.\n");
166
167 fp_msg (" -v Verbose mode; list each file as it is processed.\n");
168 fp_msg (" -H Show this message.\n");
169 fp_msg (" -V Show version number.\n");
170
171 fp_msg (" \n<FITS> FITS files to unpack; enter '-' (a hyphen) to read from stdin.\n");
172 fp_msg (" Refer to the fpack User's Guide for more extensive help.\n");
173 return(0);
174 }