Changeset 2598
- Timestamp:
- 11/20/23 13:05:46 (14 months ago)
- Location:
- XIOS3/branches/xios-3.0-beta/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS3/branches/xios-3.0-beta/src/config/field_attribute.conf
r2530 r2598 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, false) 16 17 -
XIOS3/branches/xios-3.0-beta/src/io/nc4_data_output.cpp
r2530 r2598 12 12 #include "timer.hpp" 13 13 #include "uuid.hpp" 14 15 #include <limits.h> 16 #define X_FLOAT_MAX FLT_MAX 17 #define X_FLOAT_MIN FLT_MIN 18 #define X_SHORT_MAX SHRT_MAX 19 #define X_SHORT_MIN SHRT_MIN 20 14 21 namespace xios 15 22 { … … 2265 2272 { 2266 2273 CTimer::get("Files : writing data").resume(); 2267 SuperClassWriter::writeData(data, fieldid, isCollective, nstep - 1);2274 writeAndConvertData(field, data, nstep - 1); 2268 2275 CTimer::get("Files : writing data").suspend(); 2269 2276 if (wtime) … … 2429 2436 2430 2437 CTimer::get("Files : writing data").resume(); 2431 SuperClassWriter::writeData(data, fieldid, isCollective, nstep - 1, &start, &count);2438 writeAndConvertData(field, data, nstep - 1, &start, &count); 2432 2439 CTimer::get("Files : writing data").suspend(); 2433 2440 … … 2463 2470 ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); 2464 2471 } 2472 } 2473 2474 void CNc4DataOutput::writeAndConvertData(CField* field, const CArray<double,1>& data, StdSize record, const std::vector<StdSize> *start, const std::vector<StdSize> *count) 2475 { 2476 StdString fieldid = field->getFieldOutputName(); 2477 nc_type type ; 2478 if (field->prec.isEmpty()) type = NC_FLOAT ; 2479 else 2480 { 2481 if (field->prec==2) type = NC_SHORT ; 2482 else if (field->prec==4) type = NC_FLOAT ; 2483 else if (field->prec==8) type = NC_DOUBLE ; 2484 } 2485 2486 bool conversionByNetCDF = true; // default : conversion operated by NetCDF for now (legacy behaviour) 2487 if (!field->conversion_by_NetCDF.isEmpty()) 2488 { 2489 // use conversion_by_NetCDF = ".false." to bypass NetCDF conversion 2490 // poor performances from NC_DOUBLE to NC_FLOAT with isgreater/isless in recent NetCDF available at TGCC 2491 conversionByNetCDF = field->conversion_by_NetCDF; 2492 } 2493 if ( ( type == NC_DOUBLE ) || ( conversionByNetCDF ) ) 2494 { 2495 SuperClassWriter::writeData(data, fieldid, isCollective, record, start, count); 2496 } 2497 else if ( type == NC_FLOAT ) 2498 { 2499 CArray<float,1> f_data; 2500 f_data.resize( data.numElements() ); 2501 for (int i = 0; i < data.numElements(); i++) 2502 { 2503 if (data(i) <= X_FLOAT_MAX || data(i) >= X_FLOAT_MIN) 2504 f_data(i) = data(i); 2505 else if (data(i) > X_FLOAT_MAX) 2506 f_data(i) = X_FLOAT_MAX; 2507 else if (data(i) < X_FLOAT_MIN) 2508 f_data(i) = X_FLOAT_MIN; 2509 } 2510 SuperClassWriter::writeData(f_data, fieldid, isCollective, record, start, count); 2511 } 2512 else if ( type == NC_SHORT ) 2513 { 2514 CArray<short,1> s_data; 2515 s_data.resize( data.numElements() ); 2516 for (int i = 0; i < data.numElements(); i++) 2517 { 2518 if (data(i) <= X_SHORT_MAX || data(i) >= X_SHORT_MIN) 2519 s_data(i) = data(i); 2520 else if (data(i) > X_SHORT_MAX) 2521 s_data(i) = X_SHORT_MAX; 2522 else if (data(i) < X_SHORT_MIN) 2523 s_data(i) = X_SHORT_MIN; 2524 } 2525 SuperClassWriter::writeData(s_data, fieldid, isCollective, record, start, count); 2526 } 2527 else 2528 { 2529 ERROR("CNc4DataOutput::writeAndConvertData(...)", << "Type conversion not managed for " << fieldid ); 2530 } 2531 2465 2532 } 2466 2533 -
XIOS3/branches/xios-3.0-beta/src/io/nc4_data_output.hpp
r2389 r2598 57 57 virtual void writeAttribute_(CVariable* var, const string& fieldId); 58 58 virtual int writeFieldData_(CField* field, const CArray<double,1>& data, const CDate& lastWrite, const CDate& currentWrite, int nstep); 59 void writeAndConvertData(CField* field, const CArray<double,1>& data, StdSize record, const std::vector<StdSize> *start = NULL, const std::vector<StdSize> *count = NULL); 59 60 virtual void writeFile_ (CFile* file); 60 61 virtual void closeFile_ (void); -
XIOS3/branches/xios-3.0-beta/src/io/netCdfInterface.cpp
r2531 r2598 1054 1054 1055 1055 template<> 1056 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, short* data) 1057 { 1058 return nc_get_vara_short(ncid, varid, start, count, data); 1059 } 1060 1061 template<> 1056 1062 int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, size_t* data) 1057 1063 { … … 1082 1088 { 1083 1089 return nc_put_vara_int(ncid, varid, start, count, data); 1090 } 1091 1092 template<> 1093 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const short* data) 1094 { 1095 return nc_put_vara_short(ncid, varid, start, count, data); 1084 1096 } 1085 1097 -
XIOS3/branches/xios-3.0-beta/src/io/netCdfInterface_decl.cpp
r1957 r2598 34 34 macroPutVar(float) 35 35 macroPutVar(int) 36 macroPutVar(short) 36 37 macroPutVar(size_t) 37 38 macroPutVar(char) -
XIOS3/branches/xios-3.0-beta/src/io/onetcdf4.cpp
r2531 r2598 735 735 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 736 736 } 737 738 template <> 739 void CONetCDF4::writeData_(int grpid, int varid, 740 const std::vector<StdSize>& sstart, 741 const std::vector<StdSize>& scount, const short* data) 742 { 743 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 744 } 737 745 //--------------------------------------------------------------- 738 746 -
XIOS3/branches/xios-3.0-beta/src/io/onetcdf4_decl.cpp
r1957 r2598 16 16 macro(double, 2) 17 17 macro(double, 3) 18 macro(float, 1) 19 macro(short, 1) 18 20 macro(StdString, 1) 19 21
Note: See TracChangeset
for help on using the changeset viewer.