22 #include <machine/endian.h>
73 unsigned char *outbuf;
79 outbuf = (
unsigned char*)malloc(outbufsize);
81 printf(
"malloc failed in ungzip_toshiba_mpr\n");
87 ret = inflateInit2(&strm, 47);
90 strm.avail_in = bufsize;
91 strm.next_out = outbuf;
92 strm.avail_out = outbufsize;
93 ret = inflate(&strm, Z_NO_FLUSH);
95 datsize = outbufsize - strm.avail_out;
97 memcpy(buf, outbuf, datsize);
98 printf(
"maxbuf: %d, inbuf: %d, outbuf: %d\n",
99 outbufsize, bufsize, datsize);
101 ret = inflateEnd(&strm);
123 buf = malloc(bufsize);
125 printf(
"failed to allocate memory in read_toshiba");
128 if((fp = fopen(in_file,
"r")) == NULL){
130 if((fp = fopen(strcat(in_file,
".gz"),
"r")) == NULL){
135 bsize = fread(buf, 1, bufsize, fp);
137 printf(
"file size is 0: %s\n", in_file);
144 if(ierr != 0)
return ierr;
159 unsigned char *bufrdhd;
160 unsigned char *bufpbhd;
161 unsigned char *bufelhd;
162 unsigned char *bufdat;
163 int i,
j,
k, iss, i0, i1, i2, i3;
164 int aznum, elnum, rnum, sp_rnum, lp_rnum;
165 int r_byte, irb, mesh_size, data_size;
166 int ideg, ideg_tc, inum, ibunshi, ibunbo;
167 int s1_yr, s1_mn, s1_dy, s1_hr, s1_mi, s1_sc;
168 int s2_yr, s2_mn, s2_dy, s2_hr, s2_mi, s2_sc;
169 int s3_yr, s3_mn, s3_dy, s3_hr, s3_mi, s3_sc;
170 int el_num_sec, cpi_num, sec_num, rnum1;
171 int hit_num, spa_num, lpa_num, spv_num, lpv_num;
172 int pw_hsp, pw_hlp, pw_vsp, pw_vlp, prf;
173 float mesh_lsb, mesh_offset;
174 float start_az_sec, end_az_sec, start_el_sec, end_el_sec;
175 float start_az_cpi, end_az_cpi, start_el_cpi, end_el_cpi;
176 float lower_el_angle, upper_el_angle;
177 float tx_freq_h, tx_freq_v, tx_power_h, tx_power_v;
178 float tx_plen_hs, tx_plen_hl, tx_plen_vs, tx_plen_vl;
179 float tx_antgain_h, tx_antgain_v, rx_antgain_h, rx_antgain_v;
180 float hori_beamwidth_h, hori_beamwidth_v, vert_beamwidth_h, vert_beamwidth_v;
181 float start_obs_az, start_obs_el, end_obs_az, end_obs_el;
184 const float ideg2deg = 360.0 / 65536.0;
185 const float ideg_tc2deg = 180.0 / 32768.0;
195 if(buf_offset == bufsize) {
198 printf(
"# abnormal record length (RDhd)\n");
201 bufrdhd = buf + buf_offset;
204 strncpy(hd->
data_name, &bufrdhd[16], 32);
205 hd->
s_yr = 1000 * (bufrdhd[48] >> 4) + 100 * (bufrdhd[48] & 15) + 10 * (bufrdhd[49] >> 4) + (bufrdhd[49] & 15);
206 hd->
s_mn = 10 * (bufrdhd[50] >> 4) + (bufrdhd[50] & 15);
207 hd->
s_dy = 10 * (bufrdhd[51] >> 4) + (bufrdhd[51] & 15);
208 hd->
s_hr = 10 * (bufrdhd[52] >> 4) + (bufrdhd[52] & 15);
209 hd->
s_mi = 10 * (bufrdhd[53] >> 4) + (bufrdhd[53] & 15);
210 hd->
s_sc = 10 * (bufrdhd[54] >> 4) + (bufrdhd[54] & 15);
211 hd->
e_yr = 1000 * (bufrdhd[56] >> 4) + 100 * (bufrdhd[56] & 15) + 10 * (bufrdhd[57] >> 4) + (bufrdhd[57] & 15);
212 hd->
e_mn = 10 * (bufrdhd[58] >> 4) + (bufrdhd[58] & 15);
213 hd->
e_dy = 10 * (bufrdhd[59] >> 4) + (bufrdhd[59] & 15);
214 hd->
e_hr = 10 * (bufrdhd[60] >> 4) + (bufrdhd[60] & 15);
215 hd->
e_mi = 10 * (bufrdhd[61] >> 4) + (bufrdhd[61] & 15);
216 hd->
e_sc = 10 * (bufrdhd[62] >> 4) + (bufrdhd[62] & 15);
218 s1_yr = 1000 * (bufrdhd[64] >> 4) + 100 * (bufrdhd[64] & 15) + 10 * (bufrdhd[65] >> 4) + (bufrdhd[65] & 15);
219 s1_mn = 10 * (bufrdhd[66] >> 4) + (bufrdhd[66] & 15);
220 s1_dy = 10 * (bufrdhd[67] >> 4) + (bufrdhd[67] & 15);
221 s1_hr = 10 * (bufrdhd[68] >> 4) + (bufrdhd[68] & 15);
222 s1_mi = 10 * (bufrdhd[69] >> 4) + (bufrdhd[69] & 15);
223 s1_sc = 10 * (bufrdhd[70] >> 4) + (bufrdhd[70] & 15);
224 s2_yr = 1000 * (bufrdhd[72] >> 4) + 100 * (bufrdhd[72] & 15) + 10 * (bufrdhd[73] >> 4) + (bufrdhd[73] & 15);
225 s2_mn = 10 * (bufrdhd[74] >> 4) + (bufrdhd[74] & 15);
226 s2_dy = 10 * (bufrdhd[75] >> 4) + (bufrdhd[75] & 15);
227 s2_hr = 10 * (bufrdhd[76] >> 4) + (bufrdhd[76] & 15);
228 s2_mi = 10 * (bufrdhd[77] >> 4) + (bufrdhd[77] & 15);
229 s2_sc = 10 * (bufrdhd[78] >> 4) + (bufrdhd[78] & 15);
230 s3_yr = 1000 * (bufrdhd[80] >> 4) + 100 * (bufrdhd[80] & 15) + 10 * (bufrdhd[81] >> 4) + (bufrdhd[81] & 15);
231 s3_mn = 10 * (bufrdhd[82] >> 4) + (bufrdhd[82] & 15);
232 s3_dy = 10 * (bufrdhd[83] >> 4) + (bufrdhd[83] & 15);
233 s3_hr = 10 * (bufrdhd[84] >> 4) + (bufrdhd[84] & 15);
234 s3_mi = 10 * (bufrdhd[85] >> 4) + (bufrdhd[85] & 15);
235 s3_sc = 10 * (bufrdhd[86] >> 4) + (bufrdhd[86] & 15);
236 strncpy(hd->
site_name, &bufrdhd[136], 32);
240 strncpy(hd->
sq_name, &bufrdhd[216], 16);
242 hd->
el_num = bufrdhd[236 + 1];
251 mesh_lsb = (
float)ibunshi / (
float)ibunbo;
254 mesh_offset = (
float)ibunshi / (
float)ibunbo;
260 if (opt_verbose >= 1){
262 printf(
"## data name: %s\n", hd->
data_name);
263 printf(
"## scan collection start/end time: ");
264 printf(
"%d/%d/%d, %d:%d:%d - %d/%d/%d, %d:%d:%d\n",
267 printf(
"## scan start time (s1): %d/%d/%d, %d:%d:%d\n",
268 s1_yr, s1_mn, s1_dy, s1_hr, s1_mi, s1_sc);
269 printf(
"## sequence start time (s2): %d/%d/%d, %d:%d:%d\n",
270 s2_yr, s2_mn, s2_dy, s2_hr, s2_mi, s2_sc);
271 printf(
"## mode start time (s3): %d/%d/%d, %d:%d:%d\n",
272 s3_yr, s3_mn, s3_dy, s3_hr, s3_mi, s3_sc);
273 printf(
"## site name: %s", hd->
site_name);
274 printf(
" lat=%7.4f, lon=%8.4f, alt=%6.2f\n",
276 printf(
"## sequence name: %s", hd->
sq_name);
282 printf(
"## mesh size=%d, LSB=%7.3f, offset=%7.3f\n",
283 mesh_size, mesh_lsb, mesh_offset);
287 printf(
"# abnormal mesh size: %d bit\n", mesh_size);
288 printf(
"# this program (read_toshiba_mpr) is not supported !\n");
295 printf(
"# abnormal AZ dimension: %d (> %d)\n", aznum,
AZDIM);
298 for(
j = 0;
j < aznum;
j++) {
300 if(buf_offset == bufsize) {
303 printf(
"# abnormal record length (PB header)\n");
306 bufpbhd = buf + buf_offset;
310 if (opt_verbose >= 2){
311 el_num_sec = bufpbhd[9];
314 start_az_sec =
char2uint16(bufpbhd + 16) * ideg2deg;
315 start_el_sec =
char2int16(bufpbhd + 18) * ideg_tc2deg;
317 end_el_sec =
char2int16(bufpbhd + 22) * ideg_tc2deg;
318 lower_el_angle =
char2int16(bufpbhd + 26) * ideg_tc2deg;
319 upper_el_angle =
char2int16(bufpbhd + 30) * ideg_tc2deg;
320 if(lower_el_angle > 180.0) lower_el_angle -= 360.0;
323 printf(
"## Polar Block (RAY) header: j=%d\n",
j);
324 printf(
" el_num_sec=%d, cpi_num=%d, sec_num=%d | rnum=%d\n",
325 el_num_sec, cpi_num, sec_num, rnum);
326 printf(
" start/end AZ in sector=%6.2f-%6.2f ",
327 start_az_sec, end_az_sec);
328 printf(
" start/end EL of pedestal=%6.2f-%6.2f ",
329 start_el_sec, end_el_sec);
330 printf(
" lower/upper EL angle=%6.2f-%6.2f\n",
331 lower_el_angle, upper_el_angle);
337 printf(
"# abnormal EL dimension: %d (> %d)\n", elnum,
ELDIM);
340 for(
k = 0;
k < elnum;
k++) {
343 if(buf_offset == bufsize) {
346 printf(
"# abnormal record length (EL header)\n");
349 bufelhd = buf + buf_offset;
353 if (opt_verbose >= 3){
363 start_az_cpi =
char2uint16(bufelhd + 128) * ideg2deg;
364 start_el_cpi =
char2int16(bufelhd + 130) * ideg_tc2deg;
365 end_az_cpi =
char2uint16(bufelhd + 132) * ideg2deg;
366 end_el_cpi =
char2int16(bufelhd + 134) * ideg_tc2deg;
369 pw_hsp = bufelhd[144];
370 pw_hlp = bufelhd[145];
371 pw_vsp = bufelhd[146];
372 pw_vlp = bufelhd[147];
374 tx_freq_h = 0.0001 *
char2int32(bufelhd + 176);
375 tx_freq_v = 0.0001 *
char2int32(bufelhd + 180);
376 tx_power_h = 0.0001 *
char2int32(bufelhd + 184);
377 tx_power_v = 0.0001 *
char2int32(bufelhd + 188);
378 tx_plen_hs = 0.0001 *
char2int32(bufelhd + 192);
379 tx_plen_hl = 0.0001 *
char2int32(bufelhd + 196);
380 tx_plen_vs = 0.0001 *
char2int32(bufelhd + 200);
381 tx_plen_vl = 0.0001 *
char2int32(bufelhd + 204);
382 tx_antgain_h = 0.0001 *
char2int32(bufelhd + 208);
383 tx_antgain_v = 0.0001 *
char2int32(bufelhd + 212);
384 rx_antgain_h = 0.0001 *
char2int32(bufelhd + 216);
385 rx_antgain_v = 0.0001 *
char2int32(bufelhd + 220);
386 hori_beamwidth_h = 0.0001 *
char2int32(bufelhd + 224);
387 hori_beamwidth_v = 0.0001 *
char2int32(bufelhd + 228);
388 vert_beamwidth_h = 0.0001 *
char2int32(bufelhd + 232);
389 vert_beamwidth_v = 0.0001 *
char2int32(bufelhd + 236);
392 printf(
"## EL header (%d byte): j=%d k=%d | ", data_size,
j,
k);
393 printf(
" hit_num=%d, cpi_num=%d, prf=%d,",
394 hit_num, cpi_num, prf);
395 printf(
" spv/a=%d/%d, lpv/a=%d/%d\n",
396 spv_num, spa_num, lpv_num, lpa_num);
398 if (opt_verbose >= 4){
399 printf(
" start/end AZ in cpi=%6.2f-%6.2f\n",
400 start_az_sec, end_az_sec);
401 printf(
" start/end EL in cpi=%6.2f-%6.2f\n",
402 start_el_sec, end_el_sec);
403 printf(
" < pw_short pulse: 0=0.5us, 1=1.0us, 2=2.0us, 3=4.0us >\n");
404 printf(
" < pw_long pulse: 0=24us, 1=32us, 2=48us, 3=72us >\n");
405 printf(
" pw_hsp=%d, pw_hlp=%d, pw_vsp=%d, pw_vlp=%d\n",
406 pw_hsp, pw_hlp, pw_vsp, pw_vlp);
407 printf(
" tx_freq_h=%.1f, tx_freq_v=%.1f, ",
408 tx_freq_h, tx_freq_v);
409 printf(
"tx_power_h=%.1f, tx_power_v=%.1f\n",
410 tx_power_h, tx_power_v);
411 printf(
" tx_plen_hs=%.1f, tx_plen_hl=%.1f, ",
412 tx_plen_hs, tx_plen_hl);
413 printf(
"tx_plen_vs=%.1f, tx_plen_vl=%.1f\n",
414 tx_plen_vs, tx_plen_vl);
415 printf(
" tx_antgain_h=%.2f, tx_antgain_v=%.2f, ",
416 tx_antgain_h, tx_antgain_v);
417 printf(
"rx_antgain_h=%.2f, rx_antgain_v=%.2f\n",
418 rx_antgain_h, rx_antgain_v);
419 printf(
" hori_beamwidth_h=%.2f, hori_beamwidth_v=%.2f, ",
420 hori_beamwidth_h, hori_beamwidth_v);
421 printf(
"vert_beamwidth_h=%.2f, vert_beamwidth_v=%.2f\n",
422 vert_beamwidth_h, vert_beamwidth_v);
429 printf(
"!!! causion: non-uniform range resolution is not supported !!! %d, %d\n", tmp_range_res, hd->
range_res);
437 rnum = sp_rnum + lp_rnum;
439 start_obs_az =
char2uint16(bufelhd + 380) * ideg2deg;
440 start_obs_el =
char2int16(bufelhd + 382) * ideg_tc2deg;
441 end_obs_az =
char2uint16(bufelhd + 384) * ideg2deg;
442 end_obs_el =
char2int16(bufelhd + 386) * ideg_tc2deg;
444 if(end_obs_az < start_obs_az){
447 if(start_obs_el > 180.0){
448 start_obs_el -= 360.0;
452 az[
k][
j] = 0.5 * (start_obs_az + end_obs_az);
453 el[
k][
j] = 0.5 * (start_obs_el + end_obs_el);
455 if (opt_verbose >= 3){
456 printf(
"=== short/long rnum=%d %d (%d)",sp_rnum, lp_rnum, rnum);
457 printf(
" start/end AZ=%6.2f-%6.2f (%6.2f) ",start_obs_az, end_obs_az, az[
k][
j]);
458 printf(
" start/end EL=%5.2f-%5.2f (%5.2f)\n",start_obs_el, end_obs_el, el[
k][
j]);
462 irb = rnum * (mesh_size / 8);
463 bufdat = buf + buf_offset;
467 for(
i = 0;
i < rnum;
i++)
468 rtdat[
k][
j][
i] = mesh_offset + mesh_lsb * (
float)(
char2uint16(bufdat + 2 *
i));