source: XIOS/trunk/src/io/nc4_data_output.cpp @ 701

Last change on this file since 701 was 701, checked in by rlacroix, 9 years ago

Fix the append mode after r614.

  • 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: 80.0 KB
Line 
1
2#include "nc4_data_output.hpp"
3
4#include <boost/lexical_cast.hpp>
5#include "attribute_template.hpp"
6#include "group_template.hpp"
7
8#include "file.hpp"
9#include "calendar.hpp"
10#include "context.hpp"
11#include "context_server.hpp"
12#include "netCdfException.hpp"
13#include "exception.hpp"
14
15namespace xios
16{
17      /// ////////////////////// Définitions ////////////////////// ///
18      CNc4DataOutput::CNc4DataOutput
19         (const StdString & filename, bool exist)
20            : SuperClass()
21            , SuperClassWriter(filename, exist)
22            , filename(filename)
23      {
24         StdString timeid = StdString("time_counter");
25         SuperClass::type = MULTI_FILE;
26      }
27
28      CNc4DataOutput::CNc4DataOutput
29         (const StdString & filename, bool exist, bool useClassicFormat,
30          MPI_Comm comm_file,bool multifile, bool isCollective)
31            : SuperClass()
32            , SuperClassWriter(filename, exist, useClassicFormat, &comm_file, multifile)
33            , comm_file(comm_file)
34            , filename(filename)
35            , isCollective(isCollective)
36      {
37         StdString timeid = StdString("time_counter");
38
39         SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
40      }
41
42
43      CNc4DataOutput::~CNc4DataOutput(void)
44      { /* Ne rien faire de plus */ }
45
46      ///--------------------------------------------------------------
47
48      const StdString & CNc4DataOutput::getFileName(void) const
49      {
50         return (this->filename);
51      }
52
53      //---------------------------------------------------------------
54
55      void CNc4DataOutput::writeDomain_(CDomain* domain)
56      {
57         if (domain->type == CDomain::type_attr::unstructured)
58         {
59           writeUnstructuredDomain(domain) ;
60           return ;
61         }
62
63         CContext* context = CContext::getCurrent() ;
64         CContextServer* server=context->server ;
65
66         if (domain->IsWritten(this->filename)) return;
67         domain->checkAttributes();
68
69         if (domain->isEmpty())
70           if (SuperClass::type==MULTI_FILE) return ;
71
72         std::vector<StdString> dim0, dim1;
73         StdString domid     = (!domain->name.isEmpty())
74                             ? domain->name.getValue() : domain->getId();
75         StdString appendDomid  = (singleDomain) ? "" : "_"+domid ;
76
77
78         StdString dimXid, dimYid ;
79
80         bool isRegularDomain = (domain->type == CDomain::type_attr::rectilinear);
81         switch (domain->type)
82         {
83           case CDomain::type_attr::curvilinear :
84             dimXid     = StdString("x").append(appendDomid);
85             dimYid     = StdString("y").append(appendDomid);
86             break ;
87           case CDomain::type_attr::rectilinear :
88             dimXid     = StdString("lon").append(appendDomid);
89             dimYid     = StdString("lat").append(appendDomid);
90             break;
91         }
92
93         StdString dimVertId = StdString("nvertex").append(appendDomid);
94
95         string lonid,latid,bounds_lonid,bounds_latid ;
96         string areaId = "area" + appendDomid;
97/*
98         StdString lonid_loc = (server->intraCommSize > 1)
99                             ? StdString("lon").append(appendDomid).append("_local")
100                             : lonid;
101         StdString latid_loc = (server->intraCommSize > 1)
102                             ? StdString("lat").append(appendDomid).append("_local")
103                             : latid;
104*/
105
106         try
107         {
108           switch (SuperClass::type)
109           {
110              case (MULTI_FILE) :
111              {
112  //               if (domain->isEmpty()) return;
113
114                 if (server->intraCommSize > 1)
115                 {
116  //                 SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
117  //                 SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
118                 }
119
120                 switch (domain->type)
121                 {
122                   case CDomain::type_attr::curvilinear :
123                     dim0.push_back(dimYid); dim0.push_back(dimXid);
124                     lonid = StdString("nav_lon").append(appendDomid);
125                     latid = StdString("nav_lat").append(appendDomid);
126                     break ;
127                   case CDomain::type_attr::rectilinear :
128                     lonid = StdString("lon").append(appendDomid);
129                     latid = StdString("lat").append(appendDomid);
130                     dim0.push_back(dimYid);
131                     dim1.push_back(dimXid);
132                     break;
133                 }
134
135                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
136                 bounds_latid = StdString("bounds_lat").append(appendDomid);
137
138                 SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv);
139                 SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv);
140
141                 if (domain->hasBounds)
142                   SuperClassWriter::addDimension(dimVertId, domain->nvertex);
143
144                 if (server->intraCommSize > 1)
145                 {
146                   this->writeLocalAttributes(domain->zoom_ibegin_srv,
147                                              domain->zoom_ni_srv,
148                                              domain->zoom_jbegin_srv,
149                                              domain->zoom_nj_srv,
150                                              appendDomid);
151
152                   if (singleDomain)
153                    this->writeLocalAttributes_IOIPSL(dimXid, dimYid,
154                                                      domain->zoom_ibegin_srv,
155                                                      domain->zoom_ni_srv,
156                                                      domain->zoom_jbegin_srv,
157                                                      domain->zoom_nj_srv,
158                                                      domain->ni_glo,domain->nj_glo,
159                                                      server->intraCommRank,server->intraCommSize);
160                 }
161
162                 if (domain->hasLonLat)
163                 {
164                   switch (domain->type)
165                   {
166                     case CDomain::type_attr::curvilinear :
167                       SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
168                       SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
169                       break ;
170                      case CDomain::type_attr::rectilinear :
171                        SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
172                        SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
173                        break ;
174                   }
175
176                   this->writeAxisAttributes(lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid);
177                   this->writeAxisAttributes(latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid);
178
179                   if (domain->hasBounds)
180                   {
181                     SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid);
182                     SuperClassWriter::addAttribute("bounds", bounds_latid, &latid);
183
184                     dim0.clear();
185                     dim0.push_back(dimYid);
186                     dim0.push_back(dimXid);
187                     dim0.push_back(dimVertId);
188                     SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
189                     SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
190                   }
191                 }
192
193                 dim0.clear();
194                 dim0.push_back(dimYid);
195                 dim0.push_back(dimXid);
196
197
198  // supress mask               if (server->intraCommSize > 1)
199  // supress mask               {
200  // supress mask                  SuperClassWriter::addVariable(maskid, NC_INT, dim0);
201  // supress mask
202  // supress mask                  this->writeMaskAttributes(maskid,
203  // supress mask                     domain->data_dim.getValue()/*,
204  // supress mask                     domain->data_ni.getValue(),
205  // supress mask                     domain->data_nj.getValue(),
206  // supress mask                     domain->data_ibegin.getValue(),
207  // supress mask                     domain->data_jbegin.getValue()*/);
208  // supress mask               }
209
210                 //SuperClassWriter::setDefaultValue(maskid, &dvm);
211
212                 if (domain->hasArea)
213                 {
214                   SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0);
215                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
216                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
217                 }
218
219                 SuperClassWriter::definition_end();
220
221                 if (domain->hasLonLat)
222                 {
223                   switch (domain->type)
224                   {
225                     case CDomain::type_attr::curvilinear :
226                       SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
227                       SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
228                       break;
229                     case CDomain::type_attr::rectilinear :
230                       CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
231                       SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0);
232                       CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
233                       SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0);
234                       break;
235                   }
236
237                   if (domain->hasBounds)
238                   {
239                     SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0);
240                     SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0);
241                   }
242                 }
243
244                 if (domain->hasArea)
245                   SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0);
246
247                 SuperClassWriter::definition_start();
248
249                 break;
250              }
251              case (ONE_FILE) :
252              {
253                 SuperClassWriter::addDimension(dimXid, domain->global_zoom_ni);
254                 SuperClassWriter::addDimension(dimYid, domain->global_zoom_nj);
255
256                 if (domain->hasBounds)
257                   SuperClassWriter::addDimension(dimVertId, domain->nvertex);
258
259                 if (domain->hasLonLat)
260                 {
261                   switch (domain->type)
262                   {
263                     case CDomain::type_attr::curvilinear :
264                       dim0.push_back(dimYid); dim0.push_back(dimXid);
265                       lonid = StdString("nav_lon").append(appendDomid);
266                       latid = StdString("nav_lat").append(appendDomid);
267                       SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
268                       SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
269                       break;
270
271                     case CDomain::type_attr::rectilinear :
272                       dim0.push_back(dimYid);
273                       dim1.push_back(dimXid);
274                       lonid = StdString("lon").append(appendDomid);
275                       latid = StdString("lat").append(appendDomid);
276                       SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
277                       SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
278                       break;
279                   }
280
281                   bounds_lonid = StdString("bounds_lon").append(appendDomid);
282                   bounds_latid = StdString("bounds_lat").append(appendDomid);
283
284                   this->writeAxisAttributes
285                      (lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid);
286                   this->writeAxisAttributes
287                      (latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid);
288
289                   if (domain->hasBounds)
290                   {
291                     SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid);
292                     SuperClassWriter::addAttribute("bounds", bounds_latid, &latid);
293
294                     dim0.clear();
295                     dim0.push_back(dimYid);
296                     dim0.push_back(dimXid);
297                     dim0.push_back(dimVertId);
298                     SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
299                     SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
300                   }
301                 }
302
303                 if (domain->hasArea)
304                 {
305                   dim0.clear();
306                   dim0.push_back(dimYid); dim0.push_back(dimXid);
307                   SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0);
308                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
309                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
310                   dim0.clear();
311                 }
312
313                 SuperClassWriter::definition_end();
314
315                 switch (domain->type)
316                 {
317                   case CDomain::type_attr::curvilinear :
318                   {
319                     std::vector<StdSize> start(2) ;
320                     std::vector<StdSize> count(2) ;
321                     if (domain->isEmpty())
322                     {
323                       start[0]=0 ; start[1]=0 ;
324                       count[0]=0 ; count[1]=0 ;
325                     }
326                     else
327                     {
328                       start[1]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin;
329                       start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin;
330                       count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ;
331                     }
332
333                     if (domain->hasLonLat)
334                     {
335                       SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
336                       SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
337                     }
338                     break;
339                   }
340                   case CDomain::type_attr::rectilinear :
341                   {
342                     if (domain->hasLonLat)
343                     {
344                       std::vector<StdSize> start(1) ;
345                       std::vector<StdSize> count(1) ;
346                       if (domain->isEmpty())
347                       {
348                         start[0]=0 ;
349                         count[0]=0 ;
350                         SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
351                         SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
352
353                       }
354                       else
355                       {
356                         start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin;
357                         count[0]=domain->zoom_nj_srv ;
358                         CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
359                         SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count);
360
361                         start[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin;
362                         count[0]=domain->zoom_ni_srv ;
363                         CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
364                         SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count);
365                       }
366                     }
367                     break;
368                   }
369                 }
370
371                 if (domain->hasBounds)
372                 {
373                   std::vector<StdSize> start(3);
374                   std::vector<StdSize> count(3);
375                   if (domain->isEmpty())
376                   {
377                     start[2] = start[1] = start[0] = 0;
378                     count[2] = count[1] = count[0] = 0;
379                   }
380                   else
381                   {
382                     start[2] = 0;
383                     start[1] = domain->zoom_ibegin_srv - domain->global_zoom_ibegin;
384                     start[0] = domain->zoom_jbegin_srv - domain->global_zoom_jbegin;
385                     count[2] = domain->nvertex;
386                     count[1] = domain->zoom_ni_srv;
387                     count[0] = domain->zoom_nj_srv;
388                   }
389
390                   SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0, &start, &count);
391                   SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0, &start, &count);
392                 }
393
394                 if (domain->hasArea)
395                 {
396                   std::vector<StdSize> start(2);
397                   std::vector<StdSize> count(2);
398
399                   if (domain->isEmpty())
400                   {
401                     start[0] = 0; start[1] = 0;
402                     count[0] = 0; count[1] = 0;
403                   }
404                   else
405                   {
406                     start[1] = domain->zoom_ibegin_srv - domain->global_zoom_ibegin;
407                     start[0] = domain->zoom_jbegin_srv - domain->global_zoom_jbegin;
408                     count[1] = domain->zoom_ni_srv;
409                     count[0] = domain->zoom_nj_srv;
410                   }
411
412                   SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0, &start, &count);
413                 }
414
415                 SuperClassWriter::definition_start();
416                 break;
417              }
418              default :
419                 ERROR("CNc4DataOutput::writeDomain(domain)",
420                       << "[ type = " << SuperClass::type << "]"
421                       << " not implemented yet !");
422           }
423         }
424         catch (CNetCdfException& e)
425         {
426           StdString msg("On writing the domain : ");
427           msg.append(domid); msg.append("\n");
428           msg.append("In the context : ");
429           msg.append(context->getId()); msg.append("\n");
430           msg.append(e.what());
431           ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg);
432         }
433
434         domain->addRelFile(this->filename);
435      }
436
437      void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)
438      {
439         CContext* context = CContext::getCurrent() ;
440         CContextServer* server=context->server ;
441
442         if (domain->IsWritten(this->filename)) return;
443         domain->checkAttributes();
444
445         if (domain->isEmpty())
446           if (SuperClass::type==MULTI_FILE) return ;
447
448         std::vector<StdString> dim0, dim1;
449         StdString domid     = (!domain->name.isEmpty())
450                             ? domain->name.getValue() : domain->getId();
451         StdString appendDomid  = (singleDomain) ? "" : "_"+domid ;
452
453
454         StdString dimXid = StdString("cell").append(appendDomid);
455         StdString dimVertId = StdString("nvertex").append(appendDomid);
456
457         string lonid,latid,bounds_lonid,bounds_latid ;
458         string areaId = "area" + appendDomid;
459
460         try
461         {
462           switch (SuperClass::type)
463           {
464              case (MULTI_FILE) :
465              {
466                 dim0.push_back(dimXid);
467                 SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv);
468
469                 lonid = StdString("lon").append(appendDomid);
470                 latid = StdString("lat").append(appendDomid);
471                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
472                 bounds_latid = StdString("bounds_lat").append(appendDomid);
473                 if (domain->hasLonLat)
474                 {
475                   SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
476                   SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
477                   this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid);
478                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid);
479                   this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid);
480                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
481                   if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex);
482                 }
483
484                 dim0.clear();
485                 if (domain->hasBounds)
486                 {
487                   dim0.push_back(dimXid);
488                   dim0.push_back(dimVertId);
489                   SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
490                   SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
491                 }
492
493                 dim0.clear();
494                 dim0.push_back(dimXid);
495                 if (domain->hasArea)
496                 {
497                   SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0);
498                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
499                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
500                 }
501
502                 SuperClassWriter::definition_end();
503
504                 if (domain->hasLonLat)
505                 {
506                   SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
507                   SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
508                   if (domain->hasBounds)
509                   {
510                     SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0);
511                     SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0);
512                   }
513                 }
514
515                 if (domain->hasArea)
516                   SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0);
517
518                 SuperClassWriter::definition_start();
519                 break ;
520              }
521
522              case (ONE_FILE) :
523              {
524                 lonid = StdString("lon").append(appendDomid);
525                 latid = StdString("lat").append(appendDomid);
526                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
527                 bounds_latid = StdString("bounds_lat").append(appendDomid);
528                 dim0.push_back(dimXid);
529                 SuperClassWriter::addDimension(dimXid, domain->nj_glo);
530                 if (domain->hasLonLat)
531                 {
532                   SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
533                   SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
534
535                   this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid);
536                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid);
537                   this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid);
538                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
539                   if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex);
540                 }
541                 dim0.clear();
542
543                 if (domain->hasBounds)
544                 {
545                   dim0.push_back(dimXid);
546                   dim0.push_back(dimVertId);
547                   SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
548                   SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
549                 }
550
551                 if (domain->hasArea)
552                 {
553                   dim0.clear();
554                   dim0.push_back(dimXid);
555                   SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0);
556                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId);
557                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId);
558                 }
559
560                 SuperClassWriter::definition_end();
561
562                 std::vector<StdSize> start(1), startBounds(2) ;
563                 std::vector<StdSize> count(1), countBounds(2) ;
564                 if (domain->isEmpty())
565                 {
566                   start[0]=0 ;
567                   count[0]=0 ;
568                   startBounds[1]=0 ;
569                   countBounds[1]=domain->nvertex ;
570                   startBounds[0]=0 ;
571                   countBounds[0]=0 ;
572                 }
573                 else
574                 {
575                   start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin;
576                   count[0]=domain->zoom_nj_srv ;
577                   startBounds[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin;
578                   startBounds[1]=0 ;
579                   countBounds[0]=domain->zoom_nj_srv ;
580                   countBounds[1]=domain->nvertex ;
581                 }
582
583                 if (domain->hasLonLat)
584                 {
585                   SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
586                   SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
587                   if (domain->hasBounds)
588                   {
589                     SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0,&startBounds,&countBounds);
590                     SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0,&startBounds,&countBounds);
591                   }
592                 }
593
594                 if (domain->hasArea)
595                   SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0, &start, &count);
596
597                 SuperClassWriter::definition_start();
598
599                 break;
600              }
601              default :
602                 ERROR("CNc4DataOutput::writeDomain(domain)",
603                       << "[ type = " << SuperClass::type << "]"
604                       << " not implemented yet !");
605           }
606         }
607         catch (CNetCdfException& e)
608         {
609           StdString msg("On writing the domain : ");
610           msg.append(domid); msg.append("\n");
611           msg.append("In the context : ");
612           msg.append(context->getId()); msg.append("\n");
613           msg.append(e.what());
614           ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg);
615         }
616         domain->addRelFile(this->filename);
617      }
618      //--------------------------------------------------------------
619
620      void CNc4DataOutput::writeAxis_(CAxis* axis)
621      {
622        if (axis->IsWritten(this->filename)) return;
623        axis->checkAttributes();
624        int zoom_size_srv  = axis->zoom_size_srv;
625        int zoom_begin_srv = axis->zoom_begin_srv;
626        int zoom_size  = (MULTI_FILE == SuperClass::type) ? zoom_size_srv
627                                                              : axis->global_zoom_size;
628        int zoom_begin = (MULTI_FILE == SuperClass::type) ? zoom_begin_srv
629                                                              : axis->global_zoom_begin;
630
631        if ((0 == zoom_size_srv) && (MULTI_FILE == SuperClass::type)) return;
632
633        std::vector<StdString> dims;
634        StdString axisid = !axis->name.isEmpty() ? axis->name.getValue() : axis->getId();
635        try
636        {
637          SuperClassWriter::addDimension(axisid, zoom_size);
638          dims.push_back(axisid);
639          SuperClassWriter::addVariable(axisid, NC_FLOAT, dims);
640
641          if (!axis->name.isEmpty())
642            SuperClassWriter::addAttribute("name", axis->name.getValue(), &axisid);
643
644          if (!axis->standard_name.isEmpty())
645            SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisid);
646
647          if (!axis->long_name.isEmpty())
648            SuperClassWriter::addAttribute("long_name", axis->long_name.getValue(), &axisid);
649
650          if (!axis->unit.isEmpty())
651            SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisid);
652
653          if (!axis->positive.isEmpty())
654          {
655            SuperClassWriter::addAttribute("axis", string("Z"), &axisid);
656            SuperClassWriter::addAttribute("positive",
657                                           (axis->positive == CAxis::positive_attr::up) ? string("up") : string("down"),
658                                           &axisid);
659          }
660
661          StdString axisBoundsId = axisid + "_bounds";
662          if (!axis->bounds.isEmpty())
663          {
664            dims.push_back("axis_nbounds");
665            SuperClassWriter::addVariable(axisBoundsId, NC_FLOAT, dims);
666            SuperClassWriter::addAttribute("bounds", axisBoundsId, &axisid);
667          }
668
669          SuperClassWriter::definition_end();
670          switch (SuperClass::type)
671          {
672            case MULTI_FILE:
673            {
674              CArray<double,1> axis_value(zoom_size_srv);
675              for (int i = 0; i < zoom_size_srv; i++) axis_value(i) = axis->value_srv(i);
676              SuperClassWriter::writeData(axis_value, axisid, isCollective, 0);
677
678              if (!axis->bounds.isEmpty())
679              {
680                CArray<double,2> axisBounds(2, zoom_size_srv);
681                for (int i = 0; i < zoom_size_srv; i++)
682                {
683                  axisBounds(0, i) = axis->bound_srv(i, 0);
684                  axisBounds(1, i) = axis->bound_srv(i, 1);
685                }
686                SuperClassWriter::writeData(axisBounds, axisBoundsId, isCollective, 0);
687              }
688
689              SuperClassWriter::definition_start();
690
691              break;
692            }
693            case ONE_FILE:
694            {
695              CArray<double,1> axis_value(zoom_size_srv);
696              axis_value = axis->value_srv;
697
698              std::vector<StdSize> start(1) ;
699              std::vector<StdSize> count(1) ;
700              start[0] = zoom_begin_srv-axis->global_zoom_begin;
701              count[0] = zoom_size_srv;
702              SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count);
703
704              if (!axis->bounds.isEmpty())
705              {
706                CArray<double,2> axisBounds(2, zoom_size_srv);
707                for (int i = 0; i < zoom_size_srv; ++i)
708                {
709                  axisBounds(0, i+zoom_begin_srv) = axis->bound_srv(i, 0);
710                  axisBounds(1, i+zoom_begin_srv) = axis->bound_srv(i, 1);
711                }
712                SuperClassWriter::writeData(axisBounds, axisBoundsId, isCollective, 0, &start, &count);
713              }
714
715              SuperClassWriter::definition_start();
716
717              break;
718            }
719            default :
720              ERROR("CNc4DataOutput::writeDomain(domain)",
721                    << "[ type = " << SuperClass::type << "]"
722                    << " not implemented yet !");
723          }
724        }
725        catch (CNetCdfException& e)
726        {
727          StdString msg("On writing the axis : ");
728          msg.append(axisid); msg.append("\n");
729          msg.append("In the context : ");
730          CContext* context = CContext::getCurrent() ;
731          msg.append(context->getId()); msg.append("\n");
732          msg.append(e.what());
733          ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg);
734        }
735        axis->addRelFile(this->filename);
736     }
737
738     //--------------------------------------------------------------
739
740     void CNc4DataOutput::writeGridCompressed_(CGrid* grid)
741     {
742       if (grid->isScalarGrid() || grid->isWrittenCompressed(this->filename)) return;
743
744       try
745       {
746         CArray<bool,1> axisDomainOrder = grid->axis_domain_order;
747         std::vector<StdString> domainList = grid->getDomainList();
748         std::vector<StdString> axisList   = grid->getAxisList();
749         int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0;
750
751         std::vector<StdString> dims;
752
753         if (grid->isCompressible())
754         {
755           StdString varId = grid->getId() + "_points";
756
757           int nbIndexes = (SuperClass::type == MULTI_FILE) ? grid->getNumberWrittenIndexes() : grid->getTotalNumberWrittenIndexes();
758           SuperClassWriter::addDimension(varId, nbIndexes);
759
760           dims.push_back(varId);
761           SuperClassWriter::addVariable(varId, NC_INT, dims);
762
763           StdOStringStream compress;
764           for (int i = numElement - 1; i >= 0; --i)
765           {
766             if (axisDomainOrder(i))
767             {
768               CDomain* domain = CDomain::get(domainList[domainList.size() - idxDomain - 1]);
769               StdString domId = !domain->name.isEmpty() ? domain->name.getValue() : domain->getId();
770               StdString appendDomId  = singleDomain ? "" : "_" + domId;
771
772               switch (domain->type)
773               {
774                 case CDomain::type_attr::curvilinear:
775                   compress << "y" << appendDomId << " x" << appendDomId;
776                   break;
777                 case CDomain::type_attr::rectilinear:
778                   compress << "lat" << appendDomId << " lon" << appendDomId;
779                   break;
780                 case CDomain::type_attr::unstructured:
781                   compress << "cell" << appendDomId;
782                   break;
783               }
784               ++idxDomain;
785             }
786             else
787             {
788               CAxis* axis = CAxis::get(axisList[axisList.size() - idxAxis - 1]);
789               compress << (!axis->name.isEmpty() ? axis->name.getValue() : axis->getId());
790               ++idxAxis;
791             }
792
793             if (i != 0) compress << ' ';
794           }
795           SuperClassWriter::addAttribute("compress", compress.str(), &varId);
796
797           grid->computeCompressedIndex();
798
799           CArray<int, 1> indexes(grid->getNumberWrittenIndexes());
800           std::map<int, CArray<size_t, 1> >::const_iterator it;
801           for (it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it)
802           {
803             const CArray<size_t, 1> compressedIndexes = grid->compressedOutIndexFromClient[it->first];
804             for (int i = 0; i < it->second.numElements(); i++)
805               indexes(compressedIndexes(i)) = it->second(i);
806           }
807
808           switch (SuperClass::type)
809           {
810             case (MULTI_FILE):
811             {
812               SuperClassWriter::writeData(indexes, varId, isCollective, 0);
813               break;
814             }
815             case (ONE_FILE):
816             {
817               if (grid->doGridHaveDataDistributed())
818                 grid->getDistributionServer()->computeGlobalIndex(indexes);
819
820               std::vector<StdSize> start, count;
821               start.push_back(grid->getOffsetWrittenIndexes());
822               count.push_back(grid->getNumberWrittenIndexes());
823
824               SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count);
825               break;
826             }
827           }
828         }
829         else
830         {
831           for (int i = 0; i < numElement; ++i)
832           {
833             StdString varId, compress;
834             CArray<int, 1> indexes;
835             bool isDistributed;
836             StdSize nbIndexes, totalNbIndexes, offset;
837             int firstGlobalIndex;
838
839             if (axisDomainOrder(i))
840             {
841               CDomain* domain = CDomain::get(domainList[idxDomain]);
842               if (!domain->isCompressible()
843                    || domain->type == CDomain::type_attr::unstructured
844                    || domain->isWrittenCompressed(this->filename))
845                 continue;
846
847               StdString domId = !domain->name.isEmpty() ? domain->name.getValue() : domain->getId();
848               StdString appendDomId  = singleDomain ? "" : "_" + domId;
849
850               varId = domId + "_points";
851               switch (domain->type)
852               {
853                 case CDomain::type_attr::curvilinear:
854                   compress = "y" + appendDomId + " x" + appendDomId;
855                   break;
856                 case CDomain::type_attr::rectilinear:
857                   compress = "lat" + appendDomId + " lon" + appendDomId;
858                   break;
859               }
860
861               const std::vector<int>& indexesToWrite = domain->getIndexesToWrite();
862               indexes.resize(indexesToWrite.size());
863               for (int n = 0; n < indexes.numElements(); ++n)
864                 indexes(n) = indexesToWrite[n];
865
866               isDistributed = domain->isDistributed();
867               nbIndexes = domain->getNumberWrittenIndexes();
868               totalNbIndexes = domain->getTotalNumberWrittenIndexes();
869               offset = domain->getOffsetWrittenIndexes();
870               firstGlobalIndex = domain->ibegin + domain->jbegin * domain->ni_glo;
871
872               domain->addRelFileCompressed(this->filename);
873               ++idxDomain;
874             }
875             else
876             {
877               CAxis* axis = CAxis::get(axisList[idxAxis]);
878               if (!axis->isCompressible() || axis->isWrittenCompressed(this->filename))
879                 continue;
880
881               StdString axisId = !axis->name.isEmpty() ? axis->name.getValue() : axis->getId();
882               varId = axisId + "_points";
883               compress = axisId;
884
885               const std::vector<int>& indexesToWrite = axis->getIndexesToWrite();
886               indexes.resize(indexesToWrite.size());
887               for (int n = 0; n < indexes.numElements(); ++n)
888                 indexes(n) = indexesToWrite[n];
889
890               isDistributed = axis->isDistributed();
891               nbIndexes = axis->getNumberWrittenIndexes();
892               totalNbIndexes = axis->getTotalNumberWrittenIndexes();
893               offset = axis->getOffsetWrittenIndexes();
894               firstGlobalIndex = axis->begin;
895
896               axis->addRelFileCompressed(this->filename);
897               ++idxAxis;
898             }
899
900             if (!varId.empty())
901             {
902               SuperClassWriter::addDimension(varId, (SuperClass::type == MULTI_FILE) ? nbIndexes : totalNbIndexes);
903
904               dims.clear();
905               dims.push_back(varId);
906               SuperClassWriter::addVariable(varId, NC_INT, dims);
907
908               SuperClassWriter::addAttribute("compress", compress, &varId);
909
910               switch (SuperClass::type)
911               {
912                 case (MULTI_FILE):
913                 {
914                   indexes -= firstGlobalIndex;
915                   SuperClassWriter::writeData(indexes, varId, isCollective, 0);
916                   break;
917                 }
918                 case (ONE_FILE):
919                 {
920                   std::vector<StdSize> start, count;
921                   start.push_back(offset);
922                   count.push_back(nbIndexes);
923
924                   SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count);
925                   break;
926                 }
927               }
928             }
929           }
930
931           if (!dims.empty())
932             grid->computeCompressedIndex();
933         }
934
935         grid->addRelFileCompressed(this->filename);
936       }
937       catch (CNetCdfException& e)
938       {
939         StdString msg("On writing compressed grid : ");
940         msg.append(grid->getId()); msg.append("\n");
941         msg.append("In the context : ");
942         CContext* context = CContext::getCurrent();
943         msg.append(context->getId()); msg.append("\n");
944         msg.append(e.what());
945         ERROR("CNc4DataOutput::writeGridCompressed_(CGrid* grid)", << msg);
946       }
947     }
948
949     //--------------------------------------------------------------
950
951     void CNc4DataOutput::writeTimeDimension_(void)
952     {
953       try
954       {
955        SuperClassWriter::addDimension("time_counter");
956       }
957       catch (CNetCdfException& e)
958       {
959         StdString msg("On writing time dimension : time_couter\n");
960         msg.append("In the context : ");
961         CContext* context = CContext::getCurrent() ;
962         msg.append(context->getId()); msg.append("\n");
963         msg.append(e.what());
964         ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg);
965       }
966     }
967
968      //--------------------------------------------------------------
969
970      void CNc4DataOutput::writeField_(CField* field)
971      {
972         CContext* context = CContext::getCurrent() ;
973         CContextServer* server=context->server ;
974
975         std::vector<StdString> dims, coodinates;
976         CGrid* grid = field->grid;
977         if (!grid->doGridHaveDataToWrite())
978          if (SuperClass::type==MULTI_FILE) return ;
979
980         CArray<bool,1> axisDomainOrder = grid->axis_domain_order;
981         int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0;
982         std::vector<StdString> domainList = grid->getDomainList();
983         std::vector<StdString> axisList   = grid->getAxisList();
984
985         StdString timeid  = StdString("time_counter");
986         StdString dimXid,dimYid;
987         std::deque<StdString> dimIdList, dimCoordList;
988         bool hasArea = false;
989         StdString cellMeasures = "area:";
990         bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output;
991
992         for (int i = 0; i < numElement; ++i)
993         {
994           if (axisDomainOrder(i))
995           {
996             CDomain* domain = CDomain::get(domainList[idxDomain]);
997             StdString domId = !domain->name.isEmpty() ? domain->name.getValue() : domain->getId();
998             StdString appendDomId  = singleDomain ? "" : "_" + domId ;
999
1000             if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured)
1001             {
1002               dimIdList.push_back(domId + "_points");
1003               field->setUseCompressedOutput();
1004             }
1005
1006             switch (domain->type)
1007             {
1008               case CDomain::type_attr::curvilinear:
1009                 if (!compressedOutput || !domain->isCompressible())
1010                 {
1011                   dimXid     = StdString("x").append(appendDomId);
1012                   dimIdList.push_back(dimXid);
1013                   dimYid     = StdString("y").append(appendDomId);
1014                   dimIdList.push_back(dimYid);
1015                 }
1016                 dimCoordList.push_back(StdString("nav_lon").append(appendDomId));
1017                 dimCoordList.push_back(StdString("nav_lat").append(appendDomId));
1018                 break ;
1019               case CDomain::type_attr::rectilinear:
1020                 if (!compressedOutput || !domain->isCompressible())
1021                 {
1022                   dimXid     = StdString("lon").append(appendDomId);
1023                   dimIdList.push_back(dimXid);
1024                   dimYid     = StdString("lat").append(appendDomId);
1025                   dimIdList.push_back(dimYid);
1026                 }
1027                 break ;
1028               case CDomain::type_attr::unstructured:
1029                 dimXid     = StdString("cell").append(appendDomId);
1030                 dimIdList.push_back(dimXid);
1031                 dimCoordList.push_back(StdString("lon").append(appendDomId));
1032                 dimCoordList.push_back(StdString("lat").append(appendDomId));
1033                 break ;
1034             }
1035             if (domain->hasArea)
1036             {
1037               hasArea = true;
1038               cellMeasures += " area" + appendDomId;
1039             }
1040             ++idxDomain;
1041           }
1042           else
1043           {
1044             CAxis* axis = CAxis::get(axisList[idxAxis]);
1045             StdString axisId = !axis->name.isEmpty() ? axis->name.getValue() : axis->getId();
1046
1047             if (compressedOutput && axis->isCompressible())
1048             {
1049               dimIdList.push_back(axisId + "_points");
1050               field->setUseCompressedOutput();
1051             }
1052             else
1053               dimIdList.push_back(axisId);
1054
1055             dimCoordList.push_back(axisId);
1056             ++idxAxis;
1057           }
1058         }
1059
1060/*
1061         StdString lonid_loc = (server->intraCommSize > 1)
1062                             ? StdString("lon").append(appendDomid).append("_local")
1063                             : lonid;
1064         StdString latid_loc = (server->intraCommSize > 1)
1065                             ? StdString("lat").append(appendDomid).append("_local")
1066                             : latid;
1067*/
1068         StdString fieldid   = (!field->name.isEmpty())
1069                             ? field->name.getValue() : field->getBaseFieldReference()->getId();
1070
1071//         unsigned int ssize = domain->zoom_ni_loc.getValue() * domain->zoom_nj_loc.getValue();
1072//         bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize);
1073//          bool isCurvilinear = domain->isCurvilinear ;
1074
1075         nc_type type ;
1076         if (field->prec.isEmpty()) type =  NC_FLOAT ;
1077         else
1078         {
1079           if (field->prec==2) type = NC_SHORT ;
1080           else if (field->prec==4)  type =  NC_FLOAT ;
1081           else if (field->prec==8)   type =  NC_DOUBLE ;
1082         }
1083
1084         bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once);
1085
1086         if (wtime)
1087         {
1088
1089            //StdOStringStream oss;
1090           // oss << "time_" << field->operation.getValue()
1091           //     << "_" << field->getRelFile()->output_freq.getValue();
1092          //oss
1093            if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant"));
1094            else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered"));
1095            dims.push_back(timeid);
1096         }
1097
1098         if (compressedOutput && grid->isCompressible())
1099         {
1100           dims.push_back(grid->getId() + "_points");
1101           field->setUseCompressedOutput();
1102         }
1103         else
1104         {
1105           while (!dimIdList.empty())
1106           {
1107             dims.push_back(dimIdList.back());
1108             dimIdList.pop_back();
1109           }
1110         }
1111
1112         while (!dimCoordList.empty())
1113         {
1114           coodinates.push_back(dimCoordList.back());
1115           dimCoordList.pop_back();
1116         }
1117
1118         try
1119         {
1120           SuperClassWriter::addVariable(fieldid, type, dims);
1121
1122           if (!field->standard_name.isEmpty())
1123              SuperClassWriter::addAttribute
1124                 ("standard_name",  field->standard_name.getValue(), &fieldid);
1125
1126           if (!field->long_name.isEmpty())
1127              SuperClassWriter::addAttribute
1128                 ("long_name", field->long_name.getValue(), &fieldid);
1129
1130           if (!field->unit.isEmpty())
1131              SuperClassWriter::addAttribute
1132                 ("units", field->unit.getValue(), &fieldid);
1133
1134            if (!field->valid_min.isEmpty())
1135              SuperClassWriter::addAttribute
1136                 ("valid_min", field->valid_min.getValue(), &fieldid);
1137
1138           if (!field->valid_max.isEmpty())
1139              SuperClassWriter::addAttribute
1140                 ("valid_max", field->valid_max.getValue(), &fieldid);
1141
1142            if (!field->scale_factor.isEmpty())
1143              SuperClassWriter::addAttribute
1144                 ("scale_factor", field->scale_factor.getValue(), &fieldid);
1145
1146             if (!field->add_offset.isEmpty())
1147              SuperClassWriter::addAttribute
1148                 ("add_offset", field->add_offset.getValue(), &fieldid);
1149
1150           SuperClassWriter::addAttribute
1151                 ("online_operation", field->operation.getValue(), &fieldid);
1152
1153          // write child variables as attributes
1154
1155
1156           vector<CVariable*> listVars = field->getAllVariables() ;
1157           for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ;
1158
1159
1160           if (wtime)
1161           {
1162              CDuration freqOp = field->freq_op.getValue();
1163              freqOp.solveTimeStep(*context->calendar);
1164              StdString freqOpStr = freqOp.toStringUDUnits();
1165              SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid);
1166
1167              CDuration freqOut = field->getRelFile()->output_freq.getValue();
1168              freqOut.solveTimeStep(*context->calendar);
1169              SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid);
1170
1171              StdString cellMethods = "time: ";
1172              if (field->operation.getValue() == "instant") cellMethods += "point";
1173              else if (field->operation.getValue() == "average") cellMethods += "mean";
1174              else if (field->operation.getValue() == "accumulate") cellMethods += "sum";
1175              else cellMethods += field->operation;
1176              if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar))
1177                cellMethods += " (interval: " + freqOpStr + ")";
1178              SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid);
1179           }
1180
1181           if (hasArea)
1182             SuperClassWriter::addAttribute("cell_measures", cellMeasures, &fieldid);
1183
1184           if (!field->default_value.isEmpty())
1185           {
1186              double default_value = field->default_value.getValue();
1187              float fdefault_value = (float)default_value;
1188              if (type == NC_DOUBLE)
1189                 SuperClassWriter::setDefaultValue(fieldid, &default_value);
1190              else
1191                 SuperClassWriter::setDefaultValue(fieldid, &fdefault_value);
1192           }
1193           else
1194              SuperClassWriter::setDefaultValue(fieldid, (double*)NULL);
1195
1196            if (field->compression_level.isEmpty())
1197              field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level;
1198            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level);
1199
1200           {  // Ecriture des coordonnées
1201
1202              StdString coordstr; //boost::algorithm::join(coodinates, " ")
1203              std::vector<StdString>::iterator
1204                 itc = coodinates.begin(), endc = coodinates.end();
1205
1206              for (; itc!= endc; itc++)
1207              {
1208                 StdString & coord = *itc;
1209                 if (itc+1 != endc)
1210                       coordstr.append(coord).append(" ");
1211                 else  coordstr.append(coord);
1212              }
1213
1214              SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid);
1215
1216           }
1217         }
1218         catch (CNetCdfException& e)
1219         {
1220           StdString msg("On writing field : ");
1221           msg.append(fieldid); msg.append("\n");
1222           msg.append("In the context : ");
1223           msg.append(context->getId()); msg.append("\n");
1224           msg.append(e.what());
1225           ERROR("CNc4DataOutput::writeField_(CField* field)", << msg);
1226         }
1227      }
1228
1229      //--------------------------------------------------------------
1230
1231      void CNc4DataOutput::writeFile_ (CFile* file)
1232      {
1233         StdString filename = (!file->name.isEmpty())
1234                            ? file->name.getValue() : file->getId();
1235         StdString description = (!file->description.isEmpty())
1236                               ? file->description.getValue()
1237                               : StdString("Created by xios");
1238
1239         singleDomain = (file->nbDomains == 1);
1240
1241         try
1242         {
1243           this->writeFileAttributes(filename, description,
1244                                     StdString("CF-1.5"),
1245                                     StdString("An IPSL model"),
1246                                     this->getTimeStamp());
1247
1248           if (!appendMode)
1249             SuperClassWriter::addDimension("axis_nbounds", 2);
1250         }
1251         catch (CNetCdfException& e)
1252         {
1253           StdString msg("On writing file : ");
1254           msg.append(filename); msg.append("\n");
1255           msg.append("In the context : ");
1256           CContext* context = CContext::getCurrent() ;
1257           msg.append(context->getId()); msg.append("\n");
1258           msg.append(e.what());
1259           ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg);
1260         }
1261      }
1262
1263      void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)
1264      {
1265        string name ;
1266        if (!var->name.isEmpty()) name=var->name ;
1267        else if (var->hasId()) name=var->getId() ;
1268        else return ;
1269
1270        try
1271        {
1272          if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32)
1273            addAttribute(name, var->getData<int>(), &fieldId);
1274          else if (var->type.getValue() == CVariable::type_attr::t_int16)
1275            addAttribute(name, var->getData<short int>(), &fieldId);
1276          else if (var->type.getValue() == CVariable::type_attr::t_float)
1277            addAttribute(name, var->getData<float>(), &fieldId);
1278          else if (var->type.getValue() == CVariable::type_attr::t_double)
1279            addAttribute(name, var->getData<double>(), &fieldId);
1280          else if (var->type.getValue() == CVariable::type_attr::t_string)
1281            addAttribute(name, var->getData<string>(), &fieldId);
1282          else
1283            ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)",
1284                  << "Unsupported variable of type " << var->type.getStringValue());
1285        }
1286       catch (CNetCdfException& e)
1287       {
1288         StdString msg("On writing attributes of variable with name : ");
1289         msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n");
1290         msg.append("In the context : ");
1291         CContext* context = CContext::getCurrent() ;
1292         msg.append(context->getId()); msg.append("\n");
1293         msg.append(e.what());
1294         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg);
1295       }
1296     }
1297
1298     void CNc4DataOutput::writeAttribute_ (CVariable* var)
1299     {
1300        string name ;
1301        if (!var->name.isEmpty()) name=var->name ;
1302        else if (var->hasId()) name=var->getId() ;
1303        else return ;
1304        try
1305        {
1306          if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32)
1307            addAttribute(name, var->getData<int>());
1308          else if (var->type.getValue() == CVariable::type_attr::t_int16)
1309            addAttribute(name, var->getData<short int>());
1310          else if (var->type.getValue() == CVariable::type_attr::t_float)
1311            addAttribute(name, var->getData<float>());
1312          else if (var->type.getValue() == CVariable::type_attr::t_double)
1313            addAttribute(name, var->getData<double>());
1314          else if (var->type.getValue() == CVariable::type_attr::t_string)
1315            addAttribute(name, var->getData<string>());
1316          else
1317            ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)",
1318                  << "Unsupported variable of type " << var->type.getStringValue());
1319        }
1320       catch (CNetCdfException& e)
1321       {
1322         StdString msg("On writing attributes of variable with name : ");
1323         msg.append(name); msg.append("\n");
1324         msg.append("In the context : ");
1325         CContext* context = CContext::getCurrent() ;
1326         msg.append(context->getId()); msg.append("\n");
1327         msg.append(e.what());
1328         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg);
1329       }
1330     }
1331
1332      void CNc4DataOutput::syncFile_ (void)
1333      {
1334        try
1335        {
1336          SuperClassWriter::sync() ;
1337        }
1338        catch (CNetCdfException& e)
1339        {
1340         StdString msg("On synchronizing the write among processes");
1341         msg.append("In the context : ");
1342         CContext* context = CContext::getCurrent() ;
1343         msg.append(context->getId()); msg.append("\n");
1344         msg.append(e.what());
1345         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
1346        }
1347      }
1348
1349      void CNc4DataOutput::closeFile_ (void)
1350      {
1351        try
1352        {
1353          SuperClassWriter::close() ;
1354        }
1355        catch (CNetCdfException& e)
1356        {
1357         StdString msg("On closing file");
1358         msg.append("In the context : ");
1359         CContext* context = CContext::getCurrent() ;
1360         msg.append(context->getId()); msg.append("\n");
1361         msg.append(e.what());
1362         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
1363        }
1364
1365      }
1366
1367      //---------------------------------------------------------------
1368
1369      StdString CNc4DataOutput::getTimeStamp(void) const
1370      {
1371         const int buffer_size = 100;
1372         time_t rawtime;
1373         struct tm * timeinfo = NULL;
1374         char buffer [buffer_size];
1375
1376         time ( &rawtime );
1377         timeinfo = localtime ( &rawtime );
1378         strftime (buffer, buffer_size, "%Y-%b-%d %H:%M:%S %Z", timeinfo);
1379
1380         return (StdString(buffer));
1381      }
1382
1383      //---------------------------------------------------------------
1384
1385      void CNc4DataOutput::writeFieldData_ (CField*  field)
1386      {
1387         CContext* context = CContext::getCurrent() ;
1388//          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ;
1389         CContextServer* server=context->server ;
1390
1391         CGrid* grid = field->grid ;
1392
1393         if (!grid->doGridHaveDataToWrite())
1394          if (SuperClass::type==MULTI_FILE || !isCollective) return ;
1395
1396         StdString fieldid   = (!field->name.isEmpty())
1397                             ? field->name.getValue()
1398                             : field->getBaseFieldReference()->getId();
1399
1400         StdOStringStream oss;
1401         string timeAxisId ;
1402         if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisId="time_instant" ;
1403         else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisId="time_centered" ;
1404
1405         StdString timeBoundId("time_counter_bounds");
1406
1407         StdString timeAxisBoundId;
1408         if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisBoundId="time_instant_bounds" ;
1409         else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisBoundId="time_centered_bounds" ;
1410
1411         CArray<double,1> time_data(1) ;
1412         CArray<double,1> time_data_bound(2);
1413         CArray<double,1> time_counter(1) ;
1414         CArray<double,1> time_counter_bound(2);
1415
1416        bool wtime   = !(!field->operation.isEmpty() && (field->getOperationTimeType() == func::CFunctor::once));
1417
1418        if (wtime)
1419        {
1420          Time lastWrite = field->last_Write_srv;
1421          Time lastLastWrite = field->lastlast_Write_srv;
1422
1423          if (field->getOperationTimeType() == func::CFunctor::instant)
1424            time_data(0) = lastWrite;
1425          else if (field->getOperationTimeType() == func::CFunctor::centered)
1426            time_data(0) = (lastWrite + lastLastWrite) / 2;
1427
1428          if (field->getOperationTimeType() == func::CFunctor::instant)
1429            time_data_bound(0) = time_data_bound(1) = lastWrite;
1430          else if (field->getOperationTimeType() == func::CFunctor::centered)
1431          {
1432            time_data_bound(0) = lastLastWrite;
1433            time_data_bound(1) = lastWrite;
1434          }
1435
1436          if (field->file->time_counter == CFile::time_counter_attr::instant)
1437            time_counter(0) = lastWrite;
1438          else if (field->file->time_counter == CFile::time_counter_attr::centered)
1439            time_counter(0) = (lastWrite + lastLastWrite) / 2;
1440          else if (field->file->time_counter == CFile::time_counter_attr::record)
1441            time_counter(0) = field->getNStep() - 1;
1442
1443
1444          if (field->file->time_counter == CFile::time_counter_attr::instant)
1445            time_counter_bound(0) = time_counter_bound(1) = lastWrite;
1446          else if (field->file->time_counter == CFile::time_counter_attr::centered)
1447          {
1448            time_counter_bound(0) = lastLastWrite;
1449            time_counter_bound(1) = lastWrite;
1450          }
1451          else if (field->file->time_counter == CFile::time_counter_attr::record)
1452            time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1;
1453        }
1454
1455         bool isRoot ;
1456         if (server->intraCommRank==0) isRoot=true ;
1457         else isRoot=false ;
1458
1459         if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
1460         {
1461           double scaleFactor=1. ;
1462           double addOffset=0. ;
1463           if (!field->scale_factor.isEmpty()) scaleFactor=field->scale_factor ;
1464           if (!field->add_offset.isEmpty()) addOffset=field->add_offset ;
1465           field->scaleFactorAddOffset(scaleFactor,addOffset) ;
1466         }
1467
1468         try
1469         {
1470           size_t writtenSize;
1471           if (field->getUseCompressedOutput())
1472             writtenSize = grid->getNumberWrittenIndexes();
1473           else
1474             writtenSize = grid->getWrittenDataSize();
1475
1476           CArray<double,1> fieldData(writtenSize);
1477           if (!field->default_value.isEmpty()) fieldData = field->default_value;
1478
1479           if (field->getUseCompressedOutput())
1480             field->outputCompressedField(fieldData);
1481           else
1482             field->outputField(fieldData);
1483
1484           if (!field->prec.isEmpty() && field->prec==2) fieldData=round(fieldData) ;
1485
1486           switch (SuperClass::type)
1487           {
1488              case (MULTI_FILE) :
1489              {
1490                 SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1);
1491                 if (wtime)
1492                 {
1493                   SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1);
1494                   SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1);
1495                   if (field->file->time_counter != CFile::time_counter_attr::none)
1496                   {
1497                     SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep() - 1);
1498                     if (field->file->time_counter != CFile::time_counter_attr::record)
1499                       SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1);
1500                   }
1501                 }
1502                 break ;
1503              }
1504              case (ONE_FILE) :
1505              {
1506                const std::vector<int>& nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
1507                const std::vector<int>& nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
1508                const std::vector<int>& nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
1509
1510                std::vector<StdSize> start, count;
1511
1512                if (field->getUseCompressedOutput())
1513                {
1514                  if (grid->isCompressible())
1515                  {
1516                    start.push_back(grid->getOffsetWrittenIndexes());
1517                    count.push_back(grid->getNumberWrittenIndexes());
1518                  }
1519                  else
1520                  {
1521                    CArray<bool,1> axisDomainOrder = grid->axis_domain_order;
1522                    std::vector<StdString> domainList = grid->getDomainList();
1523                    std::vector<StdString> axisList   = grid->getAxisList();
1524                    int numElement = axisDomainOrder.numElements();
1525                    int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
1526                    int idx = nZoomBeginGlobal.size() - 1;
1527
1528                    start.reserve(nZoomBeginGlobal.size());
1529                    count.reserve(nZoomBeginGlobal.size());
1530
1531
1532                    for (int i = numElement - 1; i >= 0; --i)
1533                    {
1534                      if (axisDomainOrder(i))
1535                      {
1536                        CDomain* domain = CDomain::get(domainList[idxDomain]);
1537
1538                        if (domain->isCompressible())
1539                        {
1540                          start.push_back(domain->getOffsetWrittenIndexes());
1541                          count.push_back(domain->getNumberWrittenIndexes());
1542                        }
1543                        else
1544                        {
1545                          start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
1546                          count.push_back(nZoomSizeServer[idx]);
1547                          start.push_back(nZoomBeginServer[idx - 1] - nZoomBeginGlobal[idx - 1]);
1548                          count.push_back(nZoomSizeServer[idx - 1]);
1549                        }
1550
1551                        --idxDomain;
1552                        idx -= 2;
1553                      }
1554                      else
1555                      {
1556                        CAxis* axis = CAxis::get(axisList[idxAxis]);
1557
1558                        if (axis->isCompressible())
1559                        {
1560                          start.push_back(axis->getOffsetWrittenIndexes());
1561                          count.push_back(axis->getNumberWrittenIndexes());
1562                        }
1563                        else
1564                        {
1565                          start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
1566                          count.push_back(nZoomSizeServer[idx]);
1567                        }
1568
1569                        --idxAxis;
1570                        --idx;
1571                      }
1572                    }
1573                  }
1574                }
1575                else
1576                {
1577                  int ssize = nZoomBeginGlobal.size();
1578
1579                  start.resize(ssize);
1580                  count.resize(ssize);
1581
1582                  for (int i = 0; i < ssize; ++i)
1583                  {
1584                    start[i] = nZoomBeginServer[ssize - i - 1] - nZoomBeginGlobal[ssize - i - 1];
1585                    count[i] = nZoomSizeServer[ssize - i - 1];
1586                  }
1587                }
1588
1589                SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count);
1590                if (wtime)
1591                {
1592                   SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot);
1593                   SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot);
1594                   if (field->file->time_counter != CFile::time_counter_attr::none)
1595                   {
1596                     SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep() - 1, isRoot);
1597                     if (field->file->time_counter != CFile::time_counter_attr::record)
1598                       SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot);
1599                   }
1600                }
1601
1602                break;
1603              }
1604            }
1605         }
1606         catch (CNetCdfException& e)
1607         {
1608           StdString msg("On writing field data: ");
1609           msg.append(fieldid); msg.append("\n");
1610           msg.append("In the context : ");
1611           msg.append(context->getId()); msg.append("\n");
1612           msg.append(e.what());
1613           ERROR("CNc4DataOutput::writeFieldData_ (CField*  field)", << msg);
1614         }
1615      }
1616
1617      //---------------------------------------------------------------
1618
1619      void CNc4DataOutput::writeTimeAxis_
1620                  (CField*    field,
1621                   const boost::shared_ptr<CCalendar> cal)
1622      {
1623         StdOStringStream oss;
1624
1625         if (field->getOperationTimeType() == func::CFunctor::once) return ;
1626
1627//         oss << "time_" << field->operation.getValue()
1628//             << "_" << field->getRelFile()->output_freq.getValue();
1629
1630//         StdString axisid = oss.str();
1631//         if (field->getOperationTimeType() == func::CFunctor::centered) axisid="time_centered" ;
1632//         else if (field->getOperationTimeType() == func::CFunctor::instant) axisid="time_instant" ;
1633
1634         StdString axisid("time_centered") ;
1635         StdString axisBoundId("time_centered_bounds");
1636         StdString timeid("time_counter");
1637         StdString timeBoundId("axis_nbounds");
1638
1639         if (field->getOperationTimeType() == func::CFunctor::instant)
1640         {
1641            axisid = "time_instant";
1642            axisBoundId = "time_instant_bounds";
1643         }
1644
1645         try
1646         {
1647          // Adding time_instant or time_centered
1648           std::vector<StdString> dims;
1649           dims.push_back(timeid);
1650           if (!SuperClassWriter::varExist(axisid))
1651           {
1652              SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
1653
1654              CDate timeOrigin=cal->getTimeOrigin() ;
1655              StdOStringStream oss2;
1656  //            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" "
1657  //                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ;
1658              StdString strInitdate=oss2.str() ;
1659              StdString strTimeOrigin=timeOrigin.toString() ;
1660              this->writeTimeAxisAttributes
1661                 (axisid, cal->getType(),
1662                  StdString("seconds since ").append(strTimeOrigin),
1663                  strTimeOrigin, axisBoundId);
1664           }
1665
1666           // Adding time_instant_bounds or time_centered_bounds variables
1667           if (!SuperClassWriter::varExist(axisBoundId))
1668           {
1669              dims.clear() ;
1670              dims.push_back(timeid);
1671              dims.push_back(timeBoundId);
1672              SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
1673           }
1674
1675           if (field->file->time_counter != CFile::time_counter_attr::none)
1676           {
1677             // Adding time_counter
1678             axisid = "time_counter";
1679             axisBoundId = "time_counter_bounds";
1680             dims.clear();
1681             dims.push_back(timeid);
1682             if (!SuperClassWriter::varExist(axisid))
1683             {
1684                SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
1685                SuperClassWriter::addAttribute("axis", string("T"), &axisid);
1686
1687                if (field->file->time_counter != CFile::time_counter_attr::record)
1688                {
1689                  CDate timeOrigin = cal->getTimeOrigin();
1690                  StdString strTimeOrigin = timeOrigin.toString();
1691
1692                  this->writeTimeAxisAttributes(axisid, cal->getType(),
1693                                                StdString("seconds since ").append(strTimeOrigin),
1694                                                strTimeOrigin, axisBoundId);
1695                }
1696             }
1697
1698             // Adding time_counter_bound dimension
1699             if (field->file->time_counter != CFile::time_counter_attr::record)
1700             {
1701                if (!SuperClassWriter::varExist(axisBoundId))
1702                {
1703                  dims.clear();
1704                  dims.push_back(timeid);
1705                  dims.push_back(timeBoundId);
1706                  SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
1707                }
1708             }
1709           }
1710         }
1711         catch (CNetCdfException& e)
1712         {
1713           StdString msg("On writing time axis data: ");
1714           msg.append("In the context : ");
1715           CContext* context = CContext::getCurrent() ;
1716           msg.append(context->getId()); msg.append("\n");
1717           msg.append(e.what());
1718           ERROR("CNc4DataOutput::writeTimeAxis_ (CField*    field, \
1719                  const boost::shared_ptr<CCalendar> cal)", << msg);
1720         }
1721      }
1722
1723      //---------------------------------------------------------------
1724
1725      void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name,
1726                                                   const StdString & calendar,
1727                                                   const StdString & units,
1728                                                   const StdString & time_origin,
1729                                                   const StdString & time_bounds,
1730                                                   const StdString & standard_name,
1731                                                   const StdString & long_name)
1732      {
1733         try
1734         {
1735           SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
1736           SuperClassWriter::addAttribute("long_name",     long_name    , &axis_name);
1737           SuperClassWriter::addAttribute("calendar",      calendar     , &axis_name);
1738           SuperClassWriter::addAttribute("units",         units        , &axis_name);
1739           SuperClassWriter::addAttribute("time_origin",   time_origin  , &axis_name);
1740           SuperClassWriter::addAttribute("bounds",        time_bounds  , &axis_name);
1741         }
1742         catch (CNetCdfException& e)
1743         {
1744           StdString msg("On writing time axis Attribute: ");
1745           msg.append("In the context : ");
1746           CContext* context = CContext::getCurrent() ;
1747           msg.append(context->getId()); msg.append("\n");
1748           msg.append(e.what());
1749           ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \
1750                                                          const StdString & calendar,\
1751                                                          const StdString & units, \
1752                                                          const StdString & time_origin, \
1753                                                          const StdString & time_bounds, \
1754                                                          const StdString & standard_name, \
1755                                                          const StdString & long_name)", << msg);
1756         }
1757      }
1758
1759      //---------------------------------------------------------------
1760
1761      void CNc4DataOutput::writeAxisAttributes(const StdString & axis_name,
1762                                               const StdString & axis,
1763                                               const StdString & standard_name,
1764                                               const StdString & long_name,
1765                                               const StdString & units,
1766                                               const StdString & nav_model)
1767      {
1768         try
1769         {
1770          if (!axis.empty())
1771            SuperClassWriter::addAttribute("axis"       , axis         , &axis_name);
1772
1773          SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
1774          SuperClassWriter::addAttribute("long_name"    , long_name    , &axis_name);
1775          SuperClassWriter::addAttribute("units"        , units        , &axis_name);
1776          SuperClassWriter::addAttribute("nav_model"    , nav_model    , &axis_name);
1777         }
1778         catch (CNetCdfException& e)
1779         {
1780           StdString msg("On writing Axis Attribute: ");
1781           msg.append("In the context : ");
1782           CContext* context = CContext::getCurrent() ;
1783           msg.append(context->getId()); msg.append("\n");
1784           msg.append(e.what());
1785           ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \
1786                                                      const StdString & axis, \
1787                                                      const StdString & standard_name, \
1788                                                      const StdString & long_name, \
1789                                                      const StdString & units, \
1790                                                      const StdString & nav_model)", << msg);
1791         }
1792      }
1793
1794      //---------------------------------------------------------------
1795
1796      void CNc4DataOutput::writeLocalAttributes
1797         (int ibegin, int ni, int jbegin, int nj, StdString domid)
1798      {
1799        try
1800        {
1801         SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin);
1802         SuperClassWriter::addAttribute(StdString("ni"    ).append(domid), ni);
1803         SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin);
1804         SuperClassWriter::addAttribute(StdString("nj"    ).append(domid), nj);
1805        }
1806        catch (CNetCdfException& e)
1807        {
1808           StdString msg("On writing Local Attributes: ");
1809           msg.append("In the context : ");
1810           CContext* context = CContext::getCurrent() ;
1811           msg.append(context->getId()); msg.append("\n");
1812           msg.append(e.what());
1813           ERROR("CNc4DataOutput::writeLocalAttributes \
1814                  (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg);
1815        }
1816
1817      }
1818
1819      void CNc4DataOutput::writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid,
1820                                                       int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)
1821      {
1822         CArray<int,1> array(2) ;
1823
1824         try
1825         {
1826           SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ;
1827           SuperClassWriter::addAttribute("DOMAIN_number", rank) ;
1828           array = SuperClassWriter::getDimension(dimXid) + 1, SuperClassWriter::getDimension(dimYid) + 1;
1829           SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ;
1830           array=ni_glo,nj_glo ;
1831           SuperClassWriter::addAttribute("DOMAIN_size_global", array) ;
1832           array=ni,nj ;
1833           SuperClassWriter::addAttribute("DOMAIN_size_local", array) ;
1834           array=ibegin,jbegin ;
1835           SuperClassWriter::addAttribute("DOMAIN_position_first", array) ;
1836           array=ibegin+ni-1,jbegin+nj-1 ;
1837           SuperClassWriter::addAttribute("DOMAIN_position_last",array) ;
1838           array=0,0 ;
1839           SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ;
1840           SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array);
1841           SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ;
1842  /*
1843           SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ;
1844           SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ;
1845           SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ;
1846           SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ;
1847  */
1848         }
1849         catch (CNetCdfException& e)
1850         {
1851           StdString msg("On writing Local Attributes IOIPSL \n");
1852           msg.append("In the context : ");
1853           CContext* context = CContext::getCurrent() ;
1854           msg.append(context->getId()); msg.append("\n");
1855           msg.append(e.what());
1856           ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \
1857                  (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg);
1858         }
1859      }
1860      //---------------------------------------------------------------
1861
1862      void CNc4DataOutput:: writeFileAttributes(const StdString & name,
1863                                                const StdString & description,
1864                                                const StdString & conventions,
1865                                                const StdString & production,
1866                                                const StdString & timeStamp)
1867      {
1868         try
1869         {
1870           SuperClassWriter::addAttribute("name"       , name);
1871           SuperClassWriter::addAttribute("description", description);
1872           SuperClassWriter::addAttribute("title"      , description);
1873           SuperClassWriter::addAttribute("Conventions", conventions);
1874           SuperClassWriter::addAttribute("production" , production);
1875           SuperClassWriter::addAttribute("timeStamp"  , timeStamp);
1876         }
1877         catch (CNetCdfException& e)
1878         {
1879           StdString msg("On writing File Attributes \n ");
1880           msg.append("In the context : ");
1881           CContext* context = CContext::getCurrent() ;
1882           msg.append(context->getId()); msg.append("\n");
1883           msg.append(e.what());
1884           ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \
1885                                                const StdString & description, \
1886                                                const StdString & conventions, \
1887                                                const StdString & production, \
1888                                                const StdString & timeStamp)", << msg);
1889         }
1890      }
1891
1892      //---------------------------------------------------------------
1893
1894      void CNc4DataOutput::writeMaskAttributes(const StdString & mask_name,
1895                                               int data_dim,
1896                                               int data_ni,
1897                                               int data_nj,
1898                                               int data_ibegin,
1899                                               int data_jbegin)
1900      {
1901         try
1902         {
1903           SuperClassWriter::addAttribute("data_dim"   , data_dim   , &mask_name);
1904           SuperClassWriter::addAttribute("data_ni"    , data_ni    , &mask_name);
1905           SuperClassWriter::addAttribute("data_nj"    , data_nj    , &mask_name);
1906           SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name);
1907           SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name);
1908         }
1909         catch (CNetCdfException& e)
1910         {
1911           StdString msg("On writing Mask Attributes \n ");
1912           msg.append("In the context : ");
1913           CContext* context = CContext::getCurrent() ;
1914           msg.append(context->getId()); msg.append("\n");
1915           msg.append(e.what());
1916           ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \
1917                                               int data_dim, \
1918                                               int data_ni, \
1919                                               int data_nj, \
1920                                               int data_ibegin, \
1921                                               int data_jbegin)", << msg);
1922         }
1923      }
1924
1925      ///--------------------------------------------------------------
1926
1927} // namespace xios
Note: See TracBrowser for help on using the repository browser.