[GRASS-SVN] r55625 - grass/trunk/raster/r.in.gdal

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 4 10:35:28 PDT 2013


Author: mmetz
Date: 2013-04-04 10:35:28 -0700 (Thu, 04 Apr 2013)
New Revision: 55625

Modified:
   grass/trunk/raster/r.in.gdal/main.c
Log:
r.in.gdal: fix r55611; import GDT_Float64 as DCELL_TYPE

Modified: grass/trunk/raster/r.in.gdal/main.c
===================================================================
--- grass/trunk/raster/r.in.gdal/main.c	2013-04-04 15:05:24 UTC (rev 55624)
+++ grass/trunk/raster/r.in.gdal/main.c	2013-04-04 17:35:28 UTC (rev 55625)
@@ -345,7 +345,7 @@
 	}
 	else {
             if (0 != G_make_location(parm.outloc->answer, &cellhd,
-                                     proj_info, proj_units)) {
+                                     proj_info, proj_units, NULL)) {
                 G_fatal_error(_("Unable to create new location <%s>"),
                               parm.outloc->answer);
             }
@@ -737,8 +737,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;
@@ -754,12 +754,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;
@@ -798,7 +803,10 @@
 
 	cellReal = Rast_allocate_buf(data_type);
 	cellImg = Rast_allocate_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);
@@ -836,17 +844,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];
+		    }
 		}
 		Rast_put_row(cfR, cellReal, data_type);
 		Rast_put_row(cfI, cellImg, data_type);
@@ -860,18 +874,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;
+			    }
+			}
+		    }
 
 		    Rast_insert_null_values(cell, nullFlags, ncols, data_type);
 		}
@@ -879,7 +900,7 @@
 		Rast_put_row(cf, cell, data_type);
 	    }			/* end of not complex */
 
-	    G_percent(row, nrows, 2);
+	    G_percent(row - 1, nrows, 2);
 	}			/* for loop */
     }				/* end of not AVHRR */
     else {
@@ -893,18 +914,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;
+			}
+		    }
+		}
 
 		Rast_insert_null_values(cell, nullFlags, ncols, data_type);
 	    }
@@ -931,6 +959,8 @@
 	Rast_write_history((char *)outputImg, &history);
 
 	G_free(bufComplex);
+	G_free(cellReal);
+	G_free(cellImg);
     }
     else {
 	G_debug(1, "Creating support files for %s", output);
@@ -938,6 +968,8 @@
 	Rast_short_history((char *)output, "raster", &history);
 	Rast_command_history(&history);
 	Rast_write_history((char *)output, &history);
+	
+	G_free(cell);
     }
 
     if (nullFlags != NULL)



More information about the grass-commit mailing list