source: XIOS/dev/branch_yushan_merged/src/io/nc4_data_output.cpp @ 1179

Last change on this file since 1179 was 1176, checked in by yushan, 7 years ago

save modif

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