]> Pileus Git - ~andy/rsl/blob - uf_to_radar.c
341ec339e587de8d943ad8bf4b4edb7d50dd86f3
[~andy/rsl] / uf_to_radar.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 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27
28 /* This allows us to use RSL_ftype, RSL_f_list, RSL_invf_list from rsl.h. */
29 #define USE_RSL_VARS
30 #include "rsl.h"
31
32 extern int radar_verbose_flag;
33 typedef short UF_buffer[16384]; /* Some UF files are bigger than 4096
34                                  * that the UF doc's specify.
35                                  */
36
37 #define UF_MORE 0
38 #define UF_DONE 1
39
40 static float (*f)(Range x);
41 static Range (*invf)(float x);
42
43 Volume *reset_nsweeps_in_volume(Volume *volume)
44 {
45   int i;
46   if (volume == NULL) return NULL;
47   for (i=volume->h.nsweeps; i>0; i--)
48     if (volume->sweep[i-1] != NULL) {
49       volume->h.nsweeps = i;
50       break;
51     }
52   return volume;
53 }
54 Radar *reset_nsweeps_in_all_volumes(Radar *radar)
55 {
56   int i;
57   if (radar == NULL) return NULL;
58   for (i=0; i<radar->h.nvolumes; i++)
59     radar->v[i] = reset_nsweeps_in_volume(radar->v[i]);
60   return radar;
61 }
62
63 Volume *copy_sweeps_into_volume(Volume *new_volume, Volume *old_volume)
64 {
65   int i;
66   int nsweeps;
67   if (old_volume == NULL) return new_volume;
68   if (new_volume == NULL) return new_volume;
69   nsweeps = new_volume->h.nsweeps; /* Save before copying old header. */
70   new_volume->h = old_volume->h;
71   new_volume->h.nsweeps = nsweeps;
72   for (i=0; i<old_volume->h.nsweeps; i++)
73     new_volume->sweep[i] = old_volume->sweep[i]; /* Just copy pointers. */
74   /* Free the old sweep array, not the pointers to sweeps. */
75   free(old_volume->sweep);
76   return new_volume;
77 }
78
79 void swap2(short *buf, int n)
80 {
81   short *end_addr;
82   end_addr = buf + n;
83   while (buf < end_addr) {
84     swap_2_bytes(buf);
85     buf++;
86   }
87 }
88
89
90 /********************************************************************/
91 /*********************************************************************/
92 /*                                                                   */
93 /*                  uf_into_radar                                    */
94 /*                                                                   */
95 /*  By: John Merritt                                                 */
96 /*      Space Applications Corporation                               */
97 /*      August 26, 1994                                              */
98 /*********************************************************************/
99 int uf_into_radar(UF_buffer uf, Radar **the_radar)
100 {
101   
102 /* Missing data flag : -32768 when a signed short. */
103 #define UF_NO_DATA 0X8000
104   
105   /* Any convensions may be observed, however, Radial Velocity must be VE. */
106   /* Typically:
107    *    DM = Reflectivity (dB(mW)).
108    *    DZ = Reflectivity (dBZ).
109    *    VR = Radial Velocity.
110    *    CZ = Corrected Reflectivity. (Quality controlled: AP removed, etc.)
111    *    SW = Spectrum Width.
112    *    DR = Differential Reflectivity.
113    *    XZ = X-band Reflectivity.
114    *
115    * These fields may appear in any order in the UF file.
116    *
117    * RETURN:
118    *   UF_DONE if we're done with the UF ingest.
119    *   UF_MORE if we need more UF data.
120    */
121   
122   /* These are pointers to various locations within the UF buffer 'uf'.
123    * They are used to index the different components of the UF structure in
124    * a manor consistant with the UF documentation.  For instance, uf_ma[1]
125    * will be equivalenced to the second word (2 bytes/each) of the UF
126    * buffer.
127    */
128   short *uf_ma;  /* Mandatory header block. */
129   short *uf_lu;  /* Local Use header block.  */
130   short *uf_dh;  /* Data header.  */
131   short *uf_fh;  /* Field header. */
132   short *uf_data; /* Data. */
133   
134   /* The length of each header. */
135   int len_data, len_lu;
136   
137   int current_fh_index; 
138   float scale_factor;
139   
140   int nfields, isweep, ifield, iray, i, j, m;
141   static int pulled_time_from_first_ray = 0;
142   static int need_scan_mode = 1;
143   char *field_type; /* For printing the field type upon error. */
144   short proj_name[4];
145   Ray *ray;
146   Sweep *sweep;
147   Radar *radar;
148   float x;
149   short missing_data;
150   Volume *new_volume;
151   int nbins;
152   extern int rsl_qfield[];
153   extern int *rsl_qsweep; /* See RSL_read_these_sweeps in volume.c */
154   extern int rsl_qsweep_max;
155
156   radar = *the_radar;
157
158 /*
159  * The organization of the Radar structure is by volumes, then sweeps, then
160  * rays, then gates.  This is different from the UF file organization.
161  * The UF format is sweeps, rays, then gates for all field types (volumes).
162  */
163
164
165 /* Set up all the UF pointers. */
166   uf_ma = uf;
167   uf_lu = uf + uf_ma[3] - 1;
168   uf_dh = uf + uf_ma[4] - 1;
169
170   nfields =  uf_dh[0];
171   isweep = uf_ma[9] - 1;
172
173   if (rsl_qsweep != NULL) {
174     if (isweep > rsl_qsweep_max) return UF_DONE;
175     if (rsl_qsweep[isweep] == 0) return UF_MORE;
176   }
177
178
179 /* Here is a sticky part.  We must make sure that if we encounter any
180  * additional fields that were not previously present, that we are able
181  * to load them.  This will require us to copy the entire radar structure
182  * and whack off the old one.  But, we must be sure that it really is a
183  * new field.  This is not so trivial as a couple of lines of code; I will
184  * have to think about this a little bit more.  See STICKYSOLVED below.
185  */
186 #ifdef STICKYSOLVED
187   if (radar == NULL) radar = RSL_new_radar(nfields);
188   /* Sticky solution here. */
189 #else
190   if (radar == NULL) {
191     radar = RSL_new_radar(MAX_RADAR_VOLUMES);
192     *the_radar = radar;
193     pulled_time_from_first_ray = 0;
194     for (i=0; i<MAX_RADAR_VOLUMES; i++)
195       if (rsl_qfield[i]) /* See RSL_select_fields in volume.c */
196         radar->v[i] = RSL_new_volume(20);
197   }
198   
199 #endif
200
201   if (need_scan_mode) {
202     /* PPI and RHI are enum constants defined in rsl.h */
203     if (uf_ma[34] == 1) radar->h.scan_mode = PPI;
204     else if (uf_ma[34] == 3) radar->h.scan_mode = RHI;
205     else {
206       fprintf(stderr,"Warning: UF sweep mode = %d\n", uf_ma[34]);
207       fprintf(stderr,"    Expected 1 or 3 (PPI or RHI)\n");
208       fprintf(stderr,"    Setting radar->h.scan_mode to PPI\n");
209       radar->h.scan_mode = PPI;
210     }
211     need_scan_mode = 0;
212   }
213
214 /* For LITTLE ENDIAN:
215  * WE "UNSWAP" character strings.  Because there are so few of them,
216  * it is easier to catch them here.  The entire UF buffer is swapped prior
217  * to entry to here, therefore, undo-ing these swaps; sets the
218  * character strings right.
219  */
220
221   for (i=0; i<nfields; i++) {
222     if (little_endian()) swap_2_bytes(&uf_dh[3+2*i]); /* Unswap. */
223     ifield = -1;
224     field_type = (char *)&uf_dh[3+2*i];
225     for (j=0; j<MAX_RADAR_VOLUMES; j++) {
226       if (strncmp(field_type, RSL_ftype[j], 2) == 0) {
227         ifield = j;
228         break;
229       }
230     }
231     if (ifield < 0) { /* DON'T know how to handle this yet. */
232       fprintf(stderr, "Unknown field type %c%c\n", (char)field_type[0],
233               (char)field_type[1]);
234       continue;
235     }
236
237     f = RSL_f_list[ifield];
238     invf = RSL_invf_list[ifield];
239
240     /* Do we place the data into this volume? */
241     if (radar->v[ifield] == NULL) continue; /* Nope. */
242
243     if (isweep >= radar->v[ifield]->h.nsweeps) { /* Exceeded sweep limit.
244                                                   * Allocate more sweeps.
245                                                   * Copy all previous sweeps.
246                                                   */
247       if (radar_verbose_flag)
248         fprintf(stderr,"Exceeded sweep allocation of %d. Adding 20 more.\n", isweep);
249       new_volume = RSL_new_volume(radar->v[ifield]->h.nsweeps+20);
250       new_volume = copy_sweeps_into_volume(new_volume, radar->v[ifield]);
251       radar->v[ifield] = new_volume;
252     }
253
254     if (radar->v[ifield]->sweep[isweep] == NULL) {
255       if (radar_verbose_flag)
256         fprintf(stderr,"Allocating new sweep for field %d, isweep %d\n", ifield, isweep);
257       radar->v[ifield]->sweep[isweep] = RSL_new_sweep(1000);
258       radar->v[ifield]->sweep[isweep]->h.nrays = 0; /* Increment this for each
259                                                      * ray encountered.
260                                                      */
261       radar->v[ifield]->h.f = f;
262       radar->v[ifield]->h.invf = invf;
263       radar->v[ifield]->sweep[isweep]->h.f = f;
264       radar->v[ifield]->sweep[isweep]->h.invf = invf;
265       radar->v[ifield]->sweep[isweep]->h.sweep_num = uf_ma[9];
266       radar->v[ifield]->sweep[isweep]->h.elev = uf_ma[35] / 64.0;
267     }
268     
269     
270
271     current_fh_index = uf_dh[4+2*i];
272     uf_fh = uf + current_fh_index - 1;
273     sweep = radar->v[ifield]->sweep[isweep];
274     iray =  sweep->h.nrays;
275     nbins = uf_fh[5];
276     radar->v[ifield]->sweep[isweep]->ray[iray] = RSL_new_ray(nbins);
277     ray   = radar->v[ifield]->sweep[isweep]->ray[iray];
278     sweep->h.nrays += 1;
279
280
281     if (ray) {
282         /* 
283          * ---- Beginning of MANDATORY HEADER BLOCK.
284          */
285       ray->h.ray_num = uf_ma[7];
286       if (little_endian()) swap2(&uf_ma[10], 8);
287       memcpy(radar->h.radar_name, &uf_ma[10], 8);
288       if (little_endian()) swap2(&uf_ma[10], 8/2);
289       memcpy(radar->h.name, &uf_ma[14], 8);
290       if (little_endian()) swap2(&uf_ma[14], 8/2);
291         
292       /* All components of lat/lon are the same sign.  If not, then
293        * what ever wrote the UF was in error.  A simple RSL program
294        * can repair the damage, however, not here.
295        */
296       ray->h.lat = uf_ma[18] + uf_ma[19]/60.0 + uf_ma[20]/64.0/3600;
297       ray->h.lon = uf_ma[21] + uf_ma[22]/60.0 + uf_ma[23]/64.0/3600;
298       ray->h.alt      = uf_ma[24];
299       ray->h.year     = uf_ma[25];
300       if (ray->h.year < 1900) {
301         ray->h.year += 1900;
302         if (ray->h.year < 1980) ray->h.year += 100; /* Year >= 2000. */
303       }
304       ray->h.month    = uf_ma[26];
305       ray->h.day      = uf_ma[27];
306       ray->h.hour     = uf_ma[28];
307       ray->h.minute   = uf_ma[29];
308       ray->h.sec      = uf_ma[30];
309       ray->h.azimuth  = uf_ma[32] / 64.0;
310
311       /* If Local Use Header is present and contains azimuth, use that
312        * azimuth for VR and SW. This is for WSR-88D, which runs separate
313        * scans for DZ and VR/SW at the lower elevations, which means DZ
314        * VR/SW and have different azimuths in the "same" ray.
315        */
316       len_lu = uf_ma[4] - uf_ma[3];
317       if (len_lu == 2 && (ifield == VR_INDEX || ifield == SW_INDEX)) {
318           if (strncmp((char *)uf_lu,"ZA",2) == 0 ||
319               strncmp((char *)uf_lu,"AZ",2) == 0)
320           ray->h.azimuth = uf_lu[1] / 64.0;
321       }
322       if (ray->h.azimuth < 0.) ray->h.azimuth += 360.; /* make it 0 to 360. */
323       ray->h.elev     = uf_ma[33] / 64.0;
324       ray->h.elev_num = sweep->h.sweep_num;
325       ray->h.fix_angle  = sweep->h.elev = uf_ma[35] / 64.0;
326       ray->h.azim_rate  = uf_ma[36] / 64.0;
327       ray->h.sweep_rate = ray->h.azim_rate * (60.0/360.0);
328       missing_data      = uf_ma[44];
329
330       if (pulled_time_from_first_ray == 0) {
331         radar->h.height = uf_ma[24];
332         radar->h.latd = uf_ma[18];
333         radar->h.latm = uf_ma[19];
334         radar->h.lats = uf_ma[20] / 64.0;
335         radar->h.lond = uf_ma[21];
336         radar->h.lonm = uf_ma[22];
337         radar->h.lons = uf_ma[23] / 64.0;
338         radar->h.year  = ray->h.year;
339         radar->h.month = ray->h.month;
340         radar->h.day   = ray->h.day;
341         radar->h.hour  = ray->h.hour;
342         radar->h.minute = ray->h.minute;
343         radar->h.sec    = ray->h.sec;
344         strcpy(radar->h.radar_type, "uf");
345         pulled_time_from_first_ray = 1;
346       }
347       /*
348        * ---- End of MANDATORY HEADER BLOCK.
349        */
350       
351       /* ---- Optional header used for MCTEX files. */
352         /* If this is a MCTEX file, the first 4 words following the
353              mandatory header contain the string 'MCTEX'. */
354       memcpy(proj_name, (short *)(uf + uf_ma[2] - 1), 8);
355       if (little_endian()) swap2(proj_name, 4);
356
357
358       /* ---- Local Use Header (if present) was checked during Mandatory
359        *      Header processing above.
360        */
361       
362       /* ---- Begining of FIELD HEADER. */
363       uf_fh = uf+current_fh_index - 1;
364       scale_factor      = uf_fh[1];
365       ray->h.range_bin1 = uf_fh[2] * 1000.0 + uf_fh[3]; 
366       ray->h.gate_size  = uf_fh[4];
367
368       ray->h.nbins      = uf_fh[5];
369       ray->h.pulse_width  = uf_fh[6]/(RSL_SPEED_OF_LIGHT/1.0e6);
370
371         if (strncmp((char *)proj_name, "MCTEX", 5) == 0)  /* MCTEX? */
372         {
373             /* The beamwidth values are not correct in Mctex UF files. */
374             ray->h.beam_width = 1.0;
375             sweep->h.beam_width = ray->h.beam_width;
376             sweep->h.horz_half_bw = ray->h.beam_width/2.0;
377             sweep->h.vert_half_bw = ray->h.beam_width/2.0;
378         }
379         else  /* Not MCTEX */
380         {
381             ray->h.beam_width = uf_fh[7] / 64.0;
382             sweep->h.beam_width = uf_fh[7]  / 64.0;
383             sweep->h.horz_half_bw = uf_fh[7] / 128.0; /* DFF 4/4/95 */
384             sweep->h.vert_half_bw = uf_fh[8] / 128.0; /* DFF 4/4/95 */
385         }           
386         /*      fprintf (stderr, "uf_fh[7] = %d, [8] = %d\n", (int)uf_fh[7], (int)uf_fh[8]); */
387         if((int)uf_fh[7] == -32768) {
388             ray->h.beam_width     = 1;
389             sweep->h.beam_width   = 1;
390             sweep->h.horz_half_bw = .5;
391             sweep->h.vert_half_bw = .5;
392         }
393           
394       ray->h.frequency    = uf_fh[9]  / 64.0;
395       ray->h.wavelength   = uf_fh[11] / 64.0 / 100.0;  /* cm to m. */
396       ray->h.pulse_count  = uf_fh[12];
397       if (ifield == DZ_INDEX || ifield == ZT_INDEX) {
398         radar->v[ifield]->h.calibr_const  = uf_fh[16] / 100.0;
399                             /* uf value scaled by 100 */
400       }
401       else {
402         radar->v[ifield]->h.calibr_const  = 0.0;
403       }
404       if (uf_fh[17] == (short)UF_NO_DATA) x = 0;
405       else x = uf_fh[17] / 1000000.0;  /* PRT in seconds. */
406       if (x != 0) {
407         ray->h.prf = 1/x;
408         ray->h.unam_rng = RSL_SPEED_OF_LIGHT / (2.0 * ray->h.prf * 1000.0);
409       }
410       else {
411         ray->h.prf = 0.0;
412         ray->h.unam_rng = 0.0;
413       }
414
415       if (VR_INDEX == ifield || VE_INDEX == ifield) {
416         ray->h.nyq_vel = uf_fh[19] / scale_factor;
417       }
418       
419       /* ---- End of FIELD HEADER. */
420       
421       ray->h.f = f;
422       ray->h.invf = invf;
423
424       /* ---- Begining of FIELD DATA. */
425       uf_data = uf+uf_fh[0] - 1;
426
427       len_data = ray->h.nbins;  /* Known because of RSL_new_ray. */
428       for (m=0; m<len_data; m++) {
429         if (uf_data[m] == (short)UF_NO_DATA)
430           ray->range[m] = invf(BADVAL); /* BADVAL */
431         else {
432           if(uf_data[m] == missing_data)
433             ray->range[m] = invf(NOECHO); /* NOECHO */
434           else
435             ray->range[m] = invf((float)uf_data[m]/scale_factor);
436         }
437       }
438     }
439   }
440   return UF_MORE;
441 }
442
443
444 /*********************************************************************/
445 /*                                                                   */
446 /*                  swap_uf_buffer                                   */
447 /*                                                                   */
448 /*  By: John Merritt                                                 */
449 /*      Space Applications Corporation                               */
450 /*      October 4, 1994                                              */
451 /*********************************************************************/
452 void swap_uf_buffer(UF_buffer uf)
453 {
454   short *addr_end;
455
456   addr_end = uf + sizeof(UF_buffer)/sizeof(short);
457   while (uf < addr_end)
458     swap_2_bytes(uf++);
459 }
460
461 enum UF_type {NOT_UF, TRUE_UF, TWO_BYTE_UF, FOUR_BYTE_UF};
462
463
464 /*********************************************************************/
465 /*                                                                   */
466 /*                  RSL_uf_to_radar_fp                               */
467 /*                                                                   */
468 /*  By: John Merritt                                                 */
469 /*      Space Applications Corporation                               */
470 /*      September 22, 1995                                           */
471 /*********************************************************************/
472 Radar *RSL_uf_to_radar_fp(FILE *fp)
473 {
474   union {
475     char buf[6];
476     short sword;
477     int word;
478   } magic;
479   Radar *radar;
480   int nbytes;
481   short sbytes;
482   UF_buffer uf;
483   enum UF_type uf_type;
484 #define NEW_BUFSIZ 16384
485
486
487   radar = NULL;
488   setvbuf(fp,NULL,_IOFBF,(size_t)NEW_BUFSIZ); /* Faster i/o? */
489   if (fread(magic.buf, sizeof(char), 6, fp) <= 0) return NULL;
490 /*
491  * Check for fortran record length delimeters, NCAR kludge.
492  */
493   if (strncmp("UF", magic.buf, 2) == 0) uf_type = TRUE_UF;
494   else if (strncmp("UF", &magic.buf[2], 2) == 0) uf_type = TWO_BYTE_UF;
495   else if (strncmp("UF", &magic.buf[4], 2) == 0) uf_type = FOUR_BYTE_UF;
496   else uf_type = NOT_UF;
497   
498   switch (uf_type) {
499   case FOUR_BYTE_UF:
500     if (radar_verbose_flag) fprintf(stderr,"UF file with 4 byte FORTRAN record delimeters.\n");
501     /* Handle first record specially, since we needed magic information. */
502     nbytes = magic.word;
503     if (little_endian()) swap_4_bytes(&nbytes);
504     memcpy(uf, &magic.buf[4], 2);
505     (void)fread(&uf[1], sizeof(char), nbytes-2, fp);
506     if (little_endian()) swap_uf_buffer(uf);
507     (void)fread(&nbytes, sizeof(int), 1, fp);
508     if (uf_into_radar(uf, &radar) == UF_DONE) break;
509     /* Now the rest of the file. */
510     while(fread(&nbytes, sizeof(int), 1, fp) > 0) {
511       if (little_endian()) swap_4_bytes(&nbytes);
512       
513       (void)fread(uf, sizeof(char), nbytes, fp);
514       if (little_endian()) swap_uf_buffer(uf);
515       
516       (void)fread(&nbytes, sizeof(int), 1, fp);
517       
518       if (uf_into_radar(uf, &radar) == UF_DONE) break;
519     }
520     break;
521
522   case TWO_BYTE_UF:
523     if (radar_verbose_flag) fprintf(stderr,"UF file with 2 byte FORTRAN record delimeters.\n");
524     /* Handle first record specially, since we needed magic information. */
525     sbytes = magic.sword;
526     if (little_endian()) swap_2_bytes(&sbytes);
527     memcpy(uf, &magic.buf[2], 4);
528     (void)fread(&uf[2], sizeof(char), sbytes-4, fp);
529     if (little_endian()) swap_uf_buffer(uf);
530     (void)fread(&sbytes, sizeof(short), 1, fp);
531     uf_into_radar(uf, &radar);
532     /* Now the rest of the file. */
533     while(fread(&sbytes, sizeof(short), 1, fp) > 0) {
534       if (little_endian()) swap_2_bytes(&sbytes);
535       
536       (void)fread(uf, sizeof(char), sbytes, fp);
537       if (little_endian()) swap_uf_buffer(uf);
538       
539       (void)fread(&sbytes, sizeof(short), 1, fp);
540       
541       if (uf_into_radar(uf, &radar) == UF_DONE) break;
542     }
543     break;
544
545   case TRUE_UF:
546     if (radar_verbose_flag) fprintf(stderr,"UF file with no FORTRAN record delimeters.  Good.\n");
547     /* Handle first record specially, since we needed magic information. */
548     memcpy(&sbytes, &magic.buf[2], 2); /* Record length is in word #2. */
549     if (little_endian()) swap_2_bytes(&sbytes); /* # of 2 byte words. */
550
551     memcpy(uf, &magic.buf[0], 6);
552     (void)fread(&uf[3], sizeof(short), sbytes-3, fp);
553     if (little_endian()) swap_uf_buffer(uf);
554     uf_into_radar(uf, &radar);
555     /* Now the rest of the file. */
556     while(fread(uf, sizeof(short), 2, fp) > 0) {
557       memcpy(&sbytes, &uf[1], 2);  /* Record length is in word #2. */
558       if (little_endian()) swap_2_bytes(&sbytes);
559       
560       (void)fread(&uf[2], sizeof(short), sbytes-2, fp);  /* Have words 1,2. */
561       if (little_endian()) swap_uf_buffer(uf);
562       
563       if (uf_into_radar(uf, &radar) == UF_DONE) break;
564     }
565     break;
566     
567   case NOT_UF: return NULL; break;
568   }
569   radar = reset_nsweeps_in_all_volumes(radar);
570   radar = RSL_prune_radar(radar);
571
572   return radar;
573 }
574
575
576 /*********************************************************************/
577 /*                                                                   */
578 /*                  RSL_uf_to_radar                                  */
579 /*                                                                   */
580 /*  By: John Merritt                                                 */
581 /*      Space Applications Corporation                               */
582 /*      September 22, 1995                                           */
583 /*********************************************************************/
584 Radar *RSL_uf_to_radar(char *infile)
585 {
586 /*
587  * This routine ingests a UF file and fills the Radar structure.
588  * This routine allocates space via the system routine malloc.
589  *
590  * If *infile is NULL, read from stdin.
591  */
592   FILE *fp;
593   Radar *radar;
594   
595   radar = NULL;
596   if (infile == NULL) {
597     int save_fd;
598     save_fd = dup(0);
599     fp = fdopen(save_fd, "r");
600   }  else if ((fp = fopen(infile, "r")) == NULL) {
601     perror(infile);
602     return radar;
603   }
604   fp = uncompress_pipe(fp); /* Transparently gunzip. */
605   radar = RSL_uf_to_radar_fp(fp);
606   rsl_pclose(fp);
607     
608   return radar;
609 }