3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996, 1997
6 Space Applications Corporation
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.
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.
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.
25 * Science Applications Corporation, Vienna, VA
33 void rsl_readflush(FILE *fp);
34 /*********************************************************************/
38 /*********************************************************************/
39 enum File_type RSL_filetype(char *infile)
41 /* Open the input file and peek at the first few bytes to determine
44 * UF - First two bytes 'UF'
46 * - or 5,6 bytes 'UF'. This is the most common.
48 * WSR88D - First 8 bytes: 'ARCHIVE2' or 'AR2V0001'
56 * RADTEC - 320 (decimal, in first two bytes)
57 * RAINBOW - First two bytes: decimal 1, followed by 'H'
62 if ((fp = fopen(infile, "r")) == NULL) {
67 /* Read the magic bytes. */
68 fp = uncompress_pipe(fp); /* If gzip available. */
69 if (fread(magic, sizeof(magic), 1, fp) != 1) {
70 char *magic_str = (char *)calloc(sizeof(magic)+1, sizeof(char));
71 memcpy(magic_str, magic, sizeof(magic));
72 fprintf(stderr,"Error fread: Magic is %s\n", magic_str);
74 perror("RSL_filetype");
79 rsl_readflush(fp); /* Fork, read and exit -- eliminates the 'Broken pipe' */
81 if (strncmp("ARCHIVE2.", magic, 9) == 0) return WSR88D_FILE;
82 if (strncmp("AR2V000", magic, 7) == 0) return WSR88D_FILE;
83 if (strncmp("UF", magic, 2) == 0) return UF_FILE;
84 if (strncmp("UF", &magic[2], 2) == 0) return UF_FILE;
85 if (strncmp("UF", &magic[4], 2) == 0) return UF_FILE;
86 if ((int)magic[0] == 0x0e &&
87 (int)magic[1] == 0x03 &&
88 (int)magic[2] == 0x13 &&
91 if (strncmp("RSL", magic, 3) == 0) return RSL_FILE;
92 if ((int)magic[0] == 7) return NSIG_FILE_V1;
93 if ((int)magic[1] == 7) return NSIG_FILE_V1;
94 if ((int)magic[0] == 27) return NSIG_FILE_V2;
95 if ((int)magic[1] == 27) return NSIG_FILE_V2;
96 if (strncmp("/IMAGE:", magic, 7) == 0) return RAPIC_FILE;
97 if ((int)magic[0] == 0x40 &&
100 if ((int)magic[0] == 0x01 && magic[1] == 'H') return RAINBOW_FILE;
102 if (strncmp("SUNRISE", &magic[4], 7) == 0) return LASSEN_FILE;
103 /* The 'P A B' is just too specific to be a true magic number, but that's all
106 if (strncmp("P A B ", magic, 6) == 0) return MCGILL_FILE;
108 if (strncmp(" P A B", magic, 6) == 0) return MCGILL_FILE;
109 if (strncmp("Volume", magic, 6) == 0) return EDGE_FILE;
110 if (strncmp("SSWB", magic, 4) == 0) return DORADE_FILE;
111 if (strncmp("VOLD", magic, 4) == 0) return DORADE_FILE;
122 /*********************************************************************/
124 /* RSL_anyformat_to_radar */
126 /*********************************************************************/
128 Radar *RSL_anyformat_to_radar(char *infile, ...)
131 char *callid_or_file;
134 /* If it is detected that the input file is WSR88D, use the second argument
135 * as the call id of the site, or the file name of the tape header file.
137 * Assumption: Input files are seekable.
140 switch (RSL_filetype(infile)) {
142 callid_or_file = NULL;
143 va_start(ap, infile);
144 callid_or_file = va_arg(ap, char *);
146 radar = RSL_wsr88d_to_radar(infile, callid_or_file);
148 case UF_FILE: radar = RSL_uf_to_radar(infile); break;
149 case TOGA_FILE: radar = RSL_toga_to_radar(infile); break;
150 case NSIG_FILE_V1: radar = RSL_nsig_to_radar(infile); break;
151 case NSIG_FILE_V2: radar = RSL_nsig2_to_radar(infile); break;
152 case RAPIC_FILE: radar = RSL_rapic_to_radar(infile); break;
153 case RADTEC_FILE: radar = RSL_radtec_to_radar(infile); break;
154 case RSL_FILE: radar = RSL_read_radar(infile); break;
155 #ifdef HAVE_LIBTSDISTK
156 case HDF_FILE: radar = RSL_hdf_to_radar(infile); break;
158 case RAINBOW_FILE: radar = RSL_rainbow_to_radar(infile); break;
159 case MCGILL_FILE: radar = RSL_mcgill_to_radar(infile); break;
160 case EDGE_FILE: radar = RSL_EDGE_to_radar(infile); break;
161 case LASSEN_FILE: radar = RSL_lassen_to_radar(infile); break;
162 case DORADE_FILE: radar = RSL_dorade_to_radar(infile); break;
165 fprintf(stderr, "Unknown input file type. File <%s> is not recognized by RSL.\n", infile);