]> Pileus Git - ~andy/rsl/blob - fix_headers.c
Initial import
[~andy/rsl] / fix_headers.c
1 /*
2     NASA/TRMM, Code 910.1.
3     This is the TRMM Office Radar Software Library.
4     Copyright (C) 1996, 1997
5             John H. Merritt
6             Space Applications Corporation
7             Vienna, Virginia
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU Library General Public
11     License as published by the Free Software Foundation; either
12     version 2 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17     Library General Public License for more details.
18
19     You should have received a copy of the GNU Library General Public
20     License along with this library; if not, write to the Free
21     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23 /*
24  * Fix header fields in ray headers.
25  *
26  * This routine is initially written to support 1C-51.
27  * It has been noticed that several radar files contain bad header
28  * information.  Herein, we correct it by simple linear interpolation.
29  *
30  * By: John Merritt
31  *     Space Applications Corporation
32  *     Copyright 7/16/96
33  *
34  */
35
36 #include <stdio.h>
37 #include "rsl.h"
38
39 Ray *RSL_fix_ray_header(Ray *ray)
40 {
41   return ray;
42 }
43
44 Sweep *RSL_fix_sweep_header(Sweep *sweep)
45 {
46   int i;
47   int nfixed = 0;
48   int needed_to_fix = 0;
49   Ray *ray;
50
51   if (sweep == NULL) return sweep;
52
53   for (i=0; i<sweep->h.nrays; i++) {
54         /* Here, we check and use more than one ray. */
55         ray = sweep->ray[i];
56
57         if (ray == NULL) continue;
58         if (ray->h.month < 1 || ray->h.month > 12) {
59           needed_to_fix = 1;
60           fprintf(stderr, "ray[%3.3d]->h.month = %d\n", i, ray->h.month);
61         }
62         if (ray->h.day < 1 || ray->h.day > 31) {
63           needed_to_fix = 1;
64           fprintf(stderr, "ray[%3.3d]->h.day   = %d\n", i, ray->h.day);
65         }
66         if (ray->h.year < 1980 || ray->h.year > 2020) {
67           needed_to_fix = 1;
68           fprintf(stderr, "ray[%3.3d]->h.year  = %d\n", i, ray->h.year);
69         }
70         if (ray->h.hour < 0 || ray->h.hour > 23) {
71           needed_to_fix = 1;
72           fprintf(stderr, "ray[%3.3d]->h.hour  = %d\n", i, ray->h.hour);
73         }
74         if (ray->h.minute < 0 || ray->h.minute > 59) {
75           needed_to_fix = 1;
76           fprintf(stderr, "ray[%3.3d]->h.minute= %d\n", i, ray->h.minute);
77         }
78         if (ray->h.sec < 0 || ray->h.sec > 59) {
79           needed_to_fix = 1;
80           fprintf(stderr, "ray[%3.3d]->h.sec   = %f\n", i, ray->h.sec);
81         }
82         if (ray->h.elev < 0 || ray->h.elev > 90) {
83           needed_to_fix = 1;
84           fprintf(stderr, "ray[%3.3d]->h.elev  = %f\n", i, ray->h.elev);
85         }
86         if (ray->h.range_bin1 < 0 || ray->h.range_bin1 > 150000) {
87           needed_to_fix = 1;
88           fprintf(stderr, "ray[%3.3d]->h.range_bin1  = %d\n", i, ray->h.range_bin1);
89         }
90         if (ray->h.gate_size < 0 || ray->h.gate_size > 100000) {
91           needed_to_fix = 1;
92           fprintf(stderr, "ray[%3.3d]->h.gate_size   = %d\n", i, ray->h.gate_size);
93         }
94         if (ray->h.beam_width <= 0 || ray->h.beam_width > 10) {
95           needed_to_fix = 1;
96           fprintf(stderr, "ray[%3.3d]->h.beam_width  = %f\n", i, ray->h.beam_width);
97         }
98         if (needed_to_fix) {
99           needed_to_fix = 0;
100           nfixed++;
101         }
102   }
103
104   fprintf(stderr, "Repaired %d rays in this sweep.\n", nfixed);
105
106   return sweep;
107 }
108
109 Volume *RSL_fix_volume_header(Volume *v)
110 {
111   int i;
112   if (v == NULL) return v;
113
114   for (i=0; i<v->h.nsweeps; i++)
115         RSL_fix_sweep_header(v->sweep[i]);
116
117   return v;
118 }
119
120 Radar *RSL_fix_radar_header(Radar *radar)
121 {
122   int i;
123   if (radar == NULL) return radar;
124
125   for (i=0; i<radar->h.nvolumes; i++)
126         RSL_fix_volume_header(radar->v[i]);
127
128   return radar;
129 }
130
131