]> Pileus Git - ~andy/rsl/blobdiff - radar_to_uf.c
RSL v1.44
[~andy/rsl] / radar_to_uf.c
index df237f57825888b138bcdebdef363988554904c0..dcd61a053ec56f21e609523e8fc9264b9c134a29 100644 (file)
@@ -58,10 +58,13 @@ extern int radar_verbose_flag;
  */
 
 
-typedef short UF_buffer[16384]; /* Bigger than documented 4096. */
+/* Changed old buffer size (16384) for larger dualpol files.  BLK 5/20/2011 */
+typedef short UF_buffer[20000]; /* Bigger than documented 4096. */
 
 void swap_uf_buffer(UF_buffer uf);
 void swap2(short *buf, int n);
+Radar *wsr88d_align_split_cut_rays(Radar *radar);
+
 
 /**********************************************************************/
 /*                                                                    */
@@ -131,11 +134,24 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
   int sweep_num, ray_num, rec_num;
   float x;
 
+  Radar *r_save = NULL;
+
   if (r == NULL) {
     fprintf(stderr, "radar_to_uf_fp: radar pointer NULL\n");
     return;
   }
 
+  /* If this is WSR-88D data, reorder VR and SW rays in split cuts so that
+   * their azimuths agree with DZ rays.
+   */
+  if (r->h.vcp > 0) {
+    if (wsr88d_merge_split_cuts_is_set()) {
+      /* Save a copy of the input radar; we'll restore it later. */
+      r_save = r;
+      r = wsr88d_align_split_cut_rays(r);
+    }
+  }
+
 /* Do all the headers first time around.  Then, prune OP and LU. */
   q_op = q_lu = q_dh = q_fh = 1;
 
@@ -308,7 +324,7 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
         if (ray->h.azimuth > 0) uf_ma[32] = ray->h.azimuth*64 + 0.5;
         else uf_ma[32] = ray->h.azimuth*64 - 0.5;
         uf_ma[33] = ray->h.elev*64 + 0.5;
-       uf_ma[34] = uf_sweep_mode;
+        uf_ma[34] = uf_sweep_mode;
         if (ray->h.fix_angle != 0.)
              uf_ma[35] = ray->h.fix_angle*64.0 + 0.5;
         else uf_ma[35] = sweep[k]->h.elev*64.0 + 0.5;
@@ -338,9 +354,9 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
           if (little_endian()) swap2(&uf_op[0], 8/2);
           uf_op[4] = (signed short)UF_NO_DATA;
           uf_op[5] = (signed short)UF_NO_DATA;
-          uf_op[6] = ray->h.hour;
-          uf_op[7] = ray->h.minute;
-          uf_op[8] = ray->h.sec;
+          uf_op[6] = r->h.hour;
+          uf_op[7] = r->h.minute;
+          uf_op[8] = r->h.sec;
           memcpy(&uf_op[9], "RADAR_UF", 8);
           if (little_endian()) swap2(&uf_op[9], 8/2);
           uf_op[13] = 2;
@@ -350,36 +366,11 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
         
         /* ---- Begining of LOCAL USE HEADER BLOCK. */
         q_lu = 0;
-
-       /* Note: Code within "#ifdef LUHDR_VR_AZ" below is retained for testing
-        * and is not normally compiled.  It was used to deal with azimuth
-        * differences between DZ and VR in WSR-88D split-cuts, now handled in
-        * ingest routine.
-        */
-/* 5/18/2010 Temporarily define LUHDR_VR_AZ until merge_split_cuts is
-   completed. */
-#define LUHDR_VR_AZ
-#ifdef LUHDR_VR_AZ
-        /* If DZ and VR azimuths are different, store VR azimuth in Local Use
-         * Header. This is done for WSR-88D split cuts.
-        */
-        if (sweep[DZ_INDEX] && sweep[VR_INDEX]) {
-            if (sweep[DZ_INDEX]->ray[j] && sweep[VR_INDEX]->ray[j]) {
-            vr_az = sweep[VR_INDEX]->ray[j]->h.azimuth;
-            if (sweep[DZ_INDEX]->ray[j]->h.azimuth != vr_az)
-                q_lu = 1; /* Set to use Local Use Header block. */
-            }
-        }
-#endif
         len_lu = 0;
         if (q_lu) {
-          /* Store azimuth for WSR-88D VR ray in Local Use Header. */
           uf_lu = uf+len_ma+len_op;
-          memcpy(&uf_lu[0], "AZ", 2);
-          if (little_endian()) memcpy(&uf_lu[0], "ZA", 2);
-          if (vr_az > 0) uf_lu[1] = vr_az*64 + 0.5;
-          else uf_lu[1] = vr_az*64 - 0.5;
-          len_lu = 2;
+          q_lu = 0; /* Only once. */
+          len_lu = 0;  /* I don't have anything yet. */
         }
         /* ---- End  of LOCAL USE HEADER BLOCK. */
 
@@ -413,15 +404,15 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
               uf_dh[2] = nfield;
               /* 'nfield' indexes the field number.
                * 'k' indexes the particular field from the volume.
-              *  RSL_ftype contains field names and is defined in rsl.h.
+               *  RSL_ftype contains field names and is defined in rsl.h.
                */
               if (k > max_field_names-1) {
-               fprintf(stderr,
+                fprintf(stderr,
                   "RSL_uf_to_radar: No field name for volume index %d\n", k);
-               fprintf(stderr,"RSL_ftype must be updated in rsl.h for new field.\n");
-               fprintf(stderr,"Quitting now.\n");
+                fprintf(stderr,"RSL_ftype must be updated in rsl.h for new field.\n");
+                fprintf(stderr,"Quitting now.\n");
                 return;
-             }
+              }
               memcpy(&uf_dh[3+2*(nfield-1)], RSL_ftype[k], 2);
               if (little_endian()) swap2(&uf_dh[3+2*(nfield-1)], 2/2);
               if (current_fh_index == 0) current_fh_index = len_ma+len_op+len_lu+len_dh;
@@ -432,7 +423,9 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
             /* ---- Begining of FIELD HEADER. */
             if (q_fh) {
               uf_fh = uf+current_fh_index;
-              uf_fh[1] = scale_factor = 100;
+             if (k != PH_INDEX) scale_factor = 100;
+             else scale_factor = 10;
+              uf_fh[1] = scale_factor;
               uf_fh[2] = ray->h.range_bin1/1000.0;
               uf_fh[3] = ray->h.range_bin1 - (1000*uf_fh[2]);
               uf_fh[4] = ray->h.gate_size;
@@ -440,7 +433,7 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
               uf_fh[6] = ray->h.pulse_width*(RSL_SPEED_OF_LIGHT/1.0e6);
               uf_fh[7] = sweep[k]->h.beam_width*64.0 + 0.5;
               uf_fh[8] = sweep[k]->h.beam_width*64.0 + 0.5;
-              uf_fh[9] = ray->h.frequency*64.0 + 0.5; /* Bandwidth (mHz). */
+              uf_fh[9] = ray->h.frequency * 1000.; /* Bandwidth (mHz). */
               uf_fh[10] = 0; /* Horizontal polarization. */ 
               uf_fh[11] = ray->h.wavelength*64.0*100.0; /* m to cm. */
               uf_fh[12] = ray->h.pulse_count;
@@ -506,6 +499,9 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
       } /* if (ray) */
     }
   }
+
+  /* If Radar argument "r" was modified (WSR-88D), restore the saved copy. */
+  if (r_save != NULL) r = r_save;
 }
 
 /**********************************************************************/