41 #define DATRW_PDASREAD_CC_VERSION \ 42 "DATRW_PDASREAD_CC V1.3" 45 #include <datrwxx/pdasread.h> 58 DATRW_assert(is.good(),
"ERROR: unexpected end of file!");
59 std::getline(is, retval.
line);
61 unsigned long long int delim=retval.
line.find_first_of(0x0D);
62 retval.
line.erase(delim);
64 delim=retval.
line.find_first_of(
' ');
65 if (delim!=std::string::npos)
72 std::cout <<
"line: " << retval.
line << std::endl;
73 std::cout <<
" token: \"" << retval.
token <<
"\"" << std::endl;
74 std::cout <<
" value: \"" << retval.
value <<
"\"" << std::endl;
86 while (hdline.
line!=
"DATA")
90 if (hdline.
token==
"DATASET")
92 else if (hdline.
token==
"SIGNAL")
94 else if (hdline.
token==
"VERSION")
96 else if (hdline.
token==
"DATE")
98 else if (hdline.
token==
"TIME")
100 else if (hdline.
token==
"INTERVAL")
102 else if (hdline.
token==
"VERT_UNITS")
104 else if (hdline.
token==
"HORZ_UNITS")
106 else if (hdline.
token==
"COMMENT")
111 if (hdline.
value==
"GAINRANGED")
115 else if (hdline.
token==
"FILE_TYPE")
117 if (hdline.
value==
"INT")
119 else if (hdline.
value==
"LONG")
127 std::cout <<
"dataset: " << retval.
dataset << std::endl;
128 std::cout <<
"signal: " << retval.
signal << std::endl;
129 std::cout <<
"version: " << retval.
version << std::endl;
130 std::cout <<
"date: " << retval.
date << std::endl;
131 std::cout <<
"time: " << retval.
time << std::endl;
132 std::cout <<
"interval: " << retval.
interval << std::endl;
133 std::cout <<
"vert units: " << retval.
vertunits << std::endl;
134 std::cout <<
"horz units: " << retval.
horzunits << std::endl;
135 std::cout <<
"comment: " << retval.
comment << std::endl;
136 std::cout <<
"data type: ";
138 { std::cout <<
"INT integer" << std::endl; }
140 { std::cout <<
"unknown!" << std::endl; }
154 while(is.good()&&hot)
159 if (hot)
data.push_back(sample);
170 while(is.good()&&hot)
173 catch (
FoundEOF) { hot=
false; --retval; }
194 is.get(lbyte.inchar);
196 is.get(hbyte.inchar);
197 invalue=int(lbyte.byte)+256*int(hbyte.byte);
198 if (
int(hbyte.byte)>127)
199 { value=
Tvalue(invalue-65536); }
else { value=
Tvalue(invalue); }
207 unsigned char ubyte[4];
211 is.get(inval.byte[0]);
213 is.get(inval.byte[1]);
215 is.get(inval.byte[2]);
217 is.get(inval.byte[3]);
226 unsigned char ubyte[2];
230 is.get(inval.byte[0]);
232 is.get(inval.byte[1]);
233 Short Smantissa=inval;
234 Smantissa.ubyte[0]=(inval.ubyte[0] & 0xFC);
235 int mantissa=Smantissa.ival/4;
236 unsigned short int exponent=(inval.ubyte[0] & 0x03);
237 int shifts=(5-exponent)*3;
238 int factor=(1<<shifts);
239 value=mantissa*factor;
265 os <<
"PDAS data reading functions" << std::endl;
266 os <<
"---------------------------" << std::endl;
269 <<
"The scaling of the data samples depends on the data format" << endl
270 <<
"used store original PDAS data files. The sacling is defined" << endl
271 <<
"in section 4.1.7.2 on pages 4-15 and 4-16 in the PDAS" << endl
272 <<
"user's guide. The definitions are:" << endl << endl
273 <<
" 16-bit data format" << endl
274 <<
" Data is stored in two byte integer two's complement format." 276 <<
" m: digitized value in counts" << endl
277 <<
" p: pre-amplifier gain" << endl
278 <<
" v: signal value in volts" << endl
279 <<
" v = m / (32768 * p) for high gain inputs" << endl
280 <<
" v = 20 * m / (32768 * p) for low gain inputs" << endl
281 <<
" where 32768 = 2**15 = 0x8000" << endl << endl
282 <<
" 32-bit data format" << endl
283 <<
" Data is stored in four byte integer two's complement format." 285 <<
" m: digitized value in counts" << endl
286 <<
" v: signal value in volts" << endl
287 <<
" v = m / (2147483648) for high gain inputs" << endl
288 <<
" v = 20 * m / (2147483648) for low gain inputs" << endl
289 <<
" where 2147483648 = 2**31 = 0x80000000" << endl << endl
290 <<
" 14/2 gain ranged format" << endl
291 <<
" The data is stored in two byte format. The gain code" << endl
292 <<
" is stored in the two least significant bits of the" << endl
293 <<
" 16 bits and the digitized value is in the upper 14" << endl
294 <<
" bits of the 16 bits." << endl
295 <<
" g: gain code from the lower two bits" << endl
296 <<
" p: pre-amplifier gain" << endl
297 <<
" m: two's complement value from the upper 14 bits" << endl
298 <<
" v: signal value in volts" << endl
299 <<
" v = m * (8**(5-g)) / ( 268435456 * p) " 300 <<
"for high gain inputs" << endl
301 <<
" v = 20 * m * (8**(5-g)) / ( 268435456 * p) " 302 <<
"for low gain inputs" << endl
303 <<
" where 268435456 = 2**28 = 0x10000000" << endl << endl;
305 <<
"Scaling applied by the reading functions:" << endl
306 <<
" The PDAS data files contain no information about the" << endl
307 <<
" pre-amplifier setting and about the input terminals" << endl
308 <<
" (high or low gain) used. The data can thus not be" << endl
309 <<
" scaled to volts. The conversion applied when reading is" << endl
310 <<
" m and g: as defined above" << endl
311 <<
" i: value returned by integer reading function (iseries)" << endl
312 <<
" f: value returned by float reading functions " 313 <<
"(fseries and dseries)" << endl
314 <<
" 16-bit data (indicated as INT in the FILE_TYPE field)" << endl
316 <<
" f = m / 32768 " << endl
317 <<
" 32-bit data (indicated as LONG in the FILE_TYPE field)" << endl
319 <<
" f = m / 2147483648 " << endl
320 <<
" 14/2 bit data (indicated as GAINRANGED in the COMMENT field)" 322 <<
" i = m * (8**(5-g))" << endl
323 <<
" f = m * (8**(5-g)) / 268435456 " << endl << endl
324 <<
" Thus if extracting floating point numbers from 16-bit" << endl
325 <<
" or 14/2-bit data files, you just have to apply" << endl
326 <<
" v = f / p for high gain inputs and" << endl
327 <<
" v = 20 * f / p for low gain inputs," << endl
328 <<
" where p is the pre-amplifier gain" << endl
329 <<
" to obtain the signal in volts." << endl << endl
330 <<
" For 32-bit data its even easier. You obtain the" << endl
331 <<
" signal's voltage by" << endl
332 <<
" v = f for high gain inputs and" << endl
333 <<
" v = 20 * f for low gain inputs." << endl;
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Etype
define pdas data types
exception class declaration for libdatrwxx (prototypes)
const char *const data
keywords for consistency checks
Tvalue readsample(std::istream &is, const Etype &type)
function to read one sample
Root namespace of library.
void readdata(std::istream &is, Tdata &data, const Etype &type)
HeaderLine readline(std::istream &is, const bool &verbose)
function to read the file header line
#define DATRW_abort(M)
Abort and give a message.
void help(std::ostream &os)
function to print online help
Header readheader(std::istream &is, const bool &verbose)
function to read the file header
int countdata(std::istream &is, const Etype &type)
function to skip the file data but count the samples
std::vector< Tvalue > Tdata