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

Last change on this file since 983 was 967, checked in by mhnguyen, 8 years ago

Ticket 106: Reading a scalar from file

+) Add method to read scalar value
+) Modify the way to send/receive scalar (and non-distributed) data

Test
+) On Curie
+) OK

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