source: issm/trunk/src/c/Container/Parameters.cpp@ 13975

Last change on this file since 13975 was 13975, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 13974

File size: 14.6 KB
Line 
1/*
2 * \file Parameters.c
3 * \brief: implementation of the Parameters class, derived from DataSet class
4 */
5
6/*Headers: {{{*/
7#ifdef HAVE_CONFIG_H
8 #include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include <vector>
14#include <functional>
15#include <algorithm>
16#include <iostream>
17
18#include "./DataSet.h"
19#include "../shared/shared.h"
20#include "../include/include.h"
21#include "../EnumDefinitions/EnumDefinitions.h"
22
23using namespace std;
24/*}}}*/
25
26/*Object constructors and destructor*/
27/*FUNCTION Parameters::Parameters(){{{*/
28Parameters::Parameters(){
29 enum_type=ParametersEnum;
30 return;
31}
32/*}}}*/
33/*FUNCTION Parameters::~Parameters(){{{*/
34Parameters::~Parameters(){
35 return;
36}
37/*}}}*/
38
39/*Object management*/
40/*FUNCTION Parameters::Exist{{{*/
41bool Parameters::Exist(int enum_type){
42
43 vector<Object*>::iterator object;
44 Param* param=NULL;
45
46 for ( object=objects.begin() ; object < objects.end(); object++ ){
47 param=dynamic_cast<Param*>(*object);
48 if(param->InstanceEnum()==enum_type) return true;
49 }
50 return false;
51}
52/*}}}*/
53/*FUNCTION Parameters::FindParam(bool* pbool,int enum_type){{{*/
54void Parameters::FindParam(bool* pbool,int enum_type){ _assert_(this);
55
56 vector<Object*>::iterator object;
57 Param* param=NULL;
58
59 for ( object=objects.begin() ; object < objects.end(); object++ ){
60
61 param=dynamic_cast<Param*>(*object);
62 if(param->InstanceEnum()==enum_type){
63 param->GetParameterValue(pbool);
64 return;
65 }
66 }
67 _error_("could not find parameter " << EnumToStringx(enum_type));
68}
69/*}}}*/
70/*FUNCTION Parameters::FindParam(int* pinteger,int enum_type){{{*/
71void Parameters::FindParam(int* pinteger,int enum_type){ _assert_(this);
72
73 vector<Object*>::iterator object;
74 Param* param=NULL;
75
76 for ( object=objects.begin() ; object < objects.end(); object++ ){
77
78 param=dynamic_cast<Param*>(*object);
79 if(param->InstanceEnum()==enum_type){
80 param->GetParameterValue(pinteger);
81 return;
82 }
83 }
84 _error_("could not find parameter " << EnumToStringx(enum_type));
85}
86/*}}}*/
87/*FUNCTION Parameters::FindParam(IssmDouble* pscalar, int enum_type){{{*/
88void Parameters::FindParam(IssmDouble* pscalar, int enum_type){ _assert_(this);
89
90 vector<Object*>::iterator object;
91 Param* param=NULL;
92
93 for ( object=objects.begin() ; object < objects.end(); object++ ){
94
95 param=dynamic_cast<Param*>(*object);
96 if(param->InstanceEnum()==enum_type){
97 param->GetParameterValue(pscalar);
98 return;
99 }
100 }
101 _error_("could not find parameter " << EnumToStringx(enum_type));
102}
103/*}}}*/
104/*FUNCTION Parameters::FindParam(IssmDouble* pscalar, int enum_type,IssmDouble time){{{*/
105void Parameters::FindParam(IssmDouble* pscalar, int enum_type,IssmDouble time){ _assert_(this);
106
107 vector<Object*>::iterator object;
108 Param* param=NULL;
109
110 for ( object=objects.begin() ; object < objects.end(); object++ ){
111
112 param=dynamic_cast<Param*>(*object);
113 if(param->InstanceEnum()==enum_type){
114 param->GetParameterValue(pscalar,time);
115 return;
116 }
117 }
118 _error_("could not find parameter " << EnumToStringx(enum_type));
119}
120/*}}}*/
121/*FUNCTION Parameters::FindParam(char** pstring,int enum_type){{{*/
122void Parameters::FindParam(char** pstring,int enum_type){ _assert_(this);
123
124 vector<Object*>::iterator object;
125 Param* param=NULL;
126
127 for ( object=objects.begin() ; object < objects.end(); object++ ){
128
129 param=dynamic_cast<Param*>(*object);
130 if(param->InstanceEnum()==enum_type){
131 param->GetParameterValue(pstring);
132 return;
133 }
134 }
135 _error_("could not find parameter " << EnumToStringx(enum_type));
136
137}
138/*}}}*/
139/*FUNCTION Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){{{*/
140void Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){ _assert_(this);
141
142 vector<Object*>::iterator object;
143 Param* param=NULL;
144
145 for ( object=objects.begin() ; object < objects.end(); object++ ){
146
147 param=dynamic_cast<Param*>(*object);
148 if(param->InstanceEnum()==enum_type){
149 param->GetParameterValue(pstringarray,pM);
150 return;
151 }
152 }
153 _error_("could not find parameter " << EnumToStringx(enum_type));
154
155}
156/*}}}*/
157/*FUNCTION Parameters::FindParam(int** pintarray,int* pM,int enum_type){{{*/
158void Parameters::FindParam(int** pintarray,int* pM, int enum_type){ _assert_(this);
159
160 vector<Object*>::iterator object;
161 Param* param=NULL;
162
163 for ( object=objects.begin() ; object < objects.end(); object++ ){
164
165 param=dynamic_cast<Param*>(*object);
166 if(param->InstanceEnum()==enum_type){
167 param->GetParameterValue(pintarray,pM);
168 return;
169 }
170 }
171 _error_("could not find parameter " << EnumToStringx(enum_type));
172
173}
174/*}}}*/
175/*FUNCTION Parameters::FindParam(int** pintarray,int* pM,int* pN,int enum_type){{{*/
176void Parameters::FindParam(int** pintarray,int* pM,int *pN,int enum_type){ _assert_(this);
177
178 vector<Object*>::iterator object;
179 Param* param=NULL;
180
181 for ( object=objects.begin() ; object < objects.end(); object++ ){
182
183 param=dynamic_cast<Param*>(*object);
184 if(param->InstanceEnum()==enum_type){
185 param->GetParameterValue(pintarray,pM,pN);
186 return;
187 }
188 }
189 _error_("could not find parameter " << EnumToStringx(enum_type));
190
191}
192/*}}}*/
193/*FUNCTION Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM,int enum_type){{{*/
194void Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM, int enum_type){ _assert_(this);
195
196 vector<Object*>::iterator object;
197 Param* param=NULL;
198
199 for ( object=objects.begin() ; object < objects.end(); object++ ){
200
201 param=dynamic_cast<Param*>(*object);
202 if(param->InstanceEnum()==enum_type){
203 param->GetParameterValue(pIssmDoublearray,pM);
204 return;
205 }
206 }
207 _error_("could not find parameter " << EnumToStringx(enum_type));
208
209}
210/*}}}*/
211/*FUNCTION Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM, int* pN,int enum_type){{{*/
212void Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM, int* pN,int enum_type){ _assert_(this);
213
214 vector<Object*>::iterator object;
215 Param* param=NULL;
216
217 for ( object=objects.begin() ; object < objects.end(); object++ ){
218
219 param=dynamic_cast<Param*>(*object);
220 if(param->InstanceEnum()==enum_type){
221 param->GetParameterValue(pIssmDoublearray,pM,pN);
222 return;
223 }
224 }
225 _error_("could not find parameter " << EnumToStringx(enum_type));
226
227}
228/*}}}*/
229/*FUNCTION Parameters::FindParam(IssmDouble*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){{{*/
230void Parameters::FindParam(IssmDouble*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){ _assert_(this);
231
232 vector<Object*>::iterator object;
233 Param* param=NULL;
234
235 for ( object=objects.begin() ; object < objects.end(); object++ ){
236
237 param=dynamic_cast<Param*>(*object);
238 if(param->InstanceEnum()==enum_type){
239 param->GetParameterValue(parray,pM,pmdims_array,pndims_array);
240 return;
241 }
242 }
243 _error_("could not find parameter " << EnumToStringx(enum_type));
244}
245/*}}}*/
246/*FUNCTION Parameters::FindParam(Vector<IssmDouble>** pvec,int enum_type){{{*/
247void Parameters::FindParam(Vector<IssmDouble>** pvec,int enum_type){ _assert_(this);
248
249 vector<Object*>::iterator object;
250 Param* param=NULL;
251
252 for ( object=objects.begin() ; object < objects.end(); object++ ){
253
254 param=dynamic_cast<Param*>(*object);
255 if(param->InstanceEnum()==enum_type){
256 param->GetParameterValue(pvec);
257 return;
258 }
259 }
260 _error_("could not find parameter " << EnumToStringx(enum_type));
261
262}
263/*}}}*/
264/*FUNCTION Parameters::FindParam(Matrix<IssmDouble>** pmat,int enum_type){{{*/
265void Parameters::FindParam(Matrix<IssmDouble>** pmat,int enum_type){ _assert_(this);
266
267 vector<Object*>::iterator object;
268 Param* param=NULL;
269
270 for ( object=objects.begin() ; object < objects.end(); object++ ){
271
272 param=dynamic_cast<Param*>(*object);
273 if(param->InstanceEnum()==enum_type){
274 param->GetParameterValue(pmat);
275 return;
276 }
277 }
278 _error_("could not find parameter " << EnumToStringx(enum_type));
279
280}
281/*}}}*/
282/*FUNCTION Parameters::FindParam(FILE** pfid,int enum_type){{{*/
283void Parameters::FindParam(FILE** pfid,int enum_type){ _assert_(this);
284
285 vector<Object*>::iterator object;
286 Param* param=NULL;
287
288 for ( object=objects.begin() ; object < objects.end(); object++ ){
289
290 param=dynamic_cast<Param*>(*object);
291 if(param->InstanceEnum()==enum_type){
292 param->GetParameterValue(pfid);
293 return;
294 }
295 }
296 _error_("could not find parameter " << EnumToStringx(enum_type));
297}
298/*}}}*/
299/*FUNCTION Parameters::FindParam(DataSet** pdataset,int enum_type){{{*/
300void Parameters::FindParam(DataSet** pdataset,int enum_type){
301 _assert_(this);
302
303 vector<Object*>::iterator object;
304 Param* param=NULL;
305
306 for ( object=objects.begin() ; object < objects.end(); object++ ){
307
308 param=dynamic_cast<Param*>(*object);
309 if(param->InstanceEnum()==enum_type){
310 param->GetParameterValue(pdataset);
311 return;
312 }
313 }
314 _error_("could not find parameter " << EnumToStringx(enum_type));
315}
316/*}}}*/
317
318/*FUNCTION Parameters::SetParam(bool boolean,int enum_type);{{{*/
319void Parameters::SetParam(bool boolean,int enum_type){
320
321 Param* param=NULL;
322
323 /*first, figure out if the param has already been created: */
324 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
325
326 if(param) param->SetValue(boolean); //already exists, just set it.
327 else this->AddObject(new BoolParam(enum_type,boolean)); //just add the new parameter.
328}
329/*}}}*/
330/*FUNCTION Parameters::SetParam(int integer,int enum_type);{{{*/
331void Parameters::SetParam(int integer,int enum_type){
332
333 Param* param=NULL;
334
335 /*first, figure out if the param has already been created: */
336 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
337
338 if(param) param->SetValue(integer); //already exists, just set it.
339 else this->AddObject(new IntParam(enum_type,integer)); //just add the new parameter.
340}
341/*}}}*/
342/*FUNCTION Parameters::SetParam(IssmDouble scalar,int enum_type);{{{*/
343void Parameters::SetParam(IssmDouble scalar,int enum_type){
344
345 Param* param=NULL;
346
347 /*first, figure out if the param has already been created: */
348 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
349
350 if(param) param->SetValue(scalar); //already exists, just set it.
351 else this->AddObject(new DoubleParam(enum_type,scalar)); //just add the new parameter.
352}
353/*}}}*/
354/*FUNCTION Parameters::SetParam(char* string,int enum_type);{{{*/
355void Parameters::SetParam(char* string,int enum_type){
356
357 Param* param=NULL;
358
359 /*first, figure out if the param has already been created: */
360 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
361
362 if(param) param->SetValue(string); //already exists, just set it.
363 else this->AddObject(new StringParam(enum_type,string)); //just add the new parameter.
364}
365/*}}}*/
366/*FUNCTION Parameters::SetParam(char** stringarray,int M, int enum_type);{{{*/
367void Parameters::SetParam(char** stringarray,int M, int enum_type){
368
369 Param* param=NULL;
370
371 /*first, figure out if the param has already been created: */
372 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
373
374 if(param) param->SetValue(stringarray,M); //already exists, just set it.
375 else this->AddObject(new StringArrayParam(enum_type,stringarray,M)); //just add the new parameter.
376}
377/*}}}*/
378/*FUNCTION Parameters::SetParam(IssmDouble* IssmDoublearray,int M,int enum_type);{{{*/
379void Parameters::SetParam(IssmDouble* IssmDoublearray,int M, int enum_type){
380
381 Param* param=NULL;
382
383 /*first, figure out if the param has already been created: */
384 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
385
386 if(param) param->SetValue(IssmDoublearray,M); //already exists, just set it.
387 else this->AddObject(new DoubleVecParam(enum_type,IssmDoublearray,M)); //just add the new parameter.
388}
389/*}}}*/
390/*FUNCTION Parameters::SetParam(IssmDouble* IssmDoublearray,int M,int N, int enum_type);{{{*/
391void Parameters::SetParam(IssmDouble* IssmDoublearray,int M, int N, int enum_type){
392
393 Param* param=NULL;
394
395 /*first, figure out if the param has already been created: */
396 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
397
398 if(param) param->SetValue(IssmDoublearray,M,N); //already exists, just set it.
399 else this->AddObject(new DoubleMatParam(enum_type,IssmDoublearray,M,N)); //just add the new parameter.
400}
401/*}}}*/
402/*FUNCTION Parameters::SetParam(int* intarray,int M,int enum_type);{{{*/
403void Parameters::SetParam(int* intarray,int M, int enum_type){
404
405 Param* param=NULL;
406
407 /*first, figure out if the param has already been created: */
408 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
409
410 if(param) param->SetValue(intarray,M); //already exists, just set it.
411 else this->AddObject(new IntVecParam(enum_type,intarray,M)); //just add the new parameter.
412}
413/*}}}*/
414/*FUNCTION Parameters::SetParam(int* intarray,int M,int N, int enum_type);{{{*/
415void Parameters::SetParam(int* intarray,int M, int N, int enum_type){
416
417 Param* param=NULL;
418
419 /*first, figure out if the param has already been created: */
420 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
421
422 if(param) param->SetValue(intarray,M,N); //already exists, just set it.
423 else this->AddObject(new IntMatParam(enum_type,intarray,M,N)); //just add the new parameter.
424}
425/*}}}*/
426/*FUNCTION Parameters::SetParam(Vector<IssmDouble>* vector,int enum_type);{{{*/
427void Parameters::SetParam(Vector<IssmDouble>* vector,int enum_type){
428
429 Param* param=NULL;
430
431 /*first, figure out if the param has already been created: */
432 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
433
434 if(param) param->SetValue(vector); //already exists, just set it.
435 else this->AddObject(new VectorParam(enum_type,vector)); //just add the new parameter.
436}
437/*}}}*/
438/*FUNCTION Parameters::SetParam(Matrix<IssmDouble>* matrix,int enum_type);{{{*/
439void Parameters::SetParam(Matrix<IssmDouble>* matrix,int enum_type){
440
441 Param* param=NULL;
442
443 /*first, figure out if the param has already been created: */
444 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
445
446 if(param) param->SetValue(matrix); //already exists, just set it.
447 else this->AddObject(new MatrixParam(enum_type,matrix)); //just add the new parameter.
448}
449/*}}}*/
450/*FUNCTION Parameters::SetParam(FILE* fid,int enum_type);{{{*/
451void Parameters::SetParam(FILE* fid,int enum_type){
452
453 Param* param=NULL;
454
455 /*first, figure out if the param has already been created: */
456 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
457
458 if(param) param->SetValue(fid); //already exists, just set it.
459 else this->AddObject(new FileParam(enum_type,fid)); //just add the new parameter.
460}
461/*}}}*/
462/*FUNCTION Parameters::UnitConversion(int direction_enum);{{{*/
463void Parameters::UnitConversion(int direction_enum){
464
465 vector<Object*>::iterator object;
466 Param* param=NULL;
467
468 for ( object=objects.begin() ; object < objects.end(); object++ ){
469 param=dynamic_cast<Param*>(*object);
470 param->UnitConversion(direction_enum);
471 }
472
473}
474/*}}}*/
475
476/*FUNCTION Parameters::FindParamObject{{{*/
477Object* Parameters::FindParamObject(int enum_type){
478
479 vector<Object*>::iterator object;
480 Param* param=NULL;
481
482 for ( object=objects.begin() ; object < objects.end(); object++ ){
483
484 param=dynamic_cast<Param*>(*object);
485 if(param->InstanceEnum()==enum_type){
486 return (*object);
487 }
488 }
489 return NULL;
490}
491/*}}}*/
Note: See TracBrowser for help on using the repository browser.