Changeset 2600 for XIOS3/trunk/src/io/nc4_data_output.cpp
- Timestamp:
- 11/20/23 14:30:12 (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.