[GRASS-SVN] r55632 - grass/branches/releasebranch_6_4/raster/r.in.gdal

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 4 14:48:13 PDT 2013


Author: mmetz
Date: 2013-04-04 14:48:12 -0700 (Thu, 04 Apr 2013)
New Revision: 55632

Modified:
   grass/branches/releasebranch_6_4/raster/r.in.gdal/main.c
Log:
r.in.gdal: fix GDT_Float64 import

Modified: grass/branches/releasebranch_6_4/raster/r.in.gdal/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.in.gdal/main.c	2013-04-04 21:47:57 UTC (rev 55631)
+++ grass/branches/releasebranch_6_4/raster/r.in.gdal/main.c	2013-04-04 21:48:12 UTC (rev 55632)
@@ -709,8 +709,8 @@
     int row, nrows, ncols, complex;
     int cf, cfR, cfI, bNoDataEnabled;
     int indx;
-    CELL *cell, *cellReal, *cellImg;
-    float *bufComplex;
+    void *cell, *cellReal, *cellImg;
+    void *bufComplex;
     double dfNoData;
     char outputReal[GNAME_MAX], outputImg[GNAME_MAX];
     char *nullFlags = NULL;
@@ -725,12 +725,17 @@
 
     switch (eRawGDT) {
     case GDT_Float32:
-    case GDT_Float64:
 	data_type = FCELL_TYPE;
 	eGDT = GDT_Float32;
 	complex = FALSE;
 	break;
 
+    case GDT_Float64:
+	data_type = DCELL_TYPE;
+	eGDT = GDT_Float64;
+	complex = FALSE;
+	break;
+
     case GDT_Byte:
 	data_type = CELL_TYPE;
 	eGDT = GDT_Int32;
@@ -775,7 +780,10 @@
 
 	cellReal = G_allocate_raster_buf(data_type);
 	cellImg = G_allocate_raster_buf(data_type);
-	bufComplex = (float *)G_malloc(sizeof(float) * ncols * 2);
+	if (eGDT == GDT_Float64)
+	    bufComplex = (double *)G_malloc(sizeof(double) * ncols * 2);
+	else
+	    bufComplex = (float *)G_malloc(sizeof(float) * ncols * 2);
 
 	if (group_ref != NULL) {
 	    I_add_file_to_group_ref(outputReal, G_mapset(), group_ref);
@@ -815,17 +823,23 @@
 
 		for (indx = ncols - 1; indx >= 0; indx--) {	/* CEOS: flip east-west during import - MN */
 		    if (eGDT == GDT_Int32) {
-			((GInt32 *) cellReal)[ncols - indx] =
+			((CELL *) cellReal)[ncols - indx] =
 			    ((GInt32 *) bufComplex)[indx * 2];
-			((GInt32 *) cellImg)[ncols - indx] =
+			((CELL *) cellImg)[ncols - indx] =
 			    ((GInt32 *) bufComplex)[indx * 2 + 1];
 		    }
-		    else {
-			((float *)cellReal)[ncols - indx] =
-			    bufComplex[indx * 2];
-			((float *)cellImg)[ncols - indx] =
-			    bufComplex[indx * 2 + 1];
+		    else if (eGDT == GDT_Float32) {
+			((FCELL *)cellReal)[ncols - indx] =
+			    ((float *)bufComplex)[indx * 2];
+			((FCELL *)cellImg)[ncols - indx] =
+			    ((float *)bufComplex)[indx * 2 + 1];
 		    }
+		    else if (eGDT == GDT_Float64) {
+			((DCELL *)cellReal)[ncols - indx] =
+			    ((double *)bufComplex)[indx * 2];
+			((DCELL *)cellImg)[ncols - indx] =
+			    ((double *)bufComplex)[indx * 2 + 1];
+		    }
 		}
 		G_put_raster_row(cfR, cellReal, data_type);
 		G_put_raster_row(cfI, cellImg, data_type);
@@ -839,18 +853,25 @@
 
 		    if (eGDT == GDT_Int32) {
 			for (indx = 0; indx < ncols; indx++) {
-			    if (((GInt32 *) cell)[indx] == (GInt32) dfNoData) {
+			    if (((CELL *) cell)[indx] == (GInt32) dfNoData) {
 				nullFlags[indx] = 1;
 			    }
 			}
 		    }
 		    else if (eGDT == GDT_Float32) {
 			for (indx = 0; indx < ncols; indx++) {
-			    if (((float *)cell)[indx] == (float)dfNoData) {
+			    if (((FCELL *)cell)[indx] == (float)dfNoData) {
 				nullFlags[indx] = 1;
 			    }
 			}
 		    }
+		    else if (eGDT == GDT_Float64) {
+			for (indx = 0; indx < ncols; indx++) {
+			    if (((DCELL *)cell)[indx] == dfNoData) {
+				nullFlags[indx] = 1;
+			    }
+			}
+		    }
 
 		    G_insert_null_values(cell, nullFlags, ncols, data_type);
 		}
@@ -872,18 +893,25 @@
 
 		if (eGDT == GDT_Int32) {
 		    for (indx = 0; indx < ncols; indx++) {
-			if (((GInt32 *) cell)[indx] == (GInt32) dfNoData) {
+			if (((CELL *) cell)[indx] == (CELL) dfNoData) {
 			    nullFlags[indx] = 1;
 			}
 		    }
 		}
 		else if (eGDT == GDT_Float32) {
 		    for (indx = 0; indx < ncols; indx++) {
-			if (((float *)cell)[indx] == (float)dfNoData) {
+			if (((FCELL *)cell)[indx] == (FCELL)dfNoData) {
 			    nullFlags[indx] = 1;
 			}
 		    }
 		}
+		else if (eGDT == GDT_Float64) {
+		    for (indx = 0; indx < ncols; indx++) {
+			if (((DCELL *)cell)[indx] == dfNoData) {
+			    nullFlags[indx] = 1;
+			}
+		    }
+		}
 
 		G_insert_null_values(cell, nullFlags, ncols, data_type);
 	    }
@@ -910,6 +938,8 @@
 	G_write_history((char *)outputImg, &history);
 
 	G_free(bufComplex);
+	G_free(cellReal);
+	G_free(cellImg);
     }
     else {
 	G_debug(1, "Creating support files for %s", output);
@@ -917,6 +947,8 @@
 	G_short_history((char *)output, "raster", &history);
 	G_command_history(&history);
 	G_write_history((char *)output, &history);
+
+	G_free(cell);
     }
 
     if (nullFlags != NULL)



More information about the grass-commit mailing list