16 #include <machine/endian.h>
26 #if __BYTE_ORDER == __LITTLE_ENDIAN
27 output = *((int16_t*)input);
28 #elif __BYTE_ORDER == __BIG_ENDIAN
29 output = ((int16_t)(((
unsigned char*)input)[1]) << 8) | (int16_t)(((
unsigned char*)input)[0]);
31 output = ((
char*)input)[1] * 0x100 + ((
unsigned char*)input)[0];
40 #if __BYTE_ORDER == __LITTLE_ENDIAN
41 output = *((uint16_t*)input);
42 #elif __BYTE_ORDER == __BIG_ENDIAN
43 output = ((uint16_t)(((
unsigned char*)input)[1]) << 8) | (uint16_t)(((
unsigned char*)input)[0]);
45 output = ((
unsigned char*)input)[1] * 0x100 + ((
unsigned char*)input)[0];
53 #if __BYTE_ORDER == __LITTLE_ENDIAN
54 output = *((int32_t*)input);
55 #elif __BYTE_ORDER == __BIG_ENDIAN
56 output = ((int32_t)(((
unsigned char*)input)[3]) << 24) | ((int32_t)(((
unsigned char*)input)[2]) << 16) | ((int32_t)(((
unsigned char*)input)[1]) << 8) | (int32_t)(((
unsigned char*)input)[0]);
58 output = ((
char*)input)[3] * 0x1000000 + ((
unsigned char*)input)[2] * 0x10000 + ((
unsigned char*)input)[1] * 0x100 + ((
unsigned char*)input)[0];
67 const size_t bufsize = 40 * 1024 * 1024;
73 buf = malloc(bufsize);
75 printf(
"failed to allocate memory in read_toshiba");
78 if((fp = fopen(fname,
"r")) == NULL){
82 bsize = fread(buf, 1, bufsize, fp);
84 printf(
"file size is 0: %s\n", fname);
89 if(ierr != 0)
return ierr;
101 const size_t len_bufchd = 96;
102 const size_t len_bufpcd = 320;
103 const size_t len_bufblk = 64;
104 unsigned char *bufchd, *bufpcd, *bufblk, *bufdat;
106 float s_az, e_az, s_el, e_el;
107 float tx_pilot,return_pilot;
108 int i,
j,
k, iss, i0, i1, i2, i3, rnum, aznum, elnum;
109 int r_byte, irb, irb1, irb2;
110 int ios_obs, ios_spec, ios_loc, ios_rt, ios_mesh;
111 int ideg, ibunshi, ibunbo;
112 int prf, hit_num, long_pulse;
113 const float ideg2deg = (180.0 / 8192.0);
122 for(
k = 0;
k < elnum;
k++) {
125 if(buf_offset == bufsize) {
128 }
else if(buf_offset + len_bufchd > bufsize) {
129 printf(
"# abnormal record length in common header\n");
132 bufchd = buf + buf_offset;
133 buf_offset += len_bufchd;
135 hd->
s_yr = 1000 * (bufchd[20] >> 4) + 100 * (bufchd[20] & 15) + 10 * (bufchd[21] >> 4) + (bufchd[21] & 15);
136 hd->
s_mn = 10 * (bufchd[22] >> 4) + (bufchd[22] & 15);
137 hd->
s_dy = 10 * (bufchd[23] >> 4) + (bufchd[23] & 15);
138 hd->
s_hr = 10 * (bufchd[24] >> 4) + (bufchd[24] & 15);
139 hd->
s_mi = 10 * (bufchd[25] >> 4) + (bufchd[25] & 15);
140 hd->
s_sc = 10 * (bufchd[26] >> 4) + (bufchd[26] & 15);
141 hd->
e_yr = 1000 * (bufchd[28] >> 4) + 100 * (bufchd[28] & 15) + 10 * (bufchd[29] >> 4) + (bufchd[29] & 15);
142 hd->
e_mn = 10 * (bufchd[30] >> 4) + (bufchd[30] & 15);
143 hd->
e_dy = 10 * (bufchd[31] >> 4) + (bufchd[31] & 15);
144 hd->
e_hr = 10 * (bufchd[32] >> 4) + (bufchd[32] & 15);
145 hd->
e_mi = 10 * (bufchd[33] >> 4) + (bufchd[33] & 15);
146 hd->
e_sc = 10 * (bufchd[34] >> 4) + (bufchd[34] & 15);
147 hd->
data_size = 0x10000 * bufchd[10] + 0x100 * bufchd[9] + bufchd[8];
150 if(buf_offset + len_bufpcd > bufsize) {
151 printf(
"# abnormal record length in polar-coords-data header\n");
154 bufpcd = buf + buf_offset;
155 buf_offset += len_bufpcd;
164 hd->
el_num = bufpcd[ios_obs + 10];
236 for(
j = 0;
j < aznum;
j++) {
239 if(buf_offset + len_bufblk > bufsize) {
240 printf(
"# abnormal record length in data block\n");
243 bufblk = buf + buf_offset;
244 buf_offset += len_bufblk;
251 long_pulse = bufblk[34];
271 bufdat = buf + buf_offset;
279 for(
i = 0;
i < rnum;
i++) {
283 for(
i = 0;
i < rnum;
i++) {