source: XIOS/dev/dev_olga/src/io/nc4_data_output.cpp @ 1158

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

Two server levels: merging with trunk r1137.
There are bugs.

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