2727#include <stdlib.h>
2828#include <stdio.h>
2929#include <string.h>
30+ #include <float.h>
3031#include <grass/gis.h>
3132#include <grass/raster.h>
3233#include <grass/display.h>
3536int main ( int argc , char * * argv )
3637{
3738 struct GModule * module ;
38- struct Option * info_opt , * rast_opt , * vect_opt , * coor_opt ;
39+ struct Option * info_opt , * rast_opt , * vect_opt , * coor_opt , * north_opt , * south_opt , * east_opt , * west_opt , * rows_opt , * cols_opt ;
3940 struct Cell_head window ;
4041
4142 /* Initialize the GIS calls */
@@ -63,6 +64,30 @@ int main( int argc, char **argv )
6364 coor_opt -> type = TYPE_DOUBLE ;
6465 coor_opt -> multiple = YES ;
6566
67+ north_opt = G_define_option ();
68+ north_opt -> key = "north" ;
69+ north_opt -> type = TYPE_STRING ;
70+
71+ south_opt = G_define_option ();
72+ south_opt -> key = "south" ;
73+ south_opt -> type = TYPE_STRING ;
74+
75+ east_opt = G_define_option ();
76+ east_opt -> key = "east" ;
77+ east_opt -> type = TYPE_STRING ;
78+
79+ west_opt = G_define_option ();
80+ west_opt -> key = "west" ;
81+ west_opt -> type = TYPE_STRING ;
82+
83+ rows_opt = G_define_option ();
84+ rows_opt -> key = "rows" ;
85+ rows_opt -> type = TYPE_INTEGER ;
86+
87+ cols_opt = G_define_option ();
88+ cols_opt -> key = "cols" ;
89+ cols_opt -> type = TYPE_INTEGER ;
90+
6691 if ( G_parser ( argc , argv ) )
6792 exit ( EXIT_FAILURE );
6893
@@ -249,13 +274,22 @@ int main( int argc, char **argv )
249274 int row , col ;
250275 void * ptr ;
251276 double val ;
277+ double min = DBL_MAX ;
278+ double max = - DBL_MAX ;
252279 double sum = 0 ; // sum of values
253280 int count = 0 ; // count of non null values
254281 double mean = 0 ;
255282 double squares_sum = 0 ; // sum of squares
256283 double stdev = 0 ; // standard deviation
257284
258285 G_get_cellhd ( rast_opt -> answer , "" , & window );
286+ window .north = atof ( north_opt -> answer );
287+ window .south = atof ( south_opt -> answer );
288+ window .east = atof ( east_opt -> answer );
289+ window .west = atof ( west_opt -> answer );
290+ window .rows = ( int ) atoi ( rows_opt -> answer );
291+ window .cols = ( int ) atoi ( cols_opt -> answer );
292+
259293 G_set_window ( & window );
260294 fd = G_open_cell_old ( rast_opt -> answer , "" );
261295
@@ -306,6 +340,8 @@ int main( int argc, char **argv )
306340 }
307341 if ( ! G_is_null_value ( ptr , rast_type ) )
308342 {
343+ if ( val < min ) min = val ;
344+ if ( val > max ) max = val ;
309345 sum += val ;
310346 count ++ ;
311347 squares_sum += pow ( val , 2 );
@@ -316,11 +352,13 @@ int main( int argc, char **argv )
316352 squares_sum -= count * pow ( mean , 2 );
317353 stdev = sqrt ( squares_sum / ( count - 1 ) );
318354
319- fprintf ( stdout , "SUM:%e\n" , sum );
320- fprintf ( stdout , "MEAN:%e\n" , mean );
355+ fprintf ( stdout , "MIN:%.17e\n" , min );
356+ fprintf ( stdout , "MAX:%.17e\n" , max );
357+ fprintf ( stdout , "SUM:%.17e\n" , sum );
358+ fprintf ( stdout , "MEAN:%.17e\n" , mean );
321359 fprintf ( stdout , "COUNT:%d\n" , count );
322- fprintf ( stdout , "STDEV:%e \n" , stdev );
323- fprintf ( stdout , "SQSUM:%e \n" , squares_sum );
360+ fprintf ( stdout , "STDEV:%.17e \n" , stdev );
361+ fprintf ( stdout , "SQSUM:%.17e \n" , squares_sum );
324362
325363 G_close_cell ( fd );
326364 }
0 commit comments