Changeset 878
- Timestamp:
- 07/01/16 16:55:33 (8 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/config/file_attribute.conf
r850 r878 13 13 DECLARE_ENUM2(type, one_file, multiple_file) 14 14 DECLARE_ENUM2(format, netcdf4, netcdf4_classic) 15 DECLARE_ENUM2(convention, CF, UGRID) 15 16 DECLARE_ENUM2(par_access, collective, independent) 16 17 DECLARE_ATTRIBUTE(bool, append) … … 25 26 DECLARE_ENUM4(timeseries, none, only, both, exclusive) 26 27 DECLARE_ATTRIBUTE(StdString, ts_prefix) 28 -
XIOS/trunk/src/io/nc4_data_output.cpp
r821 r878 1 2 1 #include "nc4_data_output.hpp" 3 2 … … 15 14 namespace xios 16 15 { 17 /// ////////////////////// D éfinitions ////////////////////// ///16 /// ////////////////////// Dfinitions ////////////////////// /// 18 17 CNc4DataOutput::CNc4DataOutput 19 18 (const StdString & filename, bool exist) … … 22 21 , filename(filename) 23 22 { 24 23 SuperClass::type = MULTI_FILE; 25 24 } 26 25 27 26 CNc4DataOutput::CNc4DataOutput 28 (const StdString & filename, bool exist, bool useClassicFormat, 27 (const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, 29 28 MPI_Comm comm_file,bool multifile, bool isCollective, const StdString& timeCounterName) 30 29 : SuperClass() 31 , SuperClassWriter(filename, exist, useClassicFormat, &comm_file, multifile, timeCounterName)30 , SuperClassWriter(filename, exist, useClassicFormat, useCFConvention, &comm_file, multifile, timeCounterName) 32 31 , comm_file(comm_file) 33 32 , filename(filename) 34 33 , isCollective(isCollective) 35 34 { 36 SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 37 } 38 35 SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 36 } 39 37 40 38 CNc4DataOutput::~CNc4DataOutput(void) 41 39 { /* Ne rien faire de plus */ } 42 40 43 41 ///-------------------------------------------------------------- … … 54 52 if (domain->type == CDomain::type_attr::unstructured) 55 53 { 56 writeUnstructuredDomain(domain) ; 54 if (SuperClassWriter::useCFConvention) 55 writeUnstructuredDomain(domain) ; 56 else 57 writeUnstructuredDomainUgrid(domain) ; 57 58 return ; 58 59 } … … 386 387 } 387 388 388 389 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); 390 391 } 391 392 … … 433 434 } 434 435 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) 436 724 { 437 725 CContext* context = CContext::getCurrent() ; … … 481 769 if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); 482 770 } 483 484 771 dim0.clear(); 485 772 if (domain->hasBounds) … … 1027 1314 break ; 1028 1315 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: 1029 1606 dimXid = StdString("cell").append(appendDomId); 1030 1607 dimIdList.push_back(dimXid); … … 1058 1635 } 1059 1636 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 1068 1645 StdString fieldid = field->getFieldOutputName(); 1069 1646 … … 1197 1774 SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); 1198 1775 1199 { // Ecriture des coordonn ées1776 { // Ecriture des coordonnes 1200 1777 1201 1778 StdString coordstr; //boost::algorithm::join(coodinates, " ") … … 1226 1803 } 1227 1804 1805 */ 1228 1806 //-------------------------------------------------------------- 1229 1807 … … 1239 1817 try 1240 1818 { 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 1245 1830 1246 1831 if (!appendMode) -
XIOS/trunk/src/io/nc4_data_output.hpp
r802 r878 26 26 CNc4DataOutput 27 27 (const StdString & filename, bool exist, bool useClassicFormat, 28 bool useCFConvention, 28 29 MPI_Comm comm_file, bool multifile, bool isCollective = true, 29 30 const StdString& timeCounterName = "time_counter"); … … 31 32 CNc4DataOutput(const CNc4DataOutput & dataoutput); // Not implemented. 32 33 CNc4DataOutput(const CNc4DataOutput * const dataoutput); // Not implemented. 33 34 34 35 /// Accesseur /// 35 36 const StdString & getFileName(void) const; … … 37 38 /// Destructeur /// 38 39 virtual ~CNc4DataOutput(void); 40 39 41 bool singleDomain ; 40 42 bool isCollective ; 43 44 CFile* file; 45 41 46 protected : 42 47 … … 58 63 protected : 59 64 void writeUnstructuredDomain (CDomain* domain); 65 void writeUnstructuredDomainUgrid (CDomain* domain); 60 66 void writeLocalAttributes(int ibegin, int ni, int jbegin, int nj, StdString domid); 61 67 void writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid, -
XIOS/trunk/src/io/onetcdf4.cpp
r857 r878 13 13 14 14 CONetCDF4::CONetCDF4(const StdString& filename, bool append, bool useClassicFormat, 15 bool useCFConvention, 15 16 const MPI_Comm* comm, bool multifile, const StdString& timeCounterName) 16 17 : path() 17 18 , wmpi(false) 18 19 , 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); 21 23 } 22 24 … … 29 31 ///-------------------------------------------------------------- 30 32 31 void CONetCDF4::initialize(const StdString& filename, bool append, bool useClassicFormat, 33 void CONetCDF4::initialize(const StdString& filename, bool append, bool useClassicFormat, bool useCFConvention, 32 34 const MPI_Comm* comm, bool multifile, const StdString& timeCounterName) 33 35 { 34 36 this->useClassicFormat = useClassicFormat; 37 this->useCFConvention = useCFConvention; 35 38 36 39 int mode = useClassicFormat ? 0 : NC_NETCDF4; … … 284 287 std::vector<StdSize> dimsizes; 285 288 int dimSize = dim.size(); 289 286 290 StdSize size; 287 291 StdSize totalSize; … … 292 296 std::vector<StdString>::const_iterator it = dim.begin(), end = dim.end(); 293 297 294 for ( ; it != end; it++)298 for (int idx = 0; it != end; it++, ++idx) 295 299 { 296 300 const StdString& dimid = *it; … … 314 318 if (totalSize >= maxSize) *it = 1; 315 319 } 316 317 320 int storageType = (0 == dimSize) ? NC_CONTIGUOUS : NC_CHUNKED; 318 321 CNetCdfInterface::defVarChunking(grpid, varid, storageType, &dimsizes[0]); … … 570 573 } 571 574 575 bool CONetCDF4::dimExist(const StdString& dimname) 576 { 577 int grpid = this->getCurrentGroup(); 578 return CNetCdfInterface::isDimExisted(grpid, dimname); 579 } 580 572 581 void CONetCDF4::sync(void) 573 582 { -
XIOS/trunk/src/io/onetcdf4.hpp
r802 r878 27 27 /// Constructeurs /// 28 28 CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false, 29 bool useCFConvention = true, 29 30 const MPI_Comm* comm = NULL, bool multifile = true, 30 31 const StdString& timeCounterName = "time_counter"); … … 35 36 36 37 /// Initialisation /// 37 void initialize(const StdString& filename, bool append, bool useClassicFormat, 38 void initialize(const StdString& filename, bool append, bool useClassicFormat, bool useCFConvention, 38 39 const MPI_Comm* comm, bool multifile, const StdString& timeCounterName); 39 40 void close(void); … … 99 100 100 101 bool varExist(const StdString& varname); 102 bool dimExist(const StdString& dimname); 101 103 102 104 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 103 106 104 107 //---------------------------------------------------------------- -
XIOS/trunk/src/node/domain.cpp
r847 r878 35 35 , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client() 36 36 , isRedistributed_(false) 37 { /* Ne rien faire de plus */ } 37 { 38 mesh = new CMesh(); 39 } 38 40 39 41 CDomain::CDomain(const StdString & id) … … 44 46 , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client() 45 47 , isRedistributed_(false) 46 { /* Ne rien faire de plus */ } 48 { 49 mesh = new CMesh(); 50 } 47 51 48 52 CDomain::~CDomain(void) 49 53 { 54 delete mesh; 50 55 } 51 56 … … 73 78 } 74 79 75 //---------------------------------------------------------------- 76 80 77 81 const std::vector<int>& CDomain::getIndexesToWrite(void) const 78 82 { … … 202 206 } 203 207 204 //----------------------------------------------------------------205 206 208 void CDomain::addRelFile(const StdString & filename) 207 209 { 208 210 this->relFiles.insert(filename); 209 211 } 210 212 211 213 void CDomain::addRelFileCompressed(const StdString& filename) 212 214 { 213 215 this->relFilesCompressed.insert(filename); 214 216 } 215 216 217 217 218 StdString CDomain::GetName(void) { return (StdString("domain")); } -
XIOS/trunk/src/node/domain.hpp
r836 r878 17 17 #include "transformation_enum.hpp" 18 18 19 #include "mesh.hpp" 20 19 21 namespace xios { 20 22 … … 24 26 class CDomainAttributes; 25 27 class CDomain; 28 class CFile; 26 29 27 30 ///-------------------------------------------------------------- … … 39 42 , public CDomainAttributes 40 43 { 44 41 45 enum EEventId 42 46 { … … 61 65 62 66 static CDomain* createDomain(); 63 67 68 CMesh* mesh; 69 64 70 virtual void parse(xml::CXMLNode & node); 65 71 … … 217 223 } // namespace xios 218 224 219 #endif // 225 #endif //__XIOS_CDomain__ -
XIOS/trunk/src/node/file.cpp
r876 r878 19 19 namespace xios { 20 20 21 /// ////////////////////// D éfinitions ////////////////////// ///21 /// ////////////////////// Dfinitions ////////////////////// /// 22 22 23 23 CFile::CFile(void) … … 140 140 for ( it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ ) 141 141 { 142 if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est d éfini ...142 if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est dfini ... 143 143 { 144 144 if (! (*it)->enabled.getValue()) continue; 145 145 // { it--; this->enabledFields.erase(it+1); continue; } 146 146 } 147 else // Si l'attribut 'enabled' n'est pas d éfini ...147 else // Si l'attribut 'enabled' n'est pas dfini ... 148 148 { 149 149 if (!default_enabled) continue; … … 151 151 } 152 152 153 if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est d éfini ...153 if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est dfini ... 154 154 { 155 155 if ((*it)->level.getValue() > _outputlevel) continue; 156 156 // { it--; this->enabledFields.erase(it+1); continue; } 157 157 } 158 else // Si l'attribut 'level' n'est pas d éfini ...158 else // Si l'attribut 'level' n'est pas dfini ... 159 159 { 160 160 if (default_level > _outputlevel) continue; … … 168 168 // Le champ est finalement actif, on y ajoute sa propre reference. 169 169 // (*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. 171 171 (*it)->setRelFile(CFile::get(this)); 172 172 } … … 431 431 432 432 bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic; 433 bool useCFConvention = convention.isEmpty() || convention == convention_attr::CF; 433 434 434 435 bool multifile = true; … … 470 471 if (isOpen) data_out->closeFile(); 471 472 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, 473 474 fileComm, multifile, isCollective, time_counter_name)); 474 475 isOpen = true; … … 770 771 void CFile::solveFieldRefInheritance(bool apply) 771 772 { 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. 773 774 std::vector<CField*> allF = this->getAllFields(); 774 775 for (unsigned int i = 0; i < allF.size(); i++) -
XIOS/trunk/src/node/file.hpp
r823 r878 12 12 #include "attribute_enum_impl.hpp" 13 13 #include "mpi.hpp" 14 15 16 14 17 15 namespace xios {
Note: See TracChangeset
for help on using the changeset viewer.