Changeset 612


Ignore:
Timestamp:
06/10/15 15:11:22 (6 years ago)
Author:
rlacroix
Message:

Improve CF compliance: Write the "cell_methods" metadata.

Also try to use the time units defined by the UDUnits specification.

Location:
XIOS
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/branchs/xios-1.0/src/duration.cpp

    r579 r612  
    2727      StdOStream & operator<<(StdOStream & out, const CDuration & duration) 
    2828      { 
    29          StdOStringStream sout; 
    30          bool testValue = true; 
    31          if(duration.year   != 0.0) { testValue = false; sout << duration.year   << "y "; } 
    32          if(duration.month  != 0.0) { testValue = false; sout << duration.month  << "mo "; } 
    33          if(duration.day    != 0.0) { testValue = false; sout << duration.day    << "d "; } 
    34          if(duration.hour   != 0.0) { testValue = false; sout << duration.hour   << "h "; } 
    35          if(duration.minute != 0.0) { testValue = false; sout << duration.minute << "mi "; } 
    36          if(duration.second != 0.0) { testValue = false; sout << duration.second << "s "; } 
    37          if(duration.timestep != 0.0 || testValue)       { sout << duration.timestep << "ts "; } 
    38  
    39          // << suppression de l'espace en fin de chaîne. 
    40          out << (sout.str().substr(0, sout.str().size()-1)); 
     29         out << duration.toString(); 
    4130         return out; 
    4231      } 
     
    145134      StdString CDuration::toString(void) const 
    146135      { 
    147          const  CDuration & own = *this; 
    148          StdOStringStream oss; oss << own; 
    149          return oss.str(); 
     136         StdOStringStream sout; 
     137         bool forceOutput = true; 
     138 
     139         if (year   != 0.0) { forceOutput = false; sout << year   << "y "; } 
     140         if (month  != 0.0) { forceOutput = false; sout << month  << "mo "; } 
     141         if (day    != 0.0) { forceOutput = false; sout << day    << "d "; } 
     142         if (hour   != 0.0) { forceOutput = false; sout << hour   << "h "; } 
     143         if (minute != 0.0) { forceOutput = false; sout << minute << "mi "; } 
     144         if (second != 0.0) { forceOutput = false; sout << second << "s "; } 
     145         if (timestep != 0.0 || forceOutput)     { sout << timestep << "ts "; } 
     146 
     147         // Remove the trailing space 
     148         StdString strOut = sout.str(); 
     149         return strOut.erase(strOut.size() - 1); 
     150      } 
     151 
     152      StdString CDuration::toStringUDUnits(void) const 
     153      { 
     154         if (timestep != 0.0) 
     155           ERROR("StdString CDuration::toStringUDUnits(void) const", 
     156                 "Impossible to convert a duration to string using UDUnits when a timestep is set."); 
     157 
     158         StdOStringStream sout; 
     159         bool forceOutput = true; 
     160 
     161         if (year   != 0.0) { forceOutput = false; sout << year   << " yr "; } 
     162         if (month  != 0.0) { forceOutput = false; sout << month  << " month "; } 
     163         if (day    != 0.0) { forceOutput = false; sout << day    << " d "; } 
     164         if (hour   != 0.0) { forceOutput = false; sout << hour   << " h "; } 
     165         if (minute != 0.0) { forceOutput = false; sout << minute << " min "; } 
     166         if (second != 0.0 || forceOutput)       { sout << second << " s "; } 
     167 
     168         // Remove the trailing space 
     169         StdString strOut = sout.str(); 
     170         return strOut.erase(strOut.size() - 1); 
    150171      } 
    151172 
  • XIOS/branchs/xios-1.0/src/duration.hpp

    r501 r612  
    3131            /// Autres /// 
    3232            StdString toString(void) const; 
     33            StdString toStringUDUnits(void) const; 
    3334 
    3435         public: /* static */ 
  • XIOS/branchs/xios-1.0/src/output/nc4_data_output.cpp

    r611 r612  
    794794           if (wtime) 
    795795           { 
    796               CDuration duration ; 
    797  
    798               duration=CDuration::FromString(field->freq_op) ; 
    799               duration.solveTimeStep(*(context->calendar)); 
    800               SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid); 
    801  
    802               duration=CDuration::FromString(field->getRelFile()->output_freq) ; 
    803               duration.solveTimeStep(*(context->calendar)); 
    804               SuperClassWriter::addAttribute("interval_write", duration.toString(), &fieldid); 
     796              CDuration duration = CDuration::FromString(field->freq_op); 
     797              duration.solveTimeStep(*context->calendar); 
     798              StdString freqOpStr = duration.toStringUDUnits(); 
     799              SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid); 
     800 
     801              duration = CDuration::FromString(field->getRelFile()->output_freq); 
     802              duration.solveTimeStep(*context->calendar); 
     803              SuperClassWriter::addAttribute("interval_write", duration.toStringUDUnits(), &fieldid); 
     804 
     805              StdString cellMethods = coodinates.front() + ": "; 
     806              if (field->operation.getValue() == "instant") cellMethods += "point"; 
     807              else if (field->operation.getValue() == "average") cellMethods += "mean"; 
     808              else if (field->operation.getValue() == "accumulate") cellMethods += "sum"; 
     809              else cellMethods += field->operation; 
     810              cellMethods += " (interval: " + freqOpStr + ")"; 
     811              SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid); 
    805812           } 
    806813 
  • XIOS/trunk/src/duration.cpp

    r579 r612  
    2828      StdOStream& operator<<(StdOStream& out, const CDuration& duration) 
    2929      { 
    30         StdOStringStream sout; 
    31         bool forceOutput = true; 
    32  
    33         if (duration.year   != 0.0) { forceOutput = false; sout << duration.year   << "y "; } 
    34         if (duration.month  != 0.0) { forceOutput = false; sout << duration.month  << "mo "; } 
    35         if (duration.day    != 0.0) { forceOutput = false; sout << duration.day    << "d "; } 
    36         if (duration.hour   != 0.0) { forceOutput = false; sout << duration.hour   << "h "; } 
    37         if (duration.minute != 0.0) { forceOutput = false; sout << duration.minute << "mi "; } 
    38         if (duration.second != 0.0) { forceOutput = false; sout << duration.second << "s "; } 
    39         if (duration.timestep != 0.0 || forceOutput)     { sout << duration.timestep << "ts "; } 
    40  
    41         // suppression de l'espace en fin de chaîne. 
    42         StdString strOut = sout.str(); 
    43         out << strOut.erase(strOut.size() - 1); 
    44         return out; 
     30         out << duration.toString(); 
     31         return out; 
    4532      } 
    4633 
     
    124111      StdString CDuration::toString(void) const 
    125112      { 
    126         StdOStringStream oss; oss << *this; 
    127         return oss.str(); 
     113        StdOStringStream sout; 
     114        bool forceOutput = true; 
     115 
     116        if (year   != 0.0) { forceOutput = false; sout << year   << "y "; } 
     117        if (month  != 0.0) { forceOutput = false; sout << month  << "mo "; } 
     118        if (day    != 0.0) { forceOutput = false; sout << day    << "d "; } 
     119        if (hour   != 0.0) { forceOutput = false; sout << hour   << "h "; } 
     120        if (minute != 0.0) { forceOutput = false; sout << minute << "mi "; } 
     121        if (second != 0.0) { forceOutput = false; sout << second << "s "; } 
     122        if (timestep != 0.0 || forceOutput)     { sout << timestep << "ts "; } 
     123 
     124         // Remove the trailing space 
     125        StdString strOut = sout.str(); 
     126        return strOut.erase(strOut.size() - 1); 
     127      } 
     128 
     129      StdString CDuration::toStringUDUnits(void) const 
     130      { 
     131         if (timestep != 0.0) 
     132           ERROR("StdString CDuration::toStringUDUnits(void) const", 
     133                 "Impossible to convert a duration to string using UDUnits when a timestep is set."); 
     134 
     135         StdOStringStream sout; 
     136         bool forceOutput = true; 
     137 
     138         if (year   != 0.0) { forceOutput = false; sout << year   << " yr "; } 
     139         if (month  != 0.0) { forceOutput = false; sout << month  << " month "; } 
     140         if (day    != 0.0) { forceOutput = false; sout << day    << " d "; } 
     141         if (hour   != 0.0) { forceOutput = false; sout << hour   << " h "; } 
     142         if (minute != 0.0) { forceOutput = false; sout << minute << " min "; } 
     143         if (second != 0.0 || forceOutput)       { sout << second << " s "; } 
     144 
     145         // Remove the trailing space 
     146         StdString strOut = sout.str(); 
     147         return strOut.erase(strOut.size() - 1); 
    128148      } 
    129149 
  • XIOS/trunk/src/duration.hpp

    r591 r612  
    3434            /// Autres /// 
    3535            StdString toString(void) const; 
     36            StdString toStringUDUnits(void) const; 
    3637 
    3738            /// Propriétés publiques /// 
  • XIOS/trunk/src/output/nc4_data_output.cpp

    r611 r612  
    816816           { 
    817817              CDuration duration = field->freq_op.getValue(); 
    818               duration.solveTimeStep(*(context->calendar)); 
    819               SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid); 
     818              duration.solveTimeStep(*context->calendar); 
     819              StdString freqOpStr = duration.toStringUDUnits(); 
     820              SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid); 
    820821 
    821822              duration = field->getRelFile()->output_freq.getValue(); 
    822               duration.solveTimeStep(*(context->calendar)); 
    823               SuperClassWriter::addAttribute("interval_write", duration.toString(), &fieldid); 
     823              duration.solveTimeStep(*context->calendar); 
     824              SuperClassWriter::addAttribute("interval_write", duration.toStringUDUnits(), &fieldid); 
     825 
     826              StdString cellMethods = coodinates.front() + ": "; 
     827              if (field->operation.getValue() == "instant") cellMethods += "point"; 
     828              else if (field->operation.getValue() == "average") cellMethods += "mean"; 
     829              else if (field->operation.getValue() == "accumulate") cellMethods += "sum"; 
     830              else cellMethods += field->operation; 
     831              cellMethods += " (interval: " + freqOpStr + ")"; 
     832              SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid); 
    824833           } 
    825834 
     
    10251034//              CDuration duration = field->freq_op.getValue(); 
    10261035//              duration.solveTimeStep(*(context->calendar)); 
    1027 //              SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid); 
     1036//              SuperClassWriter::addAttribute("interval_operation", duration.toStringUDUnits(), &fieldid); 
    10281037// 
    10291038//              duration = field->getRelFile()->output_freq.getValue(); 
    10301039//              duration.solveTimeStep(*(context->calendar)); 
    1031 //              SuperClassWriter::addAttribute("interval_write", duration.toString(), &fieldid); 
     1040//              SuperClassWriter::addAttribute("interval_write", duration.toStringUDUnits(), &fieldid); 
    10321041//           } 
    10331042// 
Note: See TracChangeset for help on using the changeset viewer.