#!/bin/bash # ================================================================================================== # Purpose: This script is used to interpolate ms2gt row and column binary # files which are produced by the ll2cr program. The interpolation is done # by the IDL script ``interp_colrow.pro`` that was developed by # Terry Haran - tharan@colorado.edu. # # Input parameters: # 1. The scale value with what the data should be interpolated with. This # must be a natural number: 1, 2, 3, ... # 2. The prefix string with what the output file names must start with. # 3. The ms2gt output column binary file, generated by the program ll2cr. # 4. The ms2gt output row binary file, generated by the program ll2cr. # # Output: # Two files are given to the script, and two output files will be # generated. The output files with start with the prefix string given to the # script. # The output file name convention will be as follows: # _____.img # # Comments about the fields: # # Field 1. The prefix string could have a '_' character. # Field 2. This will be either equal to "rows" or "cols". # Field 3. Number of rows. This will always be a five digit number. # Field 4. The number of scans. This will always be a five digit number. # Field 5. The value of this field will always be zero. This will always be # a five digit number. # Field 6. The number of rows per scan. # # Author: Willem.Marais@ssec.wisc.edu # Date: 09/13/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 if [ $# -ne 4 ]; then echo "Usage: " echo " "$(basename $0)" " exit 1 fi interp_factor=$1 given_tag=$2 col_filein=$3 row_filein=$4 dir_col_filein=$(dirname $col_filein) base_col_filein=$(basename $col_filein .img) dir_row_filein=$(dirname $row_filein) base_row_filein=$(basename $row_filein .img) colsin=$(echo $base_col_filein | cut -d"_" -f 3 | bc) scans=$(echo $base_col_filein | cut -d"_" -f 4 | bc) rowsperscanin=$(echo $base_col_filein | cut -d"_" -f 6 | bc) colsout=$(echo "$colsin * $interp_factor" | bc) col_filein_parts=$(echo $base_col_filein | cut -d"_" -f 1) row_filein_parts=$(echo $base_row_filein | cut -d"_" -f 1) tag=$given_tag"-"$col_filein_parts cat > runidl << EOF interp_colrow, $interp_factor, $colsin, $scans, $rowsperscanin, '$col_filein', '$row_filein', $colsout, '$tag' 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) The following IDL script failed." echo "========= IDL script =========" cat runidl echo "========= IDL output =========" cat idl_output.txt exit 1 fi rm -f runidl idl_output.txt flsave.pro