GSE++ library: reading and writing GSE waveforms
gsexx_TWID2.cc
Go to the documentation of this file.
1 
35 #define TF_GSEXX_TWID2_CC_VERSION \
36  "TF_GSEXX_TWID2_CC V1.2 "
37 #define TF_GSEXX_TWID2_CC_CVSID \
38  "$Id$"
39 
40 #include <ctime>
41 #include <cstdlib>
42 #include <gsexx.h>
43 #include <cstdio>
44 
45 namespace GSE2 {
46 namespace waveform {
47 
54 const char* const TWID2::GSEID="WID2";
56 
58 std::string TWID2::subformat() const
59 {
60  std::string retval("NSP");
61  if (Fsubformat == SF_CM6) retval="CM6";
62  return(retval);
63 }
64 
66 void TWID2::setsubformat(const std::string& key)
67 {
68  if (key.substr(0,3)==std::string("CM6")) { Fsubformat=SF_CM6; }
69  else throw
70  Terror("ERROR (TWID2): unknown subformat key!");
71 }
72 
74 std::string TWID2::line() const
75 {
76  // buffer size
77  const int bufsize=135;
78  // character buffer
79  char charbuf[bufsize];
80  std::string datatype=subformat();
81  int isec=int(Fmilsec/1000);
82  int imsec=Fmilsec-(1000*isec);
83  sprintf(charbuf, "%-4s %4.4i/%2.2i/%2.2i %2.2i:%2.2i:%2.2i.%3.3i "
84  "%-5s %-3s %-4s %-3s %8i %11.6f %10.2e %7.3f %-6s %5.1f %4.1f\n",
86  Fhour, Fminute, isec, imsec,
87  Fstation.substr(0,5).c_str(),
88  Fchannel.substr(0,3).c_str(),
89  Fauxid.substr(0,4).c_str(),
90  datatype.substr(0,3).c_str(),
92  Finstype.substr(0,6).c_str(),
93  Fhang, Fvang);
94  std::string retval(charbuf);
95  return(retval);
96 }
97 
99 void TWID2::read(std::istream& is)
100 {
101  std::string theline;
102  getline(is, theline);
103 
104  // check ID
105  std::string lineID=theline.substr(0,4);
106  if (!GSEIDmatch<TWID2>(lineID)) throw
107  Terror("ERROR (TWID2::read): missing WID2 ID!");
108 
109  Fyear =atoi(theline.substr( 5,4).c_str());
110  Fmonth =atoi(theline.substr(10,2).c_str());
111  Fday =atoi(theline.substr(13,2).c_str());
112  Fhour =atoi(theline.substr(16,2).c_str());
113  Fminute =atoi(theline.substr(19,2).c_str());
114  // Fseconds =atof(theline.substr(22,6).c_str());
115  int isec =atoi(theline.substr(22,2).c_str());
116  Fmilsec =atoi(theline.substr(25,3).c_str());
117  Fmilsec += (1000*isec);
118  /*
119  std::cerr << "TWID2 debug: "
120  << theline.substr(22,6) << " "
121  << this->seconds() << " "
122  << isec << " "
123  << Fmilsec
124  << std::endl;
125  */
126 
127  Fstation =theline.substr(29,5);
128  Fchannel =theline.substr(35,3);
129  Fauxid =theline.substr(39,4);
130 
131  this->setsubformat(theline.substr(44,3));
132 
133  Fsamps =atoi(theline.substr(48,8).c_str());
134 
135  Fsamprate=atof(theline.substr(57,11).c_str());
136  Fcalib =atof(theline.substr(69,10).c_str());
137  Fcalper =atof(theline.substr(80,7).c_str());
138  Finstype =theline.substr(88,6);
139  Fhang =atof(theline.substr(95,5).c_str());
140  Fvang =atof(theline.substr(101,4).c_str());
141 }
142 
144 double TWID2::seconds() const
145 {
146  return(double(1.e-3*Fmilsec));
147 }
148 
150 void TWID2::seconds(const double& s)
151 {
152  Fmilsec=int(1000*s);
153 }
154 
157 {
158  std::time_t nowtime=std::time(NULL);
159  std::tm *now=std::localtime(&nowtime);
160  Fyear=now->tm_year+1900;
161  Fmonth=now->tm_mon;
162  Fday=now->tm_mday;
163  Fhour=now->tm_hour;
164  Fminute=now->tm_min;
165  // Fseconds=double(now->tm_sec);
166  Fmilsec=1000*now->tm_sec;
167  Fstation="NSP";
168  Fchannel="NSP";
169  Fauxid="NSP";
171  Fsamps=-1;
172  Fsamprate=-1.;
173  Fcalib=-1.;
174  Fcalper=-1.;
175  Finstype="NSP";
176  Fhang=-1.;
177  Fvang=-1.;
178 }
179 
180 /*----------------------------------------------------------------------*/
181 
182 } // namespace waveform
183 } // namespace GSE2
184 
185 /* ----- END OF gsexx_TWID2.cc ----- */
GSE++ library: read and write GSE waveform data (prototypes).
std::string Finstype
instrument type
Definition: gsexx.h:146
std::string Fchannel
FDSN channel code.
Definition: gsexx.h:139
double seconds() const
provide seconds in GSE specific floating point format
Definition: gsexx_TWID2.cc:144
double Fcalib
calibration factor
Definition: gsexx.h:144
double Fsamprate
sampling rate (Hz)
Definition: gsexx.h:143
int Fhour
hour of time
Definition: gsexx.h:135
static const char *const GSEID
GSE line idetifier.
Definition: gsexx.h:114
int Fminute
minute of time
Definition: gsexx.h:136
void setsubformat(const std::string &key)
set subformat from key string
Definition: gsexx_TWID2.cc:66
int Fyear
year of date
Definition: gsexx.h:132
All stuff defined by the GSE2 standard.
int Fmonth
month of date
Definition: gsexx.h:133
void defaults()
set the values to defaults
Definition: gsexx_TWID2.cc:156
Base class for all exceptions in this module.
Definition: gsexx.h:68
Esubformat Fsubformat
GSE2 waveform subformat.
Definition: gsexx.h:141
std::string Fauxid
Auxiliary identification code.
Definition: gsexx.h:140
int Fsamps
number of samples
Definition: gsexx.h:142
std::string line() const
write the WID2 line
Definition: gsexx_TWID2.cc:74
int Fday
day of date
Definition: gsexx.h:134
double Fhang
horizontal orientation
Definition: gsexx.h:147
std::string Fstation
Station code.
Definition: gsexx.h:138
std::string subformat() const
return subformat ID string
Definition: gsexx_TWID2.cc:58
void read(std::istream &is)
read a WID2 line from a stream
Definition: gsexx_TWID2.cc:99
double Fcalper
calibration reference period
Definition: gsexx.h:145
double Fvang
veritcal orientation This field is required to obtain millisecond precision
Definition: gsexx.h:148