source: XIOS3/branches/xios-3.0-beta/src/io/nc4_data_input.cpp @ 2427

Last change on this file since 2427 was 2338, checked in by jderouillat, 23 months ago

Added extract_domain interface. Updated all interfaces, normalize some private attributes names of domain

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