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

Last change on this file since 770 was 770, checked in by rlacroix, 8 years ago

Field: Handle more correctly the output name for the fields with a field_ref.

If the field has an explicitly defined name (which might be inherited) then it is used as the output name.
If no name was defined but an id was set, the id is used as the output name.
If no name was defined and the id was automatically generated, the id of the field directly referenced is used as the output name.

  • 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: 4.3 KB
Line 
1#include "nc4_data_input.hpp"
2
3#include "context.hpp"
4#include "context_server.hpp"
5
6namespace xios
7{
8  CNc4DataInput::CNc4DataInput(const StdString& filename, MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/)
9    : SuperClass()
10    , SuperClassWriter(filename, &comm_file, multifile)
11    , comm_file(comm_file)
12    , filename(filename)
13    , isCollective(isCollective)
14  {
15    SuperClass::type = multifile ? MULTI_FILE : ONE_FILE;
16  }
17
18  CNc4DataInput::~CNc4DataInput(void)
19  { /* Nothing more to do */ }
20
21  StdSize CNc4DataInput::getFieldNbRecords_(CField* field)
22  {
23    StdString fieldId = field->getFieldOutputName();
24
25    if (SuperClassWriter::isTemporal(fieldId))
26    {
27      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()];
28    }
29
30    return 1;
31  }
32
33  void CNc4DataInput::readFieldData_(CField* field)
34  {
35    CContext* context = CContext::getCurrent();
36    CContextServer* server = context->server;
37
38    CGrid* grid = field->grid;
39
40    if (!grid->doGridHaveDataToWrite())
41      if (SuperClass::type==MULTI_FILE || !isCollective) return;
42
43    StdString fieldId = field->getFieldOutputName();
44
45    CArray<double,1> fieldData(grid->getWrittenDataSize());
46    if (!field->default_value.isEmpty()) fieldData = field->default_value;
47
48    switch (SuperClass::type)
49    {
50      case MULTI_FILE:
51        SuperClassWriter::getData(fieldData, fieldId, isCollective, field->getNStep() - 1);
52        break;
53      case ONE_FILE:
54      {
55/*
56        std::vector<int> nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
57        std::vector<int> nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
58        std::vector<int> nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
59
60        int ssize = nZoomBeginGlobal.size();
61
62        std::vector<StdSize> start(ssize);
63        std::vector<StdSize> count(ssize);
64
65        for (int i = 0; i < ssize; ++i)
66        {
67          start[i] = nZoomBeginServer[ssize - i - 1] - nZoomBeginGlobal[ssize - i - 1];
68          count[i] = nZoomSizeServer[ssize - i - 1];
69        }
70*/
71
72        std::vector<int> nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal();
73        std::vector<int> nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer();
74        std::vector<int> nZoomSizeServer  = grid->getDistributionServer()->getZoomSizeServer();
75
76        std::vector<StdSize> start, count;
77
78        CArray<bool,1> axisDomainOrder = grid->axis_domain_order;
79        std::vector<StdString> domainList = grid->getDomainList();
80        std::vector<StdString> axisList   = grid->getAxisList();
81        int numElement = axisDomainOrder.numElements();
82        int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1;
83        int idx = nZoomBeginGlobal.size() - 1;
84
85        start.reserve(nZoomBeginGlobal.size());
86        count.reserve(nZoomBeginGlobal.size());
87
88        for (int i = numElement - 1; i >= 0; --i)
89        {
90          if (axisDomainOrder(i))
91          {
92            CDomain* domain = CDomain::get(domainList[idxDomain]);
93            if ((domain->type) != CDomain::type_attr::unstructured)
94            {
95              start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
96              count.push_back(nZoomSizeServer[idx]);
97            }
98            --idx ;
99            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
100            count.push_back(nZoomSizeServer[idx]);
101            --idx ;
102            --idxDomain;
103          }
104          else
105          {
106            start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]);
107            count.push_back(nZoomSizeServer[idx]);
108            --idx;
109           }
110        }
111                 
112        SuperClassWriter::getData(fieldData, fieldId, isCollective, field->getNStep() - 1, &start, &count);
113        break;
114      }
115    }
116
117    field->inputField(fieldData);
118
119    if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
120    {
121      double scaleFactor = 1.0, addOffset = 0.0;
122      if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor;
123      if (!field->add_offset.isEmpty()) addOffset = field->add_offset;
124      field->invertScaleFactorAddOffset(scaleFactor, addOffset);
125    }
126  }
127
128  void CNc4DataInput::closeFile_(void)
129  {
130    SuperClassWriter::close();
131  }
132} // namespace xios
Note: See TracBrowser for help on using the repository browser.