Changeset 878 for XIOS


Ignore:
Timestamp:
07/01/16 16:55:33 (8 years ago)
Author:
oabramkina
Message:

Sequential version for UGRID norms. File attribute "convention" has been added with two possible values "CF" and "UGRID". The default value is "CF".

Location:
XIOS/trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/config/file_attribute.conf

    r850 r878  
    1313DECLARE_ENUM2(type,          one_file, multiple_file) 
    1414DECLARE_ENUM2(format,        netcdf4, netcdf4_classic) 
     15DECLARE_ENUM2(convention,    CF, UGRID) 
    1516DECLARE_ENUM2(par_access,    collective, independent) 
    1617DECLARE_ATTRIBUTE(bool,      append) 
     
    2526DECLARE_ENUM4(timeseries,    none, only, both, exclusive) 
    2627DECLARE_ATTRIBUTE(StdString, ts_prefix) 
     28 
  • XIOS/trunk/src/io/nc4_data_output.cpp

    r821 r878  
    1  
    21#include "nc4_data_output.hpp" 
    32 
     
    1514namespace xios 
    1615{ 
    17       /// ////////////////////// Définitions ////////////////////// /// 
     16      /// ////////////////////// Dfinitions ////////////////////// /// 
    1817      CNc4DataOutput::CNc4DataOutput 
    1918         (const StdString & filename, bool exist) 
     
    2221            , filename(filename) 
    2322      { 
    24          SuperClass::type = MULTI_FILE; 
     23                SuperClass::type = MULTI_FILE; 
    2524      } 
    2625 
    2726      CNc4DataOutput::CNc4DataOutput 
    28          (const StdString & filename, bool exist, bool useClassicFormat, 
     27         (const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, 
    2928          MPI_Comm comm_file,bool multifile, bool isCollective, const StdString& timeCounterName) 
    3029            : SuperClass() 
    31             , SuperClassWriter(filename, exist, useClassicFormat, &comm_file, multifile, timeCounterName) 
     30            , SuperClassWriter(filename, exist, useClassicFormat, useCFConvention, &comm_file, multifile, timeCounterName) 
    3231            , comm_file(comm_file) 
    3332            , filename(filename) 
    3433            , isCollective(isCollective) 
    3534      { 
    36          SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 
    37       } 
    38  
     35                SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 
     36      } 
    3937 
    4038      CNc4DataOutput::~CNc4DataOutput(void) 
    41       { /* Ne rien faire de plus */ } 
     39          { /* Ne rien faire de plus */ } 
    4240 
    4341      ///-------------------------------------------------------------- 
     
    5452         if (domain->type == CDomain::type_attr::unstructured) 
    5553         { 
    56            writeUnstructuredDomain(domain) ; 
     54                         if (SuperClassWriter::useCFConvention) 
     55                                writeUnstructuredDomain(domain) ; 
     56                        else 
     57                                writeUnstructuredDomainUgrid(domain) ; 
    5758           return ; 
    5859         } 
     
    386387                   } 
    387388 
    388                    SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0, &start, &count); 
    389                    SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0, &start, &count); 
     389                 SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0, &start, &count); 
     390                 SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0, &start, &count); 
    390391                 } 
    391392 
     
    433434      } 
    434435 
    435       void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain) 
     436          //-------------------------------------------------------------- 
     437 
     438                void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain) 
     439                { 
     440                        CContext* context = CContext::getCurrent() ; 
     441                        CContextServer* server=context->server ; 
     442 
     443                        if (domain->IsWritten(this->filename)) return; 
     444                        domain->checkAttributes(); 
     445                        if (domain->isEmpty()) 
     446                                if (SuperClass::type==MULTI_FILE) return ; 
     447 
     448                        std::vector<StdString> dim0; 
     449                        StdString domid = domain->getDomainOutputName(); 
     450                        StdString domainName = domain->name; 
     451 
     452                        if (domain->mesh->isWritten(domainName)) domain->mesh = CMesh::getMesh; 
     453 
     454                        domain->mesh->createMesh(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv); 
     455                        //domain->mesh->createMeshEpsilon(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv); 
     456 
     457                        StdString node_x = domainName + "_node_x"; 
     458                        StdString node_y = domainName + "_node_y"; 
     459 
     460                        StdString edge_x = domainName + "_edge_x"; 
     461                        StdString edge_y = domainName + "_edge_y"; 
     462                        StdString edge_nodes = domainName + "_edge_nodes"; 
     463 
     464                        StdString face_x = domainName + "_face_x"; 
     465                        StdString face_y = domainName + "_face_y"; 
     466                        StdString face_nodes = domainName + "_face_nodes"; 
     467 
     468                        StdString dimNode = "n" + domainName + "_node"; 
     469                        StdString dimEdge = "n" + domainName + "_edge"; 
     470                        StdString dimFace = "n" + domainName + "_face"; 
     471                        StdString dimVertex = "n" + domainName + "_vertex"; 
     472                        StdString dimTwo = "Two"; 
     473 
     474                        if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2); 
     475                        if (!isWrittenDomain(domid)) 
     476                        { 
     477                                dim0.clear(); 
     478                                SuperClassWriter::addVariable(domainName, NC_INT, dim0); 
     479                                SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName); 
     480                                SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName); 
     481                        } 
     482 
     483                        try 
     484                        { 
     485                                switch (SuperClass::type) 
     486                                { 
     487                                        case (ONE_FILE) : 
     488                                        { 
     489                                                // Adding nodes 
     490                                                if (domain->nvertex == 1) 
     491                                                { 
     492                                                        if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) 
     493                                                        { 
     494                                                                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes); 
     495                                                                dim0.clear(); 
     496                                                                dim0.push_back(dimNode); 
     497                                                                SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); 
     498                                                                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); 
     499                                                                SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x); 
     500                                                                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); 
     501                                                                SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); 
     502                                                                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); 
     503                                                                SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y); 
     504                                                                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); 
     505                                                        } 
     506                                                } // domain->nvertex == 1 
     507 
     508                                                // Adding edges and nodes, if nodes have not been defined previously 
     509                                                if (domain->nvertex == 2) 
     510                                                { 
     511                                                        // Nodes 
     512                                                        if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) 
     513                                                        { 
     514                                                                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes); 
     515                                                                dim0.clear(); 
     516                                                                dim0.push_back(dimNode); 
     517                                                                SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); 
     518                                                                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); 
     519                                                                SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x); 
     520                                                                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); 
     521                                                                SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); 
     522                                                                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); 
     523                                                                SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y); 
     524                                                                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); 
     525                                                        } 
     526                                                        // Edges 
     527                                                        if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y)) 
     528                                                        { 
     529                                                                SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); 
     530                                                                SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); 
     531                                                                SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges); 
     532                                                                dim0.clear(); 
     533                                                                dim0.push_back(dimEdge); 
     534                                                                SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); 
     535                                                                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); 
     536                                                                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x); 
     537                                                                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); 
     538                                                                SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); 
     539                                                                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); 
     540                                                                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y); 
     541                                                                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); 
     542                                                                dim0.clear(); 
     543                                                                dim0.push_back(dimEdge); 
     544                                                                dim0.push_back(dimTwo); 
     545                                                                SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0); 
     546                                                                SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); 
     547                                                                SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); 
     548                                                                SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); 
     549                                                        } 
     550                                                } // domain->nvertex == 2 
     551 
     552                                                // Adding faces, edges, and nodes, if edges and nodes have not been defined previously 
     553                                                if (domain->nvertex > 2) 
     554                                                { 
     555                                                        // Nodes 
     556                                                        if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) 
     557                                                        { 
     558                                                                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes); 
     559                                                                dim0.clear(); 
     560                                                                dim0.push_back(dimNode); 
     561                                                                SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); 
     562                                                                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); 
     563                                                                SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x); 
     564                                                                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); 
     565                                                                SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); 
     566                                                                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); 
     567                                                                SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y); 
     568                                                                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); 
     569                                                        } 
     570                                                        // Edges 
     571                                                        if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y)) 
     572                                                        { 
     573                                                                SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); 
     574                                                                SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); 
     575                                                                SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges); 
     576                                                                dim0.clear(); 
     577                                                                dim0.push_back(dimEdge); 
     578                                                                SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); 
     579                                                                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); 
     580                                                                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x); 
     581                                                                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); 
     582                                                                SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); 
     583                                                                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); 
     584                                                                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y); 
     585                                                                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); 
     586                                                                dim0.clear(); 
     587                                                                dim0.push_back(dimEdge); 
     588                                                                dim0.push_back(dimTwo); 
     589                                                                SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0); 
     590                                                                SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); 
     591                                                                SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); 
     592                                                                SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); 
     593                                                        } 
     594                                                        // Faces 
     595                                                                SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName); 
     596                                                                SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName); 
     597                                                                SuperClassWriter::addDimension(dimFace, domain->mesh->nbFaces); 
     598                                                                SuperClassWriter::addDimension(dimVertex, domain->mesh->nvertex); 
     599                                                                dim0.clear(); 
     600                                                                dim0.push_back(dimFace); 
     601                                                                SuperClassWriter::addVariable(face_x, NC_FLOAT, dim0); 
     602                                                                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x); 
     603                                                                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh faces."), &face_x); 
     604                                                                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x); 
     605                                                                SuperClassWriter::addVariable(face_y, NC_FLOAT, dim0); 
     606                                                                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y); 
     607                                                                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh faces."), &face_y); 
     608                                                                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y); 
     609                                                                dim0.clear(); 
     610                                                                dim0.push_back(dimFace); 
     611                                                                dim0.push_back(dimVertex); 
     612                                                                SuperClassWriter::addVariable(face_nodes, NC_INT, dim0); 
     613                                                                SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes); 
     614                                                                SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes); 
     615                                                                SuperClassWriter::addAttribute("start_index", 0, &face_nodes); 
     616                                                } // domain->nvertex > 2 
     617 
     618                                                SuperClassWriter::definition_end(); 
     619 
     620                                                if (!isWrittenDomain(domid)) 
     621                                                { 
     622                                                        if (domain->nvertex == 1) 
     623                                                        { 
     624                                                                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); 
     625                                                                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); 
     626                                                        } 
     627                                                        else if (domain->nvertex == 2) 
     628                            { 
     629                                                                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); 
     630                                                                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); 
     631                                                                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); 
     632                                                                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); 
     633                                                                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); 
     634                            } 
     635                                                        else 
     636                                                        { 
     637                                                                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); 
     638                                                                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); 
     639                                                                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); 
     640                                                                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); 
     641                                                                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); 
     642                                                                SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0); 
     643                                                                SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0); 
     644                                                                SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes); 
     645                                                        } 
     646                                                        setWrittenDomain(domid); 
     647                                                } // !isWrittenDomain 
     648                                                else 
     649                                                { 
     650                                                        if (domain->nvertex == 1) 
     651                                                        { 
     652                                if ( (!domain->mesh->edgesAreWritten) && (!domain->mesh->facesAreWritten) ) 
     653                                                                { 
     654                                                                        SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); 
     655                                                                        SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); 
     656                                                                } 
     657                                                        } 
     658                                                        if (domain->nvertex == 2) 
     659                                                        { 
     660                                if (!domain->mesh->facesAreWritten) 
     661                                                                { 
     662                                                                        if (!domain->mesh->nodesAreWritten) 
     663                                                                        { 
     664                                                                                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); 
     665                                                                                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); 
     666                                                                        } 
     667                                                                        SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); 
     668                                                                        SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); 
     669                                                                        SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); 
     670                                                                } 
     671                                                        }        
     672                                                        if (domain->nvertex > 2) 
     673                                                        { 
     674                                                                if (!domain->mesh->edgesAreWritten) 
     675                                                                { 
     676                                                                        if (!domain->mesh->nodesAreWritten) 
     677                                                                        { 
     678                                                                                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); 
     679                                                                                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); 
     680                                                                        } 
     681                                                                        SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); 
     682                                                                        SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); 
     683                                                                        SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); 
     684                                                                } 
     685                                                                SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0); 
     686                                                                SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0); 
     687                                                                SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes); 
     688                                                        } 
     689                                                }// isWrittenDomain 
     690 
     691                                                SuperClassWriter::definition_start(); 
     692 
     693                                                break; 
     694                                        } // ONE_FILE 
     695 
     696                                        case (MULTI_FILE) : 
     697                                        { 
     698                                                break; 
     699                                        } 
     700 
     701                                        default : 
     702                                        ERROR("CNc4DataOutput::writeDomain(domain)", 
     703                                        << "[ type = " << SuperClass::type << "]" 
     704                                        << " not implemented yet !"); 
     705                                        } // switch 
     706                                } // try 
     707 
     708                                catch (CNetCdfException& e) 
     709                                { 
     710                                        StdString msg("On writing the domain : "); 
     711                                        msg.append(domid); msg.append("\n"); 
     712                                        msg.append("In the context : "); 
     713                                        msg.append(context->getId()); msg.append("\n"); 
     714                                        msg.append(e.what()); 
     715                                        ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg); 
     716                                } 
     717 
     718        domain->addRelFile(this->filename); 
     719        } 
     720 
     721          //-------------------------------------------------------------- 
     722 
     723          void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain) 
    436724      { 
    437725         CContext* context = CContext::getCurrent() ; 
     
    481769                   if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); 
    482770                 } 
    483  
    484771                 dim0.clear(); 
    485772                 if (domain->hasBounds) 
     
    10271314                 break ; 
    10281315               case CDomain::type_attr::unstructured: 
     1316               { 
     1317                                   if (SuperClassWriter::useCFConvention) 
     1318                                   { 
     1319                                                dimXid     = StdString("cell").append(appendDomId); 
     1320                                                dimIdList.push_back(dimXid); 
     1321                                                dimCoordList.push_back(StdString("lon").append(appendDomId)); 
     1322                                                dimCoordList.push_back(StdString("lat").append(appendDomId)); 
     1323                                        } 
     1324                                   else 
     1325                                   { 
     1326                                                StdString domainName = domain->name; 
     1327                                                if (domain->nvertex == 1) 
     1328                                                { 
     1329                                                        dimXid     = "n" + domainName + "_node"; 
     1330                                                        dimIdList.push_back(dimXid); 
     1331                                                        dimCoordList.push_back(StdString(domainName + "_node_x")); 
     1332                                                        dimCoordList.push_back(StdString(domainName + "_node_y")); 
     1333                                                } 
     1334                                                else if (domain->nvertex == 2) 
     1335                                                { 
     1336                                                        dimXid     = "n" + domainName + "_edge"; 
     1337                                                        dimIdList.push_back(dimXid); 
     1338                                                        dimCoordList.push_back(StdString(domainName + "_edge_x")); 
     1339                                                        dimCoordList.push_back(StdString(domainName + "_edge_y")); 
     1340                                                } 
     1341                                                else 
     1342                                                { 
     1343                                                        dimXid     = "n" + domainName + "_face"; 
     1344                                                        dimIdList.push_back(dimXid); 
     1345                                                        dimCoordList.push_back(StdString(domainName + "_face_x")); 
     1346                                                        dimCoordList.push_back(StdString(domainName + "_face_y")); 
     1347                                                } 
     1348                                        }  // ugrid convention 
     1349                                }  // case unstructured domain 
     1350             } 
     1351 
     1352             if (domain->hasArea) 
     1353             { 
     1354               hasArea = true; 
     1355               cellMeasures += " area" + appendDomId; 
     1356             } 
     1357             ++idxDomain; 
     1358           } 
     1359           else 
     1360           { 
     1361             CAxis* axis = CAxis::get(axisList[idxAxis]); 
     1362             StdString axisId = axis->getAxisOutputName(); 
     1363 
     1364             if (compressedOutput && axis->isCompressible()) 
     1365             { 
     1366               dimIdList.push_back(axisId + "_points"); 
     1367               field->setUseCompressedOutput(); 
     1368             } 
     1369             else 
     1370               dimIdList.push_back(axisId); 
     1371 
     1372             dimCoordList.push_back(axisId); 
     1373             ++idxAxis; 
     1374           } 
     1375         } 
     1376 
     1377/* 
     1378         StdString lonid_loc = (server->intraCommSize > 1) 
     1379                             ? StdString("lon").append(appendDomid).append("_local") 
     1380                             : lonid; 
     1381         StdString latid_loc = (server->intraCommSize > 1) 
     1382                             ? StdString("lat").append(appendDomid).append("_local") 
     1383                             : latid; 
     1384*/ 
     1385         StdString fieldid = field->getFieldOutputName(); 
     1386 
     1387//         unsigned int ssize = domain->zoom_ni_loc.getValue() * domain->zoom_nj_loc.getValue(); 
     1388//         bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize); 
     1389//          bool isCurvilinear = domain->isCurvilinear ; 
     1390 
     1391         nc_type type ; 
     1392         if (field->prec.isEmpty()) type =  NC_FLOAT ; 
     1393         else 
     1394         { 
     1395           if (field->prec==2) type = NC_SHORT ; 
     1396           else if (field->prec==4)  type =  NC_FLOAT ; 
     1397           else if (field->prec==8)   type =  NC_DOUBLE ; 
     1398         } 
     1399 
     1400         bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once); 
     1401 
     1402         if (wtime) 
     1403         { 
     1404 
     1405            //StdOStringStream oss; 
     1406           // oss << "time_" << field->operation.getValue() 
     1407           //     << "_" << field->getRelFile()->output_freq.getValue(); 
     1408          //oss 
     1409            if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant")); 
     1410            else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered")); 
     1411            dims.push_back(timeid); 
     1412         } 
     1413 
     1414         if (compressedOutput && grid->isCompressible()) 
     1415         { 
     1416           dims.push_back(grid->getId() + "_points"); 
     1417           field->setUseCompressedOutput(); 
     1418         } 
     1419         else 
     1420         { 
     1421           while (!dimIdList.empty()) 
     1422           { 
     1423             dims.push_back(dimIdList.back()); 
     1424             dimIdList.pop_back(); 
     1425           } 
     1426         } 
     1427 
     1428         while (!dimCoordList.empty()) 
     1429         { 
     1430           coodinates.push_back(dimCoordList.back()); 
     1431           dimCoordList.pop_back(); 
     1432         } 
     1433 
     1434         try 
     1435         { 
     1436           SuperClassWriter::addVariable(fieldid, type, dims); 
     1437 
     1438           if (!field->standard_name.isEmpty()) 
     1439              SuperClassWriter::addAttribute 
     1440                 ("standard_name",  field->standard_name.getValue(), &fieldid); 
     1441 
     1442           if (!field->long_name.isEmpty()) 
     1443              SuperClassWriter::addAttribute 
     1444                 ("long_name", field->long_name.getValue(), &fieldid); 
     1445 
     1446           if (!field->unit.isEmpty()) 
     1447              SuperClassWriter::addAttribute 
     1448                 ("units", field->unit.getValue(), &fieldid); 
     1449 
     1450            if (!field->valid_min.isEmpty()) 
     1451              SuperClassWriter::addAttribute 
     1452                 ("valid_min", field->valid_min.getValue(), &fieldid); 
     1453 
     1454           if (!field->valid_max.isEmpty()) 
     1455              SuperClassWriter::addAttribute 
     1456                 ("valid_max", field->valid_max.getValue(), &fieldid); 
     1457 
     1458            if (!field->scale_factor.isEmpty()) 
     1459              SuperClassWriter::addAttribute 
     1460                 ("scale_factor", field->scale_factor.getValue(), &fieldid); 
     1461 
     1462             if (!field->add_offset.isEmpty()) 
     1463              SuperClassWriter::addAttribute 
     1464                 ("add_offset", field->add_offset.getValue(), &fieldid); 
     1465 
     1466           SuperClassWriter::addAttribute 
     1467                 ("online_operation", field->operation.getValue(), &fieldid); 
     1468 
     1469          // write child variables as attributes 
     1470 
     1471 
     1472           vector<CVariable*> listVars = field->getAllVariables() ; 
     1473           for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ; 
     1474 
     1475 
     1476           if (wtime) 
     1477           { 
     1478              CDuration freqOp = field->freq_op.getValue(); 
     1479              freqOp.solveTimeStep(*context->calendar); 
     1480              StdString freqOpStr = freqOp.toStringUDUnits(); 
     1481              SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid); 
     1482 
     1483              CDuration freqOut = field->getRelFile()->output_freq.getValue(); 
     1484              freqOut.solveTimeStep(*context->calendar); 
     1485              SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid); 
     1486 
     1487              StdString cellMethods = "time: "; 
     1488              if (field->operation.getValue() == "instant") cellMethods += "point"; 
     1489              else if (field->operation.getValue() == "average") cellMethods += "mean"; 
     1490              else if (field->operation.getValue() == "accumulate") cellMethods += "sum"; 
     1491              else cellMethods += field->operation; 
     1492              if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar)) 
     1493                cellMethods += " (interval: " + freqOpStr + ")"; 
     1494              SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid); 
     1495           } 
     1496 
     1497           if (hasArea) 
     1498             SuperClassWriter::addAttribute("cell_measures", cellMeasures, &fieldid); 
     1499 
     1500           if (!field->default_value.isEmpty()) 
     1501           { 
     1502              double default_value = field->default_value.getValue(); 
     1503              float fdefault_value = (float)default_value; 
     1504              if (type == NC_DOUBLE) 
     1505                 SuperClassWriter::setDefaultValue(fieldid, &default_value); 
     1506              else 
     1507                 SuperClassWriter::setDefaultValue(fieldid, &fdefault_value); 
     1508           } 
     1509           else 
     1510              SuperClassWriter::setDefaultValue(fieldid, (double*)NULL); 
     1511 
     1512            if (field->compression_level.isEmpty()) 
     1513              field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level; 
     1514            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); 
     1515 
     1516           {  // Ecriture des coordonnes 
     1517 
     1518              StdString coordstr; //boost::algorithm::join(coodinates, " ") 
     1519              std::vector<StdString>::iterator 
     1520                 itc = coodinates.begin(), endc = coodinates.end(); 
     1521 
     1522              for (; itc!= endc; itc++) 
     1523              { 
     1524                 StdString & coord = *itc; 
     1525                 if (itc+1 != endc) 
     1526                       coordstr.append(coord).append(" "); 
     1527                 else  coordstr.append(coord); 
     1528              } 
     1529 
     1530              SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid); 
     1531 
     1532           } 
     1533         } 
     1534         catch (CNetCdfException& e) 
     1535         { 
     1536           StdString msg("On writing field : "); 
     1537           msg.append(fieldid); msg.append("\n"); 
     1538           msg.append("In the context : "); 
     1539           msg.append(context->getId()); msg.append("\n"); 
     1540           msg.append(e.what()); 
     1541           ERROR("CNc4DataOutput::writeField_(CField* field)", << msg); 
     1542         } 
     1543      } 
     1544 
     1545      //-------------------------------------------------------------- 
     1546/* 
     1547      void CNc4DataOutput::writeField_(CField* field) 
     1548      { 
     1549         CContext* context = CContext::getCurrent() ; 
     1550         CContextServer* server=context->server ; 
     1551 
     1552         std::vector<StdString> dims, coodinates; 
     1553         CGrid* grid = field->grid; 
     1554         if (!grid->doGridHaveDataToWrite()) 
     1555          if (SuperClass::type==MULTI_FILE) return ; 
     1556 
     1557         CArray<bool,1> axisDomainOrder = grid->axis_domain_order; 
     1558         int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0; 
     1559         std::vector<StdString> domainList = grid->getDomainList(); 
     1560         std::vector<StdString> axisList   = grid->getAxisList(); 
     1561 
     1562         StdString timeid  = getTimeCounterName(); 
     1563         StdString dimXid,dimYid; 
     1564         std::deque<StdString> dimIdList, dimCoordList; 
     1565         bool hasArea = false; 
     1566         StdString cellMeasures = "area:"; 
     1567         bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output; 
     1568 
     1569         for (int i = 0; i < numElement; ++i) 
     1570         { 
     1571           if (axisDomainOrder(i)) 
     1572           { 
     1573             CDomain* domain = CDomain::get(domainList[idxDomain]); 
     1574             StdString domId = domain->getDomainOutputName(); 
     1575             StdString appendDomId  = singleDomain ? "" : "_" + domId ; 
     1576 
     1577             if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured) 
     1578             { 
     1579               dimIdList.push_back(domId + "_points"); 
     1580               field->setUseCompressedOutput(); 
     1581             } 
     1582 
     1583             switch (domain->type) 
     1584             { 
     1585               case CDomain::type_attr::curvilinear: 
     1586                 if (!compressedOutput || !domain->isCompressible()) 
     1587                 { 
     1588                   dimXid     = StdString("x").append(appendDomId); 
     1589                   dimIdList.push_back(dimXid); 
     1590                   dimYid     = StdString("y").append(appendDomId); 
     1591                   dimIdList.push_back(dimYid); 
     1592                 } 
     1593                 dimCoordList.push_back(StdString("nav_lon").append(appendDomId)); 
     1594                 dimCoordList.push_back(StdString("nav_lat").append(appendDomId)); 
     1595                 break ; 
     1596               case CDomain::type_attr::rectilinear: 
     1597                 if (!compressedOutput || !domain->isCompressible()) 
     1598                 { 
     1599                   dimXid     = StdString("lon").append(appendDomId); 
     1600                   dimIdList.push_back(dimXid); 
     1601                   dimYid     = StdString("lat").append(appendDomId); 
     1602                   dimIdList.push_back(dimYid); 
     1603                 } 
     1604                 break ; 
     1605               case CDomain::type_attr::unstructured: 
    10291606                 dimXid     = StdString("cell").append(appendDomId); 
    10301607                 dimIdList.push_back(dimXid); 
     
    10581635         } 
    10591636 
    1060 /* 
    1061          StdString lonid_loc = (server->intraCommSize > 1) 
    1062                              ? StdString("lon").append(appendDomid).append("_local") 
    1063                              : lonid; 
    1064          StdString latid_loc = (server->intraCommSize > 1) 
    1065                              ? StdString("lat").append(appendDomid).append("_local") 
    1066                              : latid; 
    1067 */ 
     1637 
     1638//         StdString lonid_loc = (server->intraCommSize > 1) 
     1639//                             ? StdString("lon").append(appendDomid).append("_local") 
     1640//                             : lonid; 
     1641//         StdString latid_loc = (server->intraCommSize > 1) 
     1642//                             ? StdString("lat").append(appendDomid).append("_local") 
     1643//                             : latid; 
     1644 
    10681645         StdString fieldid = field->getFieldOutputName(); 
    10691646 
     
    11971774            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); 
    11981775 
    1199            {  // Ecriture des coordonnées 
     1776           {  // Ecriture des coordonnes 
    12001777 
    12011778              StdString coordstr; //boost::algorithm::join(coodinates, " ") 
     
    12261803      } 
    12271804 
     1805*/ 
    12281806      //-------------------------------------------------------------- 
    12291807 
     
    12391817         try 
    12401818         { 
    1241            this->writeFileAttributes(filename, description, 
    1242                                      StdString("CF-1.5"), 
    1243                                      StdString("An IPSL model"), 
    1244                                      this->getTimeStamp()); 
     1819                   if (SuperClassWriter::useCFConvention) 
     1820             this->writeFileAttributes(filename, description, 
     1821                                       StdString("CF-1.5"), 
     1822                                       StdString("An IPSL model"), 
     1823                                       this->getTimeStamp()); 
     1824           else 
     1825             this->writeFileAttributes(filename, description, 
     1826                                       StdString("UGRID"), 
     1827                                       StdString("An IPSL model"), 
     1828                                       this->getTimeStamp()); 
     1829 
    12451830 
    12461831           if (!appendMode) 
  • XIOS/trunk/src/io/nc4_data_output.hpp

    r802 r878  
    2626            CNc4DataOutput 
    2727               (const StdString & filename, bool exist, bool useClassicFormat, 
     28                bool useCFConvention, 
    2829                MPI_Comm comm_file, bool multifile, bool isCollective = true, 
    2930                const StdString& timeCounterName = "time_counter"); 
     
    3132            CNc4DataOutput(const CNc4DataOutput & dataoutput);       // Not implemented. 
    3233            CNc4DataOutput(const CNc4DataOutput * const dataoutput); // Not implemented. 
    33  
     34             
    3435            /// Accesseur /// 
    3536            const StdString & getFileName(void) const; 
     
    3738            /// Destructeur /// 
    3839            virtual ~CNc4DataOutput(void); 
     40             
    3941            bool singleDomain ; 
    4042            bool isCollective ; 
     43                       
     44            CFile* file; 
     45                       
    4146         protected : 
    4247 
     
    5863         protected : 
    5964            void writeUnstructuredDomain (CDomain* domain); 
     65            void writeUnstructuredDomainUgrid (CDomain* domain); 
    6066            void writeLocalAttributes(int ibegin, int ni, int jbegin, int nj, StdString domid); 
    6167            void writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid, 
  • XIOS/trunk/src/io/onetcdf4.cpp

    r857 r878  
    1313 
    1414      CONetCDF4::CONetCDF4(const StdString& filename, bool append, bool useClassicFormat, 
     15                                                        bool useCFConvention, 
    1516                           const MPI_Comm* comm, bool multifile, const StdString& timeCounterName) 
    1617        : path() 
    1718        , wmpi(false) 
    1819        , useClassicFormat(useClassicFormat) 
    19       { 
    20          this->initialize(filename, append, useClassicFormat, comm, multifile, timeCounterName); 
     20        , useCFConvention(useCFConvention) 
     21      { 
     22         this->initialize(filename, append, useClassicFormat, useCFConvention, comm, multifile, timeCounterName); 
    2123      } 
    2224 
     
    2931      ///-------------------------------------------------------------- 
    3032 
    31       void CONetCDF4::initialize(const StdString& filename, bool append, bool useClassicFormat, 
     33      void CONetCDF4::initialize(const StdString& filename, bool append, bool useClassicFormat, bool useCFConvention,  
    3234                                 const MPI_Comm* comm, bool multifile, const StdString& timeCounterName) 
    3335      { 
    3436         this->useClassicFormat = useClassicFormat; 
     37         this->useCFConvention = useCFConvention; 
    3538 
    3639         int mode = useClassicFormat ? 0 : NC_NETCDF4; 
     
    284287         std::vector<StdSize> dimsizes; 
    285288         int dimSize = dim.size(); 
     289          
    286290         StdSize size; 
    287291         StdSize totalSize; 
     
    292296         std::vector<StdString>::const_iterator it = dim.begin(), end = dim.end(); 
    293297 
    294          for (; it != end; it++) 
     298         for (int idx = 0; it != end; it++, ++idx) 
    295299         { 
    296300            const StdString& dimid = *it; 
     
    314318              if (totalSize >= maxSize) *it = 1; 
    315319            } 
    316  
    317320            int storageType = (0 == dimSize) ? NC_CONTIGUOUS : NC_CHUNKED; 
    318321            CNetCdfInterface::defVarChunking(grpid, varid, storageType, &dimsizes[0]); 
     
    570573      } 
    571574 
     575      bool CONetCDF4::dimExist(const StdString& dimname) 
     576      { 
     577         int grpid = this->getCurrentGroup(); 
     578         return CNetCdfInterface::isDimExisted(grpid, dimname); 
     579      } 
     580 
    572581      void CONetCDF4::sync(void) 
    573582      { 
  • XIOS/trunk/src/io/onetcdf4.hpp

    r802 r878  
    2727            /// Constructeurs /// 
    2828            CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false, 
     29                          bool useCFConvention = true, 
    2930                      const MPI_Comm* comm = NULL, bool multifile = true, 
    3031                      const StdString& timeCounterName = "time_counter"); 
     
    3536 
    3637            /// Initialisation /// 
    37             void initialize(const StdString& filename, bool append, bool useClassicFormat, 
     38            void initialize(const StdString& filename, bool append, bool useClassicFormat, bool useCFConvention, 
    3839                            const MPI_Comm* comm, bool multifile, const StdString& timeCounterName); 
    3940            void close(void); 
     
    99100 
    100101            bool varExist(const StdString& varname); 
     102            bool dimExist(const StdString& dimname); 
    101103 
    102104            bool useClassicFormat; //!< If true, NetCDF4 will use the classic NetCDF3 format 
     105            bool useCFConvention;  //!< If true data is written in the CF convention otherwise in UGRID 
    103106 
    104107      //---------------------------------------------------------------- 
  • XIOS/trunk/src/node/domain.cpp

    r847 r878  
    3535      , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client() 
    3636      , isRedistributed_(false) 
    37    { /* Ne rien faire de plus */ } 
     37   { 
     38           mesh = new CMesh(); 
     39        } 
    3840 
    3941   CDomain::CDomain(const StdString & id) 
     
    4446      , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client() 
    4547      , isRedistributed_(false) 
    46    { /* Ne rien faire de plus */ } 
     48   { 
     49           mesh = new CMesh(); 
     50        } 
    4751 
    4852   CDomain::~CDomain(void) 
    4953   { 
     54           delete mesh; 
    5055   } 
    5156 
     
    7378   } 
    7479 
    75    //---------------------------------------------------------------- 
    76  
     80   
    7781   const std::vector<int>& CDomain::getIndexesToWrite(void) const 
    7882   { 
     
    202206   } 
    203207 
    204    //---------------------------------------------------------------- 
    205  
    206208   void CDomain::addRelFile(const StdString & filename) 
    207209   { 
    208210      this->relFiles.insert(filename); 
    209211   } 
    210  
     212   
    211213   void CDomain::addRelFileCompressed(const StdString& filename) 
    212214   { 
    213215      this->relFilesCompressed.insert(filename); 
    214216   } 
    215  
    216217 
    217218   StdString CDomain::GetName(void)   { return (StdString("domain")); } 
  • XIOS/trunk/src/node/domain.hpp

    r836 r878  
    1717#include "transformation_enum.hpp" 
    1818 
     19#include "mesh.hpp" 
     20 
    1921namespace xios { 
    2022 
     
    2426   class CDomainAttributes; 
    2527   class CDomain; 
     28   class CFile; 
    2629 
    2730   ///-------------------------------------------------------------- 
     
    3942      , public CDomainAttributes 
    4043   { 
     44 
    4145         enum EEventId 
    4246         { 
     
    6165 
    6266         static CDomain* createDomain(); 
    63  
     67          
     68         CMesh* mesh; 
     69         
    6470         virtual void parse(xml::CXMLNode & node); 
    6571 
     
    217223} // namespace xios 
    218224 
    219 #endif // __XIOS_CDomain__ 
     225#endif //__XIOS_CDomain__ 
  • XIOS/trunk/src/node/file.cpp

    r876 r878  
    1919namespace xios { 
    2020 
    21    /// ////////////////////// Définitions ////////////////////// /// 
     21   /// ////////////////////// Dfinitions ////////////////////// /// 
    2222 
    2323   CFile::CFile(void) 
     
    140140      for ( it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ ) 
    141141      { 
    142          if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... 
     142         if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est dfini ... 
    143143         { 
    144144            if (! (*it)->enabled.getValue()) continue; 
    145145//            { it--; this->enabledFields.erase(it+1); continue; } 
    146146         } 
    147          else // Si l'attribut 'enabled' n'est pas défini ... 
     147         else // Si l'attribut 'enabled' n'est pas dfini ... 
    148148         { 
    149149            if (!default_enabled) continue; 
     
    151151         } 
    152152 
    153          if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... 
     153         if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est dfini ... 
    154154         { 
    155155            if ((*it)->level.getValue() > _outputlevel) continue; 
    156156//            { it--; this->enabledFields.erase(it+1); continue; } 
    157157         } 
    158          else // Si l'attribut 'level' n'est pas défini ... 
     158         else // Si l'attribut 'level' n'est pas dfini ... 
    159159         { 
    160160            if (default_level > _outputlevel) continue; 
     
    168168         // Le champ est finalement actif, on y ajoute sa propre reference. 
    169169//         (*it)->refObject.push_back(*it); 
    170          // Le champ est finalement actif, on y ajoute la référence au champ de base. 
     170         // Le champ est finalement actif, on y ajoute la rfrence au champ de base. 
    171171         (*it)->setRelFile(CFile::get(this)); 
    172172      } 
     
    431431 
    432432         bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic; 
     433         bool useCFConvention = convention.isEmpty() || convention == convention_attr::CF; 
    433434 
    434435         bool multifile = true; 
     
    470471         if (isOpen) data_out->closeFile(); 
    471472 
    472         data_out = shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), append, useClassicFormat, 
     473        data_out = shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), append, useClassicFormat, useCFConvention, 
    473474                                                              fileComm, multifile, isCollective, time_counter_name)); 
    474475        isOpen = true; 
     
    770771   void CFile::solveFieldRefInheritance(bool apply) 
    771772   { 
    772       // Résolution des héritages par référence de chacun des champs contenus dans le fichier. 
     773      // Rsolution des hritages par rfrence de chacun des champs contenus dans le fichier. 
    773774      std::vector<CField*> allF = this->getAllFields(); 
    774775      for (unsigned int i = 0; i < allF.size(); i++) 
  • XIOS/trunk/src/node/file.hpp

    r823 r878  
    1212#include "attribute_enum_impl.hpp" 
    1313#include "mpi.hpp" 
    14  
    15  
    1614 
    1715namespace xios { 
Note: See TracChangeset for help on using the changeset viewer.