Changeset 2826 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Nov 2, 2005, 9:52:39 AM (20 years ago)
Author:
ansari
Message:

1/ Correction bug TimeStamp::ToDays() + petites amelioration
2/ Prise en compte du type TimeStamp dans MuTyV (sous forme de r_8 en interne)
3/ Adaptation DVList a modifs MuTyV (typ TimeStamp) et R/W PPersist

+ Petites corrections et MAJ num.version , Reza 2 Nov 2005

Location:
trunk/SophyaLib/BaseTools
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/dvlist.cc

    r2698 r2826  
    4949   Variables names should not contain space characters and is limited to 64
    5050   characters. The DVList class uses \b SOPHYA::MuTyV objects to hold values
    51    of type string, integer (\b int_8) or float (\b r_8). A comment string
    52    can be associated with each variable name. A global comment string
     51   of type string, integer (\b int_8) or float (\b r_8) or time/date (TimeStamp).
     52   A comment string can be associated with each variable name. A global comment string
    5353   can be attached to the DVList object. DVList objects can conveniently be
    5454   used to represent FITS headers. The class \b SOPHYA::ObjFileIO<DVList>
    5555   handles serialisation for DVList. (See SOPHYA::PPersist ).
     56
    5657   \sa SOPHYA::ObjFileIO<DVList>
     58   \sa SOPHYA::MuTyV
    5759
    5860   \code
     
    6567   dvl("hello") = 88;
    6668   dvl("Hello") = 77.77;   
     69   dvl("ToDay") = TimeStamp();   
    6770   dvl.Comment() = "DVList test object, with values named hello, Hello ";
    6871   // Saving the dvl object into a PPF file
     
    333336
    334337/* --Methode-- */
     338/*! Appends or sets the TimeStamp value \b val in the list with name \b key */
     339void        DVList::SetT(string const& key, TimeStamp const& val)
     340{
     341MuTyV div(val);
     342Get(key) = div;
     343}
     344
     345/* --Methode-- */
    335346/*! Assigns the comment \b comm with the name \b key .
    336347    Does nothing if the entry with name is not present in the list   */
     
    408419if (comment.length() > 0)  os << comment << endl;
    409420char buff[1024];
     421TimeStamp ts;
    410422ValList::const_iterator it;
    411423for(it = mvlist.begin(); it != mvlist.end(); it++)  {
     
    427439      sprintf(buff, "%s = %s (string) %s\n", (*it).first.substr(0,64).c_str(),
    428440              (*it).second.elval.GetStringPointer()->substr(0,800).c_str(), (*it).second.elcomm.substr(0,128).c_str());
     441      break;
     442    case MuTyV::MTVTimeStamp :
     443      ts.Set((*it).second.elval.GetRealPart());
     444      sprintf(buff, "%s = %s (TimeStamp) %s\n", (*it).first.substr(0,64).c_str(),
     445                ts.ToString().c_str(), (*it).second.elcomm.substr(0,128).c_str());
    429446      break;
    430447    default :
     
    514531      sfw = buf;  s.PutStr(sfw);
    515532      break;
     533    case MuTyV::MTVTimeStamp :
     534      sprintf(buf,"T %s %.20g\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.GetRealPart() );
     535      sfw = buf;  s.PutStr(sfw);
     536      break;
    516537    default :
    517538      break;
     
    524545}
    525546
    526 sfw = "ZZZZZ--End-of-Varible-List------"; s.PutStr(sfw);
     547sfw = "ZZZZZ--End-of-Variable-List------"; s.PutStr(sfw);
    527548}
    528549
     
    587608      dobj->SetS(key, buf+j+1);
    588609      break;
     610    case 'T' :
     611      dv = atof(buf+j+1);
     612      key = buf+2;
     613      dobj->SetT(key, TimeStamp(dv));
     614      break;
    589615    default :
    590616      break;
  • trunk/SophyaLib/BaseTools/dvlist.h

    r2823 r2826  
    5353  void              SetS(string const& key, char const*  val);
    5454  void              SetS(string const& key, string const& val);
     55  void              SetT(string const& key, TimeStamp const& val);
    5556  void              SetComment(string const& key, string const& comm);
    5657
  • trunk/SophyaLib/BaseTools/mutyv.cc

    r2615 r2826  
    1515   \ingroup BaseTools
    1616   Simple utility class which can be used to hold values of type
    17    string, integer (\b int_8) or float (\b r_8) as well as complex,
     17   string, integer (\b int_8), float (\b r_8), complex and
     18   date/time (TimeStamp). Date/time values are kept internally
     19   as double precision values and are thus less precise than
     20   TimeStamp objects.
    1821   It provides also easy conversion methods between these types.
     22
     23   \sa SOPHYA::TimeStamp
    1924
    2025   \code
     
    2833   MuTyV mvs("Bonjour !");  // mvs contains the string "Bonjour !"
    2934   string s = mvs;          // s contains "Bonjour !"
    30  
     35   TimeStamp ts;      // Current date/time
     36   MuTyV mvt = ts;
     37   s = mvt;           // s contains the current date in string format
    3138   \endcode
    3239*/
     
    7481
    7582/* --Methode-- */
     83MuTyV::MuTyV(TimeStamp const& ts)
     84{
     85  typ = MTVTimeStamp;
     86  dv = ts.ToDays();
     87  dv_im = 0.;
     88  iv = (int_8)dv;
     89  strv = NULL;
     90}
     91
     92/* --Methode-- */
    7693MuTyV & MuTyV::operator= (MuTyV const & a)
    7794{
     
    85102
    86103/* --Methode-- */
    87 char * MuTyV::operator= (char* s)
     104const char * MuTyV::operator= (const char* s)
    88105{
    89106  typ = MTVString;
     
    96113
    97114/* --Methode-- */
    98 string & MuTyV::operator= (string& s)
     115string const & MuTyV::operator= (string const& s)
    99116{
    100117  typ = MTVString;
     
    107124
    108125/* --Methode-- */
     126TimeStamp const & MuTyV::operator= (TimeStamp const& ts)
     127{
     128  typ = MTVTimeStamp;
     129  dv = ts.ToDays();
     130  dv_im = 0.;
     131  iv = (int_8)dv;
     132  return(ts);
     133}
     134
     135
     136/* --Methode-- */
    109137MuTyV::operator string() const
    110138{
    111139  if (typ == MTVString)  return(*strv);
     140  else if (typ == MTVTimeStamp) { return TimeStamp(dv).ToString(); }
    112141  else {
    113142    char buff[96];
     
    120149}
    121150
    122 
     151/* --Methode-- */
     152MuTyV::operator TimeStamp() const
     153{
     154  return TimeStamp(dv);
     155}
    123156
    124157static void mutyv_decodestr(string const & s, double& r, double& im)
  • trunk/SophyaLib/BaseTools/mutyv.h

    r2322 r2826  
    1010#include <string>
    1111#include <complex>
     12#include "timestamp.h"
     13
    1214#include <iostream>
    1315
     
    2426    MTVFloat,
    2527    MTVComplex,
    26     MTVString
     28    MTVString,
     29    MTVTimeStamp
    2730  };
    2831
     
    4245         MuTyV(char const* s); 
    4346         MuTyV(string const& s);
    44  
     47         MuTyV(TimeStamp const& ts);
     48
    4549         ~MuTyV();
    4650 
     
    5660  inline MuTyV & operator= (complex<r_8> const& v) { typ = MTVComplex; dv = (r_8)v.real();  dv_im = v.imag();
    5761                                                    iv = (int_8)dv;  return(*this); }
    58          char*  operator= (char* s);
    59          string& operator= (string& s);
     62         const char*  operator= (const char* s);
     63         string const& operator= (string const & s);
     64         TimeStamp const& operator= (TimeStamp const & s);
    6065
    6166  inline operator uint_2() const { return((uint_2)iv); }
     
    7075
    7176         operator string() const ;
     77         operator TimeStamp() const ;
    7278
    7379  inline MTVType Type() const { return typ; }
     
    8187  r_8 dv;
    8288  r_8 dv_im;   /* for holding imaginary part of a complex */
    83   string * strv; 
     89  string * strv;
    8490  MTVType typ;
    8591
  • trunk/SophyaLib/BaseTools/rawstream.cc

    r2615 r2826  
    4242RawInOutStream& RawInOutStream::read(char* s, uint_8 n)
    4343{
    44   throw NotAvailableOperation("RawInOutStream::seekg() - Not implemented ");
     44  throw NotAvailableOperation("RawInOutStream::read() - Not implemented ");
    4545}
    4646/* --Methode-- */
     
    5959RawInOutStream& RawInOutStream::write(const char* s, uint_8 n)
    6060{
    61   throw NotAvailableOperation("RawInOutStream::seekp() - Not implemented ");
     61  throw NotAvailableOperation("RawInOutStream::write() - Not implemented ");
    6262}
    6363
  • trunk/SophyaLib/BaseTools/sversion.h

    r2823 r2826  
    33
    44#define SOPHYA_VERSION   1.9
    5 #define SOPHYA_REVISION  10
     5#define SOPHYA_REVISION  15
    66#define SOPHYA_TAG       "V_Oct2005"
    77
  • trunk/SophyaLib/BaseTools/timestamp.cc

    r2805 r2826  
    6969}
    7070
     71TimeStamp::TimeStamp(int_8 days, r_8 seconds)
     72{
     73  Set(days, seconds);
     74}
     75
    7176TimeStamp::TimeStamp(string& date, string& hour)
    7277{
     
    9095void TimeStamp::Set(double days)
    9196{
    92   if (days < 0.) {
    93     mDays = days;
    94     mSeconds = (days-mDays)*86400.;
     97  if (days >= 0.) {
     98    mDays = trunc(days);
     99    mSeconds = (days-trunc(days))*86400.;
    95100  }
    96101  else {
    97     mDays = trunc(days)-1;
    98     mSeconds = (days-mDays)*86400.;
    99   }
     102    if ( (trunc(days)-days) > 0.) {
     103      mDays = trunc(days)-1;
     104      mSeconds = (days-mDays)*86400.;
     105    }
     106    else {
     107      mDays = trunc(days);
     108      mSeconds = 0.;
     109    }
     110  }
     111}
     112
     113void TimeStamp::Set(int_8 days, r_8 seconds)
     114{
     115  if ( (seconds < 0.) || (seconds > 86400.) )
     116    throw ParmError("TimeStamp::Set(int_8, r_8) seconds<0 or seconds>86400.");
     117  mDays = days;
    100118}
    101119
     
    178196  seconds -= hour*3600;
    179197  min = trunc(seconds/60.);
     198  while (min >= 60) { hour++; min -= 60; }
    180199  sec = seconds-min*60;
    181 }
     200  while (sec >= 60.) { min++; sec -= 60.; }
     201}
     202
    182203double TimeStamp::ToDays() const
    183204{
     
    185206}
    186207
    187 string TimeStamp::ToString() const
     208/*!
     209\param fgday : if false, ignore the date (dd/mm/yy) part
     210\param fghour : if false, ignore the hour (hh:mm:ss) part
     211*/
     212string TimeStamp::ToString(bool fgday, bool fghour) const
    188213{
    189214  char buff[128];
     
    193218  GetDate(aa, mm, jj);
    194219  GetHour(hh, min, sec);
    195   sprintf(buff,"%02d/%02d/%02d %02d:%02d:%02.1f GMT", jj,mm,aa,hh,min,sec);
     220  if (!fghour)
     221    sprintf(buff,"%02d/%02d/%02d ", jj,mm,aa);
     222  else if (!fgday)
     223    sprintf(buff,"%02d:%02d:%02.3f ", hh,min,sec);
     224  else
     225    sprintf(buff,"%02d/%02d/%02d %02d:%02d:%02.1f GMT", jj,mm,aa,hh,min,sec);
    196226  return buff;
    197227}
    198228
    199 void TimeStamp::Print(ostream& os)  const
    200 {
    201   os << " " << ToString() << " ";
     229/*!
     230\param fgday : if false, ignore the date (dd/mm/yy) part
     231\param fghour : if false, ignore the hour (hh:mm:ss) part
     232*/
     233void TimeStamp::Print(ostream& os, bool fgday, bool fghour)  const
     234{
     235  os << " " << ToString(fgday, fghour) << " ";
    202236}
    203237
  • trunk/SophyaLib/BaseTools/timestamp.h

    r2654 r2826  
    3232  //! Constructor with specification of number of days since 0 Jan 1901 0h TU
    3333  TimeStamp(double days);
     34  //! Constructor from number of days (since 0/01/1901) and number of seconds
     35  TimeStamp(int_8 days, r_8 seconds);
    3436  //! Constructor with specification of day,month,year,hour,minutes,seconds
    3537  TimeStamp(int year, int month, int day, int hour, int min, double sec);
     
    4244  //! Sets the value of the time stamp from the number of days since 0 Jan 1901 0h TU
    4345  void Set(double days);
     46  //! Sets the value of the time stamp from the number of days and seconds
     47  void Set(int_8 days, r_8 seconds);
    4448  //! initialize with current date and time (GMT)
    4549  void SetNow();
     
    7074  //! Return the value of the TimeStamp as days.fraction_days since 0 Jan 1901
    7175  double ToDays() const;
    72   //! Conversion operator to double
     76  //! Conversion operator to double - return ToDays()
    7377  inline operator double() const { return ToDays(); }
    7478
    7579  //! Return the timestamp in string format
    76   string ToString() const;
     80  string ToString(bool fgday=true, bool fghour=true) const;
    7781 
    78   /*! Prints the date/time in string format on \b cout */
    79   inline  void    Print() const  { Print(cout); } 
    80   /*! Prints the date/time in string format on stream \b os */
    81   virtual void    Print(ostream& os)  const;
     82  //! Return the integral number of days since 0 Jan 1901
     83  inline int_8 DaysPart() { return mDays; }
     84  //! Return the fractional number of days in seconds ( 0 < nsec < 86400. )
     85  inline r_8 SecondsPart() { return mSeconds; }
    8286
    83   //!
     87  //! Prints the date/time in string format on \b cout
     88  inline  void    Print(bool fgday=true, bool fghour=true) const 
     89     { Print(cout, fgday, fghour); } 
     90  //! Prints the date/time in string format on stream \b os
     91  virtual void    Print(ostream& os, bool fgday=true, bool fghour=true)  const;
     92
    8493  //! Number of days in a given month 
    8594  static int   MonthDays(int year, int month);
Note: See TracChangeset for help on using the changeset viewer.