Ignore:
Timestamp:
06/06/17 17:58:16 (7 years ago)
Author:
oabramkina
Message:

Two server levels: merging with trunk r1137.
There are bugs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_olga/src/io/nc4_data_output.cpp

    r1144 r1158  
    1111#include "netCdfException.hpp" 
    1212#include "exception.hpp" 
    13  
     13#include "timer.hpp" 
     14#include "uuid.hpp" 
    1415namespace xios 
    1516{ 
    1617      /// ////////////////////// Dfinitions ////////////////////// /// 
    1718      CNc4DataOutput::CNc4DataOutput 
    18          (const StdString & filename, bool exist) 
     19         (CFile* file, const StdString & filename, bool exist) 
    1920            : SuperClass() 
    2021            , SuperClassWriter(filename, exist) 
    2122            , filename(filename) 
    22       { 
    23     SuperClass::type = MULTI_FILE; 
     23            , file(file),hasTimeInstant(false),hasTimeCentered(false), timeCounterType(none) 
     24      { 
     25        SuperClass::type = MULTI_FILE; 
    2426      } 
    2527 
    2628      CNc4DataOutput::CNc4DataOutput 
    27          (const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, 
     29         (CFile* file, const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, 
    2830          MPI_Comm comm_file, bool multifile, bool isCollective, const StdString& timeCounterName) 
    2931            : SuperClass() 
     
    3234            , filename(filename) 
    3335            , isCollective(isCollective) 
    34       { 
    35     SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 
     36            , file(file),hasTimeInstant(false),hasTimeCentered(false), timeCounterType(none) 
     37      { 
     38        SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 
    3639      } 
    3740 
     
    6063        } 
    6164 
    62          
    6365         CContext* context = CContext::getCurrent() ; 
    6466         CContextServer* server=context->server ; 
     
    7880         int nvertex = (domain->nvertex.isEmpty()) ? 0 : domain->nvertex; 
    7981 
    80          StdString dimXid, dimYid ; 
    81  
     82 
     83        StdString dimXid, dimYid ; 
     84 
     85        nc_type typePrec ; 
     86        if (domain->prec.isEmpty()) typePrec =  NC_FLOAT ; 
     87        else if (domain->prec==4)  typePrec =  NC_FLOAT ; 
     88        else if (domain->prec==8)   typePrec =  NC_DOUBLE ; 
     89          
    8290         bool isRegularDomain = (domain->type == CDomain::type_attr::rectilinear); 
    8391         switch (domain->type) 
     
    209217                   { 
    210218                     case CDomain::type_attr::curvilinear : 
    211                        SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 
    212                        SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 
     219                       SuperClassWriter::addVariable(latid, typePrec, dim0); 
     220                       SuperClassWriter::addVariable(lonid, typePrec, dim0); 
    213221                       break ; 
    214222                      case CDomain::type_attr::rectilinear : 
    215                         SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 
    216                         SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); 
     223                        SuperClassWriter::addVariable(latid, typePrec, dim0); 
     224                        SuperClassWriter::addVariable(lonid, typePrec, dim1); 
    217225                        break ; 
    218226                   } 
     
    230238                     dim0.push_back(dimXid); 
    231239                     dim0.push_back(dimVertId); 
    232                      SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 
    233                      SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 
     240                     SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0); 
     241                     SuperClassWriter::addVariable(bounds_latid, typePrec, dim0); 
    234242                   } 
    235243                 } 
     
    256264                 if (domain->hasArea) 
    257265                 { 
    258                    SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); 
     266                   SuperClassWriter::addVariable(areaId, typePrec, dim0); 
    259267                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); 
    260268                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); 
     
    311319                       lonid = StdString("nav_lon").append(appendDomid); 
    312320                       latid = StdString("nav_lat").append(appendDomid); 
    313                        SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 
    314                        SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 
     321                       SuperClassWriter::addVariable(latid, typePrec, dim0); 
     322                       SuperClassWriter::addVariable(lonid, typePrec, dim0); 
    315323                       break; 
    316324 
     
    320328                       lonid = StdString("lon").append(appendDomid); 
    321329                       latid = StdString("lat").append(appendDomid); 
    322                        SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 
    323                        SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); 
     330                       SuperClassWriter::addVariable(latid, typePrec, dim0); 
     331                       SuperClassWriter::addVariable(lonid, typePrec, dim1); 
    324332                       break; 
    325333                   } 
     
    342350                     dim0.push_back(dimXid); 
    343351                     dim0.push_back(dimVertId); 
    344                      SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 
    345                      SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 
     352                     SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0); 
     353                     SuperClassWriter::addVariable(bounds_latid, typePrec, dim0); 
    346354                   } 
    347355                 } 
     
    351359                   dim0.clear(); 
    352360                   dim0.push_back(dimYid); dim0.push_back(dimXid); 
    353                    SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); 
     361                   SuperClassWriter::addVariable(areaId, typePrec, dim0); 
    354362                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); 
    355363                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); 
     
    492500        if (SuperClass::type==MULTI_FILE) return ; 
    493501 
     502     nc_type typePrec ; 
     503     if (domain->prec.isEmpty()) typePrec =  NC_FLOAT ; 
     504     else if (domain->prec==4)  typePrec =  NC_FLOAT ; 
     505     else if (domain->prec==8)   typePrec =  NC_DOUBLE ; 
     506 
    494507      std::vector<StdString> dim0; 
    495508      StdString domid = domain->getDomainOutputName(); 
     
    543556                dim0.clear(); 
    544557                dim0.push_back(dimNode); 
    545                 SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); 
     558                SuperClassWriter::addVariable(node_x, typePrec, dim0); 
    546559                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); 
    547560                SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); 
    548561                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); 
    549                 SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); 
     562                SuperClassWriter::addVariable(node_y, typePrec, dim0); 
    550563                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); 
    551564                SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); 
     
    562575                dim0.clear(); 
    563576                dim0.push_back(dimNode); 
    564                 SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); 
     577                SuperClassWriter::addVariable(node_x, typePrec, dim0); 
    565578                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); 
    566579                SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); 
    567580                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); 
    568                 SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); 
     581                SuperClassWriter::addVariable(node_y, typePrec, dim0); 
    569582                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); 
    570583                SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); 
     
    576589              dim0.clear(); 
    577590              dim0.push_back(dimEdge); 
    578               SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); 
     591              SuperClassWriter::addVariable(edge_x, typePrec, dim0); 
    579592              SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); 
    580593              SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x); 
    581594              SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); 
    582               SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); 
     595              SuperClassWriter::addVariable(edge_y, typePrec, dim0); 
    583596              SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); 
    584597              SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y); 
     
    602615                dim0.clear(); 
    603616                dim0.push_back(dimNode); 
    604                 SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); 
     617                SuperClassWriter::addVariable(node_x, typePrec, dim0); 
    605618                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); 
    606619                SuperClassWriter::addAttribute("long_name", StdString("Longitude of mesh nodes."), &node_x); 
    607620                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); 
    608                 SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); 
     621                SuperClassWriter::addVariable(node_y, typePrec, dim0); 
    609622                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); 
    610623                SuperClassWriter::addAttribute("long_name", StdString("Latitude of mesh nodes."), &node_y); 
     
    618631                dim0.clear(); 
    619632                dim0.push_back(dimEdge); 
    620                 SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); 
     633                SuperClassWriter::addVariable(edge_x, typePrec, dim0); 
    621634                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); 
    622635                SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh edges."), &edge_x); 
    623636                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); 
    624                 SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); 
     637                SuperClassWriter::addVariable(edge_y, typePrec, dim0); 
    625638                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); 
    626639                SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh edges."), &edge_y); 
     
    640653              dim0.clear(); 
    641654              dim0.push_back(dimFace); 
    642               SuperClassWriter::addVariable(face_x, NC_FLOAT, dim0); 
     655              SuperClassWriter::addVariable(face_x, typePrec, dim0); 
    643656              SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x); 
    644657              SuperClassWriter::addAttribute("long_name", StdString("Characteristic longitude of mesh faces."), &face_x); 
    645658              SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x); 
    646               SuperClassWriter::addVariable(face_y, NC_FLOAT, dim0); 
     659              SuperClassWriter::addVariable(face_y, typePrec, dim0); 
    647660              SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y); 
    648661              SuperClassWriter::addAttribute("long_name", StdString("Characteristic latitude of mesh faces."), &face_y); 
     
    906919         string areaId = "area" + appendDomid; 
    907920 
     921         nc_type typePrec ; 
     922         if (domain->prec.isEmpty()) typePrec =  NC_FLOAT ; 
     923         else if (domain->prec==4)  typePrec =  NC_FLOAT ; 
     924         else if (domain->prec==8)   typePrec =  NC_DOUBLE ; 
     925 
    908926         int nvertex = (domain->nvertex.isEmpty()) ? 0 : domain->nvertex; 
    909927 
     
    965983                 if (domain->hasLonLat) 
    966984                 { 
    967                    SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 
    968                    SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 
     985                   SuperClassWriter::addVariable(latid, typePrec, dim0); 
     986                   SuperClassWriter::addVariable(lonid, typePrec, dim0); 
    969987                   this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); 
    970988                   if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); 
     
    978996                   dim0.push_back(dimXid); 
    979997                   dim0.push_back(dimVertId); 
    980                    SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 
    981                    SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 
     998                   SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0); 
     999                   SuperClassWriter::addVariable(bounds_latid, typePrec, dim0); 
    9821000                 } 
    9831001 
     
    9861004                 if (domain->hasArea) 
    9871005                 { 
    988                    SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); 
     1006                   SuperClassWriter::addVariable(areaId, typePrec, dim0); 
    9891007                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); 
    9901008                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); 
     
    10211039                 if (domain->hasLonLat) 
    10221040                 { 
    1023                    SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); 
    1024                    SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); 
     1041                   SuperClassWriter::addVariable(latid, typePrec, dim0); 
     1042                   SuperClassWriter::addVariable(lonid, typePrec, dim0); 
    10251043 
    10261044                   this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); 
     
    10361054                   dim0.push_back(dimXid); 
    10371055                   dim0.push_back(dimVertId); 
    1038                    SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); 
    1039                    SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); 
     1056                   SuperClassWriter::addVariable(bounds_lonid, typePrec, dim0); 
     1057                   SuperClassWriter::addVariable(bounds_latid, typePrec, dim0); 
    10401058                 } 
    10411059 
     
    10441062                   dim0.clear(); 
    10451063                   dim0.push_back(dimXid); 
    1046                    SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); 
     1064                   SuperClassWriter::addVariable(areaId, typePrec, dim0); 
    10471065                   SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); 
    10481066                   SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); 
     
    11111129      void CNc4DataOutput::writeAxis_(CAxis* axis) 
    11121130      { 
    1113         CContext* context = CContext::getCurrent(); 
    1114  
    11151131        if (axis->IsWritten(this->filename)) return; 
    11161132        axis->checkAttributes(); 
     
    11301146        else setWrittenAxis(axisid); 
    11311147 
     1148        nc_type typePrec ; 
     1149        if (axis->prec.isEmpty()) typePrec =  NC_FLOAT ; 
     1150        else if (axis->prec==4)  typePrec =  NC_FLOAT ; 
     1151        else if (axis->prec==8)   typePrec =  NC_DOUBLE ; 
     1152          
     1153        if (!axis->label.isEmpty()) typePrec = NC_CHAR ; 
     1154        string strId="str_len" ; 
    11321155        try 
    11331156        { 
    11341157          SuperClassWriter::addDimension(axisid, zoom_size); 
     1158          if (!axis->label.isEmpty()) SuperClassWriter::addDimension(strId, stringArrayLen); 
    11351159          if (axis->hasValue) 
    11361160          { 
    11371161            dims.push_back(axisid); 
    1138             SuperClassWriter::addVariable(axisid, NC_FLOAT, dims); 
     1162            if (!axis->label.isEmpty()) dims.push_back(strId); 
     1163            SuperClassWriter::addVariable(axisid, typePrec, dims); 
    11391164 
    11401165            if (!axis->name.isEmpty()) 
     
    11621187            { 
    11631188              dims.push_back("axis_nbounds"); 
    1164               SuperClassWriter::addVariable(axisBoundsId, NC_FLOAT, dims); 
     1189              SuperClassWriter::addVariable(axisBoundsId, typePrec, dims); 
    11651190              SuperClassWriter::addAttribute("bounds", axisBoundsId, &axisid); 
    11661191            } 
     
    11781203              case MULTI_FILE: 
    11791204              { 
    1180                 // CArray<double,1> axis_value(axis->zoom_n); 
    1181                 // for (int i = 0; i < axis->zoom_n; i++) axis_value(i) = axis->value(i); 
    11821205                SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); 
    11831206 
    1184                 if (!axis->bounds.isEmpty()) 
     1207                if (!axis->bounds.isEmpty() && axis->label.isEmpty()) 
    11851208                  SuperClassWriter::writeData(axis->bounds, axisBoundsId, isCollective, 0); 
    11861209 
     1210                // Need to check after 
     1211                if (! axis->label.isEmpty())  SuperClassWriter::writeData(axis->label_srv, axisid, isCollective, 0); 
     1212  
    11871213                SuperClassWriter::definition_start(); 
    1188  
    11891214                break; 
    11901215              } 
    11911216              case ONE_FILE: 
    11921217              { 
    1193                 // CArray<double,1> axis_value(axis->zoom_n); 
    1194                 // axis_value = axis->value; 
    11951218                std::vector<StdSize> start(1), startBounds(2) ; 
    11961219                std::vector<StdSize> count(1), countBounds(2) ; 
     
    12011224                SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count); 
    12021225 
    1203                 if (!axis->bounds.isEmpty()) 
     1226                if (!axis->bounds.isEmpty()&& axis->label.isEmpty()) 
    12041227                { 
    12051228                  axis_bounds.resize(2, indexToWrite.numElements()); 
     
    12111234                  SuperClassWriter::writeData(axis->bounds, axisBoundsId, isCollective, 0, &startBounds, &countBounds); 
    12121235                } 
     1236 
     1237                // Need to check after 
     1238                if (! axis->label.isEmpty())  SuperClassWriter::writeData(axis->label_srv, axisid, isCollective, 0); 
    12131239 
    12141240                SuperClassWriter::definition_start(); 
     
    12331259          ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg); 
    12341260        } 
    1235        
    1236       axis->addRelFile(this->filename); 
     1261        axis->addRelFile(this->filename); 
    12371262     } 
    12381263 
     
    12471272        else setWrittenAxis(scalaId); 
    12481273 
     1274        nc_type typePrec ; 
     1275        if (scalar->prec.isEmpty()) typePrec =  NC_FLOAT ; 
     1276        else if (scalar->prec==4)  typePrec =  NC_FLOAT ; 
     1277        else if (scalar->prec==8)   typePrec =  NC_DOUBLE ; 
     1278 
     1279         
    12491280        try 
    12501281        { 
     
    12531284//            dims.push_back(scalaId); 
    12541285            std::vector<StdString> dims; 
    1255             SuperClassWriter::addVariable(scalaId, NC_FLOAT, dims); 
     1286            SuperClassWriter::addVariable(scalaId, typePrec, dims); 
    12561287 
    12571288            if (!scalar->name.isEmpty()) 
     
    15501581      void CNc4DataOutput::writeField_(CField* field) 
    15511582      { 
    1552          CContext* context = CContext::getCurrent() ; 
    1553          CContextServer* server=context->server ; 
    1554  
    1555          std::vector<StdString> dims, coodinates; 
    1556          CGrid* grid = field->grid; 
    1557          if (!grid->doGridHaveDataToWrite()) 
     1583        CContext* context = CContext::getCurrent() ; 
     1584        CContextServer* server=context->server ; 
     1585 
     1586        std::vector<StdString> dims, coodinates; 
     1587        CGrid* grid = field->grid; 
     1588        if (!grid->doGridHaveDataToWrite()) 
    15581589          if (SuperClass::type==MULTI_FILE) return ; 
    15591590 
    1560          CArray<int,1> axisDomainOrder = grid->axis_domain_order; 
    1561          int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0; 
    1562          std::vector<StdString> domainList = grid->getDomainList(); 
    1563          std::vector<StdString> axisList   = grid->getAxisList(); 
    1564          std::vector<StdString> scalarList = grid->getScalarList(); 
    1565  
    1566          StdString timeid  = getTimeCounterName(); 
    1567          StdString dimXid,dimYid; 
    1568          std::deque<StdString> dimIdList, dimCoordList; 
    1569          bool hasArea = false; 
    1570          StdString cellMeasures = "area:"; 
    1571          bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output; 
    1572  
    1573          for (int i = 0; i < numElement; ++i) 
    1574          { 
    1575            if (2 == axisDomainOrder(i)) 
    1576            { 
    1577              CDomain* domain = CDomain::get(domainList[idxDomain]); 
    1578              StdString domId = domain->getDomainOutputName(); 
    1579              StdString appendDomId  = singleDomain ? "" : "_" + domId ; 
    1580  
    1581              if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured) 
    1582              { 
    1583                dimIdList.push_back(domId + "_points"); 
    1584                field->setUseCompressedOutput(); 
    1585              } 
    1586  
    1587              switch (domain->type) 
    1588              { 
    1589                case CDomain::type_attr::curvilinear: 
    1590                  if (!compressedOutput || !domain->isCompressible()) 
    1591                  { 
    1592                    dimXid     = StdString("x").append(appendDomId); 
    1593                    dimIdList.push_back(dimXid); 
    1594                    dimYid     = StdString("y").append(appendDomId); 
    1595                    dimIdList.push_back(dimYid); 
    1596                  } 
    1597                  dimCoordList.push_back(StdString("nav_lon").append(appendDomId)); 
    1598                  dimCoordList.push_back(StdString("nav_lat").append(appendDomId)); 
    1599                  break ; 
    1600                case CDomain::type_attr::rectilinear: 
    1601                  if (!compressedOutput || !domain->isCompressible()) 
    1602                  { 
    1603                    dimXid     = StdString("lon").append(appendDomId); 
    1604                    dimIdList.push_back(dimXid); 
    1605                    dimYid     = StdString("lat").append(appendDomId); 
    1606                    dimIdList.push_back(dimYid); 
    1607                  } 
    1608                  break ; 
    1609                case CDomain::type_attr::unstructured: 
    1610                { 
    1611            if (SuperClassWriter::useCFConvention) 
    1612            { 
    1613             dimXid     = StdString("cell").append(appendDomId); 
    1614             dimIdList.push_back(dimXid); 
    1615             dimCoordList.push_back(StdString("lon").append(appendDomId)); 
    1616             dimCoordList.push_back(StdString("lat").append(appendDomId)); 
     1591        CArray<int,1> axisDomainOrder = grid->axis_domain_order; 
     1592        int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0; 
     1593        std::vector<StdString> domainList = grid->getDomainList(); 
     1594        std::vector<StdString> axisList   = grid->getAxisList(); 
     1595        std::vector<StdString> scalarList = grid->getScalarList();         
     1596 
     1597        StdString timeid  = getTimeCounterName(); 
     1598        StdString dimXid,dimYid; 
     1599        std::deque<StdString> dimIdList, dimCoordList; 
     1600        bool hasArea = false; 
     1601        StdString cellMeasures = "area:"; 
     1602        bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output; 
     1603 
     1604        for (int i = 0; i < numElement; ++i) 
     1605        { 
     1606          if (2 == axisDomainOrder(i)) 
     1607          { 
     1608            CDomain* domain = CDomain::get(domainList[idxDomain]); 
     1609            StdString domId = domain->getDomainOutputName(); 
     1610            StdString appendDomId  = singleDomain ? "" : "_" + domId ; 
     1611 
     1612            if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured) 
     1613            { 
     1614              dimIdList.push_back(domId + "_points"); 
     1615              field->setUseCompressedOutput(); 
     1616            } 
     1617 
     1618            switch (domain->type) 
     1619            { 
     1620              case CDomain::type_attr::curvilinear: 
     1621                if (!compressedOutput || !domain->isCompressible()) 
     1622                { 
     1623                  dimXid     = StdString("x").append(appendDomId); 
     1624                  dimIdList.push_back(dimXid); 
     1625                  dimYid     = StdString("y").append(appendDomId); 
     1626                  dimIdList.push_back(dimYid); 
     1627                } 
     1628                dimCoordList.push_back(StdString("nav_lon").append(appendDomId)); 
     1629                dimCoordList.push_back(StdString("nav_lat").append(appendDomId)); 
     1630              break ; 
     1631              case CDomain::type_attr::rectilinear: 
     1632                if (!compressedOutput || !domain->isCompressible()) 
     1633                { 
     1634                  dimXid     = StdString("lon").append(appendDomId); 
     1635                  dimIdList.push_back(dimXid); 
     1636                  dimYid     = StdString("lat").append(appendDomId); 
     1637                  dimIdList.push_back(dimYid); 
     1638                } 
     1639              break ; 
     1640              case CDomain::type_attr::unstructured: 
     1641              { 
     1642                if (SuperClassWriter::useCFConvention) 
     1643                { 
     1644                  dimXid     = StdString("cell").append(appendDomId); 
     1645                  dimIdList.push_back(dimXid); 
     1646                  dimCoordList.push_back(StdString("lon").append(appendDomId)); 
     1647                  dimCoordList.push_back(StdString("lat").append(appendDomId)); 
     1648                } 
     1649                else 
     1650                { 
     1651                  StdString domainName = domain->name; 
     1652                  if (domain->nvertex == 1) 
     1653                  { 
     1654                    dimXid     = "n" + domainName + "_node"; 
     1655                    dimIdList.push_back(dimXid); 
     1656                    dimCoordList.push_back(StdString(domainName + "_node_x")); 
     1657                    dimCoordList.push_back(StdString(domainName + "_node_y")); 
     1658                  } 
     1659                  else if (domain->nvertex == 2) 
     1660                  { 
     1661                    dimXid     = "n" + domainName + "_edge"; 
     1662                    dimIdList.push_back(dimXid); 
     1663                    dimCoordList.push_back(StdString(domainName + "_edge_x")); 
     1664                    dimCoordList.push_back(StdString(domainName + "_edge_y")); 
     1665                  } 
     1666                  else 
     1667                  { 
     1668                    dimXid     = "n" + domainName + "_face"; 
     1669                    dimIdList.push_back(dimXid); 
     1670                    dimCoordList.push_back(StdString(domainName + "_face_x")); 
     1671                    dimCoordList.push_back(StdString(domainName + "_face_y")); 
     1672                  } 
     1673                }  // ugrid convention 
     1674              }  // case unstructured domain 
     1675            } 
     1676 
     1677            if (domain->hasArea) 
     1678            { 
     1679              hasArea = true; 
     1680              cellMeasures += " area" + appendDomId; 
     1681            } 
     1682            ++idxDomain; 
    16171683          } 
    1618            else 
    1619            { 
    1620             StdString domainName = domain->name; 
    1621             if (domain->nvertex == 1) 
     1684          else if (1 == axisDomainOrder(i)) 
     1685          { 
     1686            CAxis* axis = CAxis::get(axisList[idxAxis]); 
     1687            StdString axisId = axis->getAxisOutputName(); 
     1688 
     1689            if (compressedOutput && axis->isCompressible()) 
    16221690            { 
    1623               dimXid     = "n" + domainName + "_node"; 
    1624               dimIdList.push_back(dimXid); 
    1625               dimCoordList.push_back(StdString(domainName + "_node_x")); 
    1626               dimCoordList.push_back(StdString(domainName + "_node_y")); 
    1627             } 
    1628             else if (domain->nvertex == 2) 
    1629             { 
    1630               dimXid     = "n" + domainName + "_edge"; 
    1631               dimIdList.push_back(dimXid); 
    1632               dimCoordList.push_back(StdString(domainName + "_edge_x")); 
    1633               dimCoordList.push_back(StdString(domainName + "_edge_y")); 
     1691              dimIdList.push_back(axisId + "_points"); 
     1692              field->setUseCompressedOutput(); 
    16341693            } 
    16351694            else 
    1636             { 
    1637               dimXid     = "n" + domainName + "_face"; 
    1638               dimIdList.push_back(dimXid); 
    1639               dimCoordList.push_back(StdString(domainName + "_face_x")); 
    1640               dimCoordList.push_back(StdString(domainName + "_face_y")); 
    1641             } 
    1642           }  // ugrid convention 
    1643         }  // case unstructured domain 
    1644              } 
    1645  
    1646              if (domain->hasArea) 
    1647              { 
    1648                hasArea = true; 
    1649                cellMeasures += " area" + appendDomId; 
    1650              } 
    1651              ++idxDomain; 
    1652            } 
    1653            else if (1 == axisDomainOrder(i)) 
    1654            { 
    1655              CAxis* axis = CAxis::get(axisList[idxAxis]); 
    1656              StdString axisId = axis->getAxisOutputName(); 
    1657  
    1658              if (compressedOutput && axis->isCompressible()) 
    1659              { 
    1660                dimIdList.push_back(axisId + "_points"); 
    1661                field->setUseCompressedOutput(); 
    1662              } 
    1663              else 
    1664                dimIdList.push_back(axisId); 
    1665  
    1666              dimCoordList.push_back(axisId); 
    1667              ++idxAxis; 
    1668            } 
    1669            else // scalar 
    1670            { 
     1695              dimIdList.push_back(axisId); 
     1696 
     1697            dimCoordList.push_back(axisId); 
     1698            ++idxAxis; 
     1699          } 
     1700          else // scalar 
     1701          { 
    16711702             /* Do nothing here */ 
    1672            } 
    1673          } 
    1674  
    1675 /* 
    1676          StdString lonid_loc = (server->intraCommSize > 1) 
    1677                              ? StdString("lon").append(appendDomid).append("_local") 
    1678                              : lonid; 
    1679          StdString latid_loc = (server->intraCommSize > 1) 
    1680                              ? StdString("lat").append(appendDomid).append("_local") 
    1681                              : latid; 
    1682 */ 
    1683          StdString fieldid = field->getFieldOutputName(); 
    1684  
    1685          nc_type type ; 
    1686          if (field->prec.isEmpty()) type =  NC_FLOAT ; 
    1687          else 
    1688          { 
    1689            if (field->prec==2) type = NC_SHORT ; 
    1690            else if (field->prec==4)  type =  NC_FLOAT ; 
    1691            else if (field->prec==8)   type =  NC_DOUBLE ; 
    1692          } 
    1693  
    1694          bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once); 
    1695  
    1696          if (wtime) 
    1697          { 
    1698  
    1699             //StdOStringStream oss; 
    1700            // oss << "time_" << field->operation.getValue() 
    1701            //     << "_" << field->getRelFile()->output_freq.getValue(); 
    1702           //oss 
    1703             if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant")); 
    1704             else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered")); 
    1705             dims.push_back(timeid); 
    1706          } 
    1707  
    1708          if (compressedOutput && grid->isCompressible()) 
    1709          { 
    1710            dims.push_back(grid->getId() + "_points"); 
    1711            field->setUseCompressedOutput(); 
    1712          } 
    1713          else 
    1714          { 
    1715            while (!dimIdList.empty()) 
    1716            { 
    1717              dims.push_back(dimIdList.back()); 
    1718              dimIdList.pop_back(); 
    1719            } 
    1720          } 
    1721  
    1722          while (!dimCoordList.empty()) 
    1723          { 
    1724            coodinates.push_back(dimCoordList.back()); 
    1725            dimCoordList.pop_back(); 
    1726          } 
    1727  
    1728          try 
    1729          { 
     1703          } 
     1704        } 
     1705 
     1706        StdString fieldid = field->getFieldOutputName(); 
     1707 
     1708        nc_type type ; 
     1709        if (field->prec.isEmpty()) type =  NC_FLOAT ; 
     1710        else 
     1711        { 
     1712          if (field->prec==2) type = NC_SHORT ; 
     1713          else if (field->prec==4)  type =  NC_FLOAT ; 
     1714          else if (field->prec==8)   type =  NC_DOUBLE ; 
     1715        } 
     1716 
     1717        bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once); 
     1718 
     1719        if (wtime) 
     1720        { 
     1721          if (field->hasTimeInstant && hasTimeInstant) coodinates.push_back(string("time_instant")); 
     1722          else if (field->hasTimeCentered && hasTimeCentered)  coodinates.push_back(string("time_centered")); 
     1723          dims.push_back(timeid); 
     1724        } 
     1725 
     1726        if (compressedOutput && grid->isCompressible()) 
     1727        { 
     1728          dims.push_back(grid->getId() + "_points"); 
     1729          field->setUseCompressedOutput(); 
     1730        } 
     1731        else 
     1732        { 
     1733          while (!dimIdList.empty()) 
     1734          { 
     1735            dims.push_back(dimIdList.back()); 
     1736            dimIdList.pop_back(); 
     1737          } 
     1738        } 
     1739 
     1740        while (!dimCoordList.empty()) 
     1741        { 
     1742          coodinates.push_back(dimCoordList.back()); 
     1743          dimCoordList.pop_back(); 
     1744        } 
     1745 
     1746        try 
     1747        { 
    17301748           SuperClassWriter::addVariable(fieldid, type, dims); 
    17311749 
     
    17421760                 ("units", field->unit.getValue(), &fieldid); 
    17431761 
    1744             if (!field->valid_min.isEmpty()) 
     1762           // Ugrid field attributes "mesh" and "location" 
     1763           if (!SuperClassWriter::useCFConvention) 
     1764           { 
     1765            if (!domainList.empty()) 
     1766            { 
     1767              CDomain* domain = CDomain::get(domainList[0]); // Suppose that we have only domain 
     1768              StdString mesh = domain->name; 
     1769              SuperClassWriter::addAttribute("mesh", mesh, &fieldid); 
     1770              StdString location; 
     1771              if (domain->nvertex == 1) 
     1772                location = "node"; 
     1773              else if (domain->nvertex == 2) 
     1774                location = "edge"; 
     1775              else if (domain->nvertex > 2) 
     1776                location = "face"; 
     1777              SuperClassWriter::addAttribute("location", location, &fieldid); 
     1778            } 
     1779 
     1780           } 
     1781 
     1782           if (!field->valid_min.isEmpty()) 
    17451783              SuperClassWriter::addAttribute 
    17461784                 ("valid_min", field->valid_min.getValue(), &fieldid); 
     
    17711809           if (!field->cell_methods.isEmpty()) 
    17721810           { 
    1773              StdString cellMethodString = field->cell_methods; 
    1774              if (field->cell_methods_mode.isEmpty() || 
     1811              StdString cellMethodString = field->cell_methods; 
     1812              if (field->cell_methods_mode.isEmpty() || 
    17751813                 (CField::cell_methods_mode_attr::overwrite == field->cell_methods_mode)) 
    1776              { 
    1777                SuperClassWriter::addAttribute("cell_methods", cellMethodString, &fieldid); 
    1778                alreadyAddCellMethod = true; 
    1779              } 
    1780              else 
    1781              { 
    1782                switch (field->cell_methods_mode) 
    1783                { 
    1784                case (CField::cell_methods_mode_attr::prefix): 
    1785                  cellMethodsPrefix = cellMethodString; 
    1786                  cellMethodsPrefix += " "; 
    1787                  break; 
    1788                case (CField::cell_methods_mode_attr::suffix): 
    1789                  cellMethodsSuffix = " "; 
    1790                  cellMethodsSuffix += cellMethodString; 
    1791                  break; 
    1792                case (CField::cell_methods_mode_attr::none): 
    1793                  break; 
    1794                default: 
    1795                  break; 
    1796                } 
    1797              } 
     1814              { 
     1815                SuperClassWriter::addAttribute("cell_methods", cellMethodString, &fieldid); 
     1816                alreadyAddCellMethod = true; 
     1817              } 
     1818              else 
     1819              { 
     1820                switch (field->cell_methods_mode) 
     1821                { 
     1822                  case (CField::cell_methods_mode_attr::prefix): 
     1823                    cellMethodsPrefix = cellMethodString; 
     1824                    cellMethodsPrefix += " "; 
     1825                    break; 
     1826                  case (CField::cell_methods_mode_attr::suffix): 
     1827                    cellMethodsSuffix = " "; 
     1828                    cellMethodsSuffix += cellMethodString; 
     1829                    break; 
     1830                  case (CField::cell_methods_mode_attr::none): 
     1831                    break; 
     1832                  default: 
     1833                    break; 
     1834                } 
     1835              } 
    17981836           } 
    17991837 
     
    18811919         singleDomain = (file->nbDomains == 1); 
    18821920 
     1921         StdString conv_str ; 
     1922         if (file->convention_str.isEmpty()) 
     1923         { 
     1924            if (SuperClassWriter::useCFConvention) conv_str="CF-1.6" ; 
     1925            else conv_str="UGRID" ; 
     1926         } 
     1927         else conv_str=file->convention_str ; 
     1928            
    18831929         try 
    18841930         { 
    1885        if (SuperClassWriter::useCFConvention) 
    1886              this->writeFileAttributes(filename, description, 
    1887                                        StdString("CF-1.5"), 
    1888                                        StdString("An IPSL model"), 
    1889                                        this->getTimeStamp()); 
    1890            else 
    1891              this->writeFileAttributes(filename, description, 
    1892                                        StdString("UGRID"), 
    1893                                        StdString("An IPSL model"), 
    1894                                        this->getTimeStamp()); 
    1895  
     1931           this->writeFileAttributes(filename, description, 
     1932                                      conv_str, 
     1933                                      StdString("An IPSL model"), 
     1934                                      this->getTimeStamp()); 
    18961935 
    18971936           if (!appendMode) 
     
    20172056         struct tm * timeinfo = NULL; 
    20182057         char buffer [buffer_size]; 
    2019  
     2058         StdString formatStr; 
     2059         if (file->time_stamp_format.isEmpty()) formatStr="%Y-%b-%d %H:%M:%S %Z" ; 
     2060         else formatStr=file->time_stamp_format; 
     2061 
     2062//         time ( &rawtime ); 
     2063//         timeinfo = localtime ( &rawtime ); 
    20202064         time ( &rawtime ); 
    2021          timeinfo = localtime ( &rawtime ); 
    2022          strftime (buffer, buffer_size, "%Y-%b-%d %H:%M:%S %Z", timeinfo); 
     2065         timeinfo = gmtime ( &rawtime ); 
     2066         strftime (buffer, buffer_size, formatStr.c_str(), timeinfo); 
    20232067 
    20242068         return (StdString(buffer)); 
     
    20332077        CGrid* grid = field->grid; 
    20342078 
    2035         if (field->getNStep()<1) return ; 
     2079        if (field->getNStep()<1)  
     2080        { 
     2081          return; 
     2082        } 
    20362083         
    20372084        if (!grid->doGridHaveDataToWrite()) 
    2038           if (SuperClass::type == MULTI_FILE || !isCollective) return; 
     2085          if (SuperClass::type == MULTI_FILE || !isCollective) 
     2086          { 
     2087            return; 
     2088          } 
    20392089 
    20402090        StdString fieldid = field->getFieldOutputName(); 
     
    20422092        StdOStringStream oss; 
    20432093        string timeAxisId; 
    2044         if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisId = "time_instant"; 
    2045         else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisId = "time_centered"; 
     2094        if (field->hasTimeInstant) timeAxisId = "time_instant"; 
     2095        else if (field->hasTimeCentered) timeAxisId = "time_centered"; 
    20462096 
    20472097        StdString timeBoundId = getTimeCounterName() + "_bounds"; 
    20482098 
    20492099        StdString timeAxisBoundId; 
    2050         if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisBoundId = "time_instant_bounds"; 
    2051         else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisBoundId = "time_centered_bounds"; 
     2100        if (field->hasTimeInstant) timeAxisBoundId = "time_instant_bounds"; 
     2101        else if (field->hasTimeCentered) timeAxisBoundId = "time_centered_bounds"; 
    20522102 
    20532103        if (!field->wasWritten()) 
    20542104        { 
    2055           if (appendMode && field->file->record_offset.isEmpty() && 
    2056                field->getOperationTimeType() != func::CFunctor::once) 
     2105          if (appendMode && field->file->record_offset.isEmpty() &&  
     2106              field->getOperationTimeType() != func::CFunctor::once) 
    20572107          { 
    2058             field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1); 
     2108            double factorUnit; 
     2109            if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) 
     2110            factorUnit=context->getCalendar()->getDayLengthInSeconds() ; 
     2111            else factorUnit=1 ; 
     2112            field->resetNStep(getRecordFromTime(field->last_Write_srv,factorUnit) + 1); 
    20592113          } 
    20602114 
     
    20692123 
    20702124        bool wtime = (field->getOperationTimeType() != func::CFunctor::once); 
     2125        bool wtimeCounter =false ; 
     2126        bool wtimeData =false ; 
     2127         
    20712128 
    20722129        if (wtime) 
     
    20752132          Time lastLastWrite = field->lastlast_Write_srv; 
    20762133 
    2077           if (field->getOperationTimeType() == func::CFunctor::instant) 
    2078             time_data(0) = lastWrite; 
    2079           else if (field->getOperationTimeType() == func::CFunctor::centered) 
     2134           
     2135          if (field->hasTimeInstant) 
     2136          { 
     2137            time_data(0) = time_data_bound(1) = lastWrite; 
     2138            time_data_bound(0) = time_data_bound(1) = lastWrite; 
     2139            if (timeCounterType==instant) 
     2140            { 
     2141              time_counter(0) = time_data(0); 
     2142              time_counter_bound(0) = time_data_bound(0); 
     2143              time_counter_bound(1) = time_data_bound(1); 
     2144              wtimeCounter=true ; 
     2145            } 
     2146            if (hasTimeInstant) wtimeData=true ; 
     2147          } 
     2148          else if (field->hasTimeCentered) 
     2149          { 
    20802150            time_data(0) = (lastWrite + lastLastWrite) / 2; 
    2081  
    2082           if (field->getOperationTimeType() == func::CFunctor::instant) 
    2083             time_data_bound(0) = time_data_bound(1) = lastWrite; 
    2084           else if (field->getOperationTimeType() == func::CFunctor::centered) 
    2085           { 
    20862151            time_data_bound(0) = lastLastWrite; 
    20872152            time_data_bound(1) = lastWrite; 
     2153            if (timeCounterType==centered) 
     2154            { 
     2155              time_counter(0) = time_data(0) ; 
     2156              time_counter_bound(0) = time_data_bound(0) ; 
     2157              time_counter_bound(1) = time_data_bound(1) ; 
     2158              wtimeCounter=true ; 
     2159            } 
     2160            if (hasTimeCentered) wtimeData=true ; 
    20882161          } 
    20892162 
    2090           if (field->file->time_counter == CFile::time_counter_attr::instant) 
    2091             time_counter(0) = lastWrite; 
    2092           else if (field->file->time_counter == CFile::time_counter_attr::centered) 
    2093             time_counter(0) = (lastWrite + lastLastWrite) / 2; 
    2094           else if (field->file->time_counter == CFile::time_counter_attr::record) 
     2163          if (timeCounterType==record) 
     2164          { 
    20952165            time_counter(0) = field->getNStep() - 1; 
    2096  
    2097  
    2098           if (field->file->time_counter == CFile::time_counter_attr::instant) 
    2099             time_counter_bound(0) = time_counter_bound(1) = lastWrite; 
    2100           else if (field->file->time_counter == CFile::time_counter_attr::centered) 
     2166            time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1; 
     2167            wtimeCounter=true ; 
     2168          } 
     2169 
     2170          if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) 
    21012171          { 
    2102             time_counter_bound(0) = lastLastWrite; 
    2103             time_counter_bound(1) = lastWrite; 
     2172            double secByDay=context->getCalendar()->getDayLengthInSeconds() ; 
     2173            time_data/=secByDay; 
     2174            time_data_bound/=secByDay; 
     2175            time_counter/=secByDay; 
     2176            time_counter_bound/=secByDay; 
    21042177          } 
    2105           else if (field->file->time_counter == CFile::time_counter_attr::record) 
    2106             time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1; 
    21072178        } 
    21082179 
     
    21402211              case (MULTI_FILE) : 
    21412212              { 
     2213                 CTimer::get("Files : writing data").resume(); 
    21422214                 SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1); 
     2215                 CTimer::get("Files : writing data").suspend(); 
    21432216                 if (wtime) 
    21442217                 { 
    2145                    SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1); 
    2146                    SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1); 
    2147                    if (field->file->time_counter != CFile::time_counter_attr::none) 
     2218                   CTimer::get("Files : writing time axis").resume(); 
     2219                   if ( wtimeData) 
    21482220                   { 
    2149                      SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1); 
    2150                      if (field->file->time_counter != CFile::time_counter_attr::record) 
    2151                        SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1); 
     2221//                     SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1); 
     2222//                     SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1); 
     2223                       SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); 
     2224                       SuperClassWriter::writeTimeAxisDataBounds(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); 
     2225                  } 
     2226                   if (wtimeCounter) 
     2227                   { 
     2228//                     SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1); 
     2229//                     if (timeCounterType!=record) SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1); 
     2230                     SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1,isRoot); 
     2231                     if (timeCounterType!=record) SuperClassWriter::writeTimeAxisDataBounds(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); 
    21522232                   } 
     2233                   CTimer::get("Files : writing time axis").suspend(); 
    21532234                 } 
    21542235                 break; 
     
    22272308                      } 
    22282309                    } 
    2229                   }                 
     2310                  } 
    22302311                } 
    22312312                else 
     
    22782359                } 
    22792360 
     2361 
     2362                CTimer::get("Files : writing data").resume(); 
    22802363                SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count); 
    2281                 if (wtime) 
    2282                 { 
    2283                    SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); 
    2284                    SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); 
    2285                    if (field->file->time_counter != CFile::time_counter_attr::none) 
     2364                CTimer::get("Files : writing data").suspend(); 
     2365 
     2366                 if (wtime) 
     2367                 { 
     2368                   CTimer::get("Files : writing time axis").resume(); 
     2369                   if ( wtimeData) 
    22862370                   { 
    2287                      SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1, isRoot); 
    2288                      if (field->file->time_counter != CFile::time_counter_attr::record) 
    2289                        SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); 
     2371//                     SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1); 
     2372//                     SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1); 
     2373                     SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); 
     2374                     SuperClassWriter::writeTimeAxisDataBounds(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); 
    22902375                   } 
    2291                 } 
     2376                   if (wtimeCounter) 
     2377                   { 
     2378//                     SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1); 
     2379//                     if (timeCounterType!=record) SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1); 
     2380                     SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1,isRoot); 
     2381                     if (timeCounterType!=record) SuperClassWriter::writeTimeAxisDataBounds(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); 
     2382 
     2383                   } 
     2384                   CTimer::get("Files : writing time axis").suspend();   
     2385                 } 
    22922386 
    22932387                break; 
     
    23132407      { 
    23142408         StdOStringStream oss; 
    2315  
     2409         bool createInstantAxis=false ; 
     2410         bool createCenteredAxis=false ; 
     2411         bool createTimeCounterAxis=false ; 
     2412          
    23162413         if (field->getOperationTimeType() == func::CFunctor::once) return ; 
    23172414 
    2318 //         oss << "time_" << field->operation.getValue() 
    2319 //             << "_" << field->getRelFile()->output_freq.getValue(); 
    2320  
    2321 //         StdString axisid = oss.str(); 
    2322 //         if (field->getOperationTimeType() == func::CFunctor::centered) axisid="time_centered" ; 
    2323 //         else if (field->getOperationTimeType() == func::CFunctor::instant) axisid="time_instant" ; 
    2324  
    2325          StdString axisid("time_centered") ; 
    2326          StdString axisBoundId("time_centered_bounds"); 
     2415 
     2416         StdString axisId ; 
     2417         StdString axisBoundId; 
    23272418         StdString timeid(getTimeCounterName()); 
    23282419         StdString timeBoundId("axis_nbounds"); 
    23292420 
    2330          if (field->getOperationTimeType() == func::CFunctor::instant) 
    2331          { 
    2332             axisid = "time_instant"; 
    2333             axisBoundId = "time_instant_bounds"; 
    2334          } 
    2335  
     2421         StdString strTimeUnits ; 
     2422         if (!field->file->time_units.isEmpty() && field->file->time_units==CFile::time_units_attr::days) strTimeUnits="days since " ; 
     2423         else  strTimeUnits="seconds since " ; 
     2424  
     2425         if (field->getOperationTimeType() == func::CFunctor::instant) field->hasTimeInstant = true; 
     2426         if (field->getOperationTimeType() == func::CFunctor::centered) field->hasTimeCentered = true; 
     2427 
     2428 
     2429         if (field->file->time_counter.isEmpty()) 
     2430         { 
     2431           if (timeCounterType==none) createTimeCounterAxis=true ; 
     2432           if (field->hasTimeCentered) 
     2433           { 
     2434             timeCounterType=centered ; 
     2435             if (!hasTimeCentered) createCenteredAxis=true ; 
     2436           } 
     2437           if (field->hasTimeInstant) 
     2438           { 
     2439             if (timeCounterType==none) timeCounterType=instant ; 
     2440             if (!hasTimeInstant) createInstantAxis=true ; 
     2441           } 
     2442         } 
     2443         else if (field->file->time_counter==CFile::time_counter_attr::instant) 
     2444         { 
     2445           if (field->hasTimeCentered) 
     2446           { 
     2447             if (!hasTimeCentered) createCenteredAxis=true ; 
     2448           } 
     2449           if (field->hasTimeInstant) 
     2450           { 
     2451             if (timeCounterType==none) createTimeCounterAxis=true ; 
     2452             timeCounterType=instant ; 
     2453             if (!hasTimeInstant) createInstantAxis=true ; 
     2454           } 
     2455         } 
     2456         else if (field->file->time_counter==CFile::time_counter_attr::centered) 
     2457         { 
     2458           if (field->hasTimeCentered) 
     2459           { 
     2460             if (timeCounterType==none) createTimeCounterAxis=true ; 
     2461             timeCounterType=centered ; 
     2462             if (!hasTimeCentered) createCenteredAxis=true ; 
     2463           } 
     2464           if (field->hasTimeInstant) 
     2465           { 
     2466             if (!hasTimeInstant) createInstantAxis=true ; 
     2467           } 
     2468         } 
     2469         else if (field->file->time_counter==CFile::time_counter_attr::instant_exclusive) 
     2470         { 
     2471           if (field->hasTimeCentered) 
     2472           { 
     2473             if (!hasTimeCentered) createCenteredAxis=true ; 
     2474           } 
     2475           if (field->hasTimeInstant) 
     2476           { 
     2477             if (timeCounterType==none) createTimeCounterAxis=true ; 
     2478             timeCounterType=instant ; 
     2479           } 
     2480         } 
     2481         else if (field->file->time_counter==CFile::time_counter_attr::centered_exclusive) 
     2482         { 
     2483           if (field->hasTimeCentered) 
     2484           { 
     2485             if (timeCounterType==none) createTimeCounterAxis=true ; 
     2486             timeCounterType=centered ; 
     2487           } 
     2488           if (field->hasTimeInstant) 
     2489           { 
     2490             if (!hasTimeInstant) createInstantAxis=true ; 
     2491           } 
     2492         } 
     2493         else if (field->file->time_counter==CFile::time_counter_attr::exclusive) 
     2494         { 
     2495           if (field->hasTimeCentered) 
     2496           { 
     2497             if (timeCounterType==none) createTimeCounterAxis=true ; 
     2498             if (timeCounterType==instant) createInstantAxis=true ; 
     2499             timeCounterType=centered ; 
     2500           } 
     2501           if (field->hasTimeInstant) 
     2502           { 
     2503             if (timeCounterType==none) 
     2504             { 
     2505               createTimeCounterAxis=true ; 
     2506               timeCounterType=instant ; 
     2507             } 
     2508             if (timeCounterType==centered) 
     2509             { 
     2510               if (!hasTimeInstant) createInstantAxis=true ; 
     2511             } 
     2512           } 
     2513         } 
     2514         else if (field->file->time_counter==CFile::time_counter_attr::none) 
     2515         { 
     2516           if (field->hasTimeCentered) 
     2517           { 
     2518             if (!hasTimeCentered) createCenteredAxis=true ; 
     2519           } 
     2520           if (field->hasTimeInstant) 
     2521           { 
     2522             if (!hasTimeInstant) createInstantAxis=true ; 
     2523           } 
     2524         } 
     2525         else if (field->file->time_counter==CFile::time_counter_attr::record) 
     2526         { 
     2527           if (timeCounterType==none) createTimeCounterAxis=true ; 
     2528           timeCounterType=record ; 
     2529           if (field->hasTimeCentered) 
     2530           { 
     2531             if (!hasTimeCentered) createCenteredAxis=true ; 
     2532           } 
     2533           if (field->hasTimeInstant) 
     2534           { 
     2535             if (!hasTimeInstant) createInstantAxis=true ; 
     2536           } 
     2537         } 
     2538          
     2539         if (createInstantAxis) 
     2540         { 
     2541           axisId="time_instant" ; 
     2542           axisBoundId="time_instant_bounds"; 
     2543           hasTimeInstant=true ; 
     2544         } 
     2545 
     2546         if (createCenteredAxis) 
     2547         { 
     2548           axisId="time_centered" ; 
     2549           axisBoundId="time_centered_bounds"; 
     2550           hasTimeCentered=true ; 
     2551         } 
     2552 
     2553          
    23362554         try 
    23372555         { 
    2338           // Adding time_instant or time_centered 
    2339            std::vector<StdString> dims; 
    2340            dims.push_back(timeid); 
    2341            if (!SuperClassWriter::varExist(axisid)) 
    2342            { 
    2343               SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 
    2344  
    2345               CDate timeOrigin=cal->getTimeOrigin() ; 
    2346               StdOStringStream oss2; 
    2347   //            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " 
    2348   //                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; 
    2349               StdString strInitdate=oss2.str() ; 
    2350               StdString strTimeOrigin=timeOrigin.toString() ; 
    2351               this->writeTimeAxisAttributes 
    2352                  (axisid, cal->getType(), 
    2353                   StdString("seconds since ").append(strTimeOrigin), 
    2354                   strTimeOrigin, axisBoundId); 
    2355            } 
    2356  
    2357            // Adding time_instant_bounds or time_centered_bounds variables 
    2358            if (!SuperClassWriter::varExist(axisBoundId)) 
    2359            { 
    2360               dims.clear() ; 
     2556            std::vector<StdString> dims; 
     2557             
     2558            if (createInstantAxis || createCenteredAxis) 
     2559            { 
     2560              // Adding time_instant or time_centered 
    23612561              dims.push_back(timeid); 
    2362               dims.push_back(timeBoundId); 
    2363               SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); 
    2364            } 
    2365  
    2366            if (field->file->time_counter != CFile::time_counter_attr::none) 
     2562              if (!SuperClassWriter::varExist(axisId)) 
     2563              { 
     2564                SuperClassWriter::addVariable(axisId, NC_DOUBLE, dims); 
     2565 
     2566                CDate timeOrigin=cal->getTimeOrigin() ; 
     2567                StdOStringStream oss2; 
     2568                StdString strInitdate=oss2.str() ; 
     2569                StdString strTimeOrigin=timeOrigin.toString() ; 
     2570                this->writeTimeAxisAttributes(axisId, cal->getType(),strTimeUnits+strTimeOrigin, 
     2571                                              strTimeOrigin, axisBoundId); 
     2572             } 
     2573 
     2574             // Adding time_instant_bounds or time_centered_bounds variables 
     2575             if (!SuperClassWriter::varExist(axisBoundId)) 
     2576             { 
     2577                dims.clear() ; 
     2578                dims.push_back(timeid); 
     2579                dims.push_back(timeBoundId); 
     2580                SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); 
     2581             } 
     2582           } 
     2583 
     2584           if (createTimeCounterAxis) 
    23672585           { 
    23682586             // Adding time_counter 
    2369              axisid = getTimeCounterName(); 
     2587             axisId = getTimeCounterName(); 
    23702588             axisBoundId = getTimeCounterName() + "_bounds"; 
    23712589             dims.clear(); 
    23722590             dims.push_back(timeid); 
    2373              if (!SuperClassWriter::varExist(axisid)) 
     2591             if (!SuperClassWriter::varExist(axisId)) 
    23742592             { 
    2375                 SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 
    2376                 SuperClassWriter::addAttribute("axis", string("T"), &axisid); 
    2377  
    2378                 if (field->file->time_counter != CFile::time_counter_attr::record) 
     2593                SuperClassWriter::addVariable(axisId, NC_DOUBLE, dims); 
     2594                SuperClassWriter::addAttribute("axis", string("T"), &axisId); 
     2595 
     2596                if (field->file->time_counter.isEmpty() ||  
     2597                   (field->file->time_counter != CFile::time_counter_attr::record)) 
    23792598                { 
    23802599                  CDate timeOrigin = cal->getTimeOrigin(); 
    23812600                  StdString strTimeOrigin = timeOrigin.toString(); 
    23822601 
    2383                   this->writeTimeAxisAttributes(axisid, cal->getType(), 
    2384                                                 StdString("seconds since ").append(strTimeOrigin), 
     2602                  this->writeTimeAxisAttributes(axisId, cal->getType(), 
     2603                                                strTimeUnits+strTimeOrigin, 
    23852604                                                strTimeOrigin, axisBoundId); 
    23862605                } 
     
    23882607 
    23892608             // Adding time_counter_bound dimension 
    2390              if (field->file->time_counter != CFile::time_counter_attr::record) 
     2609             if (field->file->time_counter.isEmpty() || (field->file->time_counter != CFile::time_counter_attr::record)) 
    23912610             { 
    23922611                if (!SuperClassWriter::varExist(axisBoundId)) 
     
    25632782           SuperClassWriter::addAttribute("title"      , description); 
    25642783           SuperClassWriter::addAttribute("Conventions", conventions); 
    2565            SuperClassWriter::addAttribute("production" , production); 
    2566            SuperClassWriter::addAttribute("timeStamp"  , timeStamp); 
     2784           // SuperClassWriter::addAttribute("production" , production); 
     2785 
     2786           StdString timeStampStr ; 
     2787           if (file->time_stamp_name.isEmpty()) timeStampStr="timeStamp" ; 
     2788           else timeStampStr=file->time_stamp_name ; 
     2789           SuperClassWriter::addAttribute(timeStampStr, timeStamp); 
     2790 
     2791           StdString uuidName ; 
     2792           if (file->uuid_name.isEmpty()) uuidName="uuid" ; 
     2793           else uuidName=file->uuid_name ; 
     2794 
     2795           if (file->uuid_format.isEmpty()) SuperClassWriter::addAttribute(uuidName, getUuidStr()); 
     2796           else SuperClassWriter::addAttribute(uuidName, getUuidStr(file->uuid_format)); 
     2797           
    25672798         } 
    25682799         catch (CNetCdfException& e) 
     
    26162847      ///-------------------------------------------------------------- 
    26172848 
    2618       StdSize CNc4DataOutput::getRecordFromTime(Time time) 
     2849      StdSize CNc4DataOutput::getRecordFromTime(Time time, double factorUnit) 
    26192850      { 
    26202851        std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time); 
     
    26222853        { 
    26232854          StdString timeAxisBoundsId(getTimeCounterName() + "_bounds"); 
    2624           if (!SuperClassWriter::varExist(timeAxisBoundsId)) 
    2625             timeAxisBoundsId = "time_instant_bounds"; 
     2855          if (!SuperClassWriter::varExist(timeAxisBoundsId)) timeAxisBoundsId = "time_centered_bounds"; 
     2856          if (!SuperClassWriter::varExist(timeAxisBoundsId)) timeAxisBoundsId = "time_instant_bounds"; 
    26262857 
    26272858          CArray<double,2> timeAxisBounds; 
    2628           SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective); 
    2629  
     2859          std::vector<StdSize> dimSize(SuperClassWriter::getDimensions(timeAxisBoundsId)) ; 
     2860           
    26302861          StdSize record = 0; 
    26312862          double dtime(time); 
    2632           for (int n = timeAxisBounds.extent(1) - 1; n >= 0; n--) 
     2863          for (int n = dimSize[0] - 1; n >= 0; n--) 
    26332864          { 
    2634             if (timeAxisBounds(1, n) < dtime) 
     2865            SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective, n); 
     2866            timeAxisBounds*=factorUnit ; 
     2867            if (timeAxisBounds(1, 0) < dtime) 
    26352868            { 
    26362869              record = n + 1; 
Note: See TracChangeset for help on using the changeset viewer.