Changeset 2600
- Timestamp:
- 11/20/23 14:30:12 (14 months ago)
- Location:
- XIOS3/trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS3/trunk/src/config/field_attribute.conf
r2529 r2600 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/trunk/src/io/nc4_data_output.cpp
r2577 r2600 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 { … … 2269 2276 { 2270 2277 CTimer::get("Files : writing data").resume(); 2271 SuperClassWriter::writeData(data, fieldid, isCollective, nstep - 1);2278 writeAndConvertData(field, data, nstep - 1); 2272 2279 CTimer::get("Files : writing data").suspend(); 2273 2280 if (wtime) … … 2433 2440 2434 2441 CTimer::get("Files : writing data").resume(); 2435 SuperClassWriter::writeData(data, fieldid, isCollective, nstep - 1, &start, &count);2442 writeAndConvertData(field, data, nstep - 1, &start, &count); 2436 2443 CTimer::get("Files : writing data").suspend(); 2437 2444 … … 2467 2474 ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); 2468 2475 } 2476 } 2477 2478 void CNc4DataOutput::writeAndConvertData(CField* field, const CArray<double,1>& data, StdSize record, const std::vector<StdSize> *start, const std::vector<StdSize> *count) 2479 { 2480 StdString fieldid = field->getFieldOutputName(); 2481 nc_type type ; 2482 if (field->prec.isEmpty()) type = NC_FLOAT ; 2483 else 2484 { 2485 if (field->prec==2) type = NC_SHORT ; 2486 else if (field->prec==4) type = NC_FLOAT ; 2487 else if (field->prec==8) type = NC_DOUBLE ; 2488 } 2489 2490 bool conversionByNetCDF = true; // default : conversion operated by NetCDF for now (legacy behaviour) 2491 if (!field->conversion_by_NetCDF.isEmpty()) 2492 { 2493 // use conversion_by_NetCDF = ".false." to bypass NetCDF conversion 2494 // poor performances from NC_DOUBLE to NC_FLOAT with isgreater/isless in recent NetCDF available at TGCC 2495 conversionByNetCDF = field->conversion_by_NetCDF; 2496 } 2497 if ( ( type == NC_DOUBLE ) || ( conversionByNetCDF ) ) 2498 { 2499 SuperClassWriter::writeData(data, fieldid, isCollective, record, start, count); 2500 } 2501 else if ( type == NC_FLOAT ) 2502 { 2503 CArray<float,1> f_data; 2504 f_data.resize( data.numElements() ); 2505 for (int i = 0; i < data.numElements(); i++) 2506 { 2507 if (data(i) <= X_FLOAT_MAX || data(i) >= X_FLOAT_MIN) 2508 f_data(i) = data(i); 2509 else if (data(i) > X_FLOAT_MAX) 2510 f_data(i) = X_FLOAT_MAX; 2511 else if (data(i) < X_FLOAT_MIN) 2512 f_data(i) = X_FLOAT_MIN; 2513 } 2514 SuperClassWriter::writeData(f_data, fieldid, isCollective, record, start, count); 2515 } 2516 else if ( type == NC_SHORT ) 2517 { 2518 CArray<short,1> s_data; 2519 s_data.resize( data.numElements() ); 2520 for (int i = 0; i < data.numElements(); i++) 2521 { 2522 if (data(i) <= X_SHORT_MAX || data(i) >= X_SHORT_MIN) 2523 s_data(i) = data(i); 2524 else if (data(i) > X_SHORT_MAX) 2525 s_data(i) = X_SHORT_MAX; 2526 else if (data(i) < X_SHORT_MIN) 2527 s_data(i) = X_SHORT_MIN; 2528 } 2529 SuperClassWriter::writeData(s_data, fieldid, isCollective, record, start, count); 2530 } 2531 else 2532 { 2533 ERROR("CNc4DataOutput::writeAndConvertData(...)", << "Type conversion not managed for " << fieldid ); 2534 } 2535 2469 2536 } 2470 2537 -
XIOS3/trunk/src/io/nc4_data_output.hpp
r2389 r2600 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/trunk/src/io/netCdfInterface.cpp
r2532 r2600 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/trunk/src/io/netCdfInterface_decl.cpp
r1957 r2600 34 34 macroPutVar(float) 35 35 macroPutVar(int) 36 macroPutVar(short) 36 37 macroPutVar(size_t) 37 38 macroPutVar(char) -
XIOS3/trunk/src/io/onetcdf4.cpp
r2579 r2600 735 735 void CONetCDF4::writeData_(int grpid, int varid, 736 736 const std::vector<StdSize>& sstart, 737 const std::vector<StdSize>& scount, const short* data) 738 { 739 CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 740 } 741 742 template <> 743 void CONetCDF4::writeData_(int grpid, int varid, 744 const std::vector<StdSize>& sstart, 737 745 const std::vector<StdSize>& scount, const int* data) 738 746 { -
XIOS3/trunk/src/io/onetcdf4_decl.cpp
r1957 r2600 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.