Ignore:
Timestamp:
01/21/14 15:28:59 (10 years ago)
Author:
ymipsl
Message:

Enhancement : Add scale_factor and add_offset attribute to field output
Operation (field-add_offset)/scale_factor would be computed before output write.
If field attribute prec=2 the field would be rounded to nearest integer value and output as short int (2 bytes).

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/output/nc4_data_output.cpp

    r463 r464  
    566566//          bool isCurvilinear = domain->isCurvilinear ;  
    567567           
    568          nc_type type = (!field->prec.isEmpty() && 
    569                         ( field->prec.getValue() == 4)) 
    570                         ? NC_FLOAT : NC_DOUBLE; 
     568         nc_type type ; 
     569         if (field->prec.isEmpty()) type =  NC_FLOAT ; 
     570         else 
     571         { 
     572           if (field->prec==2) type = NC_SHORT ; 
     573           else if (field->prec==4)  type =  NC_FLOAT ; 
     574           else if (field->prec==8)   type =  NC_DOUBLE ;  
     575         } 
     576                      
    571577         bool wtime   = !(!field->operation.isEmpty() && field->foperation->timeType() == func::CFunctor::once); 
    572578                          
     
    628634            SuperClassWriter::addAttribute 
    629635               ("valid_max", field->valid_max.getValue(), &fieldid); 
     636 
     637          if (!field->scale_factor.isEmpty()) 
     638            SuperClassWriter::addAttribute 
     639               ("scale_factor", field->scale_factor.getValue(), &fieldid); 
     640 
     641           if (!field->add_offset.isEmpty()) 
     642            SuperClassWriter::addAttribute 
     643               ("add_offset", field->add_offset.getValue(), &fieldid); 
    630644                                             
    631645         SuperClassWriter::addAttribute 
     
    765779         if (server->intraCommRank==0) isRoot=true ; 
    766780         else isRoot=false ; 
    767             
     781           
     782         if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) 
     783         { 
     784           double scaleFactor=1. ; 
     785           double addOffset=0. ; 
     786           if (!field->scale_factor.isEmpty()) scaleFactor=field->scale_factor ; 
     787           if (!field->add_offset.isEmpty()) addOffset=field->add_offset ; 
     788           field->scaleFactorAddOffset(scaleFactor,addOffset) ; 
     789         } 
     790             
    768791         if (grid->hasAxis()) // 3D 
    769792         { 
     
    771794            CArray<double,3> field_data3D(domain->zoom_ni_srv,domain->zoom_nj_srv,axis->zoom_size) ; 
    772795            if (!field->default_value.isEmpty()) field_data3D = field->default_value ; 
     796 
    773797            field->outputField(field_data3D); 
     798 
     799            if (field->prec==2) field_data3D=round(field_data3D) ; 
     800 
    774801            switch (SuperClass::type) 
    775802           { 
     
    815842            if (!field->default_value.isEmpty()) field_data2D = field->default_value ; 
    816843            field->outputField(field_data2D); 
     844            if (field->prec==2) field_data2D=round(field_data2D) ; 
    817845            switch (SuperClass::type) 
    818846            { 
Note: See TracChangeset for help on using the changeset viewer.