Changeset 562 for XIOS/branchs
- Timestamp:
- 02/24/15 09:50:14 (10 years ago)
- Location:
- XIOS/branchs/xios-1.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/branchs/xios-1.0/inputs/COMPLETE/context_surface.xml
r529 r562 1 1 <!-- Context surface --> 2 2 3 3 <context id="surface" calendar_type="Julian" start_date="2012-03-01 15:00:00" time_origin="2012-02-29 15:00:00"> 4 4 5 5 <field_definition level="1" enabled=".TRUE." domain_ref="domain_srf" axis_ref="axis_srf" operation="average" freq_op="1ts" default_value="9.96921e+36" prec="4"> 6 6 <field id="field_A_srf" name="field_A_srf" long_name="Champ en degC" operation="average" unit="degC" /> 7 <field id="field_A_srf_2" field_ref="field_A_srf" /> 7 8 <field id="field_A_srf_K" name="field_A_srf_K" field_ref="field_A_srf" long_name="Champ en degK" unit="degK"> field_A_srf + 273.15 </field> 9 <field id="field_A_srf_K_2" field_ref="field_A_srf_K" /> 8 10 <field id="field_A_srf_max" name="field_A_srf_max" field_ref="field_A_srf" long_name="maximum field_A_srf" operation="maximum" /> 9 <field id="field_D_srf" name="field_D_srf" long_name="Somme champ A et C" > field_A_srf + field_C_srf </field> 10 11 <field id="field_D_srf" name="field_D_srf" long_name="Somme champ A et C"> field_A_srf + field_C_srf </field> 11 12 </field_definition> 12 13 13 14 <file_definition type="multiple_file" par_access="collective" output_level="10" enabled=".TRUE."> 14 <file id="output_surface" name="output_surface_6h" output_freq="6h" > 15 <field field_ref="field_A_srf" > 16 <variable id="my_attribute1" type="string" >surf_att</variable> 17 <variable id="my_attribute2" type="integer" > 10 </variable> 18 <variable id="my_attribute3" type="float" >6.8</variable> 19 <variable id="my_attribute4" type="double" >100.201</variable> 15 <file id="output_surface" name="output_surface_6h" output_freq="6h"> 16 <field field_ref="field_A_srf"> 17 <variable id="my_attribute1" type="string">surf_att</variable> 18 <variable id="my_attribute2" type="integer"> 10 </variable> 19 <variable id="my_attribute3" type="float">6.8</variable> 20 <variable id="my_attribute4" type="double">100.201</variable> 21 </field> 22 <field field_ref="field_A_srf_K" /> 23 <field field_ref="field_A_srf_K_2" name="field_A_srf_K_2" /> <!-- Should be identical to field_A_srf_K --> 24 <field field_ref="field_A_srf_K" name="field_A_srf_K_3">field_A_srf_K</field> <!-- Should be identical to field_A_srf_K --> 25 <field field_ref="field_A_srf_K_2" name="field_A_srf_K_max_mean" long_name="Maximum of hourly average over 6h" operation="maximum" freq_op="1h"> @field_A_srf_K </field> 26 <field field_ref="field_A_srf" name="field_A_srf_min" operation="minimum" /> 27 <field field_ref="field_A_srf_2" name="field_A_srf_min_2" operation="minimum" /> <!-- Should be identical to field_A_srf_min --> 28 <field field_ref="field_A_srf" name="field_A_srf_max" operation="maximum" /> 29 <field field_ref="field_A_srf" name="field_A_srf_prec4" prec="8" /> 30 <field field_ref="field_A_srf_max" name="field_A_srf_mean_max" long_name="Average of hourly maximum over 6h" operation="average" freq_op="1h"> @field_A_srf_max </field> 31 <variable id="my_global_attribute_xml" type="string">file_6h</variable> 32 </file> 33 34 <file type="one_file" id="output_surface_1d" name="output_surface_1d" output_freq="1d"> 35 <field field_ref="field_A_srf"> 36 <variable id="my_attribute1" type="string">surf_att</variable> 37 <variable id="my_attribute2" type="integer">10</variable> 38 <variable id="my_attribute3" type="float">6.8</variable> 39 <variable id="my_attribute4" type="double">100.201</variable> 20 40 </field> 21 41 <field field_ref="field_A_srf_K" /> 22 42 <field field_ref="field_A_srf" name="field_A_srf_min" operation="minimum" /> 23 43 <field field_ref="field_A_srf" name="field_A_srf_max" operation="maximum" /> 24 <field field_ref="field_A_srf" name="field_A_srf_prec4" prec="8"/> 25 <field field_ref="field_A_srf_max" name="field_A_srf_mean_max" long_name="Average of hourly maximum over 6h" operation="average" freq_op="1h" > @field_A_srf_max </field> 26 <variable id="my_global_attribute_xml" type="string" >file_6h</variable> 27 </file> 28 29 <file type="one_file" id="output_surface_1d" name="output_surface_1d" output_freq="1d" > 30 <field field_ref="field_A_srf" > 31 <variable id="my_attribute1" type="string" >surf_att</variable> 32 <variable id="my_attribute2" type="integer" >10</variable> 33 <variable id="my_attribute3" type="float" >6.8</variable> 34 <variable id="my_attribute4" type="double" >100.201</variable> 35 </field> 36 <field field_ref="field_A_srf_K" /> 37 <field field_ref="field_A_srf" name="field_A_srf_min" operation="minimum" /> 38 <field field_ref="field_A_srf" name="field_A_srf_max" operation="maximum" /> 39 <field field_ref="field_A_srf" name="field_A_srf_prec4" prec="8"/> 40 <field field_ref="field_A_srf_max" name="field_A_srf_mean_max" long_name="Average of hourly maximum over 1d" operation="average" freq_op="1h" > @field_A_srf_max </field> 44 <field field_ref="field_A_srf" name="field_A_srf_prec4" prec="8" /> 45 <field field_ref="field_A_srf_max" name="field_A_srf_mean_max" long_name="Average of hourly maximum over 1d" operation="average" freq_op="1h"> @field_A_srf_max </field> 41 46 </file> 42 47 </file_definition> 43 44 45 <axis id="axis_srf"/>46 47 48 49 50 </domain_definition>51 48 49 <axis_definition> 50 <axis id="axis_srf" /> 51 </axis_definition> 52 53 <domain_definition> 54 <domain id="domain_srf" /> 55 </domain_definition> 56 52 57 </context> -
XIOS/branchs/xios-1.0/src/node/field.cpp
r501 r562 14 14 15 15 namespace xios{ 16 16 17 17 /// ////////////////////// Définitions ////////////////////// /// 18 18 … … 27 27 , active(false) , hasOutputFile(false),hasFieldOut(false), slotUpdateDate(NULL) 28 28 , processed(false) 29 { setVirtualVariableGroup() 30 31 CField::CField(const StdString 29 { setVirtualVariableGroup(); } 30 31 CField::CField(const StdString& id) 32 32 : CObjectTemplate<CField>(id), CFieldAttributes() 33 33 , refObject(), baseRefObject() … … 39 39 , active(false), hasOutputFile(false), hasFieldOut(false), slotUpdateDate(NULL) 40 40 , processed(false) 41 { setVirtualVariableGroup() 41 { setVirtualVariableGroup(); } 42 42 43 43 CField::~CField(void) 44 44 { 45 // this->grid.reset() ; 46 // this->file.reset() ; 47 this->foperation.reset() ; 48 if (hasExpression) delete expression ; 49 if (slotUpdateDate!=NULL) delete slotUpdateDate ; 50 51 } 52 45 // this->grid.reset(); 46 // this->file.reset(); 47 this->foperation.reset(); 48 if (hasExpression) delete expression; 49 if (slotUpdateDate != NULL) delete slotUpdateDate; 50 51 } 53 52 54 53 //---------------------------------------------------------------- 55 54 56 55 void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) 57 { 58 this->vVariableGroup = newVVariableGroup; 59 } 60 56 { 57 this->vVariableGroup = newVVariableGroup; 58 } 59 61 60 void CField::setVirtualVariableGroup(void) 62 61 { 63 62 this->setVirtualVariableGroup(CVariableGroup::create()); 64 63 } 65 64 66 65 CVariableGroup* CField::getVirtualVariableGroup(void) const 67 66 { 68 return (this->vVariableGroup); 69 } 70 71 67 return this->vVariableGroup; 68 } 69 72 70 std::vector<CVariable*> CField::getAllVariables(void) const 73 71 { 74 return (this->vVariableGroup->getAllChildren());75 } 76 77 void CField::solveDescInheritance(bool apply, const CAttributeMap 72 return this->vVariableGroup->getAllChildren(); 73 } 74 75 void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) 78 76 { 79 77 SuperClassAttribute::setAttributes(parent,apply); 80 78 this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); 81 79 } 82 //---------------------------------------------------------------- 80 83 81 //---------------------------------------------------------------- 84 82 85 83 bool CField::updateDataServer 86 (const CDate 84 (const CDate& currDate, 87 85 const std::deque< CArray<double, 1>* > storedClient) 88 86 { 89 87 const CDate opeDate = *last_operation + freq_operation; 90 const CDate writeDate = *last_Write + freq_write; 91 88 const CDate writeDate = *last_Write + freq_write; 89 92 90 if (opeDate <= currDate) 93 91 { 94 92 if (this->data.numElements() != this->grid->storeIndex[0]->numElements()) 95 93 { 96 this->data.resize(this->grid->storeIndex[0] 97 } 98 CArray<double,1> input(data.numElements()) 99 this->grid->inputFieldServer(storedClient, input); 94 this->data.resize(this->grid->storeIndex[0]->numElements()); 95 } 96 CArray<double,1> input(data.numElements()); 97 this->grid->inputFieldServer(storedClient, input); 100 98 (*this->foperation)(input); 101 99 *last_operation = currDate; … … 106 104 this->incrementNStep(); 107 105 *last_Write = writeDate; 108 return (true);109 } 110 return (false);111 } 112 106 return true; 107 } 108 return false; 109 } 110 113 111 bool CField::dispatchEvent(CEventServer& event) 114 112 { 115 116 if (SuperClass::dispatchEvent(event)) return true 113 114 if (SuperClass::dispatchEvent(event)) return true; 117 115 else 118 116 { … … 120 118 { 121 119 case EVENT_ID_UPDATE_DATA : 122 recvUpdateData(event) 123 return true 124 break 120 recvUpdateData(event); 121 return true; 122 break; 125 123 126 124 case EVENT_ID_ADD_VARIABLE : 127 recvAddVariable(event) 128 return true 129 break 130 125 recvAddVariable(event); 126 return true; 127 break; 128 131 129 case EVENT_ID_ADD_VARIABLE_GROUP : 132 recvAddVariableGroup(event) 133 return true 134 break ;135 130 recvAddVariableGroup(event); 131 return true; 132 break; 133 136 134 default : 137 ERROR("bool CField::dispatchEvent(CEventServer& event)", <<"Unknown Event");138 return false 139 } 140 } 141 } 142 135 ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); 136 return false; 137 } 138 } 139 } 140 143 141 void CField::sendUpdateData(void) 144 142 { 145 CContext* context = CContext::getCurrent() 146 CContextClient* client =context->client;147 148 CEventClient event(getType(),EVENT_ID_UPDATE_DATA) 149 150 map<int,CArray<int, 1>* >::iterator it 151 list<shared_ptr<CMessage> > list_msg 152 list< CArray<double,1>* > list_data 153 154 for (it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++)155 { 156 int rank =(*it).first;157 CArray<int,1>& index = *(it->second) 158 CArray<double,1> data_tmp(index.numElements()) 159 160 for (int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n));161 list_msg.push_back(shared_ptr<CMessage>(new CMessage)) 162 list_data.push_back(new CArray<double,1>(data_tmp)) 163 *list_msg.back() <<getId()<<*list_data.back();164 event.push(rank,grid->nbSenders[rank],*list_msg.back()) 165 } 166 client->sendEvent(event) 167 168 for (list< CArray<double,1>* >::iterator it=list_data.begin();it!=list_data.end();it++) delete *it;169 } 170 143 CContext* context = CContext::getCurrent(); 144 CContextClient* client = context->client; 145 146 CEventClient event(getType(),EVENT_ID_UPDATE_DATA); 147 148 map<int,CArray<int, 1>* >::iterator it; 149 list<shared_ptr<CMessage> > list_msg; 150 list< CArray<double,1>* > list_data; 151 152 for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) 153 { 154 int rank = (*it).first; 155 CArray<int,1>& index = *(it->second); 156 CArray<double,1> data_tmp(index.numElements()); 157 158 for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); 159 list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 160 list_data.push_back(new CArray<double,1>(data_tmp)); 161 *list_msg.back() << getId() << *list_data.back(); 162 event.push(rank,grid->nbSenders[rank],*list_msg.back()); 163 } 164 client->sendEvent(event); 165 166 for (list< CArray<double,1>* >::iterator it = list_data.begin(); it != list_data.end(); it++) delete *it; 167 } 168 171 169 void CField::recvUpdateData(CEventServer& event) 172 170 { 173 vector<int> ranks 174 vector<CBufferIn*> buffers 175 176 list<CEventServer::SSubEvent>::iterator it 177 string fieldId 178 179 for (it =event.subEvents.begin();it!=event.subEvents.end();++it)180 { 181 int rank =it->rank;182 CBufferIn* buffer =it->buffer;183 *buffer >>fieldId;184 ranks.push_back(rank) 185 buffers.push_back(buffer) 186 } 187 get(fieldId)->recvUpdateData(ranks,buffers) ;188 } 189 171 vector<int> ranks; 172 vector<CBufferIn*> buffers; 173 174 list<CEventServer::SSubEvent>::iterator it; 175 string fieldId; 176 177 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 178 { 179 int rank = it->rank; 180 CBufferIn* buffer = it->buffer; 181 *buffer >> fieldId; 182 ranks.push_back(rank); 183 buffers.push_back(buffer); 184 } 185 get(fieldId)->recvUpdateData(ranks,buffers); 186 } 187 190 188 void CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) 191 189 { 192 190 193 191 if (data_srv.empty()) 194 192 { 195 for (map<int, CArray<int, 1>* >::iterator it=grid->out_i_fromClient.begin();it!=grid->out_i_fromClient.end();it++)196 { 197 int rank =it->first;198 CArray<double,1> data_tmp(it->second->numElements()) 199 data_srv.insert( pair<int, CArray<double,1>* >(rank, new CArray<double,1>(data_tmp) ) );200 foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(*data_srv[rank])))) 201 } 202 } 203 204 CContext* context = CContext::getCurrent() 205 const CDate 193 for (map<int, CArray<int, 1>* >::iterator it = grid->out_i_fromClient.begin(); it != grid->out_i_fromClient.end(); it++) 194 { 195 int rank = it->first; 196 CArray<double,1> data_tmp(it->second->numElements()); 197 data_srv.insert( pair<int, CArray<double,1>* >(rank, new CArray<double,1>(data_tmp))); 198 foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(*data_srv[rank])))); 199 } 200 } 201 202 CContext* context = CContext::getCurrent(); 203 const CDate& currDate = context->getCalendar()->getCurrentDate(); 206 204 const CDate opeDate = *last_operation_srv + freq_operation_srv; 207 const CDate writeDate = *last_Write_srv + freq_write_srv; 208 209 210 205 const CDate writeDate = *last_Write_srv + freq_write_srv; 206 211 207 if (opeDate <= currDate) 212 208 { 213 for (int n=0;n<ranks.size();n++)214 { 215 CArray<double,1> data_tmp 216 *buffers[n] >>data_tmp;217 (*foperation_srv[ranks[n]])(data_tmp) 209 for (int n = 0; n < ranks.size(); n++) 210 { 211 CArray<double,1> data_tmp; 212 *buffers[n] >> data_tmp; 213 (*foperation_srv[ranks[n]])(data_tmp); 218 214 } 219 215 *last_operation_srv = currDate; 220 216 } 221 217 222 218 if (writeDate < (currDate + freq_operation_srv)) 223 219 { 224 for (int n=0;n<ranks.size();n++)220 for (int n = 0; n < ranks.size(); n++) 225 221 { 226 222 this->foperation_srv[ranks[n]]->final(); 227 223 } 228 224 229 225 *last_Write_srv = writeDate; 230 writeField() 231 *lastlast_Write_srv =*last_Write_srv;232 } 233 } 234 226 writeField(); 227 *lastlast_Write_srv = *last_Write_srv; 228 } 229 } 230 235 231 void CField::writeField(void) 236 232 { 237 if (! getRelFile()->allDomainEmpty)238 if (! 233 if (!getRelFile()->allDomainEmpty) 234 if (!grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 239 235 { 240 236 getRelFile()->checkFile(); … … 246 242 247 243 void CField::setRelFile(CFile* _file) 248 { 244 { 249 245 this->file = _file; 250 hasOutputFile =true ;251 } 252 253 //---------------------------------------------------------------- 254 255 StdString CField::GetName(void) { return (StdString("field")); }256 StdString CField::GetDefName(void) { return (CField::GetName()); }257 ENodeType CField::GetType(void) { return (eField); }246 hasOutputFile = true; 247 } 248 249 //---------------------------------------------------------------- 250 251 StdString CField::GetName(void) { return StdString("field"); } 252 StdString CField::GetDefName(void) { return CField::GetName(); } 253 ENodeType CField::GetType(void) { return eField; } 258 254 259 255 //---------------------------------------------------------------- 260 256 261 257 CGrid* CField::getRelGrid(void) const 262 { 263 return (this->grid);258 { 259 return this->grid; 264 260 } 265 261 … … 267 263 268 264 CFile* CField::getRelFile(void) const 269 { 270 return (this->file);271 } 272 265 { 266 return this->file; 267 } 268 273 269 StdSize CField::getNStep(void) const 274 270 { 275 return (this->nstep);276 } 277 271 return this->nstep; 272 } 273 278 274 void CField::incrementNStep(void) 279 275 { 280 276 this->nstep++; 281 277 } 282 278 283 279 void CField::resetNStep(void) 284 280 { 285 this->nstep =0;281 this->nstep = 0; 286 282 } 287 283 … … 291 287 { 292 288 if (this->field_ref.isEmpty()) 293 return (this->getBaseFieldReference());294 295 if (! 289 return this->getBaseFieldReference(); 290 291 if (!CField::has(this->field_ref.getValue())) 296 292 ERROR("CField::getDirectFieldReference(void)", 297 293 << "[ ref_name = " << this->field_ref.getValue() << "]" 298 294 << " invalid field name !"); 299 295 300 return (CField::get(this->field_ref.getValue()));296 return CField::get(this->field_ref.getValue()); 301 297 } 302 298 … … 304 300 305 301 CField* CField::getBaseFieldReference(void) const 306 { 307 return (baseRefObject);308 } 309 310 //---------------------------------------------------------------- 311 312 const std::vector<CField*>& CField::getAllReference(void) const 313 { 314 return (refObject);315 } 316 317 //---------------------------------------------------------------- 318 319 const StdString 320 { 321 return (this->getBaseFieldReference()->getId());322 } 323 324 //---------------------------------------------------------------- 325 326 const CDuration 327 { 328 return (this->freq_operation);329 } 330 331 //---------------------------------------------------------------- 332 const CDuration 333 { 334 return (this->freq_write);335 } 336 337 //---------------------------------------------------------------- 338 302 { 303 return baseRefObject; 304 } 305 306 //---------------------------------------------------------------- 307 308 const std::vector<CField*>& CField::getAllReference(void) const 309 { 310 return refObject; 311 } 312 313 //---------------------------------------------------------------- 314 315 const StdString& CField::getBaseFieldId(void) const 316 { 317 return this->getBaseFieldReference()->getId(); 318 } 319 320 //---------------------------------------------------------------- 321 322 const CDuration& CField::getFreqOperation(void) const 323 { 324 return this->freq_operation; 325 } 326 327 //---------------------------------------------------------------- 328 const CDuration& CField::getFreqWrite(void) const 329 { 330 return this->freq_write; 331 } 332 333 //---------------------------------------------------------------- 334 339 335 boost::shared_ptr<func::CFunctor> CField::getFieldOperation(void) const 340 336 { 341 return (this->foperation);337 return this->foperation; 342 338 } 343 339 … … 345 341 346 342 bool CField::hasDirectFieldReference(void) const 347 { 348 return (!this->field_ref.isEmpty());349 } 350 343 { 344 return !this->field_ref.isEmpty(); 345 } 346 351 347 bool CField::isActive(void) const 352 { 353 return (!this->refObject.empty());354 } 355 //---------------------------------------------------------------- 356 348 { 349 return !this->refObject.empty(); 350 } 351 //---------------------------------------------------------------- 352 357 353 CArray<double, 1> CField::getData(void) const 358 354 { … … 380 376 if (!processed) 381 377 { 382 processed =true;383 solveRefInheritance(true) 384 solveBaseReference() 385 solveOperation() 386 solveGridReference() 387 388 if (hasDirectFieldReference()) baseRefObject->processEnabledField() 389 buildExpression(); 390 active =true;378 processed = true; 379 solveRefInheritance(true); 380 solveBaseReference(); 381 solveOperation(); 382 solveGridReference(); 383 384 if (hasDirectFieldReference()) baseRefObject->processEnabledField(); 385 buildExpression(); 386 active = true; 391 387 } 392 388 } … … 396 392 std::set<CField *> sset; 397 393 CField* refer_sptr; 398 CField 399 394 CField* refer_ptr = this; 395 400 396 while (refer_ptr->hasDirectFieldReference()) 401 397 { … … 413 409 sset.insert(refer_ptr); 414 410 } 415 416 411 } 417 412 … … 420 415 std::set<CField *> sset; 421 416 CField* refer_sptr; 422 CField 423 417 CField* refer_ptr = this; 418 424 419 if (this->hasDirectFieldReference()) baseRefObject = getDirectFieldReference(); 425 420 else baseRefObject = CField::get(this); 426 421 427 422 while (refer_ptr->hasDirectFieldReference()) 428 423 { … … 439 434 sset.insert(refer_ptr); 440 435 } 441 442 if (hasDirectFieldReference()) baseRefObject->addReference(this) 443 } 444 436 437 if (hasDirectFieldReference()) baseRefObject->addReference(this); 438 } 439 445 440 //---------------------------------------------------------------- 446 441 … … 448 443 { 449 444 using namespace func; 450 451 if (!hasOutputFile && !hasFieldOut) return 452 453 StdString id 454 if (hasId()) id =getId();455 else if (!name.isEmpty()) id =name;456 else if (hasDirectFieldReference()) id =baseRefObject->getId();457 445 446 if (!hasOutputFile && !hasFieldOut) return; 447 448 StdString id; 449 if (hasId()) id = getId(); 450 else if (!name.isEmpty()) id = name; 451 else if (hasDirectFieldReference()) id = baseRefObject->getId(); 452 458 453 CContext* context = CContext::getCurrent(); 459 460 if (freq_op.isEmpty()) freq_op =string("1ts");461 462 if (operation.isEmpty() 454 455 if (freq_op.isEmpty()) freq_op = string("1ts"); 456 457 if (operation.isEmpty()) 463 458 { 464 459 ERROR("CField::solveOperation(void)", … … 466 461 << "Impossible to define an operation for this field !"); 467 462 } 468 463 469 464 CDuration freq_offset_ = NoneDu; 470 465 if (!freq_offset.isEmpty()) … … 475 470 { 476 471 freq_offset.setValue(NoneDu.toString()); 477 } 472 } 478 473 479 474 // if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER) 480 475 if (context->hasServer) 481 476 { 482 if (hasOutputFile) 477 if (hasOutputFile) 483 478 { 484 this->freq_operation_srv = CDuration::FromString(this->file->output_freq.getValue());479 this->freq_operation_srv = CDuration::FromString(this->file->output_freq.getValue()); 485 480 this->freq_write_srv = CDuration::FromString(this->file->output_freq.getValue()); 486 481 } … … 493 488 // this->foperation_srv = 494 489 // boost::shared_ptr<func::CFunctor>(new CInstant(this->data_srv)); 495 496 if (hasOutputFile) 490 491 if (hasOutputFile) 497 492 { 498 const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 493 const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 499 494 *this->last_operation_srv = *this->last_operation_srv - toffset; 500 495 } 501 496 } 502 497 503 498 // if (context->hasClient) 504 // { 499 // { 505 500 this->freq_operation = CDuration::FromString(freq_op.getValue()); 506 501 if (hasOutputFile) this->freq_write = CDuration::FromString(this->file->output_freq.getValue()); 507 if (hasFieldOut) 502 if (hasFieldOut) 508 503 { 509 504 this->freq_write = CDuration::FromString(this->fieldOut->freq_op.getValue()); … … 513 508 this->last_operation = boost::shared_ptr<CDate> 514 509 (new CDate(context->getCalendar()->getInitDate())); 515 516 const CDuration toffset = this->freq_operation - freq_offset_ - context->getCalendar()->getTimeStep(); 517 *this->last_operation = *this->last_operation - toffset; 518 519 if (operation.get()=="once") isOnceOperation=true ; 520 else isOnceOperation=false; 521 isFirstOperation=true; 522 523 524 #define DECLARE_FUNCTOR(MType, mtype) \ 525 if (operation.getValue().compare(#mtype) == 0) \ 526 { \ 527 if (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value==true) \ 510 511 const CDuration toffset = this->freq_operation - freq_offset_ - context->getCalendar()->getTimeStep(); 512 *this->last_operation = *this->last_operation - toffset; 513 514 if (operation.get() == "once") isOnceOperation = true; 515 else isOnceOperation = false; 516 isFirstOperation = true; 517 518 #define DECLARE_FUNCTOR(MType, mtype) \ 519 if (operation.getValue().compare(#mtype) == 0) \ 520 { \ 521 if (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true) \ 528 522 { \ 529 523 boost::shared_ptr<func::CFunctor> foperation_(new C##MType(this->data,default_value)); \ … … 533 527 { \ 534 528 boost::shared_ptr<func::CFunctor> foperation_(new C##MType(this->data)); \ 535 this->foperation = foperation_; 529 this->foperation = foperation_; \ 536 530 } \ 537 return; 538 } 539 531 return; \ 532 } 533 540 534 #include "functor_type.conf" 541 535 542 536 ERROR("CField::solveOperation(void)", 543 537 << "[ operation = " << operation.getValue() << "]" 544 538 << "The operation is not defined !"); 545 539 // } 546 547 548 } 549 540 } 541 550 542 //---------------------------------------------------------------- 551 543 /* 552 void CField::fromBinary(StdIStream 544 void CField::fromBinary(StdIStream& is) 553 545 { 554 546 SuperClass::fromBinary(is); … … 572 564 { 573 565 if (CDomain::has(domain_ref.getValue())) 574 domain = CDomain::get(domain_ref.getValue()) 566 domain = CDomain::get(domain_ref.getValue()); 575 567 else 576 568 ERROR("CField::solveGridReference(void)", 577 569 << "Reference to the domain \'" 578 << domain_ref.getValue() << "\' is wrong") 570 << domain_ref.getValue() << "\' is wrong"); 579 571 } 580 572 … … 582 574 { 583 575 if (CAxis::has(axis_ref.getValue())) 584 axis = CAxis::get(axis_ref.getValue()) 576 axis = CAxis::get(axis_ref.getValue()); 585 577 else 586 578 ERROR("CField::solveGridReference(void)", 587 579 << "Reference to the axis \'" 588 << axis_ref.getValue() <<"\' is wrong") 580 << axis_ref.getValue() <<"\' is wrong"); 589 581 } 590 582 … … 592 584 { 593 585 if (CGrid::has(grid_ref.getValue())) 594 this->grid = CGrid::get(grid_ref.getValue()) 586 this->grid = CGrid::get(grid_ref.getValue()); 595 587 else 596 588 ERROR("CField::solveGridReference(void)", … … 598 590 << grid_ref.getValue() << "\' is wrong"); 599 591 } 600 592 601 593 if (grid_ref.isEmpty() && domain_ref.isEmpty()) 602 594 { … … 605 597 606 598 } 607 608 CType<string> goodDomain 609 CType<string> goodAxis 599 600 CType<string> goodDomain; 601 CType<string> goodAxis; 610 602 if (!grid_ref.isEmpty()) 611 603 { 612 if (!grid->domain_ref.isEmpty()) goodDomain =grid->domain_ref;613 if (!grid->axis_ref.isEmpty()) goodAxis =grid->axis_ref;604 if (!grid->domain_ref.isEmpty()) goodDomain = grid->domain_ref; 605 if (!grid->axis_ref.isEmpty()) goodAxis = grid->axis_ref; 614 606 } 615 if (!domain_ref.isEmpty()) goodDomain=domain_ref ; 616 if (!axis_ref.isEmpty()) goodAxis=axis_ref ; 617 618 619 if (goodDomain.isEmpty()) 607 if (!domain_ref.isEmpty()) goodDomain = domain_ref; 608 if (!axis_ref.isEmpty()) goodAxis = axis_ref; 609 610 if (goodDomain.isEmpty()) 620 611 { 621 612 ERROR("CField::solveGridReference(void)", << "The horizontal domain for this field is not defined"); 622 613 } 623 else 614 else 624 615 { 625 if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) 626 else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'" <<goodDomain.get() << "\' is wrong");616 if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain); 617 else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'" << goodDomain.get() << "\' is wrong"); 627 618 } 628 619 629 620 if (!goodAxis.isEmpty()) 630 621 { 631 if (CAxis::has(goodAxis)) axis = CAxis::get(goodAxis);632 else 633 << goodAxis.get() <<"\' is wrong") 634 } 635 636 bool nothingToDo =false;637 622 if (CAxis::has(goodAxis)) axis = CAxis::get(goodAxis); 623 else ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 624 << goodAxis.get() <<"\' is wrong"); 625 } 626 627 bool nothingToDo = false; 628 638 629 if (!grid_ref.isEmpty()) 639 630 { 640 631 if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 641 if (goodAxis.isEmpty()) nothingToDo =true;642 else if (!grid->axis_ref.isEmpty()) 643 if (grid->axis_ref.get() ==goodAxis.get()) nothingToDo=true;632 if (goodAxis.isEmpty()) nothingToDo = true; 633 else if (!grid->axis_ref.isEmpty()) 634 if (grid->axis_ref.get() == goodAxis.get()) nothingToDo = true; 644 635 } 645 636 646 637 if (!nothingToDo) 647 638 { 648 639 if (!goodAxis.isEmpty()) 649 640 { 650 this->grid = CGrid::createGrid(domain, axis) 641 this->grid = CGrid::createGrid(domain, axis); 651 642 this->grid_ref.setValue(this->grid->getId()); 652 643 } 653 644 else 654 645 { 655 this->grid = CGrid::createGrid(domain) 646 this->grid = CGrid::createGrid(domain); 656 647 this->grid_ref.setValue(this->grid->getId()); 657 } 648 } 658 649 } 659 650 660 grid->solveReference() ; 661 662 } 663 651 grid->solveReference(); 652 653 } 664 654 665 655 ///------------------------------------------------------------------- 666 656 667 657 template <> 668 658 void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) 669 659 { 670 660 if (this->group_ref.isEmpty()) return; … … 680 670 681 671 std::vector<CField*> allChildren = group->getAllChildren(); 682 std::vector<CField*>::iterator 683 it = allChildren.begin(), end = allChildren.end(); 684 672 std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); 673 685 674 for (; it != end; it++) 686 675 { 687 676 CField* child = *it; 688 if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()) 689 690 } 691 } 692 677 if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); 678 679 } 680 } 681 693 682 void CField::scaleFactorAddOffset(double scaleFactor, double addOffset) 694 683 { 695 684 map<int, CArray<double,1>* >::iterator it; 696 for (it=data_srv.begin();it!=data_srv.end();it++) *it->second = (*it->second -addOffset) * 1./scaleFactor;697 } 698 685 for (it = data_srv.begin(); it != data_srv.end(); it++) *it->second = (*it->second - addOffset) / scaleFactor; 686 } 687 699 688 void CField::outputField(CArray<double,3>& fieldOut) 700 689 { 701 690 map<int, CArray<double,1>* >::iterator it; 702 for (it=data_srv.begin();it!=data_srv.end();it++)703 grid->outputField(it->first,*it->second, fieldOut) 704 705 } 706 691 for (it = data_srv.begin(); it != data_srv.end(); it++) 692 grid->outputField(it->first,*it->second, fieldOut); 693 694 } 695 707 696 void CField::outputField(CArray<double,2>& fieldOut) 708 697 { 709 698 map<int, CArray<double,1>* >::iterator it; 710 699 711 for(it=data_srv.begin();it!=data_srv.end();it++) 712 { 713 grid->outputField(it->first,*it->second, fieldOut) ; 714 } 715 } 700 for (it = data_srv.begin(); it != data_srv.end(); it++) 701 { 702 grid->outputField(it->first,*it->second, fieldOut); 703 } 704 } 705 716 706 ///------------------------------------------------------------------- 717 707 718 void CField::parse(xml::CXMLNode 708 void CField::parse(xml::CXMLNode& node) 719 709 { 720 710 SuperClass::parse(node); 721 if (! node.getContent(this->content))711 if (!node.getContent(this->content)) 722 712 { 723 713 if (node.goToChildElement()) … … 725 715 do 726 716 { 727 if (node.getElementName() =="variable" || node.getElementName()=="variable_group") this->getVirtualVariableGroup()->parseChild(node);728 } while (node.goToNextElement()) 717 if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); 718 } while (node.goToNextElement()); 729 719 node.goToParentElement(); 730 720 } 731 721 } 732 722 } 733 723 734 724 CArray<double,1>* CField::getInstantData(void) 735 725 { 736 if (!hasInstantData) 737 { 738 instantData.resize(grid->storeIndex_client.numElements()) 739 hasInstantData =true;740 } 741 return &instantData 742 } 743 726 if (!hasInstantData) 727 { 728 instantData.resize(grid->storeIndex_client.numElements()); 729 hasInstantData = true; 730 } 731 return &instantData; 732 } 733 744 734 void CField::addReference(CField* field) 745 735 { 746 refObject.push_back(field) 747 } 748 736 refObject.push_back(field); 737 } 738 749 739 void CField::addDependency(CField* field, int slotId) 750 740 { 751 fieldDependency.push_back(pair<CField*,int>(field,slotId)) 752 } 753 741 fieldDependency.push_back(pair<CField*,int>(field,slotId)); 742 } 743 754 744 void CField::buildExpression(void) 755 745 { 756 if (content.size() > 0) 757 { 758 CSimpleNodeExpr* simpleExpr =parseExpr(content+'\0');759 expression =CFieldNode::newNode(simpleExpr);760 delete simpleExpr 761 set<string> instantFieldIds 762 map<string,CField*> associatedInstantFieldIds 763 expression->getInstantFieldIds(instantFieldIds) 764 for (set<string>::iterator it =instantFieldIds.begin() ; it!=instantFieldIds.end();++it)765 { 766 if (*it !="this")746 if (content.size() > 0) 747 { 748 CSimpleNodeExpr* simpleExpr = parseExpr(content+'\0'); 749 expression = CFieldNode::newNode(simpleExpr); 750 delete simpleExpr; 751 set<string> instantFieldIds; 752 map<string,CField*> associatedInstantFieldIds; 753 expression->getInstantFieldIds(instantFieldIds); 754 for (set<string>::iterator it = instantFieldIds.begin(); it != instantFieldIds.end(); ++it) 755 { 756 if (*it != "this") 767 757 { 768 if (CField::has(*it)) 758 if (CField::has(*it)) 769 759 { 770 CField* field =CField::get(*it);771 field->processEnabledField() 772 associatedInstantFieldIds[*it] =field;760 CField* field = CField::get(*it); 761 field->processEnabledField(); 762 associatedInstantFieldIds[*it] = field; 773 763 } 774 else ERROR("void CField::buildExpression(void)", <<" Field "<<*it<<" does not exist");764 else ERROR("void CField::buildExpression(void)", << " Field " << *it << " does not exist"); 775 765 } 776 766 } 777 778 set<string> averageFieldIds 779 map<string,CField*> associatedAverageFieldIds 780 781 expression->getAverageFieldIds(averageFieldIds) 782 for (set<string>::iterator it =averageFieldIds.begin() ; it!=averageFieldIds.end();++it)783 { 784 if (CField::has(*it)) 767 768 set<string> averageFieldIds; 769 map<string,CField*> associatedAverageFieldIds; 770 771 expression->getAverageFieldIds(averageFieldIds); 772 for (set<string>::iterator it = averageFieldIds.begin(); it != averageFieldIds.end(); ++it) 773 { 774 if (CField::has(*it)) 785 775 { 786 CFieldGroup* root =CFieldGroup::get("field_definition");787 CField* averageField =root->createChild();788 CField* instantField =root->createChild();789 averageField->field_ref =*it;790 averageField->hasFieldOut =true;791 averageField->fieldOut =instantField;792 instantField->freq_op =freq_op;793 averageField-> processEnabledField() 776 CFieldGroup* root = CFieldGroup::get("field_definition"); 777 CField* averageField = root->createChild(); 778 CField* instantField = root->createChild(); 779 averageField->field_ref = *it; 780 averageField->hasFieldOut = true; 781 averageField->fieldOut = instantField; 782 instantField->freq_op = freq_op; 783 averageField-> processEnabledField(); 794 784 instantField->SuperClassAttribute::setAttributes(averageField, true); 795 instantField->field_ref.reset() 796 instantField->operation.reset() 797 798 instantField-> processEnabledField() 799 associatedAverageFieldIds[*it] =instantField;785 instantField->field_ref.reset(); 786 instantField->operation.reset(); 787 788 instantField-> processEnabledField(); 789 associatedAverageFieldIds[*it] = instantField; 800 790 } 801 else ERROR("void CField::buildExpression(void)", <<" Field "<<*it<<" does not exist");802 } 803 804 expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds) 805 806 slots.resize(instantFieldIds.size() +averageFieldIds.size());807 resetSlots() 808 int slotId =0;809 set<CField*> fields 810 expression->getFields(fields) 811 for (set<CField*>::iterator it =fields.begin() ; it!=fields.end();++it,++slotId) (*it)->addDependency(this,slotId);812 hasExpression =true;813 } 814 } 815 791 else ERROR("void CField::buildExpression(void)", << " Field " << *it << " does not exist"); 792 } 793 794 expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds); 795 796 slots.resize(instantFieldIds.size() + averageFieldIds.size()); 797 resetSlots(); 798 int slotId = 0; 799 set<CField*> fields; 800 expression->getFields(fields); 801 for (set<CField*>::iterator it = fields.begin(); it != fields.end(); ++it, ++slotId) (*it)->addDependency(this,slotId); 802 hasExpression = true; 803 } 804 } 805 816 806 void CField::resetSlots(void) 817 807 { 818 for (vector<bool>::iterator it=slots.begin();it!=slots.end();++it) *it=false;819 } 820 808 for (vector<bool>::iterator it = slots.begin(); it != slots.end(); ++it) *it = false; 809 } 810 821 811 bool CField::slotsFull(void) 822 812 { 823 bool ret=true ; 824 for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) ret &= *it; 825 return ret ; 826 } 827 828 813 bool ret = true; 814 for (vector<bool>::iterator it = slots.begin(); it != slots.end(); ++it) ret &= *it; 815 return ret; 816 } 817 829 818 void CField::setSlot(int slotId) 830 819 { 831 CContext* context = CContext::getCurrent() 832 const CDate 833 if (slotUpdateDate ==NULL || currDate!=*slotUpdateDate)834 { 835 resetSlots() 836 if (slotUpdateDate ==NULL) slotUpdateDate=new CDate(currDate);837 else *slotUpdateDate =currDate;838 } 839 slots[slotId] =true;820 CContext* context = CContext::getCurrent(); 821 const CDate& currDate = context->getCalendar()->getCurrentDate(); 822 if (slotUpdateDate == NULL || currDate != *slotUpdateDate) 823 { 824 resetSlots(); 825 if (slotUpdateDate == NULL) slotUpdateDate = new CDate(currDate); 826 else *slotUpdateDate = currDate; 827 } 828 slots[slotId] = true; 840 829 if (slotsFull()) 841 830 { 842 CArray<double,1> expr(expression->compute()) ; 843 844 if (hasInstantData) 845 { 846 instantData=expr ; 847 for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) 848 if (it->first!=this) it->first->setSlot(it->second) ; 849 } 850 851 if (hasOutputFile) updateDataFromExpression(expr) ; 852 853 } 854 } 855 856 831 CArray<double,1> expr(expression->compute()); 832 833 if (hasInstantData) 834 { 835 instantData = expr; 836 for (list< pair<CField *,int> >::iterator it = fieldDependency.begin(); it != fieldDependency.end(); ++it) 837 if (it->first != this) it->first->setSlot(it->second); 838 } 839 840 if (hasOutputFile) updateDataFromExpression(expr); 841 842 const std::vector<CField*>& refField = getAllReference(); 843 for (std::vector<CField*>::const_iterator it = refField.begin(); it != refField.end(); it++) 844 { 845 if (!(*it)->hasExpression) 846 (*it)->setDataFromExpression(expr); 847 } 848 } 849 } 857 850 858 851 CVariable* CField::addVariable(const string& id) 859 852 { 860 return vVariableGroup->createChild(id) 853 return vVariableGroup->createChild(id); 861 854 } 862 855 863 856 CVariableGroup* CField::addVariableGroup(const string& id) 864 857 { 865 return vVariableGroup->createChildGroup(id) ; 866 } 867 858 return vVariableGroup->createChildGroup(id); 859 } 868 860 869 861 void CField::sendAddVariable(const string& id) 870 862 { 871 CContext* context =CContext::getCurrent();872 873 if (! context->hasServer)874 { 875 CContextClient* client =context->client;876 877 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ;863 CContext* context = CContext::getCurrent(); 864 865 if (!context->hasServer) 866 { 867 CContextClient* client = context->client; 868 869 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); 878 870 if (client->isServerLeader()) 879 871 { 880 CMessage msg 881 msg <<this->getId();882 msg <<id;883 event.push(client->getServerLeader(),1,msg) 884 client->sendEvent(event) 872 CMessage msg; 873 msg << this->getId(); 874 msg << id; 875 event.push(client->getServerLeader(),1,msg); 876 client->sendEvent(event); 885 877 } 886 else client->sendEvent(event) ; 887 } 888 889 } 890 891 878 else client->sendEvent(event); 879 } 880 881 } 882 892 883 void CField::sendAddVariableGroup(const string& id) 893 884 { 894 CContext* context =CContext::getCurrent();895 if (! context->hasServer)896 { 897 CContextClient* client =context->client;898 899 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ;885 CContext* context = CContext::getCurrent(); 886 if (!context->hasServer) 887 { 888 CContextClient* client = context->client; 889 890 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP); 900 891 if (client->isServerLeader()) 901 892 { 902 CMessage msg 903 msg <<this->getId();904 msg <<id;905 event.push(client->getServerLeader(),1,msg) 906 client->sendEvent(event) 893 CMessage msg; 894 msg << this->getId(); 895 msg << id; 896 event.push(client->getServerLeader(),1,msg); 897 client->sendEvent(event); 907 898 } 908 else client->sendEvent(event) 909 } 910 911 } 912 899 else client->sendEvent(event); 900 } 901 902 } 903 913 904 void CField::recvAddVariable(CEventServer& event) 914 905 { 915 916 CBufferIn* buffer =event.subEvents.begin()->buffer;906 907 CBufferIn* buffer = event.subEvents.begin()->buffer; 917 908 string id; 918 *buffer>>id ; 919 get(id)->recvAddVariable(*buffer) ; 920 } 921 922 909 *buffer >> id; 910 get(id)->recvAddVariable(*buffer); 911 } 912 923 913 void CField::recvAddVariable(CBufferIn& buffer) 924 914 { 925 string id 926 buffer >>id;927 addVariable(id) 915 string id; 916 buffer >> id; 917 addVariable(id); 928 918 } 929 919 930 920 void CField::recvAddVariableGroup(CEventServer& event) 931 921 { 932 933 CBufferIn* buffer =event.subEvents.begin()->buffer;922 923 CBufferIn* buffer = event.subEvents.begin()->buffer; 934 924 string id; 935 *buffer>>id ; 936 get(id)->recvAddVariableGroup(*buffer) ; 937 } 938 939 925 *buffer >> id; 926 get(id)->recvAddVariableGroup(*buffer); 927 } 928 940 929 void CField::recvAddVariableGroup(CBufferIn& buffer) 941 930 { 942 string id ; 943 buffer>>id ; 944 addVariableGroup(id) ; 945 } 946 947 948 949 931 string id; 932 buffer >> id; 933 addVariableGroup(id); 934 } 950 935 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.