Changeset 2599
- Timestamp:
- 11/20/23 14:07:25 (14 months ago)
- Location:
- XIOS2/trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS2/trunk/src/config/field_attribute.conf
r1704 r2599 13 13 DECLARE_ATTRIBUTE(int, level) 14 14 DECLARE_ATTRIBUTE(int, prec) 15 DECLARE_ATTRIBUTE(bool, conversion_by_NetCDF) 15 16 DECLARE_ATTRIBUTE(StdString, expr) 16 17 -
XIOS2/trunk/src/io/nc4_data_output.cpp
r2515 r2599 13 13 #include "uuid.hpp" 14 14 #include "mesh_values.hpp" 15 16 #include <limits.h> 17 #define X_FLOAT_MAX FLT_MAX 18 #define X_FLOAT_MIN FLT_MIN 19 #define X_SHORT_MAX SHRT_MAX 20 #define X_SHORT_MIN SHRT_MIN 21 15 22 namespace xios 16 23 { … … 2515 2522 { 2516 2523 CTimer::get("Files : writing data").resume(); 2517 SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1);2524 writeAndConvertData(field, fieldData, field->getNStep() - 1); 2518 2525 CTimer::get("Files : writing data").suspend(); 2519 2526 if (wtime) … … 2655 2662 2656 2663 CTimer::get("Files : writing data").resume(); 2657 SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count);2664 writeAndConvertData(field, fieldData, field->getNStep() - 1, &start, &count); 2658 2665 CTimer::get("Files : writing data").suspend(); 2659 2666 … … 2688 2695 ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); 2689 2696 } 2697 } 2698 2699 void CNc4DataOutput::writeAndConvertData(CField* field, const CArray<double,1>& data, StdSize record, const std::vector<StdSize> *start, const std::vector<StdSize> *count) 2700 { 2701 StdString fieldid = field->getFieldOutputName(); 2702 nc_type type ; 2703 if (field->prec.isEmpty()) type = NC_FLOAT ; 2704 else 2705 { 2706 if (field->prec==2) type = NC_SHORT ; 2707 else if (field->prec==4) type = NC_FLOAT ; 2708 else if (field->prec==8) type = NC_DOUBLE ; 2709 } 2710 2711 bool conversionByNetCDF = true; // default : conversion operated by NetCDF for now (legacy behaviour) 2712 if (!field->conversion_by_NetCDF.isEmpty()) 2713 { 2714 // use conversion_by_NetCDF = ".false." to bypass NetCDF conversion 2715 // poor performances from NC_DOUBLE to NC_FLOAT with isgreater/isless in recent NetCDF available at TGCC 2716 conversionByNetCDF = field->conversion_by_NetCDF; 2717 } 2718 if ( ( type == NC_DOUBLE ) || ( conversionByNetCDF ) ) 2719 { 2720 SuperClassWriter::writeData(data, fieldid, isCollective, record, start, count); 2721 } 2722 else if ( type == NC_FLOAT ) 2723 { 2724 CArray<float,1> f_data; 2725 f_data.resize( data.numElements() ); 2726 for (int i = 0; i < data.numElements(); i++) 2727 { 2728 if (data(i) <= X_FLOAT_MAX || data(i) >= X_FLOAT_MIN) 2729 f_data(i) = data(i); 2730 else if (data(i) > X_FLOAT_MAX) 2731 f_data(i) = X_FLOAT_MAX; 2732 else if (data(i) < X_FLOAT_MIN) 2733 f_data(i) = X_FLOAT_MIN; 2734 } 2735 SuperClassWriter::writeData(f_data, fieldid, isCollective, record, start, count); 2736 } 2737 else if ( type == NC_SHORT ) 2738 { 2739 CArray<short,1> s_data; 2740 s_data.resize( data.numElements() ); 2741 for (int i = 0; i < data.numElements(); i++) 2742 { 2743 if (data(i) <= X_SHORT_MAX || data(i) >= X_SHORT_MIN) 2744 s_data(i) = data(i); 2745 else if (data(i) > X_SHORT_MAX) 2746 s_data(i) = X_SHORT_MAX; 2747 else if (data(i) < X_SHORT_MIN) 2748 s_data(i) = X_SHORT_MIN; 2749 } 2750 SuperClassWriter::writeData(s_data, fieldid, isCollective, record, start, count); 2751 } 2752 else 2753 { 2754 ERROR("CNc4DataOutput::writeAndConvertData(...)", << "Type conversion not managed for " << fieldid ); 2755 } 2756 2690 2757 } 2691 2758 -
XIOS2/trunk/src/io/nc4_data_output.hpp
r1639 r2599 57 57 virtual void writeAttribute_(CVariable* var, const string& fieldId); 58 58 virtual void writeFieldData_(CField* field); 59 void writeAndConvertData(CField* field, const CArray<double,1>& data, StdSize record, 60 const std::vector<StdSize> *start = NULL, const std::vector<StdSize> *count = NULL); 59 61 virtual void writeFile_ (CFile* file); 60 62 virtual void closeFile_ (void); -
XIOS2/trunk/src/io/netCdfInterface.cpp
r2428 r2599 991 991 992 992 template<> 993 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, short* data) 994 { 995 return nc_get_vara_short(ncid, varid, start, count, data); 996 } 997 998 template<> 993 999 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, char* data) 994 1000 { … … 1013 1019 { 1014 1020 return nc_put_vara_int(ncid, varid, start, count, data); 1021 } 1022 1023 template<> 1024 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const short* data) 1025 { 1026 return nc_put_vara_short(ncid, varid, start, count, data); 1015 1027 } 1016 1028 -
XIOS2/trunk/src/io/netCdfInterface_decl.cpp
r1158 r2599 33 33 macroPutVar(float) 34 34 macroPutVar(int) 35 macroPutVar(short) 35 36 macroPutVar(char) 36 37 -
XIOS2/trunk/src/io/onetcdf4.cpp
r1639 r2599 554 554 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 555 555 } 556 556 557 template <> 558 void CONetCDF4::writeData_(int grpid, int varid, 559 const std::vector<StdSize>& sstart, 560 const std::vector<StdSize>& scount, const short* data) 561 { 562 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 563 } 557 564 //--------------------------------------------------------------- 558 565 -
XIOS2/trunk/src/io/onetcdf4_decl.cpp
r1392 r2599 14 14 macro(double, 2) 15 15 macro(double, 3) 16 macro(float, 1) 17 macro(short, 1) 16 18 macro(StdString, 1) 17 19
Note: See TracChangeset
for help on using the changeset viewer.