source: XIOS/dev/XIOS_DEV_CMIP6/src/io/nc4_data_output.cpp @ 1332

Last change on this file since 1332 was 1332, checked in by oabramkina, 7 years ago

Fixing a minor bug in writing axis bounds.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:executable set to *
File size: 126.8 KB
RevLine 
[219]1#include "nc4_data_output.hpp"
2
3#include <boost/lexical_cast.hpp>
[352]4#include "attribute_template.hpp"
5#include "group_template.hpp"
[219]6
7#include "file.hpp"
8#include "calendar.hpp"
[278]9#include "context.hpp"
[300]10#include "context_server.hpp"
[498]11#include "netCdfException.hpp"
12#include "exception.hpp"
[1158]13#include "timer.hpp"
14#include "uuid.hpp"
[335]15namespace xios
[219]16{
[878]17      /// ////////////////////// Dfinitions ////////////////////// ///
[219]18      CNc4DataOutput::CNc4DataOutput
[1158]19         (CFile* file, const StdString & filename, bool exist)
[219]20            : SuperClass()
21            , SuperClassWriter(filename, exist)
22            , filename(filename)
[1158]23            , file(file),hasTimeInstant(false),hasTimeCentered(false), timeCounterType(none)
[219]24      {
[1158]25        SuperClass::type = MULTI_FILE;
[219]26      }
27
28      CNc4DataOutput::CNc4DataOutput
[1158]29         (CFile* file, const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention,
[924]30          MPI_Comm comm_file, bool multifile, bool isCollective, const StdString& timeCounterName)
[219]31            : SuperClass()
[878]32            , SuperClassWriter(filename, exist, useClassicFormat, useCFConvention, &comm_file, multifile, timeCounterName)
[379]33            , comm_file(comm_file)
[219]34            , filename(filename)
[335]35            , isCollective(isCollective)
[1158]36            , file(file),hasTimeInstant(false),hasTimeCentered(false), timeCounterType(none)
[219]37      {
[1158]38        SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
[219]39      }
40
41      CNc4DataOutput::~CNc4DataOutput(void)
[879]42    { /* Ne rien faire de plus */ }
[219]43
44      ///--------------------------------------------------------------
45
46      const StdString & CNc4DataOutput::getFileName(void) const
47      {
48         return (this->filename);
49      }
50
51      //---------------------------------------------------------------
52
[347]53      void CNc4DataOutput::writeDomain_(CDomain* domain)
[219]54      {
[1129]55        domain->computeWrittenIndex();
[1249]56        domain->computeWrittenCompressedIndex(comm_file);
57
[881]58        if (domain->type == CDomain::type_attr::unstructured)
59        {
60          if (SuperClassWriter::useCFConvention)
61            writeUnstructuredDomain(domain) ;
62          else
63            writeUnstructuredDomainUgrid(domain) ;
64          return ;
65        }
[488]66
[347]67         CContext* context = CContext::getCurrent() ;
[300]68         CContextServer* server=context->server ;
[488]69
[219]70         if (domain->IsWritten(this->filename)) return;
71         domain->checkAttributes();
[488]72
73         if (domain->isEmpty())
[881]74           if (SuperClass::type==MULTI_FILE) return;
[219]75
76         std::vector<StdString> dim0, dim1;
[772]77         StdString domid = domain->getDomainOutputName();
[318]78         StdString appendDomid  = (singleDomain) ? "" : "_"+domid ;
[706]79         if (isWrittenDomain(domid)) return ;
[774]80         else setWrittenDomain(domid);
[1132]81       
82         int nvertex = (domain->nvertex.isEmpty()) ? 0 : domain->nvertex;
[449]83
[488]84
[1158]85        StdString dimXid, dimYid ;
86
87        nc_type typePrec ;
88        if (domain->prec.isEmpty()) typePrec =  NC_FLOAT ;
89        else if (domain->prec==4)  typePrec =  NC_FLOAT ;
90        else if (domain->prec==8)   typePrec =  NC_DOUBLE ;
91         
[664]92         bool isRegularDomain = (domain->type == CDomain::type_attr::rectilinear);
[449]93         switch (domain->type)
[433]94         {
[449]95           case CDomain::type_attr::curvilinear :
96             dimXid     = StdString("x").append(appendDomid);
97             dimYid     = StdString("y").append(appendDomid);
98             break ;
[664]99           case CDomain::type_attr::rectilinear :
[449]100             dimXid     = StdString("lon").append(appendDomid);
101             dimYid     = StdString("lat").append(appendDomid);
102             break;
[488]103         }
104
[617]105         StdString dimVertId = StdString("nvertex").append(appendDomid);
106
[449]107         string lonid,latid,bounds_lonid,bounds_latid ;
[611]108         string areaId = "area" + appendDomid;
[391]109/*
[300]110         StdString lonid_loc = (server->intraCommSize > 1)
[318]111                             ? StdString("lon").append(appendDomid).append("_local")
[278]112                             : lonid;
[300]113         StdString latid_loc = (server->intraCommSize > 1)
[318]114                             ? StdString("lat").append(appendDomid).append("_local")
[278]115                             : latid;
[391]116*/
[219]117
[1129]118         CArray<size_t, 1>& indexToWrite = domain->localIndexToWriteOnServer;
119         int nbWritten = indexToWrite.numElements();
120         CArray<double,1> writtenLat, writtenLon;
121         CArray<double,2> writtenBndsLat, writtenBndsLon;
122         CArray<double,1> writtenArea;
123
124         if (domain->hasLonLat)
125         {
126           writtenLat.resize(nbWritten);
127           writtenLon.resize(nbWritten);
128           for (int idx = 0; idx < nbWritten; ++idx)
129           {
130              writtenLat(idx) = domain->latvalue(indexToWrite(idx));
131              writtenLon(idx) = domain->lonvalue(indexToWrite(idx));
132           }
133         
134
135           if (domain->hasBounds)
136           {         
137             int nvertex = domain->nvertex, idx;
138             writtenBndsLat.resize(nvertex, nbWritten);
139             writtenBndsLon.resize(nvertex, nbWritten);
140             CArray<double,2>& boundslat = domain->bounds_latvalue;
141             CArray<double,2>& boundslon = domain->bounds_lonvalue;   
142             for (idx = 0; idx < nbWritten; ++idx)
143               for (int nv = 0; nv < nvertex; ++nv)
144               {
145                 writtenBndsLat(nv, idx) = boundslat(nv, int(indexToWrite(idx)));
146                 writtenBndsLon(nv, idx) = boundslon(nv, int(indexToWrite(idx)));
147               }
148           }
149         }
150
151         if (domain->hasArea)
152         {
153           writtenArea.resize(nbWritten);           
154           for (int idx = 0; idx < nbWritten; ++idx)
155           {
156              writtenArea(idx) = domain->areavalue(indexToWrite(idx));                     
157           }
158         }
159
[498]160         try
[219]161         {
[498]162           switch (SuperClass::type)
163           {
164              case (MULTI_FILE) :
165              {
166  //               if (domain->isEmpty()) return;
[488]167
[498]168                 if (server->intraCommSize > 1)
169                 {
170  //                 SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
171  //                 SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
172                 }
[286]173
[498]174                 switch (domain->type)
175                 {
176                   case CDomain::type_attr::curvilinear :
177                     dim0.push_back(dimYid); dim0.push_back(dimXid);
178                     lonid = StdString("nav_lon").append(appendDomid);
179                     latid = StdString("nav_lat").append(appendDomid);
180                     break ;
[664]181                   case CDomain::type_attr::rectilinear :
[498]182                     lonid = StdString("lon").append(appendDomid);
183                     latid = StdString("lat").append(appendDomid);
184                     dim0.push_back(dimYid);
185                     dim1.push_back(dimXid);
186                     break;
187                 }
[488]188
[617]189                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
190                 bounds_latid = StdString("bounds_lat").append(appendDomid);
191
[1099]192                 SuperClassWriter::addDimension(dimXid, domain->zoom_ni);
193                 SuperClassWriter::addDimension(dimYid, domain->zoom_nj);
[488]194
[617]195                 if (domain->hasBounds)
196                   SuperClassWriter::addDimension(dimVertId, domain->nvertex);
197
[498]198                 if (server->intraCommSize > 1)
199                 {
[1099]200                   this->writeLocalAttributes(domain->zoom_ibegin,
201                                              domain->zoom_ni,
202                                              domain->zoom_jbegin,
203                                              domain->zoom_nj,
[616]204                                              appendDomid);
[488]205
[628]206                   if (singleDomain)
207                    this->writeLocalAttributes_IOIPSL(dimXid, dimYid,
[1099]208                                                      domain->zoom_ibegin,
209                                                      domain->zoom_ni,
210                                                      domain->zoom_jbegin,
211                                                      domain->zoom_nj,
[628]212                                                      domain->ni_glo,domain->nj_glo,
213                                                      server->intraCommRank,server->intraCommSize);
[449]214                 }
[488]215
[665]216                 if (domain->hasLonLat)
[498]217                 {
[665]218                   switch (domain->type)
219                   {
220                     case CDomain::type_attr::curvilinear :
[1158]221                       SuperClassWriter::addVariable(latid, typePrec, dim0);
222                       SuperClassWriter::addVariable(lonid, typePrec, dim0);
[665]223                       break ;
224                      case CDomain::type_attr::rectilinear :
[1158]225                        SuperClassWriter::addVariable(latid, typePrec, dim0);
226                        SuperClassWriter::addVariable(lonid, typePrec, dim1);
[665]227                        break ;
228                   }
[488]229
[665]230                   this->writeAxisAttributes(lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid);
231                   this->writeAxisAttributes(latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid);
[219]232
[665]233                   if (domain->hasBounds)
234                   {
235                     SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid);
236                     SuperClassWriter::addAttribute("bounds", bounds_latid, &latid);
[617]237
[665]238                     dim0.clear();
239                     dim0.push_back(dimYid);
240                     dim0.push_back(dimXid);
241                     dim0.push_back(dimVertId);
[1158]242                     SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0);
243                     SuperClassWriter::addVariable(bounds_latid, typePrec, dim0);
[665]244                   }
[617]245                 }
246
[498]247                 dim0.clear();
[616]248                 dim0.push_back(dimYid);
[498]249                 dim0.push_back(dimXid);
[219]250
251
[498]252  // supress mask               if (server->intraCommSize > 1)
253  // supress mask               {
254  // supress mask                  SuperClassWriter::addVariable(maskid, NC_INT, dim0);
255  // supress mask
256  // supress mask                  this->writeMaskAttributes(maskid,
257  // supress mask                     domain->data_dim.getValue()/*,
258  // supress mask                     domain->data_ni.getValue(),
259  // supress mask                     domain->data_nj.getValue(),
260  // supress mask                     domain->data_ibegin.getValue(),
261  // supress mask                     domain->data_jbegin.getValue()*/);
262  // supress mask               }
[488]263
[498]264                 //SuperClassWriter::setDefaultValue(maskid, &dvm);
[219]265
[611]266                 if (domain->hasArea)
267                 {
[1158]268                   SuperClassWriter::addVariable(areaId, typePrec, dim0);
[614]269                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
[611]270                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
271                 }
272
[498]273                 SuperClassWriter::definition_end();
[449]274
[665]275                 if (domain->hasLonLat)
[498]276                 {
[665]277                   switch (domain->type)
278                   {
[1129]279                     case CDomain::type_attr::curvilinear :                       
280                       SuperClassWriter::writeData(writtenLat, latid, isCollective, 0);
281                       SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0);
[665]282                       break;
283                     case CDomain::type_attr::rectilinear :
[1129]284                       CArray<double,1> lat = writtenLat(Range(fromStart,toEnd,domain->zoom_ni)) ;
[665]285                       SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0);
[1129]286                       CArray<double,1> lon = writtenLon(Range(0,domain->zoom_ni-1)) ;
[665]287                       SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0);
288                       break;
289                   }
[611]290
[665]291                   if (domain->hasBounds)
292                   {
[1129]293                     SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0);
294                     SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0);
[665]295                   }
[617]296                 }
297
[611]298                 if (domain->hasArea)
[1129]299                 {
[1132]300                   SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0);                   
[1129]301                 }
302
[498]303                 SuperClassWriter::definition_start();
[219]304
[498]305                 break;
306              }
307              case (ONE_FILE) :
308              {
[1099]309                 SuperClassWriter::addDimension(dimXid, domain->global_zoom_ni);
310                 SuperClassWriter::addDimension(dimYid, domain->global_zoom_nj);
[286]311
[617]312                 if (domain->hasBounds)
313                   SuperClassWriter::addDimension(dimVertId, domain->nvertex);
314
[665]315                 if (domain->hasLonLat)
[498]316                 {
[665]317                   switch (domain->type)
318                   {
319                     case CDomain::type_attr::curvilinear :
320                       dim0.push_back(dimYid); dim0.push_back(dimXid);
321                       lonid = StdString("nav_lon").append(appendDomid);
322                       latid = StdString("nav_lat").append(appendDomid);
[1158]323                       SuperClassWriter::addVariable(latid, typePrec, dim0);
324                       SuperClassWriter::addVariable(lonid, typePrec, dim0);
[665]325                       break;
[449]326
[665]327                     case CDomain::type_attr::rectilinear :
328                       dim0.push_back(dimYid);
329                       dim1.push_back(dimXid);
330                       lonid = StdString("lon").append(appendDomid);
331                       latid = StdString("lat").append(appendDomid);
[1158]332                       SuperClassWriter::addVariable(latid, typePrec, dim0);
333                       SuperClassWriter::addVariable(lonid, typePrec, dim1);
[665]334                       break;
335                   }
336
337                   bounds_lonid = StdString("bounds_lon").append(appendDomid);
338                   bounds_latid = StdString("bounds_lat").append(appendDomid);
339
340                   this->writeAxisAttributes
341                      (lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid);
342                   this->writeAxisAttributes
343                      (latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid);
344
345                   if (domain->hasBounds)
346                   {
347                     SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid);
348                     SuperClassWriter::addAttribute("bounds", bounds_latid, &latid);
349
350                     dim0.clear();
[498]351                     dim0.push_back(dimYid);
[665]352                     dim0.push_back(dimXid);
353                     dim0.push_back(dimVertId);
[1158]354                     SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0);
355                     SuperClassWriter::addVariable(bounds_latid, typePrec, dim0);
[665]356                   }
[498]357                 }
[611]358
359                 if (domain->hasArea)
360                 {
361                   dim0.clear();
362                   dim0.push_back(dimYid); dim0.push_back(dimXid);
[1158]363                   SuperClassWriter::addVariable(areaId, typePrec, dim0);
[614]364                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
[611]365                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
366                   dim0.clear();
367                 }
368
369                 SuperClassWriter::definition_end();
[286]370
[498]371                 switch (domain->type)
[384]372                 {
[498]373                   case CDomain::type_attr::curvilinear :
[449]374                   {
[498]375                     std::vector<StdSize> start(2) ;
376                     std::vector<StdSize> count(2) ;
377                     if (domain->isEmpty())
378                     {
[611]379                       start[0]=0 ; start[1]=0 ;
[498]380                       count[0]=0 ; count[1]=0 ;
381                     }
382                     else
383                     {
[1099]384                       start[1]=domain->zoom_ibegin-domain->global_zoom_ibegin;
385                       start[0]=domain->zoom_jbegin-domain->global_zoom_jbegin;
386                       count[1]=domain->zoom_ni ; count[0]=domain->zoom_nj ;
[498]387                     }
[488]388
[665]389                     if (domain->hasLonLat)
390                     {
[1129]391                       SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count);
392                       SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count);
[665]393                     }
[498]394                     break;
395                   }
[664]396                   case CDomain::type_attr::rectilinear :
[449]397                   {
[665]398                     if (domain->hasLonLat)
[498]399                     {
[665]400                       std::vector<StdSize> start(1) ;
401                       std::vector<StdSize> count(1) ;
402                       if (domain->isEmpty())
403                       {
404                         start[0]=0 ;
405                         count[0]=0 ;
[1129]406                         SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count);
407                         SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count);
[665]408                       }
409                       else
[1129]410                       { 
[1099]411                         start[0]=domain->zoom_jbegin-domain->global_zoom_jbegin;
[1143]412                         count[0]=domain->zoom_nj;                         
[1129]413                         CArray<double,1> lat = writtenLat(Range(fromStart,toEnd,domain->zoom_ni));
[665]414                         SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count);
415
[1099]416                         start[0]=domain->zoom_ibegin-domain->global_zoom_ibegin;
[1143]417                         count[0]=domain->zoom_ni;                         
[1129]418                         CArray<double,1> lon = writtenLon(Range(0,domain->zoom_ni-1));
[665]419                         SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count);
420                       }
[498]421                     }
422                     break;
[449]423                   }
[384]424                 }
[611]425
[617]426                 if (domain->hasBounds)
427                 {
428                   std::vector<StdSize> start(3);
429                   std::vector<StdSize> count(3);
430                   if (domain->isEmpty())
431                   {
432                     start[2] = start[1] = start[0] = 0;
433                     count[2] = count[1] = count[0] = 0;
434                   }
435                   else
436                   {
437                     start[2] = 0;
[1099]438                     start[1] = domain->zoom_ibegin - domain->global_zoom_ibegin;
439                     start[0] = domain->zoom_jbegin - domain->global_zoom_jbegin;
440                     count[2] = domain->nvertex;
441                     count[1] = domain->zoom_ni;
442                     count[0] = domain->zoom_nj;
[617]443                   }
[1143]444                 
[1129]445                   SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0, &start, &count);
446                   SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0, &start, &count);
[617]447                 }
448
[611]449                 if (domain->hasArea)
450                 {
451                   std::vector<StdSize> start(2);
452                   std::vector<StdSize> count(2);
453
454                   if (domain->isEmpty())
455                   {
456                     start[0] = 0; start[1] = 0;
457                     count[0] = 0; count[1] = 0;
458                   }
459                   else
460                   {
[1099]461                     start[1] = domain->zoom_ibegin - domain->global_zoom_ibegin;
462                     start[0] = domain->zoom_jbegin - domain->global_zoom_jbegin;
463                     count[1] = domain->zoom_ni;
464                     count[0] = domain->zoom_nj;
[611]465                   }
[1143]466                   
[1129]467                   SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0, &start, &count);
[611]468                 }
469
[498]470                 SuperClassWriter::definition_start();
471                 break;
472              }
473              default :
474                 ERROR("CNc4DataOutput::writeDomain(domain)",
475                       << "[ type = " << SuperClass::type << "]"
476                       << " not implemented yet !");
477           }
[449]478         }
[498]479         catch (CNetCdfException& e)
480         {
481           StdString msg("On writing the domain : ");
482           msg.append(domid); msg.append("\n");
483           msg.append("In the context : ");
484           msg.append(context->getId()); msg.append("\n");
485           msg.append(e.what());
486           ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg);
487         }
488
[449]489         domain->addRelFile(this->filename);
490      }
491
[879]492    //--------------------------------------------------------------
[878]493
[879]494    void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain)
495    {
496      CContext* context = CContext::getCurrent() ;
497      CContextServer* server=context->server ;
[878]498
[879]499      if (domain->IsWritten(this->filename)) return;
500      domain->checkAttributes();
501      if (domain->isEmpty())
502        if (SuperClass::type==MULTI_FILE) return ;
[878]503
[1158]504     nc_type typePrec ;
505     if (domain->prec.isEmpty()) typePrec =  NC_FLOAT ;
506     else if (domain->prec==4)  typePrec =  NC_FLOAT ;
507     else if (domain->prec==8)   typePrec =  NC_DOUBLE ;
508
[879]509      std::vector<StdString> dim0;
510      StdString domid = domain->getDomainOutputName();
511      StdString domainName = domain->name;
[924]512      domain->assignMesh(domainName, domain->nvertex);
[1025]513      domain->mesh->createMeshEpsilon(server->intraComm, domain->lonvalue, domain->latvalue, domain->bounds_lonvalue, domain->bounds_latvalue);
[878]514
[879]515      StdString node_x = domainName + "_node_x";
516      StdString node_y = domainName + "_node_y";
[878]517
[879]518      StdString edge_x = domainName + "_edge_x";
519      StdString edge_y = domainName + "_edge_y";
520      StdString edge_nodes = domainName + "_edge_nodes";
[878]521
[879]522      StdString face_x = domainName + "_face_x";
523      StdString face_y = domainName + "_face_y";
524      StdString face_nodes = domainName + "_face_nodes";
[902]525      StdString face_edges = domainName + "_face_edges";
526      StdString edge_faces = domainName + "_edge_face_links";
527      StdString face_faces = domainName + "_face_links";
[878]528
[879]529      StdString dimNode = "n" + domainName + "_node";
530      StdString dimEdge = "n" + domainName + "_edge";
531      StdString dimFace = "n" + domainName + "_face";
532      StdString dimVertex = "n" + domainName + "_vertex";
533      StdString dimTwo = "Two";
[878]534
[879]535      if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2);
536      if (!isWrittenDomain(domid))
537      {
538        dim0.clear();
539        SuperClassWriter::addVariable(domainName, NC_INT, dim0);
540        SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName);
[924]541        SuperClassWriter::addAttribute("long_name", StdString("Topology data of 2D unstructured mesh"), &domainName);
542        SuperClassWriter::addAttribute("topology_dimension", 2, &domainName);
[879]543        SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName);
544      }
[878]545
[879]546      try
547      {
548        switch (SuperClass::type)
549        {
550          case (ONE_FILE) :
551          {
552            // Adding nodes
553            if (domain->nvertex == 1)
554            {
555              if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
556              {
[902]557                SuperClassWriter::addDimension(dimNode, domain->ni_glo);
[879]558                dim0.clear();
559                dim0.push_back(dimNode);
[1158]560                SuperClassWriter::addVariable(node_x, typePrec, dim0);
[879]561                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
[924]562                SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x);
[879]563                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
[1158]564                SuperClassWriter::addVariable(node_y, typePrec, dim0);
[879]565                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
[924]566                SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y);
[879]567                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
568              }
569            } // domain->nvertex == 1
[878]570
[879]571            // Adding edges and nodes, if nodes have not been defined previously
572            if (domain->nvertex == 2)
573            {
574              if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
575              {
[924]576                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodesGlo);
[879]577                dim0.clear();
578                dim0.push_back(dimNode);
[1158]579                SuperClassWriter::addVariable(node_x, typePrec, dim0);
[879]580                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
[924]581                SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x);
[879]582                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
[1158]583                SuperClassWriter::addVariable(node_y, typePrec, dim0);
[879]584                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
[924]585                SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y);
[879]586                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
587              }
[924]588              SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName);
589              SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName);
590              SuperClassWriter::addDimension(dimEdge, domain->ni_glo);
591              dim0.clear();
592              dim0.push_back(dimEdge);
[1158]593              SuperClassWriter::addVariable(edge_x, typePrec, dim0);
[924]594              SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x);
595              SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x);
596              SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x);
[1158]597              SuperClassWriter::addVariable(edge_y, typePrec, dim0);
[924]598              SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y);
599              SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y);
600              SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y);
601              dim0.clear();
602              dim0.push_back(dimEdge);
603              dim0.push_back(dimTwo);
604              SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0);
605              SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes);
606              SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes);
607              SuperClassWriter::addAttribute("start_index", 0, &edge_nodes);
[879]608            } // domain->nvertex == 2
[878]609
[879]610            // Adding faces, edges, and nodes, if edges and nodes have not been defined previously
611            if (domain->nvertex > 2)
612            {
613              // Nodes
614              if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
615              {
[924]616                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodesGlo);
[879]617                dim0.clear();
618                dim0.push_back(dimNode);
[1158]619                SuperClassWriter::addVariable(node_x, typePrec, dim0);
[879]620                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
[924]621                SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x);
[879]622                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
[1158]623                SuperClassWriter::addVariable(node_y, typePrec, dim0);
[879]624                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
[924]625                SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y);
[879]626                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
627              }
628              if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y))
629              {
630                SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName);
631                SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName);
[924]632                SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdgesGlo);
[879]633                dim0.clear();
634                dim0.push_back(dimEdge);
[1158]635                SuperClassWriter::addVariable(edge_x, typePrec, dim0);
[879]636                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x);
[924]637                SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x);
[879]638                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x);
[1158]639                SuperClassWriter::addVariable(edge_y, typePrec, dim0);
[879]640                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y);
[924]641                SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y);
[879]642                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y);
643                dim0.clear();
644                dim0.push_back(dimEdge);
645                dim0.push_back(dimTwo);
646                SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0);
647                SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes);
648                SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes);
649                SuperClassWriter::addAttribute("start_index", 0, &edge_nodes);
650              }
[924]651              SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName);
652              SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName);
653              SuperClassWriter::addDimension(dimFace, domain->ni_glo);
654              SuperClassWriter::addDimension(dimVertex, domain->nvertex);
655              dim0.clear();
656              dim0.push_back(dimFace);
[1158]657              SuperClassWriter::addVariable(face_x, typePrec, dim0);
[924]658              SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x);
659              SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh faces."), &face_x);
660              SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x);
[1158]661              SuperClassWriter::addVariable(face_y, typePrec, dim0);
[924]662              SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y);
663              SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh faces."), &face_y);
664              SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y);
665              dim0.clear();
666              dim0.push_back(dimFace);
667              dim0.push_back(dimVertex);
668              SuperClassWriter::addVariable(face_nodes, NC_INT, dim0);
669              SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes);
670              SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes);
671              SuperClassWriter::addAttribute("start_index", 0, &face_nodes);
672              dim0.clear();
673              dim0.push_back(dimFace);
674              dim0.push_back(dimVertex);
675              SuperClassWriter::addVariable(face_edges, NC_INT, dim0);
676              SuperClassWriter::addAttribute("cf_role", StdString("face_edge_connectivity"), &face_edges);
677              SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its edges."), &face_edges);
678              SuperClassWriter::addAttribute("start_index", 0, &face_edges);
[929]679              SuperClassWriter::addAttribute("_FillValue", 999999, &face_edges);
[924]680              dim0.clear();
681              dim0.push_back(dimEdge);
682              dim0.push_back(dimTwo);
683              SuperClassWriter::addVariable(edge_faces, NC_INT, dim0);
684              SuperClassWriter::addAttribute("cf_role", StdString("edge_face connectivity"), &edge_faces);
685              SuperClassWriter::addAttribute("long_name", StdString("neighbor faces for edges"), &edge_faces);
686              SuperClassWriter::addAttribute("start_index", 0, &edge_faces);
687              SuperClassWriter::addAttribute("_FillValue", -999, &edge_faces);
688              SuperClassWriter::addAttribute("comment", StdString("missing neighbor faces are indicated using _FillValue"), &edge_faces);
689              dim0.clear();
690              dim0.push_back(dimFace);
691              dim0.push_back(dimVertex);
692              SuperClassWriter::addVariable(face_faces, NC_INT, dim0);
693              SuperClassWriter::addAttribute("cf_role", StdString("face_face connectivity"), &face_faces);
694              SuperClassWriter::addAttribute("long_name", StdString("Indicates which other faces neighbor each face"), &face_faces);
695              SuperClassWriter::addAttribute("start_index", 0, &face_faces);
[929]696              SuperClassWriter::addAttribute("_FillValue", 999999, &face_faces);
[924]697              SuperClassWriter::addAttribute("flag_values", -1, &face_faces);
698              SuperClassWriter::addAttribute("flag_meanings", StdString("out_of_mesh"), &face_faces);
[879]699            } // domain->nvertex > 2
[878]700
[879]701            SuperClassWriter::definition_end();
[878]702
[924]703            std::vector<StdSize> startEdges(1) ;
704            std::vector<StdSize> countEdges(1) ;
705            std::vector<StdSize> startNodes(1) ;
706            std::vector<StdSize> countNodes(1) ;
707            std::vector<StdSize> startFaces(1) ;
708            std::vector<StdSize> countFaces(1) ;
709            std::vector<StdSize> startEdgeNodes(2) ;
710            std::vector<StdSize> countEdgeNodes(2) ;
711            std::vector<StdSize> startEdgeFaces(2) ;
712            std::vector<StdSize> countEdgeFaces(2) ;
713            std::vector<StdSize> startFaceConctv(2) ;
714            std::vector<StdSize> countFaceConctv(2) ;
[902]715
[879]716            if (!isWrittenDomain(domid))
717            {
718              if (domain->nvertex == 1)
719              {
[924]720                if (domain->isEmpty())
721                 {
722                   startNodes[0]=0 ;
723                   countNodes[0]=0 ;
724                 }
725                 else
726                 {
[1132]727                   startNodes[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
728                   countNodes[0] = domain->zoom_ni ;
[924]729                 }
730
731                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes);
732                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes);
[879]733              }
734              else if (domain->nvertex == 2)
[924]735              {
736                if (domain->isEmpty())
737                 {
738                  startEdges[0]=0 ;
739                  countEdges[0]=0 ;
740                  startNodes[0]=0 ;
741                  countNodes[0]=0 ;
742                  startEdgeNodes[0]=0;
743                  startEdgeNodes[1]=0;
744                  countEdgeNodes[0]=0;
745                  countEdgeNodes[1]=0;
746
747                 }
748                 else
749                 {
[1132]750                   startEdges[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
751                   countEdges[0] = domain->zoom_ni;
[924]752                   startNodes[0] = domain->mesh->node_start;
753                   countNodes[0] = domain->mesh->node_count;
[1132]754                   startEdgeNodes[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
[924]755                   startEdgeNodes[1] = 0;
[1132]756                   countEdgeNodes[0] = domain->zoom_ni;
757                   countEdgeNodes[1] = 2;
[924]758                 }
759                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes);
760                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes);
761                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges);
762                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges);
763                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes);
764              }
[879]765              else
766              {
[924]767                if (domain->isEmpty())
768                 {
769                   startFaces[0] = 0 ;
770                   countFaces[0] = 0 ;
771                   startNodes[0] = 0;
772                   countNodes[0] = 0;
773                   startEdges[0] = 0;
774                   countEdges[0] = 0;
775                   startEdgeFaces[0] = 0;
776                   startEdgeFaces[1] = 0;
777                   countEdgeFaces[0] = 0;
778                   countEdgeFaces[1] = 0;
779                   startFaceConctv[0] = 0;
780                   startFaceConctv[1] = 0;
781                   countFaceConctv[0] = 0;
782                   countFaceConctv[1] = 0;
783                 }
784                 else
785                 {
[1132]786                   startFaces[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
787                   countFaces[0] = domain->zoom_ni ;
[924]788                   startNodes[0] = domain->mesh->node_start;
789                   countNodes[0] = domain->mesh->node_count;
790                   startEdges[0] = domain->mesh->edge_start;
791                   countEdges[0] = domain->mesh->edge_count;
792                   startEdgeNodes[0] = domain->mesh->edge_start;
793                   startEdgeNodes[1] = 0;
794                   countEdgeNodes[0] = domain->mesh->edge_count;
795                   countEdgeNodes[1]= 2;
796                   startEdgeFaces[0] = domain->mesh->edge_start;
797                   startEdgeFaces[1]= 0;
798                   countEdgeFaces[0] = domain->mesh->edge_count;
799                   countEdgeFaces[1]= 2;
[1132]800                   startFaceConctv[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
801                   startFaceConctv[1] = 0; 
802                   countFaceConctv[0] = domain->zoom_ni;
[924]803                   countFaceConctv[1] = domain->nvertex;
804                 }
805                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0, &startNodes, &countNodes);
806                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0, &startNodes, &countNodes);
807                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges);
808                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges);
809                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes);
810                SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0, &startFaces, &countFaces);
811                SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0, &startFaces, &countFaces);
812                SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes, isCollective, 0, &startFaceConctv, &countFaceConctv);
813                SuperClassWriter::writeData(domain->mesh->face_edges, face_edges, isCollective, 0, &startFaceConctv, &countFaceConctv);
814                SuperClassWriter::writeData(domain->mesh->edge_faces, edge_faces, isCollective, 0, &startEdgeFaces, &countEdgeFaces);
815                SuperClassWriter::writeData(domain->mesh->face_faces, face_faces, isCollective, 0, &startFaceConctv, &countFaceConctv);
[879]816              }
817              setWrittenDomain(domid);
818            } // !isWrittenDomain
819            else
820            {
821              if (domain->nvertex == 2)
822              {
[1132]823                startEdges[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
824                countEdges[0] = domain->zoom_ni;
825                startEdgeNodes[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
826                startEdgeNodes[1] = 0;
827                countEdgeNodes[0] = domain->zoom_ni;
[924]828                countEdgeNodes[1]= 2;
829                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges);
830                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges);
831                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes);
[879]832              } 
833              if (domain->nvertex > 2)
834              {
[924]835
[879]836                if (!domain->mesh->edgesAreWritten)
837                {
[924]838                  startEdges[0] = domain->mesh->edge_start;
839                  countEdges[0] = domain->mesh->edge_count;
840                  startEdgeNodes[0] = domain->mesh->edge_start;
841                  startEdgeNodes[1] = 0;
842                  countEdgeNodes[0] = domain->mesh->edge_count;
843                  countEdgeNodes[1]= 2;
844                  SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0, &startEdges, &countEdges);
845                  SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0, &startEdges, &countEdges);
846                  SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes, isCollective, 0, &startEdgeNodes, &countEdgeNodes);
[879]847                }
[1132]848                startFaces[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
849                countFaces[0] = domain->zoom_ni;
[924]850                startEdgeFaces[0] = domain->mesh->edge_start;
851                startEdgeFaces[1]= 0;
852                countEdgeFaces[0] = domain->mesh->edge_count;
853                countEdgeFaces[1]= 2;
[1132]854                startFaceConctv[0] = domain->zoom_ibegin-domain->global_zoom_ibegin;
855                startFaceConctv[1] = 0;
856                countFaceConctv[0] = domain->zoom_ni;
857                countFaceConctv[1] = domain->nvertex;
[924]858                SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0, &startFaces, &countFaces);
859                SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0, &startFaces, &countFaces);
860                SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes, isCollective, 0, &startFaceConctv, &countFaceConctv);
861                SuperClassWriter::writeData(domain->mesh->face_edges, face_edges, isCollective, 0, &startFaceConctv, &countFaceConctv);
862                SuperClassWriter::writeData(domain->mesh->edge_faces, edge_faces, isCollective, 0, &startEdgeFaces, &countEdgeFaces);
863                SuperClassWriter::writeData(domain->mesh->face_faces, face_faces, isCollective, 0, &startFaceConctv, &countFaceConctv);
[879]864              }
865            }// isWrittenDomain
[878]866
[879]867            SuperClassWriter::definition_start();
[878]868
[879]869            break;
870          } // ONE_FILE
[878]871
[879]872          case (MULTI_FILE) :
873          {
874            break;
875          }
[878]876
[879]877          default :
878          ERROR("CNc4DataOutput::writeDomain(domain)",
879          << "[ type = " << SuperClass::type << "]"
880          << " not implemented yet !");
881          } // switch
882        } // try
[878]883
[879]884        catch (CNetCdfException& e)
885        {
886          StdString msg("On writing the domain : ");
887          msg.append(domid); msg.append("\n");
888          msg.append("In the context : ");
889          msg.append(context->getId()); msg.append("\n");
890          msg.append(e.what());
[924]891          ERROR("CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain)", << msg);
[879]892        }
[878]893
[879]894  domain->addRelFile(this->filename);
895  }
[878]896
[879]897    //--------------------------------------------------------------
[878]898
[879]899    void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)
[449]900      {
901         CContext* context = CContext::getCurrent() ;
902         CContextServer* server=context->server ;
[488]903
[449]904         if (domain->IsWritten(this->filename)) return;
905         domain->checkAttributes();
[488]906
907         if (domain->isEmpty())
[449]908           if (SuperClass::type==MULTI_FILE) return ;
909
910         std::vector<StdString> dim0, dim1;
[772]911         StdString domid = domain->getDomainOutputName();
[705]912         if (isWrittenDomain(domid)) return ;
[774]913         else setWrittenDomain(domid);
[705]914
[449]915         StdString appendDomid  = (singleDomain) ? "" : "_"+domid ;
916
917         StdString dimXid = StdString("cell").append(appendDomid);
918         StdString dimVertId = StdString("nvertex").append(appendDomid);
[488]919
[449]920         string lonid,latid,bounds_lonid,bounds_latid ;
[611]921         string areaId = "area" + appendDomid;
[449]922
[1158]923         nc_type typePrec ;
924         if (domain->prec.isEmpty()) typePrec =  NC_FLOAT ;
925         else if (domain->prec==4)  typePrec =  NC_FLOAT ;
926         else if (domain->prec==8)   typePrec =  NC_DOUBLE ;
927
[1132]928         int nvertex = (domain->nvertex.isEmpty()) ? 0 : domain->nvertex;
[1025]929
[1132]930         CArray<size_t, 1>& indexToWrite = domain->localIndexToWriteOnServer;
931         int nbWritten = indexToWrite.numElements();
932         CArray<double,1> writtenLat, writtenLon;
933         CArray<double,2> writtenBndsLat, writtenBndsLon;
934         CArray<double,1> writtenArea;
935
936         if (domain->hasLonLat)
937         {
938           writtenLat.resize(nbWritten);
939           writtenLon.resize(nbWritten);
940           for (int idx = 0; idx < nbWritten; ++idx)
941           {
942              writtenLat(idx) = domain->latvalue(indexToWrite(idx));
943              writtenLon(idx) = domain->lonvalue(indexToWrite(idx));
944           }
945         
946
947           if (domain->hasBounds)
948           {         
949             int nvertex = domain->nvertex, idx;
950             writtenBndsLat.resize(nvertex, nbWritten);
951             writtenBndsLon.resize(nvertex, nbWritten);
952             CArray<double,2>& boundslat = domain->bounds_latvalue;
953             CArray<double,2>& boundslon = domain->bounds_lonvalue;   
954             for (idx = 0; idx < nbWritten; ++idx)
955               for (int nv = 0; nv < nvertex; ++nv)
956               {
957                 writtenBndsLat(nv, idx) = boundslat(nv, int(indexToWrite(idx)));
958                 writtenBndsLon(nv, idx) = boundslon(nv, int(indexToWrite(idx)));
959               }
960           }
961         }
962
963         if (domain->hasArea)
964         {
965           writtenArea.resize(nbWritten);           
966           for (int idx = 0; idx < nbWritten; ++idx)
967           {
968              writtenArea(idx) = domain->areavalue(indexToWrite(idx));                     
969           }
970         }
971
[498]972         try
[449]973         {
[498]974           switch (SuperClass::type)
975           {
976              case (MULTI_FILE) :
977              {
978                 dim0.push_back(dimXid);
[1132]979                 SuperClassWriter::addDimension(dimXid, domain->zoom_ni);
[488]980
[665]981                 lonid = StdString("lon").append(appendDomid);
982                 latid = StdString("lat").append(appendDomid);
[498]983                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
984                 bounds_latid = StdString("bounds_lat").append(appendDomid);
[665]985                 if (domain->hasLonLat)
986                 {
[1158]987                   SuperClassWriter::addVariable(latid, typePrec, dim0);
988                   SuperClassWriter::addVariable(lonid, typePrec, dim0);
[665]989                   this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid);
990                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid);
991                   this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid);
992                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
993                   if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex);
994                 }
[498]995                 dim0.clear();
996                 if (domain->hasBounds)
997                 {
998                   dim0.push_back(dimXid);
999                   dim0.push_back(dimVertId);
[1158]1000                   SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0);
1001                   SuperClassWriter::addVariable(bounds_latid, typePrec, dim0);
[498]1002                 }
1003
1004                 dim0.clear();
[449]1005                 dim0.push_back(dimXid);
[611]1006                 if (domain->hasArea)
1007                 {
[1158]1008                   SuperClassWriter::addVariable(areaId, typePrec, dim0);
[614]1009                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
[611]1010                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
1011                 }
1012
[498]1013                 SuperClassWriter::definition_end();
[449]1014
[665]1015                 if (domain->hasLonLat)
[498]1016                 {
[1132]1017                   SuperClassWriter::writeData(writtenLat, latid, isCollective, 0);
1018                   SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0);
[665]1019                   if (domain->hasBounds)
1020                   {
[1132]1021                     SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0);
1022                     SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0);
[665]1023                   }
[498]1024                 }
[611]1025
1026                 if (domain->hasArea)
[1132]1027                   SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0);
[611]1028
[498]1029                 SuperClassWriter::definition_start();
1030                 break ;
1031              }
[488]1032
[498]1033              case (ONE_FILE) :
1034              {
1035                 lonid = StdString("lon").append(appendDomid);
1036                 latid = StdString("lat").append(appendDomid);
1037                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
1038                 bounds_latid = StdString("bounds_lat").append(appendDomid);
1039                 dim0.push_back(dimXid);
[1132]1040                 SuperClassWriter::addDimension(dimXid, domain->ni_glo);
[665]1041                 if (domain->hasLonLat)
1042                 {
[1158]1043                   SuperClassWriter::addVariable(latid, typePrec, dim0);
1044                   SuperClassWriter::addVariable(lonid, typePrec, dim0);
[665]1045
1046                   this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid);
1047                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid);
1048                   this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid);
1049                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
[1025]1050                   if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, nvertex);
[665]1051                 }
[498]1052                 dim0.clear();
[449]1053
[498]1054                 if (domain->hasBounds)
1055                 {
1056                   dim0.push_back(dimXid);
1057                   dim0.push_back(dimVertId);
[1158]1058                   SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0);
1059                   SuperClassWriter::addVariable(bounds_latid, typePrec, dim0);
[498]1060                 }
[488]1061
[611]1062                 if (domain->hasArea)
1063                 {
1064                   dim0.clear();
1065                   dim0.push_back(dimXid);
[1158]1066                   SuperClassWriter::addVariable(areaId, typePrec, dim0);
[614]1067                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
[611]1068                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
1069                 }
1070
[498]1071                 SuperClassWriter::definition_end();
[488]1072
[498]1073                 std::vector<StdSize> start(1), startBounds(2) ;
1074                 std::vector<StdSize> count(1), countBounds(2) ;
1075                 if (domain->isEmpty())
1076                 {
1077                   start[0]=0 ;
1078                   count[0]=0 ;
1079                   startBounds[1]=0 ;
[1025]1080                   countBounds[1]=nvertex ;
[498]1081                   startBounds[0]=0 ;
1082                   countBounds[0]=0 ;
1083                 }
1084                 else
1085                 {
[1132]1086                   start[0]=domain->zoom_ibegin - domain->global_zoom_ibegin;
1087                   count[0]=domain->zoom_ni;
1088                   startBounds[0]=domain->zoom_ibegin-domain->global_zoom_ibegin;
[498]1089                   startBounds[1]=0 ;
[1132]1090                   countBounds[0]=domain->zoom_ni;
[1025]1091                   countBounds[1]=nvertex ;
[498]1092                 }
[665]1093
1094                 if (domain->hasLonLat)
[498]1095                 {
[1132]1096                   SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count);
1097                   SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count);
[665]1098                   if (domain->hasBounds)
1099                   {
[1132]1100                     SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0,&startBounds,&countBounds);
1101                     SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0,&startBounds,&countBounds);
[665]1102                   }
[498]1103                 }
[488]1104
[611]1105                 if (domain->hasArea)
[1132]1106                   SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0, &start, &count);
[488]1107
[498]1108                 SuperClassWriter::definition_start();
[488]1109
[498]1110                 break;
1111              }
1112              default :
1113                 ERROR("CNc4DataOutput::writeDomain(domain)",
1114                       << "[ type = " << SuperClass::type << "]"
1115                       << " not implemented yet !");
1116           }
[219]1117         }
[498]1118         catch (CNetCdfException& e)
1119         {
1120           StdString msg("On writing the domain : ");
1121           msg.append(domid); msg.append("\n");
1122           msg.append("In the context : ");
1123           msg.append(context->getId()); msg.append("\n");
1124           msg.append(e.what());
1125           ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg);
1126         }
[219]1127         domain->addRelFile(this->filename);
1128      }
1129      //--------------------------------------------------------------
1130
[347]1131      void CNc4DataOutput::writeAxis_(CAxis* axis)
[219]1132      {
[1030]1133        if (axis->IsWritten(this->filename)) return;
1134        axis->checkAttributes();
[488]1135
[1129]1136        axis->computeWrittenIndex();
[1249]1137        axis->computeWrittenCompressedIndex(comm_file);
[1129]1138       
[1099]1139        int zoom_size  = (MULTI_FILE == SuperClass::type) ? axis->zoom_n
1140                                                          : axis->global_zoom_n;
1141
[1235]1142        int zoom_count = axis->zoom_n;                                                 
1143        int zoom_begin = axis->zoom_begin;
1144        // int zoom_begin = (MULTI_FILE == SuperClass::type) ? axis->global_zoom_begin
1145        //                                                   : axis->zoom_begin;
1146
[1099]1147        if ((0 == axis->zoom_n) && (MULTI_FILE == SuperClass::type)) return;
1148
[1030]1149        std::vector<StdString> dims;
1150        StdString axisid = axis->getAxisOutputName();
1151        if (isWrittenAxis(axisid)) return ;
1152        else setWrittenAxis(axisid);
[705]1153
[1158]1154        nc_type typePrec ;
1155        if (axis->prec.isEmpty()) typePrec =  NC_FLOAT ;
[1235]1156        else if (axis->prec==4)   typePrec =  NC_FLOAT ;
[1158]1157        else if (axis->prec==8)   typePrec =  NC_DOUBLE ;
1158         
1159        if (!axis->label.isEmpty()) typePrec = NC_CHAR ;
1160        string strId="str_len" ;
[1030]1161        try
1162        {
[1099]1163          SuperClassWriter::addDimension(axisid, zoom_size);
[1158]1164          if (!axis->label.isEmpty()) SuperClassWriter::addDimension(strId, stringArrayLen);
[1030]1165          if (axis->hasValue)
[816]1166          {
[1030]1167            dims.push_back(axisid);
[1158]1168            if (!axis->label.isEmpty()) dims.push_back(strId);
1169            SuperClassWriter::addVariable(axisid, typePrec, dims);
[219]1170
[1030]1171            if (!axis->name.isEmpty())
1172              SuperClassWriter::addAttribute("name", axis->name.getValue(), &axisid);
[219]1173
[1030]1174            if (!axis->standard_name.isEmpty())
1175              SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisid);
[540]1176
[1030]1177            if (!axis->long_name.isEmpty())
1178              SuperClassWriter::addAttribute("long_name", axis->long_name.getValue(), &axisid);
[219]1179
[1030]1180            if (!axis->unit.isEmpty())
1181              SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisid);
[219]1182
[1030]1183            if (!axis->positive.isEmpty())
1184            {
1185              SuperClassWriter::addAttribute("axis", string("Z"), &axisid);
1186              SuperClassWriter::addAttribute("positive",
1187                                             (axis->positive == CAxis::positive_attr::up) ? string("up") : string("down"),
1188                                             &axisid);
1189            }
[399]1190
[1266]1191            if (!axis->formula.isEmpty())
1192              SuperClassWriter::addAttribute("formula", axis->formula.getValue(), &axisid);
1193
1194            if (!axis->formula_term.isEmpty())
1195              SuperClassWriter::addAttribute("formula_term", axis->formula_term.getValue(), &axisid);
1196             
[1030]1197            StdString axisBoundsId = axisid + "_bounds";
[1249]1198            if (!axis->bounds.isEmpty() && axis->label.isEmpty())
[1030]1199            {
1200              dims.push_back("axis_nbounds");
[1158]1201              SuperClassWriter::addVariable(axisBoundsId, typePrec, dims);
[1030]1202              SuperClassWriter::addAttribute("bounds", axisBoundsId, &axisid);
[1288]1203
1204              if (!axis->standard_name.isEmpty())
1205                SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisBoundsId);
1206
1207              if (!axis->unit.isEmpty())
1208                SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisBoundsId);
1209
[1266]1210              if (!axis->formula_bounds.isEmpty())
[1288]1211                SuperClassWriter::addAttribute("formula", axis->formula_bounds.getValue(), &axisBoundsId);
[1266]1212
1213              if (!axis->formula_term_bounds.isEmpty())
[1288]1214                SuperClassWriter::addAttribute("formula_term", axis->formula_term_bounds.getValue(), &axisBoundsId);
[1030]1215            }
[488]1216
[1266]1217             
[1030]1218            SuperClassWriter::definition_end();
[816]1219
[1129]1220            CArray<size_t, 1>& indexToWrite = axis->localIndexToWriteOnServer;
1221            int nbWritten = indexToWrite.numElements();
1222            CArray<double,1> axis_value(indexToWrite.numElements());
1223            for (int i = 0; i < nbWritten; i++) axis_value(i) = axis->value(indexToWrite(i));
1224            CArray<double,2> axis_bounds;
[1235]1225            CArray<string,1> axis_label;
1226            if (!axis->label.isEmpty())
1227            {
1228              axis_label.resize(indexToWrite.numElements());
1229              for (int i = 0; i < nbWritten; i++) axis_label(i) = axis->label(indexToWrite(i));
1230            }
[1129]1231
[1030]1232            switch (SuperClass::type)
1233            {
1234              case MULTI_FILE:
[816]1235              {
[1235]1236                if (axis->label.isEmpty())
1237                  SuperClassWriter::writeData(axis_value, axisid, isCollective, 0);
[633]1238
[1332]1239                axis_bounds.resize(2, indexToWrite.numElements());
1240                for (int i = 0; i < nbWritten; ++i)
1241                {
1242                  axis_bounds(0, i) = axis->bounds(0, int(indexToWrite(i)));
1243                  axis_bounds(1, i) = axis->bounds(1, int(indexToWrite(i)));
1244                }
1245
1246
[1158]1247                if (!axis->bounds.isEmpty() && axis->label.isEmpty())
[1332]1248                  SuperClassWriter::writeData(axis_bounds, axisBoundsId, isCollective, 0);
[488]1249
[1158]1250                // Need to check after
[1235]1251                if (!axis->label.isEmpty()) 
1252                  SuperClassWriter::writeData(axis_label, axisid, isCollective, 0);
[1158]1253 
[1030]1254                SuperClassWriter::definition_start();
1255                break;
1256              }
1257              case ONE_FILE:
1258              {
1259                std::vector<StdSize> start(1), startBounds(2) ;
1260                std::vector<StdSize> count(1), countBounds(2) ;
[1099]1261                start[0] = startBounds[0] = zoom_begin - axis->global_zoom_begin;
[1235]1262                count[0] = countBounds[0] = zoom_count; // zoom_size
[1030]1263                startBounds[1] = 0;
1264                countBounds[1] = 2;
[633]1265
[1235]1266                if (axis->label.isEmpty())
1267                  SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count);
1268
1269                if (!axis->bounds.isEmpty() && axis->label.isEmpty())
[1129]1270                {
1271                  axis_bounds.resize(2, indexToWrite.numElements());
1272                  for (int i = 0; i < nbWritten; ++i)
1273                  {
1274                    axis_bounds(0, i) = axis->bounds(0, int(indexToWrite(i)));
1275                    axis_bounds(1, i) = axis->bounds(1, int(indexToWrite(i)));
1276                  }
[1332]1277                  SuperClassWriter::writeData(axis_bounds, axisBoundsId, isCollective, 0, &startBounds, &countBounds);
[1129]1278                }
[609]1279
[1158]1280                // Need to check after
[1235]1281                if (!axis->label.isEmpty())
1282                {
1283                  std::vector<StdSize> startLabel(2), countLabel(2);
1284                  startLabel[0] = start[0]; startLabel[1] = 0;
1285                  countLabel[0] = count[0]; countLabel[1] = stringArrayLen;
1286                  SuperClassWriter::writeData(axis_label, axisid, isCollective, 0, &startLabel, &countLabel);
1287                }
[1158]1288
[1030]1289                SuperClassWriter::definition_start();
[609]1290
[1030]1291                break;
[816]1292              }
[1030]1293              default :
1294                ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)",
1295                      << "[ type = " << SuperClass::type << "]"
1296                      << " not implemented yet !");
[609]1297            }
1298          }
[1030]1299        }
1300        catch (CNetCdfException& e)
1301        {
1302          StdString msg("On writing the axis : ");
1303          msg.append(axisid); msg.append("\n");
1304          msg.append("In the context : ");
1305          CContext* context = CContext::getCurrent() ;
1306          msg.append(context->getId()); msg.append("\n");
1307          msg.append(e.what());
1308          ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg);
1309        }
[1158]1310        axis->addRelFile(this->filename);
[391]1311     }
[488]1312
[887]1313      void CNc4DataOutput::writeScalar_(CScalar* scalar)
1314      {
1315        if (scalar->IsWritten(this->filename)) return;
1316        scalar->checkAttributes();
1317        int scalarSize = 1;
1318
1319        StdString scalaId = scalar->getScalarOutputName();
1320        if (isWrittenAxis(scalaId)) return ;
1321        else setWrittenAxis(scalaId);
1322
[1158]1323        nc_type typePrec ;
1324        if (scalar->prec.isEmpty()) typePrec =  NC_FLOAT ;
1325        else if (scalar->prec==4)  typePrec =  NC_FLOAT ;
1326        else if (scalar->prec==8)   typePrec =  NC_DOUBLE ;
1327
1328       
[887]1329        try
1330        {
1331          if (!scalar->value.isEmpty())
1332          {
1333//            dims.push_back(scalaId);
1334            std::vector<StdString> dims;
[1158]1335            SuperClassWriter::addVariable(scalaId, typePrec, dims);
[887]1336
1337            if (!scalar->name.isEmpty())
1338              SuperClassWriter::addAttribute("name", scalar->name.getValue(), &scalaId);
1339
1340            if (!scalar->standard_name.isEmpty())
1341              SuperClassWriter::addAttribute("standard_name", scalar->standard_name.getValue(), &scalaId);
1342
1343            if (!scalar->long_name.isEmpty())
1344              SuperClassWriter::addAttribute("long_name", scalar->long_name.getValue(), &scalaId);
1345
1346            if (!scalar->unit.isEmpty())
1347              SuperClassWriter::addAttribute("units", scalar->unit.getValue(), &scalaId);
1348
1349            SuperClassWriter::definition_end();
1350
1351            switch (SuperClass::type)
1352            {
1353              case MULTI_FILE:
1354              {
1355                CArray<double,1> scalarValue(scalarSize);
1356                scalarValue(0) = scalar->value;
1357                SuperClassWriter::writeData(scalarValue, scalaId, isCollective, 0);
1358                SuperClassWriter::definition_start();
1359
1360                break;
1361              }
1362              case ONE_FILE:
1363              {
1364                CArray<double,1> scalarValue(scalarSize);
1365                scalarValue(0) = scalar->value;
1366
1367                std::vector<StdSize> start(1);
1368                std::vector<StdSize> count(1);
1369                start[0] = 0;
1370                count[0] = 1;
1371                SuperClassWriter::writeData(scalarValue, scalaId, isCollective, 0, &start, &count);
1372                SuperClassWriter::definition_start();
1373
1374                break;
1375              }
1376              default :
1377                ERROR("CNc4DataOutput::writeAxis_(CAxis* scalar)",
1378                      << "[ type = " << SuperClass::type << "]"
1379                      << " not implemented yet !");
1380            }
1381          }
1382        }
1383        catch (CNetCdfException& e)
1384        {
1385          StdString msg("On writing the scalar : ");
1386          msg.append(scalaId); msg.append("\n");
1387          msg.append("In the context : ");
1388          CContext* context = CContext::getCurrent() ;
1389          msg.append(context->getId()); msg.append("\n");
1390          msg.append(e.what());
1391          ERROR("CNc4DataOutput::writeScalar_(CScalar* scalar)", << msg);
1392        }
1393        scalar->addRelFile(this->filename);
1394     }
1395
[676]1396     //--------------------------------------------------------------
1397
1398     void CNc4DataOutput::writeGridCompressed_(CGrid* grid)
1399     {
1400       if (grid->isScalarGrid() || grid->isWrittenCompressed(this->filename)) return;
1401
1402       try
1403       {
[887]1404         CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[676]1405         std::vector<StdString> domainList = grid->getDomainList();
1406         std::vector<StdString> axisList   = grid->getAxisList();
[887]1407         std::vector<StdString> scalarList = grid->getScalarList();
1408         int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0;
[676]1409
1410         std::vector<StdString> dims;
1411
1412         if (grid->isCompressible())
1413         {
1414           StdString varId = grid->getId() + "_points";
1415
1416           int nbIndexes = (SuperClass::type == MULTI_FILE) ? grid->getNumberWrittenIndexes() : grid->getTotalNumberWrittenIndexes();
1417           SuperClassWriter::addDimension(varId, nbIndexes);
1418
1419           dims.push_back(varId);
1420           SuperClassWriter::addVariable(varId, NC_INT, dims);
1421
1422           StdOStringStream compress;
1423           for (int i = numElement - 1; i >= 0; --i)
1424           {
[887]1425             if (2 == axisDomainOrder(i))
[676]1426             {
1427               CDomain* domain = CDomain::get(domainList[domainList.size() - idxDomain - 1]);
[772]1428               StdString domId = domain->getDomainOutputName();
[676]1429               StdString appendDomId  = singleDomain ? "" : "_" + domId;
1430
1431               switch (domain->type)
1432               {
1433                 case CDomain::type_attr::curvilinear:
1434                   compress << "y" << appendDomId << " x" << appendDomId;
1435                   break;
1436                 case CDomain::type_attr::rectilinear:
1437                   compress << "lat" << appendDomId << " lon" << appendDomId;
1438                   break;
1439                 case CDomain::type_attr::unstructured:
1440                   compress << "cell" << appendDomId;
1441                   break;
1442               }
1443               ++idxDomain;
1444             }
[887]1445             else if (1 == axisDomainOrder(i))
[676]1446             {
1447               CAxis* axis = CAxis::get(axisList[axisList.size() - idxAxis - 1]);
[772]1448               compress << axis->getAxisOutputName();
[676]1449               ++idxAxis;
1450             }
[887]1451             else
1452             {
1453               CScalar* scalar = CScalar::get(scalarList[scalarList.size() - idxScalar - 1]);
1454               compress << scalar->getScalarOutputName();
1455               ++idxScalar;
1456             }
[676]1457
1458             if (i != 0) compress << ' ';
1459           }
[1144]1460           SuperClassWriter::addAttribute("compress", compress.str(), &varId);         
[676]1461
1462           CArray<int, 1> indexes(grid->getNumberWrittenIndexes());
[1143]1463           indexes = grid->localIndexToWriteOnServer;
[676]1464
1465           switch (SuperClass::type)
1466           {
1467             case (MULTI_FILE):
1468             {
1469               SuperClassWriter::writeData(indexes, varId, isCollective, 0);
1470               break;
1471             }
1472             case (ONE_FILE):
1473             {
1474               if (grid->doGridHaveDataDistributed())
1475                 grid->getDistributionServer()->computeGlobalIndex(indexes);
1476
1477               std::vector<StdSize> start, count;
1478               start.push_back(grid->getOffsetWrittenIndexes());
1479               count.push_back(grid->getNumberWrittenIndexes());
1480
1481               SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count);
1482               break;
1483             }
1484           }
1485         }
1486         else
1487         {
1488           for (int i = 0; i < numElement; ++i)
1489           {
1490             StdString varId, compress;
1491             CArray<int, 1> indexes;
1492             bool isDistributed;
1493             StdSize nbIndexes, totalNbIndexes, offset;
1494             int firstGlobalIndex;
1495
[887]1496             if (2 == axisDomainOrder(i))
[676]1497             {
1498               CDomain* domain = CDomain::get(domainList[idxDomain]);
[774]1499               StdString domId = domain->getDomainOutputName();
1500
[676]1501               if (!domain->isCompressible()
1502                    || domain->type == CDomain::type_attr::unstructured
[774]1503                    || domain->isWrittenCompressed(this->filename)
1504                    || isWrittenCompressedDomain(domId))
[676]1505                 continue;
1506
1507               StdString appendDomId  = singleDomain ? "" : "_" + domId;
1508
1509               varId = domId + "_points";
1510               switch (domain->type)
1511               {
1512                 case CDomain::type_attr::curvilinear:
1513                   compress = "y" + appendDomId + " x" + appendDomId;
1514                   break;
1515                 case CDomain::type_attr::rectilinear:
1516                   compress = "lat" + appendDomId + " lon" + appendDomId;
1517                   break;
1518               }
1519
[1249]1520               // indexes.resize(domain->compressedIndexToWriteOnServer[comm_file].numElements());
1521               // indexes = domain->compressedIndexToWriteOnServer[com_file];
1522               indexes.resize(domain->getCompressedIndexToWriteOnServer(comm_file).numElements());
1523               indexes = domain->getCompressedIndexToWriteOnServer(comm_file);
[1143]1524
[676]1525               isDistributed = domain->isDistributed();
[1249]1526               nbIndexes = domain->getNumberWrittenIndexes(comm_file);
1527               totalNbIndexes = domain->getTotalNumberWrittenIndexes(comm_file);
1528               offset = domain->getOffsetWrittenIndexes(comm_file);
[676]1529               firstGlobalIndex = domain->ibegin + domain->jbegin * domain->ni_glo;
1530
1531               domain->addRelFileCompressed(this->filename);
[774]1532               setWrittenCompressedDomain(domId);
[676]1533               ++idxDomain;
1534             }
[887]1535             else if (1 == axisDomainOrder(i))
[676]1536             {
1537               CAxis* axis = CAxis::get(axisList[idxAxis]);
[774]1538               StdString axisId = axis->getAxisOutputName();
1539
1540               if (!axis->isCompressible()
1541                    || axis->isWrittenCompressed(this->filename)
1542                    || isWrittenCompressedAxis(axisId))
[676]1543                 continue;
1544
1545               varId = axisId + "_points";
1546               compress = axisId;
1547
[1249]1548               // indexes.resize(axis->compressedIndexToWriteOnServer.numElements());
1549               // indexes = axis->compressedIndexToWriteOnServer;
[1143]1550
[1249]1551               indexes.resize(axis->getCompressedIndexToWriteOnServer(comm_file).numElements());
1552               indexes = axis->getCompressedIndexToWriteOnServer(comm_file);
1553
[676]1554               isDistributed = axis->isDistributed();
[1249]1555               nbIndexes = axis->getNumberWrittenIndexes(comm_file);
1556               totalNbIndexes = axis->getTotalNumberWrittenIndexes(comm_file);
1557               offset = axis->getOffsetWrittenIndexes(comm_file);
[676]1558               firstGlobalIndex = axis->begin;
1559
1560               axis->addRelFileCompressed(this->filename);
[774]1561               setWrittenCompressedAxis(axisId);
[676]1562               ++idxAxis;
1563             }
[887]1564             else
1565             {
1566             }
[676]1567
1568             if (!varId.empty())
1569             {
1570               SuperClassWriter::addDimension(varId, (SuperClass::type == MULTI_FILE) ? nbIndexes : totalNbIndexes);
1571
1572               dims.clear();
1573               dims.push_back(varId);
1574               SuperClassWriter::addVariable(varId, NC_INT, dims);
1575
1576               SuperClassWriter::addAttribute("compress", compress, &varId);
1577
1578               switch (SuperClass::type)
1579               {
1580                 case (MULTI_FILE):
1581                 {
1582                   indexes -= firstGlobalIndex;
1583                   SuperClassWriter::writeData(indexes, varId, isCollective, 0);
1584                   break;
1585                 }
1586                 case (ONE_FILE):
1587                 {
1588                   std::vector<StdSize> start, count;
1589                   start.push_back(offset);
1590                   count.push_back(nbIndexes);
1591
1592                   SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count);
1593                   break;
1594                 }
1595               }
1596             }
[1144]1597            }
[676]1598         }
1599
1600         grid->addRelFileCompressed(this->filename);
1601       }
1602       catch (CNetCdfException& e)
1603       {
1604         StdString msg("On writing compressed grid : ");
1605         msg.append(grid->getId()); msg.append("\n");
1606         msg.append("In the context : ");
1607         CContext* context = CContext::getCurrent();
1608         msg.append(context->getId()); msg.append("\n");
1609         msg.append(e.what());
1610         ERROR("CNc4DataOutput::writeGridCompressed_(CGrid* grid)", << msg);
1611       }
1612     }
1613
1614     //--------------------------------------------------------------
1615
[391]1616     void CNc4DataOutput::writeTimeDimension_(void)
1617     {
[498]1618       try
1619       {
[802]1620        SuperClassWriter::addDimension(getTimeCounterName());
[498]1621       }
1622       catch (CNetCdfException& e)
1623       {
[614]1624         StdString msg("On writing time dimension : time_couter\n");
[498]1625         msg.append("In the context : ");
1626         CContext* context = CContext::getCurrent() ;
1627         msg.append(context->getId()); msg.append("\n");
1628         msg.append(e.what());
1629         ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg);
1630       }
[391]1631     }
[676]1632
[219]1633      //--------------------------------------------------------------
1634
[347]1635      void CNc4DataOutput::writeField_(CField* field)
[219]1636      {
[1158]1637        CContext* context = CContext::getCurrent() ;
1638        CContextServer* server=context->server ;
[300]1639
[1158]1640        std::vector<StdString> dims, coodinates;
1641        CGrid* grid = field->grid;
1642        if (!grid->doGridHaveDataToWrite())
[567]1643          if (SuperClass::type==MULTI_FILE) return ;
[488]1644
[1158]1645        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
1646        int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0;
1647        std::vector<StdString> domainList = grid->getDomainList();
1648        std::vector<StdString> axisList   = grid->getAxisList();
1649        std::vector<StdString> scalarList = grid->getScalarList();       
[219]1650
[1158]1651        StdString timeid  = getTimeCounterName();
1652        StdString dimXid,dimYid;
1653        std::deque<StdString> dimIdList, dimCoordList;
1654        bool hasArea = false;
1655        StdString cellMeasures = "area:";
1656        bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output;
[488]1657
[1158]1658        for (int i = 0; i < numElement; ++i)
1659        {
1660          if (2 == axisDomainOrder(i))
1661          {
1662            CDomain* domain = CDomain::get(domainList[idxDomain]);
1663            StdString domId = domain->getDomainOutputName();
1664            StdString appendDomId  = singleDomain ? "" : "_" + domId ;
[676]1665
[1158]1666            if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured)
1667            {
1668              dimIdList.push_back(domId + "_points");
1669              field->setUseCompressedOutput();
1670            }
[676]1671
[1158]1672            switch (domain->type)
[879]1673            {
[1158]1674              case CDomain::type_attr::curvilinear:
1675                if (!compressedOutput || !domain->isCompressible())
1676                {
1677                  dimXid     = StdString("x").append(appendDomId);
1678                  dimIdList.push_back(dimXid);
1679                  dimYid     = StdString("y").append(appendDomId);
1680                  dimIdList.push_back(dimYid);
1681                }
1682                dimCoordList.push_back(StdString("nav_lon").append(appendDomId));
1683                dimCoordList.push_back(StdString("nav_lat").append(appendDomId));
1684              break ;
1685              case CDomain::type_attr::rectilinear:
1686                if (!compressedOutput || !domain->isCompressible())
1687                {
1688                  dimXid     = StdString("lon").append(appendDomId);
1689                  dimIdList.push_back(dimXid);
1690                  dimYid     = StdString("lat").append(appendDomId);
1691                  dimIdList.push_back(dimYid);
1692                }
1693              break ;
1694              case CDomain::type_attr::unstructured:
1695              {
1696                if (SuperClassWriter::useCFConvention)
1697                {
1698                  dimXid     = StdString("cell").append(appendDomId);
1699                  dimIdList.push_back(dimXid);
1700                  dimCoordList.push_back(StdString("lon").append(appendDomId));
1701                  dimCoordList.push_back(StdString("lat").append(appendDomId));
1702                }
1703                else
1704                {
1705                  StdString domainName = domain->name;
1706                  if (domain->nvertex == 1)
1707                  {
1708                    dimXid     = "n" + domainName + "_node";
1709                    dimIdList.push_back(dimXid);
1710                    dimCoordList.push_back(StdString(domainName + "_node_x"));
1711                    dimCoordList.push_back(StdString(domainName + "_node_y"));
1712                  }
1713                  else if (domain->nvertex == 2)
1714                  {
1715                    dimXid     = "n" + domainName + "_edge";
1716                    dimIdList.push_back(dimXid);
1717                    dimCoordList.push_back(StdString(domainName + "_edge_x"));
1718                    dimCoordList.push_back(StdString(domainName + "_edge_y"));
1719                  }
1720                  else
1721                  {
1722                    dimXid     = "n" + domainName + "_face";
1723                    dimIdList.push_back(dimXid);
1724                    dimCoordList.push_back(StdString(domainName + "_face_x"));
1725                    dimCoordList.push_back(StdString(domainName + "_face_y"));
1726                  }
1727                }  // ugrid convention
1728              }  // case unstructured domain
[879]1729            }
[1158]1730
1731            if (domain->hasArea)
[879]1732            {
[1158]1733              hasArea = true;
1734              cellMeasures += " area" + appendDomId;
[879]1735            }
[1158]1736            ++idxDomain;
1737          }
1738          else if (1 == axisDomainOrder(i))
1739          {
1740            CAxis* axis = CAxis::get(axisList[idxAxis]);
1741            StdString axisId = axis->getAxisOutputName();
1742
1743            if (compressedOutput && axis->isCompressible())
[879]1744            {
[1158]1745              dimIdList.push_back(axisId + "_points");
1746              field->setUseCompressedOutput();
[879]1747            }
[1158]1748            else
1749              dimIdList.push_back(axisId);
[878]1750
[1158]1751            dimCoordList.push_back(axisId);
1752            ++idxAxis;
1753          }
1754          else // scalar
1755          {
[887]1756             /* Do nothing here */
[1158]1757          }
1758        }
[488]1759
[1158]1760        StdString fieldid = field->getFieldOutputName();
[219]1761
[1158]1762        nc_type type ;
1763        if (field->prec.isEmpty()) type =  NC_FLOAT ;
1764        else
1765        {
1766          if (field->prec==2) type = NC_SHORT ;
1767          else if (field->prec==4)  type =  NC_FLOAT ;
1768          else if (field->prec==8)   type =  NC_DOUBLE ;
1769        }
[488]1770
[1158]1771        bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once);
[488]1772
[1158]1773        if (wtime)
1774        {
1775          if (field->hasTimeInstant && hasTimeInstant) coodinates.push_back(string("time_instant"));
1776          else if (field->hasTimeCentered && hasTimeCentered)  coodinates.push_back(string("time_centered"));
1777          dims.push_back(timeid);
1778        }
[488]1779
[1158]1780        if (compressedOutput && grid->isCompressible())
1781        {
1782          dims.push_back(grid->getId() + "_points");
1783          field->setUseCompressedOutput();
1784        }
1785        else
1786        {
1787          while (!dimIdList.empty())
1788          {
1789            dims.push_back(dimIdList.back());
1790            dimIdList.pop_back();
1791          }
1792        }
[219]1793
[1158]1794        while (!dimCoordList.empty())
1795        {
1796          coodinates.push_back(dimCoordList.back());
1797          dimCoordList.pop_back();
1798        }
[219]1799
[1158]1800        try
1801        {
[498]1802           SuperClassWriter::addVariable(fieldid, type, dims);
[488]1803
[498]1804           if (!field->standard_name.isEmpty())
1805              SuperClassWriter::addAttribute
1806                 ("standard_name",  field->standard_name.getValue(), &fieldid);
[219]1807
[498]1808           if (!field->long_name.isEmpty())
1809              SuperClassWriter::addAttribute
1810                 ("long_name", field->long_name.getValue(), &fieldid);
[219]1811
[498]1812           if (!field->unit.isEmpty())
1813              SuperClassWriter::addAttribute
1814                 ("units", field->unit.getValue(), &fieldid);
[463]1815
[1158]1816           // Ugrid field attributes "mesh" and "location"
1817           if (!SuperClassWriter::useCFConvention)
1818           {
1819            if (!domainList.empty())
1820            {
1821              CDomain* domain = CDomain::get(domainList[0]); // Suppose that we have only domain
1822              StdString mesh = domain->name;
1823              SuperClassWriter::addAttribute("mesh", mesh, &fieldid);
1824              StdString location;
1825              if (domain->nvertex == 1)
1826                location = "node";
1827              else if (domain->nvertex == 2)
1828                location = "edge";
1829              else if (domain->nvertex > 2)
1830                location = "face";
1831              SuperClassWriter::addAttribute("location", location, &fieldid);
1832            }
1833
1834           }
1835
1836           if (!field->valid_min.isEmpty())
[498]1837              SuperClassWriter::addAttribute
1838                 ("valid_min", field->valid_min.getValue(), &fieldid);
[463]1839
[498]1840           if (!field->valid_max.isEmpty())
1841              SuperClassWriter::addAttribute
1842                 ("valid_max", field->valid_max.getValue(), &fieldid);
[464]1843
[498]1844            if (!field->scale_factor.isEmpty())
1845              SuperClassWriter::addAttribute
1846                 ("scale_factor", field->scale_factor.getValue(), &fieldid);
[464]1847
[498]1848             if (!field->add_offset.isEmpty())
1849              SuperClassWriter::addAttribute
1850                 ("add_offset", field->add_offset.getValue(), &fieldid);
[488]1851
[498]1852           SuperClassWriter::addAttribute
1853                 ("online_operation", field->operation.getValue(), &fieldid);
[472]1854
[498]1855          // write child variables as attributes
[488]1856
1857
[1021]1858           bool alreadyAddCellMethod = false;
1859           StdString cellMethodsPrefix(""), cellMethodsSuffix("");
1860           if (!field->cell_methods.isEmpty())
1861           {
[1158]1862              StdString cellMethodString = field->cell_methods;
1863              if (field->cell_methods_mode.isEmpty() ||
[1021]1864                 (CField::cell_methods_mode_attr::overwrite == field->cell_methods_mode))
[1158]1865              {
1866                SuperClassWriter::addAttribute("cell_methods", cellMethodString, &fieldid);
1867                alreadyAddCellMethod = true;
1868              }
1869              else
1870              {
1871                switch (field->cell_methods_mode)
1872                {
1873                  case (CField::cell_methods_mode_attr::prefix):
1874                    cellMethodsPrefix = cellMethodString;
1875                    cellMethodsPrefix += " ";
1876                    break;
1877                  case (CField::cell_methods_mode_attr::suffix):
1878                    cellMethodsSuffix = " ";
1879                    cellMethodsSuffix += cellMethodString;
1880                    break;
1881                  case (CField::cell_methods_mode_attr::none):
1882                    break;
1883                  default:
1884                    break;
1885                }
1886              }
[1021]1887           }
[488]1888
[1021]1889
[498]1890           if (wtime)
1891           {
[614]1892              CDuration freqOp = field->freq_op.getValue();
1893              freqOp.solveTimeStep(*context->calendar);
1894              StdString freqOpStr = freqOp.toStringUDUnits();
[612]1895              SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid);
[437]1896
[614]1897              CDuration freqOut = field->getRelFile()->output_freq.getValue();
1898              freqOut.solveTimeStep(*context->calendar);
1899              SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid);
[612]1900
[1021]1901              StdString cellMethods(cellMethodsPrefix + "time: ");
[612]1902              if (field->operation.getValue() == "instant") cellMethods += "point";
1903              else if (field->operation.getValue() == "average") cellMethods += "mean";
1904              else if (field->operation.getValue() == "accumulate") cellMethods += "sum";
1905              else cellMethods += field->operation;
[614]1906              if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar))
1907                cellMethods += " (interval: " + freqOpStr + ")";
[1021]1908              cellMethods += cellMethodsSuffix;
1909              if (!alreadyAddCellMethod)
1910                SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid);
[498]1911           }
[488]1912
[611]1913           if (hasArea)
1914             SuperClassWriter::addAttribute("cell_measures", cellMeasures, &fieldid);
1915
[498]1916           if (!field->default_value.isEmpty())
1917           {
1918              double default_value = field->default_value.getValue();
1919              float fdefault_value = (float)default_value;
1920              if (type == NC_DOUBLE)
1921                 SuperClassWriter::setDefaultValue(fieldid, &default_value);
1922              else
1923                 SuperClassWriter::setDefaultValue(fieldid, &fdefault_value);
1924           }
1925           else
[517]1926              SuperClassWriter::setDefaultValue(fieldid, (double*)NULL);
[219]1927
[606]1928            if (field->compression_level.isEmpty())
1929              field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level;
1930            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level);
1931
[878]1932           {  // Ecriture des coordonnes
[488]1933
[498]1934              StdString coordstr; //boost::algorithm::join(coodinates, " ")
1935              std::vector<StdString>::iterator
1936                 itc = coodinates.begin(), endc = coodinates.end();
[488]1937
[498]1938              for (; itc!= endc; itc++)
1939              {
1940                 StdString & coord = *itc;
1941                 if (itc+1 != endc)
1942                       coordstr.append(coord).append(" ");
1943                 else  coordstr.append(coord);
1944              }
[219]1945
[498]1946              SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid);
[219]1947
[498]1948           }
[1222]1949
1950           vector<CVariable*> listVars = field->getAllVariables() ;
1951           for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ;
1952
[219]1953         }
[498]1954         catch (CNetCdfException& e)
1955         {
1956           StdString msg("On writing field : ");
1957           msg.append(fieldid); msg.append("\n");
1958           msg.append("In the context : ");
1959           msg.append(context->getId()); msg.append("\n");
1960           msg.append(e.what());
1961           ERROR("CNc4DataOutput::writeField_(CField* field)", << msg);
1962         }
[879]1963      } // writeField_()
[219]1964
1965      //--------------------------------------------------------------
1966
[347]1967      void CNc4DataOutput::writeFile_ (CFile* file)
[219]1968      {
[773]1969         StdString filename = file->getFileOutputName();
[219]1970         StdString description = (!file->description.isEmpty())
1971                               ? file->description.getValue()
[335]1972                               : StdString("Created by xios");
[609]1973
1974         singleDomain = (file->nbDomains == 1);
1975
[1158]1976         StdString conv_str ;
1977         if (file->convention_str.isEmpty())
1978         {
1979            if (SuperClassWriter::useCFConvention) conv_str="CF-1.6" ;
1980            else conv_str="UGRID" ;
1981         }
1982         else conv_str=file->convention_str ;
1983           
[498]1984         try
1985         {
[1309]1986           if (!appendMode) this->writeFileAttributes(filename, description,
1987                                                      conv_str,
1988                                                      StdString("An IPSL model"),
1989                                                      this->getTimeStamp());
[609]1990
[701]1991           if (!appendMode)
1992             SuperClassWriter::addDimension("axis_nbounds", 2);
[498]1993         }
1994         catch (CNetCdfException& e)
1995         {
1996           StdString msg("On writing file : ");
1997           msg.append(filename); msg.append("\n");
1998           msg.append("In the context : ");
1999           CContext* context = CContext::getCurrent() ;
2000           msg.append(context->getId()); msg.append("\n");
2001           msg.append(e.what());
2002           ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg);
2003         }
[219]2004      }
[488]2005
[472]2006      void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)
2007      {
[773]2008        StdString name = var->getVariableOutputName();
[488]2009
[498]2010        try
2011        {
[527]2012          if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32)
2013            addAttribute(name, var->getData<int>(), &fieldId);
2014          else if (var->type.getValue() == CVariable::type_attr::t_int16)
2015            addAttribute(name, var->getData<short int>(), &fieldId);
2016          else if (var->type.getValue() == CVariable::type_attr::t_float)
2017            addAttribute(name, var->getData<float>(), &fieldId);
2018          else if (var->type.getValue() == CVariable::type_attr::t_double)
2019            addAttribute(name, var->getData<double>(), &fieldId);
2020          else if (var->type.getValue() == CVariable::type_attr::t_string)
2021            addAttribute(name, var->getData<string>(), &fieldId);
2022          else
2023            ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)",
2024                  << "Unsupported variable of type " << var->type.getStringValue());
[498]2025        }
2026       catch (CNetCdfException& e)
2027       {
2028         StdString msg("On writing attributes of variable with name : ");
2029         msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n");
2030         msg.append("In the context : ");
2031         CContext* context = CContext::getCurrent() ;
2032         msg.append(context->getId()); msg.append("\n");
2033         msg.append(e.what());
2034         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg);
2035       }
[472]2036     }
[488]2037
[472]2038     void CNc4DataOutput::writeAttribute_ (CVariable* var)
2039     {
[773]2040        StdString name = var->getVariableOutputName();
2041
[498]2042        try
2043        {
[527]2044          if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32)
2045            addAttribute(name, var->getData<int>());
2046          else if (var->type.getValue() == CVariable::type_attr::t_int16)
2047            addAttribute(name, var->getData<short int>());
2048          else if (var->type.getValue() == CVariable::type_attr::t_float)
2049            addAttribute(name, var->getData<float>());
2050          else if (var->type.getValue() == CVariable::type_attr::t_double)
2051            addAttribute(name, var->getData<double>());
2052          else if (var->type.getValue() == CVariable::type_attr::t_string)
2053            addAttribute(name, var->getData<string>());
2054          else
2055            ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)",
2056                  << "Unsupported variable of type " << var->type.getStringValue());
[498]2057        }
2058       catch (CNetCdfException& e)
2059       {
2060         StdString msg("On writing attributes of variable with name : ");
2061         msg.append(name); msg.append("\n");
2062         msg.append("In the context : ");
2063         CContext* context = CContext::getCurrent() ;
2064         msg.append(context->getId()); msg.append("\n");
2065         msg.append(e.what());
2066         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg);
2067       }
[488]2068     }
2069
[321]2070      void CNc4DataOutput::syncFile_ (void)
2071      {
[498]2072        try
2073        {
2074          SuperClassWriter::sync() ;
2075        }
2076        catch (CNetCdfException& e)
2077        {
2078         StdString msg("On synchronizing the write among processes");
2079         msg.append("In the context : ");
2080         CContext* context = CContext::getCurrent() ;
2081         msg.append(context->getId()); msg.append("\n");
2082         msg.append(e.what());
2083         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
2084        }
[321]2085      }
[219]2086
[286]2087      void CNc4DataOutput::closeFile_ (void)
2088      {
[498]2089        try
2090        {
2091          SuperClassWriter::close() ;
2092        }
2093        catch (CNetCdfException& e)
2094        {
2095         StdString msg("On closing file");
2096         msg.append("In the context : ");
2097         CContext* context = CContext::getCurrent() ;
2098         msg.append(context->getId()); msg.append("\n");
2099         msg.append(e.what());
2100         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
2101        }
2102
[286]2103      }
2104
[219]2105      //---------------------------------------------------------------
2106
2107      StdString CNc4DataOutput::getTimeStamp(void) const
2108      {
2109         const int buffer_size = 100;
2110         time_t rawtime;
2111         struct tm * timeinfo = NULL;
2112         char buffer [buffer_size];
[1158]2113         StdString formatStr;
2114         if (file->time_stamp_format.isEmpty()) formatStr="%Y-%b-%d %H:%M:%S %Z" ;
2115         else formatStr=file->time_stamp_format;
[219]2116
[1158]2117//         time ( &rawtime );
2118//         timeinfo = localtime ( &rawtime );
[219]2119         time ( &rawtime );
[1158]2120         timeinfo = gmtime ( &rawtime );
2121         strftime (buffer, buffer_size, formatStr.c_str(), timeinfo);
[219]2122
2123         return (StdString(buffer));
2124      }
[488]2125
[219]2126      //---------------------------------------------------------------
[488]2127
[347]2128      void CNc4DataOutput::writeFieldData_ (CField*  field)
[219]2129      {
[707]2130        CContext* context = CContext::getCurrent();
2131        CContextServer* server = context->server;
2132        CGrid* grid = field->grid;
[300]2133
[1158]2134        if (field->getNStep()<1) 
2135        {
2136          return;
2137        }
[952]2138       
[707]2139        if (!grid->doGridHaveDataToWrite())
[1158]2140          if (SuperClass::type == MULTI_FILE || !isCollective)
2141          {
2142            return;
2143          }
[488]2144
[770]2145        StdString fieldid = field->getFieldOutputName();
[286]2146
[707]2147        StdOStringStream oss;
2148        string timeAxisId;
[1158]2149        if (field->hasTimeInstant) timeAxisId = "time_instant";
2150        else if (field->hasTimeCentered) timeAxisId = "time_centered";
[488]2151
[802]2152        StdString timeBoundId = getTimeCounterName() + "_bounds";
[449]2153
[707]2154        StdString timeAxisBoundId;
[1158]2155        if (field->hasTimeInstant) timeAxisBoundId = "time_instant_bounds";
2156        else if (field->hasTimeCentered) timeAxisBoundId = "time_centered_bounds";
[488]2157
[707]2158        if (!field->wasWritten())
2159        {
[1158]2160          if (appendMode && field->file->record_offset.isEmpty() && 
2161              field->getOperationTimeType() != func::CFunctor::once)
[707]2162          {
[1158]2163            double factorUnit;
2164            if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days)
2165            factorUnit=context->getCalendar()->getDayLengthInSeconds() ;
2166            else factorUnit=1 ;
2167            field->resetNStep(getRecordFromTime(field->last_Write_srv,factorUnit) + 1);
[707]2168          }
[488]2169
[707]2170          field->setWritten();
2171        }
[488]2172
2173
[707]2174        CArray<double,1> time_data(1);
2175        CArray<double,1> time_data_bound(2);
2176        CArray<double,1> time_counter(1);
2177        CArray<double,1> time_counter_bound(2);
2178
2179        bool wtime = (field->getOperationTimeType() != func::CFunctor::once);
[1158]2180        bool wtimeCounter =false ;
2181        bool wtimeData =false ;
2182       
[707]2183
[444]2184        if (wtime)
2185        {
[692]2186          Time lastWrite = field->last_Write_srv;
2187          Time lastLastWrite = field->lastlast_Write_srv;
2188
[1158]2189         
2190          if (field->hasTimeInstant)
2191          {
2192            time_data(0) = time_data_bound(1) = lastWrite;
[692]2193            time_data_bound(0) = time_data_bound(1) = lastWrite;
[1158]2194            if (timeCounterType==instant)
2195            {
2196              time_counter(0) = time_data(0);
2197              time_counter_bound(0) = time_data_bound(0);
2198              time_counter_bound(1) = time_data_bound(1);
2199              wtimeCounter=true ;
2200            }
2201            if (hasTimeInstant) wtimeData=true ;
2202          }
2203          else if (field->hasTimeCentered)
[488]2204          {
[1158]2205            time_data(0) = (lastWrite + lastLastWrite) / 2;
[692]2206            time_data_bound(0) = lastLastWrite;
2207            time_data_bound(1) = lastWrite;
[1158]2208            if (timeCounterType==centered)
2209            {
2210              time_counter(0) = time_data(0) ;
2211              time_counter_bound(0) = time_data_bound(0) ;
2212              time_counter_bound(1) = time_data_bound(1) ;
2213              wtimeCounter=true ;
2214            }
2215            if (hasTimeCentered) wtimeData=true ;
[488]2216          }
2217
[1158]2218          if (timeCounterType==record)
2219          {
[692]2220            time_counter(0) = field->getNStep() - 1;
[1158]2221            time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1;
2222            wtimeCounter=true ;
2223          }
[692]2224
[1158]2225          if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days)
[692]2226          {
[1158]2227            double secByDay=context->getCalendar()->getDayLengthInSeconds() ;
2228            time_data/=secByDay;
2229            time_data_bound/=secByDay;
2230            time_counter/=secByDay;
2231            time_counter_bound/=secByDay;
[692]2232          }
2233        }
2234
[707]2235         bool isRoot = (server->intraCommRank == 0);
[488]2236
[464]2237         if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
2238         {
[707]2239           double scaleFactor = 1.0;
2240           double addOffset = 0.0;
2241           if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor;
2242           if (!field->add_offset.isEmpty()) addOffset = field->add_offset;
2243           field->scaleFactorAddOffset(scaleFactor, addOffset);
[464]2244         }
[488]2245
[498]2246         try
[219]2247         {
[676]2248           size_t writtenSize;
2249           if (field->getUseCompressedOutput())
2250             writtenSize = grid->getNumberWrittenIndexes();
2251           else
2252             writtenSize = grid->getWrittenDataSize();
2253
2254           CArray<double,1> fieldData(writtenSize);
[567]2255           if (!field->default_value.isEmpty()) fieldData = field->default_value;
[676]2256
2257           if (field->getUseCompressedOutput())
2258             field->outputCompressedField(fieldData);
2259           else
2260             field->outputField(fieldData);
2261
[707]2262           if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData);
[567]2263
2264           switch (SuperClass::type)
[498]2265           {
[567]2266              case (MULTI_FILE) :
2267              {
[1158]2268                 CTimer::get("Files : writing data").resume();
[692]2269                 SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1);
[1158]2270                 CTimer::get("Files : writing data").suspend();
[567]2271                 if (wtime)
2272                 {
[1158]2273                   CTimer::get("Files : writing time axis").resume();
2274                   if ( wtimeData)
[692]2275                   {
[1158]2276//                     SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1);
2277//                     SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1);
2278                       SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot);
2279                       SuperClassWriter::writeTimeAxisDataBounds(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot);
2280                  }
2281                   if (wtimeCounter)
2282                   {
2283//                     SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1);
2284//                     if (timeCounterType!=record) SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1);
2285                     SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1,isRoot);
2286                     if (timeCounterType!=record) SuperClassWriter::writeTimeAxisDataBounds(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot);
[692]2287                   }
[1158]2288                   CTimer::get("Files : writing time axis").suspend();
[567]2289                 }
[707]2290                 break;
[567]2291              }
2292              case (ONE_FILE) :
2293              {
[676]2294                const std::vector<int>& nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
2295                const std::vector<int>& nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
2296                const std::vector<int>& nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
[464]2297
[676]2298                std::vector<StdSize> start, count;
[464]2299
[676]2300                if (field->getUseCompressedOutput())
2301                {
2302                  if (grid->isCompressible())
2303                  {
2304                    start.push_back(grid->getOffsetWrittenIndexes());
2305                    count.push_back(grid->getNumberWrittenIndexes());
2306                  }
2307                  else
2308                  {
[887]2309                    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[676]2310                    std::vector<StdString> domainList = grid->getDomainList();
2311                    std::vector<StdString> axisList   = grid->getAxisList();
2312                    int numElement = axisDomainOrder.numElements();
2313                    int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
2314                    int idx = nZoomBeginGlobal.size() - 1;
[464]2315
[676]2316                    start.reserve(nZoomBeginGlobal.size());
2317                    count.reserve(nZoomBeginGlobal.size());
2318
2319
2320                    for (int i = numElement - 1; i >= 0; --i)
2321                    {
[887]2322                      if (2 == axisDomainOrder(i))
[676]2323                      {
2324                        CDomain* domain = CDomain::get(domainList[idxDomain]);
2325
2326                        if (domain->isCompressible())
2327                        {
[1249]2328                          start.push_back(domain->getOffsetWrittenIndexes(comm_file));
2329                          count.push_back(domain->getNumberWrittenIndexes(comm_file));
[710]2330                          idx -= 2;
[676]2331                        }
2332                        else
2333                        {
[710]2334                          if ((domain->type) != CDomain::type_attr::unstructured)
2335                          {
2336                            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
2337                            count.push_back(nZoomSizeServer[idx]);
2338                          }
2339                          --idx;
[676]2340                          start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
2341                          count.push_back(nZoomSizeServer[idx]);
[710]2342                          --idx;
[676]2343                        }
2344                        --idxDomain;
2345                      }
[887]2346                      else if (1 == axisDomainOrder(i))
[676]2347                      {
2348                        CAxis* axis = CAxis::get(axisList[idxAxis]);
2349
2350                        if (axis->isCompressible())
2351                        {
[1249]2352                          start.push_back(axis->getOffsetWrittenIndexes(comm_file));
2353                          count.push_back(axis->getNumberWrittenIndexes(comm_file));
[676]2354                        }
2355                        else
2356                        {
2357                          start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
2358                          count.push_back(nZoomSizeServer[idx]);
2359                        }
2360
2361                        --idxAxis;
2362                        --idx;
2363                      }
2364                    }
[1158]2365                  }
[676]2366                }
2367                else
[498]2368                {
[887]2369                  CArray<int,1> axisDomainOrder = grid->axis_domain_order;
[705]2370                  std::vector<StdString> domainList = grid->getDomainList();
2371                  std::vector<StdString> axisList   = grid->getAxisList();
2372                  int numElement = axisDomainOrder.numElements();
2373                  int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
[1025]2374                  int idx = domainList.size() * 2 + axisList.size() - 1;// nZoomBeginGlobal.size() - 1;
[705]2375
2376                  start.reserve(nZoomBeginGlobal.size());
2377                  count.reserve(nZoomBeginGlobal.size());
2378
2379                  for (int i = numElement - 1; i >= 0; --i)
2380                  {
[887]2381                    if (2 == axisDomainOrder(i))
[705]2382                    {
2383                      CDomain* domain = CDomain::get(domainList[idxDomain]);
[710]2384                      if ((domain->type) != CDomain::type_attr::unstructured)
[705]2385                      {
[1099]2386                        start.push_back(domain->zoom_jbegin - domain->global_zoom_jbegin);
2387                        count.push_back(domain->zoom_nj);
[705]2388                      }
2389                      --idx ;
[1143]2390
[1099]2391                        start.push_back(domain->zoom_ibegin - domain->global_zoom_ibegin);
2392                        count.push_back(domain->zoom_ni);
[705]2393                      --idx ;
2394                      --idxDomain;
2395                    }
[887]2396                    else if (1 == axisDomainOrder(i))
[705]2397                    {
[1143]2398                        CAxis* axis = CAxis::get(axisList[idxAxis]);
[1099]2399                        start.push_back(axis->zoom_begin - axis->global_zoom_begin);
2400                        count.push_back(axis->zoom_n);
[705]2401                      --idx;
[1025]2402                      --idxAxis;
[887]2403                    }
2404                    else
2405                    {
2406                      if (1 == axisDomainOrder.numElements())
2407                      {
2408                        start.push_back(0);
2409                        count.push_back(1);
2410                      }
2411                      --idx;
2412                    }
[705]2413                  }
[498]2414                }
[488]2415
[1158]2416
2417                CTimer::get("Files : writing data").resume();
[676]2418                SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count);
[1158]2419                CTimer::get("Files : writing data").suspend();
2420
2421                 if (wtime)
2422                 {
2423                   CTimer::get("Files : writing time axis").resume();
2424                   if ( wtimeData)
[692]2425                   {
[1158]2426//                     SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1);
2427//                     SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1);
2428                     SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot);
2429                     SuperClassWriter::writeTimeAxisDataBounds(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot);
[692]2430                   }
[1158]2431                   if (wtimeCounter)
2432                   {
2433//                     SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1);
2434//                     if (timeCounterType!=record) SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1);
2435                     SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1,isRoot);
2436                     if (timeCounterType!=record) SuperClassWriter::writeTimeAxisDataBounds(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot);
[586]2437
[1158]2438                   }
2439                   CTimer::get("Files : writing time axis").suspend(); 
2440                 }
2441
[586]2442                break;
[286]2443              }
[567]2444            }
[219]2445         }
[498]2446         catch (CNetCdfException& e)
2447         {
2448           StdString msg("On writing field data: ");
2449           msg.append(fieldid); msg.append("\n");
2450           msg.append("In the context : ");
2451           msg.append(context->getId()); msg.append("\n");
2452           msg.append(e.what());
[1130]2453           ERROR("CNc4DataOutput::writeFieldData_ (CField*  field)", << msg);
[498]2454         }
[219]2455      }
2456
2457      //---------------------------------------------------------------
2458
2459      void CNc4DataOutput::writeTimeAxis_
[347]2460                  (CField*    field,
[343]2461                   const boost::shared_ptr<CCalendar> cal)
[219]2462      {
2463         StdOStringStream oss;
[1158]2464         bool createInstantAxis=false ;
2465         bool createCenteredAxis=false ;
2466         bool createTimeCounterAxis=false ;
2467         
[645]2468         if (field->getOperationTimeType() == func::CFunctor::once) return ;
[488]2469
2470
[1158]2471         StdString axisId ;
2472         StdString axisBoundId;
[802]2473         StdString timeid(getTimeCounterName());
[614]2474         StdString timeBoundId("axis_nbounds");
[488]2475
[1158]2476         StdString strTimeUnits ;
2477         if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) strTimeUnits="days since " ;
2478         else  strTimeUnits="seconds since " ;
2479 
2480         if (field->getOperationTimeType() == func::CFunctor::instant) field->hasTimeInstant = true;
2481         if (field->getOperationTimeType() == func::CFunctor::centered) field->hasTimeCentered = true;
2482
2483
2484         if (field->file->time_counter.isEmpty())
[488]2485         {
[1158]2486           if (timeCounterType==none) createTimeCounterAxis=true ;
2487           if (field->hasTimeCentered)
2488           {
2489             timeCounterType=centered ;
2490             if (!hasTimeCentered) createCenteredAxis=true ;
2491           }
2492           if (field->hasTimeInstant)
2493           {
2494             if (timeCounterType==none) timeCounterType=instant ;
2495             if (!hasTimeInstant) createInstantAxis=true ;
2496           }
[488]2497         }
[1158]2498         else if (field->file->time_counter==CFile::time_counter_attr::instant)
2499         {
2500           if (field->hasTimeCentered)
2501           {
2502             if (!hasTimeCentered) createCenteredAxis=true ;
2503           }
2504           if (field->hasTimeInstant)
2505           {
2506             if (timeCounterType==none) createTimeCounterAxis=true ;
2507             timeCounterType=instant ;
2508             if (!hasTimeInstant) createInstantAxis=true ;
2509           }
2510         }
2511         else if (field->file->time_counter==CFile::time_counter_attr::centered)
2512         {
2513           if (field->hasTimeCentered)
2514           {
2515             if (timeCounterType==none) createTimeCounterAxis=true ;
2516             timeCounterType=centered ;
2517             if (!hasTimeCentered) createCenteredAxis=true ;
2518           }
2519           if (field->hasTimeInstant)
2520           {
2521             if (!hasTimeInstant) createInstantAxis=true ;
2522           }
2523         }
2524         else if (field->file->time_counter==CFile::time_counter_attr::instant_exclusive)
2525         {
2526           if (field->hasTimeCentered)
2527           {
2528             if (!hasTimeCentered) createCenteredAxis=true ;
2529           }
2530           if (field->hasTimeInstant)
2531           {
2532             if (timeCounterType==none) createTimeCounterAxis=true ;
2533             timeCounterType=instant ;
2534           }
2535         }
2536         else if (field->file->time_counter==CFile::time_counter_attr::centered_exclusive)
2537         {
2538           if (field->hasTimeCentered)
2539           {
2540             if (timeCounterType==none) createTimeCounterAxis=true ;
2541             timeCounterType=centered ;
2542           }
2543           if (field->hasTimeInstant)
2544           {
2545             if (!hasTimeInstant) createInstantAxis=true ;
2546           }
2547         }
2548         else if (field->file->time_counter==CFile::time_counter_attr::exclusive)
2549         {
2550           if (field->hasTimeCentered)
2551           {
2552             if (timeCounterType==none) createTimeCounterAxis=true ;
2553             if (timeCounterType==instant) createInstantAxis=true ;
2554             timeCounterType=centered ;
2555           }
2556           if (field->hasTimeInstant)
2557           {
2558             if (timeCounterType==none)
2559             {
2560               createTimeCounterAxis=true ;
2561               timeCounterType=instant ;
2562             }
2563             if (timeCounterType==centered)
2564             {
2565               if (!hasTimeInstant) createInstantAxis=true ;
2566             }
2567           }
2568         }
2569         else if (field->file->time_counter==CFile::time_counter_attr::none)
2570         {
2571           if (field->hasTimeCentered)
2572           {
2573             if (!hasTimeCentered) createCenteredAxis=true ;
2574           }
2575           if (field->hasTimeInstant)
2576           {
2577             if (!hasTimeInstant) createInstantAxis=true ;
2578           }
2579         }
2580         else if (field->file->time_counter==CFile::time_counter_attr::record)
2581         {
2582           if (timeCounterType==none) createTimeCounterAxis=true ;
2583           timeCounterType=record ;
2584           if (field->hasTimeCentered)
2585           {
2586             if (!hasTimeCentered) createCenteredAxis=true ;
2587           }
2588           if (field->hasTimeInstant)
2589           {
2590             if (!hasTimeInstant) createInstantAxis=true ;
2591           }
2592         }
2593         
2594         if (createInstantAxis)
2595         {
2596           axisId="time_instant" ;
2597           axisBoundId="time_instant_bounds";
2598           hasTimeInstant=true ;
2599         }
[488]2600
[1158]2601         if (createCenteredAxis)
2602         {
2603           axisId="time_centered" ;
2604           axisBoundId="time_centered_bounds";
2605           hasTimeCentered=true ;
2606         }
2607
2608         
[498]2609         try
[219]2610         {
[1158]2611            std::vector<StdString> dims;
2612           
2613            if (createInstantAxis || createCenteredAxis)
2614            {
2615              // Adding time_instant or time_centered
2616              dims.push_back(timeid);
2617              if (!SuperClassWriter::varExist(axisId))
2618              {
2619                SuperClassWriter::addVariable(axisId, NC_DOUBLE, dims);
[488]2620
[1158]2621                CDate timeOrigin=cal->getTimeOrigin() ;
2622                StdOStringStream oss2;
2623                StdString strInitdate=oss2.str() ;
2624                StdString strTimeOrigin=timeOrigin.toString() ;
2625                this->writeTimeAxisAttributes(axisId, cal->getType(),strTimeUnits+strTimeOrigin,
2626                                              strTimeOrigin, axisBoundId);
2627             }
[219]2628
[1158]2629             // Adding time_instant_bounds or time_centered_bounds variables
2630             if (!SuperClassWriter::varExist(axisBoundId))
2631             {
2632                dims.clear() ;
2633                dims.push_back(timeid);
2634                dims.push_back(timeBoundId);
2635                SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
2636             }
[498]2637           }
[488]2638
[1158]2639           if (createTimeCounterAxis)
[498]2640           {
[692]2641             // Adding time_counter
[1158]2642             axisId = getTimeCounterName();
[802]2643             axisBoundId = getTimeCounterName() + "_bounds";
[692]2644             dims.clear();
2645             dims.push_back(timeid);
[1158]2646             if (!SuperClassWriter::varExist(axisId))
[692]2647             {
[1158]2648                SuperClassWriter::addVariable(axisId, NC_DOUBLE, dims);
2649                SuperClassWriter::addAttribute("axis", string("T"), &axisId);
[488]2650
[1158]2651                if (field->file->time_counter.isEmpty() || 
2652                   (field->file->time_counter != CFile::time_counter_attr::record))
[692]2653                {
2654                  CDate timeOrigin = cal->getTimeOrigin();
2655                  StdString strTimeOrigin = timeOrigin.toString();
[498]2656
[1158]2657                  this->writeTimeAxisAttributes(axisId, cal->getType(),
2658                                                strTimeUnits+strTimeOrigin,
[692]2659                                                strTimeOrigin, axisBoundId);
2660                }
2661             }
2662
2663             // Adding time_counter_bound dimension
[1158]2664             if (field->file->time_counter.isEmpty() || (field->file->time_counter != CFile::time_counter_attr::record))
[692]2665             {
2666                if (!SuperClassWriter::varExist(axisBoundId))
2667                {
2668                  dims.clear();
2669                  dims.push_back(timeid);
2670                  dims.push_back(timeBoundId);
2671                  SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
2672                }
2673             }
[498]2674           }
[488]2675         }
[498]2676         catch (CNetCdfException& e)
[488]2677         {
[498]2678           StdString msg("On writing time axis data: ");
2679           msg.append("In the context : ");
2680           CContext* context = CContext::getCurrent() ;
2681           msg.append(context->getId()); msg.append("\n");
2682           msg.append(e.what());
2683           ERROR("CNc4DataOutput::writeTimeAxis_ (CField*    field, \
2684                  const boost::shared_ptr<CCalendar> cal)", << msg);
[488]2685         }
[219]2686      }
2687
2688      //---------------------------------------------------------------
[488]2689
[219]2690      void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name,
2691                                                   const StdString & calendar,
2692                                                   const StdString & units,
2693                                                   const StdString & time_origin,
[488]2694                                                   const StdString & time_bounds,
[219]2695                                                   const StdString & standard_name,
[613]2696                                                   const StdString & long_name)
[219]2697      {
[498]2698         try
2699         {
2700           SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
2701           SuperClassWriter::addAttribute("long_name",     long_name    , &axis_name);
2702           SuperClassWriter::addAttribute("calendar",      calendar     , &axis_name);
2703           SuperClassWriter::addAttribute("units",         units        , &axis_name);
2704           SuperClassWriter::addAttribute("time_origin",   time_origin  , &axis_name);
2705           SuperClassWriter::addAttribute("bounds",        time_bounds  , &axis_name);
2706         }
2707         catch (CNetCdfException& e)
2708         {
2709           StdString msg("On writing time axis Attribute: ");
2710           msg.append("In the context : ");
2711           CContext* context = CContext::getCurrent() ;
2712           msg.append(context->getId()); msg.append("\n");
2713           msg.append(e.what());
2714           ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \
[613]2715                                                          const StdString & calendar,\
2716                                                          const StdString & units, \
2717                                                          const StdString & time_origin, \
2718                                                          const StdString & time_bounds, \
2719                                                          const StdString & standard_name, \
2720                                                          const StdString & long_name)", << msg);
[498]2721         }
[219]2722      }
[488]2723
[219]2724      //---------------------------------------------------------------
2725
2726      void CNc4DataOutput::writeAxisAttributes(const StdString & axis_name,
2727                                               const StdString & axis,
2728                                               const StdString & standard_name,
2729                                               const StdString & long_name,
2730                                               const StdString & units,
2731                                               const StdString & nav_model)
2732      {
[498]2733         try
2734         {
[613]2735          if (!axis.empty())
2736            SuperClassWriter::addAttribute("axis"       , axis         , &axis_name);
2737
[498]2738          SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
2739          SuperClassWriter::addAttribute("long_name"    , long_name    , &axis_name);
2740          SuperClassWriter::addAttribute("units"        , units        , &axis_name);
[973]2741//          SuperClassWriter::addAttribute("nav_model"    , nav_model    , &axis_name);
[498]2742         }
2743         catch (CNetCdfException& e)
2744         {
2745           StdString msg("On writing Axis Attribute: ");
2746           msg.append("In the context : ");
2747           CContext* context = CContext::getCurrent() ;
2748           msg.append(context->getId()); msg.append("\n");
2749           msg.append(e.what());
2750           ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \
[613]2751                                                      const StdString & axis, \
2752                                                      const StdString & standard_name, \
2753                                                      const StdString & long_name, \
2754                                                      const StdString & units, \
2755                                                      const StdString & nav_model)", << msg);
[498]2756         }
[219]2757      }
2758
2759      //---------------------------------------------------------------
[488]2760
[219]2761      void CNc4DataOutput::writeLocalAttributes
2762         (int ibegin, int ni, int jbegin, int nj, StdString domid)
2763      {
[498]2764        try
2765        {
[318]2766         SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin);
2767         SuperClassWriter::addAttribute(StdString("ni"    ).append(domid), ni);
2768         SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin);
2769         SuperClassWriter::addAttribute(StdString("nj"    ).append(domid), nj);
[498]2770        }
2771        catch (CNetCdfException& e)
2772        {
2773           StdString msg("On writing Local Attributes: ");
2774           msg.append("In the context : ");
2775           CContext* context = CContext::getCurrent() ;
2776           msg.append(context->getId()); msg.append("\n");
2777           msg.append(e.what());
2778           ERROR("CNc4DataOutput::writeLocalAttributes \
2779                  (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg);
2780        }
2781
[219]2782      }
2783
[628]2784      void CNc4DataOutput::writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid,
2785                                                       int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)
[391]2786      {
2787         CArray<int,1> array(2) ;
2788
[498]2789         try
2790         {
2791           SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ;
2792           SuperClassWriter::addAttribute("DOMAIN_number", rank) ;
[629]2793           array = SuperClassWriter::getDimension(dimXid) + 1, SuperClassWriter::getDimension(dimYid) + 1;
[498]2794           SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ;
2795           array=ni_glo,nj_glo ;
2796           SuperClassWriter::addAttribute("DOMAIN_size_global", array) ;
2797           array=ni,nj ;
2798           SuperClassWriter::addAttribute("DOMAIN_size_local", array) ;
[819]2799           array=ibegin+1,jbegin+1 ;
[498]2800           SuperClassWriter::addAttribute("DOMAIN_position_first", array) ;
[819]2801           array=ibegin+ni-1+1,jbegin+nj-1+1 ;
[498]2802           SuperClassWriter::addAttribute("DOMAIN_position_last",array) ;
2803           array=0,0 ;
2804           SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ;
2805           SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array);
2806           SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ;
2807  /*
2808           SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ;
2809           SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ;
2810           SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ;
2811           SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ;
2812  */
2813         }
2814         catch (CNetCdfException& e)
2815         {
[628]2816           StdString msg("On writing Local Attributes IOIPSL \n");
[498]2817           msg.append("In the context : ");
2818           CContext* context = CContext::getCurrent() ;
2819           msg.append(context->getId()); msg.append("\n");
2820           msg.append(e.what());
2821           ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \
2822                  (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg);
2823         }
[391]2824      }
[219]2825      //---------------------------------------------------------------
2826
2827      void CNc4DataOutput:: writeFileAttributes(const StdString & name,
2828                                                const StdString & description,
2829                                                const StdString & conventions,
2830                                                const StdString & production,
2831                                                const StdString & timeStamp)
2832      {
[498]2833         try
2834         {
2835           SuperClassWriter::addAttribute("name"       , name);
2836           SuperClassWriter::addAttribute("description", description);
[613]2837           SuperClassWriter::addAttribute("title"      , description);
2838           SuperClassWriter::addAttribute("Conventions", conventions);
[1158]2839           // SuperClassWriter::addAttribute("production" , production);
2840
2841           StdString timeStampStr ;
2842           if (file->time_stamp_name.isEmpty()) timeStampStr="timeStamp" ;
2843           else timeStampStr=file->time_stamp_name ;
2844           SuperClassWriter::addAttribute(timeStampStr, timeStamp);
2845
2846           StdString uuidName ;
2847           if (file->uuid_name.isEmpty()) uuidName="uuid" ;
2848           else uuidName=file->uuid_name ;
2849
2850           if (file->uuid_format.isEmpty()) SuperClassWriter::addAttribute(uuidName, getUuidStr());
2851           else SuperClassWriter::addAttribute(uuidName, getUuidStr(file->uuid_format));
2852         
[498]2853         }
2854         catch (CNetCdfException& e)
2855         {
2856           StdString msg("On writing File Attributes \n ");
2857           msg.append("In the context : ");
2858           CContext* context = CContext::getCurrent() ;
2859           msg.append(context->getId()); msg.append("\n");
2860           msg.append(e.what());
2861           ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \
2862                                                const StdString & description, \
2863                                                const StdString & conventions, \
2864                                                const StdString & production, \
2865                                                const StdString & timeStamp)", << msg);
2866         }
[219]2867      }
2868
2869      //---------------------------------------------------------------
2870
2871      void CNc4DataOutput::writeMaskAttributes(const StdString & mask_name,
2872                                               int data_dim,
2873                                               int data_ni,
2874                                               int data_nj,
2875                                               int data_ibegin,
2876                                               int data_jbegin)
2877      {
[498]2878         try
2879         {
2880           SuperClassWriter::addAttribute("data_dim"   , data_dim   , &mask_name);
2881           SuperClassWriter::addAttribute("data_ni"    , data_ni    , &mask_name);
2882           SuperClassWriter::addAttribute("data_nj"    , data_nj    , &mask_name);
2883           SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name);
2884           SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name);
2885         }
2886         catch (CNetCdfException& e)
2887         {
2888           StdString msg("On writing Mask Attributes \n ");
2889           msg.append("In the context : ");
2890           CContext* context = CContext::getCurrent() ;
2891           msg.append(context->getId()); msg.append("\n");
2892           msg.append(e.what());
2893           ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \
2894                                               int data_dim, \
2895                                               int data_ni, \
2896                                               int data_nj, \
2897                                               int data_ibegin, \
2898                                               int data_jbegin)", << msg);
2899         }
[219]2900      }
2901
2902      ///--------------------------------------------------------------
2903
[1158]2904      StdSize CNc4DataOutput::getRecordFromTime(Time time, double factorUnit)
[707]2905      {
2906        std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time);
2907        if (it == timeToRecordCache.end())
2908        {
[802]2909          StdString timeAxisBoundsId(getTimeCounterName() + "_bounds");
[1158]2910          if (!SuperClassWriter::varExist(timeAxisBoundsId)) timeAxisBoundsId = "time_centered_bounds";
2911          if (!SuperClassWriter::varExist(timeAxisBoundsId)) timeAxisBoundsId = "time_instant_bounds";
[707]2912
2913          CArray<double,2> timeAxisBounds;
[1158]2914          std::vector<StdSize> dimSize(SuperClassWriter::getDimensions(timeAxisBoundsId)) ;
2915         
[707]2916          StdSize record = 0;
2917          double dtime(time);
[1158]2918          for (int n = dimSize[0] - 1; n >= 0; n--)
[707]2919          {
[1158]2920            SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective, n);
2921            timeAxisBounds*=factorUnit ;
2922            if (timeAxisBounds(1, 0) < dtime)
[707]2923            {
2924              record = n + 1;
2925              break;
2926            }
2927          }
2928          it = timeToRecordCache.insert(std::make_pair(time, record)).first;
2929        }
2930        return it->second;
2931      }
[774]2932
2933      ///--------------------------------------------------------------
2934
2935      bool CNc4DataOutput::isWrittenDomain(const std::string& domainName) const
2936      {
2937        return (this->writtenDomains.find(domainName) != this->writtenDomains.end());
2938      }
2939
2940      bool CNc4DataOutput::isWrittenCompressedDomain(const std::string& domainName) const
2941      {
2942        return (this->writtenCompressedDomains.find(domainName) != this->writtenCompressedDomains.end());
2943      }
2944
2945      bool CNc4DataOutput::isWrittenAxis(const std::string& axisName) const
2946      {
2947        return (this->writtenAxis.find(axisName) != this->writtenAxis.end());
2948      }
2949
2950      bool CNc4DataOutput::isWrittenCompressedAxis(const std::string& axisName) const
2951      {
2952        return (this->writtenCompressedAxis.find(axisName) != this->writtenCompressedAxis.end());
2953      }
2954
[887]2955      bool CNc4DataOutput::isWrittenScalar(const std::string& scalarName) const
2956      {
2957        return (this->writtenScalar.find(scalarName) != this->writtenScalar.end());
2958      }
2959
[774]2960      void CNc4DataOutput::setWrittenDomain(const std::string& domainName)
2961      {
2962        this->writtenDomains.insert(domainName);
2963      }
2964
2965      void CNc4DataOutput::setWrittenCompressedDomain(const std::string& domainName)
2966      {
2967        this->writtenCompressedDomains.insert(domainName);
2968      }
2969
2970      void CNc4DataOutput::setWrittenAxis(const std::string& axisName)
2971      {
2972        this->writtenAxis.insert(axisName);
2973      }
2974
2975      void CNc4DataOutput::setWrittenCompressedAxis(const std::string& axisName)
2976      {
2977        this->writtenCompressedAxis.insert(axisName);
2978      }
[887]2979
2980      void CNc4DataOutput::setWrittenScalar(const std::string& scalarName)
2981      {
2982        this->writtenScalar.insert(scalarName);
2983      }
[335]2984} // namespace xios
Note: See TracBrowser for help on using the repository browser.