#!/bin/sh

# ================================================================
# This script will be invoked by DataAccessBlackBox after it has
# copied all DataAccess Editor parameters and values into shell
# environment variables.

# Fail if any command in error

set -e

# ================================================================
# DataAccessBlackBox wants the retrieved data to be put into one
# of the files given as parameters for this script:
#   - use the first  parameter to return GRIB fields
#   - use the second parameter to return BUFR data

# Let's use more descriptive names:

field_target=$1
obs_target=$2


# ================================================================
# The request parameters are in shell environment variables.
# The script output goes to User Interface Message Window

echo "Starting the Access script, date is $DATE, model is $MODEL, leveltype is $LEVEL_TYPE..."

# ================================================================
# Do here what ever you need (isql, ftp, cp, ...) using all those
# environment variables available from our DataAccess Editor.
# As an example we try to copy a file from our home directory

my_file=$HOME/grib.$TIME
if [ -f $my_file ]
then
  cp $my_file $field_target
else
  echo "DataAccess error: $my_file not found in the \"database\"!"
fi

# ================================================================
#      DataAccessBlackBox will take care of the rest...        :-)
