35 #include "head_cmdline.h"
60 for(
int i=0; i<skip; i++ )
61 gzgets( in, lbuf, 2048 );
66 for(
int i=0; i<h->
slice_sz(); i++ ) {
67 if( !gzgets( in, lbuf, 2048 ) )
69 if( sscanf( lbuf,
"%lf %lf %lf %lf %lf %lf %lf %lf %lf", d, d+1,
77 }
while( nr==h->
slice_sz() && ++tm<h->t() );
80 fprintf( stderr,
"\nTimes do not match!!!!!!!!!!!\n\n" );
86 int main(
int argc,
char* argv[] )
88 gengetopt_args_info args_info;
91 if (cmdline_parser (argc, argv, &args_info) != 0)
94 if( argc == 1 || args_info.inputs_num != 1 ) {
95 cmdline_parser_print_help();
100 gzFile in = gzopen( args_info.inputs[0],
"r" );
102 cerr <<
"File not found: " << args_info.inputs[0] << endl;
106 if( head_in->
read(
true) != 0 ) gzrewind( in );
117 if( args_info.x_given ) head_out->
x(
static_cast<size_t>(args_info.x_arg) );
118 if( args_info.y_given ) head_out->
y(
static_cast<size_t>(args_info.y_arg) );
119 if( args_info.z_given ) head_out->
z(
static_cast<size_t>(args_info.z_arg) );
120 if( args_info.t_given ) head_out->
t(
static_cast<size_t>(args_info.t_arg) );
121 if( args_info.data_type_given ) head_out->
type( args_info.data_type_arg );
122 if( args_info.system_given ) head_out->
systeme( args_info.system_arg==system_arg_big ?
"big_endian" :
"little_endian" );
123 if( args_info.dim_x_given ) head_out->
dim_x( args_info.dim_x_arg );
124 if( args_info.dim_y_given ) head_out->
dim_y( args_info.dim_y_arg );
125 if( args_info.dim_z_given ) head_out->
dim_z( args_info.dim_z_arg );
126 if( args_info.dim_t_given ) head_out->
dim_t( args_info.dim_t_arg );
127 if( args_info.org_x_given ) head_out->
org_x( args_info.org_x_arg );
128 if( args_info.org_y_given ) head_out->
org_y( args_info.org_y_arg );
129 if( args_info.org_z_given ) head_out->
org_z( args_info.org_z_arg );
130 if( args_info.org_t_given ) head_out->
org_t( args_info.org_t_arg );
131 if( args_info.inc_x_given ) head_out->
inc_x( args_info.inc_x_arg );
132 if( args_info.inc_y_given ) head_out->
inc_y( args_info.inc_y_arg );
133 if( args_info.inc_z_given ) head_out->
inc_z( args_info.inc_z_arg );
134 if( args_info.inc_t_given ) head_out->
inc_t( args_info.inc_t_arg );
135 if( args_info.x_units_given ) head_out->
unites_x( args_info.x_units_arg );
136 if( args_info.y_units_given ) head_out->
unites_y( args_info.y_units_arg );
137 if( args_info.z_units_given ) head_out->
unites_z( args_info.z_units_arg );
138 if( args_info.t_units_given ) head_out->
unites_t( args_info.t_units_arg );
139 if( args_info.clear_comment_given ) head_out->
comment(NULL);
140 if( args_info.comment_given ) head_out->
comment( args_info.comment_arg );
141 if( args_info.data_factor_given ) head_out->
facteur(args_info.data_factor_arg);
142 if( args_info.data_zero_given ) head_out->
zero( args_info.data_zero_arg );
143 if( args_info.author_given ) head_out->
aut_name( args_info.author_arg );
144 if( args_info.transparent_given ){
145 if( strlen(args_info.transparent_arg)!=2*
Data_Size[head_out->
type()] ){
146 cerr <<
"Incorrect tranparent value specified\n";
154 s[0] = args_info.transparent_arg[i*2];
155 s[1] = args_info.transparent_arg[i*2+1];
156 v[i] = strtol( s, &pp, 16 );
160 if( args_info.no_transparent_given ) head_out->
transparent( NULL );
163 if( args_info.jive_time_given )
168 tmpfn += basename(args_info.inputs[0]);
173 if( args_info.frankenstein_given ){
174 ofn = args_info.frankenstein_arg;
177 if( h->
read() != 0 ) gzrewind( in );
181 ofn = args_info.inputs[0];
183 if(args_info.output_file_given)
184 ofn = args_info.output_file_arg;
187 cerr <<
"Compressed IGB output is not supported. Use -f <name>.igb to write an uncompressed copy." << endl;
192 FILE* out_fp = fopen( tmpfn.c_str(),
"wb" );
193 if( out_fp == NULL ) {
194 cerr <<
"Unable to open temporary output file: " << tmpfn << endl;
200 if( !args_info.decapitate_given )
203 if( args_info.create_given )
205 else if( args_info.convert_data_flag ) {
206 double *slice_data =
new double[head_in->
slice_sz()];
207 for(
int t=0; t<head_in->
t(); t++ ) {
211 delete [] slice_data;
212 }
else if( args_info.transpose_flag ) {
214 long offset = head_out->
t()*ds;
215 long datStart = gztell( in );
216 char *buf = (
char *)malloc( head_out->
slice_sz()*ds );
217 for(
int i=0; i<head_out->
t(); i++ ) {
218 for(
int j=0; j<head_out->
slice_sz(); j++ ) {
219 gzseek( in,datStart+offset*j+i*ds, SEEK_SET );
220 gzread( in, buf+j*ds, ds*1 );
222 fwrite( buf, ds, head_out->
slice_sz(), out_fp );
226 const int bufsize=1000000;
227 char* buf =
new char[bufsize];
229 while( (nb=gzread( in, buf, bufsize )) > 0 ) fwrite( buf, 1, nb, out_fp );
235 rename( tmpfn.c_str(), ofn.c_str() );
242 printf(
"x dimension:\t%zu\n", header->
x() );
243 printf(
"y dimension:\t%zu\n", header->
y() );
244 printf(
"z dimension:\t%zu\n", header->
z() );
245 printf(
"t dimension:\t%zu\n", header->
t() );
249 printf(
"Pixel units:\t%s\n", header->
unites() );
256 printf(
"Pixel zero:\t%g\n", header->
zero() );
260 printf(
"Pixel scaling:\t%g\n", header->
facteur() );
264 printf(
"X size:\t\t%g\n", header->
dim_x() );
268 printf(
"X units:\t%s\n", header->
unites_x() );
272 printf(
"Increment in x:\t%g\n", header->
inc_x() );
276 printf(
"X origin:\t%g\n", header->
org_x() );
280 printf(
"Y size:\t\t%g\n", header->
dim_y() );
284 printf(
"Y units:\t%s\n", header->
unites_y() );
288 printf(
"Increment in y:\t%g\n", header->
inc_y() );
292 printf(
"Y origin:\t%g\n", header->
org_y() );
296 printf(
"Z size:\t\t%g\n", header->
dim_z() );
300 printf(
"Z units:\t%s\n", header->
unites_z() );
304 printf(
"Increment in z:\t%g\n", header->
inc_z() );
308 printf(
"Z origin:\t%g\n", header->
org_z() );
312 printf(
"T size:\t\t%g\n", header->
dim_t() );
316 printf(
"T units:\t%s\n", header->
unites_t() );
320 printf(
"Increment in t:\t%g\n", header->
inc_t() );
324 printf(
"T origin:\t%g\n", header->
org_t() );
326 printf(
"Created on:\t%s\n", header->
systemestr());
329 printf(
"Author:\t\t%s\n", header->
aut_name() );
331 if( header->
comment() != NULL ){
334 while( cm[i] != NULL )
335 printf(
"#%s\n", cm[i++] );
342 z_off_t zo = gztell( in );
343 const int bufsize=8196;
346 while( (nr=gzread( in, buff, bufsize )) == bufsize )
349 size_t slicesize = header->
x()*header->
y()*header->
z()*header->
data_size();
350 header->
t( nb/slicesize );
351 gzseek( in, zo, SEEK_SET );
352 if( header->
dim_t() )
359 return fn.size() >= 3 && fn.compare(fn.size()-3, 3,
".gz") == 0;
int main(int argc, char *argv[])
void write_to_binary(IGBheader *h, gzFile in, FILE *out_fp, int skip)
void output_header(IGBheader *)
size_t jive(IGBheader *header, gzFile in)
bool has_gzip_extension(const string &fn)
const char * Header_Type[]
unsigned short Data_Size[]