Ignore:
Timestamp:
09/08/10 15:02:31 (14 years ago)
Author:
hozdoba
Message:

Mise à jour intermédiaire ...
A venir : commit d'une version stable intégrant l'écriture de fichiers NetCDF4.
(en cours de finalisation actuellement)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/grid.hpp

    r114 r120  
    77namespace XMLIOSERVER 
    88{ 
    9    class CGrid: public ObjectTemplate<CGrid>, public GridAttribut 
     9   class CGrid : public ObjectTemplate<CGrid>, public GridAttribut 
    1010   { 
    1111      public: 
    1212 
    13          CGrid(void) : ObjectTemplate<CGrid>(), GridAttribut() 
    14          {/* Ne rien faire de plus */} 
    15          CGrid(const string& _id) : ObjectTemplate<CGrid>(_id), GridAttribut() 
    16          {/* Ne rien faire de plus */} 
     13         CGrid(void) : ObjectTemplate<CGrid>(), GridAttribut(), hasAxis(false), axis(NULL), domain(NULL) 
     14         { /* Ne rien faire de plus */ } 
     15         CGrid(const string& _id) : ObjectTemplate<CGrid>(_id), GridAttribut(), hasAxis(false), axis(NULL), domain(NULL) 
     16         { /* Ne rien faire de plus */ } 
    1717 
    1818         static string GetName(void) { return ("grid"); } 
     19 
     20         inline void solveReference(void) ; 
     21         inline void solveDomainRef(void) ; 
     22         inline void solveAxisRef(void) ; 
     23 
     24         inline void computeIndex(void); 
     25 
     26         inline void storeField(const Array<double,1>& field, Array<double,1>& stored); 
     27         inline void storeField(const Array<double,2>& field, Array<double,1>& stored); 
     28         inline void storeField(const Array<double,3>& field, Array<double,1>& stored); 
     29         inline void storeField(const double* const data, Array<double,1>& stored); 
     30 
     31         inline void outputField(const Array<double,1>& stored, Array<double,2>& outField); 
     32         inline void outputField(const Array<double,1>& stored, Array<double,3>& outField); 
     33 
     34         inline static CGrid* CreateObject(const CDomain* const a_domain, const CAxis* const a_axis); 
     35         inline static CGrid* CreateObject(const CDomain* const a_domain); 
    1936 
    2037         virtual ~CGrid(void) 
    2138         { /* Ne rien faire de plus */ } 
    2239 
     40 
     41      private: 
     42 
     43         bool hasAxis ; 
     44 
     45         CAxis* axis ; 
     46         CDomain* domain ; 
     47 
     48         Array<int,1> storeIndex ; 
     49         Array<int,1> out_i_index ; 
     50         Array<int,1> out_j_index ; 
     51         Array<int,1> out_l_index ; 
     52 
    2353   }; // class CGrid 
    2454 
     55 
     56   CGrid* CGrid::CreateObject(const CDomain* const a_domain, const CAxis* const a_axis) 
     57   { 
     58      string new_id = string("___") + a_domain->getId() + string("_") + a_axis->getId() + string("__") ; 
     59      CGrid* const grid = ObjectTemplate<CGrid>::CreateObject(new_id) ; 
     60 
     61      grid->domain_ref = a_domain->getId() ; 
     62      grid->axis_ref = a_axis->getId() ; 
     63 
     64      return (grid); 
     65   } 
     66 
     67   CGrid* CGrid::CreateObject(const CDomain* const a_domain) 
     68   { 
     69      string new_id = string("___") + a_domain->getId() + string("__") ; 
     70      CGrid* const grid = ObjectTemplate<CGrid>::CreateObject(new_id) ; 
     71 
     72      grid->domain_ref = a_domain->getId() ; 
     73 
     74      return (grid); 
     75   } 
     76 
     77   void CGrid::solveReference(void) 
     78   { 
     79      static bool isReferenceSolved = false; 
     80      if (isReferenceSolved) return; 
     81 
     82      // Résolution de chacune des références et indexation. 
     83      solveDomainRef() ; 
     84      solveAxisRef() ; 
     85      computeIndex() ; 
     86 
     87      isReferenceSolved = true ; 
     88   } 
     89 
     90   void CGrid::solveDomainRef(void) 
     91   { 
     92      if (domain_ref.hasValue()) 
     93      { 
     94         if (CDomain::HasObject(domain_ref)) 
     95         { 
     96           domain=CDomain::GetObject(domain_ref) ; 
     97           domain->check() ; 
     98         } 
     99         else ERROR("Référence au domaine incorrecte") ; 
     100      } 
     101      else ERROR("Domaine non défini") ; 
     102   } 
     103 
     104   void CGrid::solveAxisRef(void) 
     105   { 
     106      if (axis_ref.hasValue()) 
     107      { 
     108         hasAxis = true ; 
     109         if (CAxis::HasObject(axis_ref)) axis = CAxis::GetObject(axis_ref) ; 
     110         else ERROR("Référence a l'axe incorrecte") ; 
     111      } 
     112      else hasAxis = false ; // hasAxis est normalement déjà à false(?). 
     113   } 
     114 
     115   void CGrid::computeIndex(void) 
     116   { 
     117      int ni = domain->ni ; 
     118      int nj = domain->nj ; 
     119      int size = (hasAxis) ? (int)axis->size : 1 ; 
     120      int data_dim = domain->data_dim ; 
     121      int data_n_index = domain->data_n_index ; 
     122      int data_ibegin  = domain->data_ibegin ; 
     123      int data_jbegin  = (data_dim == 2) ? (int)domain->data_jbegin : -1; 
     124 
     125      Array<int,1>& data_i_index =* domain->data_i_index ; 
     126      Array<int,1>& data_j_index =* domain->data_j_index ; 
     127      Array<bool,2>& mask =* domain->mask ; 
     128      int i, j, l, n ; 
     129      int count, indexCount ; 
     130 
     131      for(indexCount=0, l=0; l<size ; l++) 
     132      { 
     133         for(n=0, indexCount=0; n<data_n_index; n++) 
     134         { 
     135            if (data_dim == 1) 
     136            { 
     137               i = (data_i_index(n) + data_ibegin) % ni ; 
     138               j = (data_i_index(n) + data_ibegin) / ni ; 
     139               cout<<i<<" "<<j<<" "<<mask(i,j)<<endl ; 
     140            } 
     141            else 
     142            { 
     143               i = data_i_index(n) + data_ibegin ; 
     144               j = data_j_index(n) + data_jbegin ; 
     145               cout<<i<<" "<<j<<" "<<mask(i,j)<<endl ; 
     146            } 
     147 
     148            if (i>=0 && i<ni && j>=0 && j<nj && mask(i,j) ) indexCount++ ; 
     149         } 
     150      } 
     151 
     152      storeIndex.resize(indexCount) ; 
     153      out_l_index.resize(indexCount) ; 
     154      out_i_index.resize(indexCount) ; 
     155      out_j_index.resize(indexCount) ; 
     156 
     157      for(count=0, indexCount=0, l=0; l<size; l++) 
     158      { 
     159         for(n=0; n<data_n_index; n++) 
     160         { 
     161            if (data_dim == 1) 
     162            { 
     163               i = (data_i_index(n) + data_ibegin) % ni ; 
     164               j = (data_i_index(n) + data_ibegin) / ni ; 
     165            } 
     166            else 
     167            { 
     168               i = data_i_index(n) + data_ibegin ; 
     169               j = data_j_index(n) + data_jbegin ; 
     170            } 
     171 
     172            if (i>=0 && i<ni && j>=0 && j<nj && mask(i,j)) 
     173            { 
     174               storeIndex(indexCount) = n ; 
     175               out_l_index(indexCount) = l ; 
     176               out_i_index(indexCount) = i ; 
     177               out_j_index(indexCount) = j ; 
     178               indexCount++ ; 
     179            } 
     180            count++ ; 
     181         } 
     182      } 
     183 
     184      cout << "Out of CGrid::ComputeIndex" << endl ; 
     185      cout << storeIndex << endl ; 
     186      cout << out_i_index << endl ; 
     187      cout << out_j_index << endl ; 
     188      cout << out_l_index << endl ; 
     189   } 
     190 
     191   void CGrid::storeField(const Array<double, 1>& field, Array<double, 1>& stored) 
     192   { 
     193      storeField(field.dataFirst(), stored) ; 
     194      //cout<<"Stored 1"<<stored<<endl ; 
     195   } 
     196 
     197   void CGrid::storeField(const Array<double, 2>& field, Array<double, 1>& stored) 
     198   { 
     199      storeField(field.dataFirst(), stored) ; 
     200      //cout<<"Stored 2"<<stored<<endl ; 
     201   } 
     202 
     203   void CGrid::storeField(const Array<double, 3>& field, Array<double, 1>& stored) 
     204   { 
     205      storeField(field.dataFirst(), stored) ; 
     206      //cout<<"Stored 3"<<stored<<endl ; 
     207   } 
     208 
     209   void CGrid::storeField(const double* const data, Array<double, 1>& stored) 
     210   { 
     211      int size = storeIndex.size() ; 
     212      //cout << "size " << size << endl ; 
     213 
     214      stored.resize(shape(size)) ; 
     215      //cout << "Stored " << stored << endl ; 
     216 
     217      for(int i = 0; i < size; i++) stored(i) = data[storeIndex(i)] ; 
     218      //cout << "Stored " << stored << endl ; 
     219   } 
     220 
     221   void CGrid::outputField(const Array<double, 1>& stored, Array<double, 2>& outField) 
     222   { 
     223      for(int n = 0; n < storeIndex.size(); n++) 
     224         outField(out_i_index(n), out_j_index(n)) = stored(n) ; 
     225   } 
     226 
     227   void CGrid::outputField(const Array<double, 1>& stored, Array<double, 3>& outField) 
     228   { 
     229      for(int n = 0; n < storeIndex.size(); n++) 
     230         outField(out_i_index(n), out_j_index(n), out_l_index(n)) = stored(n) ; 
     231   } 
    25232} // namespace XMLIOSERVER 
    26233 
     234 
    27235DECLARE_GROUP(Grid) 
    28236 
     237 
     238 
    29239#endif // __GRID__ 
    30240 
Note: See TracChangeset for help on using the changeset viewer.