Check-in [25c2d2d92f]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:25c2d2d92fbf0b5f612a0db7046191a2a3bdaa84
Date: 2010-03-15 16:23:15
User: a.furieri@lqt.it
Comment:fixing png_checj_sig / png_sig_cmp
Tags And Properties
Changes
hide diffs unified diffs patch

Changes to lib/rasterlite_png.c

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    int i, j;
    volatile int palette_allocated = FALSE;
    memset (sig, 0, sizeof (sig));
    if (xgdGetBuf (sig, 8, infile) < 8)
      {
	  return NULL;
      }
    if (!png_check_sig (sig, 8))
      {
	  return NULL;
      }
#ifndef PNG_SETJMP_NOT_SUPPORTED
    png_ptr =
	png_create_read_struct (PNG_LIBPNG_VER_STRING, &xgdPngJmpbufStruct,
				xgdPngErrorHandler, NULL);







|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    int i, j;
    volatile int palette_allocated = FALSE;
    memset (sig, 0, sizeof (sig));
    if (xgdGetBuf (sig, 8, infile) < 8)
      {
	  return NULL;
      }
    if (!png_sig_cmp (sig, 0, 8))
      {
	  return NULL;
      }
#ifndef PNG_SETJMP_NOT_SUPPORTED
    png_ptr =
	png_create_read_struct (PNG_LIBPNG_VER_STRING, &xgdPngJmpbufStruct,
				xgdPngErrorHandler, NULL);

Changes to src/rasterlite_grid.c

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
...
328
329
330
331
332
333
334


335
336
337



338
339
340
341
342
343
344
...
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
....
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170



1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
....
1241
1242
1243
1244
1245
1246
1247














































1248
1249
1250
1251
1252
1253
1254
....
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
....
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
....
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559

1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
....
1644
1645
1646
1647
1648
1649
1650
1651


1652




1653


1654
1655
1656
1657
1658
1659
1660
....
1662
1663
1664
1665
1666
1667
1668



1669
1670
1671
1672
1673
1674
1675
1676
....
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
....
1877
1878
1879
1880
1881
1882
1883
1884


1885




1886


1887
1888
1889
1890
1891
1892
1893
....
1895
1896
1897
1898
1899
1900
1901



1902
1903
1904
1905
1906
1907
1908
1909
....
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
	return 0;
    if (pc1->min > pc2->min)
	return 1;
    if (pc1->min < pc2->min)
	return -1;
    if (pc1->min > pc2->max)
	return 1;
    if (pc1->min < pc2->max)
	return -1;
}

static int
match_color (struct colorTable *color_table, int colors, double value,
	     unsigned char *red, unsigned char *green, unsigned char *blue)
{
/* mapping a value into the corresponding color */
................................................................................
    int j;
    int n;
    double x;
    double y;
    double aspect;
    double slope;
    double cang;
    int gray;
    float afWin[9];
    const double degreesToRadians = M_PI / 180.0;
    const double altRadians = p->altitude * degreesToRadians;
    const double azRadians = p->azimuth * degreesToRadians;
    double red;
    double green;
    double blue;
................................................................................
		      break;
		  }
	    }

	  if (bContainsNull)
	    {
		/* We have nulls so write nullValue and move on */


		r = p->no_red;
		g = p->no_green;
		b = p->no_blue;



	    }
	  else
	    {
		/* We have a valid 3x3 window. */

		/* ---------------------------------------
		 * Compute Hillshade
................................................................................
		      if (green > 255.0)
			  green = 255.0;
		      if (blue > 255.0)
			  blue = 255.0;
		      r = (unsigned char) red;
		      g = (unsigned char) green;
		      b = (unsigned) blue;



		  }
		else
		  {
		      /* plain gray-scale */
		      gray = (int) cang;
		      r = (unsigned char) gray;
		      g = (unsigned char) gray;
		      b = (unsigned) gray;

		  }
	    }
	  *p_raster++ = r;
	  *p_raster++ = g;
	  *p_raster++ = b;
      }
}

static int
triple_shaded_relief_color (struct colorTable *color_table, int colors,
			    struct triple_scan *p, unsigned char *raster,
			    int row)
{
/* creating a shaded relief color scanline */
    int color;
    int j;
    int n;
    double x;
    double y;
    double aspect;
    double slope;
    double cang;
................................................................................
		  }
	    }
	  ptr += sizeof (float);
      }
    return 1;
}

static void
export_geoTiff_float (struct colorTable *color_table, int colors,
		      const char *proj4text, const char *grid_path,

		      const char *tiff_path, unsigned char no_red,
		      unsigned char no_green, unsigned char no_blue,
		      int verbose)
{
/* exporting a FLOAT GRID as GeoTIFF */
    TIFF *tiff = NULL;
    GTIF *gtif = NULL;
    int byteorder = BYTE_ORDER_NONE;
    int c;

    int row = 0;
    char buf[1024];
    char path[1024];
    char *ptr = buf;
    int err = 0;



    int ncols = -1;
    int nrows = -1;
    double xllcorner = 0.0;
    double yllcorner = 0.0;
    double cellsize = 0.0;
    double nodata = 0.0;
    double tiepoint[6];
    double pixsize[3];
    unsigned char *raster = NULL;
    unsigned char *flt_buf = NULL;
    size_t rd;
    FILE *grid;

/* parsing the Grid Header .hdr */
    sprintf (path, "%s.hdr", grid_path);
    grid = fopen (path, "rb");
    if (!grid)
      {
	  printf ("Open error: %s\n", path);
	  return;
      }
    while ((c = getc (grid)) != EOF)
      {
	  if (c == '\r')
	    {
		/* ignoring Return chars */
		continue;
................................................................................
    if (err)
      {
	  /* there was some error */
	  printf ("Invalid FLOAT Grid Header format in: %s\n", path);
	  goto stop;
      }
    fclose (grid);















































/* parsing the Grid Cells .flt */
    sprintf (path, "%s.flt", grid_path);
    grid = fopen (path, "rb");
    if (!grid)
      {
	  printf ("Open error: %s\n", path);
................................................................................
	XTIFFClose (tiff);
    if (raster)
	free (raster);
    fclose (asc);
}

static int
fetch_float_scanline_shaded (int row, unsigned char *floats, int columns,
			     int byteorder, struct triple_scan *triplet)
{
/* feeding a TIFF scanline from a FLOAT Grid */
    int cell = 0;
    double value;
    unsigned char *ptr = floats;
    int endian_arch = check_endian_arch ();
................................................................................
			     double z_factor, double scale_factor,
			     double azimuth, double altitude, int verbose)
{
/* exporting a FLOAT GRID as GeoTIFF */
    TIFF *tiff = NULL;
    GTIF *gtif = NULL;
    int byteorder = BYTE_ORDER_NONE;
    int c;
    int row = 0;
    char buf[1024];
    char path[1024];
    char *ptr = buf;
    int err = 0;
    int ncols = -1;
    int nrows = -1;
    double xllcorner = 0.0;
    double yllcorner = 0.0;
    double cellsize = 0.0;
    double nodata = 0.0;
    double tiepoint[6];
................................................................................
    double pixsize[3];
    struct triple_scan *triplet = NULL;
    unsigned char *raster = NULL;
    unsigned char *flt_buf = NULL;
    size_t rd;
    FILE *grid;

/* parsing the Grid Header .hdr */
    sprintf (path, "%s.hdr", grid_path);
    grid = fopen (path, "rb");
    if (!grid)
      {
	  printf ("Open error: %s\n", path);

	  return;
      }
    while ((c = getc (grid)) != EOF)
      {
	  if (c == '\r')
	    {
		/* ignoring Return chars */
		continue;
	    }
	  if (c == '\n')
	    {
		*ptr = '\0';
		switch (row)
		  {
		  case 0:
		      if (!parseIntHeader (buf, "ncols ", &ncols))
			  err = 1;
		      break;
		  case 1:
		      if (!parseIntHeader (buf, "nrows ", &nrows))
			  err = 1;
		      break;
		  case 2:
		      if (!parseDblHeader (buf, "xllcorner ", &xllcorner))
			  err = 1;
		      break;
		  case 3:
		      if (!parseDblHeader (buf, "yllcorner ", &yllcorner))
			  err = 1;
		      break;
		  case 4:
		      if (!parseDblHeader (buf, "cellsize ", &cellsize))
			  err = 1;
		      break;
		  case 5:
		      if (!parseDblHeader (buf, "NODATA_value ", &nodata))
			  err = 1;
		      break;
		  case 6:
		      if (!parseOrderHeader (buf, "byteorder ", &byteorder))
			  err = 1;
		      break;
		  };
		ptr = buf;
		row++;
		if (row == 7)
		    break;
		continue;
	    }
	  *ptr++ = c;
      }
    if (err)
      {
	  /* there was some error */
	  printf ("Invalid FLOAT Grid Header format in: %s\n", path);
	  goto stop;
      }
    fclose (grid);

/* resizing CellSize */
    cellsize = (cellsize * (double) ncols) / (double) (ncols - 2);

/* parsing the Grid Cells .flt */
    sprintf (path, "%s.flt", grid_path);
    grid = fopen (path, "rb");
................................................................................
/* writing the TIFF Tags */
    TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, ncols - 2);
    TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, nrows - 2);
    TIFFSetField (tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField (tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
    TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, 1);
    TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);


    TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);




    TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 3);



/* writing the GeoTIFF Tags */
    pixsize[0] = cellsize;
    pixsize[1] = cellsize;
    pixsize[2] = 0.0;
    TIFFSetField (tiff, GTIFF_PIXELSCALE, 3, pixsize);
    tiepoint[0] = 0.0;
................................................................................
    tiepoint[2] = 0.0;
    tiepoint[3] = xllcorner;
    tiepoint[4] = yllcorner + (cellsize * nrows);
    tiepoint[5] = 0.0;
    TIFFSetField (tiff, GTIFF_TIEPOINTS, 6, tiepoint);
    GTIFSetFromProj4 (gtif, proj4text);
    GTIFWriteKeys (gtif);



    raster = malloc (ncols * 3);
    flt_buf = malloc (sizeof (float) * ncols);

/* initializing the TripleRow object */
    triplet = triple_alloc (ncols);
    triple_set_shaded_relief_params (triplet, z_factor, scale_factor, altitude,
				     azimuth);
    triple_set_monochrome_params (triplet, mono_color, mono_red, mono_green,
................................................................................
	  rd = fread (flt_buf, 1, ncols * sizeof (float), grid);
	  if (rd != (sizeof (float) * ncols))
	    {
		printf ("*** Grid read error ***\n");
		printf ("An invalid GeoTIFF was generated ... aborting ...\n");
		goto stop;
	    }
	  if (fetch_float_scanline_shaded
	      (row + 1, flt_buf, ncols, byteorder, triplet))
	    {
		if (triple_is_valid (triplet))
		  {
		      int ret = 1;
		      if (!color_table)
			  triple_shaded_relief (triplet, raster);
		      else
................................................................................
/* writing the TIFF Tags */
    TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, ncols - 2);
    TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, nrows - 2);
    TIFFSetField (tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField (tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
    TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, 1);
    TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);


    TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);




    TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 3);



/* writing the GeoTIFF Tags */
    pixsize[0] = cellsize;
    pixsize[1] = cellsize;
    pixsize[2] = 0.0;
    TIFFSetField (tiff, GTIFF_PIXELSCALE, 3, pixsize);
    tiepoint[0] = 0.0;
................................................................................
    tiepoint[2] = 0.0;
    tiepoint[3] = xllcorner;
    tiepoint[4] = yllcorner + (cellsize * nrows);
    tiepoint[5] = 0.0;
    TIFFSetField (tiff, GTIFF_TIEPOINTS, 6, tiepoint);
    GTIFSetFromProj4 (gtif, proj4text);
    GTIFWriteKeys (gtif);



    raster = malloc (ncols * 3);

/* initializing the TripleRow object */
    triplet = triple_alloc (ncols);
    triple_set_shaded_relief_params (triplet, z_factor, scale_factor, altitude,
				     azimuth);
    triple_set_monochrome_params (triplet, mono_color, mono_red, mono_green,
				  mono_blue);
................................................................................
    switch (grid_type)
      {
      case ASCII_GRID:
	  printf ("Grid Format: ASCII\n");
	  break;
      case FLOAT_GRID:
	  printf ("Grid Format: FLOAT\n");
	  break;
      default:
	  printf ("Grid Format: UNKNOWN\n");
	  break;
      }
    if (shaded_relief)
      {
	  printf ("\n           Shaded Relief arguments:\n");







<
|







 







|







 







>
>
|
|
|
>
>
>







 







>
>
>




<
|
<
<
>


<
<
<









<







 







|
<
|
>
|
|
<

<
<
<
<
<
>





>
>
>






<
<
<
<
<
<
<






|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







<

<

<
<







 







|
|
|
<

<
>


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|
>
>
|
>
>
>
>
|
>
>







 







>
>
>
|







 







<
|







 







|
>
>
|
>
>
>
>
|
>
>







 







>
>
>
|







 







<







129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
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
....
1148
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158
1159

1160





1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175







1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
....
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
....
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
....
1565
1566
1567
1568
1569
1570
1571

1572

1573


1574
1575
1576
1577
1578
1579
1580
....
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590

1591

1592
1593
1594
























































1595
1596
1597
1598
1599
1600
1601
....
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
....
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
....
1675
1676
1677
1678
1679
1680
1681

1682
1683
1684
1685
1686
1687
1688
1689
....
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
....
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
....
2286
2287
2288
2289
2290
2291
2292

2293
2294
2295
2296
2297
2298
2299
	return 0;
    if (pc1->min > pc2->min)
	return 1;
    if (pc1->min < pc2->min)
	return -1;
    if (pc1->min > pc2->max)
	return 1;

    return -1;
}

static int
match_color (struct colorTable *color_table, int colors, double value,
	     unsigned char *red, unsigned char *green, unsigned char *blue)
{
/* mapping a value into the corresponding color */
................................................................................
    int j;
    int n;
    double x;
    double y;
    double aspect;
    double slope;
    double cang;
    unsigned char gray;
    float afWin[9];
    const double degreesToRadians = M_PI / 180.0;
    const double altRadians = p->altitude * degreesToRadians;
    const double azRadians = p->azimuth * degreesToRadians;
    double red;
    double green;
    double blue;
................................................................................
		      break;
		  }
	    }

	  if (bContainsNull)
	    {
		/* We have nulls so write nullValue and move on */
		if (p->mono_color)
		  {
		      *p_raster++ = p->no_red;
		      *p_raster++ = p->no_green;
		      *p_raster++ = p->no_blue;
		  }
		else
		    *p_raster++ = 0;
	    }
	  else
	    {
		/* We have a valid 3x3 window. */

		/* ---------------------------------------
		 * Compute Hillshade
................................................................................
		      if (green > 255.0)
			  green = 255.0;
		      if (blue > 255.0)
			  blue = 255.0;
		      r = (unsigned char) red;
		      g = (unsigned char) green;
		      b = (unsigned) blue;
		      *p_raster++ = r;
		      *p_raster++ = g;
		      *p_raster++ = b;
		  }
		else
		  {
		      /* plain gray-scale */

		      gray = (unsigned char) cang;


		      *p_raster++ = gray;
		  }
	    }



      }
}

static int
triple_shaded_relief_color (struct colorTable *color_table, int colors,
			    struct triple_scan *p, unsigned char *raster,
			    int row)
{
/* creating a shaded relief color scanline */

    int j;
    int n;
    double x;
    double y;
    double aspect;
    double slope;
    double cang;
................................................................................
		  }
	    }
	  ptr += sizeof (float);
      }
    return 1;
}

static int

parse_grid_header_float (const char *grid_path, int *ext_byteorder,
			 int *ext_ncols, int *ext_nrows, double *ext_xllcorner,
			 double *ext_yllcorner, double *ext_cellsize,
			 double *ext_nodata)

{





/* parsing a Grid Header: FLOAT */
    int row = 0;
    char buf[1024];
    char path[1024];
    char *ptr = buf;
    int err = 0;
    FILE *grid;
    int c;
    int byteorder = BYTE_ORDER_NONE;
    int ncols = -1;
    int nrows = -1;
    double xllcorner = 0.0;
    double yllcorner = 0.0;
    double cellsize = 0.0;
    double nodata = 0.0;







/* parsing the Grid Header .hdr */
    sprintf (path, "%s.hdr", grid_path);
    grid = fopen (path, "rb");
    if (!grid)
      {
	  printf ("Open error: %s\n", path);
	  return 0;
      }
    while ((c = getc (grid)) != EOF)
      {
	  if (c == '\r')
	    {
		/* ignoring Return chars */
		continue;
................................................................................
    if (err)
      {
	  /* there was some error */
	  printf ("Invalid FLOAT Grid Header format in: %s\n", path);
	  goto stop;
      }
    fclose (grid);
    *ext_byteorder = byteorder;
    *ext_ncols = ncols;
    *ext_nrows = xllcorner;
    *ext_xllcorner = yllcorner;
    *ext_yllcorner = yllcorner;
    *ext_cellsize = cellsize;
    *ext_nodata = nodata;
    return 1;
  stop:
    fclose (grid);
    return 0;
}

static void
export_geoTiff_float (struct colorTable *color_table, int colors,
		      const char *proj4text, const char *grid_path,
		      const char *tiff_path, unsigned char no_red,
		      unsigned char no_green, unsigned char no_blue,
		      int verbose)
{
/* exporting a FLOAT GRID as GeoTIFF */
    TIFF *tiff = NULL;
    GTIF *gtif = NULL;
    int byteorder = BYTE_ORDER_NONE;
    int row = 0;
    char path[1024];
    int ncols = -1;
    int nrows = -1;
    double xllcorner = 0.0;
    double yllcorner = 0.0;
    double cellsize = 0.0;
    double nodata = 0.0;
    double tiepoint[6];
    double pixsize[3];
    unsigned char *raster = NULL;
    unsigned char *flt_buf = NULL;
    size_t rd;
    FILE *grid;

    if (!parse_grid_header_float
	(grid_path, &byteorder, &ncols, &nrows, &xllcorner, &yllcorner,
	 &cellsize, &nodata))
      {
	  printf ("Unable to read the Grid Header\n");
	  return;
      }

/* parsing the Grid Cells .flt */
    sprintf (path, "%s.flt", grid_path);
    grid = fopen (path, "rb");
    if (!grid)
      {
	  printf ("Open error: %s\n", path);
................................................................................
	XTIFFClose (tiff);
    if (raster)
	free (raster);
    fclose (asc);
}

static int
fetch_float_scanline_shaded (unsigned char *floats, int columns,
			     int byteorder, struct triple_scan *triplet)
{
/* feeding a TIFF scanline from a FLOAT Grid */
    int cell = 0;
    double value;
    unsigned char *ptr = floats;
    int endian_arch = check_endian_arch ();
................................................................................
			     double z_factor, double scale_factor,
			     double azimuth, double altitude, int verbose)
{
/* exporting a FLOAT GRID as GeoTIFF */
    TIFF *tiff = NULL;
    GTIF *gtif = NULL;
    int byteorder = BYTE_ORDER_NONE;

    int row = 0;

    char path[1024];


    int ncols = -1;
    int nrows = -1;
    double xllcorner = 0.0;
    double yllcorner = 0.0;
    double cellsize = 0.0;
    double nodata = 0.0;
    double tiepoint[6];
................................................................................
    double pixsize[3];
    struct triple_scan *triplet = NULL;
    unsigned char *raster = NULL;
    unsigned char *flt_buf = NULL;
    size_t rd;
    FILE *grid;

    if (!parse_grid_header_float
	(grid_path, &byteorder, &ncols, &nrows, &xllcorner, &yllcorner,
	 &cellsize, &nodata))

      {

	  printf ("Unable to read the Grid Header\n");
	  return;
      }

























































/* resizing CellSize */
    cellsize = (cellsize * (double) ncols) / (double) (ncols - 2);

/* parsing the Grid Cells .flt */
    sprintf (path, "%s.flt", grid_path);
    grid = fopen (path, "rb");
................................................................................
/* writing the TIFF Tags */
    TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, ncols - 2);
    TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, nrows - 2);
    TIFFSetField (tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField (tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
    TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, 1);
    TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);
    if (!color_table && !mono_color)
      {
	  TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 1);
	  TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
      }
    else
      {
	  TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 3);
	  TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
      }

/* writing the GeoTIFF Tags */
    pixsize[0] = cellsize;
    pixsize[1] = cellsize;
    pixsize[2] = 0.0;
    TIFFSetField (tiff, GTIFF_PIXELSCALE, 3, pixsize);
    tiepoint[0] = 0.0;
................................................................................
    tiepoint[2] = 0.0;
    tiepoint[3] = xllcorner;
    tiepoint[4] = yllcorner + (cellsize * nrows);
    tiepoint[5] = 0.0;
    TIFFSetField (tiff, GTIFF_TIEPOINTS, 6, tiepoint);
    GTIFSetFromProj4 (gtif, proj4text);
    GTIFWriteKeys (gtif);
    if (!color_table && !mono_color)
	raster = malloc (ncols);
    else
	raster = malloc (ncols * 3);
    flt_buf = malloc (sizeof (float) * ncols);

/* initializing the TripleRow object */
    triplet = triple_alloc (ncols);
    triple_set_shaded_relief_params (triplet, z_factor, scale_factor, altitude,
				     azimuth);
    triple_set_monochrome_params (triplet, mono_color, mono_red, mono_green,
................................................................................
	  rd = fread (flt_buf, 1, ncols * sizeof (float), grid);
	  if (rd != (sizeof (float) * ncols))
	    {
		printf ("*** Grid read error ***\n");
		printf ("An invalid GeoTIFF was generated ... aborting ...\n");
		goto stop;
	    }

	  if (fetch_float_scanline_shaded (flt_buf, ncols, byteorder, triplet))
	    {
		if (triple_is_valid (triplet))
		  {
		      int ret = 1;
		      if (!color_table)
			  triple_shaded_relief (triplet, raster);
		      else
................................................................................
/* writing the TIFF Tags */
    TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, ncols - 2);
    TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, nrows - 2);
    TIFFSetField (tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField (tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
    TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, 1);
    TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);
    if (!color_table && !mono_color)
      {
	  TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 1);
	  TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
      }
    else
      {
	  TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 3);
	  TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
      }

/* writing the GeoTIFF Tags */
    pixsize[0] = cellsize;
    pixsize[1] = cellsize;
    pixsize[2] = 0.0;
    TIFFSetField (tiff, GTIFF_PIXELSCALE, 3, pixsize);
    tiepoint[0] = 0.0;
................................................................................
    tiepoint[2] = 0.0;
    tiepoint[3] = xllcorner;
    tiepoint[4] = yllcorner + (cellsize * nrows);
    tiepoint[5] = 0.0;
    TIFFSetField (tiff, GTIFF_TIEPOINTS, 6, tiepoint);
    GTIFSetFromProj4 (gtif, proj4text);
    GTIFWriteKeys (gtif);
    if (!color_table && !mono_color)
	raster = malloc (ncols);
    else
	raster = malloc (ncols * 3);

/* initializing the TripleRow object */
    triplet = triple_alloc (ncols);
    triple_set_shaded_relief_params (triplet, z_factor, scale_factor, altitude,
				     azimuth);
    triple_set_monochrome_params (triplet, mono_color, mono_red, mono_green,
				  mono_blue);
................................................................................
    switch (grid_type)
      {
      case ASCII_GRID:
	  printf ("Grid Format: ASCII\n");
	  break;
      case FLOAT_GRID:
	  printf ("Grid Format: FLOAT\n");

      default:
	  printf ("Grid Format: UNKNOWN\n");
	  break;
      }
    if (shaded_relief)
      {
	  printf ("\n           Shaded Relief arguments:\n");