[2019] | 1 | /*! |
---|
| 2 | \file domain_algorithm_reorder.cpp |
---|
| 3 | \brief Algorithm for reorder a domain. |
---|
| 4 | */ |
---|
| 5 | #include "domain_algorithm_reorder.hpp" |
---|
| 6 | #include "reorder_domain.hpp" |
---|
| 7 | #include "domain.hpp" |
---|
| 8 | #include "grid.hpp" |
---|
| 9 | #include "grid_transformation_factory_impl.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios { |
---|
| 12 | CGenericAlgorithmTransformation* CDomainAlgorithmReorder::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
| 13 | CTransformation<CDomain>* transformation, |
---|
| 14 | int elementPositionInGrid, |
---|
| 15 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 16 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 17 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 18 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 19 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 20 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
| 21 | TRY |
---|
| 22 | { |
---|
| 23 | std::vector<CDomain*> domainListDestP = gridDst->getDomains(); |
---|
| 24 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
| 25 | |
---|
| 26 | CReorderDomain* reorderDomain = dynamic_cast<CReorderDomain*> (transformation); |
---|
| 27 | int domainDstIndex = elementPositionInGridDst2DomainPosition[elementPositionInGrid]; |
---|
| 28 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
| 29 | |
---|
| 30 | return (new CDomainAlgorithmReorder(isSource, domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], reorderDomain)); |
---|
| 31 | } |
---|
| 32 | CATCH |
---|
| 33 | |
---|
| 34 | bool CDomainAlgorithmReorder::dummyRegistered_ = CDomainAlgorithmReorder::registerTrans(); |
---|
| 35 | bool CDomainAlgorithmReorder::registerTrans() |
---|
| 36 | TRY |
---|
| 37 | { |
---|
| 38 | return CGridTransformationFactory<CDomain>::registerTransformation(TRANS_REORDER_DOMAIN, create); |
---|
| 39 | } |
---|
| 40 | CATCH |
---|
| 41 | |
---|
| 42 | CDomainAlgorithmReorder::CDomainAlgorithmReorder(bool isSource, CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain) |
---|
| 43 | : CAlgorithmTransformationNoDataModification(isSource) |
---|
| 44 | TRY |
---|
| 45 | { |
---|
| 46 | reorderDomain->checkValid(domainSource); |
---|
[2030] | 47 | domainDestination->type = domainSource->type; |
---|
| 48 | domainDestination->ni_glo.setValue(domainSource->ni_glo.getValue()); |
---|
| 49 | domainDestination->nj_glo.setValue(domainSource->nj_glo.getValue()); |
---|
[2019] | 50 | domainDestination->checkAttributes() ; // for now but maybe use domainSource as template for domain destination |
---|
| 51 | |
---|
| 52 | if (domainDestination->type != CDomain::type_attr::rectilinear) |
---|
| 53 | { |
---|
| 54 | ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)", |
---|
| 55 | << "Domain destination is not rectilinear. This filter work only for rectilinear domain and destination domain with < id = " |
---|
| 56 | <<domainDestination->getId() <<" > is of type "<<domainDestination->type<<std::endl); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if (domainDestination == domainSource) |
---|
| 60 | { |
---|
| 61 | ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)", |
---|
| 62 | << "Domain source and domain destination are the same. Please make sure domain destination refers to domain source" << std::endl |
---|
| 63 | << "Domain source " <<domainSource->getId() << std::endl |
---|
| 64 | << "Domain destination " <<domainDestination->getId() << std::endl); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if (!reorderDomain->invert_lat.isEmpty()) |
---|
| 68 | { |
---|
| 69 | CArray<int,1>& j_index=domainDestination->j_index ; |
---|
| 70 | int nglo = j_index.numElements() ; |
---|
| 71 | int nj_glo =domainDestination->nj_glo ; |
---|
| 72 | |
---|
| 73 | for (size_t i = 0; i < nglo ; ++i) |
---|
| 74 | { |
---|
| 75 | j_index(i)=(nj_glo-1)-j_index(i) ; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if (!reorderDomain->shift_lon_fraction.isEmpty()) |
---|
| 80 | { |
---|
| 81 | int ni_glo =domainDestination->ni_glo ; |
---|
| 82 | int offset = ni_glo*reorderDomain->shift_lon_fraction ; |
---|
| 83 | CArray<int,1>& i_index=domainDestination->i_index ; |
---|
| 84 | int nglo = i_index.numElements() ; |
---|
| 85 | |
---|
| 86 | for (size_t i = 0; i < nglo ; ++i) |
---|
| 87 | { |
---|
| 88 | i_index(i)= (i_index(i)+offset+ni_glo)%ni_glo ; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | if (!reorderDomain->min_lon.isEmpty() && !reorderDomain->max_lon.isEmpty()) |
---|
| 93 | { |
---|
| 94 | double min_lon=reorderDomain->min_lon ; |
---|
| 95 | double max_lon=reorderDomain->max_lon ; |
---|
| 96 | double delta=max_lon-min_lon ; |
---|
| 97 | |
---|
| 98 | if (!domainDestination->lonvalue_1d.isEmpty() ) |
---|
| 99 | { |
---|
| 100 | CArray<double,1>& lon=domainDestination->lonvalue_1d ; |
---|
| 101 | for (int i=0;i<lon.numElements();++i) |
---|
| 102 | { |
---|
| 103 | while (lon(i) > max_lon) lon(i)=lon(i)-delta ; |
---|
| 104 | while (lon(i) < min_lon) lon(i)=lon(i)+delta ; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | if (!domainDestination->bounds_lon_1d.isEmpty() ) |
---|
| 109 | { |
---|
| 110 | CArray<double,2>& bounds_lon=domainDestination->bounds_lon_1d ; |
---|
| 111 | for (int i=0;i<bounds_lon.extent(0);++i) |
---|
| 112 | { |
---|
| 113 | while (bounds_lon(0,i) > max_lon) bounds_lon(0,i)=bounds_lon(0,i)-delta ; |
---|
| 114 | while (bounds_lon(1,i) > max_lon) bounds_lon(1,i)=bounds_lon(1,i)-delta ; |
---|
| 115 | |
---|
| 116 | while (bounds_lon(0,i) < min_lon) bounds_lon(0,i)=bounds_lon(0,i)+delta ; |
---|
| 117 | while (bounds_lon(1,i) < min_lon) bounds_lon(1,i)=bounds_lon(1,i)+delta ; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | domainDestination->checkAttributes() ; |
---|
| 123 | } |
---|
| 124 | CATCH |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | } |
---|