[687] | 1 | #include "generate_rectilinear_domain.hpp" |
---|
| 2 | #include "type.hpp" |
---|
| 3 | |
---|
| 4 | namespace xios { |
---|
| 5 | |
---|
| 6 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 7 | |
---|
| 8 | CGenerateRectilinearDomain::CGenerateRectilinearDomain(void) |
---|
| 9 | : CObjectTemplate<CGenerateRectilinearDomain>(), CGenerateRectilinearDomainAttributes(), CTransformation<CDomain>() |
---|
| 10 | { /* Ne rien faire de plus */ } |
---|
| 11 | |
---|
| 12 | CGenerateRectilinearDomain::CGenerateRectilinearDomain(const StdString & id) |
---|
| 13 | : CObjectTemplate<CGenerateRectilinearDomain>(id), CGenerateRectilinearDomainAttributes(), CTransformation<CDomain>() |
---|
| 14 | { /* Ne rien faire de plus */ } |
---|
| 15 | |
---|
| 16 | CGenerateRectilinearDomain::~CGenerateRectilinearDomain(void) |
---|
| 17 | {} |
---|
| 18 | |
---|
[836] | 19 | CTransformation<CDomain>* CGenerateRectilinearDomain::create(const StdString& id, xml::CXMLNode* node) |
---|
| 20 | { |
---|
| 21 | CGenerateRectilinearDomain* genDomain = CGenerateRectilinearDomainGroup::get("generate_rectilinear_domain_definition")->createChild(id); |
---|
| 22 | if (node) genDomain->parse(*node); |
---|
| 23 | return static_cast<CTransformation<CDomain>*>(genDomain); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | bool CGenerateRectilinearDomain::_dummyRegistered = CGenerateRectilinearDomain::registerTrans(); |
---|
| 27 | bool CGenerateRectilinearDomain::registerTrans() |
---|
| 28 | { |
---|
| 29 | registerTransformation(TRANS_GENERATE_RECTILINEAR_DOMAIN, create); |
---|
| 30 | } |
---|
| 31 | |
---|
[687] | 32 | //---------------------------------------------------------------- |
---|
| 33 | |
---|
| 34 | StdString CGenerateRectilinearDomain::GetName(void) { return StdString("generate_rectilinear_domain"); } |
---|
| 35 | StdString CGenerateRectilinearDomain::GetDefName(void) { return StdString("generate_rectilinear_domain"); } |
---|
| 36 | ENodeType CGenerateRectilinearDomain::GetType(void) { return eGenerateRectilinearDomain; } |
---|
| 37 | |
---|
[727] | 38 | void CGenerateRectilinearDomain::checkValid(CDomain* domainDst) |
---|
[687] | 39 | { |
---|
[727] | 40 | const double defaultBndsLonStart = 0; |
---|
| 41 | const double defaultBndsLonEnd = 360; |
---|
| 42 | |
---|
| 43 | const double defaultBndsLatStart = -90; |
---|
| 44 | const double defaultBndsLatEnd = 90; |
---|
| 45 | |
---|
| 46 | if ((!lon_start.isEmpty() && lon_end.isEmpty()) || |
---|
| 47 | (lon_start.isEmpty() && !lon_end.isEmpty())) |
---|
| 48 | ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", |
---|
| 49 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 50 | << "Only longitude start or longitude end attribute is defined." << std::endl |
---|
| 51 | << "Must define both: 'lon_start' and 'lon_end'."); |
---|
| 52 | |
---|
| 53 | if ((!lat_start.isEmpty() && lat_end.isEmpty()) || |
---|
| 54 | (lat_start.isEmpty() && !lat_end.isEmpty())) |
---|
| 55 | ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", |
---|
| 56 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 57 | << "Only latitude start or latitude end attribute is defined." << std::endl |
---|
| 58 | << "Must define both: 'lat_start' and 'lat_end'."); |
---|
| 59 | |
---|
| 60 | if ((!bounds_lon_start.isEmpty() && bounds_lon_end.isEmpty()) || |
---|
| 61 | (bounds_lon_start.isEmpty() && !bounds_lon_end.isEmpty())) |
---|
| 62 | ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", |
---|
| 63 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 64 | << "Only longitude boundary start or longitude boundary end attribute is defined." << std::endl |
---|
| 65 | << "Must define both: 'bounds_lon_start' and 'bounds_lon_end'."); |
---|
| 66 | |
---|
| 67 | if ((!bounds_lat_start.isEmpty() && bounds_lat_end.isEmpty()) || |
---|
| 68 | (bounds_lat_start.isEmpty() && !bounds_lat_end.isEmpty())) |
---|
| 69 | ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", |
---|
| 70 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 71 | << "Only latitude boundary start or latitude boundary end attribute is defined." << std::endl |
---|
| 72 | << "Must define both: 'bounds_lat_start' and 'bounds_lat_end'."); |
---|
| 73 | |
---|
| 74 | if (!bounds_lon_start.isEmpty() && !lon_start.isEmpty()) |
---|
| 75 | ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", |
---|
| 76 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 77 | << "Only one longitude boundary attribute or longitude can be used but both 'bounds_lon_start' and 'lon_start' are defined." << std::endl |
---|
| 78 | << "Define only one attribute: 'bounds_lon_start' or 'lon_start'."); |
---|
| 79 | |
---|
| 80 | if (!bounds_lat_start.isEmpty() && !lat_start.isEmpty()) |
---|
| 81 | ERROR("CGenerateRectilinearDomain::checkValid(CDomain* domainDst)", |
---|
| 82 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 83 | << "Only one latitude boundary attribute or latitude can be used but both 'bounds_lat_start' and 'lat_start' are defined." << std::endl |
---|
| 84 | << "Define only one attribute: 'bounds_lat_start' or 'lat_start'."); |
---|
| 85 | |
---|
[734] | 86 | if (bounds_lon_start.isEmpty() && lon_start.isEmpty()) |
---|
[727] | 87 | { |
---|
| 88 | bounds_lon_start.setValue(defaultBndsLonStart); |
---|
| 89 | bounds_lon_end.setValue(defaultBndsLonEnd); |
---|
[734] | 90 | } |
---|
| 91 | |
---|
| 92 | if (bounds_lat_start.isEmpty() && lat_start.isEmpty()) |
---|
| 93 | { |
---|
[727] | 94 | bounds_lat_start.setValue(defaultBndsLatStart); |
---|
| 95 | bounds_lat_end.setValue(defaultBndsLatEnd); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if (!bounds_lon_start.isEmpty()) |
---|
| 99 | { |
---|
| 100 | int niGlo = domainDst->ni_glo.getValue(); |
---|
| 101 | |
---|
| 102 | double boundsLonRange = bounds_lon_end - bounds_lon_start; |
---|
[734] | 103 | double boundsLonStep = boundsLonRange/(double(niGlo)); |
---|
[775] | 104 | domainDst->bounds_lon_start.setValue(bounds_lon_start); |
---|
| 105 | domainDst->bounds_lon_end.setValue(bounds_lon_end); |
---|
| 106 | domainDst->lon_start.setValue(bounds_lon_start + boundsLonStep/2); |
---|
| 107 | domainDst->lon_end.setValue( bounds_lon_end - boundsLonStep/2); |
---|
[727] | 108 | } |
---|
| 109 | |
---|
| 110 | if (!bounds_lat_start.isEmpty()) |
---|
| 111 | { |
---|
| 112 | int njGlo = domainDst->nj_glo.getValue(); |
---|
| 113 | |
---|
| 114 | double boundsLatRange = bounds_lat_end - bounds_lat_start; |
---|
[734] | 115 | double boundsLatStep = boundsLatRange/(double(njGlo)); |
---|
[775] | 116 | domainDst->bounds_lat_start.setValue(bounds_lat_start); |
---|
| 117 | domainDst->bounds_lat_end.setValue(bounds_lat_end); |
---|
| 118 | domainDst->lat_start.setValue(bounds_lat_start + boundsLatStep/2); |
---|
| 119 | domainDst->lat_end.setValue(bounds_lat_end - boundsLatStep/2); |
---|
[727] | 120 | } |
---|
| 121 | |
---|
| 122 | if (lon_start.isEmpty() && lat_start.isEmpty()) return; |
---|
| 123 | |
---|
| 124 | if (!lon_start.isEmpty()) |
---|
| 125 | { |
---|
| 126 | int niGlo = domainDst->ni_glo.getValue(); |
---|
| 127 | |
---|
| 128 | double lonRange = lon_end - lon_start; |
---|
[734] | 129 | double lonStep = (1 == niGlo) ? lonRange : lonRange/(double(niGlo)-1); |
---|
[775] | 130 | domainDst->lon_start.setValue(lon_start); |
---|
| 131 | domainDst->lon_end.setValue(lon_end); |
---|
| 132 | domainDst->bounds_lon_start.setValue(lon_start - lonStep/2); |
---|
| 133 | domainDst->bounds_lon_end.setValue(lon_end + lonStep/2); |
---|
[727] | 134 | } |
---|
| 135 | |
---|
| 136 | if (!lat_start.isEmpty()) |
---|
| 137 | { |
---|
| 138 | int njGlo = domainDst->nj_glo.getValue(); |
---|
| 139 | |
---|
| 140 | double latRange = lat_end - lat_start; |
---|
[734] | 141 | double latStep = (1 == njGlo) ? latRange : latRange/(double(njGlo)-1); |
---|
[775] | 142 | domainDst->lat_start.setValue(lat_start); |
---|
| 143 | domainDst->lat_end.setValue(lat_end); |
---|
| 144 | domainDst->bounds_lat_start.setValue(lat_start - latStep/2); |
---|
| 145 | domainDst->bounds_lat_end.setValue(lat_end + latStep/2); |
---|
[727] | 146 | } |
---|
[687] | 147 | } |
---|
| 148 | |
---|
| 149 | } |
---|