[1985] | 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 | |
---|
[1988] | 30 | return (new CDomainAlgorithmReorder(isSource, domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], reorderDomain)); |
---|
[1985] | 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 | |
---|
[1988] | 42 | CDomainAlgorithmReorder::CDomainAlgorithmReorder(bool isSource, CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain) |
---|
[1998] | 43 | : CAlgorithmTransformationNoDataModification(isSource) |
---|
[1985] | 44 | TRY |
---|
| 45 | { |
---|
[2119] | 46 | domainDestination->type.setValue( CDomain::type_attr::rectilinear ); |
---|
| 47 | domainDestination->ni_glo = domainSource->ni_glo; |
---|
| 48 | domainDestination->nj_glo = domainSource->nj_glo; |
---|
| 49 | domainDestination->ni = domainSource->ni; |
---|
| 50 | domainDestination->nj = domainSource->nj; |
---|
| 51 | domainDestination->ibegin = domainSource->ibegin; |
---|
| 52 | domainDestination->jbegin = domainSource->jbegin; |
---|
| 53 | |
---|
[1985] | 54 | reorderDomain->checkValid(domainSource); |
---|
[2007] | 55 | domainDestination->checkAttributes() ; // for now but maybe use domainSource as template for domain destination |
---|
| 56 | |
---|
[2119] | 57 | if (domainSource->type != CDomain::type_attr::rectilinear) |
---|
[1985] | 58 | { |
---|
| 59 | ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)", |
---|
| 60 | << "Domain destination is not rectilinear. This filter work only for rectilinear domain and destination domain with < id = " |
---|
| 61 | <<domainDestination->getId() <<" > is of type "<<domainDestination->type<<std::endl); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | if (domainDestination == domainSource) |
---|
| 65 | { |
---|
| 66 | ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)", |
---|
| 67 | << "Domain source and domain destination are the same. Please make sure domain destination refers to domain source" << std::endl |
---|
| 68 | << "Domain source " <<domainSource->getId() << std::endl |
---|
| 69 | << "Domain destination " <<domainDestination->getId() << std::endl); |
---|
| 70 | } |
---|
[2011] | 71 | |
---|
[2119] | 72 | if (!reorderDomain->invert_lat.isEmpty() && reorderDomain->invert_lat.getValue() ) |
---|
[1985] | 73 | { |
---|
| 74 | CArray<int,1>& j_index=domainDestination->j_index ; |
---|
| 75 | int nglo = j_index.numElements() ; |
---|
| 76 | int nj_glo =domainDestination->nj_glo ; |
---|
| 77 | for (size_t i = 0; i < nglo ; ++i) |
---|
| 78 | { |
---|
| 79 | j_index(i)=(nj_glo-1)-j_index(i) ; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | if (!reorderDomain->shift_lon_fraction.isEmpty()) |
---|
| 84 | { |
---|
| 85 | int ni_glo =domainDestination->ni_glo ; |
---|
| 86 | int offset = ni_glo*reorderDomain->shift_lon_fraction ; |
---|
| 87 | CArray<int,1>& i_index=domainDestination->i_index ; |
---|
| 88 | int nglo = i_index.numElements() ; |
---|
| 89 | for (size_t i = 0; i < nglo ; ++i) |
---|
| 90 | { |
---|
| 91 | i_index(i)= (i_index(i)+offset+ni_glo)%ni_glo ; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | if (!reorderDomain->min_lon.isEmpty() && !reorderDomain->max_lon.isEmpty()) |
---|
| 96 | { |
---|
| 97 | double min_lon=reorderDomain->min_lon ; |
---|
| 98 | double max_lon=reorderDomain->max_lon ; |
---|
| 99 | double delta=max_lon-min_lon ; |
---|
| 100 | |
---|
| 101 | if (!domainDestination->lonvalue_1d.isEmpty() ) |
---|
| 102 | { |
---|
| 103 | CArray<double,1>& lon=domainDestination->lonvalue_1d ; |
---|
| 104 | for (int i=0;i<lon.numElements();++i) |
---|
| 105 | { |
---|
| 106 | while (lon(i) > max_lon) lon(i)=lon(i)-delta ; |
---|
| 107 | while (lon(i) < min_lon) lon(i)=lon(i)+delta ; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if (!domainDestination->bounds_lon_1d.isEmpty() ) |
---|
| 112 | { |
---|
| 113 | CArray<double,2>& bounds_lon=domainDestination->bounds_lon_1d ; |
---|
| 114 | for (int i=0;i<bounds_lon.extent(0);++i) |
---|
| 115 | { |
---|
| 116 | while (bounds_lon(0,i) > max_lon) bounds_lon(0,i)=bounds_lon(0,i)-delta ; |
---|
| 117 | while (bounds_lon(1,i) > max_lon) bounds_lon(1,i)=bounds_lon(1,i)-delta ; |
---|
| 118 | |
---|
| 119 | while (bounds_lon(0,i) < min_lon) bounds_lon(0,i)=bounds_lon(0,i)+delta ; |
---|
| 120 | while (bounds_lon(1,i) < min_lon) bounds_lon(1,i)=bounds_lon(1,i)+delta ; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
[2007] | 124 | |
---|
| 125 | domainDestination->checkAttributes() ; |
---|
[1985] | 126 | } |
---|
| 127 | CATCH |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | } |
---|