source: XIOS/dev/dev_trunk_omp/src/io/nc4_data_input.cpp @ 1670

Last change on this file since 1670 was 1646, checked in by yushan, 5 years ago

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

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