Changeset 2826 in Sophya
- Timestamp:
- Nov 2, 2005, 9:52:39 AM (20 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/dvlist.cc
r2698 r2826 49 49 Variables names should not contain space characters and is limited to 64 50 50 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 string52 can be associated with each variable name. A global comment string51 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 53 53 can be attached to the DVList object. DVList objects can conveniently be 54 54 used to represent FITS headers. The class \b SOPHYA::ObjFileIO<DVList> 55 55 handles serialisation for DVList. (See SOPHYA::PPersist ). 56 56 57 \sa SOPHYA::ObjFileIO<DVList> 58 \sa SOPHYA::MuTyV 57 59 58 60 \code … … 65 67 dvl("hello") = 88; 66 68 dvl("Hello") = 77.77; 69 dvl("ToDay") = TimeStamp(); 67 70 dvl.Comment() = "DVList test object, with values named hello, Hello "; 68 71 // Saving the dvl object into a PPF file … … 333 336 334 337 /* --Methode-- */ 338 /*! Appends or sets the TimeStamp value \b val in the list with name \b key */ 339 void DVList::SetT(string const& key, TimeStamp const& val) 340 { 341 MuTyV div(val); 342 Get(key) = div; 343 } 344 345 /* --Methode-- */ 335 346 /*! Assigns the comment \b comm with the name \b key . 336 347 Does nothing if the entry with name is not present in the list */ … … 408 419 if (comment.length() > 0) os << comment << endl; 409 420 char buff[1024]; 421 TimeStamp ts; 410 422 ValList::const_iterator it; 411 423 for(it = mvlist.begin(); it != mvlist.end(); it++) { … … 427 439 sprintf(buff, "%s = %s (string) %s\n", (*it).first.substr(0,64).c_str(), 428 440 (*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()); 429 446 break; 430 447 default : … … 514 531 sfw = buf; s.PutStr(sfw); 515 532 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; 516 537 default : 517 538 break; … … 524 545 } 525 546 526 sfw = "ZZZZZ--End-of-Vari ble-List------"; s.PutStr(sfw);547 sfw = "ZZZZZ--End-of-Variable-List------"; s.PutStr(sfw); 527 548 } 528 549 … … 587 608 dobj->SetS(key, buf+j+1); 588 609 break; 610 case 'T' : 611 dv = atof(buf+j+1); 612 key = buf+2; 613 dobj->SetT(key, TimeStamp(dv)); 614 break; 589 615 default : 590 616 break; -
trunk/SophyaLib/BaseTools/dvlist.h
r2823 r2826 53 53 void SetS(string const& key, char const* val); 54 54 void SetS(string const& key, string const& val); 55 void SetT(string const& key, TimeStamp const& val); 55 56 void SetComment(string const& key, string const& comm); 56 57 -
trunk/SophyaLib/BaseTools/mutyv.cc
r2615 r2826 15 15 \ingroup BaseTools 16 16 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. 18 21 It provides also easy conversion methods between these types. 22 23 \sa SOPHYA::TimeStamp 19 24 20 25 \code … … 28 33 MuTyV mvs("Bonjour !"); // mvs contains the string "Bonjour !" 29 34 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 31 38 \endcode 32 39 */ … … 74 81 75 82 /* --Methode-- */ 83 MuTyV::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-- */ 76 93 MuTyV & MuTyV::operator= (MuTyV const & a) 77 94 { … … 85 102 86 103 /* --Methode-- */ 87 c har * MuTyV::operator= (char* s)104 const char * MuTyV::operator= (const char* s) 88 105 { 89 106 typ = MTVString; … … 96 113 97 114 /* --Methode-- */ 98 string & MuTyV::operator= (string& s)115 string const & MuTyV::operator= (string const& s) 99 116 { 100 117 typ = MTVString; … … 107 124 108 125 /* --Methode-- */ 126 TimeStamp 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-- */ 109 137 MuTyV::operator string() const 110 138 { 111 139 if (typ == MTVString) return(*strv); 140 else if (typ == MTVTimeStamp) { return TimeStamp(dv).ToString(); } 112 141 else { 113 142 char buff[96]; … … 120 149 } 121 150 122 151 /* --Methode-- */ 152 MuTyV::operator TimeStamp() const 153 { 154 return TimeStamp(dv); 155 } 123 156 124 157 static void mutyv_decodestr(string const & s, double& r, double& im) -
trunk/SophyaLib/BaseTools/mutyv.h
r2322 r2826 10 10 #include <string> 11 11 #include <complex> 12 #include "timestamp.h" 13 12 14 #include <iostream> 13 15 … … 24 26 MTVFloat, 25 27 MTVComplex, 26 MTVString 28 MTVString, 29 MTVTimeStamp 27 30 }; 28 31 … … 42 45 MuTyV(char const* s); 43 46 MuTyV(string const& s); 44 47 MuTyV(TimeStamp const& ts); 48 45 49 ~MuTyV(); 46 50 … … 56 60 inline MuTyV & operator= (complex<r_8> const& v) { typ = MTVComplex; dv = (r_8)v.real(); dv_im = v.imag(); 57 61 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); 60 65 61 66 inline operator uint_2() const { return((uint_2)iv); } … … 70 75 71 76 operator string() const ; 77 operator TimeStamp() const ; 72 78 73 79 inline MTVType Type() const { return typ; } … … 81 87 r_8 dv; 82 88 r_8 dv_im; /* for holding imaginary part of a complex */ 83 string * strv; 89 string * strv; 84 90 MTVType typ; 85 91 -
trunk/SophyaLib/BaseTools/rawstream.cc
r2615 r2826 42 42 RawInOutStream& RawInOutStream::read(char* s, uint_8 n) 43 43 { 44 throw NotAvailableOperation("RawInOutStream:: seekg() - Not implemented ");44 throw NotAvailableOperation("RawInOutStream::read() - Not implemented "); 45 45 } 46 46 /* --Methode-- */ … … 59 59 RawInOutStream& RawInOutStream::write(const char* s, uint_8 n) 60 60 { 61 throw NotAvailableOperation("RawInOutStream:: seekp() - Not implemented ");61 throw NotAvailableOperation("RawInOutStream::write() - Not implemented "); 62 62 } 63 63 -
trunk/SophyaLib/BaseTools/sversion.h
r2823 r2826 3 3 4 4 #define SOPHYA_VERSION 1.9 5 #define SOPHYA_REVISION 1 05 #define SOPHYA_REVISION 15 6 6 #define SOPHYA_TAG "V_Oct2005" 7 7 -
trunk/SophyaLib/BaseTools/timestamp.cc
r2805 r2826 69 69 } 70 70 71 TimeStamp::TimeStamp(int_8 days, r_8 seconds) 72 { 73 Set(days, seconds); 74 } 75 71 76 TimeStamp::TimeStamp(string& date, string& hour) 72 77 { … … 90 95 void TimeStamp::Set(double days) 91 96 { 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.; 95 100 } 96 101 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 113 void 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; 100 118 } 101 119 … … 178 196 seconds -= hour*3600; 179 197 min = trunc(seconds/60.); 198 while (min >= 60) { hour++; min -= 60; } 180 199 sec = seconds-min*60; 181 } 200 while (sec >= 60.) { min++; sec -= 60.; } 201 } 202 182 203 double TimeStamp::ToDays() const 183 204 { … … 185 206 } 186 207 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 */ 212 string TimeStamp::ToString(bool fgday, bool fghour) const 188 213 { 189 214 char buff[128]; … … 193 218 GetDate(aa, mm, jj); 194 219 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); 196 226 return buff; 197 227 } 198 228 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 */ 233 void TimeStamp::Print(ostream& os, bool fgday, bool fghour) const 234 { 235 os << " " << ToString(fgday, fghour) << " "; 202 236 } 203 237 -
trunk/SophyaLib/BaseTools/timestamp.h
r2654 r2826 32 32 //! Constructor with specification of number of days since 0 Jan 1901 0h TU 33 33 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); 34 36 //! Constructor with specification of day,month,year,hour,minutes,seconds 35 37 TimeStamp(int year, int month, int day, int hour, int min, double sec); … … 42 44 //! Sets the value of the time stamp from the number of days since 0 Jan 1901 0h TU 43 45 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); 44 48 //! initialize with current date and time (GMT) 45 49 void SetNow(); … … 70 74 //! Return the value of the TimeStamp as days.fraction_days since 0 Jan 1901 71 75 double ToDays() const; 72 //! Conversion operator to double 76 //! Conversion operator to double - return ToDays() 73 77 inline operator double() const { return ToDays(); } 74 78 75 79 //! Return the timestamp in string format 76 string ToString( ) const;80 string ToString(bool fgday=true, bool fghour=true) const; 77 81 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; } 82 86 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 84 93 //! Number of days in a given month 85 94 static int MonthDays(int year, int month);
Note:
See TracChangeset
for help on using the changeset viewer.