source: XIOS/dev/branch_openmp/src/io/nc4_data_output.cpp @ 1328

Last change on this file since 1328 was 1328, checked in by yushan, 6 years ago

dev_omp

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