source: XIOS/dev/branch_openmp/src/io/nc4_data_input.cpp @ 1491

Last change on this file since 1491 was 1491, checked in by yushan, 3 years ago

Branch EP merged with Dev_cmip6 @r1490

  • 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
File size: 25.2 KB
Line 
1#include "nc4_data_input.hpp"
2
3#include "context.hpp"
4#include "context_server.hpp"
5#include "context_client.hpp"
6#include "domain.hpp"
7#include "axis.hpp"
8#include "scalar.hpp"
9
10namespace xios
11{
12  //CNc4DataInput::CNc4DataInput(const StdString& filename, ep_lib::MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/, const StdString& timeCounterName /*= "time_counter"*/)
13  CNc4DataInput::CNc4DataInput(const StdString& filename, ep_lib::MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/,
14                               bool readMetaDataPar /*= false*/, bool ugridConvention /*= false*/, const StdString& timeCounterName /*= "time_counter"*/)
15    : SuperClass()
16    , SuperClassWriter(filename, &comm_file, multifile, readMetaDataPar, timeCounterName)
17    //, SuperClassWriter(filename, &comm_file, multifile, timeCounterName)
18    , comm_file(comm_file)
19    , filename(filename)
20    , isCollective(isCollective)
21    , ugridConvention(ugridConvention)
22    , readMetaDataDomains_(), readValueDomains_()
23    , readMetaDataAxis_(), readValueAxis_()
24    , readMetaDataScalar_(), readValueScalar_()
25  {
26    SuperClass::type = multifile ? MULTI_FILE : ONE_FILE;
27  }
28
29  CNc4DataInput::~CNc4DataInput(void)
30  { /* Nothing more to do */ }
31
32  StdSize CNc4DataInput::getFieldNbRecords_(CField* field)
33  {
34    StdString fieldId = field->getFieldOutputName();
35
36    if (SuperClassWriter::isTemporal(fieldId))
37    {
38//      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()];
39      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()];
40    }
41
42    return 1;
43  }
44
45  void CNc4DataInput::readFieldData_(CField* field)
46  {
47    CContext* context = CContext::getCurrent();
48    CContextServer* server = context->server;
49
50    CGrid* grid = field->grid;
51
52    if (!grid->doGridHaveDataToWrite())
53      if (SuperClass::type==MULTI_FILE || !isCollective) return;
54
55    StdString fieldId = field->getFieldOutputName();
56
57    CArray<double,1> fieldData(grid->getWrittenDataSize());
58    if (!field->default_value.isEmpty()) fieldData = field->default_value;
59    #ifdef _usingEP
60      SuperClass::type = ONE_FILE;
61      printf("SuperClass::type = %d\n", SuperClass::type);
62    #endif
63       
64    switch (SuperClass::type)
65    {
66      case MULTI_FILE:
67        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax );
68        break;
69      case ONE_FILE:
70      {
71/*
72        std::vector<int> nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
73        std::vector<int> nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
74        std::vector<int> nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
75
76        int ssize = nZoomBeginGlobal.size();
77
78        std::vector<StdSize> start(ssize);
79        std::vector<StdSize> count(ssize);
80
81        for (int i = 0; i < ssize; ++i)
82        {
83          start[i] = nZoomBeginServer[ssize - i - 1] - nZoomBeginGlobal[ssize - i - 1];
84          count[i] = nZoomSizeServer[ssize - i - 1];
85        }
86*/
87
88        std::vector<int> nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
89        std::vector<int> nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
90        std::vector<int> nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
91
92        std::vector<StdSize> start, count;
93
94        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
95        std::vector<StdString> domainList = grid->getDomainList();
96        std::vector<StdString> axisList   = grid->getAxisList();
97        int numElement = axisDomainOrder.numElements();
98        int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
99        int idx = nZoomBeginGlobal.size() - 1;
100
101        start.reserve(nZoomBeginGlobal.size());
102        count.reserve(nZoomBeginGlobal.size());
103
104        for (int i = numElement - 1; i >= 0; --i)
105        {
106          if (2 == axisDomainOrder(i))
107          {
108            CDomain* domain = CDomain::get(domainList[idxDomain]);
109            if ((domain->type) != CDomain::type_attr::unstructured)
110            {
111              start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
112              count.push_back(nZoomSizeServer[idx]);
113            }
114            --idx ;
115            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
116            count.push_back(nZoomSizeServer[idx]);
117            --idx ;
118            --idxDomain;
119          }
120          else if (1 == axisDomainOrder(i))
121          {
122            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
123            count.push_back(nZoomSizeServer[idx]);
124            --idx;
125          }
126          else
127          {
128            if (1 == axisDomainOrder.numElements())
129            {
130              start.push_back(0);
131              count.push_back(1);
132            }
133            --idx;
134          }
135        }
136
137        SuperClassWriter::getData(fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax, &start, &count);
138        break;
139      }
140    }
141
142    field->inputField(fieldData);
143
144    if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
145    {
146      double scaleFactor = 1.0, addOffset = 0.0;
147      if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor;
148      if (!field->add_offset.isEmpty()) addOffset = field->add_offset;
149      field->invertScaleFactorAddOffset(scaleFactor, addOffset);
150    }
151  }
152
153  void CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)
154  {
155    StdString fieldId = field->getFieldOutputName();
156
157    CGrid* grid = field->grid;
158
159    std::vector<CDomain*> domainP = grid->getDomains();
160    std::vector<CAxis*> axisP = grid->getAxis();
161    std::vector<CScalar*> scalarP = grid->getScalars();
162    int gridDim = domainP.size() * 2 + axisP.size();
163
164    // Nothing to do with scalar without timestep
165    if ((0 == gridDim) && (!SuperClassWriter::isTemporal(fieldId))) 
166      return;
167
168    // Verify the compatibility of dimension of declared grid and real grid in file
169    int realGridDim = 1;
170    bool isUnstructuredGrid = SuperClassWriter::isUnstructured(fieldId);
171    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId);
172    std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId);
173
174    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size();
175    if (isUnstructuredGrid) ++realGridDim;
176
177    if (gridDim != realGridDim)
178       ERROR("CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)",
179        << "Field '" << fieldId << "' has incorrect dimension " << std::endl
180        << "Verify dimension of grid defined by 'grid_ref' or 'domain_ref'/'axis_ref' and dimension of grid in read file.");
181
182    // Remove unlimited dimension from the map, we dont need it anymore
183    if (SuperClassWriter::isTemporal(fieldId))
184    {
185      dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName());
186      dimList.pop_front() ;  // assume time dimension is first
187    }
188
189    std::list<std::pair<StdString, StdSize> > listDimSize;
190/*
191    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap)
192      listDimSize.push_front(*itMap);
193*/
194
195    //if (!SuperClassWriter::isRectilinear(fieldId))
196    if (true)
197    {
198      for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
199        listDimSize.push_front(*dimSizeMap.find(*it));
200    }
201    else
202    {
203       std::list<StdString> coords = SuperClassWriter::getCoordinatesIdList(fieldId);
204       std::list<StdString>::const_iterator itCoord = coords.begin();
205       for (; itCoord != coords.end(); itCoord++)
206       {
207         const StdString& coord = *itCoord;
208         if (SuperClassWriter::hasVariable(coord) && !SuperClassWriter::isTemporal(coord))
209         {
210           std::map<StdString, StdSize> dimsTmp = SuperClassWriter::getDimensions(&coord);
211           StdString dimNameTmp = dimsTmp.begin()->first;
212           StdSize dimSizeTmp = dimsTmp.begin()->second;
213           listDimSize.push_front(make_pair(coord, dimSizeTmp));
214           dimSizeMap.erase(dimNameTmp);
215           dimList.remove(dimNameTmp);
216         }
217       }
218       for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it)
219        listDimSize.push_front(*dimSizeMap.find(*it));
220    }
221
222    // Now process domain and axis
223    CArray<int,1> axisDomainOrder = grid->axis_domain_order;
224    int numElement = domainP.size() + axisP.size() + scalarP.size();
225    int elementPosition = 0;
226    int idxDomain = 0, idxAxis = 0, idxScalar = 0;
227
228    std::pair<std::set<StdString>::iterator,bool> it;
229    for (int i = 0; i < numElement; ++i)
230    {
231      if(2 == axisDomainOrder(i))
232      {
233        if (readAttributeValues)
234        {
235           it = readValueDomains_.insert(domainP[idxDomain]->getId());
236           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
237        }
238        else
239        {
240          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId());
241          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId);
242        }
243        ++idxDomain;
244        if (isUnstructuredGrid) ++elementPosition;
245        else elementPosition += 2;
246      }
247      else if (1 == axisDomainOrder(i))
248      {
249        if (readAttributeValues)
250        {
251          it = readValueAxis_.insert(axisP[idxAxis]->getId());
252          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
253        }
254        else
255        {
256          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId());
257          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId);
258        }
259        ++idxAxis;
260        ++elementPosition;
261      }
262      else
263      {
264        if (readAttributeValues)
265        {
266          it = readValueScalar_.insert(scalarP[idxScalar]->getId());
267          if (it.second) readScalarAttributeValueFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
268        }
269        else
270        {
271          it = readMetaDataScalar_.insert(scalarP[idxScalar]->getId());
272          if (it.second) readScalarAttributesFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId);
273        }
274        ++idxScalar;
275        ++elementPosition;
276      }
277    }
278  }
279
280  /*!
281    Read attributes of a domain from a file
282    \param [in] domain domain whose attributes are read from the file
283    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
284    \param [in] emelentPosition position of domain in grid
285    \param [in] fieldId id (or name) associated with the grid
286  */
287  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
288                                                       int elementPosition, const StdString& fieldId)
289  {
290    // There are some optional attributes of a domain to retrieve from file    // + lon lat?
291    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
292                                                              iteMap  = dimSizeMap.end();
293
294    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
295    itMapNj = itMapNi; ++itMapNj;
296
297    if ((CDomain::type_attr::rectilinear == domain->type))
298    {
299      // Ok, try to read some attributes such as longitude and latitude
300      bool hasLat = SuperClassWriter::hasVariable(itMapNj->first);
301      if (hasLat)
302      {
303        domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second);
304        std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second);
305        readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true);
306      }
307
308      bool hasLon = SuperClassWriter::hasVariable(itMapNi->first);
309      if (hasLon)
310      {
311        domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second);
312        std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second);
313        readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true);
314      }     
315    }
316    else if ((CDomain::type_attr::curvilinear == domain->type))
317    {
318      // Make sure that if there is no local domain defined on a process, the process still reads just one value.
319      int ni, nj, ibegin, jbegin;
320      if (domain->ni == 0)
321      {
322        ni = 1;
323        ibegin = 0;
324      }
325      else
326      {
327        ni = domain->ni;
328        ibegin = domain->ibegin;
329      }
330      if (domain->nj == 0)
331      {
332        nj = 1;
333        jbegin = 0;
334      }
335      else
336      {
337        nj = domain->nj;
338        jbegin = domain->jbegin;
339      }
340
341      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
342      nBeginLatLon[0] = jbegin; nBeginLatLon[1] = ibegin;
343      nSizeLatLon[0]  = nj; nSizeLatLon[1] = ni;
344
345      StdString latName = this->getLatCoordName(fieldId);
346      if (SuperClassWriter::hasVariable(latName))
347      {
348        domain->latvalue_curvilinear_read_from_file.resize(ni, nj);
349        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
350      }
351      StdString lonName = this->getLonCoordName(fieldId);
352      if (SuperClassWriter::hasVariable(lonName))
353      {
354        domain->lonvalue_curvilinear_read_from_file.resize(ni, nj);
355        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
356      }
357
358      StdString boundsLatName = this->getBoundsId(latName);
359      StdString boundsLonName = this->getBoundsId(lonName);
360
361      int nbVertex = 4; //this->getNbVertex(fieldId);
362      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
363      {
364        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
365          << "The domain " << domain->getDomainOutputName()
366          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
367          << " are not coherent. They should be the same." << std::endl
368          << " nvertex read from file: "<< nbVertex
369          << " nvertex from model: "<< domain->nvertex << std::endl);
370      } 
371
372      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
373        domain->nvertex.setValue(nbVertex);
374
375      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
376      nBeginBndsLatLon[0] = jbegin; nSizeBndsLatLon[0] = nj;
377      nBeginBndsLatLon[1] = ibegin; nSizeBndsLatLon[1] = ni;
378      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
379
380      if (SuperClassWriter::hasVariable(boundsLatName))
381      {
382        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj);
383        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
384
385      }
386      if (SuperClassWriter::hasVariable(boundsLonName)) 
387      {
388        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj);
389        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
390      }     
391    }
392    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
393    {
394      // Make sure that if there is no local domain defined on a process, the process still reads just one value.
395      int ni, ibegin;
396      if (domain->ni == 0)
397      {
398        ni = 1;
399        ibegin = 0;
400      }
401      else
402      {
403        ni = domain->ni;
404        ibegin = domain->ibegin;
405      }
406
407      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
408      nBeginLatLon[0] = ibegin;
409      nSizeLatLon[0]  = ni;
410
411      StdString latName = this->getLatCoordName(fieldId);
412      if (SuperClassWriter::hasVariable(latName))
413      {
414        domain->latvalue_unstructured_read_from_file.resize(ni);
415        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); 
416      }
417
418      StdString lonName = this->getLonCoordName(fieldId);
419      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
420      {
421        domain->lonvalue_unstructured_read_from_file.resize(ni);
422        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
423      }
424
425      StdString boundsLatName = this->getBoundsId(latName);
426      StdString boundsLonName = this->getBoundsId(lonName);
427
428      if (ugridConvention && domain->nvertex.isEmpty())
429      {
430        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
431          << " Attribute nvertex must be specified for domain " << domain->getDomainOutputName()
432          << " read from UGRID file " << this->filename << " ."<< std::endl);
433      }
434//      int nbVertex = this->getNbVertex(fieldId);
435      int nbVertex = (ugridConvention) ? domain->nvertex : this->getNbVertex(fieldId);
436     
437      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
438      {
439        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
440          << "The domain " << domain->getDomainOutputName()
441          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
442          << " are not coherent. They should be the same." << std::endl
443          << " nvertex read from file: "<< nbVertex
444          << " nvertex from model: "<< domain->nvertex << std::endl);
445      } 
446     
447      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
448        domain->nvertex.setValue(nbVertex);
449
450      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2);
451      nBeginBndsLatLon[0] = ibegin; nSizeBndsLatLon[0] = ni;
452      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
453
454      if (SuperClassWriter::hasVariable(boundsLatName)) 
455      {
456        domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
457        readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
458      }
459
460      if (SuperClassWriter::hasVariable(boundsLonName)) 
461      {
462        domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
463        readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
464      }     
465    }
466    domain->fillInLonLat();
467  }
468
469  /*!
470    Read attribute value of a domain from a file
471    \param [in] domain domain whose attributes are read from the file
472    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
473    \param [in] emelentPosition position of domain in grid
474    \param [in] fieldId id (or name) associated with the grid
475  */
476  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
477                                                   int elementPosition, const StdString& fieldId)
478  {
479    // There are some mandatory attributes of a domain to retrieve from file
480    // + ni_glo, nj_glo
481    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj,
482                                                              iteMap  = dimSizeMap.end();
483    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {}
484    itMapNj = itMapNi; ++itMapNj;
485
486    if (CDomain::type_attr::rectilinear == domain->type || CDomain::type_attr::curvilinear == domain->type ||
487        this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
488    {
489      if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second))
490      {
491        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
492          << "The domain " << domain->getDomainOutputName()
493          << " has nj_glo read from file " << this->filename << " and nj_glo provided from model"
494          << " are not coherent. They should be the same." << std::endl
495          << " nj_glo read from file: "<< itMapNj->second
496          << " nj_glo from model: "<< domain->nj_glo << std::endl);
497      } 
498      domain->nj_glo.setValue(itMapNj->second);
499
500      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
501      {
502        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
503          << "The domain " << domain->getDomainOutputName()
504          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
505          << " are not coherent. They should be the same." << std::endl
506          << " ni_glo read from file: "<< itMapNi->second
507          << " ni_glo from model: "<< domain->ni_glo << std::endl);
508      } 
509      domain->ni_glo.setValue(itMapNi->second);
510    }
511    else if (CDomain::type_attr::unstructured == domain->type|| this->isUnstructured(fieldId))
512    {
513      domain->nj_glo.setValue(1);
514
515      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
516      {
517        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
518          << "The domain " << domain->getDomainOutputName()
519          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
520          << " are not coherent. They should be the same." << std::endl
521          << " ni_glo read from file: "<< itMapNi->second
522          << " ni_glo from model: "<< domain->ni_glo << std::endl);
523      }       
524      domain->ni_glo.setValue(itMapNi->second);
525    }
526  }
527
528  /*!
529    Read attributes of an axis from a file
530    \param [in] axis axis whose attributes are read from the file
531    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
532    \param [in] emelentPosition position of axis in grid
533    \param [in] fieldId id (or name) associated with the grid
534  */
535  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
536                                                 int elementPosition, const StdString& fieldId)
537  {
538    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
539                                                              iteMap = dimSizeMap.end();
540    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
541
542    if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second))
543    {
544      ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)",
545        << "The axis " << axis->getAxisOutputName()
546        << " has n_glo read from file " << this->filename << " and n_glo provided from model"
547        << " are not coherent. They should be the same." << std::endl
548        << " n_glo read from file: "<< itMapN->second
549        << " n_glo from model: "<< axis->n_glo << std::endl);
550    }   
551    axis->n_glo.setValue(itMapN->second);
552  }
553
554  /*!
555    Read attribute value of an axis from a file
556    \param [in] axis axis whose attributes are read from the file
557    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
558    \param [in] emelentPosition position of axis in grid
559    \param [in] fieldId id (or name) associated with the grid
560  */
561  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
562                                                    int elementPosition, const StdString& fieldId)
563  {
564    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
565                                                              iteMap = dimSizeMap.end();
566    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
567
568    { // Read axis value
569      bool hasValue = SuperClassWriter::hasVariable(itMapN->first);
570      if (hasValue)
571      {
572        std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second);
573        CArray<double,1> readAxisValue(itMapN->second);
574        readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true);
575        int begin = 0, n = itMapN->second;
576        if (!axis->begin.isEmpty()) begin = axis->begin.getValue();
577        if (!axis->n.isEmpty()) n = axis->n.getValue();
578        axis->value.resize(n);
579        for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i);
580      }
581    }
582  }
583
584  /*!
585    Read attributes of a scalar from a file
586    \param [in] scalar scalar whose attributes are read from the file
587    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
588    \param [in] emelentPosition position of scalar in grid
589    \param [in] fieldId id (or name) associated with the grid
590  */
591  void CNc4DataInput::readScalarAttributesFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
592                                                  int elementPosition, const StdString& fieldId)
593  {
594    /*Nothing to do */
595  }
596
597  /*!
598    Read attribute value of an axis from a file
599    \param [in] axis axis whose attributes are read from the file
600    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file
601    \param [in] emelentPosition position of axis in grid
602    \param [in] fieldId id (or name) associated with the grid
603  */
604  void CNc4DataInput::readScalarAttributeValueFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
605                                                      int elementPosition, const StdString& fieldId)
606  {
607    /*Nothing to do */
608  }
609
610  void CNc4DataInput::closeFile_(void)
611  {
612    SuperClassWriter::close();
613  }
614} // namespace xios
Note: See TracBrowser for help on using the repository browser.