source: XIOS/trunk/src/io/nc4_data_input.cpp @ 1573

Last change on this file since 1573 was 1573, checked in by ymipsl, 3 years ago

Bug fix when reading data from file : regression from supression of zoom on the server side.

YM

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