This file is indexed.

/usr/include/CGAL/ImageIO/gis_impl.h is in libcgal-dev 4.11-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
// Copyright (c) 2005-2008 ASCLEPIOS Project, INRIA Sophia-Antipolis (France)
// All rights reserved.
//
// This file is part of the ImageIO Library, and as been adapted for
// CGAL (www.cgal.org).
// You can redistribute it and/or  modify it under the terms of the
// GNU Lesser General Public License as published by the Free Software Foundation;
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// These files are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s)     :  ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau

#ifdef CGAL_HEADER_ONLY
#define CGAL_INLINE_FUNCTION inline
#else
#define CGAL_INLINE_FUNCTION
#endif

#include <string>
#include <sstream>
#include <cstring>

#include <CGAL/ImageIO/inr.h>
#include <CGAL/ImageIO/fgetns.h>

#define _LGTH_STRING_ 1024

CGAL_INLINE_FUNCTION
PTRIMAGE_FORMAT createGisFormat() {
  PTRIMAGE_FORMAT f=(PTRIMAGE_FORMAT) ImageIO_alloc(sizeof(IMAGE_FORMAT));

  f->testImageFormat=&testGisHeader;
  f->readImageHeader=&readGisHeader;
  f->writeImage=&writeGis;
  strcpy(f->fileExtension,".dim,.dim.gz,.ima,.ima.gz");
  strcpy(f->realName,"Gis");
  return f;
}
CGAL_INLINE_FUNCTION
int writeGis( char *name, _image* im) {
  char *outputName;
  std::size_t length, extLength=0;
  int res;
  std::size_t done;

  length=strlen(name);
  outputName= (char *)ImageIO_alloc(length+8);
  
  if ( strncmp( name+length-4, ".dim", 4 ) == 0 ) {
    extLength = 4;
  }
  else if ( strncmp( name+length-4, ".ima", 4 ) == 0 ) {
    extLength = 4;
  }
  else if ( strncmp( name+length-7, ".ima.gz", 7 ) == 0 ) {
    extLength = 7;
  }
  else if ( strncmp( name+length-7, ".dim.gz", 7 ) == 0 ) {
    extLength = 7;
  }

  strncpy( outputName, name, length-extLength );
  if ( strncmp( name+length-7, ".dim.gz", 7 ) == 0 )
    strcpy( outputName+length-extLength, ".dim.gz" );
  else
    strcpy( outputName+length-extLength, ".dim" );

  _openWriteImage(im, outputName);
  if( !im->fd ) {
    fprintf(stderr, "writeGis: error: unable to open file \'%s\'\n", outputName);
    if ( outputName != NULL ) ImageIO_free( outputName );
    return ImageIO_OPENING;
  }

  if ( !writeGisHeader(im) ) {
    fprintf(stderr, "writeGis: error: unable to write header of \'%s\'\n",
	    outputName);
    if ( outputName != NULL ) ImageIO_free( outputName );
    ImageIO_close( im );
    im->fd = NULL;
    im->openMode = OM_CLOSE;
    return -1;
  }

  ImageIO_close(im);
  
  strncpy( outputName, name, length-extLength );
  if ( strncmp( name+length-3, ".gz", 3 ) == 0 ) {
    strcpy( outputName+length-extLength, ".ima.gz" );
  }
  else {
    strcpy( outputName+length-extLength, ".ima" );
  }

  _openWriteImage(im, outputName);

  if( !im->fd ) {
    fprintf(stderr, "writeGis: error: unable to open file \'%s\'\n", outputName);
    if ( outputName != NULL ) ImageIO_free( outputName );
    return ImageIO_OPENING;
  }

  if ( im->dataMode == DM_ASCII ) {
    std::size_t i, j, n, size;
    char *str = (char*)ImageIO_alloc( _LGTH_STRING_+1 );
    size = im->xdim * im->ydim * im->zdim * im->vdim;
    n = ( im->xdim < 16 ) ? im->xdim : 16;
    i = 0;

    switch( im->wordKind ) {
    default :
      fprintf(stderr, "writeGis: such word kind not handled in ascii mode for file \'%s\'\n", outputName);
      if ( outputName != NULL ) ImageIO_free( outputName );
      return( -3 );
    case WK_FIXED :
      switch ( im->wdim ) {
      default :
	fprintf(stderr, "writeGis: such word dim not handled in ascii mode for file \'%s\'\n", outputName);
	if ( outputName != NULL ) ImageIO_free( outputName );
	return( -3 );
      case 1 :
	switch ( im->sign ) {
	default :
	  fprintf(stderr, "writeGis: such sign not handled in ascii mode for file \'%s\'\n", outputName);
	  if ( outputName != NULL ) ImageIO_free( outputName );
	  return( -3 );
	case SGN_UNSIGNED :
	  {
	    unsigned char *theBuf = ( unsigned char * )im->data;
	    do {
	      memset( str, 0, _LGTH_STRING_ );
	      for ( j=0; j<n && i<size; j++, i++ ) {
		sprintf( str+strlen(str), "%d", theBuf[i] );
		if ( j<n && i<size ) sprintf( str+strlen(str), " " );
	      }
	      sprintf( str+strlen(str), "\n" );
              done = ImageIO_write( im, str, strlen( str )  );
              res = (done == strlen( str )) ? int(done) : -1;
	      if ( res  <= 0 ) {
		fprintf(stderr, "writeGis: error when writing data in \'%s\'\n", outputName);
		if ( outputName != NULL ) ImageIO_free( outputName );
		return( -3 );
	      }
	    } while ( i < size );
	  }
	  break;
	case SGN_SIGNED :
	  {
	    char *theBuf = ( char * )im->data;
	    do {
	      memset( str, 0, _LGTH_STRING_ );
	      for ( j=0; j<n && i<size; j++, i++ ) {
		sprintf( str+strlen(str), "%d", theBuf[i] );
		if ( j<n && i<size ) sprintf( str+strlen(str), " " );
	      }
	      sprintf( str+strlen(str), "\n" );
              done = ImageIO_write( im, str, strlen( str )  );
              res = (done == strlen( str )) ? int(done) : -1;
	      if ( res  <= 0 ) {
		fprintf(stderr, "writeGis: error when writing data in \'%s\'\n", outputName);
		if ( outputName != NULL ) ImageIO_free( outputName );
		return( -3 );
	      }
	    } while ( i < size );
	  }
	  break;
	} /* end of switch ( im->sign ) */
	break;
      case 2 :
	switch ( im->sign ) {
	default :
	  fprintf(stderr, "writeGis: such sign not handled in ascii mode for file \'%s\'\n", outputName);
	  if ( outputName != NULL ) ImageIO_free( outputName );
	  return( -3 );
	case SGN_UNSIGNED :
	  {
	    unsigned short int *theBuf = ( unsigned short int * )im->data;
	    do {
	      memset( str, 0, _LGTH_STRING_ );
	      for ( j=0; j<n && i<size; j++, i++ ) {
		sprintf( str+strlen(str), "%d", theBuf[i] );
		if ( j<n && i<size ) sprintf( str+strlen(str), " " );
	      }
	      sprintf( str+strlen(str), "\n" );
	      done = ImageIO_write( im, str, strlen( str )  );
              res = (done == strlen( str )) ? int(done) : -1;
	      if ( res  <= 0 ) {
		fprintf(stderr, "writeGis: error when writing data in \'%s\'\n", outputName);
		if ( outputName != NULL ) ImageIO_free( outputName );
		return( -3 );
	      }
	    } while ( i < size );
	  }
	  break;
	case SGN_SIGNED :
	  {
	    short int *theBuf = ( short int * )im->data;
	    do {
	      memset( str, 0, _LGTH_STRING_ );
	      for ( j=0; j<n && i<size; j++, i++ ) {
		sprintf( str+strlen(str), "%d", theBuf[i] );
		if ( j<n && i<size ) sprintf( str+strlen(str), " " );
	      }
	      sprintf( str+strlen(str), "\n" );
	      done = ImageIO_write( im, str, strlen( str )  );
              res = (done == strlen( str )) ? int(done) : -1;
	      if ( res  <= 0 ) {
		fprintf(stderr, "writeGis: error when writing data in \'%s\'\n", outputName);
		if ( outputName != NULL ) ImageIO_free( outputName );
		return( -3 );
	      }
	    } while ( i < size );
	  }
	  break;
	} /* end of switch ( im->sign ) */
	break;	
      } /* end of switch ( im->wdim ) */
    } /* end of switch( im->wordKind ) */

    ImageIO_free( str ); 
    if (outputName != NULL) ImageIO_free(outputName);
    return static_cast<int>(res);
  }
  else {
    bool ret = _writeInrimageData(im);
    if (outputName != NULL) ImageIO_free(outputName);
    return (ret ? 1 : -1);
  }
}

CGAL_INLINE_FUNCTION
int testGisHeader(char *,const char *name) {
   if (( !strncmp(name+strlen(name)-4, ".dim", 4)) || 
       ( !strncmp(name+strlen(name)-4, ".ima", 4)) || 
       ( !strncmp(name+strlen(name)-7, ".ima.gz", 7)) || 
       ( !strncmp(name+strlen(name)-7, ".dim.gz", 7)) )
     return 0;
  else 
    return -1;
}



CGAL_INLINE_FUNCTION
int readGisHeader( const char* name,_image* im)
{
  char *s, *str = NULL;
  int status;
  int n=0, nusermax = 20;

  str = (char*)ImageIO_alloc( _LGTH_STRING_+1 );
  
  if ( !fgetns(str, _LGTH_STRING_, im) ) 
    { ImageIO_free( str ); return -1; }

  std::istringstream iss;
  iss.str(str);
  iss >> im->xdim >> im->ydim >> im->zdim >> im->vdim;

  status = (int)iss.str().length();
  switch ( status ) {
  case 2 :    im->zdim = 1; CGAL_FALLTHROUGH;
  case 3 :    im->vdim = 1; CGAL_FALLTHROUGH;
  case 4 :    break;
  default :
    fprintf( stderr, "readGisHeader: unable to read dimensions in '%s'\n", name );
    ImageIO_free( str ); 
    return -1;
  }
  if ( im->vdim > 1 ) {
    im->vectMode = VM_INTERLACED;
  } 
  else {
    im->vectMode = VM_SCALAR;
  }
#define ADD_USER_STRING { \
    if ( n == 0 ) { \
      im->user = (char**)ImageIO_alloc( nusermax * sizeof( char*) ); \
      for ( n=0; n<nusermax; n++ ) im->user[n] = NULL; \
      n = 0; \
    } \
    im->user[n] = (char*)ImageIO_alloc( 1+strlen( s ) ); \
    strcpy( im->user[n++], s ); \
  }



  while( fgetns( str, _LGTH_STRING_, im ) != 0 ) {
    s = str;
    do {

      while ( *s == ' ' || *s == '\t' ) s++;

      if ( !strncmp( s, "-dx ", 4 ) ) {
	s += 4;
	status = sscanf( s, "%lf", &(im->vx) );
	if ( status != 1 ) {
	  fprintf( stderr, "readGisHeader: error while reading -dx in '%s'\n", s-4 );
	  *s = '\0';
	} 
	else {
	  while ( *s == '.' || (*s >= '0' && *s <= '9') ) s++;
	}
      }
      else if ( !strncmp( s, "-dy ", 4 ) ) {
	s += 4;
	status = sscanf( s, "%lf", &(im->vy) );
	if ( status != 1 ) {
	  fprintf( stderr, "readGisHeader: error while reading -dy in '%s'\n", s-4 );
	  *s = '\0';
	} 
	else {
	  while ( *s == '.' || (*s >= '0' && *s <= '9') ) s++;
	}
      }
      else if ( !strncmp( s, "-dz ", 4 ) ) {
	s += 4;
	status = sscanf( s, "%lf", &(im->vz) );
	if ( status != 1 ) {
	  fprintf( stderr, "readGisHeader: error while reading -dz in '%s'\n", s-4 );
	  *s = '\0';
	} 
	else {
	  while ( *s == '.' || (*s >= '0' && *s <= '9') ) s++;
	}
      }
      else if ( !strncmp( s, "-dt ", 4 ) ) {
	ADD_USER_STRING
	s += 4; 
	while ( *s == '.' || (*s >= '0' && *s <= '9') ) s++; 
      }

      else if ( !strncmp( s, "-type ", 6 ) ) {
	s += 6; 
	if ( !strncmp( s, "U8", 2 ) ) {
	  im->wdim     = 1;
	  im->wordKind = WK_FIXED;
	  im->sign     = SGN_UNSIGNED;
	  s += 2;
	}
	else if ( !strncmp( s, "S8", 2 ) ) {
	  im->wdim     = 1;
	  im->wordKind = WK_FIXED;
	  im->sign     = SGN_SIGNED;
	  s += 2;
	} 
	else if ( !strncmp( s, "U16", 3 ) ) {
	  im->wdim     = 2;
	  im->wordKind = WK_FIXED;
	  im->sign     = SGN_UNSIGNED;
	  s += 3;
	}
	else if ( !strncmp( s, "S16", 3 ) ) {
	  im->wdim     = 2;
	  im->wordKind = WK_FIXED;
	  im->sign     = SGN_SIGNED;
	  s += 3;
	}
	else if ( !strncmp( s, "U32", 3 ) ) {
	  im->wdim     = 4;
	  im->wordKind = WK_FIXED;
	  im->sign     = SGN_UNSIGNED;
	  s += 3;
	}
	else if ( !strncmp( s, "S32", 3 ) ) {
	  im->wdim     = 4;
	  im->wordKind = WK_FIXED;
	  im->sign     = SGN_SIGNED;
	  s += 3;
	}
	else if ( !strncmp( s, "FLOAT", 5 ) ) {
	  im->wdim     = sizeof( float );
	  im->wordKind = WK_FLOAT;
	  im->sign     = SGN_UNKNOWN;
	  s += 5;
	}
	else if ( !strncmp( s, "DOUBLE", 6 ) ) {
	  im->wdim     = sizeof( double );
	  im->wordKind = WK_FLOAT;
	  im->sign     = SGN_UNKNOWN;
	  s += 6;
	}
	else {
	  fprintf( stderr, "readGisHeader: unknown type '%s'\n", s-6 );
	  *s = '\0'; 
	}
      }

      else if ( !strncmp( s, "-bo ", 4 ) ) {
	s += 4;
	if ( !strncmp( s, "ABCD", 4 ) ) {
	  im->endianness = END_BIG;
	  s += 4;
	}
	else if ( !strncmp( s, "SUN", 3 ) ) {
	  im->endianness = END_BIG;
	  s += 3;
	}
	else if ( !strncmp( s, "DCBA", 4 ) ) {
	  im->endianness = END_LITTLE;
	  s += 4;
	}
	else if ( !strncmp( s, "ALPHA", 5 ) ) {
	  im->endianness = END_LITTLE;
	  s += 5;
	}
	else {
	  fprintf( stderr, "readGisHeader: unknown byte order '%s'\n", s-4 );
	  *s = '\0'; 
	}
      }

      else if ( !strncmp( s, "-ar ", 4 ) ) {
	s += 4;
	if ( !strncmp( s, "SUN", 3 ) ) {
	  im->endianness = END_BIG;
	  s += 3;
	}
	else if ( !strncmp( s, "ALPHA", 5 ) ) {
	  im->endianness = END_LITTLE;
	  s += 5;
	}
	else {
	  fprintf( stderr, "readGisHeader: unknown architecture '%s'\n", s-4 );
	  *s = '\0'; 
	}
      }

      else if ( !strncmp( s, "-om ", 4 ) ) {
	s += 4;
	if ( !strncmp( s, "binar", 5 ) ) {
	  im->dataMode = DM_BINARY;
	  s += 5;
	} 
	else if ( !strncmp( s, "ascii", 5 ) ) {
	  im->dataMode = DM_ASCII;
	  s += 5;
	} 
	else {
	  fprintf( stderr, "readGisHeader: unknown data type '%s'\n", s-4 );
	  ImageIO_free( str );
	  return -1;
	}
      }
      
      
      else {
	fprintf( stderr, "readGisHeader: unknown indentifier '%s'\n", s );
	ADD_USER_STRING
	*s = '\0'; 
      }

    } while( *s != '\0' && *s != '\n' );

  }
  ImageIO_free( str );
  

  if ( im->endianness == END_UNKNOWN ) {
    im->endianness = _getEndianness();
  }


  /* header is read. close header file and open data file. */
  if( name != NULL ) {
    
    std::size_t length = strlen(name) ;
    char* data_filename = (char *) ImageIO_alloc(length+4) ;
    
    if( strcmp( name+length-4, ".dim" ) ) {
      fprintf (stderr,
	       "readGisHeader: error: file header extension must be .dim\n");
      ImageIO_free( data_filename );
      return -1;
    }
    
    ImageIO_close(im);


    /* open data file
     */
    
    strcpy(data_filename,name);
    strcpy(data_filename+length-3, "ima.gz");
    _openReadImage(im,data_filename);
    
    if(!im->fd) {
      
      strcpy(data_filename,name);
      strcpy(data_filename+length-3, "ima");
      _openReadImage(im,data_filename);
      if(!im->fd) {
	fprintf(stderr, "readGisHeader: error: unable to open data file \'%s\'\n", data_filename);
	ImageIO_free( data_filename );
	return -1;
	
      }
    }
    ImageIO_free( data_filename );





    /* read data if ascii
       only U8 and S8
     */
    if ( im->dataMode == DM_ASCII ) {
      std::size_t size = std::size_t(im->xdim) * im->ydim * im->zdim * im->vdim * im->wdim;
      unsigned int n;
      char *tmp;
      int ret, iv=0;
      
      if ( im->wdim != 1 || im->wordKind != WK_FIXED ) {
	fprintf(stderr, "readGisHeader: error: unable to read such ascii type\n" );
	return -1;
      }

      n = 0 ;
      if ( size <= 0 ) return -1;
      if(!im->data) {
	im->data = ( void*) ImageIO_alloc(size);
	if(!im->data) return -1;
      }
      
      n = 0;
      str = (char*)ImageIO_alloc( _LGTH_STRING_+1 );
      while( fgetns( str, _LGTH_STRING_, im ) != 0 &&
	     n < im->xdim * im->ydim * im->zdim * im->vdim ) {
	tmp = str;
	while ( *tmp != '\n' && *tmp != '\0' && *tmp != EOF &&
		n < im->xdim * im->ydim * im->zdim * im->vdim ) {
	  /* skip trailing whitespace
	   */
	  while ( *tmp == ' ' || *tmp == '\t' )
	    tmp++;
	  if ( *tmp == '\0' || *tmp == '\n' || *tmp == EOF )
	    continue;
	  
	  /* read a number
	   */
	  switch ( im->wordKind ) {
	  case WK_FIXED :
	    ret = sscanf( tmp, "%d", &iv );
	  break;
	  default :
	    ImageIO_free( im->data ); im->data = NULL;
	    ImageIO_free( str );
	    return -1;
	  }
	  
	  if ( ret != 1 ) {
	    fprintf( stderr, "readGisHeader: error in reading ascii data\n" );
	    ImageIO_free( im->data ); im->data = NULL;
	    ImageIO_free( str );
	    return -1;	
	  }
	  
	  if ( im->wordKind == WK_FIXED 
	       && im->sign == SGN_UNSIGNED 
	       && im->wdim == 1 ) {
	    unsigned char *buf = (unsigned char *)im->data;
	    buf += n;
	    if ( iv < 0 )        *buf = (unsigned char)0;
	    else if ( iv > 255 ) *buf = (unsigned char)255;
	    else                 *buf = (unsigned char)iv;
	    n ++;
	  }
	  else if ( im->wordKind == WK_FIXED 
		    && im->sign == SGN_SIGNED 
		    && im->wdim == 1 ) {
	    char *buf = (char *)im->data;
	    buf += n;
	    if ( iv < -128 )     *buf = (char)-128;
	    else if ( iv > 127 ) *buf = (char)127;
	    else                 *buf = (char)iv;
	    n ++;
	  }
	  else if ( im->wordKind == WK_FIXED 
		    && im->sign == SGN_UNSIGNED 
		    && im->wdim == 2 ) {
	    unsigned short int *buf = (unsigned short int *)im->data;
	    buf += n;
	    if ( iv < 0 )          *buf = (unsigned short int)0;
	    else if ( iv > 65535 ) *buf = (unsigned short int)65535;
	    else                   *buf = (unsigned short int)iv;
	    n ++;
	  }
	  else if ( im->wordKind == WK_FIXED 
		    && im->sign == SGN_SIGNED 
		    && im->wdim == 2 ) {
	    short int *buf = (short int *)im->data;
	    buf += n;
	    if ( iv < -32768 )     *buf = (short int)-32768;
	    else if ( iv > 32767 ) *buf = (short int)32767;
	    else                   *buf = (short int)iv;
	    n ++;
	  }
	  else {
	    ImageIO_free( im->data ); im->data = NULL;
	    ImageIO_free( str );
	    return -1;
	  }
	  


	  /* skip a number 
	   */
	  while ( (*tmp >= '0' && *tmp <= '9') || *tmp == '.' || *tmp == '-' )
	    tmp++;
	}
      }
      ImageIO_free( str );
      ImageIO_close(im);
    }

  }

  
  /* check header validity */
  if ( im->xdim > 0 && im->ydim > 0 && im->zdim > 0 && im->vdim > 0 &&
       im->vx > 0.0 && im->vy > 0.0 && im->vz > 0.0 &&
       ( im->wordKind == WK_FLOAT ||
	 (im->wordKind == WK_FIXED && im->sign != SGN_UNKNOWN) ) &&
       im->endianness != END_UNKNOWN ) {
    return 0;
  }

  return -1;
}



CGAL_INLINE_FUNCTION
bool writeGisHeader( const _image* inr )
{
  const char *proc = "writeGisHeader";
  std::ostringstream oss;

  if ( inr->vectMode == VM_NON_INTERLACED ) {
    fprintf( stderr, "%s: can not write non interlaced data\n", proc );
    return false;
  }

  /* dimensions
   */
  oss << " " << inr->xdim << " " << inr->ydim;
  if ( inr->vdim > 1 ) {
    oss << " " << inr->zdim << " " << inr->vdim;
  }
  else if ( inr->zdim > 1 ) {
    oss << " " << inr->zdim;
  }
  oss << "\n";

  /* type
   */
  oss << "-type ";
  switch ( inr->wordKind ) {
  case WK_FIXED :
    switch( inr->sign ) {
    case SGN_UNSIGNED :
      oss << "U" << 8*inr->wdim;
      break;
    case SGN_SIGNED :
      oss << "S" << 8*inr->wdim;
      break;
    default :
      fprintf( stderr, "%s: unknown wordSign\n", proc );
      return false;    
    }
    break;
  case WK_FLOAT :
    if ( inr->wdim == sizeof( float ) ) {
      oss << "FLOAT";
    }
    else if ( inr->wdim  == sizeof( double ) ) {
      oss << "DOUBLE";
    }
    else {
      fprintf( stderr, "%s: unknown WK_FLOAT word dim\n", proc );
      return false;    
    }
    break;
  default :
    fprintf( stderr, "%s: unknown wordKind for image\n", proc );
    return false;  
  }
  oss << "\n";
  
  oss << "-dx "<< inr->vx <<"\n";
  oss << "-dy "<< inr->vy <<"\n";
  if ( inr->zdim > 1 )
    oss << "-dz " << inr->vz << "\n";

  if ( inr->wdim > 1 ) {
    oss << "-bo ";
    switch ( _getEndianness() ) {
    default :
    case END_LITTLE :
      oss << "DCBA"; break;
    case END_BIG :
      oss << "ABCD"; break;
    }
    oss << "\n";
  }
  switch ( inr->dataMode ) {
  default :
  case DM_BINARY :
    oss << "-om binar\n";
    break;
  case DM_ASCII :
    oss << "-om ascii\n";
  }
  if( ImageIO_write( inr, oss.str().data(), oss.str().length()) == 0) {
    return false;
  }
  return true;
}


CGAL_INLINE_FUNCTION
int writeGisData( const _image*) 
{
  return -1;
}