49 void close(){
if ( gzip )gzclose(gp);
else fclose(fp); }
50 void write(
void *buf,
int n){
if(gzip) gzwrite( gp, buf, n );
51 else fwrite( buf, n, 1, fp ); }
52 void printfl(
float f){
if(gzip)gzprintf(gp,
"%.7f\n",f);
else 53 fprintf( fp,
"%.7f\n", f ); }
76 for(
int i=0; i<skip; i++ )
77 gzgets( in, lbuf, 2048 );
82 for(
int i=0; i<h->
slice_sz(); i++ ) {
83 if( !gzgets( in, lbuf, 2048 ) )
85 if( sscanf( lbuf,
"%lf %lf %lf %lf %lf %lf %lf %lf %lf", d, d+1,
93 }
while( nr==h->
slice_sz() && ++tm<h->
t() );
96 fprintf( stderr,
"\nTimes do not match!!!!!!!!!!!\n\n" );
102 int main(
int argc,
char* argv[] )
104 gengetopt_args_info args_info;
107 if (cmdline_parser (argc, argv, &args_info) != 0)
110 if( argc == 1 || args_info.inputs_num != 1 ) {
111 cmdline_parser_print_help();
116 gzFile in = gzopen( args_info.inputs[0],
"r" );
118 cerr <<
"File not found: " << args_info.inputs[0] << endl;
122 if( head_in->
read(
true) != 0 ) gzrewind( in );
133 if( args_info.x_given ) head_out->
x( static_cast<size_t>(args_info.x_arg) );
134 if( args_info.y_given ) head_out->
y( static_cast<size_t>(args_info.y_arg) );
135 if( args_info.z_given ) head_out->
z( static_cast<size_t>(args_info.z_arg) );
136 if( args_info.t_given ) head_out->
t( static_cast<size_t>(args_info.t_arg) );
137 if( args_info.data_type_given ) head_out->
type( args_info.data_type_arg );
138 if( args_info.system_given ) head_out->
systeme( args_info.system_arg==system_arg_big ?
"big_endian" :
"little_endian" );
139 if( args_info.dim_x_given ) head_out->
dim_x( args_info.dim_x_arg );
140 if( args_info.dim_y_given ) head_out->
dim_y( args_info.dim_y_arg );
141 if( args_info.dim_z_given ) head_out->
dim_z( args_info.dim_z_arg );
142 if( args_info.dim_t_given ) head_out->
dim_t( args_info.dim_t_arg );
143 if( args_info.org_x_given ) head_out->
org_x( args_info.org_x_arg );
144 if( args_info.org_y_given ) head_out->
org_y( args_info.org_y_arg );
145 if( args_info.org_z_given ) head_out->
org_z( args_info.org_z_arg );
146 if( args_info.org_t_given ) head_out->
org_t( args_info.org_t_arg );
147 if( args_info.inc_x_given ) head_out->
inc_x( args_info.inc_x_arg );
148 if( args_info.inc_y_given ) head_out->
inc_y( args_info.inc_y_arg );
149 if( args_info.inc_z_given ) head_out->
inc_z( args_info.inc_z_arg );
150 if( args_info.inc_t_given ) head_out->
inc_t( args_info.inc_t_arg );
151 if( args_info.x_units_given ) head_out->
unites_x( args_info.x_units_arg );
152 if( args_info.y_units_given ) head_out->
unites_y( args_info.y_units_arg );
153 if( args_info.z_units_given ) head_out->
unites_z( args_info.z_units_arg );
154 if( args_info.t_units_given ) head_out->
unites_t( args_info.t_units_arg );
155 if( args_info.clear_comment_given ) head_out->
comment(NULL);
156 if( args_info.comment_given ) head_out->
comment( args_info.comment_arg );
157 if( args_info.data_factor_given ) head_out->
facteur(args_info.data_factor_arg);
158 if( args_info.data_zero_given ) head_out->
zero( args_info.data_zero_arg );
159 if( args_info.author_given ) head_out->
aut_name( args_info.author_arg );
160 if( args_info.transparent_given ){
161 if( strlen(args_info.transparent_arg)!=2*
Data_Size[head_out->
type()] ){
162 cerr <<
"Incorrect tranparent value specified\n";
169 for(
int i=0; i<Data_Size[head_out->
type()]; i++ ){
170 s[0] = args_info.transparent_arg[i*2];
171 s[1] = args_info.transparent_arg[i*2+1];
172 v[i] = strtol( s, &pp, 16 );
176 if( args_info.no_transparent_given ) head_out->
transparent( NULL );
179 if( args_info.jive_time_given )
184 tmpfn += basename(args_info.inputs[0]);
189 if( args_info.frankenstein_given ){
190 ofn = args_info.frankenstein_arg;
193 if( h->
read() != 0 ) gzrewind( in );
197 ofn = args_info.inputs[0];
199 if(args_info.output_file_given)
200 ofn = args_info.output_file_arg;
205 head_out->
fileptr(gzout = gzopen( tmpfn.c_str(),
"w" ) );
209 head_out->
fileptr(fout= fopen( tmpfn.c_str(),
"w" ) );
213 if( !args_info.decapitate_given )
216 if( args_info.create_given )
218 else if( args_info.convert_data_flag ) {
219 double *slice_data =
new double[head_in->
slice_sz()];
220 for(
int t=0; t<head_in->
t(); t++ ) {
224 delete [] slice_data;
225 }
else if( args_info.transpose_flag ) {
227 long offset = head_out->
t()*ds;
228 long datStart = gztell( in );
229 char *buf = (
char *)malloc( head_out->
slice_sz()*ds );
230 for(
int i=0; i<head_out->
t(); i++ ) {
231 for(
int j=0; j<head_out->
slice_sz(); j++ ) {
232 gzseek( in,datStart+offset*j+i*ds, SEEK_SET );
233 gzread( in, buf+j*ds, ds*1 );
239 const int bufsize=1000000;
240 char* buf =
new char[bufsize];
242 while( (nb=gzread( in, buf, bufsize )) > 0 ) out_fp->
write( buf, nb );
248 rename( tmpfn.c_str(), ofn.c_str() );
256 printf(
"x dimension:\t%zu\n", header->
x() );
257 printf(
"y dimension:\t%zu\n", header->
y() );
258 printf(
"z dimension:\t%zu\n", header->
z() );
259 printf(
"t dimension:\t%zu\n", header->
t() );
263 printf(
"Pixel units:\t%s\n", header->
unites() );
270 printf(
"Pixel zero:\t%g\n", header->
zero() );
274 printf(
"Pixel scaling:\t%g\n", header->
facteur() );
278 printf(
"X size:\t\t%g\n", header->
dim_x() );
282 printf(
"X units:\t%s\n", header->
unites_x() );
286 printf(
"Increment in x:\t%g\n", header->
inc_x() );
290 printf(
"X origin:\t%g\n", header->
org_x() );
294 printf(
"Y size:\t\t%g\n", header->
dim_y() );
298 printf(
"Y units:\t%s\n", header->
unites_y() );
302 printf(
"Increment in y:\t%g\n", header->
inc_y() );
306 printf(
"Y origin:\t%g\n", header->
org_y() );
310 printf(
"Z size:\t\t%g\n", header->
dim_z() );
314 printf(
"Z units:\t%s\n", header->
unites_z() );
318 printf(
"Increment in z:\t%g\n", header->
inc_z() );
322 printf(
"Z origin:\t%g\n", header->
org_z() );
326 printf(
"T size:\t\t%g\n", header->
dim_t() );
330 printf(
"T units:\t%s\n", header->
unites_t() );
334 printf(
"Increment in t:\t%g\n", header->
inc_t() );
338 printf(
"T origin:\t%g\n", header->
org_t() );
340 printf(
"Created on:\t%s\n", header->
systemestr());
343 printf(
"Author:\t\t%s\n", header->
aut_name() );
345 if( header->
comment() != NULL ){
348 while( cm[i] != NULL )
349 printf(
"#%s\n", cm[i++] );
356 z_off_t zo = gztell( in );
357 const int bufsize=8196;
360 while( (nr=gzread( in, buff, bufsize )) == bufsize )
363 int slicesize = header->
x()*header->
y()*header->
z()*header->
data_size();
364 header->
t( nb/slicesize );
365 gzseek( in, zo, SEEK_SET );
366 if( header->
dim_t() )
378 if( ofn.rfind(
".gz")==ofn.length()-3 ) ofn.resize(ofn.length()-3);
379 if( ofn.rfind(
".igb")==ofn.length()-4 ) ofn.resize(ofn.length()-3);
384 snprintf( fnm,
sizeof fnm,
"%s%d.%s", ofn.c_str(), slnum,
"igb" );
388 hout->
fileptr(gzout = gzopen( strcat(fnm,
".gz"),
"w" ) );
391 hout->
fileptr(fout= fopen( fnm,
"w" ) );
398 fprintf(stderr,
"Not enough slices in file\n" );
405 return fn.rfind(
".gz") == fn.length()-3;
void write(void *buf, int n)
void output_header(IGBheader *)
int jive(IGBheader *header, gzFile in)
void write_slice(IGBheader *header, IGBheader *in, string ofnb, double *buf, int)
int main(int argc, char *argv[])
void write_to_binary(IGBheader *h, gzFile in, FILE_PTR *out_fp, int skip)
const char * Header_Type[]
bool iscompressed(string fn)
unsigned short Data_Size[]