#!/bin/sh -x
#
# Name: makeotfrreq.sh
#
# Description: 
#
#   A tool that generates OTFR request files for each dataset name listed
#   in a file.  THe filename is the only argument.
#
#   NOTE: This is just a tool for testing the system.
#         It is meant to simulate the DADS function of generating 
#         OTFC requests for the system. 
#
#         It is NOT used in the OTFC pipeline.
# 
# 10/11/01  44597  MSwam          fix for Solaris
#
#------------------------------------------------------------------------------
#
if [ ! -r "$1" ]
then
   echo "No such file: $1"
   exit 1
fi
for i in `cat $1`
do
   ipppssoot=`echo $i | awk '{a=substr($1,1,9);print a}'`
   up_ipppssoot=`echo $ipppssoot | tr '[a-z]' '[A-Z]'`

   timestamp=`req_timestamp.pl`
#
#  trim timestamp to DDHHMMSS
   stamp=`echo $timestamp | awk '{a=substr($1,6,8);print a}'`

   reqname=${stamp}12345_${ipppssoot}.req
   echo $reqname

   filecount=`ls -1 ${ipppssoot}* | wc -l | awk '{print $1}'`
   echo $filecount

   echo "DATASET_NAME=$up_ipppssoot" >> $reqname
   echo "FILE_COUNT=$filecount" >> $reqname
   echo "DIRECTORY=`pwd`/" >> $reqname
   echo "TIMESTAMP=${stamp}12345" >> $reqname
   echo "DADS_REQ=andcaaaaikcjchablgakdbabaaaaaaaaEtest51153z" >> $reqname
   echo "DADS_SUBREQ=andcaaaaikcjchablgakdbababaaaaaa" >> $reqname
   echo "END_FILE" >> $reqname

done
