; Copyright (C) 2003 NASA/TRMM Satellite Validation Office ; ; 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 2 of the License, or ; (at your option) any later version. ; ; This program 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. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;************************************************************************** ; ; rsl_anyformat_to_radar ; ; This function determines the format of the input radar file and calls the ; appropriate function to read data into the radar structure. If successful, ; a radar structure is returned, otherwise, function returns value of -1. ; ; Syntax: ; radar = rsl_anyformat_to_radar(radarfile [, siteID-or-header] ; [, VOS_NUMBER=vosnumber] [, /CATCH_ERROR] ; [, /QUIET] [, ERROR=variable]) ; ; Inputs: ; radarfile: string containing name of radar file. ; siteID-or-header: ; optional argument for WSR-88D processing: It is a string containing ; either the 4-character WSR-88D site ID or the name of a WSR-88D ; header file. If omitted, program will attempt to get site ID from ; file name. ; ; Keyword parameters: ; VOS_NUMBER: ; for processing TSDIS HDF only, number of the volume scan to be read ; from HDF. Default is to read first VOS (VOS_NUMBER = 1). ; CATCH_ERROR: ; Set this keyword to enable an error handler that will return control ; to the calling function if an IDL error occurs. Normally when an IDL ; error occurs, a message is printed and processing stops. When ; catch_error is set, a message is printed and rsl_anyformat_to_radar ; returns -1. ; QUIET: ; Set this keyword to turn off progress reporting. ; ERROR: ; Assign a variable to this keyword to have a boolean error status ; returned. A value of 1 (true) indicates an error occurred, 0 means ; no error. ; ; Written by: Bart Kelley, GMU, January 2003 ; Based on the RSL program RSL_anyformat_to_radar by John Merritt of SM&A Corp. ;************************************************************************** ;******************************; ; rsl_filetype ; ;******************************; function rsl_filetype, infile ; Attempt to determine the file type. Returns the file type as defined in ; common FILETYPES below, or 0 if file type is not recognized. common filetypes, unknown, wsr88d_file, uf_file, hdf_file, nsig_file, $ lassen_file unknown = 0 wsr88d_file = 1 uf_file = 2 hdf_file = 3 nsig_file = 4 lassen_file = 5 ; Open file (decompress if necessary). if is_compressed(infile) then begin tmp_file = rsl_uncompress(infile) openr, iunit, tmp_file, /get_lun, /delete ; this file is deleted on close. endif else openr, iunit, infile, /get_lun ; Read in the magic bytes (in keeping with the original RSL terminology) used ; to identify the radar data format. magic = bytarr(11) readu, iunit, magic free_lun, iunit ; Test for filetype. filetype = unknown if string(magic[0:8]) eq 'ARCHIVE2.' or string(magic[0:8]) eq 'AR2V0001.' then $ filetype = wsr88d_file $ else if string(magic[4:5]) eq 'UF' or string(magic[0:1]) eq 'UF' or $ string(magic[2:3]) eq 'UF' then filetype = uf_file $ else if magic[0] eq '0e'x and magic[1] eq '03'x and magic[2] eq '13'x and $ magic[3] eq '01'x then filetype = hdf_file $ else if (magic[0] eq 0 and (magic[1] eq 27 or magic[1] eq 7)) or $ (magic[1] eq 0 and (magic[0] eq 27 or magic[0] eq 7)) $ then filetype = nsig_file $ else if string(magic[4:10]) eq 'SUNRISE' then filetype = lassen_file return, filetype end ;******************************; ; rsl_anyformat_to_radar ; ;******************************; function rsl_anyformat_to_radar, filename, siteid_or_header, $ vos_number=vosnum, catch_error=catch_error, quiet=quiet, error=error, $ _EXTRA=keywords ; This function determines the format of the input file and calls the ; appropriate function to read data into the radar structure. common filetypes, unknown, wsr88d_file, uf_file, hdf_file, nsig_file, $ lassen_file no_radar = -1 radar = no_radar error = 0 ; Set up error handler to be used with keyword CATCH_ERROR. If CATCH_ERROR is ; not set, the error handler is canceled. catch, errcode ; Error handler begins here. if errcode ne 0 then begin print,!error_state.msg_prefix+!error_state.msg message,'Error occurred while processing file '+filename+'.',/continue error = 1 return, no_radar endif if not keyword_set(catch_error) then catch, /cancel ; Cancel error handler. ; Determine file format and call appropriate ingest function. ; ("filename[0]" is used to pass filename by value.) case rsl_filetype(filename[0]) of wsr88d_file: radar = rsl_wsr88d_to_radar(filename, siteid_or_header, $ error=error, quiet=quiet) uf_file: radar = rsl_uf_to_radar(filename, error=error, quiet=quiet, $ _EXTRA=keywords) hdf_file: radar = rsl_hdf_to_radar(filename, vos_number=vosnum, $ error=error, quiet=quiet) nsig_file: radar = rsl_nsig_to_radar(filename, error=error, quiet=quiet, $ catch_error=catch_error, _EXTRA=keywords) lassen_file: radar = rsl_lassen_to_radar(filename, error=error, quiet=quiet) unknown: begin message,'Unrecognized format',/informational radar = no_radar end endcase if size(radar,/n_dimensions) eq 0 then error = 1 return, radar end