#!/bin/ksh # Get the GDAS1 ancillary data file closest to a MODIS granule date and time # Check number of arguments if [ $# != 3 ]; then echo "Usage: get_gdas dir date time" echo " dir is the directory containing the GDAS1 files" echo " date is the date (yyyyddd)" echo " time is the time (hhmm)" exit 1 fi # Get arguments dir=$1 date=$2 time=$3 # Set the day and time of the closest GDAS1 file if [[ $time -ge 0000 && $time -le 0255 ]]; then gdas_time="00" gdas_delta=0 elif [[ $time -ge 0300 && $time -le 0855 ]]; then gdas_time="06" gdas_delta=0 elif [[ $time -ge 0900 && $time -le 1455 ]]; then gdas_time="12" gdas_delta=0 elif [[ $time -ge 1500 && $time -le 2055 ]]; then gdas_time="18" gdas_delta=0 elif [[ $time -ge 2100 && $time -le 2355 ]]; then gdas_time="00" gdas_delta=1 fi # Compute the Gregorian date (yyyymmdd) of the closest GDAS1 file modis_date=`dateplus -J $date` gdas_date=`dateplus $gdas_delta $modis_date | cut -c3-8` # Find the GDAS1 file gdas_name="gdas1.PGrbF00."${gdas_date}.${gdas_time}"z" gdas_file=`find $dir -size +20000000c -name $gdas_name` # Check for success if [[ $gdas_file != "" ]]; then echo $gdas_file exit 0 else exit 1 fi