]> Pileus Git - ~andy/rsl/blobdiff - radar_to_uf.c
RSL v1.44
[~andy/rsl] / radar_to_uf.c
index 0c9ee3dda9a72f48c031ab7a2e2a8dc9f06b28ae..dcd61a053ec56f21e609523e8fc9264b9c134a29 100644 (file)
@@ -63,6 +63,8 @@ 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);
+
 
 /**********************************************************************/
 /*                                                                    */
@@ -132,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;
 
@@ -339,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;
@@ -351,38 +366,11 @@ void RSL_radar_to_uf_fp(Radar *r, FILE *fp)
         
         /* ---- Begining of LOCAL USE HEADER BLOCK. */
         q_lu = 0;
-
-        /* TODO: Code within "#ifdef LUHDR_VR_AZ" below should be removed
-         * once testing of merge_split_cuts is completed.
-         */
-/* 7/25/2011 There's really no need to remove this code after merge_split_cuts.
- * We can continue using it for exact VR azimuth in RSL.  Non-RSL programs can
- * use the mandatory header azimuth, which is exact for DZ and a close
- * approximation for VR when merge-split-cuts is applied.
- */
-/* Preprocessor directives are for testing. */
-#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. */
 
@@ -445,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;
@@ -511,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;
 }
 
 /**********************************************************************/