Changeset 612 for XIOS/branchs
- Timestamp:
- 06/10/15 15:11:22 (8 years ago)
- Location:
- XIOS/branchs/xios-1.0/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/branchs/xios-1.0/src/duration.cpp
r579 r612 27 27 StdOStream & operator<<(StdOStream & out, const CDuration & duration) 28 28 { 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(); 41 30 return out; 42 31 } … … 145 134 StdString CDuration::toString(void) const 146 135 { 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); 150 171 } 151 172 -
XIOS/branchs/xios-1.0/src/duration.hpp
r501 r612 31 31 /// Autres /// 32 32 StdString toString(void) const; 33 StdString toStringUDUnits(void) const; 33 34 34 35 public: /* static */ -
XIOS/branchs/xios-1.0/src/output/nc4_data_output.cpp
r611 r612 794 794 if (wtime) 795 795 { 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); 805 812 } 806 813
Note: See TracChangeset
for help on using the changeset viewer.