Changeset 2598 for XIOS3/branches/xios-3.0-beta/src/io/nc4_data_output.cpp
- Timestamp:
- 11/20/23 13:05:46 (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.