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
RevLine 
[3702]1/*
2 * \file Parameters.c
3 * \brief: implementation of the Parameters class, derived from DataSet class
4 */
5
[12706]6/*Headers: {{{*/
[3702]7#ifdef HAVE_CONFIG_H
[9320]8 #include <config.h>
[3702]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"
[3775]20#include "../include/include.h"
[3702]21#include "../EnumDefinitions/EnumDefinitions.h"
22
23using namespace std;
24/*}}}*/
25
26/*Object constructors and destructor*/
[12706]27/*FUNCTION Parameters::Parameters(){{{*/
[3702]28Parameters::Parameters(){
[10522]29 enum_type=ParametersEnum;
[3702]30 return;
31}
32/*}}}*/
[12706]33/*FUNCTION Parameters::~Parameters(){{{*/
[3702]34Parameters::~Parameters(){
35 return;
36}
37/*}}}*/
38
39/*Object management*/
[12706]40/*FUNCTION Parameters::Exist{{{*/
[8263]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++ ){
[13975]47 param=dynamic_cast<Param*>(*object);
[9883]48 if(param->InstanceEnum()==enum_type) return true;
[8263]49 }
50 return false;
51}
52/*}}}*/
[12706]53/*FUNCTION Parameters::FindParam(bool* pbool,int enum_type){{{*/
[8376]54void Parameters::FindParam(bool* pbool,int enum_type){ _assert_(this);
[13975]55
[3702]56 vector<Object*>::iterator object;
57 Param* param=NULL;
58
59 for ( object=objects.begin() ; object < objects.end(); object++ ){
60
[13975]61 param=dynamic_cast<Param*>(*object);
[9883]62 if(param->InstanceEnum()==enum_type){
[3766]63 param->GetParameterValue(pbool);
[8263]64 return;
[3702]65 }
66 }
[13395]67 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]68}
69/*}}}*/
[12706]70/*FUNCTION Parameters::FindParam(int* pinteger,int enum_type){{{*/
[8376]71void Parameters::FindParam(int* pinteger,int enum_type){ _assert_(this);
[13975]72
[3702]73 vector<Object*>::iterator object;
74 Param* param=NULL;
75
76 for ( object=objects.begin() ; object < objects.end(); object++ ){
77
[13975]78 param=dynamic_cast<Param*>(*object);
[9883]79 if(param->InstanceEnum()==enum_type){
[3766]80 param->GetParameterValue(pinteger);
[8263]81 return;
[3702]82 }
83 }
[13395]84 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]85}
86/*}}}*/
[12706]87/*FUNCTION Parameters::FindParam(IssmDouble* pscalar, int enum_type){{{*/
88void Parameters::FindParam(IssmDouble* pscalar, int enum_type){ _assert_(this);
[13975]89
[3732]90 vector<Object*>::iterator object;
91 Param* param=NULL;
92
93 for ( object=objects.begin() ; object < objects.end(); object++ ){
94
[13975]95 param=dynamic_cast<Param*>(*object);
[9883]96 if(param->InstanceEnum()==enum_type){
[3766]97 param->GetParameterValue(pscalar);
[8263]98 return;
[3732]99 }
100 }
[13395]101 _error_("could not find parameter " << EnumToStringx(enum_type));
[3732]102}
103/*}}}*/
[13395]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
[13975]112 param=dynamic_cast<Param*>(*object);
[13395]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/*}}}*/
[12706]121/*FUNCTION Parameters::FindParam(char** pstring,int enum_type){{{*/
[8376]122void Parameters::FindParam(char** pstring,int enum_type){ _assert_(this);
[13975]123
[3702]124 vector<Object*>::iterator object;
125 Param* param=NULL;
126
127 for ( object=objects.begin() ; object < objects.end(); object++ ){
128
[13975]129 param=dynamic_cast<Param*>(*object);
[9883]130 if(param->InstanceEnum()==enum_type){
[3766]131 param->GetParameterValue(pstring);
[8263]132 return;
[3702]133 }
134 }
[13395]135 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]136
137}
138/*}}}*/
[12706]139/*FUNCTION Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){{{*/
[8376]140void Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){ _assert_(this);
[13975]141
[3702]142 vector<Object*>::iterator object;
143 Param* param=NULL;
144
145 for ( object=objects.begin() ; object < objects.end(); object++ ){
146
[13975]147 param=dynamic_cast<Param*>(*object);
[9883]148 if(param->InstanceEnum()==enum_type){
[3766]149 param->GetParameterValue(pstringarray,pM);
[8263]150 return;
[3702]151 }
152 }
[13395]153 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]154
155}
156/*}}}*/
[12706]157/*FUNCTION Parameters::FindParam(int** pintarray,int* pM,int enum_type){{{*/
[8376]158void Parameters::FindParam(int** pintarray,int* pM, int enum_type){ _assert_(this);
[6213]159
160 vector<Object*>::iterator object;
161 Param* param=NULL;
162
163 for ( object=objects.begin() ; object < objects.end(); object++ ){
164
[13975]165 param=dynamic_cast<Param*>(*object);
[9883]166 if(param->InstanceEnum()==enum_type){
[6213]167 param->GetParameterValue(pintarray,pM);
[8263]168 return;
[6213]169 }
170 }
[13395]171 _error_("could not find parameter " << EnumToStringx(enum_type));
[6213]172
173}
174/*}}}*/
[12706]175/*FUNCTION Parameters::FindParam(int** pintarray,int* pM,int* pN,int enum_type){{{*/
[8600]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
[13975]183 param=dynamic_cast<Param*>(*object);
[9883]184 if(param->InstanceEnum()==enum_type){
[8600]185 param->GetParameterValue(pintarray,pM,pN);
186 return;
187 }
188 }
[13395]189 _error_("could not find parameter " << EnumToStringx(enum_type));
[8600]190
191}
192/*}}}*/
[12706]193/*FUNCTION Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM,int enum_type){{{*/
194void Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM, int enum_type){ _assert_(this);
[8263]195
[3702]196 vector<Object*>::iterator object;
197 Param* param=NULL;
198
199 for ( object=objects.begin() ; object < objects.end(); object++ ){
200
[13975]201 param=dynamic_cast<Param*>(*object);
[9883]202 if(param->InstanceEnum()==enum_type){
[12706]203 param->GetParameterValue(pIssmDoublearray,pM);
[8263]204 return;
[3702]205 }
206 }
[13395]207 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]208
209}
210/*}}}*/
[12706]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);
[8263]213
[3702]214 vector<Object*>::iterator object;
215 Param* param=NULL;
216
217 for ( object=objects.begin() ; object < objects.end(); object++ ){
218
[13975]219 param=dynamic_cast<Param*>(*object);
[9883]220 if(param->InstanceEnum()==enum_type){
[12706]221 param->GetParameterValue(pIssmDoublearray,pM,pN);
[8263]222 return;
[3702]223 }
224 }
[13395]225 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]226
227}
228/*}}}*/
[12706]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);
[13975]231
[4855]232 vector<Object*>::iterator object;
233 Param* param=NULL;
234
235 for ( object=objects.begin() ; object < objects.end(); object++ ){
236
[13975]237 param=dynamic_cast<Param*>(*object);
[9883]238 if(param->InstanceEnum()==enum_type){
[4855]239 param->GetParameterValue(parray,pM,pmdims_array,pndims_array);
[8263]240 return;
[4855]241 }
242 }
[13395]243 _error_("could not find parameter " << EnumToStringx(enum_type));
[4855]244}
245/*}}}*/
[13395]246/*FUNCTION Parameters::FindParam(Vector<IssmDouble>** pvec,int enum_type){{{*/
247void Parameters::FindParam(Vector<IssmDouble>** pvec,int enum_type){ _assert_(this);
[13975]248
[3702]249 vector<Object*>::iterator object;
250 Param* param=NULL;
251
252 for ( object=objects.begin() ; object < objects.end(); object++ ){
253
[13975]254 param=dynamic_cast<Param*>(*object);
[9883]255 if(param->InstanceEnum()==enum_type){
[3766]256 param->GetParameterValue(pvec);
[8263]257 return;
[3702]258 }
259 }
[13395]260 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]261
262}
263/*}}}*/
[13395]264/*FUNCTION Parameters::FindParam(Matrix<IssmDouble>** pmat,int enum_type){{{*/
265void Parameters::FindParam(Matrix<IssmDouble>** pmat,int enum_type){ _assert_(this);
[13975]266
[3702]267 vector<Object*>::iterator object;
268 Param* param=NULL;
269
270 for ( object=objects.begin() ; object < objects.end(); object++ ){
271
[13975]272 param=dynamic_cast<Param*>(*object);
[9883]273 if(param->InstanceEnum()==enum_type){
[3766]274 param->GetParameterValue(pmat);
[8263]275 return;
[3702]276 }
277 }
[13395]278 _error_("could not find parameter " << EnumToStringx(enum_type));
[3702]279
280}
281/*}}}*/
[12706]282/*FUNCTION Parameters::FindParam(FILE** pfid,int enum_type){{{*/
[8376]283void Parameters::FindParam(FILE** pfid,int enum_type){ _assert_(this);
[4059]284
[4873]285 vector<Object*>::iterator object;
286 Param* param=NULL;
287
288 for ( object=objects.begin() ; object < objects.end(); object++ ){
289
[13975]290 param=dynamic_cast<Param*>(*object);
[9883]291 if(param->InstanceEnum()==enum_type){
[4873]292 param->GetParameterValue(pfid);
[8263]293 return;
[4873]294 }
295 }
[13395]296 _error_("could not find parameter " << EnumToStringx(enum_type));
[4873]297}
298/*}}}*/
[13975]299/*FUNCTION Parameters::FindParam(DataSet** pdataset,int enum_type){{{*/
300void Parameters::FindParam(DataSet** pdataset,int enum_type){
301 _assert_(this);
[4873]302
[13975]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
[12706]318/*FUNCTION Parameters::SetParam(bool boolean,int enum_type);{{{*/
[4059]319void Parameters::SetParam(bool boolean,int enum_type){
320
321 Param* param=NULL;
[13975]322
[4059]323 /*first, figure out if the param has already been created: */
[13975]324 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]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/*}}}*/
[12706]330/*FUNCTION Parameters::SetParam(int integer,int enum_type);{{{*/
[4059]331void Parameters::SetParam(int integer,int enum_type){
332
333 Param* param=NULL;
[13975]334
[4059]335 /*first, figure out if the param has already been created: */
[13975]336 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]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/*}}}*/
[12706]342/*FUNCTION Parameters::SetParam(IssmDouble scalar,int enum_type);{{{*/
343void Parameters::SetParam(IssmDouble scalar,int enum_type){
[4059]344
345 Param* param=NULL;
[13975]346
[4059]347 /*first, figure out if the param has already been created: */
[13975]348 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]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/*}}}*/
[12706]354/*FUNCTION Parameters::SetParam(char* string,int enum_type);{{{*/
[4059]355void Parameters::SetParam(char* string,int enum_type){
356
357 Param* param=NULL;
[13975]358
[4059]359 /*first, figure out if the param has already been created: */
[13975]360 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]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/*}}}*/
[12706]366/*FUNCTION Parameters::SetParam(char** stringarray,int M, int enum_type);{{{*/
[4059]367void Parameters::SetParam(char** stringarray,int M, int enum_type){
368
369 Param* param=NULL;
[13975]370
[4059]371 /*first, figure out if the param has already been created: */
[13975]372 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]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/*}}}*/
[12706]378/*FUNCTION Parameters::SetParam(IssmDouble* IssmDoublearray,int M,int enum_type);{{{*/
379void Parameters::SetParam(IssmDouble* IssmDoublearray,int M, int enum_type){
[4059]380
381 Param* param=NULL;
[13975]382
[4059]383 /*first, figure out if the param has already been created: */
[13975]384 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]385
[12706]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.
[4059]388}
389/*}}}*/
[12706]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){
[4059]392
393 Param* param=NULL;
[13975]394
[4059]395 /*first, figure out if the param has already been created: */
[13975]396 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]397
[12706]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.
[4059]400}
401/*}}}*/
[12706]402/*FUNCTION Parameters::SetParam(int* intarray,int M,int enum_type);{{{*/
[8600]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: */
[13975]408 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[8600]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/*}}}*/
[12706]414/*FUNCTION Parameters::SetParam(int* intarray,int M,int N, int enum_type);{{{*/
[8600]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: */
[13975]420 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[8600]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/*}}}*/
[13395]426/*FUNCTION Parameters::SetParam(Vector<IssmDouble>* vector,int enum_type);{{{*/
427void Parameters::SetParam(Vector<IssmDouble>* vector,int enum_type){
[4059]428
429 Param* param=NULL;
[13975]430
[4059]431 /*first, figure out if the param has already been created: */
[13975]432 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]433
434 if(param) param->SetValue(vector); //already exists, just set it.
[11995]435 else this->AddObject(new VectorParam(enum_type,vector)); //just add the new parameter.
[4059]436}
437/*}}}*/
[13395]438/*FUNCTION Parameters::SetParam(Matrix<IssmDouble>* matrix,int enum_type);{{{*/
439void Parameters::SetParam(Matrix<IssmDouble>* matrix,int enum_type){
[4059]440
441 Param* param=NULL;
[13975]442
[4059]443 /*first, figure out if the param has already been created: */
[13975]444 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4059]445
446 if(param) param->SetValue(matrix); //already exists, just set it.
[11995]447 else this->AddObject(new MatrixParam(enum_type,matrix)); //just add the new parameter.
[4059]448}
449/*}}}*/
[12706]450/*FUNCTION Parameters::SetParam(FILE* fid,int enum_type);{{{*/
[4873]451void Parameters::SetParam(FILE* fid,int enum_type){
[4059]452
[4873]453 Param* param=NULL;
454
455 /*first, figure out if the param has already been created: */
[13975]456 param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
[4873]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/*}}}*/
[12706]462/*FUNCTION Parameters::UnitConversion(int direction_enum);{{{*/
[9356]463void Parameters::UnitConversion(int direction_enum){
[4873]464
[9356]465 vector<Object*>::iterator object;
466 Param* param=NULL;
467
468 for ( object=objects.begin() ; object < objects.end(); object++ ){
[13975]469 param=dynamic_cast<Param*>(*object);
[9356]470 param->UnitConversion(direction_enum);
471 }
472
473}
474/*}}}*/
475
[12706]476/*FUNCTION Parameters::FindParamObject{{{*/
[3702]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
[13975]484 param=dynamic_cast<Param*>(*object);
[9883]485 if(param->InstanceEnum()==enum_type){
[3766]486 return (*object);
[3702]487 }
488 }
489 return NULL;
490}
491/*}}}*/
Note: See TracBrowser for help on using the repository browser.