GSE++ library: reading and writing GSE waveforms

◆ decode()

intT GSE2::waveform::CM6::decode ( std::istream &  is)

CM6 subformat decoding function.

The function decodes an integer value from CM6 subformat. It takes an input stream to read from. This is necessary since the function has to skip line-ends on its own. If you want to read from a character string, use string streams. The numerical value returned is just the next decoded integer value from the stream. It is a second difference value. You still have to remove second differences afterwards.

Author
Thomas Forbriger, Stefan Stange and others (see comments in the source code)
Parameters
isinput stream to read from
Returns
next integer value decoded from stream.
See also
GSE2::waveform::TDAT2readCM6

Definition at line 191 of file gsexx_cm6.cc.

Referenced by GSE2::waveform::TDAT2readCM6::convert().

192 {
193 // The original version of the core of this function was coded by Stefan
194 // Stange. The code (decomp_6b) can be found in gse_functions.c in his
195 // library. Here is the original comment by Stefan Stange:
196 
197 /*********************************************************************
198 * Function: decomp_6b
199 * This routine evolves the data series from the 6Byte encoding according
200 * GSE2.0 based on dcomp6.f in CODECO by Urs Kradolfer.
201 * Input is the character representation (meaning the file pointer to it),
202 * the number of samples to be expected and the pointer to the data.
203 * Output is the data series in LONG (has to be allocated elsewhere!).
204 * The GSE file must be opened and positioned to or before the "DAT2" line.
205 * Returns actual # of samples or -1 as error code.
206 * Calls no other routines.
207 * St. Stange, 1.10.1998 , verified for PC-byte-sex 11.4.2001
208 *********************************************************************/
209  static int ichar[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
210  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,2,3,4,5,6,7,
211  8,9,10,11,0,0,0,0,0,0,0,12,13,14,15,16,17,18,19,20,21,22,
212  23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,0,0,0,0,0,0,
213  38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,
214  57,58,59,60,61,62,63,0,0,0,0,0,0},/*1 more than in FORTRAN*/
215  isign=020, ioflow=040, mask1=017, mask2=037, m127=0177;
216 
217  int k, inn, jsign=0, joflow=0;
218  char inchar; // character just read from stream
219  intT retval; // decoded samples
220 
221  // read next
222  is.get(inchar);
223  while (inchar == '\n') { is.get(inchar); }
224  if (isspace(inchar))
225  throw Terror("ERROR (CM6::decode): illegal whitespace");
226  if (is.eof())
227  throw Terror("ERROR (CM6::decode): illegal end of file");
228 
229  /* get ascii code of input character, strip off any higher bits
230  (don't know whether it does what it says) and get number representation */
231 
232  k = int(int(inchar) & m127);
233  inn = ichar[k];
234 
235  jsign = (inn & isign); /* get sign bit */
236  joflow = (inn & ioflow); /* get continuation bit if any */
237  retval = (long)(inn & mask1); /* remove dispensable bits and store */
238 
239  while (joflow != 0) /* loop over other bytes in sample */
240  {
241  retval <<= 5; /* multiply with 32 for next byte */
242 
243  // read next
244  is.get(inchar);
245  while (inchar == '\n') { is.get(inchar); }
246  if (isspace(inchar))
247  throw Terror("ERROR (CM6::decode): illegal whitespace");
248  if (is.eof())
249  throw Terror("ERROR (CM6::decode): illegal end of file");
250 
251  /* now the same procedure as above */
252  k = int(int(inchar) & m127);
253  inn = ichar[k];
254  joflow = (inn & ioflow); /* get continuation bit if any */
255  retval = retval + intT(inn & mask2); /* remove bits and store */
256 
257  } /* finish up sample if there is no further continuation bit */
258 
259  if (jsign != 0) retval = -retval; /* evaluate sign bit */
260 
261  return(retval);
262 } // decode
int intT
All GSE2 waveform data is based on 4 byte integers.
Definition: gsexx.h:89
Here is the caller graph for this function: