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

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

Use the NetCDF wrapper for inputs for better error checking.

  • 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: 78.4 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           SuperClassWriter::addDimension("axis_nbounds", 2);
1249         }
1250         catch (CNetCdfException& e)
1251         {
1252           StdString msg("On writing file : ");
1253           msg.append(filename); msg.append("\n");
1254           msg.append("In the context : ");
1255           CContext* context = CContext::getCurrent() ;
1256           msg.append(context->getId()); msg.append("\n");
1257           msg.append(e.what());
1258           ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg);
1259         }
1260      }
1261
1262      void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)
1263      {
1264        string name ;
1265        if (!var->name.isEmpty()) name=var->name ;
1266        else if (var->hasId()) name=var->getId() ;
1267        else return ;
1268
1269        try
1270        {
1271          if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32)
1272            addAttribute(name, var->getData<int>(), &fieldId);
1273          else if (var->type.getValue() == CVariable::type_attr::t_int16)
1274            addAttribute(name, var->getData<short int>(), &fieldId);
1275          else if (var->type.getValue() == CVariable::type_attr::t_float)
1276            addAttribute(name, var->getData<float>(), &fieldId);
1277          else if (var->type.getValue() == CVariable::type_attr::t_double)
1278            addAttribute(name, var->getData<double>(), &fieldId);
1279          else if (var->type.getValue() == CVariable::type_attr::t_string)
1280            addAttribute(name, var->getData<string>(), &fieldId);
1281          else
1282            ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)",
1283                  << "Unsupported variable of type " << var->type.getStringValue());
1284        }
1285       catch (CNetCdfException& e)
1286       {
1287         StdString msg("On writing attributes of variable with name : ");
1288         msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n");
1289         msg.append("In the context : ");
1290         CContext* context = CContext::getCurrent() ;
1291         msg.append(context->getId()); msg.append("\n");
1292         msg.append(e.what());
1293         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg);
1294       }
1295     }
1296
1297     void CNc4DataOutput::writeAttribute_ (CVariable* var)
1298     {
1299        string name ;
1300        if (!var->name.isEmpty()) name=var->name ;
1301        else if (var->hasId()) name=var->getId() ;
1302        else return ;
1303        try
1304        {
1305          if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32)
1306            addAttribute(name, var->getData<int>());
1307          else if (var->type.getValue() == CVariable::type_attr::t_int16)
1308            addAttribute(name, var->getData<short int>());
1309          else if (var->type.getValue() == CVariable::type_attr::t_float)
1310            addAttribute(name, var->getData<float>());
1311          else if (var->type.getValue() == CVariable::type_attr::t_double)
1312            addAttribute(name, var->getData<double>());
1313          else if (var->type.getValue() == CVariable::type_attr::t_string)
1314            addAttribute(name, var->getData<string>());
1315          else
1316            ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)",
1317                  << "Unsupported variable of type " << var->type.getStringValue());
1318        }
1319       catch (CNetCdfException& e)
1320       {
1321         StdString msg("On writing attributes of variable with name : ");
1322         msg.append(name); msg.append("\n");
1323         msg.append("In the context : ");
1324         CContext* context = CContext::getCurrent() ;
1325         msg.append(context->getId()); msg.append("\n");
1326         msg.append(e.what());
1327         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg);
1328       }
1329     }
1330
1331      void CNc4DataOutput::syncFile_ (void)
1332      {
1333        try
1334        {
1335          SuperClassWriter::sync() ;
1336        }
1337        catch (CNetCdfException& e)
1338        {
1339         StdString msg("On synchronizing the write among processes");
1340         msg.append("In the context : ");
1341         CContext* context = CContext::getCurrent() ;
1342         msg.append(context->getId()); msg.append("\n");
1343         msg.append(e.what());
1344         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
1345        }
1346      }
1347
1348      void CNc4DataOutput::closeFile_ (void)
1349      {
1350        try
1351        {
1352          SuperClassWriter::close() ;
1353        }
1354        catch (CNetCdfException& e)
1355        {
1356         StdString msg("On closing file");
1357         msg.append("In the context : ");
1358         CContext* context = CContext::getCurrent() ;
1359         msg.append(context->getId()); msg.append("\n");
1360         msg.append(e.what());
1361         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
1362        }
1363
1364      }
1365
1366      //---------------------------------------------------------------
1367
1368      StdString CNc4DataOutput::getTimeStamp(void) const
1369      {
1370         const int buffer_size = 100;
1371         time_t rawtime;
1372         struct tm * timeinfo = NULL;
1373         char buffer [buffer_size];
1374
1375         time ( &rawtime );
1376         timeinfo = localtime ( &rawtime );
1377         strftime (buffer, buffer_size, "%Y-%b-%d %H:%M:%S %Z", timeinfo);
1378
1379         return (StdString(buffer));
1380      }
1381
1382      //---------------------------------------------------------------
1383
1384      void CNc4DataOutput::writeFieldData_ (CField*  field)
1385      {
1386         CContext* context = CContext::getCurrent() ;
1387//          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ;
1388         CContextServer* server=context->server ;
1389
1390         CGrid* grid = field->grid ;
1391
1392         if (!grid->doGridHaveDataToWrite())
1393          if (SuperClass::type==MULTI_FILE || !isCollective) return ;
1394
1395         StdString fieldid   = (!field->name.isEmpty())
1396                             ? field->name.getValue()
1397                             : field->getBaseFieldReference()->getId();
1398
1399         StdOStringStream oss;
1400         string timeAxisId ;
1401         if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisId="time_instant" ;
1402         else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisId="time_centered" ;
1403
1404         StdString timeBoundId("time_counter_bounds");
1405
1406         StdString timeAxisBoundId;
1407         if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisBoundId="time_instant_bounds" ;
1408         else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisBoundId="time_centered_bounds" ;
1409
1410         CArray<double,1> time_data(1) ;
1411         CArray<double,1> time_counter(1) ;
1412         CArray<double,1> time_counter_bound(2);
1413         CArray<double,1> time_data_bound(2);
1414
1415        bool wtime   = !(!field->operation.isEmpty() && (field->getOperationTimeType() == func::CFunctor::once));
1416
1417        if (wtime)
1418        {
1419          time_counter(0)= (Time(field->last_Write_srv) + Time(field->lastlast_Write_srv)) / 2;
1420          if (field->getOperationTimeType() == func::CFunctor::instant)
1421            time_data(0) = Time(field->last_Write_srv);
1422          else if (field->getOperationTimeType() == func::CFunctor::centered) time_data(0) = time_counter(0);
1423
1424          time_counter_bound(0) = Time(field->lastlast_Write_srv);
1425          time_counter_bound(1) = Time(field->last_Write_srv);
1426          if (field->getOperationTimeType() == func::CFunctor::instant)
1427            time_data_bound(0) = time_data_bound(1) = Time(field->last_Write_srv);
1428          else if (field->getOperationTimeType() == func::CFunctor::centered)
1429          {
1430            time_data_bound(0) = time_counter_bound(0);
1431            time_data_bound(1) = time_counter_bound(1);
1432          }
1433         }
1434
1435         bool isRoot ;
1436         if (server->intraCommRank==0) isRoot=true ;
1437         else isRoot=false ;
1438
1439         if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
1440         {
1441           double scaleFactor=1. ;
1442           double addOffset=0. ;
1443           if (!field->scale_factor.isEmpty()) scaleFactor=field->scale_factor ;
1444           if (!field->add_offset.isEmpty()) addOffset=field->add_offset ;
1445           field->scaleFactorAddOffset(scaleFactor,addOffset) ;
1446         }
1447
1448         try
1449         {
1450           size_t writtenSize;
1451           if (field->getUseCompressedOutput())
1452             writtenSize = grid->getNumberWrittenIndexes();
1453           else
1454             writtenSize = grid->getWrittenDataSize();
1455
1456           CArray<double,1> fieldData(writtenSize);
1457           if (!field->default_value.isEmpty()) fieldData = field->default_value;
1458
1459           if (field->getUseCompressedOutput())
1460             field->outputCompressedField(fieldData);
1461           else
1462             field->outputField(fieldData);
1463
1464           if (!field->prec.isEmpty() && field->prec==2) fieldData=round(fieldData) ;
1465
1466           switch (SuperClass::type)
1467           {
1468              case (MULTI_FILE) :
1469              {
1470                 SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep()-1);
1471                 if (wtime)
1472                 {
1473                   SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1);
1474                   SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1);
1475                   SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1);
1476                   SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1);
1477                 }
1478                 break ;
1479              }
1480              case (ONE_FILE) :
1481              {
1482                const std::vector<int>& nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
1483                const std::vector<int>& nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
1484                const std::vector<int>& nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
1485
1486                std::vector<StdSize> start, count;
1487
1488                if (field->getUseCompressedOutput())
1489                {
1490                  if (grid->isCompressible())
1491                  {
1492                    start.push_back(grid->getOffsetWrittenIndexes());
1493                    count.push_back(grid->getNumberWrittenIndexes());
1494                  }
1495                  else
1496                  {
1497                    CArray<bool,1> axisDomainOrder = grid->axis_domain_order;
1498                    std::vector<StdString> domainList = grid->getDomainList();
1499                    std::vector<StdString> axisList   = grid->getAxisList();
1500                    int numElement = axisDomainOrder.numElements();
1501                    int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
1502                    int idx = nZoomBeginGlobal.size() - 1;
1503
1504                    start.reserve(nZoomBeginGlobal.size());
1505                    count.reserve(nZoomBeginGlobal.size());
1506
1507
1508                    for (int i = numElement - 1; i >= 0; --i)
1509                    {
1510                      if (axisDomainOrder(i))
1511                      {
1512                        CDomain* domain = CDomain::get(domainList[idxDomain]);
1513
1514                        if (domain->isCompressible())
1515                        {
1516                          start.push_back(domain->getOffsetWrittenIndexes());
1517                          count.push_back(domain->getNumberWrittenIndexes());
1518                        }
1519                        else
1520                        {
1521                          start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
1522                          count.push_back(nZoomSizeServer[idx]);
1523                          start.push_back(nZoomBeginServer[idx - 1] - nZoomBeginGlobal[idx - 1]);
1524                          count.push_back(nZoomSizeServer[idx - 1]);
1525                        }
1526
1527                        --idxDomain;
1528                        idx -= 2;
1529                      }
1530                      else
1531                      {
1532                        CAxis* axis = CAxis::get(axisList[idxAxis]);
1533
1534                        if (axis->isCompressible())
1535                        {
1536                          start.push_back(axis->getOffsetWrittenIndexes());
1537                          count.push_back(axis->getNumberWrittenIndexes());
1538                        }
1539                        else
1540                        {
1541                          start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
1542                          count.push_back(nZoomSizeServer[idx]);
1543                        }
1544
1545                        --idxAxis;
1546                        --idx;
1547                      }
1548                    }
1549                  }
1550                }
1551                else
1552                {
1553                  int ssize = nZoomBeginGlobal.size();
1554
1555                  start.resize(ssize);
1556                  count.resize(ssize);
1557
1558                  for (int i = 0; i < ssize; ++i)
1559                  {
1560                    start[i] = nZoomBeginServer[ssize - i - 1] - nZoomBeginGlobal[ssize - i - 1];
1561                    count[i] = nZoomSizeServer[ssize - i - 1];
1562                  }
1563                }
1564
1565                SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count);
1566                if (wtime)
1567                {
1568                  SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot);
1569                  SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep() - 1, isRoot);
1570                  SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot);
1571                  SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot);
1572                }
1573
1574                break;
1575              }
1576            }
1577         }
1578         catch (CNetCdfException& e)
1579         {
1580           StdString msg("On writing field data: ");
1581           msg.append(fieldid); msg.append("\n");
1582           msg.append("In the context : ");
1583           msg.append(context->getId()); msg.append("\n");
1584           msg.append(e.what());
1585           ERROR("CNc4DataOutput::writeFieldData_ (CField*  field)", << msg);
1586         }
1587      }
1588
1589      //---------------------------------------------------------------
1590
1591      void CNc4DataOutput::writeTimeAxis_
1592                  (CField*    field,
1593                   const boost::shared_ptr<CCalendar> cal)
1594      {
1595         StdOStringStream oss;
1596
1597         if (field->getOperationTimeType() == func::CFunctor::once) return ;
1598
1599//         oss << "time_" << field->operation.getValue()
1600//             << "_" << field->getRelFile()->output_freq.getValue();
1601
1602//         StdString axisid = oss.str();
1603//         if (field->getOperationTimeType() == func::CFunctor::centered) axisid="time_centered" ;
1604//         else if (field->getOperationTimeType() == func::CFunctor::instant) axisid="time_instant" ;
1605
1606         StdString axisid("time_centered") ;
1607         StdString axisBoundId("time_centered_bounds");
1608         StdString timeid("time_counter");
1609         StdString timeBoundId("axis_nbounds");
1610
1611         if (field->getOperationTimeType() == func::CFunctor::instant)
1612         {
1613            axisid = "time_instant";
1614            axisBoundId = "time_instant_bounds";
1615         }
1616
1617         try
1618         {
1619          // Adding time_instant or time_centered
1620           std::vector<StdString> dims;
1621           dims.push_back(timeid);
1622           if (!SuperClassWriter::varExist(axisid))
1623           {
1624              SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
1625
1626              CDate timeOrigin=cal->getTimeOrigin() ;
1627              StdOStringStream oss2;
1628  //            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" "
1629  //                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ;
1630              StdString strInitdate=oss2.str() ;
1631              StdString strTimeOrigin=timeOrigin.toString() ;
1632              this->writeTimeAxisAttributes
1633                 (axisid, cal->getType(),
1634                  StdString("seconds since ").append(strTimeOrigin),
1635                  strTimeOrigin, axisBoundId);
1636           }
1637
1638           // Adding time_instant_bounds or time_centered_bounds variables
1639           if (!SuperClassWriter::varExist(axisBoundId))
1640           {
1641              dims.clear() ;
1642              dims.push_back(timeid);
1643              dims.push_back(timeBoundId);
1644              SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
1645           }
1646
1647           // Adding time_counter
1648           axisid = "time_counter" ;
1649           axisBoundId = "time_counter_bounds" ;
1650           dims.clear() ;
1651           dims.push_back(timeid);
1652           if (!SuperClassWriter::varExist(axisid))
1653           {
1654              SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
1655              SuperClassWriter::addAttribute("axis", string("T"), &axisid);
1656              CDate timeOrigin=cal->getTimeOrigin() ;
1657              StdString strTimeOrigin=timeOrigin.toString() ;
1658
1659              this->writeTimeAxisAttributes
1660                 (axisid, cal->getType(),
1661                  StdString("seconds since ").append(strTimeOrigin),
1662                  strTimeOrigin, axisBoundId);
1663           }
1664
1665           // Adding time_counter_bound dimension
1666           if (!SuperClassWriter::varExist(axisBoundId))
1667           {
1668              dims.clear();
1669              dims.push_back(timeid);
1670              dims.push_back(timeBoundId);
1671              SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
1672           }
1673         }
1674         catch (CNetCdfException& e)
1675         {
1676           StdString msg("On writing time axis data: ");
1677           msg.append("In the context : ");
1678           CContext* context = CContext::getCurrent() ;
1679           msg.append(context->getId()); msg.append("\n");
1680           msg.append(e.what());
1681           ERROR("CNc4DataOutput::writeTimeAxis_ (CField*    field, \
1682                  const boost::shared_ptr<CCalendar> cal)", << msg);
1683         }
1684      }
1685
1686      //---------------------------------------------------------------
1687
1688      void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name,
1689                                                   const StdString & calendar,
1690                                                   const StdString & units,
1691                                                   const StdString & time_origin,
1692                                                   const StdString & time_bounds,
1693                                                   const StdString & standard_name,
1694                                                   const StdString & long_name)
1695      {
1696         try
1697         {
1698           SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
1699           SuperClassWriter::addAttribute("long_name",     long_name    , &axis_name);
1700           SuperClassWriter::addAttribute("calendar",      calendar     , &axis_name);
1701           SuperClassWriter::addAttribute("units",         units        , &axis_name);
1702           SuperClassWriter::addAttribute("time_origin",   time_origin  , &axis_name);
1703           SuperClassWriter::addAttribute("bounds",        time_bounds  , &axis_name);
1704         }
1705         catch (CNetCdfException& e)
1706         {
1707           StdString msg("On writing time axis Attribute: ");
1708           msg.append("In the context : ");
1709           CContext* context = CContext::getCurrent() ;
1710           msg.append(context->getId()); msg.append("\n");
1711           msg.append(e.what());
1712           ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \
1713                                                          const StdString & calendar,\
1714                                                          const StdString & units, \
1715                                                          const StdString & time_origin, \
1716                                                          const StdString & time_bounds, \
1717                                                          const StdString & standard_name, \
1718                                                          const StdString & long_name)", << msg);
1719         }
1720      }
1721
1722      //---------------------------------------------------------------
1723
1724      void CNc4DataOutput::writeAxisAttributes(const StdString & axis_name,
1725                                               const StdString & axis,
1726                                               const StdString & standard_name,
1727                                               const StdString & long_name,
1728                                               const StdString & units,
1729                                               const StdString & nav_model)
1730      {
1731         try
1732         {
1733          if (!axis.empty())
1734            SuperClassWriter::addAttribute("axis"       , axis         , &axis_name);
1735
1736          SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
1737          SuperClassWriter::addAttribute("long_name"    , long_name    , &axis_name);
1738          SuperClassWriter::addAttribute("units"        , units        , &axis_name);
1739          SuperClassWriter::addAttribute("nav_model"    , nav_model    , &axis_name);
1740         }
1741         catch (CNetCdfException& e)
1742         {
1743           StdString msg("On writing Axis Attribute: ");
1744           msg.append("In the context : ");
1745           CContext* context = CContext::getCurrent() ;
1746           msg.append(context->getId()); msg.append("\n");
1747           msg.append(e.what());
1748           ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \
1749                                                      const StdString & axis, \
1750                                                      const StdString & standard_name, \
1751                                                      const StdString & long_name, \
1752                                                      const StdString & units, \
1753                                                      const StdString & nav_model)", << msg);
1754         }
1755      }
1756
1757      //---------------------------------------------------------------
1758
1759      void CNc4DataOutput::writeLocalAttributes
1760         (int ibegin, int ni, int jbegin, int nj, StdString domid)
1761      {
1762        try
1763        {
1764         SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin);
1765         SuperClassWriter::addAttribute(StdString("ni"    ).append(domid), ni);
1766         SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin);
1767         SuperClassWriter::addAttribute(StdString("nj"    ).append(domid), nj);
1768        }
1769        catch (CNetCdfException& e)
1770        {
1771           StdString msg("On writing Local Attributes: ");
1772           msg.append("In the context : ");
1773           CContext* context = CContext::getCurrent() ;
1774           msg.append(context->getId()); msg.append("\n");
1775           msg.append(e.what());
1776           ERROR("CNc4DataOutput::writeLocalAttributes \
1777                  (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg);
1778        }
1779
1780      }
1781
1782      void CNc4DataOutput::writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid,
1783                                                       int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)
1784      {
1785         CArray<int,1> array(2) ;
1786
1787         try
1788         {
1789           SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ;
1790           SuperClassWriter::addAttribute("DOMAIN_number", rank) ;
1791           array = SuperClassWriter::getDimension(dimXid) + 1, SuperClassWriter::getDimension(dimYid) + 1;
1792           SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ;
1793           array=ni_glo,nj_glo ;
1794           SuperClassWriter::addAttribute("DOMAIN_size_global", array) ;
1795           array=ni,nj ;
1796           SuperClassWriter::addAttribute("DOMAIN_size_local", array) ;
1797           array=ibegin,jbegin ;
1798           SuperClassWriter::addAttribute("DOMAIN_position_first", array) ;
1799           array=ibegin+ni-1,jbegin+nj-1 ;
1800           SuperClassWriter::addAttribute("DOMAIN_position_last",array) ;
1801           array=0,0 ;
1802           SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ;
1803           SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array);
1804           SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ;
1805  /*
1806           SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ;
1807           SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ;
1808           SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ;
1809           SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ;
1810  */
1811         }
1812         catch (CNetCdfException& e)
1813         {
1814           StdString msg("On writing Local Attributes IOIPSL \n");
1815           msg.append("In the context : ");
1816           CContext* context = CContext::getCurrent() ;
1817           msg.append(context->getId()); msg.append("\n");
1818           msg.append(e.what());
1819           ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \
1820                  (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg);
1821         }
1822      }
1823      //---------------------------------------------------------------
1824
1825      void CNc4DataOutput:: writeFileAttributes(const StdString & name,
1826                                                const StdString & description,
1827                                                const StdString & conventions,
1828                                                const StdString & production,
1829                                                const StdString & timeStamp)
1830      {
1831         try
1832         {
1833           SuperClassWriter::addAttribute("name"       , name);
1834           SuperClassWriter::addAttribute("description", description);
1835           SuperClassWriter::addAttribute("title"      , description);
1836           SuperClassWriter::addAttribute("Conventions", conventions);
1837           SuperClassWriter::addAttribute("production" , production);
1838           SuperClassWriter::addAttribute("timeStamp"  , timeStamp);
1839         }
1840         catch (CNetCdfException& e)
1841         {
1842           StdString msg("On writing File Attributes \n ");
1843           msg.append("In the context : ");
1844           CContext* context = CContext::getCurrent() ;
1845           msg.append(context->getId()); msg.append("\n");
1846           msg.append(e.what());
1847           ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \
1848                                                const StdString & description, \
1849                                                const StdString & conventions, \
1850                                                const StdString & production, \
1851                                                const StdString & timeStamp)", << msg);
1852         }
1853      }
1854
1855      //---------------------------------------------------------------
1856
1857      void CNc4DataOutput::writeMaskAttributes(const StdString & mask_name,
1858                                               int data_dim,
1859                                               int data_ni,
1860                                               int data_nj,
1861                                               int data_ibegin,
1862                                               int data_jbegin)
1863      {
1864         try
1865         {
1866           SuperClassWriter::addAttribute("data_dim"   , data_dim   , &mask_name);
1867           SuperClassWriter::addAttribute("data_ni"    , data_ni    , &mask_name);
1868           SuperClassWriter::addAttribute("data_nj"    , data_nj    , &mask_name);
1869           SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name);
1870           SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name);
1871         }
1872         catch (CNetCdfException& e)
1873         {
1874           StdString msg("On writing Mask Attributes \n ");
1875           msg.append("In the context : ");
1876           CContext* context = CContext::getCurrent() ;
1877           msg.append(context->getId()); msg.append("\n");
1878           msg.append(e.what());
1879           ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \
1880                                               int data_dim, \
1881                                               int data_ni, \
1882                                               int data_nj, \
1883                                               int data_ibegin, \
1884                                               int data_jbegin)", << msg);
1885         }
1886      }
1887
1888      ///--------------------------------------------------------------
1889
1890} // namespace xios
Note: See TracBrowser for help on using the repository browser.