Changeset 316


Ignore:
Timestamp:
02/20/12 17:42:29 (12 years ago)
Author:
ymipsl
Message:
  • Change date format :

dd/mm/yyyy-hh:mm:ss becomes yyyy-mm-dd hh:mm:ss

  • add boost date_time functionality

YM

Location:
XIOS/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/bld.cfg

    r314 r316  
    2525search_src           true 
    2626src::zzz . 
     27src::date $PWD/extern/boost/src/date_time 
    2728bld::lib xios 
    2829bld::target libxios.a 
    29 bld::target generate_fortran_interface.exe  
     30#bld::target test.exe 
     31#bld::target generate_fortran_interface.exe  
    3032bld::target xios_server.exe test_cs.exe  
    3133bld::exe_dep 
  • XIOS/trunk/src/date.cpp

    r231 r316  
    11#include "date.hpp" 
    22#include "calendar.hpp" 
     3#include <boost/date_time/gregorian/gregorian.hpp> 
     4#include <boost/date_time/posix_time/posix_time.hpp> 
     5 
     6using namespace boost::posix_time ; 
     7using namespace boost::gregorian ; 
    38 
    49namespace xmlioserver 
     
    4853      StdOStream & operator<<(StdOStream & out, const CDate & date) 
    4954      { 
    50          std::streamsize s = out.width (2); 
    51          char c = out.fill ('0'); 
    52          out << date.day << '/'; 
    53          s = out.width (2); c = out.fill ('0'); 
    54          out << date.month << '/'; 
    55          s = out.width (4); c = out.fill ('0'); 
    56          out << date.year << '-'; 
    57          s = out.width (2); c = out.fill ('0'); 
    58          out << date.hour << ':'; 
    59          s = out.width (2); c = out.fill ('0'); 
    60          out << date.minute << ':'; 
    61          s = out.width (2); c = out.fill ('0'); 
    62          out << date.second; 
     55         std::streamsize s ;  
     56         char c ; 
    6357          
     58         s = out.width (4);  c = out.fill ('0') ; out << date.year << '-'; 
     59         s = out.width (2);  c = out.fill ('0') ; out << date.month << '-'; 
     60         s = out.width (2);  c = out.fill ('0') ; out << date.day << ' '; 
     61         s = out.width (2);  c = out.fill ('0') ; out << date.hour << ':'; 
     62         s = out.width (2);  c = out.fill ('0') ; out << date.minute << ':'; 
     63         s = out.width (2);  c = out.fill ('0') ; out << date.second ; 
     64 
    6465         return (out); 
    6566      } 
     
    6768      StdIStream & operator>>(StdIStream & in, CDate & date) // Non testée. 
    6869      { 
    69          char c = '/'; // Le caractÚre c est utilisé pour "recueillir" les séparateurs "/" et ":". 
    70          in >> date.day  >> c >> date.month  >> c >> date.year   >> c; 
    71          in >> date.hour >> c >> date.minute >> c >> date.second; 
    72          if(!date.checkDate()) 
    73          { 
    74             DEBUG("La date initialisée (depuis une chaîne de caractÚres) " 
    75                   << "a été modifiée car elle était incorrecte " 
    76                   << "par rapport au calendrier souhaité."); 
    77          } 
    78          return (in); 
     70        char sep = '-'; // Le caractÚre c est utilisé pour "recueillir" les séparateurs "/" et ":". 
     71        char c ; 
     72          
     73        in >> date.year >> c ; 
     74        if (c==sep) 
     75        { 
     76          in >> date.month >> c ; 
     77          if (c==sep) 
     78          { 
     79            in >> date.day  ; 
     80            c=in.get(); 
     81            sep=' ' ; 
     82            if (c==sep) 
     83            { 
     84              in >> date.hour >> c ; 
     85              sep=':' ; 
     86              if (c==sep)  
     87              { 
     88                in>>date.minute >> c; 
     89                if (c==sep) 
     90                { 
     91                  in>>date.second ; 
     92                  if(!date.checkDate()) 
     93                    ERROR("StdIStream & operator >> (StdIStream & in, CDate & date)",<<"Bad date format or not conform to calendar" ); 
     94                    return (in); 
     95                } 
     96              } 
     97            } 
     98          } 
     99        } 
     100        ERROR("StdIStream & operator >> (StdIStream & in, CDate & date)",<<"Bad date format or not conform to calendar" ); 
     101        return (in); 
    79102      } 
    80103 
  • XIOS/trunk/src/output/nc4_data_output.cpp

    r314 r316  
    563563            SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); 
    564564            date::CDate initDate=cal->getInitDate() ; 
    565             StdOStringStream oss2; 
    566             oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " 
    567                 <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; 
    568             StdString strInitdate=oss2.str() ; 
     565//            StdOStringStream oss2; 
     566//            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " 
     567//                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; 
     568//            StdString strInitdate=oss2.str() ; 
     569            StdString strInitdate=initDate.toString() ; 
    569570            this->writeTimeAxisAttributes 
    570571               (axisid, cal->getType(), 
  • XIOS/trunk/src/test/test.cpp

    r300 r316  
    33#include <string> 
    44 
     5#include <boost/date_time/gregorian/gregorian.hpp> 
     6#include <boost/date_time/posix_time/posix_time.hpp> 
     7 
    58using namespace std ; 
    6  
    7  
    8 class CLog : public ostream 
    9 { 
    10    public : 
    11    CLog() : ostream(NULL),level(0) {} 
    12    CLog& operator()(int l) {if (l<=level) rdbuf(cout.rdbuf()) ; else rdbuf(NULL) ; return *this;} 
    13    void setLevel(int l) {level=l; }  
    14    int level ; 
    15 //   ostringstream& getStream() { return *(ostringstream*)(this) ; } 
    16 //   ~CLog(void) { cout<<"info message "<< this->str();} 
    17 }; 
    18  
     9using namespace boost::posix_time ; 
     10using namespace boost::gregorian ; 
    1911 
    2012int main(void) 
    2113{ 
    22   CLog out ; 
    23   cout<<string("toto")<<endl ; 
    24   out<<"123"<<endl ; 
    25   out.setLevel(5) ; 
    26   out(7)<<"coucou 1"<<endl ; 
    27   out(3)<<"coucou 2"<<endl<<"i23"<<endl ; 
    28    
     14      ptime t(time_from_string("2012-02-30 15:24")) ; 
     15       
     16        
     17      std::cout << to_simple_string(t) << std::endl; 
     18 
     19  return 1 ;   
    2920} 
  • XIOS/trunk/src/test/test_cs.f90

    r313 r316  
    7777  CALL xios_set_context_attr("test",calendar_type="Gregorian")  
    7878  CALL xios_set_context_attr("test",calendar_type="Gregorian")  
    79   CALL xios_set_context_attr("test",start_date="01/01/2000 - 00:00:00") 
     79!  CALL xios_set_context_attr("test",start_date="01/01/2000 - 00:00:00") 
    8080  CALL xios_set_context_attr("test",calendar_type="Gregorian")  
    8181  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj) 
Note: See TracChangeset for help on using the changeset viewer.