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