[GRASS-SVN] r54215 - in grass-addons: grass6/imagery/i.spec.unmix grass7/imagery/i.spec.unmix

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 6 00:42:12 PST 2012


Author: rashadkm
Date: 2012-12-06 00:42:12 -0800 (Thu, 06 Dec 2012)
New Revision: 54215

Modified:
   grass-addons/grass6/imagery/i.spec.unmix/la_extra.c
   grass-addons/grass6/imagery/i.spec.unmix/la_extra.h
   grass-addons/grass6/imagery/i.spec.unmix/main.c
   grass-addons/grass7/imagery/i.spec.unmix/la_extra.c
   grass-addons/grass7/imagery/i.spec.unmix/la_extra.h
   grass-addons/grass7/imagery/i.spec.unmix/main.c
Log:
i.spec.unmix memory cleanup

Modified: grass-addons/grass6/imagery/i.spec.unmix/la_extra.c
===================================================================
--- grass-addons/grass6/imagery/i.spec.unmix/la_extra.c	2012-12-05 18:23:20 UTC (rev 54214)
+++ grass-addons/grass6/imagery/i.spec.unmix/la_extra.c	2012-12-06 08:42:12 UTC (rev 54215)
@@ -512,3 +512,16 @@
 
     return 0;
 }
+
+int vec_free(VEC *vec)
+{
+  if ( !vec || (vec->dim) < 0 )
+    /* don't trust it */
+    return -1;
+   
+	//G_free(vec->ve);
+
+    G_free(vec);
+      
+  return 0;
+}

Modified: grass-addons/grass6/imagery/i.spec.unmix/la_extra.h
===================================================================
--- grass-addons/grass6/imagery/i.spec.unmix/la_extra.h	2012-12-05 18:23:20 UTC (rev 54214)
+++ grass-addons/grass6/imagery/i.spec.unmix/la_extra.h	2012-12-06 08:42:12 UTC (rev 54215)
@@ -24,3 +24,4 @@
 mat_struct *G_matrix_resize(mat_struct * in, int rows, int cols);
 double v_norm2(VEC * x);
 VEC *G_vec_copy(VEC * in);
+int vec_free(VEC *vec);

Modified: grass-addons/grass6/imagery/i.spec.unmix/main.c
===================================================================
--- grass-addons/grass6/imagery/i.spec.unmix/main.c	2012-12-05 18:23:20 UTC (rev 54214)
+++ grass-addons/grass6/imagery/i.spec.unmix/main.c	2012-12-06 08:42:12 UTC (rev 54215)
@@ -223,7 +223,10 @@
     /* memory allocation */
     A_tilde = G_matrix_init(A->rows + 1, A->cols, A->rows + 1);
     if (A_tilde == NULL)
-	G_fatal_error(_("Unable to allocate memory for matrix"));
+    {
+	    G_fatal_error(_("Unable to allocate memory for matrix"));
+	    exit(1);
+	  }  
 
     for (i = 0; i < A->rows; i++)
 	for (j = 0; j < A->cols; j++)
@@ -266,15 +269,18 @@
     *  check  max_total for number of digits to configure mu size
     */
     mu = 0.0001 * pow(10, -1 * ceil(log10(max_total)));
-    G_message("mu = %lf", mu);
+    /*G_message("mu = %lf", mu); */
 
-    // Missing? startvector = G_vector_init (0, 0, RVEC);
+    // Missing? startvector = G_vector_init (0, 0, RVEC); 
     startvector = G_vec_get2(A->cols, startvector);
 
 
 
     if (startvector == NULL)
-	G_fatal_error(_("Unable to allocate memory for vector"));
+    {
+	    G_fatal_error(_("Unable to allocate memory for vector"));
+	    exit(1);
+	  }  
 
 
     // Missing? A_times_startvector = G_vector_init (0, 0, RVEC);
@@ -400,16 +406,13 @@
 
       /* G_debug (5, "Change: %g - deviation: %g",   change, deviation); */
 
+	  }
 
-	    }
-
-
 	    /*----------  end of second contraint -----------------------
 	    * store fractions in resulting rows of resulting files
 	    * (number of bands = vector dimension) 
-	    
+	    */
 
-	    /* write result in full percent */
 
 	    VEC *fraction;
 
@@ -424,17 +427,14 @@
 	    /* save error and iterations */
 	    error_cell[col] = (CELL) (100 * error);
 	    iter_cell[col] = iterations;
+	    
+	    
+	    vec_free(fraction);
 
-	    /*
-	     V_FREE(fraction);
-	     V_FREE(b);
-	    **/    
 
 	} /* end cols loop */
 
 
-
-
 	/* write the resulting rows into output files: */
 	for (i = 0; i < A->cols; i++)	/* no. of spectra */
 	    G_put_map_row(resultfd[i], result_cell[i]);
@@ -464,7 +464,12 @@
 		"0 0 0 0 \n" "201 0 255 0\n" "end\n" "EOF", result_name);
 
 	/* G_system (command); */
+	
+	
+    vec_free(startvector);
 
+    vec_free(A_times_startvector);
+
 	/* create histogram */
 	do_histogram(result_name, Ref.file[i].mapset);
     }
@@ -484,7 +489,13 @@
 	G_close_cell(iter_fd);
 
     G_matrix_free(A);
+   
+    vec_free(errorvector);
 
+    vec_free(temp);
+    
+    vec_free(b_gamma);
+
     make_history(result_name, parm.group->answer, parm.matrixfile->answer);
 
     exit(EXIT_SUCCESS);

Modified: grass-addons/grass7/imagery/i.spec.unmix/la_extra.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/la_extra.c	2012-12-05 18:23:20 UTC (rev 54214)
+++ grass-addons/grass7/imagery/i.spec.unmix/la_extra.c	2012-12-06 08:42:12 UTC (rev 54215)
@@ -494,3 +494,16 @@
 
     return 0;
 }
+
+int vec_free(VEC *vec)
+{
+  if ( !vec || (vec->dim) < 0 )
+    /* don't trust it */
+    return -1;
+   
+	//G_free(vec->ve);
+
+    G_free(vec);
+      
+  return 0;
+}

Modified: grass-addons/grass7/imagery/i.spec.unmix/la_extra.h
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/la_extra.h	2012-12-05 18:23:20 UTC (rev 54214)
+++ grass-addons/grass7/imagery/i.spec.unmix/la_extra.h	2012-12-06 08:42:12 UTC (rev 54215)
@@ -24,3 +24,4 @@
 mat_struct *G_matrix_resize(mat_struct * in, int rows, int cols);
 double v_norm2(VEC * x);
 VEC *G_vec_copy(VEC * in);
+int vec_free(VEC *vec);

Modified: grass-addons/grass7/imagery/i.spec.unmix/main.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/main.c	2012-12-05 18:23:20 UTC (rev 54214)
+++ grass-addons/grass7/imagery/i.spec.unmix/main.c	2012-12-06 08:42:12 UTC (rev 54215)
@@ -401,10 +401,7 @@
 	    error_cell[col] = (CELL) (100 * error);
 	    iter_cell[col] = iterations;
 
-	    /****V_FREE(fraction);
-	    V_FREE(b);
-	    *****/
-
+      vec_free(fraction);
 	}			/* end cols loop */
 
 	/* write the resulting rows into output files:  */
@@ -428,7 +425,11 @@
 	char command[1080];
 
 	Rast_close(resultfd[i]);
+	
+	 vec_free(startvector);
 
+    vec_free(A_times_startvector);
+
 	/* make grey scale color table */
 	sprintf(result_name, "%s.%d", parm.result->answer, (i + 1));
 	sprintf(command, "r.colors map=%s color=rules <<EOF\n"
@@ -453,7 +454,13 @@
 	Rast_close(iter_fd);
 
     G_matrix_free(A);
+   
+    vec_free(errorvector);
 
+    vec_free(temp);
+    
+    vec_free(b_gamma);    
+
     make_history(result_name, parm.group->answer, parm.matrixfile->answer);
 
     exit(EXIT_SUCCESS);



More information about the grass-commit mailing list