#include "domain.hpp" #include "attribute_template_impl.hpp" #include "object_template_impl.hpp" #include "group_template_impl.hpp" #include namespace xmlioserver { namespace tree { /// ////////////////////// Définitions ////////////////////// /// CDomain::CDomain(void) : CObjectTemplate(), CDomainAttributes() , isChecked(false), local_mask(new CMask()), relFiles() , ibegin_sub(), iend_sub(), jbegin_sub(), jend_sub() , lonvalue_sub(), latvalue_sub() { /* Ne rien faire de plus */ } CDomain::CDomain(const StdString & id) : CObjectTemplate(id), CDomainAttributes() , isChecked(false), local_mask(new CMask()), relFiles() , ibegin_sub(), iend_sub(), jbegin_sub(), jend_sub() , lonvalue_sub(), latvalue_sub() { /* Ne rien faire de plus */ } CDomain::~CDomain(void) { this->local_mask.reset(); for (StdSize i = 0; i < this->lonvalue_sub.size(); i++) { this->lonvalue_sub[i].reset(); this->latvalue_sub[i].reset(); } } ///--------------------------------------------------------------- const std::set & CDomain::getRelFiles(void) const { return (this->relFiles); } //---------------------------------------------------------------- bool CDomain::IsWritten(const StdString & filename) const { return (this->relFiles.find(filename) != this->relFiles.end()); } //---------------------------------------------------------------- void CDomain::addRelFile(const StdString & filename) { this->relFiles.insert(filename); } //---------------------------------------------------------------- void CDomain::fromBinary(StdIStream & is) { SuperClass::fromBinary(is); this->ibegin_sub.push_back(this->ibegin.getValue()); this->jbegin_sub.push_back(this->jbegin.getValue()); this->iend_sub.push_back(this->iend.getValue()); this->jend_sub.push_back(this->jend.getValue()); this->latvalue_sub.push_back(this->latvalue.getValue()); this->lonvalue_sub.push_back(this->lonvalue.getValue()); #define CLEAR_ATT(name_)\ SuperClassAttribute::operator[](#name_)->clear() CLEAR_ATT(mask); CLEAR_ATT(data_n_index); CLEAR_ATT(data_i_index); CLEAR_ATT(data_j_index); CLEAR_ATT(data_ni); CLEAR_ATT(data_nj); CLEAR_ATT(data_ibegin); CLEAR_ATT(data_jbegin); CLEAR_ATT(ni); CLEAR_ATT(nj); #undef CLEAR_ATT this->ibegin.setValue(*std::min_element(this->ibegin_sub.begin(),this->ibegin_sub.end())); this->jbegin.setValue(*std::min_element(this->jbegin_sub.begin(),this->jbegin_sub.end())); this->iend.setValue(*std::max_element(this->iend_sub.begin(),this->iend_sub.end())); this->jend.setValue(*std::max_element(this->jend_sub.begin(),this->jend_sub.end())); } //---------------------------------------------------------------- StdString CDomain::GetName(void) { return (StdString("domain")); } StdString CDomain::GetDefName(void){ return (CDomain::GetName()); } ENodeType CDomain::GetType(void) { return (eDomain); } //---------------------------------------------------------------- void CDomain::checkGlobalDomain(void) { if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || (ni_glo.isEmpty() || nj_glo.getValue() <= 0 )) ERROR("CDomain::checkAttributes(void)", << "Le domaine global est mal défini," << " vérifiez les valeurs de \'ni_glo\' et \'nj_glo\' !") ; } //---------------------------------------------------------------- void CDomain::checkLocalIDomain(void) { if (!ni.isEmpty() && !ibegin.isEmpty() && iend.isEmpty()) iend.setValue(ibegin.getValue() + ni.getValue() - 1) ; else if (!ni.isEmpty() && !iend.isEmpty() && ibegin.isEmpty()) ibegin.setValue( - ni.getValue() + iend.getValue() + 1) ; else if (!ibegin.isEmpty() && !iend.isEmpty() && ni.isEmpty()) ni.setValue(iend.getValue() - ibegin.getValue() + 1) ; else if (!ibegin.isEmpty() && !iend.isEmpty() && !ni.isEmpty() && (iend.getValue() != ibegin.getValue() + ni.getValue() - 1)) { ERROR("CDomain::checkAttributes(void)", << "Le domaine est mal défini," << " iend est différent de (ibegin + ni - 1) !") ; } else { ERROR("CDomain::checkAttributes(void)", << "Le domaine est mal défini," << " deux valeurs au moins parmis iend, ibegin, ni doivent être définies !") ; } if (ni.getValue() < 0 || ibegin.getValue() > iend.getValue() || ibegin.getValue() < 1 || iend.getValue() > ni_glo.getValue()) ERROR("CDomain::checkAttributes(void)", << "Domaine local mal défini," << " vérifiez les valeurs ni, ni_glo, ibegin, iend") ; } //---------------------------------------------------------------- void CDomain::checkLocalJDomain(void) { if (!nj.isEmpty() && !jbegin.isEmpty() && jend.isEmpty()) jend.setValue(jbegin.getValue() + nj.getValue() - 1) ; else if (!nj.isEmpty() && !jend.isEmpty() && jbegin.isEmpty()) jbegin.setValue( - nj.getValue() + jend.getValue() + 1) ; else if (!jbegin.isEmpty() && !jend.isEmpty() && nj.isEmpty()) nj.setValue(jend.getValue() - jbegin.getValue() + 1) ; else if (!jbegin.isEmpty() && !jend.isEmpty() && !nj.isEmpty() && (jend.getValue() != jbegin.getValue() + nj.getValue() - 1)) { ERROR("CDomain::checkAttributes(void)", << "Le domaine est mal défini," << " iend est différent de (jbegin + nj - 1) !") ; } else { ERROR("CDomain::checkAttributes(void)", << "Le domaine est mal défini," << " deux valeurs au moins parmis jend, jbegin, nj doivent être définies !") ; } if (nj.getValue() < 0 || jbegin.getValue() > jend.getValue() || jbegin.getValue() < 1 || jend.getValue() > nj_glo.getValue()) ERROR("CDomain::checkAttributes(void)", << "Domaine local mal défini," << " vérifiez les valeurs nj, nj_glo, jbegin, jend") ; } //---------------------------------------------------------------- void CDomain::checkMask(void) { if (!mask.isEmpty()) { unsigned int niu = ni.getValue(), nju = nj.getValue(); if ((mask.getValue()->shape()[0] != niu) || (mask.getValue()->shape()[1] != nju)) ERROR("CDomain::checkAttributes(void)", <<"Le masque n'a pas la même taille que le domaine local") ; } else // (!mask.hasValue()) { // Si aucun masque n'est défini, // on en crée un nouveau qui valide l'intégralité du domaine. ARRAY_CREATE(__arr, bool, 2, [ni.getValue()][nj.getValue()]); for (int i = 0; i < ni.getValue(); i++) for (int j = 0; j < nj.getValue(); j++) (*__arr)[i][j] = true; mask.setValue(__arr); __arr.reset(); } } //---------------------------------------------------------------- void CDomain::checkDomainData(void) { if (!data_dim.isEmpty() && !(data_dim.getValue() == 1 || data_dim.getValue() == 2)) { ERROR("CDomain::checkAttributes(void)", << "Dimension des données non comptatible (doit être 1 ou 2) !") ; } else if (data_dim.isEmpty()) { ERROR("CDomain::checkAttributes(void)", << "Dimension des données non définie !") ; } if (data_ibegin.isEmpty()) data_ibegin.setValue(0) ; if (data_jbegin.isEmpty() && (data_dim.getValue() == 2)) data_jbegin.setValue(0) ; if (!data_ni.isEmpty() && (data_ni.getValue() <= 0)) { ERROR("CDomain::checkAttributes(void)", << "Dimension des données négative (data_ni).") ; } else if (data_ni.isEmpty()) { data_ni.setValue((data_dim.getValue() == 1) ? (ni.getValue() * nj.getValue()) : ni.getValue()); } if (data_dim.getValue() == 2) { if (!data_nj.isEmpty() && (data_nj.getValue() <= 0) ) { ERROR("CDomain::checkAttributes(void)", << "Dimension des données négative (data_nj).") ; } else if (data_nj.isEmpty()) data_nj.setValue(nj.getValue()) ; } } //---------------------------------------------------------------- void CDomain::checkCompression(void) { if (!data_i_index.isEmpty()) { int ssize = data_i_index.getValue()->size(); if (!data_n_index.isEmpty() && (data_n_index.getValue() != ssize)) { ERROR("CDomain::checkAttributes(void)", <<"Dimension data_i_index incompatible avec data_n_index.") ; } else if (data_n_index.isEmpty()) data_n_index.setValue(ssize) ; if (data_dim.getValue() == 2) { if (!data_j_index.isEmpty() && (data_j_index.getValue()->size() != data_i_index.getValue()->size())) { ERROR("CDomain::checkAttributes(void)", <<"Dimension data_j_index incompatible avec data_i_index.") ; } else if (data_j_index.isEmpty()) { ERROR("CDomain::checkAttributes(void)", <<"La donnée data_j_index doit être renseignée !") ; } } } else { if (!data_n_index.isEmpty() || ((data_dim.getValue() == 2) && (!data_j_index.isEmpty()))) ERROR("CDomain::checkAttributes(void)", << "data_i_index non défini") ; } if (data_n_index.isEmpty()) { // -> bloc re-vérifié OK if (data_dim.getValue() == 1) { const int dni = data_ni.getValue(); ARRAY_CREATE(__arri, int, 1, [dni]); data_n_index.setValue(dni); for (int i = 0; i < dni; i++) (*__arri)[i] = i+1 ; data_i_index.setValue(__arri) ; } else // (data_dim == 2) { const int dni = data_ni.getValue() * data_nj.getValue(); ARRAY_CREATE(__arri, int, 1, [dni]); ARRAY_CREATE(__arrj, int, 1, [dni]); data_n_index.setValue(dni); for(int count = 0, i = 0; i < data_ni.getValue(); i++) { for(int j = 0; j < data_nj.getValue(); j++, count++) { (*__arri)[count] = i+1 ; (*__arrj)[count] = j+1 ; } } data_i_index.setValue(__arri) ; data_j_index.setValue(__arrj) ; __arri.reset(); __arrj.reset(); } } } //---------------------------------------------------------------- void CDomain::completeLonLat(void) { ARRAY(double, 1) lonvalue_ = this->lonvalue.getValue(), latvalue_ = this->latvalue.getValue(); if (this->data_dim.getValue() == 2) { StdSize dn = this->ni.getValue()*this->nj.getValue(); lonvalue_->resize(boost::extents[dn]); latvalue_->resize(boost::extents[dn]); for (StdSize k = 0; k < lonvalue_sub.size(); k++) { int l = 0; ARRAY(double, 1) lonvalue_loc = this->lonvalue_sub[k], latvalue_loc = this->latvalue_sub[k]; const int ibegin_loc = ibegin_sub[k], iend_loc = iend_sub[k], jbegin_loc = jbegin_sub[k], jend_loc = jend_sub[k]; for (int i = ibegin_loc-1; i <= (iend_loc-1); i++) { for (int j = jbegin_loc-1; j <= (jend_loc-1); j++) { (*lonvalue_)[i+j*this->ni.getValue()] = (*lonvalue_loc)[l]; (*latvalue_)[i+j*this->ni.getValue()] = (*latvalue_loc)[l++]; } } } } else { StdSize dn = this->ni.getValue(); lonvalue_->resize(boost::extents[dn]); latvalue_->resize(boost::extents[dn]); for (StdSize k = 0; k < lonvalue_sub.size(); k++) { int l = 0; ARRAY(double, 1) lonvalue_loc = this->lonvalue_sub[k], latvalue_loc = this->latvalue_sub[k]; const int ibegin_loc = ibegin_sub[k], iend_loc = iend_sub[k], jbegin_loc = jbegin_sub[k], jend_loc = jend_sub[k]; for (int i = ibegin_loc-1; i <= (iend_loc-1); i++) (*lonvalue_)[i] = (*lonvalue_loc)[l++]; for (int j = jbegin_loc-1, l = 0; j <= (jend_loc-1); j++) (*latvalue_)[j] = (*latvalue_loc)[l++]; } } } //---------------------------------------------------------------- void CDomain::checkAttributes(void) { if (this->isChecked) return; this->checkGlobalDomain(); this->checkLocalIDomain(); this->checkLocalJDomain(); if (this->latvalue_sub.size() == 0) { this->checkMask(); this->checkDomainData(); this->checkCompression(); } else { this->completeLonLat(); } this->completeMask(); this->isChecked = true; } //---------------------------------------------------------------- void CDomain::completeMask(void) { this->local_mask->resize(ni.getValue(), nj.getValue()); /*this->local_mask->setDataPosition (data_dim.getValue(), data_ni.getValue(), data_nj.getValue(), data_ibegin.getValue(), data_jbegin.getValue(), data_n_index.getValue(), data_i_index.getValue(), data_j_index.getValue());*/ } //---------------------------------------------------------------- boost::shared_ptr CDomain::getLocalMask(void) const { return (this->local_mask); } //---------------------------------------------------------------- const std::vector & CDomain::getIBeginSub(void) const { return (this->ibegin_sub); } //---------------------------------------------------------------- const std::vector & CDomain::getIEndSub(void) const { return (this->iend_sub); } //---------------------------------------------------------------- const std::vector & CDomain::getJBeginSub(void) const { return (this->jbegin_sub); } //---------------------------------------------------------------- const std::vector & CDomain::getJEndSub(void) const { return (this->iend_sub); } //---------------------------------------------------------------- const std::vector & CDomain::getLonValueSub(void) const { return (this->lonvalue_sub); } //---------------------------------------------------------------- const std::vector & CDomain::getLatValueSub(void) const { return (this->latvalue_sub); } ///--------------------------------------------------------------- } // namespace tree } // namespace xmlioserver