DATRW++ library: seismic data I/O with multiple formats

◆ readsample()

Tvalue datrw::pdas::readsample ( std::istream &  is,
const Etype type 
)

function to read one sample

Definition at line 182 of file pdasread.cc.

References DATRW_abort, FtypeGAINRANGED, FtypeINT, and FtypeLONG.

Referenced by countdata(), and readdata().

183  {
184  int invalue;
185  Tvalue value;
186  union Byte {
187  char inchar;
188  unsigned char byte;
189  }; // union byte
190  if (type==FtypeINT)
191  {
192  Byte lbyte, hbyte;
193  if (is.eof()) throw FoundEOF();
194  is.get(lbyte.inchar);
195  if (is.eof()) throw FoundEOF();
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); }
200  }
201  else if (type==FtypeLONG)
202  {
203  union Long {
204  // long int ival;
205  int ival;
206  char byte[4];
207  unsigned char ubyte[4];
208  }; // union Long
209  Long inval;
210  if (is.eof()) throw FoundEOF();
211  is.get(inval.byte[0]);
212  if (is.eof()) throw FoundEOF();
213  is.get(inval.byte[1]);
214  if (is.eof()) throw FoundEOF();
215  is.get(inval.byte[2]);
216  if (is.eof()) throw FoundEOF();
217  is.get(inval.byte[3]);
218  value=inval.ival;
219  }
220  else if (type==FtypeGAINRANGED)
221  {
222  // DATRW_abort("gainranged format ist not supported");
223  union Short {
224  short int ival;
225  char byte[2];
226  unsigned char ubyte[2];
227  }; // union Short
228  Short inval;
229  if (is.eof()) throw FoundEOF();
230  is.get(inval.byte[0]);
231  if (is.eof()) throw FoundEOF();
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;
240  /*
241  std::cerr
242  << inval.ival << " "
243  << Smantissa.ival << " "
244  << mantissa << " "
245  << exponent << " "
246  << shifts << " "
247  << factor << " "
248  << value << " " << std::endl;
249  */
250  }
251  else
252  {
253  DATRW_abort("ERROR: unsupported data type!");
254  }
255  return(value);
256  }
int Tvalue
Definition: pdasread.h:75
#define DATRW_abort(M)
Abort and give a message.
Definition: error.h:101
Here is the caller graph for this function: