#!/bin/sh
set -xa

# Dump aircraft data for MADIS
#
# This script's Variables
#   CDY  (imported)  Current day (like PDY but not based on com/date)
#   HHMM (imported)  Current time
#   RUNDIR     the MADIS Run directory
#   ATIME      the 9-character DB time (YYDDDHHMM)
#   MIN        the current minute (MM)
#
#   BUFRRAW    directory for the output aircraft BUFR dumps

RUNDIR=${DATA}

# RAW BUFR FILES
BUFRRAW=${COMOUT}/aircraft/bufr
mkdir -p ${BUFRRAW} ${RUNDIR}/aircraft 
###############################################################################
# Determine the time
###############################################################################

#  By the default below the minutes were rounded back
#  to the nearest hour.

HH=${HHMM:0:2}
MIN=${HHMM:2:2}
ATIME=`date -d "$CDY $HH:00 UTC" +%y%j%H%M`

$USHmadis/FSL_aircraft.run $RUNDIR $ATIME $MIN $BUFRRAW
export err=$?;err_chk
