1 /**********************************************************
2  * Version $Id: grid_latlon_statistics.cpp 1252 2011-12-15 15:43:13Z oconrad $
3  *********************************************************/
4 
5 ///////////////////////////////////////////////////////////
6 //                                                       //
7 //                         SAGA                          //
8 //                                                       //
9 //      System for Automated Geoscientific Analyses      //
10 //                                                       //
11 //                     Tool Library                      //
12 //                    statistics_grid                    //
13 //                                                       //
14 //-------------------------------------------------------//
15 //                                                       //
16 //               grid_latlon_statistics.cpp              //
17 //                                                       //
18 //                 Copyright (C) 2012 by                 //
19 //                      Olaf Conrad                      //
20 //                                                       //
21 //-------------------------------------------------------//
22 //                                                       //
23 // This file is part of 'SAGA - System for Automated     //
24 // Geoscientific Analyses'. SAGA is free software; you   //
25 // can redistribute it and/or modify it under the terms  //
26 // of the GNU General Public License as published by the //
27 // Free Software Foundation, either version 2 of the     //
28 // License, or (at your option) any later version.       //
29 //                                                       //
30 // SAGA is distributed in the hope that it will be       //
31 // useful, but WITHOUT ANY WARRANTY; without even the    //
32 // implied warranty of MERCHANTABILITY or FITNESS FOR A  //
33 // PARTICULAR PURPOSE. See the GNU General Public        //
34 // License for more details.                             //
35 //                                                       //
36 // You should have received a copy of the GNU General    //
37 // Public License along with this program; if not, see   //
38 // <http://www.gnu.org/licenses/>.                       //
39 //                                                       //
40 //-------------------------------------------------------//
41 //                                                       //
42 //    e-mail:     oconrad@saga-gis.org                   //
43 //                                                       //
44 //    contact:    Olaf Conrad                            //
45 //                Institute of Geography                 //
46 //                University of Hamburg                  //
47 //                Germany                                //
48 //                                                       //
49 ///////////////////////////////////////////////////////////
50 
51 //---------------------------------------------------------
52 
53 
54 ///////////////////////////////////////////////////////////
55 //														 //
56 //														 //
57 //														 //
58 ///////////////////////////////////////////////////////////
59 
60 //---------------------------------------------------------
61 #include "grid_latlon_statistics.h"
62 
63 
64 ///////////////////////////////////////////////////////////
65 //														 //
66 //														 //
67 //														 //
68 ///////////////////////////////////////////////////////////
69 
70 //---------------------------------------------------------
CGrid_Statistics_Latitudinal(void)71 CGrid_Statistics_Latitudinal::CGrid_Statistics_Latitudinal(void)
72 {
73 	//-----------------------------------------------------
74 	Set_Name		(_TL("Longitudinal Grid Statistics"));
75 
76 	Set_Author		("O.Conrad (c) 2012");
77 
78 	Set_Description	(_TW(
79 		""
80 	));
81 
82 	//-----------------------------------------------------
83 	Parameters.Add_Grid(
84 		""	, "GRID"	, _TL("Grid"),
85 		_TL(""),
86 		PARAMETER_INPUT
87 	);
88 
89 	Parameters.Add_Table(
90 		""	, "STATS"	, _TL("Latitudinal Statistics"),
91 		_TL(""),
92 		PARAMETER_OUTPUT
93 	);
94 }
95 
96 
97 ///////////////////////////////////////////////////////////
98 //														 //
99 ///////////////////////////////////////////////////////////
100 
101 //---------------------------------------------------------
On_Execute(void)102 bool CGrid_Statistics_Latitudinal::On_Execute(void)
103 {
104 	CSG_Grid	*pGrid	= Parameters("GRID" )->asGrid();
105 	CSG_Table	*pTable	= Parameters("STATS")->asTable();
106 
107 	pTable->Destroy();
108 	pTable->Fmt_Name("%s [%s]", _TL("Latitudinal Statistics"), pGrid->Get_Name());
109 	pTable->Add_Field("Y"     , SG_DATATYPE_Double);
110 	pTable->Add_Field("MEAN"  , SG_DATATYPE_Double);
111 	pTable->Add_Field("MIN"   , SG_DATATYPE_Double);
112 	pTable->Add_Field("MAX"   , SG_DATATYPE_Double);
113 	pTable->Add_Field("STDDEV", SG_DATATYPE_Double);
114 
115 	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
116 	{
117 		CSG_Simple_Statistics	Statistics;
118 
119 		for(int x=0; x<Get_NX(); x++)
120 		{
121 			Statistics	+= pGrid->asDouble(x, y);
122 		}
123 
124 		CSG_Table_Record	*pRecord	= pTable->Add_Record();
125 
126 		pRecord->Set_Value(0, pGrid->Get_System().Get_yGrid_to_World(y));
127 		pRecord->Set_Value(1, Statistics.Get_Mean   ());
128 		pRecord->Set_Value(2, Statistics.Get_Minimum());
129 		pRecord->Set_Value(3, Statistics.Get_Maximum());
130 		pRecord->Set_Value(4, Statistics.Get_StdDev ());
131 	}
132 
133 	return( true );
134 }
135 
136 
137 ///////////////////////////////////////////////////////////
138 //														 //
139 //														 //
140 //														 //
141 ///////////////////////////////////////////////////////////
142 
143 //---------------------------------------------------------
CGrid_Statistics_Meridional(void)144 CGrid_Statistics_Meridional::CGrid_Statistics_Meridional(void)
145 {
146 	//-----------------------------------------------------
147 	Set_Name		(_TL("Meridional Grid Statistics"));
148 
149 	Set_Author		("O.Conrad (c) 2012");
150 
151 	Set_Description	(_TW(
152 		""
153 	));
154 
155 	//-----------------------------------------------------
156 	Parameters.Add_Grid(
157 		""	, "GRID"	, _TL("Grid"),
158 		_TL(""),
159 		PARAMETER_INPUT
160 	);
161 
162 	Parameters.Add_Table(
163 		""	, "STATS"	, _TL("Meridional Statistics"),
164 		_TL(""),
165 		PARAMETER_OUTPUT
166 	);
167 }
168 
169 
170 ///////////////////////////////////////////////////////////
171 //														 //
172 ///////////////////////////////////////////////////////////
173 
174 //---------------------------------------------------------
On_Execute(void)175 bool CGrid_Statistics_Meridional::On_Execute(void)
176 {
177 	CSG_Grid	*pGrid	= Parameters("GRID" )->asGrid();
178 	CSG_Table	*pTable	= Parameters("STATS")->asTable();
179 
180 	pTable->Destroy();
181 	pTable->Fmt_Name("%s [%s]", _TL("Meridional Statistics"), pGrid->Get_Name());
182 	pTable->Add_Field("X"     , SG_DATATYPE_Double);
183 	pTable->Add_Field("MEAN"  , SG_DATATYPE_Double);
184 	pTable->Add_Field("MIN"   , SG_DATATYPE_Double);
185 	pTable->Add_Field("MAX"   , SG_DATATYPE_Double);
186 	pTable->Add_Field("STDDEV", SG_DATATYPE_Double);
187 
188 	for(int x=0; x<Get_NX() && Set_Progress(x, Get_NX()); x++)
189 	{
190 		CSG_Simple_Statistics	Statistics;
191 
192 		for(int y=0; y<Get_NY(); y++)
193 		{
194 			Statistics	+= pGrid->asDouble(x, y);
195 		}
196 
197 		CSG_Table_Record	*pRecord	= pTable->Add_Record();
198 
199 		pRecord->Set_Value(0, pGrid->Get_System().Get_xGrid_to_World(x));
200 		pRecord->Set_Value(1, Statistics.Get_Mean   ());
201 		pRecord->Set_Value(2, Statistics.Get_Minimum());
202 		pRecord->Set_Value(3, Statistics.Get_Maximum());
203 		pRecord->Set_Value(4, Statistics.Get_StdDev ());
204 	}
205 
206 	return( true );
207 }
208 
209 
210 ///////////////////////////////////////////////////////////
211 //														 //
212 //														 //
213 //														 //
214 ///////////////////////////////////////////////////////////
215 
216 //---------------------------------------------------------
217