1 /**********************************************************
2 * Version $Id$
3 *********************************************************/
4
5 ///////////////////////////////////////////////////////////
6 // //
7 // SAGA //
8 // //
9 // System for Automated Geoscientific Analyses //
10 // //
11 // Tool Library //
12 // Grid_Calculus //
13 // //
14 //-------------------------------------------------------//
15 // //
16 // kff_synth.cpp //
17 // //
18 // Copyright (C) 2013 by //
19 // HfT Stuttgart //
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: johannes.engels@hft-stuttgart.de //
43 // //
44 // contact: Johannes Engels //
45 // Hochschule fuer Technik Stuttgart //
46 // Schellingstr. 24 //
47 // 70174 Stuttgart //
48 // Germany //
49 // //
50 ///////////////////////////////////////////////////////////
51
52 //---------------------------------------------------------
53
54
55 ///////////////////////////////////////////////////////////
56 // //
57 // //
58 // //
59 ///////////////////////////////////////////////////////////
60
61 //---------------------------------------------------------
62 #include "kff_synth.h"
63
64 extern "C" {
65 #include "./../grid_filter/geodesic_morph_rec/storeorg.h"
66 #include "./../grid_filter/geodesic_morph_rec/spezfunc.h"
67 }
68
69 ///////////////////////////////////////////////////////////
70 // //
71 // //
72 // //
73 ///////////////////////////////////////////////////////////
74
75 //---------------------------------------------------------
Ckff_synthesis(void)76 Ckff_synthesis::Ckff_synthesis(void)
77 {
78 Set_Name (_TL("Spherical Harmonic Synthesis"));
79
80 Set_Author (SG_T("HfT Stuttgart (c) 2013"));
81
82 Set_Description (_TW(
83 "Synthesis of a completely normalized spherical harmonic expansion. The coefficients are "
84 "read from the input file (ASCII file, columns separated by space).\n\n"
85 ));
86
87 Parameters.Add_Grid_Output (NULL,
88 "OUTPUT_GRID",
89 _TL("Synthesized Grid"),
90 _TL("Synthesized Grid"));
91
92 Parameters.Add_FilePath (NULL,
93 "FILE",
94 _TL("File with Coefficients"),
95 _TL("ASCII file with columns degree, order, c_lm, s_lm (separated by space)"));
96
97 Parameters.Add_Value (NULL, "MINDEGREE",
98 _TL ("Start Degree"),
99 _TL ("Start Degree"),
100 PARAMETER_TYPE_Int,
101 0);
102
103 Parameters.Add_Value (NULL, "MAXDEGREE",
104 _TL ("Expansion Degree"),
105 _TL ("Expansion Degree"),
106 PARAMETER_TYPE_Int,
107 180);
108
109 Parameters.Add_Value (NULL, "LAT_START",
110 _TL ("Start Latitude"),
111 _TL ("Start Latitude"),
112 PARAMETER_TYPE_Double,
113 -90.0);
114
115 Parameters.Add_Value (NULL, "END_LAT",
116 _TL ("End Latitude"),
117 _TL ("End Latitude"),
118 PARAMETER_TYPE_Double,
119 90.0);
120
121 Parameters.Add_Value (NULL, "LONG_START",
122 _TL ("Start Longitude"),
123 _TL ("Start Longitude"),
124 PARAMETER_TYPE_Double,
125 -180.0);
126
127 Parameters.Add_Value (NULL, "END_LONG",
128 _TL ("End Longitude"),
129 _TL ("End Longitude"),
130 PARAMETER_TYPE_Double,
131 180.0);
132
133 Parameters.Add_Value (NULL, "INC",
134 _TL ("Latitude / Longitude Increment"),
135 _TL ("Latitude / Longitude Increment"),
136 PARAMETER_TYPE_Double,
137 1.0);
138 }
139
140 ///////////////////////////////////////////////////////////
141 // //
142 // //
143 // //
144 ///////////////////////////////////////////////////////////
145
On_Execute(void)146 bool Ckff_synthesis::On_Execute(void)
147 {
148 CSG_Grid *poutgrid;
149
150 int numlat = 0;
151 int numlong = 0;
152 int maxdegree = 0;
153 int mindegree = 0;
154 int rc = 0;
155 double inc = 0.0;
156 double lat_start = 0.0;
157 double end_lat = 0.0;
158 double long_start = 0.0;
159 double end_long = 0.0;
160 CSG_String fileName;
161 double **c_lm;
162 double **s_lm;
163 double **gitter;
164 char *error_liste = "nix";
165
166 //poutgrid = Parameters ("OUTPUT GRID")->asGrid ();
167
168 fileName = Parameters("FILE")->asString();
169 inc = Parameters ("INC")->asDouble ();
170 mindegree = Parameters ("MINDEGREE")->asInt ();
171 maxdegree = Parameters ("MAXDEGREE")->asInt ();
172 lat_start = Parameters ("LAT_START")->asDouble ();
173 end_lat = Parameters ("END_LAT")->asDouble ();
174 long_start = Parameters ("LONG_START")->asDouble ();
175 end_long = Parameters ("END_LONG")->asDouble ();
176
177 numlat = static_cast <int> (floor ((end_lat - lat_start) / inc) + 1);
178 numlong = static_cast <int> (floor ((end_long - long_start) / inc) + 1);
179 gitter = (double **) matrix_all_alloc (numlat, numlong, 'D', 0);
180
181 read_coefficients (fileName.b_str(),
182 mindegree,
183 maxdegree,
184 &c_lm,
185 &s_lm);
186
187
188 rc = kff_synthese_regel_gitter_m (inc,
189 lat_start,
190 end_lat,
191 long_start,
192 end_long,
193 numlat,
194 numlong,
195 'A',
196 mindegree,
197 maxdegree,
198 c_lm,
199 s_lm,
200 gitter,
201 &error_liste);
202
203 poutgrid = SG_Create_Grid(SG_DATATYPE_Double, numlong, numlat, inc, long_start, lat_start);
204 poutgrid ->Set_Name(_TL("Synthesized Grid"));
205
206 for (int y = 0; y < numlat; y++)
207 {
208 #pragma omp parallel for
209 for (int x = 0; x < numlong; x++)
210 {
211 poutgrid->Set_Value(x,y, gitter[y][x]);
212 }
213 }
214
215 Parameters("OUTPUT_GRID")->Set_Value(poutgrid);
216
217 matrix_all_free ((void **) gitter);
218 matrix_all_free ((void **) c_lm);
219 matrix_all_free ((void **) s_lm);
220
221 return( true );
222 }
223
224
225 ///////////////////////////////////////////////////////////
226 // //
227 // //
228 // //
229 ///////////////////////////////////////////////////////////
230
231 //---------------------------------------------------------
232