Index: XIOS/trunk/src/node/domain.cpp
===================================================================
--- XIOS/trunk/src/node/domain.cpp	(revision 665)
+++ XIOS/trunk/src/node/domain.cpp	(revision 666)
@@ -138,7 +138,4 @@
      checkLocalIDomain();
      checkLocalJDomain();
-
-     ibegin_client = ibegin; ni_client = ni; iend_client = ibegin + ni - 1;
-     jbegin_client = jbegin; nj_client = nj; jend_client = jbegin + nj - 1;
 
      if (i_index.isEmpty())
@@ -340,5 +337,5 @@
             data_i_index.resize(dni) ;
             data_j_index.resize(dni) ;
-            data_n_index.setValue(dni);
+
             for (int i = 0; i < dni; ++i)
             {
@@ -353,6 +350,4 @@
             data_j_index.resize(dni) ;
 
-            data_n_index.setValue(dni);
-
             for(int count = 0, j = 0; j  < data_nj.getValue(); ++j)
             {
@@ -367,33 +362,12 @@
    }
 
-   void CDomain::completeLonClient()
+   //----------------------------------------------------------------
+   void CDomain::completeLonLatClient(void)
    {
      int i,j,k ;
      CArray<double,1> lonvalue_temp(ni*nj) ;
      CArray<double,2> bounds_lon_temp(nvertex,ni*nj);
-
-     if (!lonvalue_1d.isEmpty() && !lonvalue_2d.isEmpty())
-       ERROR("CDomain::completeLonLatClient(void)",
-            <<"Only one longitude value can be used but both lonvalue_1d and lonvalue_2d are defined! "<<endl
-            <<"Define only one longitude value: lonvalue_1d or lonvalue_2d ");
-
-     if (!lonvalue_1d.isEmpty() && lonvalue_2d.isEmpty())
-     {
-       if (lonvalue_1d.numElements() != i_index.numElements())
-         ERROR("CDomain::completeLonLatClient(void)",
-               <<"lonvalue_1d has not the same size as the local domain"<<endl
-               <<"Local size is "<<i_index.numElements()<<endl
-               <<"lonvalue_1d size is "<<lonvalue_1d.numElements());
-     }
-
-     if (lonvalue_1d.isEmpty() && !lonvalue_2d.isEmpty())
-     {
-        if ((lonvalue_2d.extent(0) != ni) ||
-            (lonvalue_2d.extent(1) != nj))
-           ERROR("CDomain::completeLonLatClient(void)",
-                 <<"the lonvalue has not the same size as the local domain"<<endl
-                 <<"Local size is "<<ni<<"x"<<nj<<endl
-                 <<"Lonvalue size is "<<lonvalue_2d.extent(0)<<"x"<<lonvalue_2d.extent(1));
-     }
+     CArray<double,1> latvalue_temp(ni*nj) ;
+     CArray<double,2> bounds_lat_temp(nvertex,ni*nj);
 
      if (!lonvalue_2d.isEmpty())
@@ -403,8 +377,13 @@
           {
             lonvalue_temp(i+j*ni) = lonvalue_2d(i,j);
+            latvalue_temp(i+j*ni) = latvalue_2d(i,j);
             if (hasBounds)
             {
               k=j*ni+i;
-              for(int n=0;n<nvertex;++n) bounds_lon_temp(n,k) = bounds_lon_2d(n,i,j);
+              for(int n=0;n<nvertex;++n)
+              {
+                bounds_lon_temp(n,k) = bounds_lon_2d(n,i,j);
+                bounds_lat_temp(n,k) = bounds_lat_2d(n,i,j);
+              }
             }
           }
@@ -415,5 +394,5 @@
        if (type_attr::rectilinear == type)
        {
-         if (ni == lonvalue_1d.numElements())
+         if ((ni == lonvalue_1d.numElements()) && (nj == latvalue_1d.numElements()))
          {
            for(j=0;j<nj;++j)
@@ -422,7 +401,12 @@
                k=j*ni+i;
                lonvalue_temp(k) = lonvalue_1d(i);
+               latvalue_temp(k) = latvalue_1d(j);
                if (hasBounds)
                {
-                 for(int n=0;n<nvertex;++n) bounds_lon_temp(n,k) = bounds_lon_1d(n,i);
+                 for(int n=0;n<nvertex;++n)
+                 {
+                   bounds_lon_temp(n,k) = bounds_lon_1d(n,i);
+                   bounds_lat_temp(n,k) = bounds_lat_1d(n,j);
+                 }
                }
              }
@@ -430,117 +414,16 @@
           else
             ERROR("CDomain::completeLonClient(void)",
-                 <<"The lonvalue_1d has not the same size as the local domain"<<endl
-                 <<"Local size is "<<ni<<endl
-                 <<"Lonvalue_1d size is "<<lonvalue_1d.numElements());
+                 <<"lonvalue_1d and latvalue_1d has not the same size as the local domain"<<endl
+                 <<"Local size is "<<ni<<"x " << nj<< endl
+                 <<"lonvalue_1d size is "<<lonvalue_1d.numElements()
+                 <<"latvalue_1d size is "<<latvalue_1d.numElements());
        }
        else if (type==type_attr::curvilinear || type==type_attr::unstructured)
        {
          lonvalue_temp=lonvalue_1d;
+         latvalue_temp=latvalue_1d;
          if (hasBounds)
          {
            bounds_lon_temp=bounds_lon_1d;
-         }
-       }
-     }
-
-     StdSize dm = zoom_ni_client * zoom_nj_client;
-
-      // Make sure that this attribute is non-empty for every client.
-     if (0 != dm)
-     {
-       lonvalue_client.resize(dm);
-       if (hasBounds) bounds_lon_client.resize(nvertex, dm);
-     }
-
-
-     for (i = 0; i < zoom_ni_client; ++i)
-     {
-       for (j = 0; j < zoom_nj_client; ++j)
-       {
-         lonvalue_client(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni );
-         if (hasBounds)
-         {
-           for(int n=0;n<nvertex;n++)
-           {
-             bounds_lon_client(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni );
-           }
-         }
-       }
-     }
-   }
-
-   void CDomain::completeLatClient()
-   {
-     int i,j,k;
-     CArray<double,1> latvalue_temp(ni*nj) ;
-     CArray<double,2> bounds_lat_temp(nvertex,ni*nj);
-
-     if (!latvalue_1d.isEmpty() && !latvalue_2d.isEmpty())
-       ERROR("CDomain::completeLonLatClient(void)",
-            <<"Only one longitude value can be used but both latvalue_1d and latvalue_2d are defined! "<<endl
-            <<"Define only one longitude value: latvalue_1d or latvalue_2d ");
-
-     if (!latvalue_1d.isEmpty() && latvalue_2d.isEmpty())
-     {
-       if (latvalue_1d.numElements() != i_index.numElements())
-         ERROR("CDomain::completeLonLatClient(void)",
-               <<"the latvalue_1d has not the same size as the local domain"<<endl
-               <<"Local size is "<<i_index.numElements()<<endl
-               <<"Mask size is "<<latvalue_1d.numElements());
-     }
-
-     if (latvalue_1d.isEmpty() && !latvalue_2d.isEmpty())
-     {
-        if ((latvalue_2d.extent(0) != ni) ||
-            (latvalue_2d.extent(1) != nj))
-           ERROR("CDomain::completeLonLatClient(void)",
-                 <<"the mask has not the same size as the local domain"<<endl
-                 <<"Local size is "<<ni<<"x"<<nj<<endl
-                 <<"Mask size is "<<latvalue_2d.extent(0)<<"x"<<latvalue_2d.extent(1));
-     }
-
-     if (!latvalue_2d.isEmpty())
-     {
-        for (j = 0; j < nj; ++j)
-          for (i = 0; i < ni; ++i)
-          {
-            latvalue_temp(i+j*ni) = latvalue_2d(i,j);
-            if (hasBounds)
-            {
-              k=j*ni+i;
-              for(int n=0;n<nvertex;n++) bounds_lat_temp(n,k) = bounds_lat_2d(n,i,j);
-            }
-          }
-     }
-
-     if (!latvalue_1d.isEmpty())
-     {
-       if (type_attr::rectilinear == type)
-       {
-
-         if (nj == latvalue_1d.numElements())
-         {
-           for(j=0;j<nj;++j)
-             for(i=0;i<ni;++i)
-             {
-               k=j*ni+i;
-               latvalue_temp(k) = latvalue_1d(j);
-               if (hasBounds)
-               {
-                 for(int n=0;n<nvertex;n++) bounds_lat_temp(n,k) = bounds_lat_1d(n,j);
-               }
-             }
-          }
-          else
-            ERROR("CDomain::completeLonClient(void)",
-                 <<"The latvalue_1d has not the same size as the local domain"<<endl
-                 <<"Local size is "<<nj<<endl
-                 <<"Latvalue_1d size is "<<latvalue_1d.numElements());
-       }
-       else if (type==type_attr::curvilinear || type==type_attr::unstructured)
-       {
-         latvalue_temp=latvalue_1d;
-         if (hasBounds)
-         {
            bounds_lat_temp=bounds_lat_1d;
          }
@@ -548,52 +431,54 @@
      }
 
-     StdSize dm = zoom_ni_client * zoom_nj_client;
+    int i_ind,j_ind;
+    int global_zoom_iend=global_zoom_ibegin+global_zoom_ni-1;
+    int global_zoom_jend=global_zoom_jbegin+global_zoom_nj-1;
+
+    int globalIndexCountZoom = 0;
+    int nbIndex = i_index.numElements();
+    for (i = 0; i < nbIndex; ++i)
+    {
+      i_ind=i_index(i);
+      j_ind=j_index(i);
+
+      if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend)
+      {
+        ++globalIndexCountZoom;
+      }
+    }
 
       // Make sure that this attribute is non-empty for every client.
-     if (0 != dm)
-     {
-       latvalue_client.resize(dm);
-       if (hasBounds) bounds_lat_client.resize(nvertex,dm);
-     }
-
-     for (i = 0; i < zoom_ni_client; i++)
-     {
-       for (j = 0; j < zoom_nj_client; j++)
+     if (0 != globalIndexCountZoom)
+     {
+       lonvalue_client.resize(globalIndexCountZoom);
+       latvalue_client.resize(globalIndexCountZoom);
+       if (hasBounds)
        {
-         latvalue_client(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni );
+         bounds_lon_client.resize(nvertex,globalIndexCountZoom);
+         bounds_lat_client.resize(nvertex,globalIndexCountZoom);
+       }
+     }
+
+     int nCountZoom = 0;
+     for (i = 0; i < nbIndex; ++i)
+     {
+       i_ind=i_index(i);
+       j_ind=j_index(i);
+
+       if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend)
+       {
+         lonvalue_client(nCountZoom) = lonvalue_temp(i);
+         latvalue_client(nCountZoom) = latvalue_temp(i);
          if (hasBounds)
          {
-           for(int n=0;n<nvertex;n++)
+           for (int n = 0; n < nvertex; ++n)
            {
-             bounds_lat_client(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni );
+             bounds_lon_client(n,nCountZoom) = bounds_lon_temp(n,i);
+             bounds_lat_client(n,nCountZoom) = bounds_lat_temp(n,i);
            }
          }
+         ++nCountZoom;
        }
      }
-   }
-
-   //----------------------------------------------------------------
-   void CDomain::completeLonLatClient(void)
-   {
-     completeLonClient();
-     completeLatClient();
-   }
-
-
-   //----------------------------------------------------------------
-   void CDomain::checkZoom(void)
-   {
-      int global_zoom_iend=global_zoom_ibegin+global_zoom_ni-1 ;
-      zoom_ibegin_client = ibegin_client > global_zoom_ibegin ? ibegin_client : global_zoom_ibegin ;
-      zoom_iend_client = iend_client < global_zoom_iend ? iend_client : global_zoom_iend ;
-      zoom_ni_client=zoom_iend_client-zoom_ibegin_client+1 ;
-      if (zoom_ni_client<0) zoom_ni_client=0 ;
-
-
-      int global_zoom_jend=global_zoom_jbegin+global_zoom_nj-1 ;
-      zoom_jbegin_client = jbegin_client > global_zoom_jbegin ? jbegin_client : global_zoom_jbegin ;
-      zoom_jend_client = jend_client < global_zoom_jend ? jend_client : global_zoom_jend ;
-      zoom_nj_client=zoom_jend_client-zoom_jbegin_client+1 ;
-      if (zoom_nj_client<0) zoom_nj_client=0;
    }
 
@@ -691,4 +576,54 @@
      hasLonLat = (!latvalue_1d.isEmpty() && !lonvalue_1d.isEmpty()) ||
                  (!latvalue_2d.isEmpty() && !lonvalue_2d.isEmpty());
+     if (hasLonLat)
+     {
+       if (!lonvalue_1d.isEmpty() && !lonvalue_2d.isEmpty())
+         ERROR("CDomain::completeLonLatClient(void)",
+              <<"Only one longitude value can be used but both lonvalue_1d and lonvalue_2d are defined! "<<endl
+              <<"Define only one longitude value: lonvalue_1d or lonvalue_2d ");
+
+       if (!lonvalue_1d.isEmpty() && lonvalue_2d.isEmpty())
+       {
+         if (lonvalue_1d.numElements() != i_index.numElements())
+           ERROR("CDomain::completeLonLatClient(void)",
+                 <<"lonvalue_1d has not the same size as the local domain"<<endl
+                 <<"Local size is "<<i_index.numElements()<<endl
+                 <<"lonvalue_1d size is "<<lonvalue_1d.numElements());
+       }
+
+       if (lonvalue_1d.isEmpty() && !lonvalue_2d.isEmpty())
+       {
+          if ((lonvalue_2d.extent(0) != ni) ||
+              (lonvalue_2d.extent(1) != nj))
+             ERROR("CDomain::completeLonLatClient(void)",
+                   <<"the lonvalue has not the same size as the local domain"<<endl
+                   <<"Local size is "<<ni<<"x"<<nj<<endl
+                   <<"Lonvalue size is "<<lonvalue_2d.extent(0)<<"x"<<lonvalue_2d.extent(1));
+       }
+
+       if (!latvalue_1d.isEmpty() && !latvalue_2d.isEmpty())
+         ERROR("CDomain::completeLonLatClient(void)",
+              <<"Only one longitude value can be used but both latvalue_1d and latvalue_2d are defined! "<<endl
+              <<"Define only one longitude value: latvalue_1d or latvalue_2d ");
+
+       if (!latvalue_1d.isEmpty() && latvalue_2d.isEmpty())
+       {
+         if (latvalue_1d.numElements() != i_index.numElements())
+           ERROR("CDomain::completeLonLatClient(void)",
+                 <<"the latvalue_1d has not the same size as the local domain"<<endl
+                 <<"Local size is "<<i_index.numElements()<<endl
+                 <<"Mask size is "<<latvalue_1d.numElements());
+       }
+
+       if (latvalue_1d.isEmpty() && !latvalue_2d.isEmpty())
+       {
+          if ((latvalue_2d.extent(0) != ni) ||
+              (latvalue_2d.extent(1) != nj))
+             ERROR("CDomain::completeLonLatClient(void)",
+                   <<"the mask has not the same size as the local domain"<<endl
+                   <<"Local size is "<<ni<<"x"<<nj<<endl
+                   <<"Mask size is "<<latvalue_2d.extent(0)<<"x"<<latvalue_2d.extent(1));
+       }
+     }
    }
 
@@ -697,5 +632,4 @@
      CContext* context=CContext::getCurrent() ;
 
-     this->checkZoom();
      if (this->isClientAfterTransformationChecked) return;
      if (context->hasClient)
@@ -742,5 +676,4 @@
      CContext* context=CContext::getCurrent() ;
 
-     this->checkZoom();
      if (this->isChecked) return;
      if (context->hasClient)
@@ -759,5 +692,4 @@
 
       this->checkDomain();
-      this->checkZoom();
       this->checkLonLat();
       this->checkBounds();
@@ -769,5 +701,5 @@
          this->checkDomainData();
          this->checkCompression();
-         this->completeLonLatClient();
+
       }
       else
@@ -777,7 +709,8 @@
       if (context->hasClient)
       {
-        computeConnectedServer() ;
-        sendServerAttribut() ;
-        sendLonLatArea() ;
+        this->computeConnectedServer();
+        this->completeLonLatClient();
+        this->sendServerAttribut();
+        this->sendLonLatArea();
       }
 
@@ -837,7 +770,4 @@
   void CDomain::computeConnectedServer(void)
   {
-    ibegin_client=ibegin; ni_client=ni; iend_client=ibegin_client + ni_client - 1;
-    jbegin_client=jbegin; nj_client=nj; jend_client=jbegin_client + nj_client - 1;
-
     CContext* context=CContext::getCurrent() ;
     CContextClient* client=context->client ;
@@ -846,6 +776,6 @@
 
     int i,j,i_ind,j_ind, nbIndex;
-    int zoom_iend=global_zoom_ibegin+global_zoom_ni-1 ;
-    int zoom_jend=global_zoom_jbegin+global_zoom_nj-1 ;
+    int global_zoom_iend=global_zoom_ibegin+global_zoom_ni-1 ;
+    int global_zoom_jend=global_zoom_jbegin+global_zoom_nj-1 ;
 
     // Precompute number of index
@@ -857,5 +787,5 @@
       j_ind=j_index(i);
 
-      if (i_ind >= global_zoom_ibegin && i_ind <= zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= zoom_jend)
+      if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend)
       {
         ++globalIndexCountZoom;
@@ -878,5 +808,5 @@
       globalIndexDomain(globalIndexCount) = globalIndex;
       ++globalIndexCount;
-      if (i_ind >= global_zoom_ibegin && i_ind <= zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= zoom_jend)
+      if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend)
       {
         globalIndexDomainZoom(globalIndexCountZoom) = globalIndex;
@@ -1076,10 +1006,6 @@
       {
         idx = static_cast<int>(it->second[n]);
-        i = i_index(idx);
-        j = j_index(idx);
-        ind = (i - zoom_ibegin_client) + (j - zoom_jbegin_client) * zoom_ni_client;
-
-        lon(n) = lonvalue_client(ind);
-        lat(n) = latvalue_client(ind);
+        lon(n) = lonvalue_client(idx);
+        lat(n) = latvalue_client(idx);
 
         if (hasBounds)
@@ -1088,8 +1014,8 @@
           CArray<double,2>& boundslat = list_boundslat.back();
 
-          for (nv = 0; nv < nvertex; nv++)
+          for (nv = 0; nv < nvertex; ++nv)
           {
-            boundslon(nv, n) = bounds_lon_client(nv, ind);
-            boundslat(nv, n) = bounds_lat_client(nv, ind);
+            boundslon(nv, n) = bounds_lon_client(nv, idx);
+            boundslat(nv, n) = bounds_lat_client(nv, idx);
           }
         }
@@ -1252,5 +1178,5 @@
       if (hasBounds)
       {
-        for (int nv = 0; nv < nvertex; nv++)
+        for (int nv = 0; nv < nvertex; ++nv)
           bounds_lon_srv(nv, ind_srv) = boundslon(nv, ind);
       }
