]> Pileus Git - ~andy/rsl/blobdiff - wsr88d_m31.c
RSL v1.44
[~andy/rsl] / wsr88d_m31.c
index 9e4c5b198603b7172bafd659ed092e1dba08ec44..2ae2143ee936d4ec589300a4cd045563a9a69438 100644 (file)
@@ -6,18 +6,20 @@
            SSAI
            Lanham, Maryland
 
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the
+    Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+    Boston, MA  02110-1301, USA.
 */
 
 
@@ -102,9 +104,6 @@ typedef struct {
 } Wsr88d_ray_m31;
 
 
-enum radial_status {START_OF_ELEV, INTERMED_RADIAL, END_OF_ELEV, BEGIN_VOS,
-    END_VOS};
-
 
 void wsr88d_swap_m31_hdr(Wsr88d_msg_hdr *msghdr)
 {
@@ -367,7 +366,6 @@ int wsr88d_get_vol_index(char* dataname)
     return -1;
 }
 
-
 #define MAXRAYS_M31 800
 #define MAXSWEEPS 20
 
@@ -394,11 +392,14 @@ void wsr88d_load_ray_into_radar(Wsr88d_ray_m31 *wsr88d_ray, int isweep,
     int vol_index, waveform;
     char *type_str;
 
-    int keep_hi_prf_dz = 0; /* TODO: make this an argument. */
+    extern int rsl_qfield[]; /* See RSL_select_fields in volume.c */
 
     enum waveforms {surveillance=1, doppler_w_amb_res, doppler_no_amb_res,
        batch};
 
+    int merging_split_cuts;
+
+    merging_split_cuts =  wsr88d_merge_split_cuts_is_set();
     nfields = wsr88d_ray->ray_hdr.data_block_count - nconstblocks;
     field_offset = (int *) &wsr88d_ray->ray_hdr.radial_const;
     do_swap = little_endian();
@@ -420,6 +421,10 @@ void wsr88d_load_ray_into_radar(Wsr88d_ray_m31 *wsr88d_ray, int isweep,
                    iray);
            return;
        }
+
+       /* Is this field in the selected fields list? */
+       if (!rsl_qfield[vol_index]) continue;
+
        switch (vol_index) {
            case DZ_INDEX: f = DZ_F; invf = DZ_INVF;
                 type_str = "Reflectivity"; break;
@@ -437,13 +442,17 @@ void wsr88d_load_ray_into_radar(Wsr88d_ray_m31 *wsr88d_ray, int isweep,
 
        waveform = vcp_data.waveform[isweep];
 
-       /* Ignore short-range reflectivity from velocity split cuts unless
-        * merging of split cuts is suppressed.  The indicators for this type of
-        * reflectivity are surveillance mode is 0 and elevation angle is
-        * below 6 degrees.
+       /* If this field is reflectivity, check to see if it's from the velocity
+         * sweep in a split cut.  If so, we normally skip it since we already
+         * have reflectivity from the surveillance sweep.  It is kept only when
+         * the user has turned off merging of split cuts.  We skip over this
+         * field if all of the following are true: surveillance PRF number is 0,
+         * waveform is Contiguous Doppler with Ambiguity Resolution (range
+         * unfolding), and we're merging split cuts.
         */
        if (vol_index == DZ_INDEX && (vcp_data.surveil_prf_num[isweep] == 0 &&
-                   vcp_data.fixed_angle[isweep] < 6.0 && !keep_hi_prf_dz))
+                   vcp_data.waveform[isweep] == doppler_w_amb_res &&
+                   merging_split_cuts))
            continue;
 
        /* Load the data for this field. */
@@ -526,15 +535,17 @@ Radar *wsr88d_load_m31_into_radar(Wsr88d_file *wf)
     short non31_seg_remainder[1202]; /* Remainder after message header */
     int end_of_vos = 0, isweep = 0;
     int msg_hdr_size, msg_size, n;
-    int sweep_hdrs_written = 0, prev_elev_num = 1, prev_raynum = 0, raynum = 0;
+    int prev_elev_num = 1, prev_raynum = 0, raynum = 0;
     Radar *radar = NULL;
+    enum radial_status {START_OF_ELEV, INTERMED_RADIAL, END_OF_ELEV, BEGIN_VOS,
+        END_VOS};
+
 
-    /* Message type 31 is a variable length message.  All other types are made
-     * up of 1 or more segments, where each segment is 2432 bytes in length.
-     * To handle these differences, read the message header and check its type.
-     * If it is 31, use the size given in the message header to determine the
-     * number of bytes to read.  If not, simply read the remainder of the
-     * 2432-byte segment.
+    /* Message type 31 is a variable length message.  All other types consist of
+     * 1 or more segments of length 2432 bytes.  To handle all types, we read
+     * the message header and check the type.  If not 31, then simply read
+     * the remainder of the 2432-byte segment.  If it is 31, use the size given
+     * in message header to determine how many bytes to read.
      */
 
     n = fread(&msghdr, sizeof(Wsr88d_msg_hdr), 1, wf->fptr);
@@ -543,18 +554,18 @@ Radar *wsr88d_load_m31_into_radar(Wsr88d_file *wf)
     msg_hdr_size = sizeof(Wsr88d_msg_hdr) - sizeof(msghdr.rpg);
 
     radar = RSL_new_radar(MAX_RADAR_VOLUMES);
+    memset(&wsr88d_ray, 0, sizeof(Wsr88d_ray_m31)); /* Initialize to be safe. */
 
     while (! end_of_vos) {
        if (msghdr.msg_type == 31) {
            if (little_endian()) wsr88d_swap_m31_hdr(&msghdr);
 
            /* Get size of the remainder of message.  The given size is in
-            * halfwords, but we want it in bytes, so double it.
+            * halfwords; convert it to bytes.
             */
            msg_size = (int) msghdr.msg_size * 2 - msg_hdr_size;
 
            n = read_wsr88d_ray_m31(wf, msg_size, &wsr88d_ray);
-           /* Assume error message was issued from read routine */
            if (n <= 0) return NULL;
            raynum = wsr88d_ray.ray_hdr.azm_num;
            if (raynum > MAXRAYS_M31) {
@@ -566,24 +577,30 @@ Radar *wsr88d_load_m31_into_radar(Wsr88d_file *wf)
            }
 
            /* Check for an unexpected start of new elevation, and issue a
-            * warning if this has occurred.  This usually means less rays than
-            * expected.  It happens, but rarely.
+            * warning if this has occurred.  This condition usually means
+            * less rays then expected in the sweep that just ended.
             */
            if (wsr88d_ray.ray_hdr.radial_status == START_OF_ELEV &&
-                   sweep_hdrs_written != prev_elev_num) {
+                   wsr88d_ray.ray_hdr.elev_num-1 > isweep) {
                fprintf(stderr,"Warning: Radial status is Start-of-Elevation, "
                        "but End-of-Elevation was not\n"
                        "issued for elevation number %d.  Number of rays = %d"
                        "\n", prev_elev_num, prev_raynum);
                wsr88d_load_sweep_header(radar, isweep);
                isweep++;
-               sweep_hdrs_written++;
                prev_elev_num = wsr88d_ray.ray_hdr.elev_num - 1;
            }
 
            /* Load ray into radar structure. */
            wsr88d_load_ray_into_radar(&wsr88d_ray, isweep, radar);
            prev_raynum = raynum;
+
+           /* Check for end of sweep */
+           if (wsr88d_ray.ray_hdr.radial_status == END_OF_ELEV) {
+               wsr88d_load_sweep_header(radar, isweep);
+               isweep++;
+               prev_elev_num = wsr88d_ray.ray_hdr.elev_num;
+           }
        }
        else { /* msg_type not 31 */
            n = fread(&non31_seg_remainder, sizeof(non31_seg_remainder), 1,
@@ -605,33 +622,24 @@ Radar *wsr88d_load_m31_into_radar(Wsr88d_file *wf)
            }
        }
 
-       /* Check for end of sweep */
-       if (wsr88d_ray.ray_hdr.radial_status == END_OF_ELEV) {
-           wsr88d_load_sweep_header(radar, isweep);
-           isweep++;
-           sweep_hdrs_written++;
-           prev_elev_num = wsr88d_ray.ray_hdr.elev_num;
-       }
-
        /* If not at end of volume scan, read next message header. */
        if (wsr88d_ray.ray_hdr.radial_status != END_VOS) {
            n = fread(&msghdr, sizeof(Wsr88d_msg_hdr), 1, wf->fptr);
            if (n < 1) {
                fprintf(stderr,"Warning: load_wsr88d_m31_into_radar: ");
-               if (feof(wf->fptr) != 0) fprintf(stderr,
-                       "Unexpected end of file.\n");
+               if (feof(wf->fptr) != 0)
+                   fprintf(stderr,"Unexpected end of file.\n");
                else fprintf(stderr,"Failed reading msghdr.\n");
                fprintf(stderr,"Current sweep index: %d\n"
                        "Last ray read: %d\n", isweep, prev_raynum);
                wsr88d_load_sweep_header(radar, isweep);
-               return radar;
+               end_of_vos = 1;
            }
        }
        else {
            end_of_vos = 1;
            wsr88d_load_sweep_header(radar, isweep);
        }
-       if (feof(wf->fptr) != 0) end_of_vos = 1;
     }  /* while not end of vos */
 
     return radar;