1 |
/************************************************************ |
2 |
* 20/9/2005 modified by david fedele to read buffer-data |
3 |
* instead raw-data-file |
4 |
************************************************************** |
5 |
* include needed system headers |
6 |
*/ |
7 |
#include <stdio.h> /* include standard i/o library */ |
8 |
#include <stdlib.h> /* include standard library */ |
9 |
#include <string.h> /* include string library */ |
10 |
#include <unistd.h> /* include unix standard library */ |
11 |
#include <sys/types.h> /* */ |
12 |
#include <sys/stat.h> /* */ |
13 |
#include <fcntl.h> /* */ |
14 |
#include <errno.h> /* error simbol definitions */ |
15 |
#include <time.h> /* system time definitions */ |
16 |
#include <math.h> /* math library */ |
17 |
/************************************************************ |
18 |
* 20/9/2005 modified by david fedele */ |
19 |
/*void readped_(float *ped_buf, int *error, int *fd)*/ |
20 |
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); |
21 |
|
22 |
|
23 |
void readped_(float *ped_buf, int *error,char *buffer, int *len,int *curpos) |
24 |
/**************************************************************/ |
25 |
|
26 |
{ |
27 |
|
28 |
int i; |
29 |
unsigned int decimals,units; |
30 |
unsigned int word; |
31 |
unsigned int ped_buf_temp[1024]; |
32 |
|
33 |
*error=0; |
34 |
/************************************************************ |
35 |
* 20/9/2005 modified by david fedele */ |
36 |
/* int nread; */ |
37 |
|
38 |
/* /\*** read the buffer ***\/ */ |
39 |
/* nread=read(*fd, ped_buf_temp, 2*1024); */ |
40 |
/* if( nread==0 ) { */ |
41 |
/* printf("readped: Unexpected end of file %d at %d \n",*fd,nread); */ |
42 |
/* *error=1; */ |
43 |
/* return ; */ |
44 |
/* } */ |
45 |
/* if ( nread != 2*1024) { */ |
46 |
/* printf("readped: Error on reading: nread = %d \n",nread); */ |
47 |
/* *error=-1; */ |
48 |
/* return ; */ |
49 |
/* } */ |
50 |
|
51 |
|
52 |
/* /\*** correct byte ***\/ //endianess... */ |
53 |
/* for(i=0; i<1024; i++) { */ |
54 |
/* word = ped_buf_temp[i]; */ |
55 |
/* ped_buf_temp[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */ |
56 |
/* } */ |
57 |
|
58 |
int nbytes2=2; |
59 |
char *buff=buffer; |
60 |
|
61 |
if( *curpos+(2*1024)-1>*len ) { |
62 |
printf("readped: Unexpected end of file\n"); |
63 |
*error=1; |
64 |
return ; |
65 |
} |
66 |
|
67 |
for(i=0; i<1024; i++) |
68 |
getbytes_(&nbytes2,buff,curpos,&ped_buf_temp[i]); |
69 |
|
70 |
|
71 |
/*****************************************************************/ |
72 |
|
73 |
/***interpreta*/ |
74 |
for(i=0; i<1024; i++) { |
75 |
|
76 |
word = ped_buf_temp[i]; |
77 |
units = ( (word >> 4) & 0x0fff ) ; |
78 |
decimals = (word & 0x000f) ; |
79 |
ped_buf[i] = (float)units + (float)decimals / 16.; |
80 |
// printf("%i %i %i %f \n",i,units,decimals,ped_buf[i]); |
81 |
} |
82 |
|
83 |
|
84 |
// for( i=0; i<1024; i++) printf("%x \n",ped_buf[i]);//??? |
85 |
|
86 |
return; |
87 |
} |