SCALE-RM
read_toshiba_mpr.c
Go to the documentation of this file.
1 /*---------------------------------------------------------------
2  15 Oct 2019 Shin Satoh
3 FUNCTION: int read_toshiba_mpr
4  to read MP-PAWR RAW data in Toshiba original format
5  opt_verbose = 0: no printout (silent)
6  1: print common (RAW DATA) header info
7  2: print Polar Block (RAY) header info
8  3: print EL header info
9 ----------------------------------------------------------------*/
10 /*
11  modified by Shigenori Otsuka
12  */
13 
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdint.h>
19 #include <inttypes.h>
20 #include <limits.h>
21 #ifdef __APPLE__
22 #include <machine/endian.h>
23 #else
24 #include <endian.h>
25 #endif
26 #include <zlib.h>
27 #include "read_toshiba_mpr.h"
28 
29 /*
30 int16_t char2int16(void *input)
31 {
32  int16_t output;
33 
34 #if __BYTE_ORDER == __LITTLE_ENDIAN
35  output = *((int16_t*)input);
36 #elif __BYTE_ORDER == __BIG_ENDIAN
37  output = ((int16_t)(((unsigned char*)input)[1]) << 8) | (int16_t)(((unsigned char*)input)[0]);
38 #else
39  output = ((char*)input)[1] * 0x100 + ((unsigned char*)input)[0];
40 #endif
41  return output;
42 }
43 
44 uint16_t char2uint16(void *input)
45 {
46  uint16_t output;
47 
48 #if __BYTE_ORDER == __LITTLE_ENDIAN
49  output = *((uint16_t*)input);
50 #elif __BYTE_ORDER == __BIG_ENDIAN
51  output = ((uint16_t)(((unsigned char*)input)[1]) << 8) | (uint16_t)(((unsigned char*)input)[0]);
52 #else
53  output = ((unsigned char*)input)[1] * 0x100 + ((unsigned char*)input)[0];
54 #endif
55  return output;
56 }
57 
58 int32_t char2int32(void *input)
59 {
60  int32_t output;
61 #if __BYTE_ORDER == __LITTLE_ENDIAN
62  output = *((int32_t*)input);
63 #elif __BYTE_ORDER == __BIG_ENDIAN
64  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]);
65 #else
66  output = ((char*)input)[3] * 0x1000000 + ((unsigned char*)input)[2] * 0x10000 + ((unsigned char*)input)[1] * 0x100 + ((unsigned char*)input)[0];
67 #endif
68  return output;
69 }
70 */
71 
72 size_t ungzip_toshiba_mpr(size_t outbufsize, size_t bufsize, unsigned char *buf){
73  unsigned char *outbuf;
74  size_t datsize;
75  z_stream strm;
76  int ret;
77 
78 #ifdef DA
79  outbuf = (unsigned char*)malloc(outbufsize);
80  if(outbuf == NULL){
81  printf("malloc failed in ungzip_toshiba_mpr\n");
82  datsize = 0;
83  } else {
84  strm.zalloc = Z_NULL;
85  strm.zfree = Z_NULL;
86  strm.opaque = Z_NULL;
87  ret = inflateInit2(&strm, 47);
88 
89  strm.next_in = buf;
90  strm.avail_in = bufsize;
91  strm.next_out = outbuf;
92  strm.avail_out = outbufsize;
93  ret = inflate(&strm, Z_NO_FLUSH);
94 
95  datsize = outbufsize - strm.avail_out;
96 
97  memcpy(buf, outbuf, datsize);
98  printf("maxbuf: %d, inbuf: %d, outbuf: %d\n",
99  outbufsize, bufsize, datsize);
100 
101  ret = inflateEnd(&strm);
102  free(outbuf);
103  }
104 #endif
105  return datsize;
106 }
107 
108 
109 int read_toshiba_mpr(char *in_file,
110  int opt_verbose,
111  mppawr_header *hd,
112  float az[ELDIM][AZDIM],
113  float el[ELDIM][AZDIM],
114  float rtdat[ELDIM][AZDIM][RDIM])
115 {
116  const size_t bufsize = AZDIM * (ELDIM * (RDIM * 2 + LEN_BUFELHD) + LEN_BUFPBHD) + LEN_BUFRDHD; // max size
117  size_t bsize; // actual data size
118  int ierr;
119  unsigned char *buf;
120  FILE *fp;
121  char *is_gzip;
122 
123  buf = malloc(bufsize);
124  if(buf == NULL){
125  printf("failed to allocate memory in read_toshiba");
126  return -99;
127  }
128  if((fp = fopen(in_file, "r")) == NULL){
129  is_gzip = "true";
130  if((fp = fopen(strcat(in_file,".gz"), "r")) == NULL){
131  //printf("file not found: %s\n", in_file);
132  return -9;
133  }
134  }
135  bsize = fread(buf, 1, bufsize, fp);
136  if(bsize == 0){
137  printf("file size is 0: %s\n", in_file);
138  return -9;
139  }
140 
141  if(is_gzip == "true") bsize = ungzip_toshiba_mpr(bufsize, bsize, buf);
142 
143  ierr = decode_toshiba_mpr(bsize, buf, opt_verbose, hd, az, el, rtdat);
144  if(ierr != 0) return ierr;
145 
146  free(buf);
147 
148  return 0;
149 }
150 
151 
152 int decode_toshiba_mpr(size_t bufsize, unsigned char *buf,
153  int opt_verbose,
154  mppawr_header *hd,
155  float az[ELDIM][AZDIM],
156  float el[ELDIM][AZDIM],
157  float rtdat[ELDIM][AZDIM][RDIM])
158 {
159  unsigned char *bufrdhd; /* RAW DATA hdr */
160  unsigned char *bufpbhd; /* POLAR BLOCK hdr */
161  unsigned char *bufelhd; /* EL hdr */
162  unsigned char *bufdat; /* 2 byte x 800 range (max) */
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;
182  // added by Otsuka
183  size_t buf_offset;
184  const float ideg2deg = 360.0 / 65536.0;
185  const float ideg_tc2deg = 180.0 / 32768.0;
186  int tmp_range_res;
187 
188  // init param
189  hd->range_res = -1;
190 
191  /*----- open RAW DATA file -----*/
192  buf_offset = 0;
193 
194  /*----- read RAW DATA header (512 byte)-----*/
195  if(buf_offset == bufsize) {
196  goto READEND;
197  } else if(buf_offset + LEN_BUFRDHD > bufsize) {
198  printf("# abnormal record length (RDhd)\n");
199  goto READERR;
200  }
201  bufrdhd = buf + buf_offset;
202  buf_offset += LEN_BUFRDHD;
203 
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);
217  /*--- Scan-start(s1), Sequence-start(s2), Mode-start(s3) time-- */
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);
237  hd->latitude = 0.000001 * char2int32(bufrdhd + 168 + 0);
238  hd->longitude = 0.000001 * char2int32(bufrdhd + 172 + 0);
239  hd->altitude = 0.01 * char2int32(bufrdhd + 180 + 0);
240  strncpy(hd->sq_name, &bufrdhd[216], 16);
241 
242  hd->el_num = bufrdhd[236 + 1];
243  hd->ray_num = char2uint16(bufrdhd + 238); //unsigned
244  hd->start_az = char2uint16(bufrdhd + 240) * ideg2deg; //unsigned
245  hd->start_el = char2int16(bufrdhd + 242) * ideg_tc2deg;
246  hd->end_az = char2int16(bufrdhd + 244) * ideg2deg; //unsigned
247  hd->end_el = char2int16(bufrdhd + 246) * ideg_tc2deg;
248  mesh_size = char2int16(bufrdhd + 384) * 8; /* mesh_size stored in byte? */
249  ibunshi = char2int32(bufrdhd + 388);
250  ibunbo = char2int32(bufrdhd + 392);
251  mesh_lsb = (float)ibunshi / (float)ibunbo;
252  ibunshi = char2int32(bufrdhd + 396);
253  ibunbo = char2int32(bufrdhd + 400);
254  mesh_offset = (float)ibunshi / (float)ibunbo;
255  hd->range_num = RDIM; /* <== shoud be fixed num, becasue of rtdat's base dim */
256 
257  hd->mesh_offset = mesh_offset; //save offset
258 
259  /*--- print RAW DATA header ---*/
260  if (opt_verbose >= 1){
261  //printf("## input file: %s\n", in_file);
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",
265  hd->s_yr, hd->s_mn, hd->s_dy, hd->s_hr, hd->s_mi, hd->s_sc,
266  hd->e_yr, hd->e_mn, hd->e_dy, hd->e_hr, hd->e_mi, hd->e_sc);
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",
275  hd->latitude, hd->longitude, hd->altitude);
276  printf("## sequence name: %s", hd->sq_name);
277  printf(" el_num=%d, ray_num=%d\n", hd->el_num, hd->ray_num);
278  /*---
279  printf("## start/end AZ angle=%5.1f-%5.1f ",hd->start_az, hd->end_az);
280  printf(" start/end EL angle=%5.2f-%5.2f\n",hd->start_el, hd->end_el);
281  ---*/
282  printf("## mesh size=%d, LSB=%7.3f, offset=%7.3f\n",
283  mesh_size, mesh_lsb, mesh_offset);
284  }
285 
286  if(mesh_size != 16){ /* 2-byte data */
287  printf("# abnormal mesh size: %d bit\n", mesh_size);
288  printf("# this program (read_toshiba_mpr) is not supported !\n");
289  goto READERR;
290  }
291 
292  /*----- RAY data (PPI) loop -----*/
293  aznum = hd->ray_num;
294  if(aznum > AZDIM){
295  printf("# abnormal AZ dimension: %d (> %d)\n", aznum, AZDIM);
296  goto READERR;
297  }
298  for(j = 0; j < aznum; j++) { /*= AZ loop uses j =*/
299  /*----- read POLAR BLOCK (RAY) header (10368 byte)-----*/
300  if(buf_offset == bufsize) {
301  goto READEND;
302  } else if(buf_offset + LEN_BUFPBHD > bufsize) {
303  printf("# abnormal record length (PB header)\n");
304  goto READERR;
305  }
306  bufpbhd = buf + buf_offset;
307  buf_offset += LEN_BUFPBHD;
308 
309  /*--- get PB header info for print ---*/
310  if (opt_verbose >= 2){
311  el_num_sec = bufpbhd[9]; //unsigned
312  cpi_num = char2uint16(bufpbhd + 12); //unsigned
313  sec_num = char2uint16(bufpbhd + 14); //unsigned
314  start_az_sec = char2uint16(bufpbhd + 16) * ideg2deg; //unsigned
315  start_el_sec = char2int16(bufpbhd + 18) * ideg_tc2deg;
316  end_az_sec = char2uint16(bufpbhd + 20) * ideg2deg; //unsigned
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;
321 
322  /*--- print PB header ---*/
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);
332  }
333 
334  /*----- EL data (RHI) loop -----*/
335  elnum = hd->el_num;
336  if(elnum > ELDIM){
337  printf("# abnormal EL dimension: %d (> %d)\n", elnum, ELDIM);
338  goto READERR;
339  }
340  for(k = 0; k < elnum; k++) { /*= EL loop uses k =*/
341 
342  /*----- read EL header (432 byte)-----*/
343  if(buf_offset == bufsize) {
344  goto READEND;
345  } else if(buf_offset + LEN_BUFELHD > bufsize) {
346  printf("# abnormal record length (EL header)\n");
347  goto READERR;
348  }
349  bufelhd = buf + buf_offset;
350  buf_offset += LEN_BUFELHD;
351 
352  /*** if (opt_verbose >= 3 && (j==0 || j==1) && (k==3 || k==4)){ ***/
353  if (opt_verbose >= 3){
354 
355  /*--- get EL header info for print ---*/
356  data_size = char2uint16(bufelhd + 0); //unsigned
357  hit_num = char2uint16(bufelhd + 8); //unsigned
358  cpi_num = char2uint16(bufelhd + 10); //unsigned
359  spa_num = char2uint16(bufelhd + 12); /*short pulse align range num*/ //unsigned
360  lpa_num = char2uint16(bufelhd + 14); /*long pulse align range num*/ //unsigned
361  spv_num = char2uint16(bufelhd + 16); /*short pulse valid range num*/ //unsigned
362  lpv_num = char2uint16(bufelhd + 18); /*long pulse valid range num*/ //unsigned
363  start_az_cpi = char2uint16(bufelhd + 128) * ideg2deg; //unsigned
364  start_el_cpi = char2int16(bufelhd + 130) * ideg_tc2deg;
365  end_az_cpi = char2uint16(bufelhd + 132) * ideg2deg; //unsigned
366  end_el_cpi = char2int16(bufelhd + 134) * ideg_tc2deg;
367  /*short pulse: 0=0.5us, 1=1.0us, 2=2.0us, 3=4.0us*/
368  /*long pulse: 0=24us, 1=32us, 2=48us, 3=72us*/
369  pw_hsp = bufelhd[144]; /*pulse width of H-pol short pulse*/
370  pw_hlp = bufelhd[145]; /*pulse width of H-pol long pulse*/
371  pw_vsp = bufelhd[146]; /*pulse width of V-pol short pulse*/
372  pw_vlp = bufelhd[147]; /*pulse width of V-pol long pulse*/
373  prf = char2uint16(bufelhd + 148); //unsigned
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);
390 
391  /*--- print EL header ---*/
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);
397 
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);
423  }
424  } /* end of if (opt_verbose >= 3) */
425 
426  /* range resolution (RAY) */
427  tmp_range_res = char2uint16(bufelhd + 372); //unsigned
428  if((hd->range_res > 0) && (hd->range_res != tmp_range_res)){
429  printf("!!! causion: non-uniform range resolution is not supported !!! %d, %d\n", tmp_range_res, hd->range_res);
430  goto READERR;
431  }
432  hd->range_res = tmp_range_res; //overwrite
433 
434  /*--- get range num and angle data---*/
435  sp_rnum = char2uint16(bufelhd + 376); //unsigned
436  lp_rnum = char2uint16(bufelhd + 378); //unsigned
437  rnum = sp_rnum + lp_rnum;
438  /* hd->range_num = rnum; */
439  start_obs_az = char2uint16(bufelhd + 380) * ideg2deg; //unsigned
440  start_obs_el = char2int16(bufelhd + 382) * ideg_tc2deg;
441  end_obs_az = char2uint16(bufelhd + 384) * ideg2deg; //unsigned
442  end_obs_el = char2int16(bufelhd + 386) * ideg_tc2deg;
443 
444  if(end_obs_az < start_obs_az){
445  end_obs_az += 360.0;
446  }
447  if(start_obs_el > 180.0){
448  start_obs_el -= 360.0;
449  }
450 
451  /*--- store AZ and EL ---*/
452  az[k][j] = 0.5 * (start_obs_az + end_obs_az);
453  el[k][j] = 0.5 * (start_obs_el + end_obs_el);
454 
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]);
459  }
460 
461  /*----- read data block -----*/
462  irb = rnum * (mesh_size / 8);
463  bufdat = buf + buf_offset;
464  buf_offset += irb;
465 
466  /*--- store raw data ---*/
467  for(i = 0; i < rnum; i++)
468  rtdat[k][j][i] = mesh_offset + mesh_lsb * (float)(char2uint16(bufdat + 2 * i));
469 
470  } /* end of k-loop */
471  } /* end of j-loop */
472 
473  goto READEND;
474 
475  READERR:
476  return -8;
477 
478  READEND:
479  return 0;
480 }
mppawr_header::start_el
float start_el
Definition: read_toshiba_mpr.h:48
mppawr_header::e_mn
int e_mn
Definition: read_toshiba_mpr.h:44
mppawr_header::s_yr
int s_yr
Definition: read_toshiba_mpr.h:43
LEN_BUFRDHD
#define LEN_BUFRDHD
Definition: read_toshiba_mpr.h:15
mppawr_header
Definition: read_toshiba_mpr.h:41
mppawr_header::altitude
double altitude
Definition: read_toshiba_mpr.h:47
mppawr_header::ray_num
int ray_num
Definition: read_toshiba_mpr.h:45
mppawr_header::range_num
int range_num
Definition: read_toshiba_mpr.h:45
RDIM
#define RDIM
Definition: read_toshiba.h:6
mppawr_header::s_dy
int s_dy
Definition: read_toshiba_mpr.h:43
mppawr_header::latitude
double latitude
Definition: read_toshiba_mpr.h:47
char2uint16
uint16_t char2uint16(void *input)
Definition: read_toshiba.c:36
mppawr_header::longitude
double longitude
Definition: read_toshiba_mpr.h:47
mppawr_header::el_num
int el_num
Definition: read_toshiba_mpr.h:45
decode_toshiba_mpr
int decode_toshiba_mpr(size_t bufsize, unsigned char *buf, int opt_verbose, mppawr_header *hd, float az[ELDIM][AZDIM], float el[ELDIM][AZDIM], float rtdat[ELDIM][AZDIM][RDIM])
Definition: read_toshiba_mpr.c:152
char2int16
int16_t char2int16(void *input)
Definition: read_toshiba.c:22
mppawr_header::start_az
float start_az
Definition: read_toshiba_mpr.h:48
mppawr_header::sq_name
char sq_name[16]
Definition: read_toshiba_mpr.h:42
float
typedef float(real32_t)
char2int32
int32_t char2int32(void *input)
Definition: read_toshiba.c:50
mod_atmos_vars::j
real(rp), allocatable, target, public j
Definition: mod_atmos_vars.F90:141
read_toshiba_mpr.h
mppawr_header::data_name
char data_name[32]
Definition: read_toshiba_mpr.h:42
mppawr_header::range_res
int range_res
Definition: read_toshiba_mpr.h:46
mppawr_header::e_hr
int e_hr
Definition: read_toshiba_mpr.h:44
mppawr_header::e_sc
int e_sc
Definition: read_toshiba_mpr.h:44
scale_tracer::k
real(rp), public k
Definition: scale_tracer.F90:45
scale_file::i
logical, public i
Definition: scale_file.F90:196
mppawr_header::s_sc
int s_sc
Definition: read_toshiba_mpr.h:43
mppawr_header::s_hr
int s_hr
Definition: read_toshiba_mpr.h:43
mppawr_header::end_el
float end_el
Definition: read_toshiba_mpr.h:48
ungzip_toshiba_mpr
size_t ungzip_toshiba_mpr(size_t outbufsize, size_t bufsize, unsigned char *buf)
Definition: read_toshiba_mpr.c:72
mppawr_header::mesh_offset
float mesh_offset
Definition: read_toshiba_mpr.h:49
AZDIM
#define AZDIM
Definition: read_toshiba.h:7
mppawr_header::e_yr
int e_yr
Definition: read_toshiba_mpr.h:44
read_toshiba_mpr
int read_toshiba_mpr(char *in_file, int opt_verbose, mppawr_header *hd, float az[ELDIM][AZDIM], float el[ELDIM][AZDIM], float rtdat[ELDIM][AZDIM][RDIM])
Definition: read_toshiba_mpr.c:109
mppawr_header::s_mn
int s_mn
Definition: read_toshiba_mpr.h:43
mppawr_header::e_dy
int e_dy
Definition: read_toshiba_mpr.h:44
LEN_BUFELHD
#define LEN_BUFELHD
Definition: read_toshiba_mpr.h:17
mppawr_header::s_mi
int s_mi
Definition: read_toshiba_mpr.h:43
mppawr_header::site_name
char site_name[32]
Definition: read_toshiba_mpr.h:42
mppawr_header::end_az
float end_az
Definition: read_toshiba_mpr.h:48
LEN_BUFPBHD
#define LEN_BUFPBHD
Definition: read_toshiba_mpr.h:16
mppawr_header::e_mi
int e_mi
Definition: read_toshiba_mpr.h:44
ELDIM
#define ELDIM
Definition: read_toshiba.h:8