Changeset 22521
- Timestamp:
- 03/11/18 09:46:49 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/Inputs/Inputs.cpp
r22519 r22521 31 31 int Inputs::AddInput(Input* in_input){/*{{{*/ 32 32 33 /*First, go through dataset of inputs and check whether any input 34 * with the same name is already in. If so, erase the corresponding 35 * object before adding this new one: */ 36 vector<Object*>::iterator object; 37 Input* input=NULL; 38 39 /*In debugging mode, check that the input is not a NULL pointer*/ 40 _assert_(in_input); 41 42 for ( object=objects.begin() ; object < objects.end(); object++ ){ 43 44 input=xDynamicCast<Input*>(*object); 45 46 if (input->InstanceEnum()==in_input->InstanceEnum()){ 47 this->DeleteObject(input); 48 break; 49 } 50 } 33 _assert_(in_input); 34 35 /*Delete input if it already exists*/ 36 this->DeleteInput(in_input->InstanceEnum()); 37 38 /*Now add new input to the dataset*/ 51 39 this->AddObject(in_input); 52 40 … … 56 44 void Inputs::ChangeEnum(int oldenumtype,int newenumtype){/*{{{*/ 57 45 58 /*Go through dataset of inputs and look for input with 59 * same enum as input enum, once found, just change its name */ 60 vector<Object*>::iterator object; 61 Input* input=NULL; 62 63 /*Delete existing input of newenumtype if it exists*/ 64 for ( object=objects.begin() ; object < objects.end(); object++ ){ 65 input=xDynamicCast<Input*>(*object); 66 67 if (input->InstanceEnum()==newenumtype){ 68 this->DeleteObject(input); 69 break; 70 } 71 } 72 73 /*Change enum_type of input of oldenumtype*/ 74 for ( object=objects.begin() ; object < objects.end(); object++ ){ 75 76 input=xDynamicCast<Input*>(*object); 77 78 if (input->InstanceEnum()==oldenumtype){ 79 input->ChangeEnum(newenumtype); 80 break; 81 } 82 } 83 } 84 /*}}}*/ 46 /*Delete input if it already exists*/ 47 this->DeleteInput(newenumtype); 48 49 /*Now get old input and change its enum (do not error out if not found)*/ 50 Input* input=this->GetInput(oldenumtype); 51 if(input) input->ChangeEnum(newenumtype); 52 }/*}}}*/ 85 53 void Inputs::Configure(Parameters* parameters){/*{{{*/ 86 54 … … 99 67 int Inputs::DeleteInput(int enum_type){/*{{{*/ 100 68 101 vector<Object*>::iterator object; 102 Input* input=NULL; 103 104 for ( object=objects.begin() ; object < objects.end(); object++ ){ 105 106 input=xDynamicCast<Input*>(*object); 107 108 if (input->InstanceEnum()==enum_type){ 109 this->DeleteObject(input); 110 break; 111 } 112 } 113 69 Input* input=this->GetInput(enum_type); 70 if(input) this->DeleteObject(input); 114 71 return 1; 115 72 … … 119 76 120 77 /*Make a copy of the original input: */ 121 Input* original= xDynamicCast<Input*>(this->GetInput(original_enum));78 Input* original=this->GetInput(original_enum); 122 79 if(!original)_error_("could not find input with enum: " << EnumToStringx(original_enum)); 123 80 Input* copy=xDynamicCast<Input*>(original->copy()); … … 136 93 137 94 for ( object=objects.begin() ; object < objects.end(); object++ ){ 138 139 95 input=xDynamicCast<Input*>(*object); 140 141 if (input->InstanceEnum()==enum_name){ 142 return input; 143 } 144 } 96 if (input->InstanceEnum()==enum_name) return input; 97 } 98 145 99 return NULL; 146 100 } … … 148 102 void Inputs::GetInputAverage(IssmDouble* pvalue,int enum_type){/*{{{*/ 149 103 150 vector<Object*>::iterator object; 151 Input* input=NULL; 152 bool found=false; 153 154 /*Go through inputs and check whether any input with the same name is already in: */ 155 for ( object=objects.begin() ; object < objects.end(); object++ ){ 156 157 input=xDynamicCast<Input*>(*object); 158 if (input->InstanceEnum()==enum_type){ 159 found=true; 160 break; 161 } 162 } 163 164 if (!found){ 165 /*we could not find an input with the correct enum type. No defaults values were provided, 166 * error out: */ 167 _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 168 } 104 /*Find input in current dataset*/ 105 Input* input=this->GetInput(enum_type); 106 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 169 107 170 108 /*Ok, we have an input if we made it here, request the input to return the value: */ … … 175 113 void Inputs::GetInputValue(bool* pvalue,int enum_type){/*{{{*/ 176 114 177 vector<Object*>::iterator object; 178 Input* input=NULL; 179 bool found=false; 180 181 /*Go through inputs and check whether any input with the same name is already in: */ 182 for ( object=objects.begin() ; object < objects.end(); object++ ){ 183 184 input=xDynamicCast<Input*>(*object); 185 if (input->InstanceEnum()==enum_type){ 186 found=true; 187 break; 188 } 189 } 190 191 if (!found){ 192 /*we could not find an input with the correct enum type. No defaults values were provided, 193 * error out: */ 194 _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 195 } 115 /*Find input in current dataset*/ 116 Input* input=this->GetInput(enum_type); 117 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 196 118 197 119 /*Ok, we have an input if we made it here, request the input to return the value: */ … … 202 124 void Inputs::GetInputValue(int* pvalue,int enum_type){/*{{{*/ 203 125 204 vector<Object*>::iterator object; 205 Input* input=NULL; 206 bool found=false; 207 208 /*Go through inputs and check whether any input with the same name is already in: */ 209 for ( object=objects.begin() ; object < objects.end(); object++ ){ 210 211 input=xDynamicCast<Input*>(*object); 212 if (input->InstanceEnum()==enum_type){ 213 found=true; 214 break; 215 } 216 } 217 218 if (!found){ 219 /*we could not find an input with the correct enum type. No defaults values were provided, 220 * error out: */ 221 _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 222 } 126 /*Find input in current dataset*/ 127 Input* input=this->GetInput(enum_type); 128 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 223 129 224 130 /*Ok, we have an input if we made it here, request the input to return the value: */ 225 131 input->GetInputValue(pvalue); 226 132 227 } 228 /*}}}*/ 133 }/*}}}*/ 229 134 void Inputs::GetInputValue(IssmDouble* pvalue,int enum_type){/*{{{*/ 230 135 231 vector<Object*>::iterator object; 232 Input* input=NULL; 233 bool found=false; 234 235 /*Go through inputs and check whether any input with the same name is already in: */ 236 for ( object=objects.begin() ; object < objects.end(); object++ ){ 237 238 input=xDynamicCast<Input*>(*object); 239 if (input->InstanceEnum()==enum_type){ 240 found=true; 241 break; 242 } 243 } 244 245 if (!found){ 246 /*we could not find an input with the correct enum type. No defaults values were provided, 247 * error out: */ 248 _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 249 } 136 /*Find input in current dataset*/ 137 Input* input=this->GetInput(enum_type); 138 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 250 139 251 140 /*Ok, we have an input if we made it here, request the input to return the value: */ 252 141 input->GetInputValue(pvalue); 253 142 254 } 255 /*}}}*/ 143 }/*}}}*/ 256 144 IssmDouble Inputs::Max(int enumtype){/*{{{*/ 257 145 258 /*Output*/ 259 IssmDouble max; 260 261 /*Get input*/ 262 Input* input=xDynamicCast<Input*>(this->GetInput(enumtype)); 263 264 /*Apply ContrainMin: */ 265 if (input){ 266 max=input->Max(); 267 } 268 else{ 269 _error_("Input " << EnumToStringx(enumtype) << " not found"); 270 } 271 272 /*Return output*/ 273 return max; 274 } 275 /*}}}*/ 146 /*Find input in current dataset*/ 147 Input* input=this->GetInput(enumtype); 148 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 149 150 /*Return output*/ 151 return input->Max(); 152 153 }/*}}}*/ 276 154 IssmDouble Inputs::MaxAbs(int enumtype){/*{{{*/ 277 155 278 /*Output*/ 279 IssmDouble max; 280 281 /*Get input*/ 282 Input* input=xDynamicCast<Input*>(this->GetInput(enumtype)); 283 284 /*Apply ContrainMin: */ 285 if (input){ 286 max=input->MaxAbs(); 287 } 288 else{ 289 _error_("Input " << EnumToStringx(enumtype) << " not found"); 290 } 291 292 /*Return output*/ 293 return max; 294 } 295 /*}}}*/ 156 /*Find input in current dataset*/ 157 Input* input=this->GetInput(enumtype); 158 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 159 160 /*Return output*/ 161 return input->MaxAbs(); 162 163 }/*}}}*/ 296 164 IssmDouble Inputs::Min(int enumtype){/*{{{*/ 297 165 298 /*Output*/ 299 IssmDouble min; 300 301 /*Get input*/ 302 Input* input=xDynamicCast<Input*>(this->GetInput(enumtype)); 303 304 /*Apply ContrainMin: */ 305 if (input){ 306 min=input->Min(); 307 } 308 else{ 309 _error_("Input " << EnumToStringx(enumtype) << " not found"); 310 } 311 312 /*Return output*/ 313 return min; 314 } 315 /*}}}*/ 166 /*Find input in current dataset*/ 167 Input* input=this->GetInput(enumtype); 168 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 169 170 /*Return output*/ 171 return input->Min(); 172 173 }/*}}}*/ 316 174 IssmDouble Inputs::MinAbs(int enumtype){/*{{{*/ 317 175 318 /*Output*/ 319 IssmDouble min; 320 321 /*Get input*/ 322 Input* input=xDynamicCast<Input*>(this->GetInput(enumtype)); 323 324 /*Apply ContrainMin: */ 325 if (input){ 326 min=input->MinAbs(); 327 } 328 else{ 329 _error_("Input " << EnumToStringx(enumtype) << " not found"); 330 } 331 332 /*Return output*/ 333 return min; 334 } 335 /*}}}*/ 176 /*Find input in current dataset*/ 177 Input* input=this->GetInput(enumtype); 178 if (!input) _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")"); 179 180 /*Return output*/ 181 return input->MinAbs(); 182 183 }/*}}}*/ 336 184 Inputs* Inputs::SpawnSegInputs(int index1,int index2){/*{{{*/ 337 185
Note:
See TracChangeset
for help on using the changeset viewer.