#!/bin/bash # ============================================================================ # Purpose: This script is used to convert a SDS array in a HDF4 file into a # raster binary file. If geolocation data in a HDF4 file is converted into # a raster binary file. # # Input parameters: # 1. The L1B HDF4 file. # 2. The SDS array name in the L1B HDF4 file that is going to be converted # into a raster binary file. # 3. A prefix string that will be added to the output file name. # # Output: The output will be a raster binary file. The file name will include # the specifications of the binary file. There are four fields, delimited # by the '_' character. The fields are are follows: # ___.dat # # Author: Willem.Marais@ssec.wisc.edu # Date: 09/17/2012 # ============================================================================ # Check if the IDL interpreter is available if [ -z $IDL_CMD ]; then idl_path_str=$(which idl) if [ $? -ne 0 ]; then echo "(ERROR) Set the environmental variable IDL_CMD equal to the IDL interpreter path." exit 1 fi IDL_CMD=$idl_path_str fi usage_str=$(basename $0)" " if [ $# -ne 3 ]; then echo "(ERROR) Usage: " echo " "$usage_str exit 1 fi hdf_file=$1 sds_name=$2 out_prefix_str=$3 # If the desired file already exists, don't execute the IDL code ls "$out_prefix_str"_*.dat &> /dev/null if [ $? -eq 0 ]; then exit 0 fi cat > runidl << EOF hdf_to_binary, '$hdf_file', '$sds_name', '$out_prefix_str' exit EOF if [ "$SCRIPT_DEBUG" == "YES" ]; then cat runidl $IDL_CMD runidl &> idl_output.txt idl_rtn=$? cat idl_output.txt else $IDL_CMD runidl &> idl_output.txt idl_rtn=$? fi grep -i "Error" idl_output.txt &> /dev/null if [ $? -eq 0 ] || [ $idl_rtn -ne 0 ]; then echo "(ERROR) IDL script 'hdf_to_binary' could not convert file "$(basename $hdf_file)" into binary file." echo "========= IDL script =========" cat runidl echo "========= IDL output =========" cat idl_output.txt exit 1 fi rm -f runidl idl_output.txt flsave.pro