35 #include <type_traits> 39 typename std::enable_if<!std::numeric_limits<T>::is_integer,
bool>::type
44 return std::abs(x-y) <= std::numeric_limits<T>::epsilon() * std::abs(x+y) * ulp
54 #define IGB_BIG_ENDIAN 666666666 55 #define IGB_LITTLE_ENDIAN 777777777 67 #define IGB_D_COMPLEX 8 69 #define IGB_STRUCTURE 10 70 #define IGB_POINTER 11 82 #define IGB_MIN_TYPE 1 83 #define IGB_MAX_TYPE 22 101 #define IGB_ENDIAN_VAL -1.24e5 102 #define IGB_LITTLE_END_REP 0,48,242,199 105 #define ERR_EOF_IN_HEADER 1 106 #define ERR_LINE_TOO_LONG 2 107 #define ERR_UNPRINTABLE_CHAR 3 108 #define ERR_IGB_SYNTAX 4 109 #define ERR_UNDEFINED_X_Y_TYPE 5 110 #define ERR_SIZE_REDEFINED 6 111 #define ERR_SIZE_NOT_DEFINED 7 112 #define WARN_DIM_INCONSISTENT 256 170 #define HFLT_MIN -65504 171 #define HFLT_MAX 65504 175 #ifndef HEADER_GLOBALS 198 size_t v_x=0, v_y=0, v_z=1, v_t=1;
201 unsigned long v_systeme=endian() ;
205 unsigned int v_lut=0 ;
206 unsigned int v_comp=0 ;
208 float v_org_x=1., v_org_y=1., v_org_z=1., v_org_t=0.;
209 float v_inc_x=1., v_inc_y=1., v_inc_z=1., v_inc_t=1.;
210 float v_dim_x, v_dim_y, v_dim_z, v_dim_t ;
211 float *v_vect_z=NULL;
212 char v_unites_x[41]={}, v_unites_y[41]={}, v_unites_z[41]={}, v_unites_t[41]={};
214 char v_unites[41]={};
215 float v_facteur=1., v_zero=0.;
216 char v_struct_desc[41]={};
217 char v_aut_name[41]={};
218 char** v_comment=(
char**)calloc(
NALLOC,
sizeof(
char*));
219 void* v_transparent=NULL;
220 int puts_fcn(
char *);
221 int seek(
size_t,
int );
223 int read_vz(
float *vz,
int sz );
227 bool bool_x=
false, bool_y=
false, bool_z=
false, bool_t=
false;
228 bool bool_type=
false;
229 bool bool_taille=
false;
232 bool bool_trame=
false;
234 bool bool_comp=
false;
235 bool bool_epais=
false;
236 bool bool_org_x=
false, bool_org_y=
false, bool_org_z=
false, bool_org_t=
false;
237 bool bool_inc_x=
false, bool_inc_y=
false, bool_inc_z=
false, bool_inc_t=
false;
238 bool bool_dim_x, bool_dim_y=
false, bool_dim_z=
false, bool_dim_t=
false;
239 bool bool_vect_z=
false;
240 bool bool_unites_x=
false, bool_unites_y=
false, bool_unites_z=
false, bool_unites_t=
false;
241 bool bool_unites=
false;
242 bool bool_facteur=
false, bool_zero=
false;
243 bool bool_struct_desc=
false;
244 bool bool_aut_name=
false;
245 bool bool_comment=
false;
246 bool bool_transparent=
false;
250 IGBheader( gzFile a = NULL,
bool read=
false,
bool quiet=
false );
251 IGBheader( FILE *f,
bool read=
false,
bool quiet=
false );
255 int read(
bool quiet=
false );
256 void fileptr( gzFile f );
257 void fileptr( FILE* f );
259 void close(
void){
if(gzipping)gzclose((gzFile)file);
else fclose((FILE*)file);}
260 void swab(
void *,
int nd=-1 );
261 double from_raw(
double a ){
return a*v_facteur+v_zero; }
262 double to_raw(
double a ){
return (a-v_zero)/v_facteur; }
264 int go2slice(
size_t s );
265 void comment(
const char* );
266 inline char **
comment(
void){
return v_comment;}
268 inline size_t x(
void){
return v_x; }
269 inline size_t x(
bool &
set ){
set=bool_x;
return v_x; }
270 inline void x(
size_t a ){ v_x = a; bool_x =
true;}
271 inline size_t y(
void){
return v_y; }
272 inline size_t y(
bool &
set ){
set=bool_y;
return v_y; }
273 inline void y(
size_t a ){ v_y = a; bool_y =
true;}
274 inline size_t z(
void){
return v_z; }
275 inline size_t z(
bool &
set ){
set=bool_z;
return v_z; }
276 inline void z(
size_t a ){ v_z = a; bool_z =
true;}
277 inline size_t t(
void){
return v_t; }
278 inline size_t t(
bool &
set ){
set=bool_t;
return v_t; }
279 inline void t(
size_t a ){ v_t = a; bool_t =
true;}
280 inline int type(
void){
return v_type; }
281 inline int type(
bool &
set ){
set=bool_type;
return v_type; }
282 inline void type(
int a ){ v_type = a; bool_type =
true; }
284 inline int taille(
void){
return v_taille; }
285 inline int taille(
bool &
set ){
set=bool_taille;
return v_taille; }
286 inline void taille(
int a ){ v_taille = a; bool_taille =
true;}
287 inline int num(
void){
return v_num; }
288 inline int num(
bool &
set ){
set=bool_num;
return v_num; }
289 inline void num(
int a ){ v_num = a; bool_num =
true;}
290 inline int bin(
void){
return v_bin; }
291 inline int bin(
bool &
set ){
set=bool_bin;
return v_bin; }
292 inline void bin(
int a ){ v_bin = a; bool_bin =
true;}
293 inline int trame(
void){
return v_trame; }
294 inline int trame(
bool &
set ){
set=bool_trame;
return v_trame; }
295 inline void trame(
int a ){ v_trame = a; bool_trame =
true;}
296 const char* systemestr(
void);
297 inline int systeme(
void ){
return v_systeme; }
298 void systeme(
const char* s );
299 inline unsigned int lut(
void){
return v_lut; }
300 inline unsigned int lut(
bool &
set ){
set=bool_lut;
return v_lut; }
301 inline void lut(
unsigned int a ){ v_lut = a; bool_lut =
true; }
302 inline unsigned int comp(
void){
return v_comp; }
303 inline unsigned int comp(
bool &
set ){
set=bool_lut;
return v_lut; }
304 inline void comp(
unsigned int a ){ v_comp = a; bool_comp =
true;}
305 inline float epais(
void){
return v_epais; }
306 inline float epais(
bool &
set ){
set=bool_epais;
return v_epais; }
307 inline void epais(
float a ){ v_epais = a; bool_epais =
true;}
308 inline float org_x(
void){
return v_org_x; }
309 inline float org_x(
bool &
set ){
set=bool_org_x;
return v_org_x; }
310 inline void org_x(
float a ){ v_org_x = a; bool_org_x =
true; }
311 inline float org_y(
void){
return v_org_y; }
312 inline float org_y(
bool &
set ){
set=bool_org_y;
return v_org_y; }
313 inline void org_y(
float a ){ v_org_y = a; bool_org_y =
true; }
314 inline float org_z(
void){
return v_org_z; }
315 inline float org_z(
bool &
set ){
set=bool_org_z;
return v_org_z; }
316 inline void org_z(
float a ){ v_org_z = a; bool_org_z =
true;}
317 inline float org_t(
void){
return v_org_t; }
318 inline float org_t(
bool &
set ){
set=bool_org_t;
return v_org_t; }
319 inline void org_t(
float a ){ v_org_t = a; bool_org_t =
true;}
320 inline void inc_x(
float a ){ v_inc_x = a; bool_inc_x =
true;}
321 inline float inc_x(
bool &
set ){
set=bool_inc_x;
return v_inc_x; }
322 inline float inc_x(
void){
return v_inc_x; }
323 inline void inc_y(
float a ){ v_inc_y = a; bool_inc_y =
true;}
324 inline float inc_y(
bool &
set ){
set=bool_inc_y;
return v_inc_y; }
325 inline float inc_y(
void){
return v_inc_y; }
326 inline void inc_z(
float a ){ v_inc_z = a; bool_inc_z =
true;}
327 inline float inc_z(
bool &
set ){
set=bool_inc_z;
return v_inc_z; }
328 inline float inc_z(
void){
return v_inc_z; }
329 inline void inc_t(
float a ){ v_inc_t = a; bool_inc_t =
true;}
330 inline float inc_t(
bool &
set ){
set=bool_inc_t;
return v_inc_t; }
331 inline float inc_t(
void){
return v_inc_t; }
332 inline void dim_x(
float a ){ v_dim_x = a; bool_dim_x =
true;}
333 inline float dim_x(
bool &
set ){
set=bool_dim_x;
return v_dim_x; }
334 inline float dim_x(
void){
return v_dim_x; }
335 inline void dim_y(
float a ){ v_dim_y = a; bool_dim_y =
true;}
336 inline float dim_y(
bool &
set ){
set=bool_dim_y;
return v_dim_y; }
337 inline float dim_y(
void){
return v_dim_y; }
338 inline void dim_z(
float a ){ v_dim_z = a; bool_dim_y =
true;}
339 inline float dim_z(
bool &
set ){
set=bool_dim_z;
return v_dim_z; }
340 inline float dim_z(
void){
return v_dim_z; }
341 inline void dim_t(
float a ){ v_dim_t = a; bool_dim_t =
true;}
342 inline float dim_t(
bool &
set ){
set=bool_dim_t;
return v_dim_t; }
343 inline float dim_t(
void){
return v_dim_t; }
344 inline void facteur(
float a ){ v_facteur = a; bool_facteur =
true; }
345 inline float facteur(
bool &
set ){
set=bool_facteur;
return v_facteur; }
346 inline float facteur(
void){
return v_facteur; }
347 inline void zero(
float a ){ v_zero = a; bool_zero =
true; }
348 inline float zero(
bool &
set ){
set=bool_zero;
return v_zero; }
349 inline float zero(
void){
return v_zero; }
350 inline void vect_z(
float* a ){ v_vect_z = a; bool_vect_z =
true; }
351 inline float*
vect_z(
bool &
set ){
set=bool_vect_z;
return v_vect_z; }
352 inline float*
vect_z(
void){
return v_vect_z; }
353 inline void unites_x(
const char* a ){ strcpy(v_unites_x, a); bool_unites_x =
true; }
354 inline char*
unites_x(
bool &
set ){
set=bool_unites_x;
return v_unites_x; }
356 inline void unites_y(
const char* a ){ strcpy(v_unites_y, a); bool_unites_y =
true;}
357 inline char*
unites_y(
bool &
set ){
set=bool_unites_y;
return v_unites_y; }
359 inline void unites_z(
const char* a ){ strcpy(v_unites_z,a); bool_unites_z =
true; }
360 inline char*
unites_z(
bool &
set ){
set=bool_unites_z;
return v_unites_z; }
362 inline void unites_t(
const char* a ){ strcpy(v_unites_t, a); bool_unites_t =
true; }
363 inline char*
unites_t(
bool &
set ){
set=bool_unites_t;
return v_unites_t; }
365 inline void unites(
const char* a ){ strcpy(v_unites, a); bool_unites =
true; }
366 inline char*
unites(
bool &
set ){
set=bool_unites;
return v_unites; }
367 inline char*
unites(
void){
return v_unites; }
368 inline void struct_desc(
const char* a ){ strcpy(v_struct_desc, a); bool_struct_desc =
true; }
369 inline char*
struct_desc(
bool &
set ){
set=bool_struct_desc;
return v_struct_desc; }
371 inline void aut_name(
const char* a ){ strcpy(v_aut_name, a); bool_aut_name =
true; }
372 inline char*
aut_name(
bool &
set ){
set=bool_aut_name;
return v_aut_name; }
374 inline void transparent(
void* a ){ v_transparent=a; bool_transparent =
true; }
375 inline void*
transparent(
bool &
set ){
set=bool_transparent;
return v_transparent; }
381 template<
class T>
int read_data( T* dp,
size_t numt=1,
char *buf=NULL );
382 template<
class T>
void write_data( T* dp,
size_t numt=1,
char *buf=NULL );
383 template<
class T>
void to_bin(
void *buf, T d );
384 template<
class T>
void to_bin(
void *buf, T *d );
385 template<
class T> T convert_buffer_datum(
void *buf,
int a );
399 const size_t slicesize = data_size()*slice_sz()*numt;
400 bool alloc_buf =
false;
402 buf =
new char[slicesize]();
406 const size_t numprimitive = slice_sz()*num_components();
407 for (
size_t a=0; a<numprimitive; a++ )
408 to_bin<T>( buf+a*data_size(), dp[a] );
411 gzwrite( (gzFile)file, buf, slicesize );
413 fwrite( buf, 1, slicesize, (FILE*)file );
415 if ( alloc_buf )
delete[] buf;
433 const size_t slicesize = data_size()*slice_sz()*numt;
434 bool alloc_buf =
false;
436 buf =
new char[slicesize]();
442 numread = gzread( (gzFile)(file), buf, slicesize )/data_size();
444 numread = fread( buf, 1, slicesize, (FILE *)(file) )/data_size();
446 if ( systeme() != endian() ) swab(buf, numread);
448 size_t numprimitive = numread*num_components();
450 #pragma omp parallel for schedule(guided) 451 for (
size_t a=0; a<numprimitive; a++ )
452 dp[a] = convert_buffer_datum<T>( buf, a );
454 if ( alloc_buf )
delete[] buf;
472 datum = ((
unsigned char *)buf)[a];
475 datum = ((
signed char *)buf)[a];
478 datum = ((
short *)buf)[a];
481 datum = ((
long *)buf)[a];
487 datum = ((
float *)buf)[a];
493 datum = ((
double *)buf)[a];
496 datum = ((
int *)buf)[a];
499 datum = ((
unsigned int *)buf)[a];
502 datum = ((
unsigned short *)buf)[a];
508 memset(&datum,0,
sizeof(datum));
510 return datum=from_raw(datum);
519 #define CONVERT_TYPE(D,m,M,B) { if(datum > M) datum = M; else if(datum < m) datum = m; \ 520 const D a0 = static_cast<D>(datum); (*reinterpret_cast<D*>(B))=a0;} 531 double datum=to_raw(d);
573 (*
reinterpret_cast<short_float*
>(buf)) = shortFromFloat(datum);
593 for(
size_t i=0; i<num_components(); i++ ){
594 double datum=to_raw(d[i]);
595 char *dp = (
char *)buf + i*
sizeof(
double);
602 for(
size_t i=0; i<num_components(); i++ ){
603 double datum=to_raw(d[i]);
604 char *dp = (
char *)buf + i*
sizeof(
float);
609 to_bin<T>( buf, *d );
constexpr T min(T a, T b)
constexpr T max(T a, T b)