10 pEnd = (
unsigned char *)p + numValues*bytesPerPoint;
11 while (p < (
void *)pEnd) {
13 p2 = (
char *)p + bytesPerPoint-1;
19 p = (
unsigned char *)p + bytesPerPoint;
160Checksum(
short *data,
int needToReorderBytes,
int oldcksum,
int numbytes)
165 while(numbytes-- > 0) {
167 if (needToReorderBytes)
171 return oldcksum&0xffff;
181 int numBytesPerPoint;
186 numBytesPerPoint = 1;
189 numBytesPerPoint = 2;
192 numBytesPerPoint = 4;
195 numBytesPerPoint = 4;
198 numBytesPerPoint = 8;
206 numBytesPerPoint *= 2;
208 return numBytesPerPoint;
229 int numBytesPerPoint;
230 unsigned long numBytesToRead, numBytesToAllocate;
231 unsigned long numBytesRead;
238 if (numBytesPerPoint <= 0) {
239 printf(
"Invalid wave type (0x%x).\n", type);
242 numBytesToRead = npnts * numBytesPerPoint;
244 numBytesToAllocate = numBytesToRead;
245 if (numBytesToAllocate == 0)
246 numBytesToAllocate = 8;
247 p = malloc(numBytesToAllocate);
249 printf(
"Unable to allocate %ld bytes to store data.\n", numBytesToAllocate);
252 if (numBytesToRead > 0) {
253 if (waveDataSize < numBytesToRead) {
259 memset(p, 0, numBytesToRead);
262 if (err =
CPReadFile(fr, numBytesToRead, p, &numBytesRead)) {
264 printf(
"Error %d occurred while reading the wave data.\n", err);
267 if (needToReorderBytes) {
269 ReorderBytes(p, numBytesPerPoint, numBytesToRead/numBytesPerPoint);
295ReadWave(
CP_FILE_REF fr,
int* typePtr,
long* npntsPtr,
long* ndimptr,
double* sfa,
double* sfb,
void** waveDataPtrPtr,
char **
name)
297 unsigned long startFilePos;
300 int binHeaderSize, waveHeaderSize, checkSumSize;
301 unsigned long waveDataSize;
302 unsigned long numBytesRead;
303 int needToReorderBytes;
305 unsigned long modDate;
310 (* name) = (
char *) malloc(64);
312 *waveDataPtrPtr = NULL;
321 printf(
"Error %d occurred while reading the file version.\n", err);
330 needToReorderBytes = (
version & 0xFF) == 0;
331 if (needToReorderBytes)
340 checkSumSize = binHeaderSize + waveHeaderSize;
346 checkSumSize = binHeaderSize + waveHeaderSize;
352 checkSumSize = binHeaderSize + waveHeaderSize;
358 checkSumSize = binHeaderSize + waveHeaderSize - 4;
368 if (err =
CPReadFile(fr, binHeaderSize+waveHeaderSize, buffer, &numBytesRead)) {
374 check =
Checksum((
short*)buffer, needToReorderBytes, 0, checkSumSize);
382 if (needToReorderBytes) {
478 ndimptr[0] = w5->
nDim[0];
479 ndimptr[1] = w5->
nDim[1];
480 ndimptr[2] = w5->
nDim[2];
481 ndimptr[3] = w5->
nDim[3];
505 waveDataSize = wfmSize - offsetof(
WaveHeader2, wData) - 16;
508 waveDataSize = wfmSize - offsetof(
WaveHeader5, wData);
531 if (err =
LoadNumericWaveData(fr, type, npnts, waveDataSize, needToReorderBytes, waveDataPtrPtr))
struct BinHeader2 BinHeader2
struct WaveHeader2 WaveHeader2
struct BinHeader5 BinHeader5
struct WaveHeader5 WaveHeader5
struct BinHeader1 BinHeader1
struct BinHeader3 BinHeader3
static int Checksum(short *data, int needToReorderBytes, int oldcksum, int numbytes)
static int LoadNumericWaveData(CP_FILE_REF fr, int type, long npnts, unsigned long waveDataSize, int needToReorderBytes, void **pp)
static void ReorderBinHeader2(BinHeader2 *p)
int ReadWave(CP_FILE_REF fr, int *typePtr, long *npntsPtr, long *ndimptr, double *sfa, double *sfb, void **waveDataPtrPtr, char **name)
static void ReorderBinHeader5(BinHeader5 *p)
static void ReorderLong(void *lp)
static void ReorderBytes(void *p, int bytesPerPoint, long numValues)
static void ReorderShort(void *sp)
static int NumBytesPerPoint(int type)
static void ReorderBinHeader3(BinHeader3 *p)
static void ReorderBinHeader1(BinHeader1 *p)
static void ReorderWaveHeader2(WaveHeader2 *p)
static void ReorderDouble(void *dp)
static void ReorderWaveHeader5(WaveHeader5 *p)