2 NASA/TRMM, Code 910.1.
\r
3 This is the TRMM Office Radar Software Library.
\r
4 Copyright (C) 1996, 1997
\r
6 Space Applications Corporation
\r
9 This library is free software; you can redistribute it and/or
\r
10 modify it under the terms of the GNU Library General Public
\r
11 License as published by the Free Software Foundation; either
\r
12 version 2 of the License, or (at your option) any later version.
\r
14 This library is distributed in the hope that it will be useful,
\r
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
17 Library General Public License for more details.
\r
19 You should have received a copy of the GNU Library General Public
\r
20 License along with this library; if not, write to the Free
\r
21 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
24 * By John H. Merritt
\r
25 * Science Applications Corporation, Vienna, VA
\r
33 void rsl_readflush(FILE *fp);
\r
34 /*********************************************************************/
\r
38 /*********************************************************************/
\r
39 enum File_type RSL_filetype(char *infile)
\r
41 /* Open the input file and peek at the first few bytes to determine
\r
44 * UF - First two bytes 'UF'
\r
45 * - or 3,4 bytes 'UF'
\r
46 * - or 5,6 bytes 'UF'. This is the most common.
\r
48 * WSR88D - First 8 bytes: 'ARCHIVE2' or 'AR2V0001'
\r
56 * RADTEC - 320 (decimal, in first two bytes)
\r
57 * RAINBOW - First two bytes: decimal 1, followed by 'H'
\r
62 if ((fp = fopen(infile, "r")) == NULL) {
\r
67 /* Read the magic bytes. */
\r
68 fp = uncompress_pipe(fp); /* If gzip available. */
\r
69 if (fread(magic, sizeof(magic), 1, fp) != 1) {
\r
70 char *magic_str = (char *)calloc(sizeof(magic)+1, sizeof(char));
\r
71 memcpy(magic_str, magic, sizeof(magic));
\r
72 fprintf(stderr,"Error fread: Magic is %s\n", magic_str);
\r
74 perror("RSL_filetype");
\r
75 /* Thanks to Thiago Biscaro for fixing defunct process problem. */
\r
81 Closes the stream and wait for associated processes to terminate
\r
82 (just like wait() ) to avoid defunct processes. The old rsl_readflush
\r
83 function wasn't doing this, N calls to anyformat_to_radar would
\r
84 generate N defunct processes associated with the main program
\r
90 if (strncmp("ARCHIVE2.", magic, 9) == 0) return WSR88D_FILE;
\r
91 if (strncmp("AR2V000", magic, 7) == 0) return WSR88D_FILE;
\r
92 if (strncmp("UF", magic, 2) == 0) return UF_FILE;
\r
93 if (strncmp("UF", &magic[2], 2) == 0) return UF_FILE;
\r
94 if (strncmp("UF", &magic[4], 2) == 0) return UF_FILE;
\r
95 if ((int)magic[0] == 0x0e &&
\r
96 (int)magic[1] == 0x03 &&
\r
97 (int)magic[2] == 0x13 &&
\r
98 (int)magic[3] == 0x01
\r
100 if (strncmp("RSL", magic, 3) == 0) return RSL_FILE;
\r
101 if ((int)magic[0] == 7) return NSIG_FILE_V1;
\r
102 if ((int)magic[1] == 7) return NSIG_FILE_V1;
\r
103 if ((int)magic[0] == 27) return NSIG_FILE_V2;
\r
104 if ((int)magic[1] == 27) return NSIG_FILE_V2;
\r
105 if (strncmp("/IMAGE:", magic, 7) == 0) return RAPIC_FILE;
\r
106 if ((int)magic[0] == 0x40 &&
\r
107 (int)magic[1] == 0x01
\r
108 ) return RADTEC_FILE;
\r
109 if ((int)magic[0] == 0x01 && magic[1] == 'H') return RAINBOW_FILE;
\r
111 if (strncmp("SUNRISE", &magic[4], 7) == 0) return LASSEN_FILE;
\r
112 /* The 'P A B' is just too specific to be a true magic number, but that's all
\r
115 if (strncmp("P A B ", magic, 6) == 0) return MCGILL_FILE;
\r
116 /* Byte swapped ? */
\r
117 if (strncmp(" P A B", magic, 6) == 0) return MCGILL_FILE;
\r
118 if (strncmp("Volume", magic, 6) == 0) return EDGE_FILE;
\r
119 if (strncmp("SSWB", magic, 4) == 0) return DORADE_FILE;
\r
120 if (strncmp("VOLD", magic, 4) == 0) return DORADE_FILE;
\r
131 /*********************************************************************/
\r
133 /* RSL_anyformat_to_radar */
\r
135 /*********************************************************************/
\r
137 Radar *RSL_anyformat_to_radar(char *infile, ...)
\r
140 char *callid_or_file;
\r
143 /* If it is detected that the input file is WSR88D, use the second argument
\r
144 * as the call id of the site, or the file name of the tape header file.
\r
146 * Assumption: Input files are seekable.
\r
149 switch (RSL_filetype(infile)) {
\r
151 callid_or_file = NULL;
\r
152 va_start(ap, infile);
\r
153 callid_or_file = va_arg(ap, char *);
\r
155 radar = RSL_wsr88d_to_radar(infile, callid_or_file);
\r
157 case UF_FILE: radar = RSL_uf_to_radar(infile); break;
\r
158 case TOGA_FILE: radar = RSL_toga_to_radar(infile); break;
\r
159 case NSIG_FILE_V1: radar = RSL_nsig_to_radar(infile); break;
\r
160 case NSIG_FILE_V2: radar = RSL_nsig2_to_radar(infile); break;
\r
161 case RAPIC_FILE: radar = RSL_rapic_to_radar(infile); break;
\r
162 case RADTEC_FILE: radar = RSL_radtec_to_radar(infile); break;
\r
163 case RSL_FILE: radar = RSL_read_radar(infile); break;
\r
164 #ifdef HAVE_LIBTSDISTK
\r
165 case HDF_FILE: radar = RSL_hdf_to_radar(infile); break;
\r
167 case RAINBOW_FILE: radar = RSL_rainbow_to_radar(infile); break;
\r
168 case MCGILL_FILE: radar = RSL_mcgill_to_radar(infile); break;
\r
169 case EDGE_FILE: radar = RSL_EDGE_to_radar(infile); break;
\r
170 case LASSEN_FILE: radar = RSL_lassen_to_radar(infile); break;
\r
171 case DORADE_FILE: radar = RSL_dorade_to_radar(infile); break;
\r
174 fprintf(stderr, "Unknown input file type. File <%s> is not recognized by RSL.\n", infile);
\r