Changeset 1004 for XIOS/trunk/src
- Timestamp:
- 11/25/16 14:12:15 (7 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/config/interpolate_domain_attribute.conf
r982 r1004 5 5 6 6 /* Write interpolation weights into file */ 7 DECLARE_ENUM2(mode,write,read) 7 DECLARE_ENUM3(mode,compute,read,read_or_compute) 8 DECLARE_ATTRIBUTE(StdString, weight_filename) 9 DECLARE_ATTRIBUTE(bool, write_weight) -
XIOS/trunk/src/node/interpolate_domain.cpp
r982 r1004 48 48 } 49 49 50 StdString weightFile = "interpolation_weights_" + domainSrc->getDomainOutputName(); 50 if (this->mode.isEmpty()) this->mode.setValue(mode_attr::compute); 51 if (this->write_weight.isEmpty()) this->write_weight.setValue(false); 51 52 52 if (!this->mode.isEmpty()) 53 { 54 if (mode_attr::read == this->mode) 55 { 56 if (this->file.isEmpty()) 57 { 53 StdString weightFile; 54 switch (this->mode) 55 { 56 case mode_attr::read: 57 if (this->file.isEmpty()) 58 { 59 if (!this->write_weight) 58 60 ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 59 61 << "Read mode is activated but there is no file specified." << std::endl 60 62 << "Please define a correct file containing interpolation weights with option 'file'. "); 61 } 62 else 63 { 64 weightFile = this->file; 65 ifstream f(weightFile.c_str()); 66 if (!f.good()) 67 ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 68 << "Read mode is activated but file " << weightFile << " doesn't exist." << std::endl 69 << "Please check this file "); 70 } 71 } 72 else 73 { 74 if (file.isEmpty()) 75 this->file.setValue(weightFile); 76 } 77 } 78 else 79 { 80 if (!file.isEmpty()) // set mode read 81 { 82 weightFile = this->file; 83 ifstream f(weightFile.c_str()); 84 if (!f.good()) // file doesn't exist 85 this->mode.setValue(mode_attr::write); 86 else 87 this->mode.setValue(mode_attr::read); 88 } 89 else // only calculate weights() Mode set write but there is no file) 90 { 91 this->mode.setValue(mode_attr::write); 92 } 63 } 64 else 65 { 66 weightFile = this->file; 67 ifstream f(weightFile.c_str()); 68 if (!f.good()) 69 ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 70 << "Read mode is activated but file " << weightFile << " doesn't exist." << std::endl 71 << "Please check this file "); 72 } 73 break; 74 case mode_attr::compute: 75 break; 76 case mode_attr::read_or_compute: 77 if (!this->file.isEmpty() && !this->write_weight) 78 { 79 weightFile = this->file; 80 ifstream f(weightFile.c_str()); 81 if (!f.good()) 82 ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 83 << "read_or_compute mode is activated but file " << weightFile << " doesn't exist." << std::endl 84 << "Please check this file "); 85 } 86 break; 87 default: 88 break; 93 89 } 94 90 -
XIOS/trunk/src/node/interpolate_domain.hpp
r836 r1004 50 50 virtual ~CInterpolateDomain(void); 51 51 52 virtual void checkValid(CDomain* axisDest);52 virtual void checkValid(CDomain* domainSource); 53 53 54 54 /// Accesseurs statiques /// -
XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp
r982 r1004 48 48 49 49 CDomainAlgorithmInterpolate::CDomainAlgorithmInterpolate(CDomain* domainDestination, CDomain* domainSource, CInterpolateDomain* interpDomain) 50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false) 51 { 50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false), readFromFile_(false) 51 { 52 CContext* context = CContext::getCurrent(); 52 53 interpDomain_->checkValid(domainSource); 53 if ((CInterpolateDomain::mode_attr::write == interpDomain_->mode) && 54 (!interpDomain_->file.isEmpty())) 55 writeToFile_ = true; 54 fileToReadWrite_ = "xios_interpolation_weights_"; 55 56 if (interpDomain_->weight_filename.isEmpty()) 57 { 58 fileToReadWrite_ += context->getId() + "_" + 59 domainSource->getDomainOutputName() + "_" + 60 domainDestination->getDomainOutputName() + ".nc"; 61 } 62 else 63 fileToReadWrite_ = interpDomain_->weight_filename; 64 65 ifstream f(fileToReadWrite_.c_str()); 66 switch (interpDomain_->mode) 67 { 68 case CInterpolateDomain::mode_attr::read: 69 readFromFile_ = true; 70 break; 71 case CInterpolateDomain::mode_attr::compute: 72 readFromFile_ = false; 73 break; 74 case CInterpolateDomain::mode_attr::read_or_compute: 75 if (!f.good()) 76 readFromFile_ = false; 77 else 78 readFromFile_ = true; 79 break; 80 default: 81 break; 82 } 83 84 writeToFile_ = interpDomain_->write_weight; 85 56 86 } 57 87 … … 354 384 } 355 385 356 if (writeToFile_ )386 if (writeToFile_ && !readFromFile_) 357 387 writeRemapInfo(interpMapValue); 358 388 exchangeRemapInfo(interpMapValue); … … 439 469 void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 440 470 { 441 if ( CInterpolateDomain::mode_attr::read == interpDomain_->mode)471 if (readFromFile_ && !writeToFile_) 442 472 readRemapInfo(); 443 473 else … … 448 478 449 479 void CDomainAlgorithmInterpolate::writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 450 { 451 std::string filename = interpDomain_->file.getValue(); 452 writeInterpolationInfo(filename, interpMapValue); 480 { 481 writeInterpolationInfo(fileToReadWrite_, interpMapValue); 453 482 } 454 483 455 484 void CDomainAlgorithmInterpolate::readRemapInfo() 456 { 457 std::string filename = interpDomain_->file.getValue(); 485 { 458 486 std::map<int,std::vector<std::pair<int,double> > > interpMapValue; 459 readInterpolationInfo(file name, interpMapValue);487 readInterpolationInfo(fileToReadWrite_, interpMapValue); 460 488 461 489 exchangeRemapInfo(interpMapValue); -
XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp
r982 r1004 48 48 CInterpolateDomain* interpDomain_; 49 49 bool writeToFile_; 50 bool readFromFile_; 51 StdString fileToReadWrite_; 50 52 51 53 // class WriteNetCdf;
Note: See TracChangeset
for help on using the changeset viewer.